Skip to content

Commit

Permalink
[FIXED JENKINS-15120]
Browse files Browse the repository at this point in the history
- integrated the newer release of remoting
- jar caching won't work with class file directory, so plugin
  WEB-INF/classes are now exploded as WEB-INF/lib/classes.jar
  (This should also solve the problem of slow plugin extraction in the
  presene of Anti-virus software on Windows.)
- because the structure of the exploded jar file has changed, I changed
  the up-to-date check timestamp file name to force re-extraction in
  existing installations.
  • Loading branch information
kohsuke committed Jun 8, 2013
1 parent ad60e8e commit f7330d7
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 12 deletions.
3 changes: 3 additions & 0 deletions changelog.html
Expand Up @@ -65,6 +65,9 @@
Improved the tracking of queued jobs and their eventual builds in the REST API.
<li class='rfe'>
Added a new extension point to contribute custom plexus components into Maven for the maven project type.
<li class='major rfe'>
Remoting classloader performance improvement upon reconnection to the same slave.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-15120">issue 15120</a>)
</ul>
</div><!--=TRUNK-END=-->

Expand Down
86 changes: 75 additions & 11 deletions core/src/main/java/hudson/ClassicPluginStrategy.java
Expand Up @@ -23,7 +23,6 @@
*/
package hudson;

import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import hudson.Plugin.DummyImpl;
import hudson.PluginWrapper.Dependency;
Expand All @@ -36,11 +35,21 @@
import hudson.util.VersionNumber;
import jenkins.ClassLoaderReflectionToolkit;
import jenkins.ExtensionFilter;
import org.apache.commons.io.output.NullOutputStream;
import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.Expand;
import org.apache.tools.ant.taskdefs.Zip;
import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.types.PatternSet;
import org.apache.tools.ant.types.Resource;
import org.apache.tools.ant.types.ZipFileSet;
import org.apache.tools.ant.types.resources.MappedResourceCollection;
import org.apache.tools.ant.util.GlobPatternMapper;
import org.apache.tools.zip.ZipEntry;
import org.apache.tools.zip.ZipExtraField;
import org.apache.tools.zip.ZipOutputStream;

import java.io.Closeable;
import java.io.File;
Expand All @@ -57,7 +66,6 @@
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;
import java.util.jar.Attributes;
Expand Down Expand Up @@ -413,24 +421,20 @@ private static void parseClassPath(Manifest manifest, File archive, List<File> p
* Explodes the plugin into a directory, if necessary.
*/
private static void explode(File archive, File destDir) throws IOException {
if(!destDir.exists())
destDir.mkdirs();
destDir.mkdirs();

// timestamp check
File explodeTime = new File(destDir,".timestamp");
File explodeTime = new File(destDir,".timestamp2");
if(explodeTime.exists() && explodeTime.lastModified()==archive.lastModified())
return; // no need to expand

// delete the contents so that old files won't interfere with new files
Util.deleteRecursive(destDir);

try {
Expand e = new Expand();
e.setProject(new Project());
e.setTaskType("unzip");
e.setSrc(archive);
e.setDest(destDir);
e.execute();
Project prj = new Project();
unzipExceptClasses(archive, destDir, prj);
createClassJarFromWebInfClasses(archive, destDir, prj);
} catch (BuildException x) {
throw new IOException2("Failed to expand " + archive,x);
}
Expand All @@ -442,6 +446,66 @@ private static void explode(File archive, File destDir) throws IOException {
}
}

/**
* Repackage classes directory into a jar file to make it remoting friendly.
* The remoting layer can cache jar files but not class files.
*/
private static void createClassJarFromWebInfClasses(File archive, File destDir, Project prj) {
File classesJar = new File(destDir, "WEB-INF/lib/classes.jar");

ZipFileSet zfs = new ZipFileSet();
zfs.setProject(prj);
zfs.setSrc(archive);
zfs.setIncludes("WEB-INF/classes/");

MappedResourceCollection mapper = new MappedResourceCollection();
mapper.add(zfs);

GlobPatternMapper gm = new GlobPatternMapper();
gm.setFrom("WEB-INF/classes/*");
gm.setTo("*");
mapper.add(gm);

final long dirTime = archive.lastModified();
Zip z = new Zip() {
/**
* Forces the fixed timestamp for directories to make sure
* classes.jar always get a consistent checksum.
*/
protected void zipDir(Resource dir, ZipOutputStream zOut, String vPath,
int mode, ZipExtraField[] extra)
throws IOException {

ZipOutputStream wrapped = new ZipOutputStream(new NullOutputStream()) {
@Override
public void putNextEntry(ZipEntry ze) throws IOException {
ze.setTime(dirTime+1999); // roundup
super.putNextEntry(ze);
}
};
super.zipDir(dir,wrapped,vPath,mode,extra);
}
};
z.setProject(prj);
z.setTaskType("zip");
classesJar.getParentFile().mkdirs();
z.setDestFile(classesJar);
z.add(mapper);
z.execute();
}

private static void unzipExceptClasses(File archive, File destDir, Project prj) {
Expand e = new Expand();
e.setProject(prj);
e.setTaskType("unzip");
e.setSrc(archive);
e.setDest(destDir);
PatternSet p = new PatternSet();
p.setExcludes("WEB-INF/classes/");
e.addPatternset(p);
e.execute();
}

/**
* Used to load classes from dependency plugins.
*/
Expand Down
5 changes: 5 additions & 0 deletions maven-plugin/src/main/java/hudson/maven/Maven3Builder.java
Expand Up @@ -160,6 +160,9 @@ public Result call() throws IOException {
throw new IOException2(e);
} catch (Exception e) {
throw new IOException2(e);
} finally {
if (DUMP_PERFORMANCE_COUNTERS)
Channel.current().dumpPerformanceCounters(listener.error("Remoting stats"));
}
}

Expand Down Expand Up @@ -571,4 +574,6 @@ private String mojoExec(ExecutionEvent event) {
private static final long serialVersionUID = 1L;

private static final Logger LOGGER = Logger.getLogger(Maven3Builder.class.getName());

public static boolean DUMP_PERFORMANCE_COUNTERS = Boolean.getBoolean(Maven3Builder.class.getName()+".dumpPerformanceCounters");
}
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -175,7 +175,7 @@ THE SOFTWARE.
<dependency>
<groupId>org.jenkins-ci.main</groupId>
<artifactId>remoting</artifactId>
<version>2.23</version>
<version>2.24</version>
</dependency>

<dependency>
Expand Down

0 comments on commit f7330d7

Please sign in to comment.