提交 8c6962e9 编写于 作者: O Olivier Lamy

fix Maven31ProcessFactory

上级 b9a77396
......@@ -27,14 +27,14 @@ import hudson.EnvVars;
import hudson.FilePath;
import hudson.Launcher;
import hudson.model.BuildListener;
import hudson.model.Run.RunnerAbortedException;
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.remoting.Callable;
import hudson.remoting.Channel;
import hudson.remoting.Which;
import hudson.tasks.Maven.MavenInstallation;
import org.jvnet.hudson.maven3.agent.Maven3Main;
import org.jvnet.hudson.maven3.launcher.Maven3Launcher;
import org.jvnet.hudson.maven3.launcher.Maven31Interceptor;
import org.jvnet.hudson.maven3.listeners.HudsonMavenExecutionResult;
import java.io.File;
......@@ -47,8 +47,7 @@ import java.net.URL;
*
* @author Olivier Lamy
*/
public class Maven31ProcessFactory
extends Maven3ProcessFactory
public class Maven31ProcessFactory extends AbstractMavenProcessFactory implements ProcessCache.Factory
{
Maven31ProcessFactory( MavenModuleSet mms, AbstractMavenBuild<?, ?> build, Launcher launcher, EnvVars envVars,
......@@ -56,28 +55,115 @@ public class Maven31ProcessFactory
super( mms, build, launcher, envVars, mavenOpts, workDir );
}
@Override
protected String getMainClassName()
{
return Maven3Main.class.getName();
}
@Override
protected String getMavenAgentClassPath(MavenInstallation mvn,boolean isMaster,FilePath slaveRoot,BuildListener listener) throws IOException, InterruptedException {
String classWorldsJar = getLauncher().getChannel().call(new Maven3ProcessFactory.GetClassWorldsJar(mvn.getHome(),listener));
return (isMaster? Which.jarFile(Maven3Main.class).getAbsolutePath():slaveRoot.child("maven31-agent.jar").getRemote())+
String path = (isMaster? Which.jarFile(Maven3Main.class).getAbsolutePath():slaveRoot.child("maven31-agent.jar").getRemote())+
(getLauncher().isUnix()?":":";")+classWorldsJar;
return path;
}
@Override
protected String getMavenInterceptorClassPath(MavenInstallation mvn,boolean isMaster,FilePath slaveRoot) throws IOException, InterruptedException {
return isMaster?
Which.jarFile(Maven3Launcher.class).getAbsolutePath():
String path = isMaster?
Which.jarFile(Maven31Interceptor.class).getAbsolutePath():
slaveRoot.child("maven31-interceptor.jar").getRemote();
return path;
}
protected String getMavenInterceptorCommonClassPath(MavenInstallation mvn,boolean isMaster,FilePath slaveRoot) throws IOException, InterruptedException {
return isMaster?
String path = isMaster?
Which.jarFile(HudsonMavenExecutionResult.class).getAbsolutePath():
slaveRoot.child("maven3-interceptor-commons.jar").getRemote();
return path;
}
@Override
protected String getMavenInterceptorOverride(MavenInstallation mvn,
boolean isMaster, FilePath slaveRoot) throws IOException,
InterruptedException {
return null;
}
@Override
protected void applyPlexusModuleContributor(Channel channel, AbstractMavenBuild<?, ?> context) throws InterruptedException, IOException {
channel.call(new InstallPlexusModulesTask(context));
}
private static final class InstallPlexusModulesTask implements Callable<Void,IOException>
{
PlexusModuleContributor c;
public InstallPlexusModulesTask(AbstractMavenBuild<?, ?> context) throws IOException, InterruptedException {
c = PlexusModuleContributorFactory.aggregate(context);
}
public Void call() throws IOException {
org.jvnet.hudson.maven3.agent.Maven3Main.addPlexusComponents(
c.getPlexusComponentJars().toArray( new URL[0] ) );
return null;
}
private static final long serialVersionUID = 1L;
}
/**
* Finds classworlds.jar
*/
protected static final class GetClassWorldsJar implements Callable<String,IOException> {
private static final long serialVersionUID = -2599434124883557137L;
private final String mvnHome;
private final TaskListener listener;
protected GetClassWorldsJar(String mvnHome, TaskListener listener) {
this.mvnHome = mvnHome;
this.listener = listener;
}
public String call() throws IOException {
File home = new File(mvnHome);
if (MavenProcessFactory.debug)
listener.getLogger().println("Using mvnHome: "+ mvnHome);
File bootDir = new File(home, "boot");
File[] classworlds = bootDir.listFiles(CLASSWORLDS_FILTER);
if(classworlds==null || classworlds.length==0) {
listener.error(Messages.MavenProcessFactory_ClassWorldsNotFound(home));
throw new Run.RunnerAbortedException();
}
return classworlds[0].getAbsolutePath();
}
}
/**
* Locates classworlds jar file.
*
* Note that Maven 3.0 changed the name to plexus-classworlds
*
* <pre>
* $ find tools/ -name "plexus-classworlds*.jar"
* tools/maven-3.0-alpha-2/boot/plexus-classworlds-1.3.jar
* tools/maven-3.0-alpha-3/boot/plexus-classworlds-2.2.2.jar
* tools/maven-3.0-alpha-4/boot/plexus-classworlds-2.2.2.jar
* tools/maven-3.0-alpha-5/boot/plexus-classworlds-2.2.2.jar
* tools/maven-3.0-alpha-6/boot/plexus-classworlds-2.2.2.jar
* </pre>
*/
private static final FilenameFilter CLASSWORLDS_FILTER = new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.contains("plexus-classworlds") && name.endsWith(".jar");
}
};
}
......@@ -33,16 +33,15 @@ import hudson.remoting.Callable;
import hudson.remoting.Channel;
import hudson.remoting.Which;
import hudson.tasks.Maven.MavenInstallation;
import org.jvnet.hudson.maven3.agent.Maven3Main;
import org.jvnet.hudson.maven3.launcher.Maven3Launcher;
import org.jvnet.hudson.maven3.listeners.HudsonMavenExecutionResult;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.net.URL;
import org.jvnet.hudson.maven3.agent.Maven3Main;
import org.jvnet.hudson.maven3.launcher.Maven3Launcher;
import org.jvnet.hudson.maven3.listeners.HudsonMavenExecutionResult;
/**
* {@link AbstractMavenProcessFactory} for Maven 3.
*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册