Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDJ Houghton2008-04-08 11:26:37 -0400
committerDJ Houghton2008-04-08 11:26:37 -0400
commit1bd0fc4d9fd9f36388a3194ab2cc57841bf542fe (patch)
tree2c6cd57c6e6dcc91db7833005fbe786f7035e017 /bundles/org.eclipse.equinox.p2.tests.optimizers
parente775868ec9114fad7b95242e3fec9016e6b9056d (diff)
downloadrt.equinox.p2-1bd0fc4d9fd9f36388a3194ab2cc57841bf542fe.tar.gz
rt.equinox.p2-1bd0fc4d9fd9f36388a3194ab2cc57841bf542fe.tar.xz
rt.equinox.p2-1bd0fc4d9fd9f36388a3194ab2cc57841bf542fe.zip
Bug 226142 - Create new test project for testing bundles not in the SDK
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.tests.optimizers')
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.optimizers/.classpath7
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.optimizers/.project28
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.optimizers/.settings/org.eclipse.jdt.core.prefs7
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.optimizers/META-INF/MANIFEST.MF31
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.optimizers/build.properties6
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.optimizers/plugin.xml21
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/optimizers/AllTests.java30
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/optimizers/Bug209233Test.java54
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/optimizers/JBDiffStepTest.java75
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/optimizers/JBDiffZipStepTest.java67
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/optimizers/JarDeltaOptimizerTest.java87
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/optimizers/Pack200OptimizerTest.java77
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/processors/AllTests.java29
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/processors/ArtifactRepositoryMock.java53
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/processors/JBPatchStepTest.java63
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/processors/JBPatchZipStepTest.java82
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/processors/JarDeltaProcessorTest.java73
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/processors/Pack200ProcessorTest.java52
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/repository/processing/Adder.java53
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/repository/processing/AllTests.java27
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/repository/processing/ByteShifter.java73
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/repository/processing/Counter.java84
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/repository/processing/Multiplier.java53
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/repository/processing/ProcessingStepHandlerTest.java211
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/repository/processing/ProcessingStepTest.java108
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/optimizers/AutomatedTests.java29
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/optimizers/TestActivator.java42
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/optimizers/TestData.java168
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/sar/AllTests.java27
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/sar/DirectByteArrayOutputStreamTest.java47
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/sar/SarTest.java150
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.optimizers/testData/jarprocessor.jar.pack.gzbin0 -> 13587 bytes
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.optimizers/testData/optimizers/1_6/org.eclipse.equinox.app_1.0.100.v20071015.jar.pack.gzbin0 -> 34588 bytes
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.optimizers/testData/optimizers/eclipse-3.2-3.3.jbdiffbin0 -> 7935 bytes
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.optimizers/testData/optimizers/eclipse-3.2.exebin0 -> 180224 bytes
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.optimizers/testData/optimizers/eclipse-3.3.exebin0 -> 53248 bytes
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.optimizers/testData/optimizers/org.eclipse.equinox.app_1.0.100.v20071015.jarbin0 -> 78074 bytes
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.optimizers/testData/optimizers/org.eclipse.equinox.app_1.0.100.v20071015.jar.pack.gzbin0 -> 33474 bytes
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.optimizers/testData/optimizers/org.eclipse.jdt_3.2.0-3.3.0.jbdiffbin0 -> 24134 bytes
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.optimizers/testData/optimizers/org.eclipse.jdt_3.2.0.v20060605-1400.njarbin0 -> 40662 bytes
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.optimizers/testData/optimizers/org.eclipse.jdt_3.3.0.v20070607-1300.njarbin0 -> 42387 bytes
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.optimizers/testData/optimizers/testdata_1.0.0.1-2.jarbin0 -> 1893 bytes
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.optimizers/testData/optimizers/testdata_1.0.0.1.jarbin0 -> 1958 bytes
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.optimizers/testData/optimizers/testdata_1.0.0.2.jarbin0 -> 1939 bytes
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.optimizers/testData/sar/alien.zipbin0 -> 1135 bytes
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.optimizers/testData/sar/org.eclipse.jdt_3.2.0.v20060605-1400.jarbin0 -> 40669 bytes
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.optimizers/testData/sar/org.eclipse.jdt_3.2.0.v20060605-1400.sarbin0 -> 50750 bytes
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.optimizers/testData/sar/org.eclipse.jdt_3.3.0.v20070607-1300.jarbin0 -> 42387 bytes
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.optimizers/testData/sar/org.eclipse.jdt_3.3.0.v20070607-1300.sarbin0 -> 57994 bytes
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.optimizers/testData/sar/test.zipbin0 -> 1267 bytes
50 files changed, 1914 insertions, 0 deletions
diff --git a/bundles/org.eclipse.equinox.p2.tests.optimizers/.classpath b/bundles/org.eclipse.equinox.p2.tests.optimizers/.classpath
new file mode 100644
index 000000000..2fbb7a23e
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.optimizers/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/bundles/org.eclipse.equinox.p2.tests.optimizers/.project b/bundles/org.eclipse.equinox.p2.tests.optimizers/.project
new file mode 100644
index 000000000..2bc9a3891
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.optimizers/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.equinox.p2.tests.optimizers</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/bundles/org.eclipse.equinox.p2.tests.optimizers/.settings/org.eclipse.jdt.core.prefs b/bundles/org.eclipse.equinox.p2.tests.optimizers/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 000000000..8114580e9
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.optimizers/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+#Tue Apr 08 11:13:27 EDT 2008
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
+org.eclipse.jdt.core.compiler.compliance=1.4
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.3
diff --git a/bundles/org.eclipse.equinox.p2.tests.optimizers/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.tests.optimizers/META-INF/MANIFEST.MF
new file mode 100644
index 000000000..e16100c27
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.optimizers/META-INF/MANIFEST.MF
@@ -0,0 +1,31 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: p2 Optimizers Test Plug-in
+Bundle-SymbolicName: org.eclipse.equinox.p2.tests.optimizers;singleton:=true
+Bundle-Version: 1.0.0.qualifier
+Bundle-RequiredExecutionEnvironment: J2SE-1.4
+Require-Bundle: org.eclipse.equinox.common;bundle-version="3.4.0",
+ org.junit;bundle-version="3.8.2"
+Export-Package: org.eclipse.equinox.p2.tests.artifact.optimizers,
+ org.eclipse.equinox.p2.tests.artifact.processors,
+ org.eclipse.equinox.p2.tests.artifact.repository.processing,
+ org.eclipse.equinox.p2.tests.sar
+Import-Package: ie.wombat.jbdiff,
+ org.eclipse.equinox.internal.p2.artifact.optimizers,
+ org.eclipse.equinox.internal.p2.artifact.optimizers.jardelta,
+ org.eclipse.equinox.internal.p2.artifact.optimizers.jbdiff,
+ org.eclipse.equinox.internal.p2.artifact.optimizers.pack200,
+ org.eclipse.equinox.internal.p2.artifact.processors.jardelta,
+ org.eclipse.equinox.internal.p2.artifact.processors.jbdiff,
+ org.eclipse.equinox.internal.p2.artifact.processors.pack200,
+ org.eclipse.equinox.internal.p2.artifact.processors.verifier,
+ org.eclipse.equinox.internal.p2.artifact.repository,
+ org.eclipse.equinox.internal.p2.core.helpers,
+ org.eclipse.equinox.internal.p2.metadata,
+ org.eclipse.equinox.internal.p2.sar,
+ org.eclipse.equinox.internal.provisional.p2.artifact.repository,
+ org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing,
+ org.eclipse.equinox.internal.provisional.p2.metadata,
+ org.osgi.framework;version="1.4.0"
+Bundle-ActivationPolicy: lazy
+Bundle-Activator: org.eclipse.equinox.p2.tests.optimizers.TestActivator
diff --git a/bundles/org.eclipse.equinox.p2.tests.optimizers/build.properties b/bundles/org.eclipse.equinox.p2.tests.optimizers/build.properties
new file mode 100644
index 000000000..c832c5c21
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.optimizers/build.properties
@@ -0,0 +1,6 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml,\
+ testData/
diff --git a/bundles/org.eclipse.equinox.p2.tests.optimizers/plugin.xml b/bundles/org.eclipse.equinox.p2.tests.optimizers/plugin.xml
new file mode 100644
index 000000000..d9646386c
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.optimizers/plugin.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.2"?>
+<plugin>
+ <extension
+ point="org.eclipse.equinox.p2.artifact.repository.processingSteps"
+ id="org.eclipse.equinox.p2.processing.ByteShifter">
+ <step class="org.eclipse.equinox.p2.tests.artifact.repository.processing.ByteShifter"/>
+ </extension>
+
+ <extension
+ point="org.eclipse.equinox.p2.artifact.repository.processingSteps"
+ id="org.eclipse.equinox.p2.processing.Adder">
+ <step class="org.eclipse.equinox.p2.tests.artifact.repository.processing.Adder"/>
+ </extension>
+
+ <extension
+ point="org.eclipse.equinox.p2.artifact.repository.processingSteps"
+ id="org.eclipse.equinox.p2.processing.Multiplier">
+ <step class="org.eclipse.equinox.p2.tests.artifact.repository.processing.Multiplier"/>
+ </extension>
+</plugin>
diff --git a/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/optimizers/AllTests.java b/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/optimizers/AllTests.java
new file mode 100644
index 000000000..194be73c0
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/optimizers/AllTests.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG (Stefan Liebig) - initial API and implementation
+ * IBM Corporation - ongoing development
+ *******************************************************************************/
+package org.eclipse.equinox.p2.tests.artifact.optimizers;
+
+import junit.framework.*;
+
+/**
+ * Performs all automated director tests.
+ */
+public class AllTests extends TestCase {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(AllTests.class.getName());
+ suite.addTestSuite(JBDiffStepTest.class);
+ suite.addTestSuite(JBDiffZipStepTest.class);
+ suite.addTestSuite(Pack200OptimizerTest.class);
+ suite.addTestSuite(JarDeltaOptimizerTest.class);
+ suite.addTestSuite(Bug209233Test.class);
+ return suite;
+ }
+}
diff --git a/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/optimizers/Bug209233Test.java b/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/optimizers/Bug209233Test.java
new file mode 100644
index 000000000..97abc5de4
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/optimizers/Bug209233Test.java
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG (Stefan Liebig) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.p2.tests.artifact.optimizers;
+
+import ie.wombat.jbdiff.JBDiff;
+import java.io.*;
+import java.util.Arrays;
+import junit.framework.TestCase;
+import org.eclipse.equinox.internal.p2.core.helpers.FileUtils;
+import org.eclipse.equinox.p2.tests.optimizers.TestData;
+
+/**
+ * ... <code>Bug209233Test</code> ...
+ */
+public class Bug209233Test extends TestCase {
+
+ // public void testGenerateTestDataDiff() throws IOException {
+ // File predecessor = TestData.getTempFile("sar", "org.eclipse.jdt_3.2.0.v20060605-1400.sar");
+ // File current = TestData.getTempFile("sar", "org.eclipse.jdt_3.3.0.v20070607-1300.sar");
+ // File diff = File.createTempFile("org.eclipse.jdt_3.2.0-3.3.0~", ".jbdiff");
+ // JBDiff.bsdiff(predecessor, current, diff);
+ // }
+
+ public void testDiffJdt32SarToJdt33Sar() throws IOException {
+
+ InputStream current = TestData.get("sar", "org.eclipse.jdt_3.3.0.v20070607-1300.sar");
+ ByteArrayOutputStream currentBS = new ByteArrayOutputStream();
+ FileUtils.copyStream(current, true, currentBS, true);
+ byte[] currentBytes = currentBS.toByteArray();
+
+ InputStream predecessor = TestData.get("sar", "org.eclipse.jdt_3.2.0.v20060605-1400.sar");
+ ByteArrayOutputStream predecessorBS = new ByteArrayOutputStream();
+ FileUtils.copyStream(predecessor, true, predecessorBS, true);
+ byte[] predecessorBytes = predecessorBS.toByteArray();
+
+ byte[] actualBytes = JBDiff.bsdiff(predecessorBytes, predecessorBytes.length, currentBytes, currentBytes.length);
+
+ InputStream expected = TestData.get("optimizers", "org.eclipse.jdt_3.2.0-3.3.0.jbdiff");
+ ByteArrayOutputStream expectedBS = new ByteArrayOutputStream();
+ FileUtils.copyStream(expected, true, expectedBS, true);
+ byte[] expectedBytes = expectedBS.toByteArray();
+
+ assertEquals("Different lengths.", expectedBytes.length, actualBytes.length);
+ assertTrue("Different bytes.", Arrays.equals(expectedBytes, actualBytes));
+ }
+}
diff --git a/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/optimizers/JBDiffStepTest.java b/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/optimizers/JBDiffStepTest.java
new file mode 100644
index 000000000..07501ff5c
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/optimizers/JBDiffStepTest.java
@@ -0,0 +1,75 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG (Stefan Liebig) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.p2.tests.artifact.optimizers;
+
+import java.io.*;
+import java.util.Arrays;
+import junit.framework.TestCase;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.equinox.internal.p2.artifact.optimizers.jbdiff.JBDiffStep;
+import org.eclipse.equinox.internal.p2.core.helpers.FileUtils;
+import org.eclipse.equinox.internal.p2.metadata.ArtifactKey;
+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.ArtifactDescriptor;
+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository;
+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStepDescriptor;
+import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey;
+import org.eclipse.equinox.p2.tests.artifact.processors.ArtifactRepositoryMock;
+import org.eclipse.equinox.p2.tests.optimizers.TestData;
+import org.osgi.framework.Version;
+
+/**
+ * Test the <code>JBDiffStepTest</code> processing step.
+ */
+public class JBDiffStepTest extends TestCase {
+
+ // public void testGenerateTestDataExe32To33() throws IOException {
+ // File exe32 = TestData.getTempFile("optimizers", "eclipse-3.2.exe");
+ // File exe33 = TestData.getTempFile("optimizers", "eclipse-3.3.exe");
+ // File diff = File.createTempFile("eclipse-3.2-3.3~", ".jbdiff");
+ // JBDiff.bsdiff(exe32, exe33, diff);
+ // }
+
+ /**
+ * Test diffing the launcher.
+ *
+ * @throws IOException
+ */
+ public void testDiffEclipseExe32to33() throws IOException {
+
+ IArtifactRepository repoMock = ArtifactRepositoryMock.getMock("testData/optimizers/eclipse-3.2.exe");
+ MockableJBDiffStep differ = new MockableJBDiffStep(repoMock);
+ ProcessingStepDescriptor stepDescriptor = new ProcessingStepDescriptor("id", "ns,cl,id1,1.0", true);
+ IArtifactKey key = new ArtifactKey("cl", "id1", new Version("1.1"));
+ ArtifactDescriptor descriptor = new ArtifactDescriptor(key);
+ differ.initialize(stepDescriptor, descriptor);
+
+ ByteArrayOutputStream destination = new ByteArrayOutputStream();
+ differ.link(destination, new NullProgressMonitor());
+
+ InputStream inputStream = TestData.get("optimizers", "eclipse-3.3.exe");
+ FileUtils.copyStream(inputStream, true, differ, true);
+
+ inputStream = TestData.get("optimizers", "eclipse-3.2-3.3.jbdiff");
+ ByteArrayOutputStream expected = new ByteArrayOutputStream();
+ FileUtils.copyStream(inputStream, true, expected, true);
+ assertTrue(Arrays.equals(expected.toByteArray(), destination.toByteArray()));
+ }
+
+ /**
+ * Need to inject a repository!
+ */
+ private static class MockableJBDiffStep extends JBDiffStep {
+ public MockableJBDiffStep(IArtifactRepository repository) {
+ super(repository);
+ }
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/optimizers/JBDiffZipStepTest.java b/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/optimizers/JBDiffZipStepTest.java
new file mode 100644
index 000000000..7fb727394
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/optimizers/JBDiffZipStepTest.java
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG (Stefan Liebig) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.p2.tests.artifact.optimizers;
+
+import java.io.*;
+import java.util.Arrays;
+import junit.framework.TestCase;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.equinox.internal.p2.artifact.optimizers.jbdiff.JBDiffZipStep;
+import org.eclipse.equinox.internal.p2.core.helpers.FileUtils;
+import org.eclipse.equinox.internal.p2.metadata.ArtifactKey;
+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.ArtifactDescriptor;
+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository;
+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStepDescriptor;
+import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey;
+import org.eclipse.equinox.p2.tests.artifact.processors.ArtifactRepositoryMock;
+import org.eclipse.equinox.p2.tests.optimizers.TestData;
+import org.osgi.framework.Version;
+
+/**
+ * Test the <code>JBDiffZipTest</code> processing step.
+ */
+public class JBDiffZipStepTest extends TestCase {
+
+ /**
+ * Test diffing the <b>normalized</b> jars. This is indicated by the extension ".njar".
+ *
+ * @throws IOException
+ */
+ public void testDiffJdt32to33() throws IOException {
+ IArtifactRepository repoMock = ArtifactRepositoryMock.getMock("testData/optimizers/org.eclipse.jdt_3.2.0.v20060605-1400.njar");
+ MockableJBDiffZipStep differ = new MockableJBDiffZipStep(repoMock);
+ ProcessingStepDescriptor stepDescriptor = new ProcessingStepDescriptor("id", "ns,cl,id1,1.0", true);
+ IArtifactKey key = new ArtifactKey("cl", "id1", new Version("1.1"));
+ ArtifactDescriptor descriptor = new ArtifactDescriptor(key);
+ differ.initialize(stepDescriptor, descriptor);
+
+ ByteArrayOutputStream destination = new ByteArrayOutputStream();
+ differ.link(destination, new NullProgressMonitor());
+
+ InputStream inputStream = TestData.get("optimizers", "org.eclipse.jdt_3.3.0.v20070607-1300.njar");
+ FileUtils.copyStream(inputStream, true, differ, true);
+
+ inputStream = TestData.get("optimizers", "org.eclipse.jdt_3.2.0-3.3.0.jbdiff");
+ ByteArrayOutputStream expected = new ByteArrayOutputStream();
+ FileUtils.copyStream(inputStream, true, expected, true);
+
+ assertTrue("Different diff bytes.", Arrays.equals(expected.toByteArray(), destination.toByteArray()));
+ }
+
+ /**
+ * Need to inject a repository!
+ */
+ private static class MockableJBDiffZipStep extends JBDiffZipStep {
+ public MockableJBDiffZipStep(IArtifactRepository repository) {
+ super(repository);
+ }
+ }
+}
diff --git a/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/optimizers/JarDeltaOptimizerTest.java b/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/optimizers/JarDeltaOptimizerTest.java
new file mode 100644
index 000000000..dd6595e12
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/optimizers/JarDeltaOptimizerTest.java
@@ -0,0 +1,87 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG (Stefan Liebig) - initial API and implementation
+ * IBM Corporation - ongoing development
+ *******************************************************************************/
+package org.eclipse.equinox.p2.tests.artifact.optimizers;
+
+import java.io.*;
+import java.util.zip.ZipInputStream;
+import junit.framework.TestCase;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.equinox.internal.p2.artifact.optimizers.jardelta.JarDeltaOptimizerStep;
+import org.eclipse.equinox.internal.p2.core.helpers.FileUtils;
+import org.eclipse.equinox.internal.p2.metadata.ArtifactKey;
+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.ArtifactDescriptor;
+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository;
+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStep;
+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStepDescriptor;
+import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey;
+import org.eclipse.equinox.p2.tests.artifact.processors.ArtifactRepositoryMock;
+import org.eclipse.equinox.p2.tests.optimizers.TestData;
+import org.osgi.framework.Version;
+
+/**
+ * Test the <code>JarDelta</code> processing step.
+ */
+public class JarDeltaOptimizerTest extends TestCase {
+
+ // public void testPrepare() throws IOException {
+ // IArtifactRepository repoMock = ArtifactRepositoryMock.getMock("testData/optimizers/testdata_1.0.0.1.jar");
+ // ProcessingStep step = new MockableJarDeltaOptimizerStep(repoMock);
+ // ProcessingStepDescriptor stepDescriptor = new ProcessingStepDescriptor("id", "ns,cl,id1,1.0.0.1", true);
+ // IArtifactKey key = new ArtifactKey("ns", "cl", "id1", new Version("1.0.0.2"));
+ // ArtifactDescriptor descriptor = new ArtifactDescriptor(key);
+ // step.initialize(stepDescriptor, descriptor);
+ // ByteArrayOutputStream destination = new ByteArrayOutputStream();
+ // step.link(destination, new NullProgressMonitor());
+ //
+ // InputStream inputStream = TestActivator.getContext().getBundle().getEntry("testData/optimizers/testdata_1.0.0.2.jar").openStream();
+ // FileUtils.copyStream(inputStream, true, step, true);
+ // destination.close();
+ //
+ // inputStream = new ByteArrayInputStream(destination.toByteArray());
+ // FileOutputStream file = new FileOutputStream("d:/jardelta.jar");
+ // FileUtils.copyStream(inputStream, true, file, true);
+ // }
+
+ public void testOptimization() throws IOException {
+ IArtifactRepository repoMock = ArtifactRepositoryMock.getMock("testData/optimizers/testdata_1.0.0.1.jar");
+ ProcessingStep step = new MockableJarDeltaOptimizerStep(repoMock);
+ ProcessingStepDescriptor stepDescriptor = new ProcessingStepDescriptor("id", "ns,cl,id1,1.0.0.1", true);
+ IArtifactKey key = new ArtifactKey("cl", "id1", new Version("1.0.0.2"));
+ ArtifactDescriptor descriptor = new ArtifactDescriptor(key);
+ step.initialize(stepDescriptor, descriptor);
+ ByteArrayOutputStream destination = new ByteArrayOutputStream();
+ step.link(destination, new NullProgressMonitor());
+
+ InputStream inputStream = TestData.get("optimizers", "testdata_1.0.0.2.jar");
+ FileUtils.copyStream(inputStream, true, step, true);
+ destination.close();
+
+ inputStream = TestData.get("optimizers", "testdata_1.0.0.1-2.jar");
+ ByteArrayOutputStream expected = new ByteArrayOutputStream();
+ FileUtils.copyStream(inputStream, true, expected, true);
+
+ ZipInputStream expectedJar = new ZipInputStream(new ByteArrayInputStream(expected.toByteArray()));
+ ZipInputStream testJar = new ZipInputStream(new ByteArrayInputStream(destination.toByteArray()));
+ TestData.assertEquals(expectedJar, testJar);
+ expectedJar.close();
+ testJar.close();
+ }
+
+ /**
+ * Need to inject a repository!
+ */
+ private static class MockableJarDeltaOptimizerStep extends JarDeltaOptimizerStep {
+ public MockableJarDeltaOptimizerStep(IArtifactRepository repository) {
+ super(repository);
+ }
+ }
+}
diff --git a/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/optimizers/Pack200OptimizerTest.java b/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/optimizers/Pack200OptimizerTest.java
new file mode 100644
index 000000000..f61c78883
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/optimizers/Pack200OptimizerTest.java
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2008 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.p2.tests.artifact.optimizers;
+
+import java.io.*;
+import java.util.Arrays;
+import junit.framework.TestCase;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.equinox.internal.p2.artifact.optimizers.pack200.Pack200OptimizerStep;
+import org.eclipse.equinox.internal.p2.core.helpers.FileUtils;
+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStep;
+import org.eclipse.equinox.p2.tests.optimizers.TestActivator;
+import org.osgi.framework.Bundle;
+
+public class Pack200OptimizerTest extends TestCase {
+
+ public Pack200OptimizerTest(String name) {
+ super(name);
+ }
+
+ public Pack200OptimizerTest() {
+ super("");
+ }
+
+ // public void testPrepare() throws IOException {
+ // // Setup the step
+ // ProcessingStep step = new Pack200OptimizerStep();
+ // FileOutputStream destination = new FileOutputStream("c:/packed.pack.gz");
+ // step.link(destination, new NullProgressMonitor());
+ //
+ // // drive the source data through the step
+ // Bundle bundle = TestActivator.getContext().getBundle();
+ // InputStream inputStream = bundle.getEntry("testData/optimizers/org.eclipse.equinox.app_1.0.100.v20071015.jar").openStream();
+ // FileUtils.copyStream(inputStream, true, step, true);
+ //
+ // destination.close();
+ // }
+
+ public void testPack() throws IOException {
+ // Setup the step
+ ProcessingStep step = new Pack200OptimizerStep();
+ 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/org.eclipse.equinox.app_1.0.100.v20071015.jar").openStream();
+ FileUtils.copyStream(inputStream, true, step, true);
+
+ // Get the test data. The Sun 1.6.0_01 JRE produces a different packed file
+ // then the IBM V5 JRE, so both versions of the test data are maintained.
+ // TODO: investigate this? Is the difference spurious? Are there differences
+ // in the pack200 results for other JREs? Do we need a more general
+ // solution to the problem?
+ String javaVersion = System.getProperty("java.version");
+ boolean is1_6 = (javaVersion.compareTo("1.6") > 0 ? true : false);
+
+ if (!is1_6) {
+ inputStream = bundle.getEntry("testData/optimizers/org.eclipse.equinox.app_1.0.100.v20071015.jar.pack.gz").openStream();
+ } else {
+ inputStream = bundle.getEntry("testData/optimizers/1_6/org.eclipse.equinox.app_1.0.100.v20071015.jar.pack.gz").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.optimizers/src/org/eclipse/equinox/p2/tests/artifact/processors/AllTests.java b/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/processors/AllTests.java
new file mode 100644
index 000000000..ab6d5f8cd
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/processors/AllTests.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG (Stefan Liebig) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.p2.tests.artifact.processors;
+
+import junit.framework.*;
+
+/**
+ * Performs all automated director tests.
+ */
+public class AllTests extends TestCase {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(AllTests.class.getName());
+ suite.addTestSuite(JBPatchStepTest.class);
+ suite.addTestSuite(JBPatchZipStepTest.class);
+ suite.addTestSuite(JarDeltaProcessorTest.class);
+ suite.addTestSuite(Pack200ProcessorTest.class);
+ return suite;
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/processors/ArtifactRepositoryMock.java b/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/processors/ArtifactRepositoryMock.java
new file mode 100644
index 000000000..a2939aed2
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/processors/ArtifactRepositoryMock.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG (Stefan Liebig) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.p2.tests.artifact.processors;
+
+import java.io.*;
+import java.lang.reflect.*;
+import org.eclipse.core.runtime.*;
+import org.eclipse.equinox.internal.p2.core.helpers.FileUtils;
+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactDescriptor;
+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository;
+import org.eclipse.equinox.p2.tests.optimizers.TestActivator;
+
+/**
+ * Mock the getArtifact() needed to locate the predecessor.
+ */
+public class ArtifactRepositoryMock implements InvocationHandler {
+
+ private String artifactResource;
+
+ public static IArtifactRepository getMock(String artifactResource) {
+ return (IArtifactRepository) Proxy.newProxyInstance(IArtifactRepository.class.getClassLoader(), new Class[] {IArtifactRepository.class}, new ArtifactRepositoryMock(artifactResource));
+ }
+
+ private ArtifactRepositoryMock(String artifactResource) {
+ this.artifactResource = artifactResource;
+ }
+
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ if (!method.getName().equals("getArtifact"))
+ throw new RuntimeException("Unexpected usage!");
+
+ return getArtifact((IArtifactDescriptor) args[0], (OutputStream) args[1], (IProgressMonitor) args[2]);
+ }
+
+ private IStatus getArtifact(IArtifactDescriptor descriptor, OutputStream destination, IProgressMonitor monitor) {
+ InputStream inputStream;
+ try {
+ inputStream = TestActivator.getContext().getBundle().getEntry(artifactResource).openStream();
+ FileUtils.copyStream(inputStream, true, destination, true);
+ return Status.OK_STATUS;
+ } catch (IOException e) {
+ return new Status(IStatus.ERROR, TestActivator.PI, ":-(", e);
+ }
+ }
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/processors/JBPatchStepTest.java b/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/processors/JBPatchStepTest.java
new file mode 100644
index 000000000..77eee5c0d
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/processors/JBPatchStepTest.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG (Stefan Liebig) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.p2.tests.artifact.processors;
+
+import java.io.*;
+import java.util.Arrays;
+import junit.framework.TestCase;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.equinox.internal.p2.artifact.processors.jbdiff.JBPatchStep;
+import org.eclipse.equinox.internal.p2.core.helpers.FileUtils;
+import org.eclipse.equinox.internal.p2.metadata.ArtifactKey;
+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.ArtifactDescriptor;
+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository;
+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStep;
+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStepDescriptor;
+import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey;
+import org.eclipse.equinox.p2.tests.optimizers.TestData;
+import org.osgi.framework.Version;
+
+/**
+ * Test the <code>JBPatchStep</code>
+ *
+ */
+public class JBPatchStepTest extends TestCase {
+
+ public void testPatchEclipseExe32to33() throws IOException {
+ IArtifactRepository repoMock = ArtifactRepositoryMock.getMock("testData/optimizers/eclipse-3.2.exe");
+ ProcessingStep patcher = new MockableJBPatchStep(repoMock);
+ ProcessingStepDescriptor descriptor = new ProcessingStepDescriptor("id", "ns,cl,id1,1.0", true);
+ IArtifactKey key = new ArtifactKey("cl", "id1", new Version("1.1"));
+ ArtifactDescriptor context = new ArtifactDescriptor(key);
+ patcher.initialize(descriptor, context);
+
+ ByteArrayOutputStream destination = new ByteArrayOutputStream();
+ patcher.link(destination, new NullProgressMonitor());
+
+ InputStream inputStream = TestData.get("optimizers", "eclipse-3.2-3.3.jbdiff");
+ FileUtils.copyStream(inputStream, true, patcher, true);
+
+ inputStream = TestData.get("optimizers", "eclipse-3.3.exe");
+ ByteArrayOutputStream expected = new ByteArrayOutputStream();
+ FileUtils.copyStream(inputStream, true, expected, true);
+ assertTrue(Arrays.equals(expected.toByteArray(), destination.toByteArray()));
+ }
+
+ /**
+ * Need to inject a repository!
+ */
+ private static class MockableJBPatchStep extends JBPatchStep {
+ public MockableJBPatchStep(IArtifactRepository repository) {
+ super.repository = repository;
+ }
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/processors/JBPatchZipStepTest.java b/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/processors/JBPatchZipStepTest.java
new file mode 100644
index 000000000..fb73e93fb
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/processors/JBPatchZipStepTest.java
@@ -0,0 +1,82 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG (Stefan Liebig) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.p2.tests.artifact.processors;
+
+import java.io.*;
+import java.util.Arrays;
+import junit.framework.TestCase;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.equinox.internal.p2.artifact.processors.jbdiff.JBPatchZipStep;
+import org.eclipse.equinox.internal.p2.core.helpers.FileUtils;
+import org.eclipse.equinox.internal.p2.metadata.ArtifactKey;
+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.ArtifactDescriptor;
+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository;
+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStep;
+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStepDescriptor;
+import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey;
+import org.eclipse.equinox.p2.tests.optimizers.TestData;
+import org.osgi.framework.Version;
+
+/**
+ * Test the <code>JBPatchZipStep</code> processing step.
+ */
+public class JBPatchZipStepTest extends TestCase {
+
+ // /**
+ // * This is a disabled "unit test" that was used to generate the data needed for real test.
+ // * @throws IOException
+ // */
+ // public void testGenerateTestData() throws IOException {
+ //
+ // File sar32 = TestData.getTempFile("sar", "org.eclipse.jdt_3.2.0.v20060605-1400.sar");
+ // File sar33 = TestData.getTempFile("sar", "org.eclipse.jdt_3.3.0.v20070607-1300.sar");
+ //
+ // File diff = File.createTempFile("org.eclipse.jdt_3.2.0-3.3.0", ".jbdiff");
+ // JBDiff.bsdiff(sar32, sar33, diff);
+ // }
+
+ /**
+ * Test patching the <b>normalized</b> jars. This is indicated by the extension ".njar".
+ *
+ * @throws IOException
+ */
+ public void testPatchOrgEclipseJdt32to33() throws IOException {
+
+ IArtifactRepository repoMock = ArtifactRepositoryMock.getMock("testData/optimizers/org.eclipse.jdt_3.2.0.v20060605-1400.njar");
+ ProcessingStep patcher = new MockableJBPatchZipStep(repoMock);
+ ProcessingStepDescriptor descriptor = new ProcessingStepDescriptor("id", "ns,cl,id1,1.0", true);
+ IArtifactKey key = new ArtifactKey("cl", "id1", new Version("1.1"));
+ ArtifactDescriptor context = new ArtifactDescriptor(key);
+ patcher.initialize(descriptor, context);
+
+ ByteArrayOutputStream destination = new ByteArrayOutputStream();
+ patcher.link(destination, new NullProgressMonitor());
+
+ InputStream inputStream = TestData.get("optimizers", "org.eclipse.jdt_3.2.0-3.3.0.jbdiff");
+ FileUtils.copyStream(inputStream, true, patcher, true);
+
+ inputStream = TestData.get("optimizers", "org.eclipse.jdt_3.3.0.v20070607-1300.njar");
+ ByteArrayOutputStream expected = new ByteArrayOutputStream();
+ FileUtils.copyStream(inputStream, true, expected, true);
+
+ assertTrue("Different resulting njar.", Arrays.equals(expected.toByteArray(), destination.toByteArray()));
+ }
+
+ /**
+ * Need to inject a repository!
+ */
+ private static class MockableJBPatchZipStep extends JBPatchZipStep {
+ public MockableJBPatchZipStep(IArtifactRepository repository) {
+ super.repository = repository;
+ }
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/processors/JarDeltaProcessorTest.java b/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/processors/JarDeltaProcessorTest.java
new file mode 100644
index 000000000..a20d72de5
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/processors/JarDeltaProcessorTest.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2008 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ * compeople AG (Stefan Liebig)
+ *******************************************************************************/
+package org.eclipse.equinox.p2.tests.artifact.processors;
+
+import java.io.*;
+import java.util.zip.ZipInputStream;
+import junit.framework.TestCase;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.equinox.internal.p2.artifact.processors.jardelta.JarDeltaProcessorStep;
+import org.eclipse.equinox.internal.p2.core.helpers.FileUtils;
+import org.eclipse.equinox.internal.p2.metadata.ArtifactKey;
+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.ArtifactDescriptor;
+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository;
+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStep;
+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStepDescriptor;
+import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey;
+import org.eclipse.equinox.p2.tests.optimizers.TestData;
+import org.osgi.framework.Version;
+
+public class JarDeltaProcessorTest extends TestCase {
+
+ public JarDeltaProcessorTest(String name) {
+ super(name);
+ }
+
+ public JarDeltaProcessorTest() {
+ super("");
+ }
+
+ public void testProcessing() throws IOException {
+ IArtifactRepository repoMock = ArtifactRepositoryMock.getMock("testData/optimizers/testdata_1.0.0.1.jar");
+ ProcessingStep step = new MockableJarDeltaProcessorStep(repoMock);
+ ProcessingStepDescriptor stepDescriptor = new ProcessingStepDescriptor("id", "ns,cl,id1,1.0.0.1", true);
+ IArtifactKey key = new ArtifactKey("cl", "id1", new Version("1.0.0.2"));
+ ArtifactDescriptor descriptor = new ArtifactDescriptor(key);
+ step.initialize(stepDescriptor, descriptor);
+ ByteArrayOutputStream destination = new ByteArrayOutputStream();
+ step.link(destination, new NullProgressMonitor());
+
+ InputStream inputStream = TestData.get("optimizers", "testdata_1.0.0.1-2.jar");
+ FileUtils.copyStream(inputStream, true, step, true);
+ destination.close();
+
+ inputStream = TestData.get("optimizers", "testdata_1.0.0.2.jar");
+ ByteArrayOutputStream expected = new ByteArrayOutputStream();
+ FileUtils.copyStream(inputStream, true, expected, true);
+
+ ZipInputStream expectedJar = new ZipInputStream(new ByteArrayInputStream(expected.toByteArray()));
+ ZipInputStream testJar = new ZipInputStream(new ByteArrayInputStream(destination.toByteArray()));
+ TestData.assertEquals(expectedJar, testJar);
+ expectedJar.close();
+ testJar.close();
+ }
+
+ /**
+ * Need to inject a repository!
+ */
+ private static class MockableJarDeltaProcessorStep extends JarDeltaProcessorStep {
+ public MockableJarDeltaProcessorStep(IArtifactRepository repository) {
+ super();
+ this.repository = repository;
+ }
+ }
+}
diff --git a/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/processors/Pack200ProcessorTest.java b/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/processors/Pack200ProcessorTest.java
new file mode 100644
index 000000000..12b765095
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/processors/Pack200ProcessorTest.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2008 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.p2.tests.artifact.processors;
+
+import java.io.*;
+import java.util.Arrays;
+import junit.framework.TestCase;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.equinox.internal.p2.artifact.processors.pack200.Pack200ProcessorStep;
+import org.eclipse.equinox.internal.p2.core.helpers.FileUtils;
+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStep;
+import org.eclipse.equinox.p2.tests.optimizers.TestActivator;
+import org.osgi.framework.Bundle;
+
+public class Pack200ProcessorTest extends TestCase {
+
+ public Pack200ProcessorTest(String name) {
+ super(name);
+ }
+
+ public Pack200ProcessorTest() {
+ super("");
+ }
+
+ public void testUnpack() throws IOException {
+ // 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/org.eclipse.equinox.app_1.0.100.v20071015.jar.pack.gz").openStream();
+ FileUtils.copyStream(inputStream, true, step, true);
+
+ // Get the test data
+ inputStream = bundle.getEntry("testData/optimizers/org.eclipse.equinox.app_1.0.100.v20071015.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.optimizers/src/org/eclipse/equinox/p2/tests/artifact/repository/processing/Adder.java b/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/repository/processing/Adder.java
new file mode 100644
index 000000000..50b7840c9
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/repository/processing/Adder.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+* Copyright (c) 2007 compeople AG 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
+* http://www.eclipse.org/legal/epl-v10.html
+*
+* Contributors:
+* compeople AG (Stefan Liebig) - initial API and implementation
+* IBM - continuing development
+*******************************************************************************/
+package org.eclipse.equinox.p2.tests.artifact.repository.processing;
+
+import java.io.IOException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.equinox.internal.p2.artifact.repository.Activator;
+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactDescriptor;
+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStep;
+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStepDescriptor;
+
+public class Adder extends ProcessingStep {
+
+ protected int operand;
+
+ public Adder() {
+ // needed
+ }
+
+ public Adder(int operand) {
+ super();
+ this.operand = operand;
+ }
+
+ public void initialize(ProcessingStepDescriptor descriptor, IArtifactDescriptor context) {
+ super.initialize(descriptor, context);
+ try {
+ operand = Integer.valueOf(descriptor.getData()).intValue();
+ } catch (NumberFormatException e) {
+ int code = descriptor.isRequired() ? IStatus.ERROR : IStatus.INFO;
+ setStatus(new Status(code, Activator.ID, "Adder operand specification invalid", e));
+ return;
+ }
+ }
+
+ public void write(int b) throws IOException {
+ getDestination().write(b + operand);
+ }
+
+ public void close() throws IOException {
+ super.close();
+ }
+}
diff --git a/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/repository/processing/AllTests.java b/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/repository/processing/AllTests.java
new file mode 100644
index 000000000..0eb941c04
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/repository/processing/AllTests.java
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * Copyright (c) 2007 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.p2.tests.artifact.repository.processing;
+
+import junit.framework.*;
+
+/**
+ * Performs all automated director tests.
+ */
+public class AllTests extends TestCase {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(AllTests.class.getName());
+ suite.addTestSuite(ProcessingStepHandlerTest.class);
+ suite.addTestSuite(ProcessingStepTest.class);
+ return suite;
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/repository/processing/ByteShifter.java b/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/repository/processing/ByteShifter.java
new file mode 100644
index 000000000..ff6e04ee6
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/repository/processing/ByteShifter.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+* Copyright (c) 2007 compeople AG 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
+* http://www.eclipse.org/legal/epl-v10.html
+*
+* Contributors:
+* compeople AG (Stefan Liebig) - initial API and implementation
+* IBM - continuing development
+*******************************************************************************/
+package org.eclipse.equinox.p2.tests.artifact.repository.processing;
+
+import java.io.IOException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.equinox.internal.p2.artifact.repository.Activator;
+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactDescriptor;
+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStep;
+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStepDescriptor;
+
+public class ByteShifter extends ProcessingStep {
+
+ protected int operand;
+
+ public ByteShifter() {
+ super();
+ }
+
+ public ByteShifter(int shiftLeft) {
+ super();
+ this.operand = shiftLeft;
+ basicInitialize(null);
+ }
+
+ private void basicInitialize(ProcessingStepDescriptor descriptor) {
+ // if the status is already set to something that not ok, we've already found a problem.
+ if (!getStatus().isOK())
+ return;
+
+ int code;
+ // if there is a descriptor, decide if the "bad case" is an error or info. If no
+ // descriptor then default to error.
+ if (descriptor != null)
+ code = descriptor.isRequired() ? IStatus.ERROR : IStatus.INFO;
+ else
+ code = IStatus.ERROR;
+
+ // finally, check the actual setup and set the status.
+ if (operand <= 0)
+ setStatus(new Status(code, Activator.ID, "ByteShifter operand invalid: " + operand));
+ }
+
+ public void initialize(ProcessingStepDescriptor descriptor, IArtifactDescriptor context) {
+ super.initialize(descriptor, context);
+ try {
+ operand = Integer.valueOf(descriptor.getData()).intValue();
+ } catch (NumberFormatException e) {
+ int code = descriptor.isRequired() ? IStatus.ERROR : IStatus.INFO;
+ setStatus(new Status(code, Activator.ID, "ByteShifter operand specification invalid", e));
+ return;
+ }
+ basicInitialize(descriptor);
+ }
+
+ public void write(int b) throws IOException {
+ getDestination().write(b == -1 ? b : b << operand);
+ }
+
+ public IStatus getStatus() {
+ return Status.OK_STATUS;
+ }
+}
diff --git a/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/repository/processing/Counter.java b/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/repository/processing/Counter.java
new file mode 100644
index 000000000..008b05370
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/repository/processing/Counter.java
@@ -0,0 +1,84 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2008 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.p2.tests.artifact.repository.processing;
+
+import java.io.IOException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.equinox.internal.p2.artifact.repository.Activator;
+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactDescriptor;
+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStep;
+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStepDescriptor;
+
+public class Counter extends ProcessingStep {
+
+ protected long size = -1;
+ long total = 0;
+
+ public Counter() {
+ // needed
+ }
+
+ public Counter(long size) {
+ super();
+ this.size = size;
+ basicInitialize(null);
+ }
+
+ private void basicInitialize(ProcessingStepDescriptor descriptor) {
+ // if the status is already set to something that not ok, we've already found a problem.
+ if (!getStatus().isOK())
+ return;
+
+ int code;
+ // if there is a descriptor, decide if the "bad case" is an error or info. If no
+ // descriptor then default to error.
+ if (descriptor != null)
+ code = descriptor.isRequired() ? IStatus.ERROR : IStatus.INFO;
+ else
+ code = IStatus.ERROR;
+
+ // finally, check the actual setup and set the status.
+ if (size != -1)
+ setStatus(new Status(code, Activator.ID, "Counter size not set"));
+ }
+
+ public void initialize(ProcessingStepDescriptor descriptor, IArtifactDescriptor context) {
+ super.initialize(descriptor, context);
+ String data = descriptor.getData();
+ if (data == null)
+ return;
+ try {
+ if (data.equals("download"))
+ size = Long.parseLong(context.getProperty(IArtifactDescriptor.DOWNLOAD_SIZE));
+ else if (data.equals("artifact"))
+ size = Long.parseLong(context.getProperty(IArtifactDescriptor.ARTIFACT_SIZE));
+ else
+ size = Long.parseLong(data);
+ } catch (NumberFormatException e) {
+ int code = descriptor.isRequired() ? IStatus.ERROR : IStatus.INFO;
+ setStatus(new Status(code, Activator.ID, "Counter size specification invalid", e));
+ return;
+ }
+ basicInitialize(descriptor);
+ }
+
+ public void write(int b) throws IOException {
+ total++;
+ getDestination().write(b);
+ }
+
+ public void close() throws IOException {
+ super.close();
+ if (total != size)
+ setStatus(new Status(IStatus.WARNING, "plugin id", "Size mismatch. Was " + total + " should have been " + size));
+ }
+}
diff --git a/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/repository/processing/Multiplier.java b/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/repository/processing/Multiplier.java
new file mode 100644
index 000000000..4dae1cc20
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/repository/processing/Multiplier.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+* Copyright (c) 2007 compeople AG 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
+* http://www.eclipse.org/legal/epl-v10.html
+*
+* Contributors:
+* compeople AG (Stefan Liebig) - initial API and implementation
+* IBM - continuing development
+*******************************************************************************/
+package org.eclipse.equinox.p2.tests.artifact.repository.processing;
+
+import java.io.IOException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.equinox.internal.p2.artifact.repository.Activator;
+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactDescriptor;
+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStep;
+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStepDescriptor;
+
+public class Multiplier extends ProcessingStep {
+
+ protected int operand;
+
+ public Multiplier() {
+ // needed
+ }
+
+ public Multiplier(int operand) {
+ super();
+ this.operand = operand;
+ }
+
+ public void initialize(ProcessingStepDescriptor descriptor, IArtifactDescriptor context) {
+ super.initialize(descriptor, context);
+ try {
+ operand = Integer.valueOf(descriptor.getData()).intValue();
+ } catch (NumberFormatException e) {
+ int code = descriptor.isRequired() ? IStatus.ERROR : IStatus.INFO;
+ setStatus(new Status(code, Activator.ID, "Multiplier operand specification invalid", e));
+ return;
+ }
+ }
+
+ public void write(int b) throws IOException {
+ getDestination().write(b == -1 ? b : b * operand);
+ }
+
+ public void close() throws IOException {
+ super.close();
+ }
+}
diff --git a/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/repository/processing/ProcessingStepHandlerTest.java b/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/repository/processing/ProcessingStepHandlerTest.java
new file mode 100644
index 000000000..14293a951
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/repository/processing/ProcessingStepHandlerTest.java
@@ -0,0 +1,211 @@
+/*******************************************************************************
+* Copyright (c) 2007 compeople AG 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
+* http://www.eclipse.org/legal/epl-v10.html
+*
+* Contributors:
+* compeople AG (Stefan Liebig) - initial API and implementation
+* IBM - continuing development
+*******************************************************************************/
+package org.eclipse.equinox.p2.tests.artifact.repository.processing;
+
+import java.io.*;
+import java.util.Arrays;
+import junit.framework.TestCase;
+import org.eclipse.core.runtime.*;
+import org.eclipse.equinox.internal.p2.artifact.processors.pack200.Pack200ProcessorStep;
+import org.eclipse.equinox.internal.p2.artifact.processors.verifier.MD5Verifier;
+import org.eclipse.equinox.internal.p2.core.helpers.FileUtils;
+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.*;
+import org.eclipse.equinox.p2.tests.optimizers.TestActivator;
+
+public class ProcessingStepHandlerTest extends TestCase {
+
+ // private static final int BUFFER_SIZE = 8 * 1024;
+
+ ProcessingStepHandler handler = new ProcessingStepHandler();
+ IProgressMonitor monitor = new NullProgressMonitor();
+
+ public void testExecuteNoPSs() throws IOException {
+ ProcessingStepDescriptor[] descriptors = new ProcessingStepDescriptor[0];
+ OutputStream result = new ByteArrayOutputStream(10);
+ OutputStream testStream = handler.createAndLink(descriptors, null, result, monitor);
+ testStream.write("Test".getBytes());
+ testStream.close();
+ assertEquals("Test", result.toString());
+ }
+
+ public void testExecuteOneByteShifterPS() throws IOException {
+ ProcessingStep[] steps = new ProcessingStep[] {new ByteShifter(1)};
+ ByteArrayOutputStream result = new ByteArrayOutputStream(10);
+ OutputStream testStream = handler.link(steps, result, monitor);
+ testStream.write(new byte[] {1});
+ testStream.close();
+ assertTrue(Arrays.equals(new byte[] {2}, result.toByteArray()));
+ }
+
+ public void testExecuteTwoByteShifterPSs() throws IOException {
+ ProcessingStep[] steps = new ProcessingStep[] {new ByteShifter(1), new ByteShifter(2)};
+ ByteArrayOutputStream result = new ByteArrayOutputStream(10);
+ OutputStream testStream = handler.link(steps, result, monitor);
+ testStream.write(new byte[] {1});
+ testStream.close();
+ assertTrue(Arrays.equals(new byte[] {8}, result.toByteArray()));
+ }
+
+ public void testExecuteOneMD5VerifierPSOk() throws IOException {
+ ProcessingStep[] steps = new ProcessingStep[] {new MD5Verifier("0cbc6611f5540bd0809a388dc95a615b")};
+ ByteArrayOutputStream result = new ByteArrayOutputStream(10);
+ OutputStream testStream = handler.link(steps, result, monitor);
+ testStream.write("Test".getBytes());
+ testStream.close();
+ assertEquals("Test", result.toString());
+ }
+
+ public void testExecuteOneMD5VerifierPSFails() throws IOException {
+ ProcessingStep[] steps = new ProcessingStep[] {new MD5Verifier("9cbc6611f5540bd0809a388dc95a615b")};
+ ByteArrayOutputStream result = new ByteArrayOutputStream(10);
+ OutputStream testStream = handler.link(steps, result, monitor);
+ testStream.write("Test".getBytes());
+ try {
+ testStream.close();
+ assertEquals("Test", result.toString());
+ assertTrue((ProcessingStepHandler.checkStatus(testStream).getSeverity() == IStatus.ERROR));
+ } catch (IOException e) {
+ assertTrue(true);
+ }
+ }
+
+ public void testExecuteOneByteShifterAndOneMD5VerifierPSOk() throws IOException {
+ // Order of PSs is important!!
+ ProcessingStep[] steps = new ProcessingStep[] {new ByteShifter(1), new MD5Verifier("ceeee507e8db83294600218b4e198897")};
+ ByteArrayOutputStream result = new ByteArrayOutputStream(10);
+ OutputStream testStream = handler.link(steps, result, monitor);
+ testStream.write(new byte[] {1, 2, 3, 4, 5});
+ testStream.close();
+ assertTrue(Arrays.equals(new byte[] {2, 4, 6, 8, 10}, result.toByteArray()));
+ }
+
+ public void testExecuteOneByteShifterAndOneMD5VerifierPSFailWrongOrder() throws IOException {
+ // Order of PSs is important - here it wrong!!
+ ProcessingStep[] steps = new ProcessingStep[] {new MD5Verifier("af476bbaf152a4c39ca4e5c498a88aa0"), new ByteShifter(1)};
+ ByteArrayOutputStream result = new ByteArrayOutputStream(10);
+ OutputStream testStream = handler.link(steps, result, monitor);
+ testStream.write(new byte[] {1, 2, 3, 4, 5});
+ try {
+ testStream.close();
+ assertTrue(Arrays.equals(new byte[] {2, 4, 6, 8, 10}, result.toByteArray()));
+ assertTrue((ProcessingStepHandler.checkStatus(testStream).getSeverity() == IStatus.ERROR));
+ } catch (IOException e) {
+ assertTrue(true);
+ }
+ }
+
+ public void testAssureOrderingOfPSs1() throws IOException {
+ ProcessingStep[] steps = new ProcessingStep[] {new Adder(1), new Multiplier(2)};
+ ByteArrayOutputStream result = new ByteArrayOutputStream(10);
+ OutputStream testStream = handler.link(steps, result, monitor);
+ testStream.write(new byte[] {1, 2, 3, 4, 5});
+ testStream.close();
+ assertTrue(Arrays.equals(new byte[] {4, 6, 8, 10, 12}, result.toByteArray()));
+ }
+
+ public void testAssureOrderingOfPSs2() throws IOException {
+ ProcessingStep[] steps = new ProcessingStep[] {new Multiplier(2), new Adder(1)};
+ ByteArrayOutputStream result = new ByteArrayOutputStream(10);
+ OutputStream testStream = handler.link(steps, result, monitor);
+ testStream.write(new byte[] {1, 2, 3, 4, 5});
+ testStream.close();
+ assertTrue(Arrays.equals(new byte[] {3, 5, 7, 9, 11}, result.toByteArray()));
+ }
+
+ public void testExecuteOnePack200UnpackerPS() throws IOException {
+ ProcessingStepDescriptor[] descriptors = new ProcessingStepDescriptor[] {new ProcessingStepDescriptor("org.eclipse.equinox.p2.processing.Pack200Unpacker", null, true)};
+ ProcessingStep[] steps = handler.create(descriptors, null);
+ ByteArrayOutputStream result = new ByteArrayOutputStream(100000);
+ OutputStream testStream = handler.link(steps, result, monitor);
+ IStatus status = ProcessingStepHandler.checkStatus(testStream);
+ assertTrue("Step is not ready.", status.isOK());
+ InputStream inputStream = TestActivator.getContext().getBundle().getEntry("testData/jarprocessor.jar.pack.gz").openStream();
+ FileUtils.copyStream(inputStream, true, testStream, true);
+ assertEquals(35062, result.size());
+ }
+
+ public void testCreateByteShifterPS() {
+ ProcessingStepDescriptor[] descriptors = new ProcessingStepDescriptor[] {new ProcessingStepDescriptor("org.eclipse.equinox.p2.processing.ByteShifter", "1", true)};
+ ProcessingStep[] steps = handler.create(descriptors, null);
+ assertNotNull(steps);
+ assertEquals(1, steps.length);
+ assertEquals(ByteShifter.class, steps[0].getClass());
+ }
+
+ public void testCreateMD5VerifierPS() {
+ ProcessingStepDescriptor[] descriptors = new ProcessingStepDescriptor[] {new ProcessingStepDescriptor("org.eclipse.equinox.p2.processing.MD5Verifier", "1", true)};
+ ProcessingStep[] steps = handler.create(descriptors, null);
+ assertNotNull(steps);
+ assertEquals(1, steps.length);
+ assertEquals(MD5Verifier.class, steps[0].getClass());
+ }
+
+ public void testCreateAdderPS() {
+ ProcessingStepDescriptor[] descriptors = new ProcessingStepDescriptor[] {new ProcessingStepDescriptor("org.eclipse.equinox.p2.processing.Adder", "1", true)};
+ ProcessingStep[] steps = handler.create(descriptors, null);
+ assertNotNull(steps);
+ assertEquals(1, steps.length);
+ assertEquals(Adder.class, steps[0].getClass());
+ }
+
+ public void testCreateMultiplierPS() {
+ ProcessingStepDescriptor[] descriptors = new ProcessingStepDescriptor[] {new ProcessingStepDescriptor("org.eclipse.equinox.p2.processing.Multiplier", "2", true)};
+ ProcessingStep[] steps = handler.create(descriptors, null);
+ assertNotNull(steps);
+ assertEquals(1, steps.length);
+ assertEquals(Multiplier.class, steps[0].getClass());
+ }
+
+ public void testCreatePack200UnpackerPS() {
+ ProcessingStepDescriptor[] descriptors = new ProcessingStepDescriptor[] {new ProcessingStepDescriptor("org.eclipse.equinox.p2.processing.Pack200Unpacker", null, true)};
+ ProcessingStep[] steps = handler.create(descriptors, null);
+ assertNotNull(steps);
+ assertEquals(1, steps.length);
+ assertEquals(Pack200ProcessorStep.class, steps[0].getClass());
+ }
+
+ public void testCreatePSsAndAssureOrderingOfPSs1() throws IOException {
+ ProcessingStepDescriptor adder = new ProcessingStepDescriptor("org.eclipse.equinox.p2.processing.Adder", "1", true);
+ ProcessingStepDescriptor multiplier = new ProcessingStepDescriptor("org.eclipse.equinox.p2.processing.Multiplier", "2", true);
+ ProcessingStepDescriptor[] descriptors = new ProcessingStepDescriptor[] {adder, multiplier};
+ ProcessingStep[] steps = handler.create(descriptors, null);
+ ByteArrayOutputStream result = new ByteArrayOutputStream(10);
+ OutputStream testStream = handler.link(steps, result, monitor);
+ testStream.write(new byte[] {1, 2, 3, 4, 5});
+ testStream.close();
+ assertTrue(Arrays.equals(new byte[] {4, 6, 8, 10, 12}, result.toByteArray()));
+ }
+
+ public void testCreatePSsAndAssureOrderingOfPSs2() throws IOException {
+ ProcessingStepDescriptor adder = new ProcessingStepDescriptor("org.eclipse.equinox.p2.processing.Adder", "1", true);
+ ProcessingStepDescriptor multiplier = new ProcessingStepDescriptor("org.eclipse.equinox.p2.processing.Multiplier", "2", true);
+ ProcessingStepDescriptor[] descriptors = new ProcessingStepDescriptor[] {multiplier, adder};
+ ProcessingStep[] steps = handler.create(descriptors, null);
+ ByteArrayOutputStream result = new ByteArrayOutputStream(10);
+ OutputStream testStream = handler.link(steps, result, monitor);
+ testStream.write(new byte[] {1, 2, 3, 4, 5});
+ testStream.close();
+ assertTrue(Arrays.equals(new byte[] {3, 5, 7, 9, 11}, result.toByteArray()));
+ }
+
+ public void testLinkPSs() throws IOException {
+ ProcessingStepDescriptor adder = new ProcessingStepDescriptor("org.eclipse.equinox.p2.processing.Adder", "1", true);
+ ProcessingStepDescriptor multiplier = new ProcessingStepDescriptor("org.eclipse.equinox.p2.processing.Multiplier", "2", true);
+ ProcessingStepDescriptor[] descriptors = new ProcessingStepDescriptor[] {adder, multiplier};
+ ByteArrayOutputStream result = new ByteArrayOutputStream(10);
+ OutputStream testStream = handler.createAndLink(descriptors, null, result, monitor);
+ testStream.write(new byte[] {1, 2, 3, 4, 5});
+ testStream.close();
+ assertTrue(Arrays.equals(new byte[] {4, 6, 8, 10, 12}, result.toByteArray()));
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/repository/processing/ProcessingStepTest.java b/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/repository/processing/ProcessingStepTest.java
new file mode 100644
index 000000000..c77e074fc
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/artifact/repository/processing/ProcessingStepTest.java
@@ -0,0 +1,108 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG (Stefan Liebig) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.p2.tests.artifact.repository.processing;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import junit.framework.TestCase;
+import org.eclipse.core.runtime.*;
+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStep;
+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStepHandler;
+
+public class ProcessingStepTest extends TestCase {
+
+ private ProcessingStep ps;
+ private boolean flushed;
+ private boolean closed;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ ps = new ProcessingStep() {};
+ flushed = false;
+ closed = false;
+ }
+
+ public void testDefaultStatus() {
+ assertNotNull(ps.getStatus());
+ assertTrue(ps.getStatus().isOK());
+ assertTrue(ps.getStatus(false).isOK());
+ assertTrue(ps.getStatus(true).isOK());
+ assertTrue(ProcessingStepHandler.checkStatus(ps).isOK());
+ }
+
+ public void testGetDeepStatus() {
+ ProcessingStep ps2 = new ProcessingStep() {};
+ ps.link(ps2, new NullProgressMonitor());
+ assertTrue(ps.getStatus(true).isOK());
+
+ ps2.setStatus(new Status(IStatus.ERROR, "plugin id", "message"));
+ assertFalse(ps.getStatus(true).isOK());
+ assertTrue(ps.getStatus(true).isMultiStatus());
+ assertEquals(IStatus.ERROR, ps.getStatus(true).getSeverity());
+ MultiStatus multi = (MultiStatus) ps.getStatus(true);
+ assertEquals(2, multi.getChildren().length);
+
+ ProcessingStep ps3 = new ProcessingStep() {};
+ ps2.link(ps3, new NullProgressMonitor());
+ assertFalse(ps.getStatus(true).isOK());
+ assertTrue(ps.getStatus(true).isMultiStatus());
+ assertEquals(IStatus.ERROR, ps.getStatus(true).getSeverity());
+ multi = (MultiStatus) ps.getStatus(true);
+ assertEquals(3, multi.getChildren().length);
+
+ ps3.setStatus(Status.CANCEL_STATUS);
+ assertFalse(ps.getStatus(true).isOK());
+ assertTrue(ps.getStatus(true).isMultiStatus());
+ assertEquals(IStatus.CANCEL, ps.getStatus(true).getSeverity());
+ }
+
+ public void testFlush() throws IOException {
+ OutputStream destination = new OutputStream() {
+
+ public void write(int b) throws IOException {
+ }
+
+ public void flush() {
+ flushed = true;
+ }
+ };
+ ps.link(destination, new NullProgressMonitor());
+ ps.flush();
+ assertTrue(flushed);
+ }
+
+ public void testCloseSimpleOutputStreamAsDestination() throws IOException {
+ OutputStream destination = new OutputStream() {
+
+ public void write(int b) throws IOException {
+ }
+
+ public void close() {
+ closed = true;
+ }
+ };
+ ps.link(destination, new NullProgressMonitor());
+ ps.close();
+ assertFalse(closed);
+ }
+
+ public void testCloseProcessingStepAsDestination() throws IOException {
+ OutputStream destination = new ProcessingStep() {
+ public void close() {
+ closed = true;
+ }
+ };
+ ps.link(destination, new NullProgressMonitor());
+ ps.close();
+ assertTrue(closed);
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/optimizers/AutomatedTests.java b/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/optimizers/AutomatedTests.java
new file mode 100644
index 000000000..96b52a872
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/optimizers/AutomatedTests.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.p2.tests.optimizers;
+
+import junit.framework.*;
+
+/**
+ * @since 1.0
+ */
+public class AutomatedTests extends TestCase {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(AutomatedTests.class.getName());
+ suite.addTest(org.eclipse.equinox.p2.tests.artifact.optimizers.AllTests.suite());
+ suite.addTest(org.eclipse.equinox.p2.tests.artifact.processors.AllTests.suite());
+ suite.addTest(org.eclipse.equinox.p2.tests.artifact.repository.processing.AllTests.suite());
+ suite.addTest(org.eclipse.equinox.p2.tests.sar.AllTests.suite());
+ return suite;
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/optimizers/TestActivator.java b/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/optimizers/TestActivator.java
new file mode 100644
index 000000000..cd6876056
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/optimizers/TestActivator.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.p2.tests.optimizers;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+/**
+ * @since 1.0
+ */
+public class TestActivator implements BundleActivator {
+
+ public static final String PI = "org.eclipse.equinox.p2.tests.optimizers"; //$NON-NLS-1$
+ private static BundleContext bundleContext;
+
+ /* (non-Javadoc)
+ * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ bundleContext = context;
+ }
+
+ /* (non-Javadoc)
+ * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ bundleContext = null;
+ }
+
+ public static BundleContext getContext() {
+ return bundleContext;
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/optimizers/TestData.java b/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/optimizers/TestData.java
new file mode 100644
index 000000000..464fa1e77
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/optimizers/TestData.java
@@ -0,0 +1,168 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG (Stefan Liebig) - initial API and implementation
+ * Red Hat, Inc. (Andrew Overholt) - add getFile method
+ *******************************************************************************/
+package org.eclipse.equinox.p2.tests.optimizers;
+
+import java.io.*;
+import java.util.*;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+import junit.framework.Assert;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.equinox.internal.p2.core.helpers.FileUtils;
+
+/**
+ * <code>TestData</code> helps with handling of test data.
+ */
+public class TestData {
+
+ private static final String TEST_DATA_ROOT_FOLDER = "testData";
+ private static final String PREFIX_SEPERATOR = "~";
+
+ /**
+ * Get an input stream from the resource testDataName within the folder
+ * testDataFolder of the testData folder of this project.
+ * @param testDataFolder
+ * @param testDataName
+ * @return input stream for the test data
+ * @throws IOException
+ */
+ public static InputStream get(String testDataFolder, String testDataName) throws IOException {
+ return new BufferedInputStream(TestActivator.getContext().getBundle().getEntry(TEST_DATA_ROOT_FOLDER + "/" + testDataFolder + "/" + testDataName).openStream());
+ }
+
+ /**
+ * Get a File from the resource testDataName within the folder
+ * testDataFolder of the testData folder of this project.
+ * @param testDataFolder
+ * @return test data File
+ * @throws IOException
+ */
+ public static File getFile(String testDataFolder, String testDataName) throws IOException {
+ return new File(FileLocator.toFileURL(TestActivator.getContext().getBundle().getEntry(TEST_DATA_ROOT_FOLDER + "/" + testDataFolder + "/" + testDataName)).getPath());
+ }
+
+ /**
+ * Create a temporary file for the test data. The temporary file will be deleted
+ * when the jvm exists. If testDataName contains an extension this extension will
+ * be used as suffix for the temporary file.
+ * @param testDataFolder
+ * @param testDataName
+ * @return temporary file with test data
+ * @throws IOException
+ */
+ public static File getTempFile(String testDataFolder, String testDataName) throws IOException {
+ File temp = createTempFile(testDataName);
+ OutputStream out = new FileOutputStream(temp);
+ FileUtils.copyStream(get(testDataFolder, testDataName), true, out, true);
+ return temp;
+ }
+
+ /**
+ * Create a temporary file. This file will be deleted if the jvm exits.
+ * If testDataName contains an extension this extension will be used as
+ * suffix for the temporary file.
+ * @param testDataName
+ * @return temporary file
+ * @throws IOException
+ */
+ public static File createTempFile(String testDataName) throws IOException {
+ int i = testDataName.lastIndexOf('.');
+ File temp = (i == -1) ? File.createTempFile(testDataName + PREFIX_SEPERATOR, ".tmp") : File.createTempFile(testDataName.substring(0, i) + PREFIX_SEPERATOR, testDataName.substring(i));
+ temp.deleteOnExit();
+ return temp;
+ }
+
+ /**
+ * Assert equality of files.
+ * @param expected
+ * @param actual
+ * @throws IOException
+ */
+ public static void assertEquals(File expected, File actual) throws IOException {
+ Assert.assertEquals("Files have different lengths.", expected.length(), actual.length());
+ TestData.assertEquals(new BufferedInputStream(new FileInputStream(expected)), new BufferedInputStream(new FileInputStream(actual)));
+ }
+
+ /**
+ * Assert equality of input streams.
+ * @param expected
+ * @param actual
+ * @throws IOException
+ */
+ public static void assertEquals(InputStream expected, InputStream actual) throws IOException {
+ try {
+ int readExpected = 0;
+ int readActual = 0;
+ int count = 0;
+ while (readActual != -1 && readExpected != -1) {
+ readActual = actual.read();
+ readExpected = expected.read();
+ Assert.assertEquals("Different bytes at " + count, readExpected, readActual);
+ count++;
+ }
+ } finally {
+ if (expected != null)
+ expected.close();
+ if (actual != null)
+ actual.close();
+ }
+ }
+
+ /**
+ * Assert equality of zip input streams.
+ * @param input1
+ * @param input2
+ * @throws IOException
+ */
+ public static void assertEquals(ZipInputStream input1, ZipInputStream input2) throws IOException {
+ Map jar1 = getEntries(input1);
+ Map jar2 = getEntries(input2);
+ for (Iterator i = jar1.keySet().iterator(); i.hasNext();) {
+ String name = (String) i.next();
+ Object[] file1 = (Object[]) jar1.get(name);
+ Object[] file2 = (Object[]) jar2.remove(name);
+ Assert.assertNotNull(file2);
+
+ ZipEntry entry1 = (ZipEntry) file1[0];
+ ZipEntry entry2 = (ZipEntry) file2[0];
+ // compare the entries
+ Assert.assertTrue(entry1.getName().equals(entry2.getName()));
+ Assert.assertTrue(entry1.getSize() == entry2.getSize());
+ // TODO for now skip over the timestamp as they seem to be different
+ // assertTrue(entry1.getTime() == entry2.getTime());
+ Assert.assertTrue(entry1.isDirectory() == entry2.isDirectory());
+ Assert.assertTrue(entry1.getCrc() == entry2.getCrc());
+ Assert.assertTrue(entry1.getMethod() == entry2.getMethod());
+
+ // check the content of the entries
+ Assert.assertTrue(Arrays.equals((byte[]) file1[1], (byte[]) file2[1]));
+ }
+
+ // ensure that we have consumed all of the entries in the second JAR
+ Assert.assertTrue(jar2.size() == 0);
+ }
+
+ private static Map getEntries(ZipInputStream input) throws IOException {
+ Map result = new HashMap();
+ while (true) {
+ ZipEntry entry = input.getNextEntry();
+ if (entry == null)
+ return result;
+
+ ByteArrayOutputStream content = new ByteArrayOutputStream();
+ FileUtils.copyStream(input, false, content, true);
+ input.closeEntry();
+ result.put(entry.getName(), new Object[] {entry, content.toByteArray()});
+ }
+ }
+
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/sar/AllTests.java b/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/sar/AllTests.java
new file mode 100644
index 000000000..af49c8c26
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/sar/AllTests.java
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG (Stefan Liebig) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.p2.tests.sar;
+
+import junit.framework.*;
+
+/**
+ * Performs all sar tests.
+ */
+public class AllTests extends TestCase {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(AllTests.class.getName());
+ suite.addTestSuite(DirectByteArrayOutputStreamTest.class);
+ suite.addTestSuite(SarTest.class);
+ return suite;
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/sar/DirectByteArrayOutputStreamTest.java b/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/sar/DirectByteArrayOutputStreamTest.java
new file mode 100644
index 000000000..d98ae78e7
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/sar/DirectByteArrayOutputStreamTest.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG (Stefan Liebig) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.p2.tests.sar;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.util.Arrays;
+import junit.framework.TestCase;
+import org.eclipse.equinox.internal.p2.sar.DirectByteArrayOutputStream;
+
+/**
+ * Test the <code>DirectByteArrayOutputStream</code>
+ */
+public class DirectByteArrayOutputStreamTest extends TestCase {
+
+ private static final String JUST11BYTES = "just11bytes";
+ private static final int ELEVEN = JUST11BYTES.getBytes().length;
+
+ /**
+ * Test the constraints of the DBAOS
+ *
+ * @throws IOException
+ */
+ public void testDBAOSConstraints() throws IOException {
+ DirectByteArrayOutputStream out = new DirectByteArrayOutputStream(1024);
+ out.write(JUST11BYTES.getBytes());
+ assertEquals(ELEVEN, out.getBufferLength());
+ assertEquals(ELEVEN, out.toByteArray().length);
+ assertNotSame(out.toByteArray(), out.getBuffer());
+ assertEquals(1024, out.getBuffer().length);
+ assertEquals(JUST11BYTES, new String(out.getBuffer(), 0, out.getBufferLength()));
+ ByteArrayInputStream in = out.getInputStream();
+ assertEquals(ELEVEN, in.available());
+ byte[] elevenBytes = new byte[ELEVEN];
+ in.read(elevenBytes);
+ assertTrue(Arrays.equals(JUST11BYTES.getBytes(), elevenBytes));
+ assertEquals(-1, in.read());
+ }
+}
diff --git a/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/sar/SarTest.java b/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/sar/SarTest.java
new file mode 100644
index 000000000..1811889e1
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.optimizers/src/org/eclipse/equinox/p2/tests/sar/SarTest.java
@@ -0,0 +1,150 @@
+/*******************************************************************************
+ * Copyright (c) 2007 compeople AG 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * compeople AG (Stefan Liebig) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.p2.tests.sar;
+
+import java.io.*;
+import java.util.Arrays;
+import junit.framework.TestCase;
+import org.eclipse.equinox.internal.p2.sar.SarUtil;
+import org.eclipse.equinox.p2.tests.optimizers.TestData;
+
+/**
+ * Test the sar stuff.
+ */
+public class SarTest extends TestCase {
+
+ // public void testGenerateTestDataNJarAndSarFromJar32() throws IOException {
+ // InputStream jar32 = TestData.get("sar", "org.eclipse.jdt_3.2.0.v20060605-1400.jar");
+ // generateNJarAndSar("org.eclipse.jdt_3.2.0.v20060605-1400", jar32);
+ // }
+ //
+ // public void testGenerateTestDataNJarAndSarFromJar33() throws IOException {
+ // InputStream jar32 = TestData.get("sar", "org.eclipse.jdt_3.3.0.v20070607-1300.jar");
+ // generateNJarAndSar("org.eclipse.jdt_3.3.0.v20070607-1300", jar32);
+ // }
+ //
+ // private void generateNJarAndSar(String name, InputStream jar) throws IOException {
+ // File njar = File.createTempFile(name, ".njar");
+ // OutputStream njarOut = new BufferedOutputStream(new FileOutputStream(njar));
+ //
+ // SarUtil.normalize(jar, njarOut);
+ //
+ // File sar = File.createTempFile(name, ".sar");
+ // SarUtil.zipToSar(njar, sar);
+ // }
+
+ public void testJarToSarForJdt320() throws IOException {
+ InputStream jdt320Jar = TestData.get("optimizers", "org.eclipse.jdt_3.2.0.v20060605-1400.njar");
+ InputStream jdt320Sar = TestData.get("sar", "org.eclipse.jdt_3.2.0.v20060605-1400.sar");
+ doJarToSar(jdt320Jar, jdt320Sar);
+ }
+
+ public void testSarToJarForJdt320() throws IOException {
+ InputStream jdt320Sar = TestData.get("sar", "org.eclipse.jdt_3.2.0.v20060605-1400.sar");
+ InputStream jdt320Jar = TestData.get("optimizers", "org.eclipse.jdt_3.2.0.v20060605-1400.njar");
+ doSarToJar(jdt320Sar, jdt320Jar);
+ }
+
+ public void testJarToSarForJdt330() throws IOException {
+ InputStream jdt330Jar = TestData.get("optimizers", "org.eclipse.jdt_3.3.0.v20070607-1300.njar");
+ InputStream jdt330Sar = TestData.get("sar", "org.eclipse.jdt_3.3.0.v20070607-1300.sar");
+ doJarToSar(jdt330Jar, jdt330Sar);
+ }
+
+ public void testSarToJarForJdt330() throws IOException {
+ InputStream jdt330Sar = TestData.get("sar", "org.eclipse.jdt_3.3.0.v20070607-1300.sar");
+ InputStream jdt330Jar = TestData.get("optimizers", "org.eclipse.jdt_3.3.0.v20070607-1300.njar");
+ doSarToJar(jdt330Sar, jdt330Jar);
+ }
+
+ /**
+ * @throws IOException
+ */
+ private void doJarToSar(InputStream jar, InputStream expectedSar) throws IOException {
+ File sar = TestData.createTempFile("doJarToSar.sar");
+ OutputStream sarOut = new BufferedOutputStream(new FileOutputStream(sar));
+
+ SarUtil.zipToSar(jar, sarOut);
+
+ InputStream sarIn = new BufferedInputStream(new FileInputStream(sar));
+ TestData.assertEquals(sarIn, expectedSar);
+ }
+
+ /**
+ * @throws IOException
+ */
+ private void doSarToJar(InputStream sar, InputStream expectedJar) throws IOException {
+ File jar = TestData.createTempFile("doSarToJar.jar");
+ OutputStream jarOut = new BufferedOutputStream(new FileOutputStream(jar));
+
+ SarUtil.sarToZip(sar, jarOut);
+
+ InputStream jarIn = new BufferedInputStream(new FileInputStream(jar));
+ TestData.assertEquals(jarIn, expectedJar);
+ }
+
+ /**
+ * @throws IOException
+ */
+ public void testZipToSarAndBack() throws IOException {
+ File originalZipFile = TestData.getTempFile("sar", "test.zip");
+ File sarFile = TestData.createTempFile("test.sar");
+ File recreatedZipFile = TestData.createTempFile("test.zip");
+
+ long before = System.currentTimeMillis();
+ SarUtil.zipToSar(originalZipFile, sarFile);
+ System.out.println("zipToSar took: " + (System.currentTimeMillis() - before));
+
+ before = System.currentTimeMillis();
+ SarUtil.sarToZip(sarFile, recreatedZipFile);
+ System.out.println("sarToZip took: " + (System.currentTimeMillis() - before));
+
+ TestData.assertEquals(originalZipFile, recreatedZipFile);
+ }
+
+ /**
+ * @throws IOException
+ */
+ public void testNormalizeOnFiles() throws IOException {
+ File alienZip = TestData.getTempFile("sar", "alien.zip");
+
+ File normalizedAlienZip = TestData.createTempFile("normalizedalien.zip");
+ SarUtil.normalize(alienZip, normalizedAlienZip);
+
+ assertTrue(alienZip.length() != normalizedAlienZip.length());
+
+ File renormalizedAlienZip = TestData.createTempFile("renormalizedalien.zip");
+ SarUtil.normalize(normalizedAlienZip, renormalizedAlienZip);
+
+ TestData.assertEquals(normalizedAlienZip, renormalizedAlienZip);
+ }
+
+ /**
+ * @throws IOException
+ */
+ public void testNormalizeOnStreames() throws IOException {
+ InputStream alienZip = TestData.get("sar", "alien.zip");
+ ByteArrayOutputStream normalizedAlienZip = new ByteArrayOutputStream();
+ ByteArrayOutputStream renormalizedAlienZip = new ByteArrayOutputStream();
+ try {
+ SarUtil.normalize(alienZip, normalizedAlienZip);
+
+ SarUtil.normalize(new ByteArrayInputStream(normalizedAlienZip.toByteArray()), renormalizedAlienZip);
+
+ assertTrue(Arrays.equals(normalizedAlienZip.toByteArray(), renormalizedAlienZip.toByteArray()));
+ } finally {
+ if (alienZip != null)
+ alienZip.close();
+ }
+
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/jarprocessor.jar.pack.gz b/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/jarprocessor.jar.pack.gz
new file mode 100644
index 000000000..f2df489b2
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/jarprocessor.jar.pack.gz
Binary files differ
diff --git a/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/optimizers/1_6/org.eclipse.equinox.app_1.0.100.v20071015.jar.pack.gz b/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/optimizers/1_6/org.eclipse.equinox.app_1.0.100.v20071015.jar.pack.gz
new file mode 100644
index 000000000..9f52ad35f
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/optimizers/1_6/org.eclipse.equinox.app_1.0.100.v20071015.jar.pack.gz
Binary files differ
diff --git a/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/optimizers/eclipse-3.2-3.3.jbdiff b/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/optimizers/eclipse-3.2-3.3.jbdiff
new file mode 100644
index 000000000..deac744b8
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/optimizers/eclipse-3.2-3.3.jbdiff
Binary files differ
diff --git a/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/optimizers/eclipse-3.2.exe b/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/optimizers/eclipse-3.2.exe
new file mode 100644
index 000000000..7826d1ed8
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/optimizers/eclipse-3.2.exe
Binary files differ
diff --git a/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/optimizers/eclipse-3.3.exe b/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/optimizers/eclipse-3.3.exe
new file mode 100644
index 000000000..c5cd8f038
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/optimizers/eclipse-3.3.exe
Binary files differ
diff --git a/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/optimizers/org.eclipse.equinox.app_1.0.100.v20071015.jar b/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/optimizers/org.eclipse.equinox.app_1.0.100.v20071015.jar
new file mode 100644
index 000000000..0c809eeed
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/optimizers/org.eclipse.equinox.app_1.0.100.v20071015.jar
Binary files differ
diff --git a/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/optimizers/org.eclipse.equinox.app_1.0.100.v20071015.jar.pack.gz b/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/optimizers/org.eclipse.equinox.app_1.0.100.v20071015.jar.pack.gz
new file mode 100644
index 000000000..b586d3cc8
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/optimizers/org.eclipse.equinox.app_1.0.100.v20071015.jar.pack.gz
Binary files differ
diff --git a/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/optimizers/org.eclipse.jdt_3.2.0-3.3.0.jbdiff b/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/optimizers/org.eclipse.jdt_3.2.0-3.3.0.jbdiff
new file mode 100644
index 000000000..b920d53bb
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/optimizers/org.eclipse.jdt_3.2.0-3.3.0.jbdiff
Binary files differ
diff --git a/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/optimizers/org.eclipse.jdt_3.2.0.v20060605-1400.njar b/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/optimizers/org.eclipse.jdt_3.2.0.v20060605-1400.njar
new file mode 100644
index 000000000..41ee47bcc
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/optimizers/org.eclipse.jdt_3.2.0.v20060605-1400.njar
Binary files differ
diff --git a/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/optimizers/org.eclipse.jdt_3.3.0.v20070607-1300.njar b/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/optimizers/org.eclipse.jdt_3.3.0.v20070607-1300.njar
new file mode 100644
index 000000000..9deec2f0e
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/optimizers/org.eclipse.jdt_3.3.0.v20070607-1300.njar
Binary files differ
diff --git a/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/optimizers/testdata_1.0.0.1-2.jar b/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/optimizers/testdata_1.0.0.1-2.jar
new file mode 100644
index 000000000..71a546b02
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/optimizers/testdata_1.0.0.1-2.jar
Binary files differ
diff --git a/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/optimizers/testdata_1.0.0.1.jar b/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/optimizers/testdata_1.0.0.1.jar
new file mode 100644
index 000000000..49e7f90a2
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/optimizers/testdata_1.0.0.1.jar
Binary files differ
diff --git a/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/optimizers/testdata_1.0.0.2.jar b/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/optimizers/testdata_1.0.0.2.jar
new file mode 100644
index 000000000..3515b0f46
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/optimizers/testdata_1.0.0.2.jar
Binary files differ
diff --git a/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/sar/alien.zip b/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/sar/alien.zip
new file mode 100644
index 000000000..9872214cc
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/sar/alien.zip
Binary files differ
diff --git a/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/sar/org.eclipse.jdt_3.2.0.v20060605-1400.jar b/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/sar/org.eclipse.jdt_3.2.0.v20060605-1400.jar
new file mode 100644
index 000000000..d674aef01
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/sar/org.eclipse.jdt_3.2.0.v20060605-1400.jar
Binary files differ
diff --git a/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/sar/org.eclipse.jdt_3.2.0.v20060605-1400.sar b/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/sar/org.eclipse.jdt_3.2.0.v20060605-1400.sar
new file mode 100644
index 000000000..0abfe3604
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/sar/org.eclipse.jdt_3.2.0.v20060605-1400.sar
Binary files differ
diff --git a/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/sar/org.eclipse.jdt_3.3.0.v20070607-1300.jar b/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/sar/org.eclipse.jdt_3.3.0.v20070607-1300.jar
new file mode 100644
index 000000000..9deec2f0e
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/sar/org.eclipse.jdt_3.3.0.v20070607-1300.jar
Binary files differ
diff --git a/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/sar/org.eclipse.jdt_3.3.0.v20070607-1300.sar b/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/sar/org.eclipse.jdt_3.3.0.v20070607-1300.sar
new file mode 100644
index 000000000..842bb71f7
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/sar/org.eclipse.jdt_3.3.0.v20070607-1300.sar
Binary files differ
diff --git a/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/sar/test.zip b/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/sar/test.zip
new file mode 100644
index 000000000..dde8b8440
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.optimizers/testData/sar/test.zip
Binary files differ

Back to the top