Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FIXED JENKINS-16261] Defer JAR copying from MavenComputerListener.pr…
…eOnline.

Originally-Committed-As: bf7eb802d9b4535927dca89a41f62fc24d1c409f
  • Loading branch information
jglick committed Aug 23, 2013
1 parent 3a7e811 commit 4880a36
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 149 deletions.
67 changes: 59 additions & 8 deletions src/main/java/hudson/maven/AbstractMavenProcessFactory.java
Expand Up @@ -33,6 +33,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.Serializable;
import java.net.ServerSocket;
import java.net.Socket;
Expand All @@ -42,6 +43,8 @@
import java.util.Arrays;

import jenkins.model.Jenkins;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.Zip;

import org.kohsuke.stapler.framework.io.IOException2;

Expand Down Expand Up @@ -357,7 +360,7 @@ private ArgumentListBuilder buildMavenAgentCmdLine(BuildListener listener, int t
args.addTokenized(getMavenOpts());

args.add( "-cp" );
args.add(getMavenAgentClassPath(mvn,isMaster,slaveRoot,listener));
args.add(getMavenAgentClassPath(mvn, slaveRoot, listener));


args.add(getMainClassName());
Expand All @@ -374,9 +377,9 @@ private ArgumentListBuilder buildMavenAgentCmdLine(BuildListener listener, int t
args.add(remotingJar);

// interceptor.jar
args.add(getMavenInterceptorClassPath(mvn,isMaster,slaveRoot));
args.add(getMavenInterceptorClassPath(mvn, slaveRoot, listener));

String mavenInterceptorCommonClasspath = getMavenInterceptorCommonClassPath( mvn, isMaster, slaveRoot );
String mavenInterceptorCommonClasspath = getMavenInterceptorCommonClassPath(mvn, slaveRoot, listener);

if (mavenInterceptorCommonClasspath!=null){
args.add( mavenInterceptorCommonClasspath );
Expand All @@ -385,7 +388,7 @@ private ArgumentListBuilder buildMavenAgentCmdLine(BuildListener listener, int t
// TCP/IP port to establish the remoting infrastructure
args.add(tcpPort);

String interceptorOverride = getMavenInterceptorOverride(mvn,isMaster,slaveRoot);
String interceptorOverride = getMavenInterceptorOverride(mvn, slaveRoot, listener);
if (interceptorOverride!=null) {
args.add(interceptorOverride);
}
Expand All @@ -396,25 +399,25 @@ private ArgumentListBuilder buildMavenAgentCmdLine(BuildListener listener, int t
/**
* 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;
protected abstract String getMavenAgentClassPath(MavenInstallation mvn, 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;
protected abstract String getMavenInterceptorClassPath(MavenInstallation mvn, FilePath slaveRoot, BuildListener listener) throws IOException, InterruptedException;

/**
* Returns the classpath string for the maven-interceptor jar
* @since 1.525
*/
protected String getMavenInterceptorCommonClassPath(MavenInstallation mvn,boolean isMaster,FilePath slaveRoot) throws IOException, InterruptedException {
protected String getMavenInterceptorCommonClassPath(MavenInstallation mvn, FilePath slaveRoot, BuildListener listener) throws IOException, InterruptedException {
return null;
}

/**
* For Maven 2.1.x - 2.2.x we need an additional jar which overrides some classes in the other interceptor jar.
*/
protected abstract String getMavenInterceptorOverride(MavenInstallation mvn,boolean isMaster,FilePath slaveRoot) throws IOException, InterruptedException;
protected abstract String getMavenInterceptorOverride(MavenInstallation mvn, FilePath slaveRoot, BuildListener listener) throws IOException, InterruptedException;

/**
* Returns the name of the Maven main class.
Expand Down Expand Up @@ -493,6 +496,54 @@ public String call() throws IOException {
}
}

/**
* Copies a Maven-related JAR to the slave on demand.
* Can also be used when run on master.
* @param root the FS root of the slave (null means running on master)
* @param representative a representative class present in the JAR
* @param seedName the basename of the JAR
* @param listener a listener for any problems
* @return the (local or remote) absolute path of the JAR
* @throws IOException in case copying fails
* @throws InterruptedException in case copying is interrupted
* @since 1.530
*/
protected final String classPathEntry(FilePath root, Class<?> representative, String seedName, TaskListener listener) throws IOException, InterruptedException {
if (root == null) { // master
return Which.jarFile(representative).getAbsolutePath();
} else {
return copyJar(listener.getLogger(), root, representative, seedName).getRemote();
}
}
/**
* Copies a jar file from the master to slave.
*/
static FilePath copyJar(PrintStream log, FilePath dst, Class<?> representative, String seedName) throws IOException, InterruptedException {
// in normal execution environment, the master should be loading 'representative' from this jar, so
// in that way we can find it.
File jar = Which.jarFile(representative);
FilePath copiedJar = dst.child(seedName + ".jar");

if (jar.isDirectory()) {
// but during the development and unit test environment, we may be picking the class up from the classes dir
Zip zip = new Zip();
zip.setBasedir(jar);
File t = File.createTempFile(seedName, "jar");
t.delete();
zip.setDestFile(t);
zip.setProject(new Project());
zip.execute();
jar = t;
} else if (copiedJar.lastModified() > jar.lastModified()) {
log.println(seedName + ".jar already up to date");
return copiedJar;
}

new FilePath(jar).copyTo(copiedJar);
log.println("Copied " + seedName + ".jar");
return copiedJar;
}

/**
* Returns the current {@link Node} on which we are buildling.
*/
Expand Down
21 changes: 6 additions & 15 deletions src/main/java/hudson/maven/Maven31ProcessFactory.java
Expand Up @@ -29,7 +29,6 @@
import hudson.model.BuildListener;
import hudson.remoting.Callable;
import hudson.remoting.Channel;
import hudson.remoting.Which;
import hudson.tasks.Maven.MavenInstallation;
import jenkins.maven3.agent.Maven31Main;
import org.jvnet.hudson.maven3.launcher.Maven31Interceptor;
Expand Down Expand Up @@ -58,9 +57,9 @@ protected String getMainClassName()
}

@Override
protected String getMavenAgentClassPath(MavenInstallation mvn,boolean isMaster,FilePath slaveRoot,BuildListener listener) throws IOException, InterruptedException {
protected String getMavenAgentClassPath(MavenInstallation mvn, FilePath slaveRoot, BuildListener listener) throws IOException, InterruptedException {
String classWorldsJar = getLauncher().getChannel().call(new Maven3ProcessFactory.GetClassWorldsJar(mvn.getHome(),listener));
String path = (isMaster? Which.jarFile(Maven31Main.class).getAbsolutePath():slaveRoot.child("maven31-agent.jar").getRemote())+
String path = classPathEntry(slaveRoot, Maven31Main.class, "maven31-agent", listener) +
(getLauncher().isUnix()?":":";")+classWorldsJar;

// TODO this configurable??
Expand Down Expand Up @@ -91,20 +90,12 @@ public Void call() throws IOException {
}

@Override
protected String getMavenInterceptorClassPath(MavenInstallation mvn,boolean isMaster,FilePath slaveRoot) throws IOException, InterruptedException {
String path = isMaster?
Which.jarFile(Maven31Interceptor.class).getAbsolutePath():
slaveRoot.child("maven31-interceptor.jar").getRemote();

return path;
protected String getMavenInterceptorClassPath(MavenInstallation mvn, FilePath slaveRoot, BuildListener listener) throws IOException, InterruptedException {
return classPathEntry(slaveRoot, Maven31Interceptor.class, "maven31-interceptor", listener);
}

protected String getMavenInterceptorCommonClassPath(MavenInstallation mvn,boolean isMaster,FilePath slaveRoot) throws IOException, InterruptedException {
String path = isMaster?
Which.jarFile(HudsonMavenExecutionResult.class).getAbsolutePath():
slaveRoot.child("maven3-interceptor-commons.jar").getRemote();

return path;
protected String getMavenInterceptorCommonClassPath(MavenInstallation mvn, FilePath slaveRoot, BuildListener listener) throws IOException, InterruptedException {
return classPathEntry(slaveRoot, HudsonMavenExecutionResult.class, "maven3-interceptor-commons", listener);
}


Expand Down
19 changes: 7 additions & 12 deletions src/main/java/hudson/maven/Maven3ProcessFactory.java
Expand Up @@ -31,7 +31,6 @@
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;
Expand All @@ -55,10 +54,10 @@ public class Maven3ProcessFactory extends AbstractMavenProcessFactory implements
}

@Override
protected String getMavenAgentClassPath(MavenInstallation mvn,boolean isMaster,FilePath slaveRoot,BuildListener listener) throws IOException, InterruptedException {
protected String getMavenAgentClassPath(MavenInstallation mvn, FilePath slaveRoot, BuildListener listener) throws IOException, InterruptedException {
String classWorldsJar = getLauncher().getChannel().call(new GetClassWorldsJar(mvn.getHome(),listener));

return (isMaster? Which.jarFile(Maven3Main.class).getAbsolutePath():slaveRoot.child("maven3-agent.jar").getRemote())+
return classPathEntry(slaveRoot, Maven3Main.class, "maven3-agent", listener) +
(getLauncher().isUnix()?":":";")+classWorldsJar;
}

Expand All @@ -68,21 +67,17 @@ protected String getMainClassName() {
}

@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();
protected String getMavenInterceptorClassPath(MavenInstallation mvn, FilePath slaveRoot, BuildListener listener) throws IOException, InterruptedException {
return classPathEntry(slaveRoot, Maven3Launcher.class, "maven3-interceptor", listener);
}

protected String getMavenInterceptorCommonClassPath(MavenInstallation mvn,boolean isMaster,FilePath slaveRoot) throws IOException, InterruptedException {
return isMaster?
Which.jarFile(HudsonMavenExecutionResult.class).getAbsolutePath():
slaveRoot.child("maven3-interceptor-commons.jar").getRemote();
protected String getMavenInterceptorCommonClassPath(MavenInstallation mvn, FilePath slaveRoot, BuildListener listener) throws IOException, InterruptedException {
return classPathEntry(slaveRoot, HudsonMavenExecutionResult.class, "maven3-interceptor-commons", listener);
}

@Override
protected String getMavenInterceptorOverride(MavenInstallation mvn,
boolean isMaster, FilePath slaveRoot) throws IOException,
FilePath slaveRoot, BuildListener listener) throws IOException,
InterruptedException {
return null;
}
Expand Down
99 changes: 0 additions & 99 deletions src/main/java/hudson/maven/MavenComputerListener.java

This file was deleted.

0 comments on commit 4880a36

Please sign in to comment.