Alternate suggestion to return success/ failure for ArchiveServices
git-svn-id: https://brutex.net/svn/xservices/trunk@11 e7e49efb-446e-492e-b9ec-fcafc1997a86tag-20130205r
parent
f25e3d4af9
commit
f38a378f68
Binary file not shown.
|
@ -16,16 +16,18 @@
|
|||
|
||||
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;
|
||||
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 @@ public class RunTask {
|
|||
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 @@ public class RunTask {
|
|||
{
|
||||
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;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -196,7 +196,7 @@ public class ArchiveService {
|
|||
bzip.setDestfile(dst);
|
||||
|
||||
Map<String, String> result = runner.postTask();
|
||||
return new ReturnCode(0,"complete","");
|
||||
return new ReturnCode(0,result.get("System.stdOut"),result.get("System.stdErr"));
|
||||
}
|
||||
|
||||
@WebMethod(exclude = true)
|
||||
|
|
Loading…
Reference in New Issue