Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Niefer2009-02-21 00:08:40 +0000
committerAndrew Niefer2009-02-21 00:08:40 +0000
commit2d3e4454cfdde906ded295743e8d03056290c84a (patch)
tree17f2e4ee85434818459d95d3c95fc6331ff83506 /bundles/org.eclipse.equinox.p2.jarprocessor
parent0572acab24bca9bc1917fe3a0d1d3b67e8ea4d55 (diff)
downloadrt.equinox.p2-2d3e4454cfdde906ded295743e8d03056290c84a.tar.gz
rt.equinox.p2-2d3e4454cfdde906ded295743e8d03056290c84a.tar.xz
rt.equinox.p2-2d3e4454cfdde906ded295743e8d03056290c84a.zip
bug 190041 - signing zips with jarprocessor ant task
bug 219832 - signing with keypass bug 265564 - signing and packing artifact repos
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.jarprocessor')
-rw-r--r--bundles/org.eclipse.equinox.p2.jarprocessor/.classpath1
-rw-r--r--bundles/org.eclipse.equinox.p2.jarprocessor/.externalToolBuilders/AntTaskBuilder.launch19
-rw-r--r--bundles/org.eclipse.equinox.p2.jarprocessor/.project10
-rw-r--r--bundles/org.eclipse.equinox.p2.jarprocessor/META-INF/MANIFEST.MF1
-rw-r--r--bundles/org.eclipse.equinox.p2.jarprocessor/build.properties11
-rw-r--r--bundles/org.eclipse.equinox.p2.jarprocessor/lib/.cvsignore1
-rw-r--r--bundles/org.eclipse.equinox.p2.jarprocessor/localbuild.xml12
-rw-r--r--bundles/org.eclipse.equinox.p2.jarprocessor/plugin.xml21
-rw-r--r--bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/equinox/internal/p2/jarprocessor/ZipProcessor.java126
-rw-r--r--bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/equinox/internal/p2/jarprocessor/unsigner/UnsignCommand.java37
-rw-r--r--bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/equinox/internal/p2/jarprocessor/unsigner/Unsigner.java147
-rw-r--r--bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/internal/provisional/equinox/p2/jarprocessor/JarProcessorExecutor.java10
-rw-r--r--bundles/org.eclipse.equinox.p2.jarprocessor/src_ant/org/eclipse/equinox/internal/p2/jarprocessor/ant/AntBasedProcessorExecutor.java36
-rw-r--r--bundles/org.eclipse.equinox.p2.jarprocessor/src_ant/org/eclipse/equinox/internal/p2/jarprocessor/ant/AntSignCommand.java59
-rw-r--r--bundles/org.eclipse.equinox.p2.jarprocessor/src_ant/org/eclipse/equinox/internal/p2/jarprocessor/ant/JarProcessorTask.java110
15 files changed, 523 insertions, 78 deletions
diff --git a/bundles/org.eclipse.equinox.p2.jarprocessor/.classpath b/bundles/org.eclipse.equinox.p2.jarprocessor/.classpath
index 7cdeb7319..0179ed600 100644
--- a/bundles/org.eclipse.equinox.p2.jarprocessor/.classpath
+++ b/bundles/org.eclipse.equinox.p2.jarprocessor/.classpath
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
+ <classpathentry kind="src" output="bin_ant" path="src_ant"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/CDC-1.1%Foundation-1.1"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="output" path="bin"/>
diff --git a/bundles/org.eclipse.equinox.p2.jarprocessor/.externalToolBuilders/AntTaskBuilder.launch b/bundles/org.eclipse.equinox.p2.jarprocessor/.externalToolBuilders/AntTaskBuilder.launch
new file mode 100644
index 000000000..ae5694459
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.jarprocessor/.externalToolBuilders/AntTaskBuilder.launch
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<launchConfiguration type="org.eclipse.ant.AntBuilderLaunchConfigurationType">
+<booleanAttribute key="org.eclipse.ant.ui.ATTR_TARGETS_UPDATED" value="true"/>
+<booleanAttribute key="org.eclipse.ant.ui.DEFAULT_VM_INSTALL" value="false"/>
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
+<listEntry value="/org.eclipse.equinox.p2.jarprocessor/localbuild.xml"/>
+</listAttribute>
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
+<listEntry value="1"/>
+</listAttribute>
+<booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/>
+<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/>
+<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="true"/>
+<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.equinox.p2.jarprocessor"/>
+<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/org.eclipse.equinox.p2.jarprocessor/localbuild.xml}"/>
+<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,incremental,"/>
+<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
+<stringAttribute key="org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY" value="${workspace_loc:/org.eclipse.equinox.p2.jarprocessor}"/>
+</launchConfiguration>
diff --git a/bundles/org.eclipse.equinox.p2.jarprocessor/.project b/bundles/org.eclipse.equinox.p2.jarprocessor/.project
index b3a3e9e0c..a81ef8047 100644
--- a/bundles/org.eclipse.equinox.p2.jarprocessor/.project
+++ b/bundles/org.eclipse.equinox.p2.jarprocessor/.project
@@ -20,6 +20,16 @@
<arguments>
</arguments>
</buildCommand>
+ <buildCommand>
+ <name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
+ <triggers>full,incremental,</triggers>
+ <arguments>
+ <dictionary>
+ <key>LaunchConfigHandle</key>
+ <value>&lt;project&gt;/.externalToolBuilders/AntTaskBuilder.launch</value>
+ </dictionary>
+ </arguments>
+ </buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
diff --git a/bundles/org.eclipse.equinox.p2.jarprocessor/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.jarprocessor/META-INF/MANIFEST.MF
index 23b25c5a4..655624269 100644
--- a/bundles/org.eclipse.equinox.p2.jarprocessor/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.p2.jarprocessor/META-INF/MANIFEST.MF
@@ -8,5 +8,6 @@ Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: CDC-1.1/Foundation-1.1,
J2SE-1.4
Export-Package: org.eclipse.equinox.internal.p2.jarprocessor;x-friends:="org.eclipse.equinox.p2.artifact.repository,org.eclipse.pde.build",
+ org.eclipse.equinox.internal.p2.jarprocessor.unsigner;x-internal:=true,
org.eclipse.equinox.internal.p2.jarprocessor.verifier;x-internal:=true,
org.eclipse.internal.provisional.equinox.p2.jarprocessor;x-friends:="org.eclipse.equinox.p2.artifact.optimizers,org.eclipse.equinox.p2.artifact.repository,org.eclipse.pde.build"
diff --git a/bundles/org.eclipse.equinox.p2.jarprocessor/build.properties b/bundles/org.eclipse.equinox.p2.jarprocessor/build.properties
index a6b8330d2..d8902a19f 100644
--- a/bundles/org.eclipse.equinox.p2.jarprocessor/build.properties
+++ b/bundles/org.eclipse.equinox.p2.jarprocessor/build.properties
@@ -13,5 +13,14 @@ output.. = bin/
bin.includes = META-INF/,\
.,\
about.html,\
- plugin.properties
+ plugin.properties,\
+ plugin.xml,\
+ lib/jarprocessor-ant.jar
src.includes = about.html
+
+source.lib/jarprocessor-ant.jar = src_ant/
+output.lib/jarprocessor-ant.jar = bin_ant/
+
+jars.extra.classpath = platform:/plugin/org.apache.ant/lib/ant.jar
+jars.compile.order = .,\
+ lib/jarprocessor-ant.jar
diff --git a/bundles/org.eclipse.equinox.p2.jarprocessor/lib/.cvsignore b/bundles/org.eclipse.equinox.p2.jarprocessor/lib/.cvsignore
new file mode 100644
index 000000000..c45d3e953
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.jarprocessor/lib/.cvsignore
@@ -0,0 +1 @@
+jarprocessor-ant.jar
diff --git a/bundles/org.eclipse.equinox.p2.jarprocessor/localbuild.xml b/bundles/org.eclipse.equinox.p2.jarprocessor/localbuild.xml
new file mode 100644
index 000000000..107dcb2b0
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.jarprocessor/localbuild.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0"?>
+<project name="project" default="workspaceBinaries">
+ <description>
+ Build the jarprocessor-ant.jar by gathering up the results of a workspace build from bin_ant.
+ </description>
+
+ <target name="workspaceBinaries" description="Jar up the binaries that were compiled by the jdt builder" >
+ <mkdir dir="lib" />
+ <delete file="lib/jarprocessor-ant.jar" failonerror="false"/>
+ <jar destfile="lib/jarprocessor-ant.jar" basedir="bin_ant"/>
+ </target>
+</project>
diff --git a/bundles/org.eclipse.equinox.p2.jarprocessor/plugin.xml b/bundles/org.eclipse.equinox.p2.jarprocessor/plugin.xml
new file mode 100644
index 000000000..36d254f41
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.jarprocessor/plugin.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.0"?>
+<plugin>
+ <!-- Tasks -->
+ <extension
+ point="org.eclipse.ant.core.antTasks">
+ <antTask
+ class="org.eclipse.equinox.internal.p2.jarprocessor.ant.JarProcessorTask"
+ headless="true"
+ library="lib/jarprocessor-ant.jar"
+ name="eclipse.jarProcessor">
+ </antTask>
+ </extension>
+ <!-- Extra Classpath -->
+ <extension
+ point="org.eclipse.ant.core.extraClasspathEntries">
+ <extraClasspathEntry
+ library="lib/jarprocessor-ant.jar">
+ </extraClasspathEntry>
+ </extension>
+</plugin>
diff --git a/bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/equinox/internal/p2/jarprocessor/ZipProcessor.java b/bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/equinox/internal/p2/jarprocessor/ZipProcessor.java
index 92a1cf894..15b7a743d 100644
--- a/bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/equinox/internal/p2/jarprocessor/ZipProcessor.java
+++ b/bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/equinox/internal/p2/jarprocessor/ZipProcessor.java
@@ -10,11 +10,21 @@
*******************************************************************************/
package org.eclipse.equinox.internal.p2.jarprocessor;
-import java.io.*;
-import java.util.*;
-import java.util.zip.*;
-import org.eclipse.internal.provisional.equinox.p2.jarprocessor.IProcessStep;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Enumeration;
+import java.util.Properties;
+import java.util.Set;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipException;
+import java.util.zip.ZipFile;
+import java.util.zip.ZipOutputStream;
+
import org.eclipse.internal.provisional.equinox.p2.jarprocessor.JarProcessor;
+import org.eclipse.internal.provisional.equinox.p2.jarprocessor.JarProcessorExecutor;
/**
* @author aniefer@ca.ibm.com
@@ -22,23 +32,22 @@ import org.eclipse.internal.provisional.equinox.p2.jarprocessor.JarProcessor;
*/
public class ZipProcessor {
- private IProcessStep signStep = null;
- private IProcessStep packStep = null;
- private IProcessStep packUnpackStep = null;
- private IProcessStep unpackStep = null;
-
+ private JarProcessorExecutor executor = null;
+ private JarProcessorExecutor.Options options = null;
+
private String workingDirectory = null;
private Properties properties = null;
private Set packExclusions = null;
private Set signExclusions = null;
- private String command = null;
- private boolean packing = false;
- private boolean signing = false;
- private boolean repacking = false;
- private boolean unpacking = false;
- private boolean verbose = false;
- private boolean processAll = false;
-
+
+ public void setExecutor(JarProcessorExecutor executor) {
+ this.executor = executor;
+ }
+
+ public void setOptions(JarProcessorExecutor.Options options) {
+ this.options = options;
+ }
+
public void setWorkingDirectory(String dir) {
workingDirectory = dir;
}
@@ -49,45 +58,24 @@ public class ZipProcessor {
return workingDirectory;
}
- public void setSignCommand(String command) {
- this.command = command;
- this.signing = (command != null);
- }
-
- public void setPack(boolean pack) {
- this.packing = pack;
- }
-
- public void setRepack(boolean repack) {
- this.repacking = repack;
- }
-
- public void setUnpack(boolean unpack) {
- this.unpacking = unpack;
- }
-
- public void setVerbose(boolean verbose) {
- this.verbose = verbose;
- }
-
- public void setProcessAll(boolean all) {
- this.processAll = all;
+ private boolean repacking() {
+ return options.repack || (options.pack && options.signCommand != null);
}
-
+
public void processZip(File zipFile) throws ZipException, IOException {
- if (verbose)
+ if (options.verbose)
System.out.println("Processing " + zipFile.getPath()); //$NON-NLS-1$
ZipFile zip = new ZipFile(zipFile);
initialize(zip);
- String extension = unpacking ? "pack.gz" : ".jar"; //$NON-NLS-1$ //$NON-NLS-2$
+ String extension = options.unpack ? "pack.gz" : ".jar"; //$NON-NLS-1$ //$NON-NLS-2$
File tempDir = new File(getWorkingDirectory(), "temp_" + zipFile.getName()); //$NON-NLS-1$
JarProcessor processor = new JarProcessor();
- processor.setVerbose(verbose);
- processor.setProcessAll(processAll);
+ processor.setVerbose(options.verbose);
+ processor.setProcessAll(options.processAll);
processor.setWorkingDirectory(tempDir.getCanonicalPath());
- if (unpacking) {
- processor.addProcessStep(unpackStep);
+ if (options.unpack) {
+ executor.addPackUnpackStep(processor, properties, options);
}
File outputFile = new File(getWorkingDirectory(), zipFile.getName() + ".temp"); //$NON-NLS-1$
@@ -102,31 +90,31 @@ public class ZipProcessor {
InputStream entryStream = zip.getInputStream(entry);
- boolean pack = packing && !packExclusions.contains(name);
- boolean sign = signing && !signExclusions.contains(name);
- boolean repack = repacking && !packExclusions.contains(name);
+ boolean pack = options.pack && !packExclusions.contains(name);
+ boolean sign = options.signCommand != null && !signExclusions.contains(name);
+ boolean repack = repacking() && !packExclusions.contains(name);
File extractedFile = null;
- if (entry.getName().endsWith(extension) && (pack || sign || repack || unpacking)) {
+ if (entry.getName().endsWith(extension) && (pack || sign || repack || options.unpack)) {
extractedFile = new File(tempDir, name);
parent = extractedFile.getParentFile();
if (!parent.exists())
parent.mkdirs();
- if (verbose)
+ if (options.verbose)
System.out.println("Extracting " + entry.getName()); //$NON-NLS-1$
FileOutputStream extracted = new FileOutputStream(extractedFile);
Utils.transferStreams(entryStream, extracted, true); // this will close the stream
entryStream = null;
- boolean skip = Utils.shouldSkipJar(extractedFile, processAll, verbose);
+ boolean skip = Utils.shouldSkipJar(extractedFile, options.processAll, options.verbose);
if (skip) {
//skipping this file
entryStream = new FileInputStream(extractedFile);
- if (verbose)
+ if (options.verbose)
System.out.println(entry.getName() + " is not marked, skipping."); //$NON-NLS-1$
} else {
- if (unpacking) {
+ if (options.unpack) {
File result = processor.processJar(extractedFile);
name = name.substring(0, name.length() - extractedFile.getName().length()) + result.getName();
extractedFile = result;
@@ -134,19 +122,19 @@ public class ZipProcessor {
if (repack || sign) {
processor.clearProcessSteps();
if (repack)
- processor.addProcessStep(packUnpackStep);
+ executor.addPackUnpackStep(processor, properties, options);
if (sign)
- processor.addProcessStep(signStep);
+ executor.addSignStep(processor, properties, options);
extractedFile = processor.processJar(extractedFile);
}
if (pack) {
processor.clearProcessSteps();
- processor.addProcessStep(packStep);
+ executor.addPackStep(processor, properties, options);
File modifiedFile = processor.processJar(extractedFile);
if (modifiedFile.exists()) {
try {
String newName = name.substring(0, name.length() - extractedFile.getName().length()) + modifiedFile.getName();
- if (verbose) {
+ if (options.verbose) {
System.out.println("Adding " + newName + " to " + outputFile.getPath()); //$NON-NLS-1$ //$NON-NLS-2$
System.out.println();
}
@@ -158,13 +146,13 @@ public class ZipProcessor {
Utils.clear(modifiedFile);
} catch (IOException e) {
Utils.close(entryStream);
- if (verbose) {
+ if (options.verbose) {
e.printStackTrace();
System.out.println("Warning: Problem reading " + modifiedFile.getPath() + ".");
}
}
entryStream = null;
- } else if (verbose) {
+ } else if (options.verbose) {
System.out.println("Warning: " + modifiedFile.getPath() + " not found.");
}
}
@@ -173,14 +161,14 @@ public class ZipProcessor {
try {
entryStream = new FileInputStream(extractedFile);
} catch (IOException e) {
- if (verbose) {
+ if (options.verbose) {
e.printStackTrace();
System.out.println("Warning: Problem reading " + extractedFile.getPath() + ".");
}
}
}
- if (verbose && entryStream != null) {
+ if (options.verbose && entryStream != null) {
System.out.println("Adding " + name + " to " + outputFile.getPath()); //$NON-NLS-1$ //$NON-NLS-2$
}
}
@@ -192,7 +180,7 @@ public class ZipProcessor {
Utils.transferStreams(entryStream, zipOut, false);
zipOut.closeEntry();
} catch (ZipException e) {
- if(verbose) {
+ if(options.verbose) {
System.out.println("Warning: " + name + " already exists in " + outputFile.getName() + ". Skipping.");
}
}
@@ -202,7 +190,7 @@ public class ZipProcessor {
if (extractedFile != null)
Utils.clear(extractedFile);
- if (verbose) {
+ if (options.verbose) {
System.out.println();
System.out.println("Processing " + zipFile.getPath()); //$NON-NLS-1$
}
@@ -227,7 +215,7 @@ public class ZipProcessor {
stream = zip.getInputStream(entry);
properties.load(stream);
} catch (IOException e) {
- if (verbose)
+ if (options.verbose)
e.printStackTrace();
} finally {
Utils.close(stream);
@@ -237,9 +225,7 @@ public class ZipProcessor {
packExclusions = Utils.getPackExclusions(properties);
signExclusions = Utils.getSignExclusions(properties);
- packUnpackStep = new PackUnpackStep(properties, verbose);
- packStep = new PackStep(properties, verbose);
- signStep = new SignCommandStep(properties, command, verbose);
- unpackStep = new UnpackStep(properties, verbose);
+ if (executor == null)
+ executor = new JarProcessorExecutor();
}
}
diff --git a/bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/equinox/internal/p2/jarprocessor/unsigner/UnsignCommand.java b/bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/equinox/internal/p2/jarprocessor/unsigner/UnsignCommand.java
new file mode 100644
index 000000000..0ef56d0b7
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/equinox/internal/p2/jarprocessor/unsigner/UnsignCommand.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * 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 - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.internal.p2.jarprocessor.unsigner;
+
+import java.io.File;
+import java.util.List;
+import java.util.Properties;
+import org.eclipse.equinox.internal.p2.jarprocessor.SignCommandStep;
+
+public class UnsignCommand extends SignCommandStep {
+
+ public UnsignCommand(Properties options, String command, boolean verbose) {
+ super(options, command, verbose);
+ }
+
+ public File postProcess(File input, File workingDirectory, List containers) {
+ if (command != null && input != null && shouldSign(input, containers)) {
+ execute(input);
+ }
+ return null;
+ }
+
+ private void execute(File input) {
+ Unsigner jarUnsigner = new Unsigner();
+ jarUnsigner.setJar(input);
+ jarUnsigner.setKeepManifestEntries(false);
+ jarUnsigner.execute();
+ }
+}
diff --git a/bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/equinox/internal/p2/jarprocessor/unsigner/Unsigner.java b/bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/equinox/internal/p2/jarprocessor/unsigner/Unsigner.java
new file mode 100644
index 000000000..955701938
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/equinox/internal/p2/jarprocessor/unsigner/Unsigner.java
@@ -0,0 +1,147 @@
+/*******************************************************************************
+ * 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.internal.p2.jarprocessor.unsigner;
+import java.io.*;
+import java.util.Enumeration;
+import java.util.jar.JarFile;
+import java.util.jar.Manifest;
+import java.util.zip.*;
+
+/**
+ * This class removes the signature files from a jar and clean up the manifest.
+ */
+public class Unsigner {
+ private static final String META_INF = "META-INF"; //$NON-NLS-1$
+ private static final String DSA_EXT = ".DSA"; //$NON-NLS-1$
+ private static final String RSA_EXT = ".RSA"; //$NON-NLS-1$
+ private static final String SF_EXT = ".SF"; //$NON-NLS-1$
+ private static final String META_INF_PREFIX = META_INF + '/';
+
+ private String[] signers;
+ private File jarFile;
+ private boolean keepManifestContent = false;
+
+ private boolean isSigned(File file) {
+ ZipFile jar = null;
+ try {
+ jar = new ZipFile(file);
+
+ if (signers != null) {
+ for (int i = 0; i < signers.length; i++) {
+ if (jar.getEntry((META_INF_PREFIX + signers[i] + SF_EXT).toUpperCase()) != null)
+ return true;
+ }
+ } else {
+ Enumeration entries = jar.entries();
+ while (entries.hasMoreElements()) {
+ ZipEntry entry = (ZipEntry) entries.nextElement();
+ String entryName = entry.getName();
+ if(entryName.endsWith(SF_EXT) && entryName.startsWith(META_INF))
+ return true;
+ }
+ }
+ return false;
+ } catch (ZipException e) {
+ return false;
+ } catch (IOException e) {
+ return false;
+ } finally {
+ if (jar != null)
+ try {
+ jar.close();
+ } catch (IOException e) {
+ //Ignore
+ }
+ }
+ }
+
+ public void execute() {
+ processJar(jarFile);
+ }
+
+ private void processJar(File inputFile) {
+ if (!isSigned(inputFile))
+ return;
+
+ try {
+ ZipInputStream input = new ZipInputStream(new BufferedInputStream(new FileInputStream(inputFile)));
+ File outputFile = File.createTempFile("removing.", ".signature", inputFile.getParentFile()); //$NON-NLS-1$ //$NON-NLS-2$
+ ZipOutputStream output = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(outputFile)));
+
+ ZipEntry inputZe = input.getNextEntry();
+ byte[] b = new byte[8192];
+ while (inputZe != null) {
+ byte remove = shouldRemove(inputZe);
+ if (remove == 2) {
+ inputZe = input.getNextEntry();
+ continue;
+ }
+
+ //copy the file or modify the manifest.mf
+ if (remove == 1) {
+ output.putNextEntry(new ZipEntry(inputZe.getName()));
+ Manifest m = new Manifest();
+ m.read(input);
+ m.getEntries().clear(); //This is probably not subtle enough
+ m.write(output);
+ } else {
+ output.putNextEntry(inputZe);
+ while (input.available() != 0) {
+ int read = input.read(b);
+ if (read != -1)
+ output.write(b, 0, read);
+ }
+ }
+ output.closeEntry();
+ input.closeEntry();
+
+ inputZe = input.getNextEntry();
+ }
+ output.close();
+ input.close();
+ inputFile.delete();
+ outputFile.renameTo(inputFile);
+ } catch (FileNotFoundException e) {
+ //this can't happen we have checked before
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private byte shouldRemove(ZipEntry entry) {
+ String entryName = entry.getName();
+ if(keepManifestContent == false && entryName.equalsIgnoreCase(JarFile.MANIFEST_NAME)) {
+ return 1;
+ }
+ if (signers != null) {
+ for (int i = 0; i < signers.length; i++) {
+ if (entryName.equalsIgnoreCase(META_INF_PREFIX + signers[i] + SF_EXT) || entryName.equalsIgnoreCase(META_INF_PREFIX + signers[i] + RSA_EXT) || entryName.equalsIgnoreCase(META_INF_PREFIX + signers[i] + DSA_EXT))
+ return 2;
+ }
+ } else {
+ if (entryName.startsWith(META_INF) && (entryName.endsWith(SF_EXT) || entryName.endsWith(RSA_EXT) || entryName.endsWith(DSA_EXT)))
+ return 2;
+ }
+ return 0;
+ }
+
+ public void setRemoveSigners(String[] fileName) {
+ signers = fileName;
+ }
+
+ public void setJar(File file) {
+ jarFile = file;
+ }
+
+ public void setKeepManifestEntries(boolean keep) {
+ keepManifestContent = keep;
+ }
+}
diff --git a/bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/internal/provisional/equinox/p2/jarprocessor/JarProcessorExecutor.java b/bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/internal/provisional/equinox/p2/jarprocessor/JarProcessorExecutor.java
index 29a560e70..6fed1b269 100644
--- a/bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/internal/provisional/equinox/p2/jarprocessor/JarProcessorExecutor.java
+++ b/bundles/org.eclipse.equinox.p2.jarprocessor/src/org/eclipse/internal/provisional/equinox/p2/jarprocessor/JarProcessorExecutor.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2008 IBM Corporation and others.
+ * Copyright (c) 2007, 2009 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
@@ -32,12 +32,8 @@ public class JarProcessorExecutor {
if (options.input.isFile() && options.input.getName().endsWith(".zip")) { //$NON-NLS-1$
ZipProcessor processor = new ZipProcessor();
processor.setWorkingDirectory(options.outputDir);
- processor.setSignCommand(options.signCommand);
- processor.setPack(options.pack);
- processor.setRepack(options.repack || (options.pack && options.signCommand != null));
- processor.setUnpack(options.unpack);
- processor.setVerbose(options.verbose);
- processor.setProcessAll(options.processAll);
+ processor.setOptions(options);
+ processor.setExecutor(this);
try {
processor.processZip(options.input);
} catch (ZipException e) {
diff --git a/bundles/org.eclipse.equinox.p2.jarprocessor/src_ant/org/eclipse/equinox/internal/p2/jarprocessor/ant/AntBasedProcessorExecutor.java b/bundles/org.eclipse.equinox.p2.jarprocessor/src_ant/org/eclipse/equinox/internal/p2/jarprocessor/ant/AntBasedProcessorExecutor.java
new file mode 100644
index 000000000..62e995ef5
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.jarprocessor/src_ant/org/eclipse/equinox/internal/p2/jarprocessor/ant/AntBasedProcessorExecutor.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2009 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 - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.internal.p2.jarprocessor.ant;
+
+import java.util.Properties;
+import org.apache.tools.ant.Project;
+import org.eclipse.equinox.internal.p2.jarprocessor.unsigner.UnsignCommand;
+import org.eclipse.internal.provisional.equinox.p2.jarprocessor.JarProcessor;
+import org.eclipse.internal.provisional.equinox.p2.jarprocessor.JarProcessorExecutor;
+
+public class AntBasedProcessorExecutor extends JarProcessorExecutor {
+ private final Project project;
+ private final Properties signArguments;
+ private final String antTaskName;
+
+ public AntBasedProcessorExecutor(Properties signArguments, Project project, String antTaskName) {
+ this.signArguments = signArguments;
+ this.project = project;
+ this.antTaskName = antTaskName;
+ }
+
+ public void addSignStep(JarProcessor processor, Properties properties, Options options) {
+ if (signArguments.get(JarProcessorTask.UNSIGN) != null)
+ processor.addProcessStep(new UnsignCommand(properties, options.signCommand, options.verbose));
+ if (signArguments.get(JarProcessorTask.SIGN) != null)
+ processor.addProcessStep(new AntSignCommand(properties, signArguments, project, antTaskName, options.signCommand, options.verbose));
+ }
+}
diff --git a/bundles/org.eclipse.equinox.p2.jarprocessor/src_ant/org/eclipse/equinox/internal/p2/jarprocessor/ant/AntSignCommand.java b/bundles/org.eclipse.equinox.p2.jarprocessor/src_ant/org/eclipse/equinox/internal/p2/jarprocessor/ant/AntSignCommand.java
new file mode 100644
index 000000000..591cf8c72
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.jarprocessor/src_ant/org/eclipse/equinox/internal/p2/jarprocessor/ant/AntSignCommand.java
@@ -0,0 +1,59 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2009 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 - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.internal.p2.jarprocessor.ant;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+import java.util.Properties;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.taskdefs.SignJar;
+import org.eclipse.equinox.internal.p2.jarprocessor.SignCommandStep;
+
+public class AntSignCommand extends SignCommandStep {
+ private final Project project;
+ private final Properties jarSignerArguments;
+ private final String antTaskName;
+
+ public AntSignCommand(Properties options, Properties signArguments, Project project, String antTaskName, String command, boolean verbose) {
+ super(options, command, verbose);
+ this.project = project;
+ this.jarSignerArguments = signArguments;
+ this.antTaskName = antTaskName;
+ }
+
+ public File postProcess(File input, File workingDirectory, List containers) {
+ if (command != null && input != null && shouldSign(input, containers)) {
+ execute(input);
+ }
+ return null;
+ }
+
+ private void execute(File input) {
+ try {
+ SignJar jarSigner = new SignJar();
+ jarSigner.setJar(input);
+ jarSigner.setAlias(jarSignerArguments.getProperty(JarProcessorTask.ALIAS));
+ jarSigner.setKeystore(jarSignerArguments.getProperty(JarProcessorTask.KEYSTORE));
+ jarSigner.setStorepass(jarSignerArguments.getProperty(JarProcessorTask.STOREPASS));
+ jarSigner.setKeypass(jarSignerArguments.getProperty(JarProcessorTask.KEYPASS));
+ jarSigner.setProject(project);
+ jarSigner.setTaskName(antTaskName);
+ jarSigner.execute();
+ } catch (BuildException e) {
+ if (e.getCause() instanceof IOException) {
+ throw new BuildException("The jarsigner could not be found. Make sure to run with the build with a JDK.", e); //$NON-NLS-1$
+ }
+ throw e;
+ }
+ }
+}
diff --git a/bundles/org.eclipse.equinox.p2.jarprocessor/src_ant/org/eclipse/equinox/internal/p2/jarprocessor/ant/JarProcessorTask.java b/bundles/org.eclipse.equinox.p2.jarprocessor/src_ant/org/eclipse/equinox/internal/p2/jarprocessor/ant/JarProcessorTask.java
new file mode 100644
index 000000000..9989bcac9
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.jarprocessor/src_ant/org/eclipse/equinox/internal/p2/jarprocessor/ant/JarProcessorTask.java
@@ -0,0 +1,110 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2009 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 - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.internal.p2.jarprocessor.ant;
+
+import java.io.File;
+import java.util.Properties;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Task;
+import org.eclipse.internal.provisional.equinox.p2.jarprocessor.JarProcessorExecutor.Options;
+
+/**
+ * This task provides massaging facilities for jar files.
+ * It supports: signing, unsigning, normalization, packing
+ * -
+ */
+public class JarProcessorTask extends Task {
+ private final Options options = new Options();
+ private final Properties signArgs = new Properties();
+
+ public static final String ALIAS = "alias"; //$NON-NLS-1$
+ public static final String KEYSTORE = "keystore"; //$NON-NLS-1$
+ public static final String STOREPASS = "storepass"; //$NON-NLS-1$
+ public static final String KEYPASS = "keypass"; //$NON-NLS-1$
+ public static final String UNSIGN = "unsign"; //$NON-NLS-1$
+ public static final String SIGN = "sign"; //$NON-NLS-1$
+
+ private static final String FAKE_COMMAND = "fake"; //$NON-NLS-1$
+
+ public void setAlias(String alias) {
+ signArgs.setProperty(ALIAS, alias);
+ }
+
+ public void setKeystore(String keystore) {
+ signArgs.setProperty(KEYSTORE, keystore);
+ }
+
+ public void setJar(File jar) {
+ options.input = jar;
+ options.outputDir = jar.getParentFile().getAbsolutePath();
+ }
+
+ public void setInputFolder(File folder) {
+ options.input = folder;
+ options.outputDir = folder.getAbsolutePath();
+ }
+
+ public void setStorepass(String storepass) {
+ signArgs.setProperty(STOREPASS, storepass);
+ }
+
+ public void setKeypass(String keypass) {
+ if (keypass != null && keypass.length() > 0 && !keypass.startsWith("${")) //$NON-NLS-1$
+ signArgs.setProperty(KEYPASS, keypass);
+ }
+
+ public void setPack(boolean pack) {
+ options.pack = pack;
+ }
+
+ public void setNormalize(boolean normalize) {
+ options.repack = normalize;
+ }
+
+ public void setUnsign(boolean unsign) {
+ if (unsign) {
+ signArgs.put(UNSIGN, Boolean.TRUE.toString());
+ options.signCommand = FAKE_COMMAND;
+ }
+ }
+
+ public void setSign(boolean sign) {
+ if (sign) {
+ signArgs.put(SIGN, Boolean.TRUE.toString());
+ options.signCommand = FAKE_COMMAND;
+ }
+ }
+
+ private void adjustAndValidateConfiguration() {
+ //Sign and pack implies a normalization
+ if (options.signCommand != null && options.pack)
+ options.repack = true;
+
+ //Check that alias, and storepass are set
+ if (options.signCommand != null && signArgs.getProperty(UNSIGN) == null) {
+ if (signArgs.getProperty(ALIAS) == null)
+ throw new BuildException("Alias must be set"); //$NON-NLS-1$
+
+ if (signArgs.getProperty(STOREPASS) == null)
+ throw new BuildException("Storepass must be set"); //$NON-NLS-1$
+ }
+ }
+
+ public void execute() {
+ options.processAll = true;
+ adjustAndValidateConfiguration();
+ new AntBasedProcessorExecutor(signArgs, getProject(), getTaskName()).runJarProcessor(options);
+ }
+
+ public void setVerbose(boolean verbose) {
+ options.verbose = verbose;
+ }
+}

Back to the top