16,6 → 16,8 |
|
package net.brutex.xservices.util; |
|
import java.io.ByteArrayOutputStream; |
import java.io.PrintStream; |
import java.util.Iterator; |
import java.util.Map; |
import java.util.Vector; |
22,10 → 24,10 |
import org.apache.tools.ant.BuildException; |
import org.apache.tools.ant.BuildListener; |
import org.apache.tools.ant.BuildLogger; |
import org.apache.tools.ant.DefaultLogger; |
import org.apache.tools.ant.Project; |
import org.apache.tools.ant.Target; |
import org.apache.tools.ant.Task; |
import org.apache.tools.ant.listener.TimestampedLogger; |
import org.apache.tools.ant.taskdefs.Echo; |
|
/** |
38,27 → 40,22 |
Target anttarget; |
Task anttask; |
|
ByteArrayOutputStream out = new ByteArrayOutputStream(); |
ByteArrayOutputStream err = new ByteArrayOutputStream(); |
TimestampedLogger log = null; |
|
public RunTask(Task anttask) { |
|
antproject = new Project(); |
antproject.init(); |
antproject.setBasedir(System.getProperty("java.io.tmpdir")); |
DefaultLogger log = new DefaultLogger(); |
log.setErrorPrintStream(System.err); |
log.setOutputPrintStream(System.out); |
log = new TimestampedLogger(); |
log.setOutputPrintStream(new PrintStream(out)); |
log.setErrorPrintStream(new PrintStream(err)); |
log.setMessageOutputLevel(Echo.EchoLevel.VERBOSE.getLevel()); |
|
antproject.addBuildListener(log); |
Vector listeners = antproject.getBuildListeners(); |
for (Iterator i = listeners.iterator(); i.hasNext(); ) { |
BuildListener listener = (BuildListener) i.next(); |
|
if (listener instanceof BuildLogger) { |
BuildLogger logger = (BuildLogger) listener; |
logger.setMessageOutputLevel(Echo.EchoLevel.VERBOSE.getLevel()); |
logger.setOutputPrintStream(System.out); |
logger.setErrorPrintStream(System.err); |
} |
} |
|
|
anttarget = new Target(); |
anttarget.setName("XBridgeNGDynamicTarget"); |
anttarget.setProject(antproject); |
82,10 → 79,14 |
{ |
try { |
antproject.executeTarget(anttarget.getName()); |
//anttask.execute(); |
return antproject.getProperties(); |
} catch (Exception ex) { |
throw new BuildException(ex); |
new PrintStream(err).println(ex.getMessage()); |
} |
Map<String, String> map = antproject.getProperties(); |
map.put("System.stdOut", out.toString()); |
map.put("System.stdErr", err.toString()); |
//anttask.execute(); |
return map; |
|
} |
} |