diff options
| author | Curtis Windatt | 2012-11-14 15:01:11 +0000 |
|---|---|---|
| committer | John Arthorne | 2012-11-14 15:01:11 +0000 |
| commit | 1971740ba62534120d9f33162963d4517c898424 (patch) | |
| tree | 8921d60a24e469c8cba3f1f3e35e6b64d0596ee2 | |
| parent | 99d7eb61f20739c313031de8ecfca64ec0275e99 (diff) | |
| download | rt.equinox.p2-1971740ba62534120d9f33162963d4517c898424.tar.gz rt.equinox.p2-1971740ba62534120d9f33162963d4517c898424.tar.xz rt.equinox.p2-1971740ba62534120d9f33162963d4517c898424.zip | |
Bug 392861 - Incorrectly closed streams in Jar Processorv20121114-150111
4 files changed, 71 insertions, 65 deletions
diff --git a/bundles/org.eclipse.equinox.p2.jarprocessor/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.jarprocessor/META-INF/MANIFEST.MF index 5c21d1f2d..6922020fd 100644 --- a/bundles/org.eclipse.equinox.p2.jarprocessor/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.equinox.p2.jarprocessor/META-INF/MANIFEST.MF @@ -4,9 +4,8 @@ Bundle-SymbolicName: org.eclipse.equinox.p2.jarprocessor;singleton:=true Bundle-Name: %pluginName Bundle-Vendor: %providerName Bundle-Localization: plugin -Bundle-Version: 1.0.200.qualifier -Bundle-RequiredExecutionEnvironment: CDC-1.1/Foundation-1.1, - J2SE-1.4 +Bundle-Version: 1.0.300.qualifier +Bundle-RequiredExecutionEnvironment: J2SE-1.5 Main-Class: org.eclipse.equinox.internal.p2.jarprocessor.Main Export-Package: org.eclipse.equinox.internal.p2.jarprocessor;x-friends:="org.eclipse.equinox.p2.artifact.repository,org.eclipse.pde.build", org.eclipse.equinox.internal.p2.jarprocessor.unsigner;x-internal:=true, diff --git a/bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/equinox/internal/p2/jarprocessor/Utils.java b/bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/equinox/internal/p2/jarprocessor/Utils.java index 084cf4786..5f1e68391 100644 --- a/bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/equinox/internal/p2/jarprocessor/Utils.java +++ b/bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/equinox/internal/p2/jarprocessor/Utils.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2010 IBM Corporation and others. + * Copyright (c) 2006, 2012 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -253,17 +253,6 @@ public class Utils { JarFile jar = null; try { jar = new JarFile(jarFile, false); - } catch (ZipException e) { - //not a jar, don't bother logging this. - return null; - } catch (IOException e) { - if (verbose) { - System.out.println("Failed to obtain eclipse.inf due to IOException: " + jarFile); //$NON-NLS-1$ - e.printStackTrace(); - } - return null; - } - try { JarEntry mark = jar.getJarEntry(MARK_FILE_NAME); if (mark != null) { InputStream in = jar.getInputStream(mark); @@ -273,6 +262,9 @@ public class Utils { return props; } return new Properties(); + } catch (ZipException e) { + //not a jar, don't bother logging this. + return null; } catch (IOException e) { if (verbose) { System.out.println("Failed to obtain eclipse.inf due to IOException: " + jarFile); //$NON-NLS-1$ diff --git a/bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/equinox/internal/p2/jarprocessor/unsigner/Unsigner.java b/bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/equinox/internal/p2/jarprocessor/unsigner/Unsigner.java index 6e8ca82b1..3d7b49091 100644 --- a/bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/equinox/internal/p2/jarprocessor/unsigner/Unsigner.java +++ b/bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/equinox/internal/p2/jarprocessor/unsigner/Unsigner.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2009 IBM Corporation and others. + * Copyright (c) 2007, 2012 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -9,11 +9,13 @@ * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.equinox.internal.p2.jarprocessor.unsigner; + import java.io.*; import java.util.Enumeration; import java.util.jar.JarFile; import java.util.jar.Manifest; import java.util.zip.*; +import org.eclipse.equinox.internal.p2.jarprocessor.Utils; /** * This class removes the signature files from a jar and clean up the manifest. @@ -24,11 +26,11 @@ public class Unsigner { private static final String RSA_EXT = ".RSA"; //$NON-NLS-1$ private static final String SF_EXT = ".SF"; //$NON-NLS-1$ private static final String META_INF_PREFIX = META_INF + '/'; - + private String[] signers; private File jarFile; private boolean keepManifestContent = false; - + private boolean isSigned(File file) { ZipFile jar = null; try { @@ -44,7 +46,7 @@ public class Unsigner { while (entries.hasMoreElements()) { ZipEntry entry = (ZipEntry) entries.nextElement(); String entryName = entry.getName(); - if(entryName.endsWith(SF_EXT) && entryName.startsWith(META_INF)) + if (entryName.endsWith(SF_EXT) && entryName.startsWith(META_INF)) return true; } } @@ -54,27 +56,30 @@ public class Unsigner { } catch (IOException e) { return false; } finally { - if (jar != null) + if (jar != null) { try { jar.close(); } catch (IOException e) { //Ignore } + } } } - + public void execute() { processJar(jarFile); } - + private void processJar(File inputFile) { if (!isSigned(inputFile)) return; + ZipInputStream input = null; + ZipOutputStream output = null; try { - ZipInputStream input = new ZipInputStream(new BufferedInputStream(new FileInputStream(inputFile))); + input = new ZipInputStream(new BufferedInputStream(new FileInputStream(inputFile))); File outputFile = File.createTempFile("removing.", ".signature", inputFile.getParentFile()); //$NON-NLS-1$ //$NON-NLS-2$ - ZipOutputStream output = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(outputFile))); + output = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(outputFile))); ZipEntry inputZe = input.getNextEntry(); byte[] b = new byte[8192]; @@ -113,12 +118,15 @@ public class Unsigner { //this can't happen we have checked before } catch (IOException e) { e.printStackTrace(); + } finally { + Utils.close(input); + Utils.close(output); } } - + private byte shouldRemove(ZipEntry entry) { String entryName = entry.getName(); - if(keepManifestContent == false && entryName.equalsIgnoreCase(JarFile.MANIFEST_NAME)) { + if (keepManifestContent == false && entryName.equalsIgnoreCase(JarFile.MANIFEST_NAME)) { return 1; } if (signers != null) { @@ -132,15 +140,15 @@ public class Unsigner { } return 0; } - + public void setRemoveSigners(String[] fileName) { signers = fileName; } - + public void setJar(File file) { jarFile = file; } - + public void setKeepManifestEntries(boolean keep) { keepManifestContent = keep; } diff --git a/bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/internal/provisional/equinox/p2/jarprocessor/JarProcessor.java b/bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/internal/provisional/equinox/p2/jarprocessor/JarProcessor.java index 217d01013..f2547178c 100644 --- a/bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/internal/provisional/equinox/p2/jarprocessor/JarProcessor.java +++ b/bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/internal/provisional/equinox/p2/jarprocessor/JarProcessor.java @@ -304,33 +304,41 @@ public class JarProcessor { tempDir = new File(parent, "temp_" + depth + '_' + workingFile.getName()); //$NON-NLS-1$ } - JarFile jar = new JarFile(workingFile, false); - Map replacements = new HashMap(); - Properties inf = Utils.getEclipseInf(workingFile, verbose); - extractEntries(jar, tempDir, replacements, inf); - - boolean infAdjusted = false; - if (inf != null) - infAdjusted = adjustInf(workingFile, inf); - - //Recreate the jar with replacements. - //This is not strictly necessary if we didn't change the inf file and didn't change any content - if (!replacements.isEmpty() || infAdjusted) { - File tempJar = null; - tempJar = new File(tempDir, workingFile.getName()); - File parent = tempJar.getParentFile(); - if (!parent.exists()) - parent.mkdirs(); - JarOutputStream jarOut = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(tempJar))); - recreateJar(jar, jarOut, replacements, tempDir, inf); - - jar.close(); - if (tempJar != null) { - if (!workingFile.equals(input)) { - workingFile.delete(); + JarFile jar = null; + try { + jar = new JarFile(workingFile, false); + Map replacements = new HashMap(); + Properties inf = Utils.getEclipseInf(workingFile, verbose); + extractEntries(jar, tempDir, replacements, inf); + + boolean infAdjusted = false; + if (inf != null) + infAdjusted = adjustInf(workingFile, inf); + + //Recreate the jar with replacements. + //This is not strictly necessary if we didn't change the inf file and didn't change any content + if (!replacements.isEmpty() || infAdjusted) { + File tempJar = null; + tempJar = new File(tempDir, workingFile.getName()); + File parent = tempJar.getParentFile(); + if (!parent.exists()) + parent.mkdirs(); + JarOutputStream jarOut = null; + try { + jarOut = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(tempJar))); + recreateJar(jar, jarOut, replacements, tempDir, inf); + } finally { + Utils.close(jarOut); + } + if (tempJar != null) { + if (!workingFile.equals(input)) { + workingFile.delete(); + } + workingFile = tempJar; } - workingFile = tempJar; } + } finally { + Utils.close(jar); } //post @@ -370,29 +378,28 @@ public class JarProcessor { try { File tempJar = new File(directory, "temp_" + input.getName()); //$NON-NLS-1$ JarFile jar = null; + JarOutputStream jarOut = null; + InputStream jarIn = null; try { jar = new JarFile(input, false); - } catch (JarException e) { - //not a jar - return; - } - JarOutputStream jarOut = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(tempJar))); - InputStream in = null; - try { + jarOut = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(tempJar))); Enumeration entries = jar.entries(); for (JarEntry entry = (JarEntry) entries.nextElement(); entry != null; entry = entries.hasMoreElements() ? (JarEntry) entries.nextElement() : null) { JarEntry newEntry = new JarEntry(entry.getName()); newEntry.setTime(entry.getTime()); - in = new BufferedInputStream(jar.getInputStream(entry)); + jarIn = new BufferedInputStream(jar.getInputStream(entry)); jarOut.putNextEntry(newEntry); - Utils.transferStreams(in, jarOut, false); + Utils.transferStreams(jarIn, jarOut, false); jarOut.closeEntry(); - in.close(); + jarIn.close(); } + } catch (JarException e) { + //not a jar + return; } finally { Utils.close(jarOut); + Utils.close(jarIn); Utils.close(jar); - Utils.close(in); } tempJar.setLastModified(input.lastModified()); input.delete(); |
