diff --git a/maven-plugin/src/main/java/hudson/maven/Maven31ProcessFactory.java b/maven-plugin/src/main/java/hudson/maven/Maven31ProcessFactory.java index b6c97c1f3dcd42093fba3d7e720069ff9a23e513..9a435c0643cc35b826ae0b82d7724135078d4b48 100644 --- a/maven-plugin/src/main/java/hudson/maven/Maven31ProcessFactory.java +++ b/maven-plugin/src/main/java/hudson/maven/Maven31ProcessFactory.java @@ -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 + { + 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 { + 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 + * + *
+     * $ 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
+     * 
+ */ + private static final FilenameFilter CLASSWORLDS_FILTER = new FilenameFilter() { + public boolean accept(File dir, String name) { + return name.contains("plexus-classworlds") && name.endsWith(".jar"); + } + }; } diff --git a/maven-plugin/src/main/java/hudson/maven/Maven3ProcessFactory.java b/maven-plugin/src/main/java/hudson/maven/Maven3ProcessFactory.java index 2c0ddf9ddbc9a02eb4cbe7c3aac4c86898cd561f..8051028d6d440c274f3292d16761b8bb7b118acb 100644 --- a/maven-plugin/src/main/java/hudson/maven/Maven3ProcessFactory.java +++ b/maven-plugin/src/main/java/hudson/maven/Maven3ProcessFactory.java @@ -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. *