Alternate suggestion to return success/ failure for ArchiveServices

git-svn-id: https://brutex.net/svn/xservices/trunk@11 e7e49efb-446e-492e-b9ec-fcafc1997a86
tag-20130205r
Brian Rosenberger 2010-01-29 12:49:45 +00:00
parent f25e3d4af9
commit f38a378f68
3 changed files with 21 additions and 20 deletions

Binary file not shown.

View File

@ -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,26 +40,21 @@ 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);
antproject.addBuildListener(log);
Vector listeners = antproject.getBuildListeners();
for (Iterator i = listeners.iterator(); i.hasNext(); ) {
BuildListener listener = (BuildListener) i.next();
log = new TimestampedLogger();
log.setOutputPrintStream(new PrintStream(out));
log.setErrorPrintStream(new PrintStream(err));
log.setMessageOutputLevel(Echo.EchoLevel.VERBOSE.getLevel());
if (listener instanceof BuildLogger) {
BuildLogger logger = (BuildLogger) listener;
logger.setMessageOutputLevel(Echo.EchoLevel.VERBOSE.getLevel());
logger.setOutputPrintStream(System.out);
logger.setErrorPrintStream(System.err);
}
}
antproject.addBuildListener(log);
anttarget = new Target();
anttarget.setName("XBridgeNGDynamicTarget");
@ -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;
}
}

View File

@ -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)