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;
|
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,26 +40,21 @@ 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));
|
||||||
antproject.addBuildListener(log);
|
log.setMessageOutputLevel(Echo.EchoLevel.VERBOSE.getLevel());
|
||||||
Vector listeners = antproject.getBuildListeners();
|
|
||||||
for (Iterator i = listeners.iterator(); i.hasNext(); ) {
|
|
||||||
BuildListener listener = (BuildListener) i.next();
|
|
||||||
|
|
||||||
if (listener instanceof BuildLogger) {
|
antproject.addBuildListener(log);
|
||||||
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");
|
||||||
|
@ -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;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue