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

Merge pull request #923 from evernat/master

Optimize and close Zip resources in ClassicPluginStrategy and FilePath
...@@ -441,7 +441,7 @@ public class ClassicPluginStrategy implements PluginStrategy { ...@@ -441,7 +441,7 @@ public class ClassicPluginStrategy implements PluginStrategy {
* Repackage classes directory into a jar file to make it remoting friendly. * Repackage classes directory into a jar file to make it remoting friendly.
* The remoting layer can cache jar files but not class files. * The remoting layer can cache jar files but not class files.
*/ */
private static void createClassJarFromWebInfClasses(File archive, File destDir, Project prj) { private static void createClassJarFromWebInfClasses(File archive, File destDir, Project prj) throws IOException {
File classesJar = new File(destDir, "WEB-INF/lib/classes.jar"); File classesJar = new File(destDir, "WEB-INF/lib/classes.jar");
ZipFileSet zfs = new ZipFileSet(); ZipFileSet zfs = new ZipFileSet();
...@@ -458,31 +458,36 @@ public class ClassicPluginStrategy implements PluginStrategy { ...@@ -458,31 +458,36 @@ public class ClassicPluginStrategy implements PluginStrategy {
mapper.add(gm); mapper.add(gm);
final long dirTime = archive.lastModified(); final long dirTime = archive.lastModified();
Zip z = new Zip() { // this ZipOutputStream is reused and not created for each directory
/** final ZipOutputStream wrappedZOut = new ZipOutputStream(new NullOutputStream()) {
* Forces the fixed timestamp for directories to make sure @Override
* classes.jar always get a consistent checksum. public void putNextEntry(ZipEntry ze) throws IOException {
*/ ze.setTime(dirTime+1999); // roundup
protected void zipDir(Resource dir, ZipOutputStream zOut, String vPath, super.putNextEntry(ze);
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); try {
z.setTaskType("zip"); Zip z = new Zip() {
classesJar.getParentFile().mkdirs(); /**
z.setDestFile(classesJar); * Forces the fixed timestamp for directories to make sure
z.add(mapper); * classes.jar always get a consistent checksum.
z.execute(); */
protected void zipDir(Resource dir, ZipOutputStream zOut, String vPath,
int mode, ZipExtraField[] extra)
throws IOException {
// use wrappedZOut instead of zOut
super.zipDir(dir,wrappedZOut,vPath,mode,extra);
}
};
z.setProject(prj);
z.setTaskType("zip");
classesJar.getParentFile().mkdirs();
z.setDestFile(classesJar);
z.add(mapper);
z.execute();
} finally {
wrappedZOut.close();
}
} }
private static void unzipExceptClasses(File archive, File destDir, Project prj) { private static void unzipExceptClasses(File archive, File destDir, Project prj) {
......
...@@ -530,7 +530,12 @@ public final class FilePath implements Serializable { ...@@ -530,7 +530,12 @@ public final class FilePath implements Serializable {
if (p != null) { if (p != null) {
p.mkdirs(); p.mkdirs();
} }
IOUtils.copy(zip.getInputStream(e), f); InputStream input = zip.getInputStream(e);
try {
IOUtils.copy(input, f);
} finally {
input.close();
}
try { try {
FilePath target = new FilePath(f); FilePath target = new FilePath(f);
int mode = e.getUnixMode(); int mode = e.getUnixMode();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册