EMMA Coverage Report (generated Mon Oct 04 21:03:19 MDT 2004)
[all classes][biz.xsoftware.buildtemplate]

COVERAGE SUMMARY FOR SOURCE FILE [AntSocketLogger.java]

nameclass, %method, %block, %line, %
AntSocketLogger.java100% (1/1)20%  (1/5)8%   (11/143)11%  (4/38)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AntSocketLogger100% (1/1)20%  (1/5)8%   (11/143)11%  (4/38)
buildFinished (BuildEvent): void 0%   (0/1)0%   (0/16)0%   (0/7)
buildStarted (BuildEvent): void 0%   (0/1)0%   (0/4)0%   (0/2)
printMessage (String, PrintStream, int): void 0%   (0/1)0%   (0/62)0%   (0/11)
targetStarted (BuildEvent): void 0%   (0/1)0%   (0/50)0%   (0/14)
AntSocketLogger (): void 100% (1/1)100% (11/11)100% (4/4)

1package biz.xsoftware.buildtemplate;
2import java.io.IOException;
3import java.io.OutputStream;
4import java.io.PrintStream;
5import java.io.PrintWriter;
6import java.net.InetAddress;
7import java.net.Socket;
8 
9import org.apache.tools.ant.BuildEvent;
10import org.apache.tools.ant.DefaultLogger;
11/*
12 * Created on Sep 6, 2004
13 *
14 * TODO To change the template for this generated file go to
15 * Window - Preferences - Java - Code Style - Code Templates
16 */
17 
18/**
19 * @author Dean Hiller
20 *
21 * TODO To change the template for this generated type comment go to
22 * Window - Preferences - Java - Code Style - Code Templates
23 */
24public class AntSocketLogger extends DefaultLogger {
25        
26        public static final String PORT_PROPERTY = "biz.xsoftware.buildtemplate.AntSocketLogger.port";
27        private boolean socketFailure = false;
28        private Socket socket;
29        private PrintWriter writer;
30        private StringBuffer cache = new StringBuffer();
31        public AntSocketLogger() {
32        }
33        
34        
35        /* (non-Javadoc)
36         * @see org.apache.tools.ant.DefaultLogger#printMessage(java.lang.String, java.io.PrintStream, int)
37         */
38        protected void printMessage(String message, PrintStream stream, int priority) {
39                if(socketFailure)
40                        stream.print(message+"\n");
41                else if(writer != null) {
42                        if(cache != null) {
43                                writer.print(cache.toString());
44                                cache = null;
45                        }
46                        writer.print(message+"\n");
47                        writer.flush();
48                }
49                else {
50                        //unfortunately, sometimes, the socket does not open at all, like
51                        //when there is some kind fo failure on a taskdef, and so we
52                        //must print it out to stream so it is still printed to the screen
53                        //at some point.
54                        stream.print(message+"\n");
55                        cache.append(message).append("\n");
56                }
57        }
58        
59        /* (non-Javadoc)
60         * @see org.apache.tools.ant.BuildListener#buildStarted(org.apache.tools.ant.BuildEvent)
61         */
62        public void buildStarted(BuildEvent evt) {                                
63                super.buildStarted(evt);
64        }
65        
66        /* (non-Javadoc)
67         * @see org.apache.tools.ant.BuildListener#targetStarted(org.apache.tools.ant.BuildEvent)
68         */
69        public void targetStarted(BuildEvent evt) {
70                if(socket == null && !socketFailure) {
71                        String portString = evt.getProject().getProperty(PORT_PROPERTY);
72                        int port = Integer.parseInt(portString);
73                        InetAddress localHost;
74                        try {
75                                localHost = InetAddress.getByName("127.0.0.1");
76                                socket = new Socket(localHost, port);
77                                OutputStream socketOut = socket.getOutputStream();
78                                writer = new PrintWriter(socketOut);
79                                writer.flush();
80                        } catch (Exception e) {
81                                socketFailure = true;
82                                e.printStackTrace(out);
83                        }
84                }                
85                
86                super.targetStarted(evt);
87        }
88        /* (non-Javadoc)
89         * @see org.apache.tools.ant.BuildListener#buildFinished(org.apache.tools.ant.BuildEvent)
90         */
91        public void buildFinished(BuildEvent evt) {
92                super.buildFinished(evt);
93                
94                try {
95                        if(socket != null)
96                                socket.close();
97                } catch (IOException e) {
98                        e.printStackTrace(out);
99                }
100        }
101}

[all classes][biz.xsoftware.buildtemplate]
EMMA 2.0.4217 (C) Vladimir Roubtsov