Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 38035 Details for
Bug 127375
Add update site performance enhancement utility
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Handle nested jars
update.pack200.txt (text/plain), 58.29 KB, created by
Andrew Niefer
on 2006-04-07 15:48:54 EDT
(
hide
)
Description:
Handle nested jars
Filename:
MIME Type:
Creator:
Andrew Niefer
Created:
2006-04-07 15:48:54 EDT
Size:
58.29 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.update.core >Index: src/org/eclipse/update/core/FeatureContentProvider.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.update.core/src/org/eclipse/update/core/FeatureContentProvider.java,v >retrieving revision 1.61 >diff -u -r1.61 FeatureContentProvider.java >--- src/org/eclipse/update/core/FeatureContentProvider.java 29 Mar 2006 23:37:07 -0000 1.61 >+++ src/org/eclipse/update/core/FeatureContentProvider.java 7 Apr 2006 19:36:45 -0000 >@@ -109,7 +109,15 @@ > > // hashtable of locks > private static Hashtable locks = new Hashtable(); >- >+ >+ protected static Object getLock(String key) { >+ synchronized (lock) { >+ if (locks.get(key) == null) >+ locks.put(key, key); >+ return locks.get(key); >+ } >+ } >+ > /** > * Feature content provider constructor > * >@@ -179,13 +187,7 @@ > // is still copying into it > File localFile = null; > FileFragment localFileFragment = null; >- Object keyLock = null; >- synchronized (lock) { >- if (locks.get(key) == null) >- locks.put(key, key); >- keyLock = locks.get(key); >- } >- >+ Object keyLock = getLock(key); > synchronized (keyLock) { > localFile = Utilities.lookupLocalFile(key); > if (localFile != null) { >Index: src/org/eclipse/update/internal/core/FeaturePackagedContentProvider.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.update.core/src/org/eclipse/update/internal/core/FeaturePackagedContentProvider.java,v >retrieving revision 1.46 >diff -u -r1.46 FeaturePackagedContentProvider.java >--- src/org/eclipse/update/internal/core/FeaturePackagedContentProvider.java 6 Apr 2006 17:02:53 -0000 1.46 >+++ src/org/eclipse/update/internal/core/FeaturePackagedContentProvider.java 7 Apr 2006 19:36:45 -0000 >@@ -10,15 +10,16 @@ > *******************************************************************************/ > package org.eclipse.update.internal.core; > import java.io.*; >-import java.net.*; >+import java.net.URL; > import java.util.*; >- >-import org.eclipse.core.runtime.*; >+import org.eclipse.core.runtime.CoreException; > import org.eclipse.osgi.internal.provisional.verifier.CertificateVerifierFactory; > import org.eclipse.osgi.util.NLS; > import org.eclipse.update.core.*; >+import org.eclipse.update.core.model.SiteModel; > import org.eclipse.update.internal.security.JarVerifier; > import org.eclipse.update.internal.verifier.CertVerifier; >+import org.eclipse.update.jarprocessor.JarProcessor; > > /** > * Content Provider of a Feature Package >@@ -28,7 +29,7 @@ > private ContentReference localManifest = null; > private ContentReference[] localFeatureFiles = new ContentReference[0]; > private IVerifier jarVerifier = null; >- >+ private SiteModel siteModel = null; > /* > * filter for file with .jar > */ >@@ -64,6 +65,13 @@ > return jarVerifier; > } > >+ public void setFeature(IFeature feature) { >+ super.setFeature(feature); >+ ISite featureSite = feature.getSite(); >+ if(featureSite instanceof SiteModel){ >+ siteModel = (SiteModel) featureSite; >+ } >+ } > /* > * @see IFeatureContentProvider#getFeatureManifestReference() > */ >@@ -168,13 +176,64 @@ > URL url = (siteContentProvider == null) ? null : siteContentProvider.getArchiveReference(archiveID); > > try { >- references[0] = asLocalReference(new JarContentReference(archiveID, url), monitor); >+ references[0] = retrieveLocalJar(new JarContentReference(archiveID, url), monitor); > } catch (IOException e) { > throw errorRetrieving(archiveID, references[0], e); > } > return references; > } > >+ private ContentReference retrieveLocalJar(JarContentReference reference, InstallMonitor monitor) throws IOException, CoreException { >+ //If the site does not support pack200, just get the jar as normal >+ if(siteModel == null || !siteModel.supportsPack200() || !JarProcessor.canPerformUnpack()) { >+ return asLocalReference(reference, monitor); >+ } >+ >+ ContentReference packedRef = null; >+ String key = reference.toString(); >+ Object jarLock = getLock(key); >+ synchronized (jarLock) { >+ //do we have this jar already? >+ File localFile = Utilities.lookupLocalFile(key); >+ if (localFile != null) { >+ // check if the cached file is still valid (no newer version on server) >+ if (UpdateManagerUtils.isSameTimestamp(reference.asURL(), localFile.lastModified())) >+ return reference.createContentReference(reference.getIdentifier(), localFile); >+ } >+ >+ try { >+ //don't have jar, check for pack.gz >+ URL packGZURL = new URL(reference.asURL().toExternalForm() + ".pack.gz"); //$NON-NLS-1$ >+ packedRef = asLocalReference(new JarContentReference(reference.getIdentifier(), packGZURL), monitor); >+ } catch (IOException e) { >+ //no pack.gz >+ } >+ } >+ if (packedRef == null) { >+ //no pack.gz on server, get normal jar >+ return asLocalReference(reference, monitor); >+ } >+ >+ synchronized (jarLock) { >+ Object packedLock = getLock(packedRef.toString()); >+ synchronized (packedLock) { >+ File tempFile = packedRef.asFile(); >+ long timeStamp = tempFile.lastModified(); >+ >+ JarProcessor processor = JarProcessor.getUnpackProcessor(null); >+ processor.setWorkingDirectory(tempFile.getParent()); >+ >+ File packedFile = new File(tempFile.toString() + ".pack.gz"); //$NON-NLS-1$ >+ tempFile.renameTo(packedFile); >+ //unpacking the jar will strip the ".pack.gz" and leave us back with the original filename >+ processor.processJar(packedFile); >+ >+ tempFile.setLastModified(timeStamp); >+ Utilities.mapLocalFile(key, tempFile); >+ } >+ } >+ return packedRef; >+ } > /* > * @see IFeatureContentProvider#getNonPluginEntryArchiveReferences(INonPluginEntry) > */ >Index: src/org/eclipse/update/core/model/SiteModel.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.update.core/src/org/eclipse/update/core/model/SiteModel.java,v >retrieving revision 1.21 >diff -u -r1.21 SiteModel.java >--- src/org/eclipse/update/core/model/SiteModel.java 1 Mar 2005 20:29:16 -0000 1.21 >+++ src/org/eclipse/update/core/model/SiteModel.java 7 Apr 2006 19:36:45 -0000 >@@ -45,6 +45,7 @@ > private URL locationURL; > private String mirrorsURLString; > private ConfiguredSiteModel configuredSiteModel; >+ private boolean pack200 = false; > > /** > * Creates an uninitialized site model object. >@@ -447,4 +448,22 @@ > assertIsWriteable(); > this.mirrorsURLString = mirrorsURL; > } >+ >+ /** >+ * Get whether or not this site may contain jars packed with pack200. >+ * The packed version of foo.jar, is expected to be foo.jar.pack.gz >+ * @return >+ */ >+ public boolean supportsPack200() { >+ return pack200; >+ } >+ >+ /** >+ * Set whether or not this site may contain jars packed with pack200 >+ * The packed version of foo.jar is expected to be foo.jar.pack.gz >+ * @param pack >+ */ >+ public void setSupportsPack200(boolean pack){ >+ pack200 = pack; >+ } > } >Index: src/org/eclipse/update/core/model/DefaultSiteParser.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.update.core/src/org/eclipse/update/core/model/DefaultSiteParser.java,v >retrieving revision 1.70 >diff -u -r1.70 DefaultSiteParser.java >--- src/org/eclipse/update/core/model/DefaultSiteParser.java 30 Mar 2006 02:34:37 -0000 1.70 >+++ src/org/eclipse/update/core/model/DefaultSiteParser.java 7 Apr 2006 19:36:45 -0000 >@@ -513,6 +513,11 @@ > site.setMirrorsURLString(mirrorsURL); > } > >+ String pack200 = attributes.getValue("pack200"); //$NON-NLS-1$ >+ if(pack200 != null && new Boolean(pack200).booleanValue()){ >+ site.setSupportsPack200(true); >+ } >+ > if ( (site instanceof ExtendedSite) && (Boolean.getBoolean(attributes.getValue("digestURL")))) { //$NON-NLS-1$ > ExtendedSite extendedSite = (ExtendedSite) site; > extendedSite.setDigestExist(true); >Index: src/org/eclipse/update/jarprocessor/pack-readme.html >=================================================================== >RCS file: src/org/eclipse/update/jarprocessor/pack-readme.html >diff -N src/org/eclipse/update/jarprocessor/pack-readme.html >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/update/jarprocessor/pack-readme.html 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,82 @@ >+<!DOCTYPE html PUBLIC "-//w3c//dtd html 4.0 transitional//en"> >+<html> >+<head> >+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> >+ <title>Eclipse update packing tool readme</title> >+</head> >+<body> >+<h1>Eclipse update packing tool</h1> >+ >+<h3>Overview</h3> >+The update packing tool processes a hierarchy of arbitrarily nested >+JARs and ZIP files. It is a generic utility that performs a depth first traversal of >+a nested hierarchy of ZIPs and JARs, performs various commands on >+each of the JARs in the hierarchy, and then rebuilds the same hierarchy >+of ZIPs and JARs again. Currently its main functions are: >+<ul> >+ <li>Packing JARs using the Java 1.5 <a href="http://java.sun.com/j2se/1.5.0/docs/tooldocs/share/pack200.html">pack200</a> >+ command.</li> >+ <li>Unpacking PACK.GZs using the Java 1.5 <a href="http://java.sun.com/j2se/1.5.0/docs/tooldocs/share/unpack200.html">unpack200</a> >+ command.</li> >+ <li>Normalizing JARs for future compression by pack200. This is accomplished >+ by running the pack200 command with the <tt>--repack</tt> command line argument.</li> >+ <li>Signing JARs to allow for authentication of the origin of JARs. This is accomplished by >+ running a supplied command (typically the command will just be a wrapper around >+ the Java <a href="http://java.sun.com/j2se/1.3/docs/tooldocs/win32/jarsigner.html">jarsigner</a> tool).</li> >+</ul> >+The packing tool is used in the following contexts: >+<ul> >+ <li>During a PDE build, to prepare JARs for uploading to an Eclipse >+ update site. In this usage, it is used to both nomalize JAR contents >+ (pack200 -repack), and sign JARs.</li> >+ <li>On an update site, to convert traditional JAR content into the >+ compressed pack200 format.</li> >+ <li>From an Eclipse client application during update, to convert >+ compressed pack200 format content into executable JAR files.</li> >+</ul> >+<h3>Tool usage</h3> >+To run the packing tool, you need a 1.5 JRE installed. The tool is run >+by invoking Java as follows: >+ >+<pre> >+ java jarprocessor.jar [options] input >+</pre> >+ >+Where <tt>input</tt> is either a zip file, a directory, or a JAR (or a pack.gz file). All files ending >+in ".jar" or ".pack.gz" in the provided zip or directory hierarchy >+will be processed. >+The following additional command line arguments are supported: >+<ul> >+<li>-repack : Normalize the jars using pack200 <tt>--repack</tt></li> >+<li>-sign <cmd> : signs the jars by executing the provided command. >+The command will be provided a single argument that will be the full path of the JAR to process. >+</li> >+<li>-pack : for each input in JAR form, produce a corresponding output >+in packed form. For an input "a.jar", the output is a.jar.pack.gz. >+</li> >+<li>-unpack : for each input in packed form, produce a corresponding output >+in unpacked form. For an input "a.jar.pack.gz", the output is "a.jar". -unpack is mutually exclusive with -repack, -pack and -sign.</li> >+<li>-outputDir <dir> : The directory to put the tool's output into. If the input was a zip file, then an output zip file will be >+created containg all the output files. If the input was a directory, for each input file there is a corresponding output file in the output directory. By default the current working directory is used. If the input is in the same >+directory as the output, the input files may be overwritten.</li> >+</ul> >+ >+Additionally, when the input is a zip file, it may contain a file called >+<tt>pack.properties</tt>. The pack.properties file supports the following values: >+<ul> >+<li>pack.excludes = jarName[, jarName]* : A comma-delimited list of JARs that should not be packed or repacked. >+</li> >+<li>sign.excludes = jarName[, jarName]* : A comma-delimited list of JARs that should not be signed. >+</li> >+<li><jarname>.pack.args = option[, option]* : A comma-delimited list of additional arguments that should >+be passed to pack200 when packing any jar with name <jarname>. >+</ul> >+</p> >+<p> >+<font size=-1> >+Copyright (c) IBM Corporation and others 2006. All rights reserved. This program and the accompanying materials >+are made available under the terms of the >+<a href="http://www.eclipse.org/legal/epl-v10.html">Eclipse Public License v1.0</a>. >+</font> >+</body> >+</html> >Index: src/org/eclipse/update/jarprocessor/internal/CommandStep.java >=================================================================== >RCS file: src/org/eclipse/update/jarprocessor/internal/CommandStep.java >diff -N src/org/eclipse/update/jarprocessor/internal/CommandStep.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/update/jarprocessor/internal/CommandStep.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,49 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 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.update.jarprocessor.internal; >+ >+import java.io.IOException; >+import java.util.Properties; >+import org.eclipse.update.jarprocessor.IProcessStep; >+ >+/** >+ * @author aniefer >+ * >+ */ >+public abstract class CommandStep implements IProcessStep { >+ protected String command = null; >+ protected String extension = null; >+ protected Properties options = null; >+ >+ public CommandStep(Properties options, String command, String extension) { >+ this.command = command; >+ this.extension = extension; >+ this.options = options; >+ } >+ >+ protected static int execute(String[] cmd) throws IOException { >+ Runtime runtime = Runtime.getRuntime(); >+ Process proc = runtime.exec(cmd); >+ try { >+ int result = proc.waitFor(); >+ return result; >+ } catch (InterruptedException e) { >+ //ignore >+ } >+ return -1; >+ } >+ >+ public Properties getOptions() { >+ if(options == null) >+ options = new Properties(); >+ return options; >+ } >+} >Index: src/org/eclipse/update/jarprocessor/Main.java >=================================================================== >RCS file: src/org/eclipse/update/jarprocessor/Main.java >diff -N src/org/eclipse/update/jarprocessor/Main.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/update/jarprocessor/Main.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,152 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 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.update.jarprocessor; >+ >+import java.io.*; >+import java.util.zip.ZipException; >+import org.eclipse.update.jarprocessor.internal.*; >+ >+/** >+ * @author aniefer >+ * >+ */ >+public class Main { >+ >+ public static class Options { >+ public String outputDir = "."; //$NON-NLS-1$ >+ public String signCommand = null; >+ public boolean pack = false; >+ public boolean repack = false; >+ public boolean unpack = false; >+ public File input = null; >+ } >+ >+ private static void printUsage() { >+ System.out.println("[-option ...]... input"); //$NON-NLS-1$ >+ System.out.println("The following options are supported:"); //$NON-NLS-1$ >+ System.out.println("-repack normalize jars "); //$NON-NLS-1$ >+ System.out.println("-sign <command> sign jars using <command>"); //$NON-NLS-1$ >+ System.out.println("-pack pack the jars. pack and repack are redundant unless"); //$NON-NLS-1$ >+ System.out.println(" sign is also specified."); //$NON-NLS-1$ >+ System.out.println("-unpack unpack pack.gz files. Unpack is mutually exclusive"); //$NON-NLS-1$ >+ System.out.println(" with repack, sign and pack."); //$NON-NLS-1$ >+ System.out.println(); >+ System.out.println("-outputDir <dir> the output directory"); //$NON-NLS-1$ >+ } >+ >+ public static Options processArguments(String[] args) { >+ if (args.length == 0) { >+ printUsage(); >+ return null; >+ } >+ >+ Options options = new Options(); >+ int i = 0; >+ for (; i < args.length - 1; i++) { >+ if (args[i].equals("-pack")) {//$NON-NLS-1$ >+ options.pack = true; >+ } else if (args[i].equals("-unpack")) { //$NON-NLS-1$ >+ options.unpack = true; >+ } else if (args[i].equals("-sign") && i < args.length - 2) { //$NON-NLS-1$ >+ if (args[i + 1].startsWith("-")) { //$NON-NLS-1$ >+ printUsage(); >+ return null; >+ } >+ options.signCommand = args[++i]; >+ } else if (args[i].equals("-repack")) { //$NON-NLS-1$ >+ options.repack = true; >+ } else if (args[i].equals("-outputDir") && i < args.length - 2) { //$NON-NLS-1$ >+ if (args[i + 1].startsWith("-")) { //$NON-NLS-1$ >+ printUsage(); >+ return null; >+ } >+ options.outputDir = args[++i]; >+ } >+ } >+ >+ options.input = new File(args[i]); >+ >+ String problemMessage = null; >+ if (options.unpack) { >+ if (!JarProcessor.canPerformUnpack()) { >+ problemMessage = "The unpack200 command cannot be found."; //$NON-NLS-1$ >+ } else if (options.input.isFile() && !args[i].endsWith(".zip") && !args[i].endsWith(".pack.gz")) { //$NON-NLS-1$ //$NON-NLS-2$ >+ problemMessage = "Input file is not a pack.gz file."; //$NON-NLS-1$ >+ } else if (options.pack || options.repack || options.signCommand != null) { >+ problemMessage = "Pack, repack or sign cannot be specified with unpack."; //$NON-NLS-1$ >+ } >+ } else { >+ if (options.input.isFile() && !args[i].endsWith(".zip") && !args[i].endsWith(".jar")) { //$NON-NLS-1$ //$NON-NLS-2$ >+ problemMessage = "Input file is not a jar file."; //$NON-NLS-1$ >+ } else if ((options.pack || options.repack) && !JarProcessor.canPerformUnpack()) { >+ problemMessage = "The pack200 command can not be found."; //$NON-NLS-1$ >+ } >+ } >+ if(problemMessage != null){ >+ System.out.println(problemMessage); >+ System.out.println(); >+ printUsage(); >+ return null; >+ } >+ >+ return options; >+ } >+ >+ /** >+ * @param args >+ * @throws FileNotFoundException >+ */ >+ public static void main(String[] args) { >+ Options options = processArguments(args); >+ if (options == null) >+ return; >+ >+ if (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); >+ try { >+ processor.processZip(options.input); >+ } catch (ZipException e) { >+ // TODO Auto-generated catch block >+ e.printStackTrace(); >+ } catch (IOException e) { >+ // TODO Auto-generated catch block >+ e.printStackTrace(); >+ } >+ } else { >+ JarProcessor processor = new JarProcessor(); >+ processor.setWorkingDirectory(options.outputDir); >+ >+ if (options.repack || (options.pack && options.signCommand != null)) >+ processor.addProcessStep(new PackUnpackStep(null)); >+ >+ if (options.signCommand != null) >+ processor.addProcessStep(new SignCommandStep(null, options.signCommand)); >+ >+ if (options.pack) >+ processor.addProcessStep(new PackStep(null)); >+ else if (options.unpack) >+ processor.addProcessStep(new UnpackStep(null)); >+ >+ try { >+ processor.process(options.input, options.unpack ? Utils.PACK_GZ_FILTER : Utils.JAR_FILTER); >+ } catch (FileNotFoundException e) { >+ // TODO Auto-generated catch block >+ e.printStackTrace(); >+ } >+ } >+ } >+ >+} >Index: src/org/eclipse/update/jarprocessor/JarProcessor.java >=================================================================== >RCS file: src/org/eclipse/update/jarprocessor/JarProcessor.java >diff -N src/org/eclipse/update/jarprocessor/JarProcessor.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/update/jarprocessor/JarProcessor.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,271 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 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.update.jarprocessor; >+ >+import java.io.*; >+import java.util.*; >+import java.util.jar.*; >+import org.eclipse.update.jarprocessor.internal.*; >+ >+/** >+ * @author aniefer >+ * >+ */ >+public class JarProcessor { >+ private List steps = new ArrayList(); >+ private String workingDirectory = ""; //$NON-NLS-1$ >+ private int depth = -1; >+ >+ static public JarProcessor getUnpackProcessor(Properties properties) { >+ if (!canPerformUnpack()) >+ throw new UnsupportedOperationException(); >+ JarProcessor processor = new JarProcessor(); >+ processor.addProcessStep(new UnpackStep(properties)); >+ return processor; >+ } >+ >+ static public JarProcessor getPackProcessor(Properties properties) { >+ if (!canPerformPack()) >+ throw new UnsupportedOperationException(); >+ JarProcessor processor = new JarProcessor(); >+ processor.addProcessStep(new PackStep(properties)); >+ return processor; >+ } >+ >+ static public boolean canPerformPack() { >+ return PackStep.canPack(); >+ } >+ >+ static public boolean canPerformUnpack() { >+ return UnpackStep.canUnpack(); >+ } >+ >+ public String getWorkingDirectory() { >+ return workingDirectory; >+ } >+ >+ public void setWorkingDirectory(String dir) { >+ workingDirectory = dir; >+ } >+ >+ public void addProcessStep(IProcessStep step) { >+ steps.add(step); >+ } >+ >+ public void clearProcessSteps() { >+ steps.clear(); >+ } >+ >+ public void process(File input, FileFilter filter) throws FileNotFoundException { >+ if (!input.exists()) >+ throw new FileNotFoundException(); >+ >+ File[] files = null; >+ if (input.isDirectory()) { >+ files = input.listFiles(); >+ } else if (filter.accept(input)) { >+ files = new File[] {input}; >+ } >+ for (int i = 0; i < files.length; i++) { >+ System.out.println("Processing " + files[i].getName()); //$NON-NLS-1$ >+ if (files[i].isDirectory()) { >+ String dir = getWorkingDirectory(); >+ setWorkingDirectory(dir + "/" + files[i].getName()); //$NON-NLS-1$ >+ process(files[i], filter); >+ setWorkingDirectory(dir); >+ } else if (filter.accept(files[i])) { >+ try { >+ processJar(files[i]); >+ } catch (IOException e) { >+ // TODO Auto-generated catch block >+ e.printStackTrace(); >+ } >+ } >+ } >+ } >+ >+ /** >+ * Recreate a jar file. The replacements map specifies entry names to be replaced, the replacements are >+ * expected to be found in directory. >+ * >+ * @param jar - The input jar >+ * @param outputJar - the output >+ * @param replacements - map of entryName -> new entryName >+ * @param directory - location to find file for new entryName >+ * @throws IOException >+ */ >+ private void recreateJar(JarFile jar, JarOutputStream outputJar, Map replacements, File directory) throws IOException { >+ InputStream in = null; >+ try { >+ Enumeration entries = jar.entries(); >+ for (JarEntry entry = (JarEntry) entries.nextElement(); entry != null; entry = entries.hasMoreElements() ? (JarEntry) entries.nextElement() : null) { >+ File replacement = null; >+ JarEntry newEntry = null; >+ if (replacements.containsKey(entry.getName())) { >+ String name = (String) replacements.get(entry.getName()); >+ replacement = new File(directory, name); >+ in = new BufferedInputStream(new FileInputStream(replacement)); >+ newEntry = new JarEntry(name); >+ } else { >+ in = new BufferedInputStream(jar.getInputStream(entry)); >+ newEntry = new JarEntry(entry.getName()); >+ } >+ newEntry.setTime(entry.getTime()); >+ outputJar.putNextEntry(newEntry); >+ Utils.transferStreams(in, outputJar, false); >+ outputJar.closeEntry(); >+ in.close(); >+ >+ //delete the nested jar file >+ if (replacement != null) { >+ replacement.delete(); >+ } >+ } >+ } finally { >+ Utils.close(outputJar); >+ Utils.close(jar); >+ Utils.close(in); >+ } >+ } >+ >+ private String recursionEffect(String entryName) { >+ String result = null; >+ for (Iterator iter = steps.iterator(); iter.hasNext();) { >+ IProcessStep step = (IProcessStep) iter.next(); >+ >+ result = step.recursionEffect(entryName); >+ if (result != null) >+ entryName = result; >+ } >+ return result; >+ } >+ >+ private void extractEntries(JarFile jar, File tempDir, Map data) throws IOException { >+ Enumeration entries = jar.entries(); >+ if (entries.hasMoreElements()) { >+ for (JarEntry entry = (JarEntry) entries.nextElement(); entry != null; entry = entries.hasMoreElements() ? (JarEntry) entries.nextElement() : null) { >+ String name = entry.getName(); >+ String newName = recursionEffect(name); >+ if (newName != null) { >+ //extract entry to temp directory >+ File extracted = new File(tempDir, name); >+ File parentDir = extracted.getParentFile(); >+ if (!parentDir.exists()) >+ parentDir.mkdirs(); >+ >+ InputStream in = null; >+ OutputStream out = null; >+ try { >+ in = jar.getInputStream(entry); >+ out = new BufferedOutputStream(new FileOutputStream(extracted)); >+ Utils.transferStreams(in, out, true); //this will close both streams >+ } finally { >+ Utils.close(in); >+ Utils.close(out); >+ } >+ extracted.setLastModified(entry.getTime()); >+ data.put(name, newName); >+ >+ //recurse >+ String dir = getWorkingDirectory(); >+ setWorkingDirectory(parentDir.getCanonicalPath()); >+ processJar(extracted); >+ setWorkingDirectory(dir); >+ >+ //delete the extracted item leaving the recursion result >+ if (!name.equals(newName)) >+ extracted.delete(); >+ } >+ } >+ } >+ } >+ >+ private File preProcess(File input, File tempDir) { >+ File result = null; >+ for (Iterator iter = steps.iterator(); iter.hasNext();) { >+ IProcessStep step = (IProcessStep) iter.next(); >+ result = step.preProcess(input, tempDir); >+ if (result != null) >+ input = result; >+ } >+ return input; >+ } >+ >+ private File postProcess(File input, File tempDir) { >+ File result = null; >+ for (Iterator iter = steps.iterator(); iter.hasNext();) { >+ IProcessStep step = (IProcessStep) iter.next(); >+ result = step.postProcess(input, tempDir); >+ if (result != null) >+ input = result; >+ } >+ return input; >+ } >+ >+ public void processJar(File input) throws IOException { >+ ++depth; >+ long lastModified = input.lastModified(); >+ File workingDir = new File(getWorkingDirectory()); >+ if (!workingDir.exists()) >+ workingDir.mkdirs(); >+ >+ //pre >+ File workingFile = preProcess(input, workingDir); >+ >+ //Extract entries from jar and recurse on them >+ File tempDir = null; >+ if (depth == 0) { >+ tempDir = new File(workingDir, "temp." + workingFile.getName()); //$NON-NLS-1$ >+ } else { >+ File parent = workingDir.getParentFile(); >+ tempDir = new File(parent, "temp_" + depth + '_' + workingFile.getName()); //$NON-NLS-1$ >+ } >+ >+ JarFile jar = new JarFile(workingFile, false); >+ Map replacements = new HashMap(); >+ extractEntries(jar, tempDir, replacements); >+ >+ //Recreate the jar with replacements. This also has the effect of normalizing the jar, so we want to do this even if >+ //we aren't actually replacing anything >+ File tempJar = null; >+ tempJar = new File(tempDir, workingFile.getName()); >+ File parent = tempJar.getParentFile(); >+ if (!parent.exists()) >+ parent.mkdirs(); >+ JarOutputStream jarOut = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(tempJar))); >+ recreateJar(jar, jarOut, replacements, tempDir); >+ >+ jar.close(); >+ if (tempJar != null) { >+ if (!workingFile.equals(input)) { >+ workingFile.delete(); >+ } >+ workingFile = tempJar; >+ } >+ >+ //post >+ File result = postProcess(workingFile, workingDir); >+ if (!result.equals(workingFile) && !workingFile.equals(input)) >+ workingFile.delete(); >+ if (!result.getParentFile().equals(workingDir)) { >+ File finalFile = new File(workingDir, result.getName()); >+ if (finalFile.exists()) >+ finalFile.delete(); >+ result.renameTo(finalFile); >+ } >+ >+ if (tempDir.exists()) >+ Utils.clear(tempDir); >+ >+ result.setLastModified(lastModified); >+ --depth; >+ } >+} >Index: src/org/eclipse/update/jarprocessor/internal/ZipProcessor.java >=================================================================== >RCS file: src/org/eclipse/update/jarprocessor/internal/ZipProcessor.java >diff -N src/org/eclipse/update/jarprocessor/internal/ZipProcessor.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/update/jarprocessor/internal/ZipProcessor.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,171 @@ >+/** >+ * >+ */ >+package org.eclipse.update.jarprocessor.internal; >+ >+import java.io.*; >+import java.util.*; >+import java.util.zip.*; >+import org.eclipse.update.jarprocessor.IProcessStep; >+import org.eclipse.update.jarprocessor.JarProcessor; >+ >+/** >+ * @author aniefer >+ * >+ */ >+public class ZipProcessor { >+ >+ private IProcessStep signStep = null; >+ private IProcessStep packStep = null; >+ private IProcessStep packUnpackStep = null; >+ private IProcessStep unpackStep = 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; >+ >+ public void setWorkingDirectory(String dir) { >+ workingDirectory = dir; >+ } >+ >+ public String getWorkingDirectory() { >+ if (workingDirectory == null) >+ workingDirectory = "."; //$NON-NLS-1$ >+ 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 processZip(File zipFile) throws ZipException, IOException { >+ ZipFile zip = new ZipFile(zipFile); >+ initialize(zip); >+ >+ String extension = unpacking ? "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.setWorkingDirectory(tempDir.getCanonicalPath()); >+ if (unpacking) { >+ processor.addProcessStep(unpackStep); >+ } >+ >+ File outputFile = new File(getWorkingDirectory(), zipFile.getName() + ".temp"); //$NON-NLS-1$ >+ File parent = outputFile.getParentFile(); >+ if (!parent.exists()) >+ parent.mkdirs(); >+ ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(outputFile)); >+ Enumeration entries = zip.entries(); >+ if (entries.hasMoreElements()) { >+ for (ZipEntry entry = (ZipEntry) entries.nextElement(); entry != null; entry = entries.hasMoreElements() ? (ZipEntry) entries.nextElement() : null) { >+ String name = entry.getName(); >+ >+ InputStream entryStream = zip.getInputStream(entry); >+ >+ boolean pack = packing && !packExclusions.contains(name); >+ boolean sign = signing && !signExclusions.contains(name); >+ boolean repack = repacking && !packExclusions.contains(name); >+ >+ File extractedFile = null; >+ >+ if (entry.getName().endsWith(extension) && (pack || sign || repack || unpacking)) { >+ extractedFile = new File(tempDir, name); >+ parent = extractedFile.getParentFile(); >+ if (!parent.exists()) >+ parent.mkdirs(); >+ FileOutputStream extracted = new FileOutputStream(extractedFile); >+ Utils.transferStreams(entryStream, extracted, true); >+ >+ if (unpacking) { >+ processor.processJar(extractedFile); >+ name = name.substring(0, name.length() - Utils.PACKED_SUFFIX.length()); >+ extractedFile = new File(tempDir, name); >+ } else { >+ processor.clearProcessSteps(); >+ if (repack) >+ processor.addProcessStep(packUnpackStep); >+ if (sign) >+ processor.addProcessStep(signStep); >+ processor.processJar(extractedFile); >+ extractedFile = new File(tempDir, extractedFile.getName()); >+ if (pack) { >+ processor.clearProcessSteps(); >+ processor.addProcessStep(packStep); >+ processor.processJar(extractedFile); >+ >+ File modifiedFile = new File(tempDir, extractedFile.getName() + Utils.PACKED_SUFFIX); >+ ZipEntry zipEntry = new ZipEntry(name + Utils.PACKED_SUFFIX); >+ entryStream = new FileInputStream(modifiedFile); >+ zipOut.putNextEntry(zipEntry); >+ Utils.transferStreams(entryStream, zipOut, false); >+ entryStream.close(); >+ Utils.clear(modifiedFile); >+ } >+ } >+ entryStream = new FileInputStream(extractedFile); >+ } >+ ZipEntry newEntry = new ZipEntry(name); >+ zipOut.putNextEntry(newEntry); >+ Utils.transferStreams(entryStream, zipOut, false); >+ zipOut.closeEntry(); >+ entryStream.close(); >+ >+ if (extractedFile != null) >+ Utils.clear(extractedFile); >+ } >+ >+ } >+ zipOut.close(); >+ zip.close(); >+ >+ File finalFile = new File(getWorkingDirectory(), zipFile.getName()); >+ if (finalFile.exists()) >+ finalFile.delete(); >+ outputFile.renameTo(finalFile); >+ Utils.clear(tempDir); >+ } >+ >+ private void initialize(ZipFile zip) { >+ ZipEntry entry = zip.getEntry("pack.properties"); //$NON-NLS-1$ >+ properties = new Properties(); >+ if (entry != null) { >+ InputStream stream = null; >+ try { >+ stream = zip.getInputStream(entry); >+ properties.load(stream); >+ } catch (IOException e) { >+ // TODO Auto-generated catch block >+ e.printStackTrace(); >+ } finally { >+ Utils.close(stream); >+ } >+ } >+ >+ packExclusions = Utils.getPackExclusions(properties); >+ signExclusions = Utils.getSignExclusions(properties); >+ >+ packUnpackStep = new PackUnpackStep(properties); >+ packStep = new PackStep(properties); >+ signStep = new SignCommandStep(properties, command); >+ unpackStep = new UnpackStep(properties); >+ } >+} >Index: src/org/eclipse/update/jarprocessor/internal/Utils.java >=================================================================== >RCS file: src/org/eclipse/update/jarprocessor/internal/Utils.java >diff -N src/org/eclipse/update/jarprocessor/internal/Utils.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/update/jarprocessor/internal/Utils.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,171 @@ >+/** >+ * >+ */ >+package org.eclipse.update.jarprocessor.internal; >+ >+import java.io.*; >+import java.util.*; >+import java.util.jar.JarFile; >+ >+/** >+ * @author aniefer >+ * >+ */ >+public class Utils { >+ public static final String PACK200_PROPERTY = "org.eclipse.update.jarprocessor.pack200"; //$NON-NLS-1$ >+ public static final String JRE = "@jre"; //$NON-NLS-1$ >+ public static final String PATH = "@path"; //$NON-NLS-1$ >+ public static final String NONE = "@none"; //$NON-NLS-1$ >+ >+ public static final String PACKED_SUFFIX = ".pack.gz"; //$NON-NLS-1$ >+ public static final String JAR_SUFFIX = ".jar"; //$NON-NLS-1$ >+ >+ public static final FileFilter JAR_FILTER = new FileFilter() { >+ public boolean accept(File pathname) { >+ return pathname.isFile() && pathname.getName().endsWith(".jar"); //$NON-NLS-1$ >+ } >+ }; >+ >+ public static final FileFilter PACK_GZ_FILTER = new FileFilter() { >+ public boolean accept(File pathname) { >+ return pathname.isFile() && pathname.getName().endsWith(PACKED_SUFFIX); >+ } >+ }; >+ >+ public static void close(Object stream) { >+ if (stream != null) { >+ try { >+ if (stream instanceof InputStream) >+ ((InputStream) stream).close(); >+ else if (stream instanceof OutputStream) >+ ((OutputStream) stream).close(); >+ else if (stream instanceof JarFile) >+ ((JarFile) stream).close(); >+ } catch (IOException e) { >+ //ignore >+ } >+ } >+ } >+ >+ /** >+ * get the set of commands to try to execute pack/unpack >+ * @param cmd, the command, either "pack200" or "unpack200" >+ * @return String [] or null >+ */ >+ public static String[] getPack200Commands(String cmd) { >+ String[] locations = null; >+ String prop = System.getProperty(PACK200_PROPERTY); >+ String javaHome = System.getProperty("java.home"); //$NON-NLS-1$ >+ if (NONE.equals(prop)) { >+ return null; >+ } else if (JRE.equals(prop)) { >+ locations = new String[] {javaHome + "/bin/" + cmd}; //$NON-NLS-1$ >+ } else if (PATH.equals(prop)) { >+ locations = new String[] {cmd}; >+ } else if (prop == null) { >+ locations = new String[] {javaHome + "/bin/" + cmd, cmd}; //$NON-NLS-1$ >+ } else { >+ locations = new String[] {prop + "/" + cmd}; //$NON-NLS-1$ >+ } >+ return locations; >+ } >+ >+ /** >+ * Transfers all available bytes from the given input stream to the given >+ * output stream. Closes both streams if close == true, regardless of failure. >+ * Flushes the destination stream if close == false >+ * >+ * @param source >+ * @param destination >+ * @param close >+ * @throws IOException >+ */ >+ public static void transferStreams(InputStream source, OutputStream destination, boolean close) throws IOException { >+ source = new BufferedInputStream(source); >+ destination = new BufferedOutputStream(destination); >+ try { >+ byte[] buffer = new byte[8192]; >+ while (true) { >+ int bytesRead = -1; >+ if ((bytesRead = source.read(buffer)) == -1) >+ break; >+ destination.write(buffer, 0, bytesRead); >+ } >+ } finally { >+ if (close) { >+ close(source); >+ close(destination); >+ } else { >+ destination.flush(); >+ } >+ } >+ } >+ >+ /** >+ * Deletes all the files and directories from the given root down (inclusive). >+ * Returns false if we could not delete some file or an exception occurred >+ * at any point in the deletion. >+ * Even if an exception occurs, a best effort is made to continue deleting. >+ */ >+ public static boolean clear(java.io.File root) { >+ boolean result = clearChildren(root); >+ try { >+ if (root.exists()) >+ result &= root.delete(); >+ } catch (Exception e) { >+ result = false; >+ } >+ return result; >+ } >+ >+ /** >+ * Deletes all the files and directories from the given root down, except for >+ * the root itself. >+ * Returns false if we could not delete some file or an exception occurred >+ * at any point in the deletion. >+ * Even if an exception occurs, a best effort is made to continue deleting. >+ */ >+ public static boolean clearChildren(java.io.File root) { >+ boolean result = true; >+ if (root.isDirectory()) { >+ String[] list = root.list(); >+ // for some unknown reason, list() can return null. >+ // Just skip the children If it does. >+ if (list != null) >+ for (int i = 0; i < list.length; i++) >+ result &= clear(new java.io.File(root, list[i])); >+ } >+ return result; >+ } >+ >+ public static Set getPackExclusions(Properties properties) { >+ if (properties == null) >+ return Collections.EMPTY_SET; >+ >+ String packExcludes = properties.getProperty("pack.excludes"); //$NON-NLS-1$ >+ if (packExcludes != null) { >+ String[] excludes = packExcludes.split(",\\s*"); //$NON-NLS-1$ >+ Set packExclusions = new HashSet(); >+ for (int i = 0; i < excludes.length; i++) { >+ packExclusions.add(excludes[i]); >+ } >+ return packExclusions; >+ } >+ return Collections.EMPTY_SET; >+ } >+ >+ public static Set getSignExclusions(Properties properties) { >+ if (properties == null) >+ return Collections.EMPTY_SET; >+ String signExcludes = properties.getProperty("sign.excludes"); //$NON-NLS-1$ >+ if (signExcludes != null) { >+ String[] excludes = signExcludes.split(",\\s*"); //$NON-NLS-1$ >+ Set signExclusions = new HashSet(); >+ for (int i = 0; i < excludes.length; i++) { >+ signExclusions.add(excludes[i]); >+ } >+ return signExclusions; >+ } >+ return Collections.EMPTY_SET; >+ } >+} >Index: src/org/eclipse/update/jarprocessor/jarprocessor.jardesc >=================================================================== >RCS file: src/org/eclipse/update/jarprocessor/jarprocessor.jardesc >diff -N src/org/eclipse/update/jarprocessor/jarprocessor.jardesc >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/update/jarprocessor/jarprocessor.jardesc 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,22 @@ >+<?xml version="1.0" encoding="UTF-8"?> >+<jardesc> >+ <jar path="org.eclipse.update.core/jarprocessor.jar"/> >+ <options overwrite="false" compress="true" exportErrors="true" exportWarnings="true" saveDescription="false" descriptionLocation="/org.eclipse.update.core/src/org/eclipse/update/jarprocessor/jarprocessor.jardesc" useSourceFolders="false" buildIfNeeded="true" includeDirectoryEntries="false" storeRefactorings="false"/> >+ <refactoring structuralOnly="false" deprecationInfo="true"/> >+ <selectedProjects> >+ <project name="org.eclipse.update.core"/> >+ </selectedProjects> >+ <manifest manifestVersion="1.0" usesManifest="true" reuseManifest="false" saveManifest="false" generateManifest="true" manifestLocation="" mainClassHandleIdentifier="=org.eclipse.update.core/src<org.eclipse.update.jarprocessor{Main.java[Main"> >+ <sealing sealJar="false"> >+ <packagesToSeal/> >+ <packagesToUnSeal/> >+ </sealing> >+ </manifest> >+ <selectedElements exportClassFiles="true" exportOutputFolder="false" exportJavaFiles="true"> >+ <javaElement handleIdentifier="=org.eclipse.update.core/src<org.eclipse.update.jarprocessor{JarProcessor.java"/> >+ <javaElement handleIdentifier="=org.eclipse.update.core/src<org.eclipse.update.jarprocessor.internal"/> >+ <javaElement handleIdentifier="=org.eclipse.update.core/src<org.eclipse.update.jarprocessor{IProcessStep.java"/> >+ <file path="/org.eclipse.update.core/src/org/eclipse/update/jarprocessor/pack-readme.html"/> >+ <javaElement handleIdentifier="=org.eclipse.update.core/src<org.eclipse.update.jarprocessor{Main.java"/> >+ </selectedElements> >+</jardesc> >Index: src/org/eclipse/update/jarprocessor/IProcessStep.java >=================================================================== >RCS file: src/org/eclipse/update/jarprocessor/IProcessStep.java >diff -N src/org/eclipse/update/jarprocessor/IProcessStep.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/update/jarprocessor/IProcessStep.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,47 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 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.update.jarprocessor; >+ >+import java.io.File; >+ >+/** >+ * @author aniefer >+ * >+ */ >+public interface IProcessStep { >+ >+ /** >+ * The effect of this processing step if the JarProcessor was to recurse on this entry. >+ * Return null if this step will not do anything with this entry. >+ * Return the new entryName if this step will modify this entry on recursion. >+ * @param entryName >+ * @return >+ */ >+ String recursionEffect(String entryName); >+ >+ /** >+ * Perform some processing on the input file before the JarProcessor considers the entries for recursion. >+ * return the file containing the result of the processing >+ * @param input >+ * @param workingDirectory >+ * @return >+ */ >+ File preProcess(File input, File workingDirectory); >+ >+ /** >+ * Perform some processing on the input file after the JarProcessor returns from recursion >+ * return the file containing the result of the processing >+ * @param input >+ * @param workingDirectory >+ * @return >+ */ >+ File postProcess(File input, File workingDirectory); >+} >Index: src/org/eclipse/update/jarprocessor/internal/PackUnpackStep.java >=================================================================== >RCS file: src/org/eclipse/update/jarprocessor/internal/PackUnpackStep.java >diff -N src/org/eclipse/update/jarprocessor/internal/PackUnpackStep.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/update/jarprocessor/internal/PackUnpackStep.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,84 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 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.update.jarprocessor.internal; >+ >+import java.io.File; >+import java.io.IOException; >+import java.util.Properties; >+import java.util.Set; >+ >+/** >+ * @author aniefer >+ * >+ */ >+public class PackUnpackStep extends PackStep { >+ private Set exclusions = null; >+// private PackStep pack = null; >+// private UnpackStep unpack = null; >+ >+ public PackUnpackStep(Properties options) { >+ super(options); >+ exclusions = Utils.getPackExclusions(options); >+// pack = new PackStep(options); >+// unpack = new UnpackStep(options); >+ } >+ >+ public String recursionEffect(String entryName) { >+ if (canPack() && entryName.endsWith(".jar") && !exclusions.contains(entryName)) { //$NON-NLS-1$ >+ return entryName; >+ } >+ return null; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.update.jarprocessor.IProcessStep#preProcess(java.io.File, java.io.File) >+ */ >+ public File postProcess(File input, File workingDirectory) { >+ if (canPack() && command != null) { >+ File tempFile = new File(workingDirectory, "temp_" + input.getName()); //$NON-NLS-1$ >+ try { >+ String[] tmp = getCommand(input, tempFile); >+ String[] cmd = new String[tmp.length + 1]; >+ cmd[0] = tmp[0]; >+ cmd[1] = "-r"; //$NON-NLS-1$ >+ System.arraycopy(tmp, 1, cmd, 2, tmp.length - 1); >+ >+ int result = execute(cmd); >+ if (result == 0 && tempFile.exists()) { >+ File finalFile = new File(workingDirectory, input.getName()); >+ if(finalFile.exists()) >+ finalFile.delete(); >+ tempFile.renameTo(finalFile); >+ return finalFile; >+ } >+ } catch (IOException e) { >+ //didn't work >+ return null; >+ } >+ } >+ return null; >+ } >+// public File postProcess(File input, File workingDirectory){ >+// if(PackStep.canPack() && UnpackStep.canUnpack() ){ >+// File packed = pack.postProcess(input, workingDirectory); >+// return unpack.preProcess(packed, workingDirectory); >+// } >+// return null; >+// } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.update.jarprocessor.IProcessStep#postProcess(java.io.File, java.io.File) >+ */ >+ public File preProcess(File input, File workingDirectory) { >+ return null; >+ } >+ >+} >Index: src/org/eclipse/update/jarprocessor/internal/SignCommandStep.java >=================================================================== >RCS file: src/org/eclipse/update/jarprocessor/internal/SignCommandStep.java >diff -N src/org/eclipse/update/jarprocessor/internal/SignCommandStep.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/update/jarprocessor/internal/SignCommandStep.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,87 @@ >+/** >+ * >+ */ >+package org.eclipse.update.jarprocessor.internal; >+ >+import java.io.*; >+import java.util.*; >+import java.util.jar.*; >+ >+/** >+ * @author aniefer >+ * >+ */ >+public class SignCommandStep extends CommandStep { >+ private Set exclusions = null; >+ >+ public SignCommandStep(Properties options, String command) { >+ super(options, command, ".jar"); //$NON-NLS-1$ >+ exclusions = Utils.getSignExclusions(options); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.update.jarprocessor.IProcessStep#recursionEffect(java.lang.String) >+ */ >+ public String recursionEffect(String entryName) { >+ if (entryName.endsWith(extension) && !exclusions.contains(entryName)) >+ return entryName; >+ return null; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.update.jarprocessor.IProcessStep#preProcess(java.io.File, java.io.File) >+ */ >+ public File preProcess(File input, File workingDirectory) { >+ return null; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.update.jarprocessor.IProcessStep#postProcess(java.io.File, java.io.File) >+ */ >+ public File postProcess(File input, File workingDirectory) { >+ if (command != null) { >+ try { >+ String[] cmd = new String[] {command, input.getCanonicalPath()}; >+ int result = execute(cmd); >+ if (result == 0) { >+ normalize(input, workingDirectory); >+ return input; >+ } >+ } catch (IOException e) { >+ //boo >+ e.printStackTrace(); >+ } >+ } >+ return null; >+ } >+ >+ private void normalize(File input, File workingDirectory) { >+ try { >+ File tempJar = new File(workingDirectory, "temp_" + input.getName()); //$NON-NLS-1$ >+ JarFile jar = new JarFile(input); >+ JarOutputStream jarOut = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(tempJar))); >+ InputStream in = null; >+ try { >+ Enumeration entries = jar.entries(); >+ for (JarEntry entry = (JarEntry) entries.nextElement(); entry != null; entry = entries.hasMoreElements() ? (JarEntry) entries.nextElement() : null) { >+ JarEntry newEntry = new JarEntry(entry.getName()); >+ newEntry.setTime(entry.getTime()); >+ in = new BufferedInputStream(jar.getInputStream(entry)); >+ jarOut.putNextEntry(newEntry); >+ Utils.transferStreams(in, jarOut, false); >+ jarOut.closeEntry(); >+ in.close(); >+ } >+ } finally { >+ Utils.close(jarOut); >+ Utils.close(jar); >+ Utils.close(in); >+ } >+ tempJar.setLastModified(input.lastModified()); >+ input.delete(); >+ tempJar.renameTo(input); >+ } catch (IOException e) { >+ //boo >+ } >+ } >+} >Index: src/org/eclipse/update/jarprocessor/internal/UnpackStep.java >=================================================================== >RCS file: src/org/eclipse/update/jarprocessor/internal/UnpackStep.java >diff -N src/org/eclipse/update/jarprocessor/internal/UnpackStep.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/update/jarprocessor/internal/UnpackStep.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,109 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 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.update.jarprocessor.internal; >+ >+import java.io.File; >+import java.io.IOException; >+import java.util.Properties; >+ >+/** >+ * @author aniefer >+ * >+ */ >+public class UnpackStep extends CommandStep { >+ public static final String UNPACKER_PROPERTY = "org.eclipse.update.jarprocessor.Unpacker"; //$NON-NLS-1$ >+ private static Boolean canUnpack = null; >+ private static String command = null; >+ >+ public static boolean canUnpack() { >+ if (canUnpack != null) >+ return canUnpack.booleanValue(); >+ >+ String[] locations = Utils.getPack200Commands("unpack200"); //$NON-NLS-1$ >+ if (locations == null) { >+ canUnpack = Boolean.FALSE; >+ command = null; >+ return false; >+ } >+ >+ int result; >+ for (int i = 0; i < locations.length; i++) { >+ if (locations[i] == null) >+ continue; >+ try { >+ result = execute(new String[] {locations[i], "-V"}); //$NON-NLS-1$ >+ if (result == 0) { >+ command = locations[i]; >+ canUnpack = Boolean.TRUE; >+ return true; >+ } >+ } catch (IOException e) { >+ //no good >+ } >+ } >+ >+ canUnpack = Boolean.FALSE; >+ return false; >+ } >+ >+ public UnpackStep(Properties options) { >+ super(options, null, null); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.update.jarprocessor.IProcessStep#recursionEffect(java.lang.String) >+ */ >+ public String recursionEffect(String entryName) { >+ if (canUnpack() && entryName.endsWith(Utils.PACKED_SUFFIX)) { >+ return entryName.substring(0, entryName.length() - Utils.PACKED_SUFFIX.length()); >+ } >+ return null; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.update.jarprocessor.IProcessStep#preProcess(java.io.File, java.io.File) >+ */ >+ public File preProcess(File input, File workingDirectory) { >+ if (canUnpack() && command != null) { >+ String name = input.getName(); >+ if (name.endsWith(Utils.PACKED_SUFFIX)) { >+ name = name.substring(0, name.length() - Utils.PACKED_SUFFIX.length()); >+ >+ File unpacked = new File(workingDirectory, name); >+ File parent = unpacked.getParentFile(); >+ if (!parent.exists()) >+ parent.mkdirs(); >+ try { >+ String options = getOptions().getProperty(input.getName() + ".unpack.args"); //$NON-NLS-1$ >+ String[] cmd = null; >+ if (options != null) { >+ cmd = new String[] {command, options, input.getCanonicalPath(), unpacked.getCanonicalPath()}; >+ } else { >+ cmd = new String[] {command, input.getCanonicalPath(), unpacked.getCanonicalPath()}; >+ } >+ execute(cmd); >+ } catch (IOException e) { >+ //didn't work >+ return null; >+ } >+ return unpacked; >+ } >+ } >+ return null; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.update.jarprocessor.IProcessStep#postProcess(java.io.File, java.io.File) >+ */ >+ public File postProcess(File input, File workingDirectory) { >+ return null; >+ } >+} >Index: src/org/eclipse/update/jarprocessor/internal/PackStep.java >=================================================================== >RCS file: src/org/eclipse/update/jarprocessor/internal/PackStep.java >diff -N src/org/eclipse/update/jarprocessor/internal/PackStep.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/update/jarprocessor/internal/PackStep.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,101 @@ >+/******************************************************************************* >+ * Copyright (c) 2006 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.update.jarprocessor.internal; >+ >+import java.io.File; >+import java.io.IOException; >+import java.util.*; >+ >+public class PackStep extends CommandStep { >+ >+ protected static String command = null; >+ private static Boolean canPack = null; >+ >+ private Set exclusions = Collections.EMPTY_SET; >+ >+ public static boolean canPack() { >+ if (canPack != null) >+ return canPack.booleanValue(); >+ >+ String[] locations = Utils.getPack200Commands("pack200"); //$NON-NLS-1$ >+ if (locations == null) { >+ canPack = Boolean.FALSE; >+ command = null; >+ return false; >+ } >+ >+ int result; >+ for (int i = 0; i < locations.length; i++) { >+ if (locations[i] == null) >+ continue; >+ try { >+ result = execute(new String[] {locations[i], "-V"}); //$NON-NLS-1$ >+ if (result == 0) { >+ command = locations[i]; >+ canPack = Boolean.TRUE; >+ return true; >+ } >+ } catch (IOException e) { >+ //no good >+ } >+ } >+ >+ canPack = Boolean.FALSE; >+ return false; >+ } >+ >+ public PackStep(Properties options) { >+ super(options, null, null); >+ exclusions = Utils.getPackExclusions(options); >+ } >+ >+ public String recursionEffect(String entryName) { >+ if (canPack() && entryName.endsWith(".jar") && !exclusions.contains(entryName)) { //$NON-NLS-1$ >+ return entryName + Utils.PACKED_SUFFIX; >+ } >+ return null; >+ } >+ >+ public File preProcess(File input, File workingDirectory) { >+ return null; >+ } >+ >+ public File postProcess(File input, File workingDirectory) { >+ if (canPack() && command != null) { >+ File outputFile = new File(workingDirectory, input.getName() + Utils.PACKED_SUFFIX); >+ try { >+ String[] cmd = getCommand(input, outputFile); >+ execute(cmd); >+ } catch (IOException e) { >+ //didn't work >+ return null; >+ } >+ return outputFile; >+ } >+ return null; >+ } >+ >+ protected String[] getCommand(File input, File outputFile) throws IOException { >+ String[] cmd = null; >+ String options = getOptions().getProperty(input.getName() + ".pack.args"); //$NON-NLS-1$ >+ if (options != null) { >+ String[] args = options.split(",\\s*"); //$NON-NLS-1$ >+ cmd = new String[3 + args.length]; >+ cmd[0] = command; >+ System.arraycopy(args, 0, cmd, 1, args.length); >+ cmd[cmd.length - 2] = outputFile.getCanonicalPath(); >+ cmd[cmd.length - 1] = input.getCanonicalPath(); >+ } else { >+ cmd = new String[] {command, outputFile.getCanonicalPath(), input.getCanonicalPath()}; >+ } >+ return cmd; >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 127375
:
37769
|
37820
|
38035
|
38421
|
38861
|
39181
|
39196