Subversion Repositories XServices

Rev

Rev 6 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6 Rev 11
Line 14... Line 14...
14
 *   limitations under the License.
14
 *   limitations under the License.
15
 */
15
 */
Line 16... Line 16...
16
 
16
 
Line -... Line 17...
-
 
17
package net.brutex.xservices.util;
-
 
18
 
17
package net.brutex.xservices.util;
19
import java.io.ByteArrayOutputStream;
18
 
20
import java.io.PrintStream;
19
import java.util.Iterator;
21
import java.util.Iterator;
20
import java.util.Map;
22
import java.util.Map;
21
import java.util.Vector;
23
import java.util.Vector;
22
import org.apache.tools.ant.BuildException;
24
import org.apache.tools.ant.BuildException;
23
import org.apache.tools.ant.BuildListener;
-
 
24
import org.apache.tools.ant.BuildLogger;
25
import org.apache.tools.ant.BuildListener;
25
import org.apache.tools.ant.DefaultLogger;
26
import org.apache.tools.ant.BuildLogger;
26
import org.apache.tools.ant.Project;
27
import org.apache.tools.ant.Project;
-
 
28
import org.apache.tools.ant.Target;
27
import org.apache.tools.ant.Target;
29
import org.apache.tools.ant.Task;
Line 28... Line 30...
28
import org.apache.tools.ant.Task;
30
import org.apache.tools.ant.listener.TimestampedLogger;
29
import org.apache.tools.ant.taskdefs.Echo;
31
import org.apache.tools.ant.taskdefs.Echo;
30
 
32
 
Line 36... Line 38...
36
 
38
 
37
    Project antproject;
39
    Project antproject;
38
    Target anttarget;
40
    Target anttarget;
Line -... Line 41...
-
 
41
    Task anttask;
-
 
42
 
-
 
43
    ByteArrayOutputStream out = new ByteArrayOutputStream();
-
 
44
    ByteArrayOutputStream err = new ByteArrayOutputStream();
39
    Task anttask;
45
    TimestampedLogger log = null;
Line 40... Line 46...
40
 
46
 
41
    public RunTask(Task anttask) {
47
    public RunTask(Task anttask) {
42
 
48
 
43
        antproject = new Project();
49
        antproject = new Project();
44
        antproject.init();
50
        antproject.init();
45
        antproject.setBasedir(System.getProperty("java.io.tmpdir"));
51
        antproject.setBasedir(System.getProperty("java.io.tmpdir"));
-
 
52
        log = new TimestampedLogger();
-
 
53
        log.setOutputPrintStream(new PrintStream(out));
46
        DefaultLogger log = new DefaultLogger();
54
        log.setErrorPrintStream(new PrintStream(err));
47
        log.setErrorPrintStream(System.err);
-
 
48
        log.setOutputPrintStream(System.out);
-
 
49
        antproject.addBuildListener(log);
-
 
50
        Vector listeners = antproject.getBuildListeners();
-
 
51
        for (Iterator i = listeners.iterator(); i.hasNext(); ) {
-
 
52
            BuildListener listener = (BuildListener) i.next();
-
 
53
 
-
 
54
            if (listener instanceof BuildLogger) {
-
 
55
                BuildLogger logger = (BuildLogger) listener;
-
 
56
                logger.setMessageOutputLevel(Echo.EchoLevel.VERBOSE.getLevel());
-
 
57
                logger.setOutputPrintStream(System.out);
-
 
Line 58... Line 55...
58
                logger.setErrorPrintStream(System.err);
55
        log.setMessageOutputLevel(Echo.EchoLevel.VERBOSE.getLevel());
59
            }
56
 
60
        }
57
        antproject.addBuildListener(log);
61
 
58
        
Line 80... Line 77...
80
    public Map<String, String> postTask()
77
    public Map<String, String> postTask()
81
            throws BuildException
78
            throws BuildException
82
        {
79
        {
83
        try {
80
        try {
84
        antproject.executeTarget(anttarget.getName());
81
        antproject.executeTarget(anttarget.getName());
85
        //anttask.execute();
-
 
86
        return antproject.getProperties();
-
 
87
        } catch (Exception ex) {
82
        } catch (Exception ex) {
88
            throw new BuildException(ex);
83
            new PrintStream(err).println(ex.getMessage());
89
        }
84
        }
-
 
85
        Map<String, String> map = antproject.getProperties();
-
 
86
        map.put("System.stdOut", out.toString());
-
 
87
        map.put("System.stdErr", err.toString());
-
 
88
        //anttask.execute();
-
 
89
        return map;
-
 
90
        
90
    }
91
    }
91
}
92
}