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; package net.brutex.xservices.util;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Vector; import java.util.Vector;
import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.BuildListener; import org.apache.tools.ant.BuildListener;
import org.apache.tools.ant.BuildLogger; import org.apache.tools.ant.BuildLogger;
import org.apache.tools.ant.DefaultLogger;
import org.apache.tools.ant.Project; import org.apache.tools.ant.Project;
import org.apache.tools.ant.Target; import org.apache.tools.ant.Target;
import org.apache.tools.ant.Task; import org.apache.tools.ant.Task;
import org.apache.tools.ant.listener.TimestampedLogger;
import org.apache.tools.ant.taskdefs.Echo; import org.apache.tools.ant.taskdefs.Echo;
/** /**
@ -38,27 +40,22 @@ public class RunTask {
Target anttarget; Target anttarget;
Task anttask; Task anttask;
ByteArrayOutputStream out = new ByteArrayOutputStream();
ByteArrayOutputStream err = new ByteArrayOutputStream();
TimestampedLogger log = null;
public RunTask(Task anttask) { public RunTask(Task anttask) {
antproject = new Project(); antproject = new Project();
antproject.init(); antproject.init();
antproject.setBasedir(System.getProperty("java.io.tmpdir")); antproject.setBasedir(System.getProperty("java.io.tmpdir"));
DefaultLogger log = new DefaultLogger(); log = new TimestampedLogger();
log.setErrorPrintStream(System.err); log.setOutputPrintStream(new PrintStream(out));
log.setOutputPrintStream(System.out); log.setErrorPrintStream(new PrintStream(err));
log.setMessageOutputLevel(Echo.EchoLevel.VERBOSE.getLevel());
antproject.addBuildListener(log); 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 = new Target();
anttarget.setName("XBridgeNGDynamicTarget"); anttarget.setName("XBridgeNGDynamicTarget");
anttarget.setProject(antproject); anttarget.setProject(antproject);
@ -82,10 +79,14 @@ public class RunTask {
{ {
try { try {
antproject.executeTarget(anttarget.getName()); antproject.executeTarget(anttarget.getName());
//anttask.execute();
return antproject.getProperties();
} catch (Exception ex) { } 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); bzip.setDestfile(dst);
Map<String, String> result = runner.postTask(); 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) @WebMethod(exclude = true)