/xservices/trunk/src/java/net/brutex/xservices/util/RunTask.java |
---|
0,0 → 1,98 |
/* |
* Copyright 2010 Brian Rosenberger (Brutex Network) |
* |
* Licensed under the Apache License, Version 2.0 (the "License"); |
* you may not use this file except in compliance with the License. |
* You may obtain a copy of the License at |
* |
* http://www.apache.org/licenses/LICENSE-2.0 |
* |
* Unless required by applicable law or agreed to in writing, software |
* distributed under the License is distributed on an "AS IS" BASIS, |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
* 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.HashMap; |
import java.util.Map; |
import net.brutex.xservices.types.AntProperty; |
import net.brutex.xservices.types.ReturnCode; |
import org.apache.tools.ant.BuildException; |
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; |
/** |
* |
* @author Brian Rosenberger, bru@brutex.de |
*/ |
public class RunTask { |
Project antproject; |
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")); |
log = new TimestampedLogger(); |
log.setOutputPrintStream(new PrintStream(out)); |
log.setErrorPrintStream(new PrintStream(err)); |
log.setMessageOutputLevel(Echo.EchoLevel.VERBOSE.getLevel()); |
antproject.addBuildListener(log); |
anttarget = new Target(); |
anttarget.setName("XBridgeNGDynamicTarget"); |
anttarget.setProject(antproject); |
antproject.addTarget(anttarget); |
this.anttask = anttask; |
prepareTask(); |
} |
private void prepareTask() |
throws BuildException { |
anttask.init(); |
anttask.setProject(antproject); |
anttask.setOwningTarget(anttarget); |
anttarget.addTask(anttask); |
antproject.addOrReplaceTarget(anttarget); |
} |
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 (BuildException ex) { |
new PrintStream(err).println(ex.getMessage()); |
returnCode = 1; |
} |
newMap = antproject.getProperties(); |
for (Map.Entry<String, String> e : origMap.entrySet()) { |
newMap.remove(e.getKey()); |
} |
//anttask.execute(); |
return new ReturnCode(returnCode, |
out.toString(), |
err.toString(), |
AntProperty.createAntPropertyList(newMap)); |
} |
} |
/xservices/trunk/src/java/net/brutex/xservices/util/BrutexNamespaces.java |
---|
0,0 → 1,35 |
/* |
* Copyright 2010 Brian Rosenberger (Brutex Network) |
* |
* Licensed under the Apache License, Version 2.0 (the "License"); |
* you may not use this file except in compliance with the License. |
* You may obtain a copy of the License at |
* |
* http://www.apache.org/licenses/LICENSE-2.0 |
* |
* Unless required by applicable law or agreed to in writing, software |
* distributed under the License is distributed on an "AS IS" BASIS, |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
* See the License for the specific language governing permissions and |
* limitations under the License. |
*/ |
package net.brutex.xservices.util; |
/** |
* Holds static namespace information. |
* |
* |
* @author Brian Rosenberger, bru@brutex.de |
*/ |
public class BrutexNamespaces { |
/** |
* Brutex Network XServices web service namespace declaration |
*/ |
public static final String WS_XSERVICES = "http://ws.xservices.brutex.net"; |
private BrutexNamespaces() {}; |
} |
/xservices/trunk/src/java/net/brutex/xservices/util/UnRarTask.java |
---|
0,0 → 1,74 |
/* |
* Copyright 2010 Brian Rosenberger (Brutex Network) |
* |
* Licensed under the Apache License, Version 2.0 (the "License"); |
* you may not use this file except in compliance with the License. |
* You may obtain a copy of the License at |
* |
* http://www.apache.org/licenses/LICENSE-2.0 |
* |
* Unless required by applicable law or agreed to in writing, software |
* distributed under the License is distributed on an "AS IS" BASIS, |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
* See the License for the specific language governing permissions and |
* limitations under the License. |
*/ |
package net.brutex.xservices.util; |
import de.innosystec.unrar.Archive; |
import de.innosystec.unrar.exception.RarException; |
import de.innosystec.unrar.rarfile.FileHeader; |
import java.io.File; |
import java.io.FileOutputStream; |
import java.io.IOException; |
import java.util.List; |
import org.apache.tools.ant.BuildException; |
import org.apache.tools.ant.Task; |
/** |
* |
* @author Brian Rosenberger, bru@brutex.de |
*/ |
public class UnRarTask extends Task { |
private File dst = null; |
private File src = null; |
public File getDst() { |
return dst; |
} |
public void setDst(File dst) { |
this.dst = dst; |
} |
public File getSrc() { |
return src; |
} |
public void setSrc(File src) { |
this.src = src; |
} |
@Override |
public void execute() { |
if(src==null ) throw new BuildException("Please supply a source archive file."); |
if(!src.exists()) throw new BuildException("Archive '"+src.getName()+"' does not exist."); |
try { |
if(dst==null) dst = new File(src.getParent()); |
Archive ar = new Archive(src); |
List<FileHeader> list = ar.getFileHeaders(); |
for(FileHeader h : list) { |
ar.extractFile(h, new FileOutputStream(new File(dst.getAbsolutePath()+"/"+h.getFileNameString()))); |
} |
} catch (RarException ex) { |
throw new BuildException(ex.getMessage(), ex); |
} catch (IOException ex) { |
throw new BuildException(ex.getMessage(), ex); |
} |
} |
} |