Subversion Repositories XServices

Compare Revisions

Regard whitespace Rev 12 → Rev 11

/xservices/trunk/src/java/net/brutex/xservices/ws/ArchiveService.java
13,6 → 13,7
* See the License for the specific language governing permissions and
* limitations under the License.
*/
 
package net.brutex.xservices.ws;
 
import java.io.File;
49,6 → 50,7
public static final String WS_OPERATION_UNZIP = "unzip";
public static final String WS_OPERATION_GUNZIP = "gunzip";
public static final String WS_OPERATION_BUNZIP2 = "bunzip2";
 
public static final String WS_PARAM_SOURCEFILE = "source";
public static final String WS_PARAM_SOURCEFILE_STRING = "srcfile";
public static final String WS_PARAM_SOURCEURL = "srcurl";
55,6 → 57,7
public static final String WS_PARAM_SOURCEARCHIVE = "archivesource";
public static final String WS_PARAM_DESTFILE = "destfile";
public static final String WS_PARAM_DESTDIR = "destdir";
 
public static final String WS_PARAM_ENCODING = "encoding";
public static final String WS_PARAM_OVERWRITE = "overwrite";
 
71,19 → 74,19
}
 
@WebMethod(operationName = WS_OPERATION_GZIP, action = WS_OPERATION_GZIP)
public ReturnCode gzip(@WebParam(name = WS_PARAM_SOURCEFILE) FileResource src,
public String gzip(@WebParam(name = WS_PARAM_SOURCEFILE) FileResource src,
@WebParam(name = WS_PARAM_DESTFILE) String file) {
return gzip(src, new File(file));
}
 
@WebMethod(operationName = WS_OPERATION_GZIP_ARCHIVE, action = WS_OPERATION_GZIP_ARCHIVE)
public ReturnCode gzipFromArchive(@WebParam(name = WS_PARAM_SOURCEARCHIVE) ArchiveResource src,
public String gzipFromArchive(@WebParam(name = WS_PARAM_SOURCEARCHIVE) ArchiveResource src,
@WebParam(name = WS_PARAM_DESTFILE) String file) {
return gzip(src, new File(file));
}
 
@WebMethod(operationName = WS_OPERATION_GUNZIP, action = WS_OPERATION_GUNZIP)
public ReturnCode gunzip(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src,
public String gunzip(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src,
@WebParam(name = WS_PARAM_DESTDIR) String dest) {
File target = null;
if (!dest.equals("") && dest != null) {
93,7 → 96,7
}
 
@WebMethod(operationName = WS_OPERATION_BUNZIP2)
public ReturnCode bunzip2(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src,
public String bunzip2(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src,
@WebParam(name = WS_PARAM_DESTDIR) String dest) {
File target = null;
if (!dest.equals("") && dest != null) {
103,7 → 106,7
}
 
@WebMethod(operationName = "gunzipFromURL")
public ReturnCode gunzipFromURL(@WebParam(name = WS_PARAM_SOURCEURL) String src,
public String gunzipFromURL(@WebParam(name = WS_PARAM_SOURCEURL) String src,
@WebParam(name = WS_PARAM_DESTDIR) String dest) {
File target = null;
if (!dest.equals("") && dest != null) {
113,7 → 116,7
}
 
@WebMethod(operationName = "bunzip2FromURL")
public ReturnCode bunzip2FromURL(@WebParam(name = WS_PARAM_SOURCEURL) String src,
public String bunzip2FromURL(@WebParam(name = WS_PARAM_SOURCEURL) String src,
@WebParam(name = WS_PARAM_DESTDIR) String dest) {
File target = null;
if (!dest.equals("") && dest != null) {
123,7 → 126,7
}
 
@WebMethod(operationName = "zip")
public ReturnCode zip(@WebParam(name = WS_PARAM_SOURCEFILE) FileResource src,
public String zip(@WebParam(name = WS_PARAM_SOURCEFILE) FileResource src,
@WebParam(name = WS_PARAM_DESTFILE) String file,
@WebParam(name = WS_PARAM_OVERWRITE) boolean overwrite,
@WebParam(name = WS_PARAM_ENCODING) String encoding,
138,7 → 141,7
}
 
@WebMethod(operationName = "zipFromArchive")
public ReturnCode zipFromArchive(@WebParam(name = WS_PARAM_SOURCEARCHIVE) ArchiveResource src,
public String zipFromArchive(@WebParam(name = WS_PARAM_SOURCEARCHIVE) ArchiveResource src,
@WebParam(name = WS_PARAM_DESTFILE) String file,
@WebParam(name = WS_PARAM_OVERWRITE) boolean update,
@WebParam(name = WS_PARAM_ENCODING) String encoding,
146,8 → 149,9
return zip(src, new File(file), encoding, !update, level);
}
 
 
@WebMethod(operationName = "unzip")
public ReturnCode unzip(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src,
public String unzip(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src,
@WebParam(name = WS_PARAM_DESTDIR) String dest,
@WebParam(name = WS_PARAM_OVERWRITE) boolean overwrite,
@WebParam(name = WS_PARAM_ENCODING) String encoding) {
155,13 → 159,13
}
 
@WebMethod(operationName = "unrar")
public ReturnCode unrar(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src,
public String unrar(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src,
@WebParam(name = WS_PARAM_DESTDIR) String dest) {
return unrar(new File(src), new File(dest));
}
 
@WebMethod(operationName = "untar")
public ReturnCode untar(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src,
public String untar(@WebParam(name = WS_PARAM_SOURCEFILE_STRING) String src,
@WebParam(name = WS_PARAM_DESTDIR) String dest,
@WebParam(name = WS_PARAM_OVERWRITE) boolean overwrite,
@WebParam(name = "compression") CompressionType compression) {
191,11 → 195,12
bzip.setSrcResource(src.getAntResource(bzip.getProject()));
bzip.setDestfile(dst);
 
return runner.postTask();
Map<String, String> result = runner.postTask();
return new ReturnCode(0,result.get("System.stdOut"),result.get("System.stdErr"));
}
 
@WebMethod(exclude = true)
private ReturnCode gzip(ResourceInterface src, File dst) {
private String gzip(ResourceInterface src, File dst) {
if (dst.exists() && dst.isFile()) {
dst.delete();
}
204,11 → 209,14
RunTask runner = new RunTask(gzip);
gzip.addConfigured(src.getAntResource(gzip.getProject()));
gzip.setDestfile(dst);
return runner.postTask();
Map<String, String> result = runner.postTask();
return "complete";
}
 
 
 
@WebMethod(exclude = true)
private ReturnCode zip(ResourceInterface src, File dst, String encoding, boolean update, int compresslevel) {
private String zip(ResourceInterface src, File dst, String encoding, boolean update, int compresslevel) {
Zip zip = new Zip();
zip.setTaskName("Zip");
RunTask runner = new RunTask(zip);
219,11 → 227,12
}
zip.setUpdate(update);
zip.setLevel(compresslevel);
return runner.postTask();
Map<String, String> result = runner.postTask();
return "complete";
}
 
@WebMethod(exclude = true)
private ReturnCode GUnzip(ResourceInterface src, File dst) {
private String GUnzip(ResourceInterface src, File dst) {
GUnzip uz = new GUnzip();
uz.setTaskName("GUnzip");
RunTask runner = new RunTask(uz);
231,11 → 240,12
if (dst != null) {
uz.setDest(dst);
}
return runner.postTask();
Map<String, String> result = runner.postTask();
return "complete";
}
 
@WebMethod(exclude = true)
private ReturnCode BUnzip2(ResourceInterface src, File dst) {
private String BUnzip2(ResourceInterface src, File dst) {
BUnzip2 uz = new BUnzip2();
uz.setTaskName("BUnzip2");
RunTask runner = new RunTask(uz);
243,11 → 253,12
if (dst != null) {
uz.setDest(dst);
}
return runner.postTask();
Map<String, String> result = runner.postTask();
return "complete";
}
 
@WebMethod(exclude = true)
private ReturnCode unzip(File src, File dest, boolean overwrite, String encoding) {
private String unzip(File src, File dest, boolean overwrite, String encoding) {
Expand unzip = new Expand();
unzip.setTaskName("UnZip");
RunTask runner = new RunTask(unzip);
257,11 → 268,13
if (encoding != null && !encoding.equals("")) {
unzip.setEncoding(encoding);
}
return runner.postTask();
 
Map<String, String> result = runner.postTask();
return "complete";
}
 
@WebMethod(exclude = true)
private ReturnCode untar(File src, File dest, boolean overwrite, Untar.UntarCompressionMethod compression) {
private String untar(File src, File dest, boolean overwrite, Untar.UntarCompressionMethod compression) {
Untar unzip = new Untar();
unzip.setTaskName("Untar");
RunTask runner = new RunTask(unzip);
269,16 → 282,20
unzip.setDest(dest);
unzip.setOverwrite(overwrite);
unzip.setCompression(compression);
return runner.postTask();
Map<String, String> result = runner.postTask();
return "complete";
}
 
@WebMethod(exclude = true)
private ReturnCode unrar(File src, File dst) {
private String unrar(File src, File dst) {
UnRarTask unrar = new UnRarTask();
unrar.setTaskName("UnRar");
RunTask runner = new RunTask(unrar);
unrar.setSrc(src);
unrar.setDst(dst);
return runner.postTask();
Map<String, String> result = runner.postTask();
return "complete";
}
 
}
/xservices/trunk/src/java/net/brutex/xservices/ws/FileService.java
13,9 → 13,11
* See the License for the specific language governing permissions and
* limitations under the License.
*/
 
package net.brutex.xservices.ws;
 
import java.io.File;
import java.util.Map;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
23,14 → 25,11
import net.brutex.xservices.types.FileResource;
import net.brutex.xservices.types.FileSetResource;
import net.brutex.xservices.types.ResourceInterface;
import net.brutex.xservices.types.ReturnCode;
import net.brutex.xservices.util.RunTask;
import org.apache.tools.ant.taskdefs.Basename;
import org.apache.tools.ant.taskdefs.Copy;
import org.apache.tools.ant.taskdefs.Echo;
import org.apache.tools.ant.taskdefs.LoadResource;
import org.apache.tools.ant.taskdefs.optional.unix.Chgrp;
import org.apache.tools.ant.taskdefs.optional.unix.Chown;
import org.apache.tools.ant.types.FileSet;
 
/**
41,23 → 40,27
public class FileService {
 
@WebMethod(operationName = "basename")
public ReturnCode basename(@WebParam(name = "file") String filename,
public String basename(@WebParam(name = "file") String filename,
@WebParam(name = "suffix") String suffix) {
return basename(new File(filename), suffix);
}
 
@WebMethod(operationName = "copy")
public ReturnCode copy(@WebParam(name = "fileset") FileSetResource src,
public void copy(@WebParam(name="fileset") FileSetResource src,
@WebParam(name = "todir") String todir,
@WebParam(name = "preservelastmodified") boolean plm,
@WebParam(name = "overwrite") boolean overwrite,
@WebParam(name = "encoding") String encoding)
throws XServicesFault {
return copy(src, new File(todir), plm, overwrite, encoding);
try {
copy(src, new File(todir), plm, overwrite, encoding);
} catch (Exception ex) {
throw new XServicesFault(ex.getMessage(), ex);
}
}
 
@WebMethod(operationName = "loadResource")
public ReturnCode loadRes(@WebParam(name = "resource") FileResource res,
public String loadRes(@WebParam(name = "resource") FileResource res,
@WebParam(name = "encoding") String encoding) {
if (encoding == null || encoding.equals("")) {
encoding = System.getProperty("file.encoding");
66,7 → 69,7
}
 
@WebMethod(operationName = "loadResourceFromArchive")
public ReturnCode loadResFromArchive(@WebParam(name = "archiveresource") ArchiveResource res,
public String loadResFromArchive(@WebParam(name = "archiveresource") ArchiveResource res,
@WebParam(name = "encoding") String encoding) {
if (encoding == null || encoding.equals("")) {
encoding = System.getProperty("file.encoding");
75,26 → 78,14
}
 
@WebMethod(operationName = "echoToFile")
public ReturnCode echo2file(@WebParam(name = "message") String message,
public String echo2file(@WebParam(name="message") String message,
@WebParam(name = "file") String file, @WebParam(name = "encoding") String encoding,
@WebParam(name = "append") boolean append) {
return echo(message, new File(file), encoding, append);
}
 
@WebMethod(operationName = "changeOwner")
public ReturnCode changeOwner(@WebParam(name = "fileset") FileSetResource res,
@WebParam(name = "owner") String owner) {
return chown(res, owner);
}
 
@WebMethod(operationName = "changeGroup")
public ReturnCode changeGroup(@WebParam(name = "fileset") FileSetResource res,
@WebParam(name = "group") String group) {
return chgrp(res, group);
}
 
@WebMethod(exclude = true)
private ReturnCode basename(File file,
private String basename(File file,
String suffix) {
Basename basename = new Basename();
RunTask runner = new RunTask(basename);
103,11 → 94,11
basename.setSuffix(suffix);
}
basename.setProperty("basename.value");
return runner.postTask();
Map<String, String> result = runner.postTask();
return result.get("basename.value");
}
 
@WebMethod(exclude = true)
private ReturnCode loadResource(ResourceInterface src, String encoding) {
private String loadResource(ResourceInterface src, String encoding) {
LoadResource lr = new LoadResource();
lr.setTaskName("LoadResource");
RunTask runner = new RunTask(lr);
115,11 → 106,12
lr.setEncoding(encoding);
System.out.println("Using encoding: " + encoding);
lr.setProperty("LoadResource.out");
return runner.postTask();
Map<String, String> result = runner.postTask();
return result.get("LoadResource.out");
}
 
@WebMethod(exclude = true)
private ReturnCode echo(String msg, File file, String encoding, boolean append) {
private String echo(String msg, File file, String encoding, boolean append) {
Echo echo = new Echo();
echo.setTaskName("toFile");
RunTask runTask = new RunTask(echo);
127,11 → 119,12
echo.setEncoding(encoding);
echo.setFile(file);
echo.setAppend(append);
return runTask.postTask();
Map<String, String> result = runTask.postTask();
return "complete";
}
 
@WebMethod(exclude = true)
private ReturnCode copy(FileSetResource src, File dst, boolean preservelastmodified,
private void copy(FileSetResource src, File dst, boolean preservelastmodified,
boolean overwrite, String encoding) {
Copy copy = new Copy();
copy.setTaskName("Copy");
139,12 → 132,8
FileSet set = src.getAntFileSet(copy.getProject());
copy.add(set);
 
if (dst.isDirectory()) {
copy.setTodir(dst);
}
if (dst.isFile()) {
copy.setTofile(dst);
}
if(dst.isDirectory()) copy.setTodir(dst);
if(dst.isFile()) copy.setTofile(dst);
copy.setOverwrite(overwrite);
copy.setPreserveLastModified(preservelastmodified);
if (encoding != null && !encoding.equals("")) {
153,28 → 142,6
copy.setOutputEncoding(System.getProperty("file.encoding"));
}
 
return runner.postTask();
Map<String, String> result = runner.postTask();
}
 
@WebMethod(exclude = true)
private ReturnCode chown(FileSetResource src, String owner) {
Chown chown = new Chown();
chown.setTaskName("Chown");
RunTask runner = new RunTask(chown);
chown.setOwner(owner);
FileSet set = src.getAntFileSet(chown.getProject());
chown.add(set);
return runner.postTask();
}
 
@WebMethod(exclude = true)
private ReturnCode chgrp(FileSetResource src, String group) {
Chgrp chgrp = new Chgrp();
chgrp.setTaskName("Chgrp");
RunTask runner = new RunTask(chgrp);
chgrp.setGroup(group);
FileSet set = src.getAntFileSet(chgrp.getProject());
chgrp.add(set);
return runner.postTask();
}
}
/xservices/trunk/src/java/net/brutex/xservices/ws/ExecuteService.java
155,19 → 155,11
long timeout) {
ExecTask exe = new ExecTask();
RunTask runner = new RunTask(exe);
 
/*
Commandline cmdl = new Commandline();
cmdl.setExecutable(executable);
cmdl.addArguments(args);
System.out.println(cmdl.describeCommand());
*/
exe.setExecutable(executable);
for (String s : args) {
exe.createArg().setValue(s);
}
 
exe.setCommand(cmdl);
exe.setDir(dir);
if (spawn) {
exe.setSpawn(spawn);
183,8 → 175,16
exe.setVMLauncher(vmlauncher);
exe.setSearchPath(searchpath);
 
return runner.postTask();
Map<String, String> result = runner.postTask();
ReturnCode res = null;
if (spawn) {
res = new ReturnCode(0, null, null);
} else {
res = new ReturnCode(Integer.valueOf(result.get("ExecuteService.result")),
result.get("ExecuteService.stdout"), result.get("ExecuteService.stderr"));
}
return res;
}
 
@WebMethod(exclude = true)
private ReturnCode sshExec(String host,
203,7 → 203,12
sshexec.setTrust(true);
sshexec.setTimeout(timeout);
sshexec.setOutputproperty("SSHExec.stdout");
return runner.postTask();
Map<String, String> result = runner.postTask();
ReturnCode res = null;
res = new ReturnCode(0,
result.get("SSHExec.stdout"), "");
 
return res;
}
 
@WebMethod(exclude = true)
225,7 → 230,12
sshexec.setTrust(true);
sshexec.setTimeout(timeout);
sshexec.setOutputproperty("SSHExec.stdout");
return runner.postTask();
Map<String, String> result = runner.postTask();
ReturnCode res = null;
res = new ReturnCode(0,
result.get("SSHExec.stdout"), "");
 
return res;
}
 
@WebMethod(exclude = true)
244,7 → 254,12
rexec.setCommand(command);
rexec.setTimeout((int) Math.round(timeout));
 
return runner.postTask();
Map<String, String> result = runner.postTask();
ReturnCode res = null;
res = new ReturnCode(0,
"", "");
 
return res;
}
 
@WebMethod(exclude = true)
266,6 → 281,10
rexec.createWrite().addText(command);
rexec.createRead().addText(expect);
 
return runner.postTask();
Map<String, String> result = runner.postTask();
ReturnCode res = null;
res = new ReturnCode(0,
"", "");
return res;
}
}
/xservices/trunk/src/java/net/brutex/xservices/util/RunTask.java
13,15 → 13,17
* 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.Iterator;
import java.util.Map;
import net.brutex.xservices.types.AntProperty;
import net.brutex.xservices.types.ReturnCode;
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.Project;
import org.apache.tools.ant.Target;
import org.apache.tools.ant.Task;
37,6 → 39,7
Project antproject;
Target anttarget;
Task anttask;
 
ByteArrayOutputStream out = new ByteArrayOutputStream();
ByteArrayOutputStream err = new ByteArrayOutputStream();
TimestampedLogger log = null;
71,28 → 74,19
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());
public Map<String, String> postTask()
throws BuildException
{
try {
antproject.executeTarget(anttarget.getName());
} catch (BuildException ex) {
} catch (Exception ex) {
new PrintStream(err).println(ex.getMessage());
returnCode = 1;
}
newMap = antproject.getProperties();
 
for (Map.Entry<String, String> e : origMap.entrySet()) {
newMap.remove(e.getKey());
}
 
Map<String, String> map = antproject.getProperties();
map.put("System.stdOut", out.toString());
map.put("System.stdErr", err.toString());
//anttask.execute();
return new ReturnCode(returnCode,
out.toString(),
err.toString(),
AntProperty.createAntPropertyList(newMap));
return map;
 
}
}
/xservices/trunk/src/java/net/brutex/xservices/types/AntProperty.java
File deleted
/xservices/trunk/src/java/net/brutex/xservices/types/ReturnCode.java
16,7 → 16,6
 
package net.brutex.xservices.types;
 
import java.util.List;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
import net.brutex.xservices.util.BrutexNamespaces;
56,10 → 55,6
@XmlElement(name="stdErr", nillable=false)
public String stdErr="";
 
 
@XmlElement(name="propertyList", nillable=true)
public List<AntProperty> property = null;
 
/**
* Create a new ReturnCode default constructor.
*/
73,10 → 68,9
* @param stdOut standard out string
* @param stdErr standard error string
*/
public ReturnCode(int returnCode, String stdOut, String stdErr, List<AntProperty> props) {
public ReturnCode(int returnCode, String stdOut, String stdErr) {
this.returnCode = returnCode;
this.stdOut = stdOut;
this.stdErr = stdErr;
this.property = props;
}
}