mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-16 05:22:22 +00:00
removed unnecessary code duplication between MavenProcessFactory and Maven3ProcessFactory
This commit is contained in:
1 parent
32f36fef51
commit
5acad66d68
3 files changed
+127
-164
No files matched your search
@@ -15,6 +15,7 @@ import hudson.model.Executor;
|
||||
import hudson.model.JDK;
|
||||
import hudson.model.Node;
|
||||
import hudson.model.TaskListener;
|
||||
import hudson.model.Run.RunnerAbortedException;
|
||||
import hudson.remoting.Callable;
|
||||
import hudson.remoting.Channel;
|
||||
import hudson.remoting.RemoteInputStream;
|
||||
@@ -38,6 +39,9 @@ import java.net.SocketTimeoutException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.UnsupportedCharsetException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import jenkins.model.Jenkins;
|
||||
|
||||
import org.kohsuke.stapler.framework.io.IOException2;
|
||||
|
||||
/*
|
||||
@@ -248,10 +252,76 @@ public abstract class AbstractMavenProcessFactory
|
||||
|
||||
/**
|
||||
* Builds the command line argument list to launch the maven process.
|
||||
*
|
||||
*/
|
||||
protected abstract ArgumentListBuilder buildMavenAgentCmdLine(BuildListener listener,int tcpPort)
|
||||
throws IOException, InterruptedException;
|
||||
protected ArgumentListBuilder buildMavenAgentCmdLine(BuildListener listener,int tcpPort) throws IOException, InterruptedException {
|
||||
MavenInstallation mvn = getMavenInstallation(listener);
|
||||
if(mvn==null) {
|
||||
listener.error("Maven version is not configured for this project. Can't determine which Maven to run");
|
||||
throw new RunnerAbortedException();
|
||||
}
|
||||
if(mvn.getHome()==null) {
|
||||
listener.error("Maven '%s' doesn't have its home set",mvn.getName());
|
||||
throw new RunnerAbortedException();
|
||||
}
|
||||
|
||||
boolean isMaster = getCurrentNode()== Jenkins.getInstance();
|
||||
FilePath slaveRoot=null;
|
||||
if(!isMaster)
|
||||
slaveRoot = getCurrentNode().getRootPath();
|
||||
|
||||
ArgumentListBuilder args = new ArgumentListBuilder();
|
||||
JDK jdk = getJava(listener);
|
||||
if(jdk==null) {
|
||||
args.add("java");
|
||||
} else {
|
||||
args.add(jdk.getHome()+"/bin/java"); // use JDK.getExecutable() here ?
|
||||
}
|
||||
|
||||
if(debugPort!=0)
|
||||
args.add("-Xrunjdwp:transport=dt_socket,server=y,address="+debugPort);
|
||||
if(yjp)
|
||||
args.add("-agentlib:yjpagent=tracing");
|
||||
|
||||
args.addTokenized(getMavenOpts());
|
||||
|
||||
args.add( "-cp" );
|
||||
args.add(getMavenAgentClassPath(mvn,isMaster,slaveRoot,listener));
|
||||
args.add(getMainClassName());
|
||||
|
||||
// M2_HOME
|
||||
args.add(mvn.getHome());
|
||||
|
||||
// remoting.jar
|
||||
String remotingJar = getLauncher().getChannel().call(new GetRemotingJar());
|
||||
if(remotingJar==null) {// this shouldn't be possible, but there are still reports indicating this, so adding a probe here.
|
||||
listener.error("Failed to determine the location of slave.jar");
|
||||
throw new RunnerAbortedException();
|
||||
}
|
||||
args.add(remotingJar);
|
||||
|
||||
// interceptor.jar
|
||||
args.add(getMavenInterceptorClassPath(mvn,isMaster,slaveRoot));
|
||||
|
||||
// TCP/IP port to establish the remoting infrastructure
|
||||
args.add(tcpPort);
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the classpath string for the maven-agent jar including classworlds
|
||||
*/
|
||||
protected abstract String getMavenAgentClassPath(MavenInstallation mvn,boolean isMaster,FilePath slaveRoot,BuildListener listener) throws IOException, InterruptedException ;
|
||||
|
||||
/**
|
||||
* Returns the classpath string for the maven-interceptor jar
|
||||
*/
|
||||
protected abstract String getMavenInterceptorClassPath(MavenInstallation mvn,boolean isMaster,FilePath slaveRoot) throws IOException, InterruptedException ;
|
||||
|
||||
/**
|
||||
* Returns the name of the Maven main class.
|
||||
*/
|
||||
protected abstract String getMainClassName();
|
||||
|
||||
public String getMavenOpts() {
|
||||
if( this.mavenOpts != null )
|
||||
@@ -349,5 +419,19 @@ public abstract class AbstractMavenProcessFactory
|
||||
|
||||
public static final String MAVEN_REMOTE_USEINET_ENV_VAR_NAME = "MAVEN_REMOTE_USEINET";
|
||||
|
||||
/**
|
||||
* If true, launch Maven with YJP offline profiler agent.
|
||||
*/
|
||||
public static boolean yjp = Boolean.getBoolean("hudson.maven.yjp");
|
||||
|
||||
/**
|
||||
* If not 0, launch Maven with a debugger port.
|
||||
*/
|
||||
public static int debugPort;
|
||||
|
||||
static {
|
||||
String port = System.getProperty("hudson.maven.debugPort");
|
||||
if(port!=null)
|
||||
debugPort = Integer.parseInt(port);
|
||||
}
|
||||
}
|
||||
@@ -27,14 +27,11 @@ import hudson.EnvVars;
|
||||
import hudson.FilePath;
|
||||
import hudson.Launcher;
|
||||
import hudson.model.BuildListener;
|
||||
import jenkins.model.Jenkins;
|
||||
import hudson.model.JDK;
|
||||
import hudson.model.Run.RunnerAbortedException;
|
||||
import hudson.model.TaskListener;
|
||||
import hudson.remoting.Callable;
|
||||
import hudson.remoting.Which;
|
||||
import hudson.tasks.Maven.MavenInstallation;
|
||||
import hudson.util.ArgumentListBuilder;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
@@ -53,75 +50,32 @@ public class Maven3ProcessFactory extends AbstractMavenProcessFactory implements
|
||||
Maven3ProcessFactory(MavenModuleSet mms, Launcher launcher, EnvVars envVars, String mavenOpts, FilePath workDir) {
|
||||
super( mms, launcher, envVars, mavenOpts, workDir );
|
||||
}
|
||||
/**
|
||||
* Builds the command line argument list to launch the maven process.
|
||||
*
|
||||
*/
|
||||
protected ArgumentListBuilder buildMavenAgentCmdLine(BuildListener listener,int tcpPort) throws IOException, InterruptedException {
|
||||
MavenInstallation mvn = getMavenInstallation(listener);
|
||||
if(mvn==null) {
|
||||
listener.error("Maven version is not configured for this project. Can't determine which Maven to run");
|
||||
throw new RunnerAbortedException();
|
||||
}
|
||||
if(mvn.getHome()==null) {
|
||||
listener.error("Maven '%s' doesn't have its home set",mvn.getName());
|
||||
throw new RunnerAbortedException();
|
||||
}
|
||||
|
||||
// find classworlds.jar
|
||||
@Override
|
||||
protected String getMavenAgentClassPath(MavenInstallation mvn,boolean isMaster,FilePath slaveRoot,BuildListener listener) throws IOException, InterruptedException {
|
||||
String classWorldsJar = getLauncher().getChannel().call(new GetClassWorldsJar(mvn.getHome(),listener));
|
||||
|
||||
boolean isMaster = getCurrentNode()== Jenkins.getInstance();
|
||||
FilePath slaveRoot=null;
|
||||
if(!isMaster)
|
||||
slaveRoot = getCurrentNode().getRootPath();
|
||||
|
||||
ArgumentListBuilder args = new ArgumentListBuilder();
|
||||
JDK jdk = getJava(listener);
|
||||
if(jdk==null) {
|
||||
args.add("java");
|
||||
} else {
|
||||
args.add(jdk.getHome()+"/bin/java"); // use JDK.getExecutable() here ?
|
||||
}
|
||||
|
||||
if(MavenProcessFactory.debugPort!=0)
|
||||
args.add("-Xrunjdwp:transport=dt_socket,server=y,address="+MavenProcessFactory.debugPort);
|
||||
if(MavenProcessFactory.yjp)
|
||||
args.add("-agentlib:yjpagent=tracing");
|
||||
|
||||
args.addTokenized(getMavenOpts());
|
||||
|
||||
args.add("-cp");
|
||||
args.add(
|
||||
(isMaster? Which.jarFile(Maven3Main.class).getAbsolutePath():slaveRoot.child("maven3-agent.jar").getRemote())+
|
||||
(getLauncher().isUnix()?":":";")+classWorldsJar);
|
||||
args.add(Maven3Main.class.getName());
|
||||
|
||||
// M2_HOME
|
||||
args.add(mvn.getHome());
|
||||
|
||||
// remoting.jar
|
||||
String remotingJar = getLauncher().getChannel().call(new GetRemotingJar());
|
||||
if(remotingJar==null) {// this shouldn't be possible, but there are still reports indicating this, so adding a probe here.
|
||||
listener.error("Failed to determine the location of slave.jar");
|
||||
throw new RunnerAbortedException();
|
||||
}
|
||||
args.add(remotingJar);
|
||||
|
||||
args.add(isMaster?
|
||||
Which.jarFile(Maven3Launcher.class).getAbsolutePath():
|
||||
slaveRoot.child("maven3-interceptor.jar").getRemote());
|
||||
|
||||
// TCP/IP port to establish the remoting infrastructure
|
||||
args.add(tcpPort);
|
||||
|
||||
return args;
|
||||
return (isMaster? Which.jarFile(Maven3Main.class).getAbsolutePath():slaveRoot.child("maven3-agent.jar").getRemote())+
|
||||
(getLauncher().isUnix()?":":";")+classWorldsJar;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getMainClassName() {
|
||||
return Maven3Main.class.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getMavenInterceptorClassPath(MavenInstallation mvn,boolean isMaster,FilePath slaveRoot) throws IOException, InterruptedException {
|
||||
return isMaster?
|
||||
Which.jarFile(Maven3Launcher.class).getAbsolutePath():
|
||||
slaveRoot.child("maven3-interceptor.jar").getRemote();
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds classworlds.jar
|
||||
*/
|
||||
private static final class GetClassWorldsJar implements Callable<String,IOException> {
|
||||
private static final long serialVersionUID = -2599434124883557137L;
|
||||
private final String mvnHome;
|
||||
private final TaskListener listener;
|
||||
|
||||
@@ -137,15 +91,8 @@ public class Maven3ProcessFactory extends AbstractMavenProcessFactory implements
|
||||
File bootDir = new File(home, "boot");
|
||||
File[] classworlds = bootDir.listFiles(CLASSWORLDS_FILTER);
|
||||
if(classworlds==null || classworlds.length==0) {
|
||||
// Maven 2.0.6 puts it to a different place
|
||||
bootDir = new File(home, "boot");
|
||||
classworlds = bootDir.listFiles(CLASSWORLDS_FILTER);
|
||||
if(classworlds==null || classworlds.length==0) {
|
||||
// FIXME use messages
|
||||
//listener.error(Messages.MavenProcessFactory_ClassWorldsNotFound(home));
|
||||
listener.error("classworld not found");
|
||||
throw new RunnerAbortedException();
|
||||
}
|
||||
listener.error(Messages.MavenProcessFactory_ClassWorldsNotFound(home));
|
||||
throw new RunnerAbortedException();
|
||||
}
|
||||
return classworlds[0].getAbsolutePath();
|
||||
}
|
||||
|
||||
@@ -29,14 +29,11 @@ import hudson.EnvVars;
|
||||
import hudson.maven.agent.Main;
|
||||
import hudson.maven.agent.Maven21Interceptor;
|
||||
import hudson.model.BuildListener;
|
||||
import jenkins.model.Jenkins;
|
||||
import hudson.model.JDK;
|
||||
import hudson.model.Run.RunnerAbortedException;
|
||||
import hudson.model.TaskListener;
|
||||
import hudson.remoting.Callable;
|
||||
import hudson.remoting.Which;
|
||||
import hudson.tasks.Maven.MavenInstallation;
|
||||
import hudson.util.ArgumentListBuilder;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
@@ -55,88 +52,39 @@ final class MavenProcessFactory extends AbstractMavenProcessFactory implements P
|
||||
super( mms, launcher, envVars, mavenOpts, workDir );
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the command line argument list to launch the maven process.
|
||||
*
|
||||
* UGLY.
|
||||
*/
|
||||
protected ArgumentListBuilder buildMavenAgentCmdLine(BuildListener listener,int tcpPort) throws IOException, InterruptedException {
|
||||
MavenInstallation mvn = getMavenInstallation(listener);
|
||||
if(mvn==null) {
|
||||
listener.error("Maven version is not configured for this project. Can't determine which Maven to run");
|
||||
throw new RunnerAbortedException();
|
||||
}
|
||||
if(mvn.getHome()==null) {
|
||||
listener.error("Maven '%s' doesn't have its home set",mvn.getName());
|
||||
throw new RunnerAbortedException();
|
||||
}
|
||||
|
||||
// find classworlds.jar
|
||||
@Override
|
||||
protected String getMavenAgentClassPath(MavenInstallation mvn,boolean isMaster,FilePath slaveRoot,BuildListener listener) throws IOException, InterruptedException {
|
||||
String classWorldsJar = getLauncher().getChannel().call(new GetClassWorldsJar(mvn.getHome(),listener));
|
||||
|
||||
boolean isMaster = getCurrentNode()== Jenkins.getInstance();
|
||||
FilePath slaveRoot=null;
|
||||
if(!isMaster)
|
||||
slaveRoot = getCurrentNode().getRootPath();
|
||||
|
||||
ArgumentListBuilder args = new ArgumentListBuilder();
|
||||
JDK jdk = getJava(listener);
|
||||
if(jdk==null) {
|
||||
args.add("java");
|
||||
} else {
|
||||
args.add(jdk.getHome()+"/bin/java"); // use JDK.getExecutable() here ?
|
||||
}
|
||||
|
||||
if(debugPort!=0)
|
||||
args.add("-Xrunjdwp:transport=dt_socket,server=y,address="+debugPort);
|
||||
if(yjp)
|
||||
args.add("-agentlib:yjpagent=tracing");
|
||||
|
||||
args.addTokenized(getMavenOpts());
|
||||
|
||||
args.add( "-cp" );
|
||||
String classPath =
|
||||
( isMaster ? Which.jarFile( Main.class ).getAbsolutePath()
|
||||
: slaveRoot.child( "maven-agent.jar" ).getRemote() )
|
||||
+ ( getLauncher().isUnix() ? ":" : ";" )
|
||||
+ ( isMaster ? classWorldsJar : slaveRoot.child( "classworlds.jar" ).getRemote() );
|
||||
args.add( classPath );
|
||||
//+classWorldsJar);
|
||||
args.add(Main.class.getName());
|
||||
|
||||
// M2_HOME
|
||||
args.add(mvn.getHome());
|
||||
|
||||
// remoting.jar
|
||||
String remotingJar = getLauncher().getChannel().call(new GetRemotingJar());
|
||||
if(remotingJar==null) {// this shouldn't be possible, but there are still reports indicating this, so adding a probe here.
|
||||
listener.error("Failed to determine the location of slave.jar");
|
||||
throw new RunnerAbortedException();
|
||||
}
|
||||
args.add(remotingJar);
|
||||
|
||||
// interceptor.jar
|
||||
args.add(isMaster?
|
||||
Which.jarFile(hudson.maven.agent.AbortException.class).getAbsolutePath():
|
||||
slaveRoot.child("maven-interceptor.jar").getRemote());
|
||||
|
||||
// TCP/IP port to establish the remoting infrastructure
|
||||
args.add(tcpPort);
|
||||
|
||||
// if this is Maven 2.1, interceptor override
|
||||
if(mvn.isMaven2_1(getLauncher())) {
|
||||
args.add(isMaster?
|
||||
Which.jarFile(Maven21Interceptor.class).getAbsolutePath():
|
||||
slaveRoot.child("maven2.1-interceptor.jar").getRemote());
|
||||
}
|
||||
|
||||
return args;
|
||||
return classPath;
|
||||
}
|
||||
|
||||
protected String getMainClassName() {
|
||||
return Main.class.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getMavenInterceptorClassPath(MavenInstallation mvn,boolean isMaster,FilePath slaveRoot) throws IOException, InterruptedException {
|
||||
if(mvn.isMaven2_1(getLauncher())) {
|
||||
return isMaster?
|
||||
Which.jarFile(Maven21Interceptor.class).getAbsolutePath():
|
||||
slaveRoot.child("maven2.1-interceptor.jar").getRemote();
|
||||
} else {
|
||||
return isMaster?
|
||||
Which.jarFile(hudson.maven.agent.AbortException.class).getAbsolutePath():
|
||||
slaveRoot.child("maven-interceptor.jar").getRemote();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds classworlds.jar
|
||||
*/
|
||||
private static final class GetClassWorldsJar implements Callable<String,IOException> {
|
||||
private static final long serialVersionUID = 5812919424079344101L;
|
||||
private final String mvnHome;
|
||||
private final TaskListener listener;
|
||||
|
||||
@@ -193,23 +141,7 @@ final class MavenProcessFactory extends AbstractMavenProcessFactory implements P
|
||||
*/
|
||||
public static boolean debug = false;
|
||||
|
||||
/**
|
||||
* If not 0, launch Maven with a debugger port.
|
||||
*/
|
||||
public static int debugPort;
|
||||
|
||||
public static boolean profile = Boolean.getBoolean("hudson.maven.profile");
|
||||
|
||||
/**
|
||||
* If true, launch Maven with YJP offline profiler agent.
|
||||
*/
|
||||
public static boolean yjp = Boolean.getBoolean("hudson.maven.yjp");
|
||||
|
||||
static {
|
||||
String port = System.getProperty("hudson.maven.debugPort");
|
||||
if(port!=null)
|
||||
debugPort = Integer.parseInt(port);
|
||||
}
|
||||
|
||||
public static int socketTimeOut = Integer.parseInt( System.getProperty( "hudson.maven.socketTimeOut", Integer.toString( 30*1000 ) ) );
|
||||
}
|
||||
Reference in new issue
Block a user