提交 f7330d7a 编写于 作者: K Kohsuke Kawaguchi

[FIXED JENKINS-15120]

- 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.
上级 ad60e8e8
......@@ -65,6 +65,9 @@ Upcoming changes</a>
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=-->
......
......@@ -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;
......@@ -36,11 +35,21 @@ import hudson.util.MaskingClassLoader;
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;
......@@ -57,7 +66,6 @@ import java.util.Collection;
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;
......@@ -413,11 +421,10 @@ public class ClassicPluginStrategy implements PluginStrategy {
* 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
......@@ -425,12 +432,9 @@ public class ClassicPluginStrategy implements PluginStrategy {
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);
}
......@@ -442,6 +446,66 @@ public class ClassicPluginStrategy implements PluginStrategy {
}
}
/**
* 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.
*/
......
......@@ -160,6 +160,9 @@ public class Maven3Builder extends AbstractMavenBuilder implements DelegatingCal
throw new IOException2(e);
} catch (Exception e) {
throw new IOException2(e);
} finally {
if (DUMP_PERFORMANCE_COUNTERS)
Channel.current().dumpPerformanceCounters(listener.error("Remoting stats"));
}
}
......@@ -571,4 +574,6 @@ public class Maven3Builder extends AbstractMavenBuilder implements DelegatingCal
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");
}
......@@ -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>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册