diff options
author | Ian Bull | 2012-09-20 19:33:32 +0000 |
---|---|---|
committer | Ian Bull | 2012-10-01 21:44:24 +0000 |
commit | 2f4b8b75353f177c3857fe09b9be6546f78ff3bb (patch) | |
tree | 1b918031f4a6aee0abe5fcecef9d3b2b0aa8cde6 | |
parent | 9b046ca9e6e6cb390b787cb51bf5ed335ddc946d (diff) | |
download | rt.equinox.p2-2f4b8b75353f177c3857fe09b9be6546f78ff3bb.tar.gz rt.equinox.p2-2f4b8b75353f177c3857fe09b9be6546f78ff3bb.tar.xz rt.equinox.p2-2f4b8b75353f177c3857fe09b9be6546f78ff3bb.zip |
Revert "Revert "Bug 387557 - JarProcessor 'tampers' eclipse.inf of signed jars in some cases""
This reverts commit b1df469a2938fd2d98cba299ca8d9a88cbdaf0f9.
8 files changed, 73 insertions, 36 deletions
diff --git a/bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/equinox/internal/p2/jarprocessor/CommandStep.java b/bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/equinox/internal/p2/jarprocessor/CommandStep.java index dde666095..d03a9f795 100644 --- a/bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/equinox/internal/p2/jarprocessor/CommandStep.java +++ b/bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/equinox/internal/p2/jarprocessor/CommandStep.java @@ -62,7 +62,8 @@ public abstract class CommandStep implements IProcessStep { return options; } - public void adjustInf(File input, Properties inf, List containers) { - //nothing + public boolean adjustInf(File input, Properties inf, List containers) { + //do nothing by default + return false; } } diff --git a/bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/equinox/internal/p2/jarprocessor/PackStep.java b/bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/equinox/internal/p2/jarprocessor/PackStep.java index bb4cac8c2..f85bb5584 100644 --- a/bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/equinox/internal/p2/jarprocessor/PackStep.java +++ b/bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/equinox/internal/p2/jarprocessor/PackStep.java @@ -164,30 +164,31 @@ public class PackStep extends CommandStep { return "Pack"; //$NON-NLS-1$ } - public void adjustInf(File input, Properties inf, List containers) { + public boolean adjustInf(File input, Properties inf, List containers) { if (input == null || inf == null) - return; + return false; //don't be verbose to check if we should mark the inf boolean v = verbose; verbose = false; if (!shouldPack(input, containers, inf)) { verbose = v; - return; + return false; } verbose = v; //mark as conditioned if not previously marked. A signed jar is assumed to be previously conditioned. - if (inf.getProperty(Utils.MARK_PROPERTY) == null) { - inf.put(Utils.MARK_PROPERTY, "true"); //$NON-NLS-1$ - - //record arguments used - String arguments = inf.getProperty(Utils.PACK_ARGS); - if (arguments == null) { - arguments = getArguments(input, inf, containers); - if (arguments != null && arguments.length() > 0) - inf.put(Utils.PACK_ARGS, arguments); - } + if (inf.getProperty(Utils.MARK_PROPERTY) != null) + return false; + + inf.put(Utils.MARK_PROPERTY, "true"); //$NON-NLS-1$ + //record arguments used + String arguments = inf.getProperty(Utils.PACK_ARGS); + if (arguments == null) { + arguments = getArguments(input, inf, containers); + if (arguments != null && arguments.length() > 0) + inf.put(Utils.PACK_ARGS, arguments); } + return true; } } diff --git a/bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/internal/provisional/equinox/p2/jarprocessor/IProcessStep.java b/bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/internal/provisional/equinox/p2/jarprocessor/IProcessStep.java index 1479c4c32..e0bd05974 100644 --- a/bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/internal/provisional/equinox/p2/jarprocessor/IProcessStep.java +++ b/bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/internal/provisional/equinox/p2/jarprocessor/IProcessStep.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2008 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 @@ -59,6 +59,7 @@ public interface IProcessStep { * @param input * @param inf * @param containers inf properties for containing jars, innermost jar is first on the list + * @return <code>true</code> if the properties file was adjusted, and false othewise */ - public void adjustInf(File input, Properties inf, List containers); + public boolean adjustInf(File input, Properties inf, List containers); } 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 235915696..5e6ec83e9 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 @@ -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 @@ -256,11 +256,13 @@ public class JarProcessor { return input; } - private void adjustInf(File input, Properties inf) { + private boolean adjustInf(File input, Properties inf) { + boolean adjusted = false; for (Iterator iter = steps.iterator(); iter.hasNext();) { IProcessStep step = (IProcessStep) iter.next(); - step.adjustInf(input, inf, containingInfs); + adjusted |= step.adjustInf(input, inf, containingInfs); } + return adjusted; } public File processJar(File input) throws IOException { @@ -307,25 +309,28 @@ public class JarProcessor { Properties inf = Utils.getEclipseInf(workingFile, verbose); extractEntries(jar, tempDir, replacements, inf); + boolean infAdjusted = false; if (inf != null) - adjustInf(workingFile, inf); + infAdjusted = adjustInf(workingFile, inf); //Recreate the jar with replacements. - //TODO: This is not strictly necessary if we didn't change the inf file and didn't change any content - 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(); + //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(); + } + workingFile = tempJar; } - workingFile = tempJar; } //post diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/processors/Pack200ProcessorTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/processors/Pack200ProcessorTest.java index 73c829551..b2b8f93b3 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/processors/Pack200ProcessorTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/artifact/processors/Pack200ProcessorTest.java @@ -68,4 +68,33 @@ public class Pack200ProcessorTest extends TestCase { assertFalse(step.getStatus().isOK()); } + /** + * Tests the case where we are unpacking a file that was not packed by + * our own pack step. In this case the eclipse.inf may not be present + * and we must not attempt to modify it. + * @throws IOException + */ + public void testUnpackFileNotPackedByJarProcessor() throws IOException { + //this test is only applicable if pack200 is available + if (!PackStep.canPack()) + return; + // Setup the processor + ProcessingStep step = new Pack200ProcessorStep(); + ByteArrayOutputStream destination = new ByteArrayOutputStream(); + step.link(destination, new NullProgressMonitor()); + + // drive the source data through the step + Bundle bundle = TestActivator.getContext().getBundle(); + InputStream inputStream = bundle.getEntry("testData/optimizers/bug387557.bundle_1.0.0.201208200951.jar.pack.gz").openStream(); + FileUtils.copyStream(inputStream, true, step, true); + + // Get the expected result + inputStream = bundle.getEntry("testData/optimizers/bug387557.bundle_1.0.0.201208200951.jar").openStream(); + ByteArrayOutputStream expected = new ByteArrayOutputStream(); + FileUtils.copyStream(inputStream, true, expected, true); + + // Compare + assertTrue(Arrays.equals(expected.toByteArray(), destination.toByteArray())); + } + } diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/NewMirrorApplicationArtifactTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/NewMirrorApplicationArtifactTest.java index a79eb95ff..7b240a5ce 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/NewMirrorApplicationArtifactTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/NewMirrorApplicationArtifactTest.java @@ -344,7 +344,7 @@ public class NewMirrorApplicationArtifactTest extends AbstractProvisioningTest { fail(message + " descriptor mismatch"); if (!(expectedFile.exists() && actualFile.exists())) fail(message + " file does not exist"); - assertTrue(expectedFile.length() == actualFile.length()); + assertEquals("Unexpected difference in " + actualFile.getName(), expectedFile.length(), actualFile.length()); continue top; } } diff --git a/bundles/org.eclipse.equinox.p2.tests/testData/optimizers/bug387557.bundle_1.0.0.201208200951.jar b/bundles/org.eclipse.equinox.p2.tests/testData/optimizers/bug387557.bundle_1.0.0.201208200951.jar Binary files differnew file mode 100644 index 000000000..842fc4f1e --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.tests/testData/optimizers/bug387557.bundle_1.0.0.201208200951.jar diff --git a/bundles/org.eclipse.equinox.p2.tests/testData/optimizers/bug387557.bundle_1.0.0.201208200951.jar.pack.gz b/bundles/org.eclipse.equinox.p2.tests/testData/optimizers/bug387557.bundle_1.0.0.201208200951.jar.pack.gz Binary files differnew file mode 100644 index 000000000..7ef9c7a98 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.tests/testData/optimizers/bug387557.bundle_1.0.0.201208200951.jar.pack.gz |