目前编译环境是
[maven3@inc-platform-dev-144-9 hudson-2.0.1_win]$ mvn -v
Apache Maven 3.0.3 (r1075438; 2011-03-01 01:31:09+0800)
Maven home: /home/maven3/apache-maven-3.0.3
Java version: 1.6.0_25, vendor: Sun Microsystems Inc.
Java home: /usr/alibaba/install/jdk1.6.0_25/jre
Default locale: en_US, platform. encoding: ISO-8859-1
一)hudson.maven.agent.Main
增加callShell函数的2个版本。
//see http://www.devdaily.com/java/java-exec-processbuilder-process-2
//fixedexeclinuxshell hang
//多线程版
privatestaticint callShell_mt(String cmd)throwsIOException,
InterruptedException {
List commands =newArrayList();
System.out
.print(" ***warning!only support shell!callShell start byliangjz.*** ");
commands.add("/bin/sh");
commands.add("-c");
commands.add(cmd);
SystemCommandExecutor commandExecutor =newSystemCommandExecutor(commands);
intshellExitStatus = commandExecutor.executeCommand();
//stdoutandstderrof the command are returned as StringBuilder objects
StringBuilder stdout = commandExecutor.getStandardOutputFromCommand();
System.out.println("The numeric result of the command was: "+ shellExitStatus);
System.out.println(stdout);
returnshellExitStatus;
}
privatestaticintcallShell(String cmd)throwsIOException,
InterruptedException{
List commands =newArrayList();
System.out
.print(" ***warning!support shell!may be waiting long time ,please!!callShell start byliangjz.*** ");
commands.add("/bin/sh");
commands.add("-c");
commands.add(cmd);
ProcessBuilder pb =newProcessBuilder(commands);
pb.redirectErrorStream(true);// use this to capture messages sent to
//stderr
Process shell = pb.start();
InputStream shellIn = shell.getInputStream();// this captures the
// output from the
// command
intshellExitStatus = shell.waitFor();// wait for the shell to finish
// and get the return code
// at this point you can process the output issued by the command
// for instance, this reads the output and writes it to System.out:
intc;
while((c = shellIn.read()) != -1) {
System.out.write(c);
}
// close the stream
try{
shellIn.close();
}catch(IOException ignoreMe) {
}
System.out.print(" *** callShell End byliangjz,return "+ shellExitStatus);
returnshellExitStatus;
}
//launch根据mvn命令行传递入的参数才触发调用外部shell.
publicstaticintlaunch(String[] args)throwsNoSuchMethodException,
IllegalAccessException, NoSuchRealmException,
InvocationTargetException, ClassNotFoundException {
// ClassWorld world = ClassWorldAdapter.getInstance( launcher.getWorld()
// );
ClassWorld world =launcher.getWorld();
Set builtinRealms =newHashSet(world.getRealms());
booleancallShell =false;
intcallShellRet=-1;
try{
System.out.println("----- hudson.maven.agent.Main.launch start by liangjz----");
String libs =null;
String workspace=null;
String apps=null;
String crid="0";
StringBuilder sb=newStringBuilder();
sb.append("'");
for(inti = 0; i < args.length; i++) {
//System.out.println("arg" + i + "=" +args[i]);
if(args[i].startsWith("-DlibsOrder")) {
String[] tmpArr = args[i].split("=");
if(tmpArr.length== 2) {
callShell =true;
libs = tmpArr[1];
}
}elseif(args[i].startsWith("-Dapps")){
String[] tmpArr = args[i].split("=");
if(tmpArr.length== 2) {
apps = tmpArr[1];
}
}elseif(args[i].startsWith("-DWORKSPACE")){
String[] tmpArr = args[i].split("=");
if(tmpArr.length