Subversion Repositories XServices

Compare Revisions

Ignore whitespace Rev 11 → Rev 12

/xservices/trunk/src/java/net/brutex/xservices/util/RunTask.java
13,17 → 13,15
* See the License for the specific language governing permissions and
* limitations under the License.
*/
 
package net.brutex.xservices.util;
 
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.Iterator;
import java.util.HashMap;
import java.util.Map;
import java.util.Vector;
import net.brutex.xservices.types.AntProperty;
import net.brutex.xservices.types.ReturnCode;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.BuildListener;
import org.apache.tools.ant.BuildLogger;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.Target;
import org.apache.tools.ant.Task;
39,7 → 37,6
Project antproject;
Target anttarget;
Task anttask;
 
ByteArrayOutputStream out = new ByteArrayOutputStream();
ByteArrayOutputStream err = new ByteArrayOutputStream();
TimestampedLogger log = null;
55,7 → 52,7
log.setMessageOutputLevel(Echo.EchoLevel.VERBOSE.getLevel());
 
antproject.addBuildListener(log);
 
anttarget = new Target();
anttarget.setName("XBridgeNGDynamicTarget");
anttarget.setProject(antproject);
67,26 → 64,35
 
private void prepareTask()
throws BuildException {
anttask.init();
anttask.setProject(antproject);
anttask.setOwningTarget(anttarget);
anttarget.addTask(anttask);
antproject.addOrReplaceTarget(anttarget);
anttask.init();
anttask.setProject(antproject);
anttask.setOwningTarget(anttarget);
anttarget.addTask(anttask);
antproject.addOrReplaceTarget(anttarget);
}
 
public Map<String, String> postTask()
throws BuildException
{
public ReturnCode postTask() {
int returnCode = 0;
Map<String, String> origMap = new HashMap<String, String>();
Map<String, String> newMap = null;
origMap.putAll(antproject.getProperties());
try {
antproject.executeTarget(anttarget.getName());
} catch (Exception ex) {
antproject.executeTarget(anttarget.getName());
} catch (BuildException ex) {
new PrintStream(err).println(ex.getMessage());
returnCode = 1;
}
Map<String, String> map = antproject.getProperties();
map.put("System.stdOut", out.toString());
map.put("System.stdErr", err.toString());
newMap = antproject.getProperties();
 
for (Map.Entry<String, String> e : origMap.entrySet()) {
newMap.remove(e.getKey());
}
 
//anttask.execute();
return map;
return new ReturnCode(returnCode,
out.toString(),
err.toString(),
AntProperty.createAntPropertyList(newMap));
 
}
}