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 37769 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]
First patch
update.pack200.txt (text/plain), 47.69 KB, created by
Andrew Niefer
on 2006-04-05 12:27:32 EDT
(
hide
)
Description:
First patch
Filename:
MIME Type:
Creator:
Andrew Niefer
Created:
2006-04-05 12:27:32 EDT
Size:
47.69 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 5 Apr 2006 16:14:24 -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.45 >diff -u -r1.45 FeaturePackagedContentProvider.java >--- src/org/eclipse/update/internal/core/FeaturePackagedContentProvider.java 3 Aug 2005 19:09:49 -0000 1.45 >+++ src/org/eclipse/update/internal/core/FeaturePackagedContentProvider.java 5 Apr 2006 16:14:24 -0000 >@@ -10,13 +10,14 @@ > *******************************************************************************/ > 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.util.NLS; > import org.eclipse.update.core.*; >-import org.eclipse.update.internal.security.*; >+import org.eclipse.update.core.model.SiteModel; >+import org.eclipse.update.internal.security.JarVerifier; >+import org.eclipse.update.jarprocessor.JarProcessor; > > /** > * Content Provider of a Feature Package >@@ -26,7 +27,7 @@ > private ContentReference localManifest = null; > private ContentReference[] localFeatureFiles = new ContentReference[0]; > private IVerifier jarVerifier = null; >- >+ private SiteModel siteModel = null; > /* > * filter for file with .jar > */ >@@ -58,6 +59,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() > */ >@@ -162,13 +170,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 5 Apr 2006 16:14:24 -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 5 Apr 2006 16:14:24 -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/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,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 org.eclipse.update.jarprocessor.IProcessStep; >+ >+/** >+ * @author aniefer >+ * >+ */ >+public class CommandStep implements IProcessStep { >+ private String command = null; >+ private String extension = null; >+ private Properties options = null; >+ >+ public CommandStep(Properties options, String command, String extension) { >+ this.command = command; >+ this.extension = extension; >+ this.options = options; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.update.jarprocessor.IProcessStep#recursionEffect(java.lang.String) >+ */ >+ public String recursionEffect(String entryName) { >+ if (entryName.endsWith(extension)) >+ 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) >+ return input; >+ } catch (IOException e) { >+ //boo >+ e.printStackTrace(); >+ } >+ } >+ return input; >+ } >+ >+ public 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,119 @@ >+/******************************************************************************* >+ * 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 { >+ private static final String OUTPUT = "-outputDir="; //$NON-NLS-1$ >+ private static final String COMMAND = "-signCommand="; //$NON-NLS-1$ >+ >+ private static String outputDir = null; >+ private static String command = null; >+ >+ private static void printUsage(){ >+ System.out.println(" -pack [-signCommand=value] [-outputDir=value] input"); //$NON-NLS-1$ >+ System.out.println("\tPack the input jars. If signCommand is specified, then the jars are first repacked and signed using that command"); //$NON-NLS-1$ >+ System.out.println("\tIf input is a directory, all contained jars are packed, subdirectories are visited recursively."); //$NON-NLS-1$ >+ System.out.println("\tThe signCommand will be executed with 1 argument that is the file to sign."); //$NON-NLS-1$ >+ System.out.println(); >+ System.out.println("-unpack [-outputDir=value] input"); //$NON-NLS-1$ >+ System.out.println("\tUnpack the input pack.gz files"); //$NON-NLS-1$ >+ System.out.println(); >+ System.out.println("[-outputDir=value] input.zip"); //$NON-NLS-1$ >+ System.out.println("\tCreate an outputDir/input.zip file containing processed repacked, signed & optionally packed versions of jars found"); //$NON-NLS-1$ >+ System.out.println("\tin input.zip"); //$NON-NLS-1$ >+ } >+ >+ private static void processZipFile(File zip){ >+ ZipProcessor processor = new ZipProcessor(); >+ processor.setWorkingDirectory(outputDir); >+ processor.setCommand(command); >+ try { >+ processor.processZip(zip); >+ } catch (ZipException e) { >+ // TODO Auto-generated catch block >+ e.printStackTrace(); >+ } catch (IOException e) { >+ // TODO Auto-generated catch block >+ e.printStackTrace(); >+ } >+ >+ >+ } >+ >+ /** >+ * @param args >+ */ >+ public static void main(String[] args) { >+ boolean packing = true; >+ >+ outputDir = "."; //$NON-NLS-1$ >+ >+ if (args.length == 0) { >+ printUsage(); >+ return; >+ } >+ >+ int i = 0; >+ for (; i < args.length - 1; i++) { >+ if(args[i].equals("-pack")) {//$NON-NLS-1$ >+ packing = true; >+ } else if( args[i].equals("-unpack")) { //$NON-NLS-1$ >+ packing = false; >+ } else if(args[i].startsWith(COMMAND) && args[i].length() > COMMAND.length()) { >+ command = args[i].substring(COMMAND.length()).trim(); >+ } else if (args[i].startsWith(OUTPUT)) { >+ outputDir=args[i].substring(OUTPUT.length()).trim(); >+ } >+ } >+ File input = new File(args[i]); >+ >+ if(input.getName().endsWith(".zip")){ //$NON-NLS-1$ >+ processZipFile(input); >+ } else { >+ try { >+ if(packing) { >+ if(!JarProcessor.canPerformPack()){ >+ System.out.println("Cannot find a pack200 executable."); //$NON-NLS-1$ >+ return; >+ } >+ JarProcessor processor = new JarProcessor(); >+ processor.setWorkingDirectory(outputDir); >+ processor.addProcessStep( command != null ? (IProcessStep) new PackUnpackStep(null) : (IProcessStep) new PackStep(null)); >+ if(command != null){ >+ processor.addProcessStep(new CommandStep(null, command, ".jar")); //$NON-NLS-1$ >+ processor.addProcessStep(new PackStep(null)); >+ } >+ processor.process(input, Utils.JAR_FILTER); >+ } else { >+ if(!JarProcessor.canPerformUnpack()){ >+ System.out.println("Cannot find a unpack200 exectuable."); //$NON-NLS-1$ >+ return; >+ } >+ JarProcessor processor = new JarProcessor(); >+ processor.setWorkingDirectory(outputDir); >+ processor.addProcessStep(new UnpackStep(null)); >+ processor.process(input, Utils.PACK_GZ_FILTER); >+ } >+ } catch (FileNotFoundException e ){ >+ System.out.println(e.getLocalizedMessage()); >+ } >+ } >+ } >+ >+} >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,169 @@ >+/** >+ * >+ */ >+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 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 = true; >+ private boolean repacking = true; >+ >+ public void setWorkingDirectory(String dir) { >+ workingDirectory = dir; >+ } >+ >+ public String getWorkingDirectory() { >+ if(workingDirectory == null) >+ workingDirectory = "."; //$NON-NLS-1$ >+ return workingDirectory; >+ } >+ >+ public void setCommand(String command){ >+ this.command = command; >+ } >+ >+ public void processZip(File zipFile) throws ZipException, IOException { >+ ZipFile zip = new ZipFile(zipFile); >+ initialize(zip); >+ >+ File tempDir = new File(getWorkingDirectory(), "temp_" + zipFile.getName()); //$NON-NLS-1$ >+ JarProcessor processor = new JarProcessor(); >+ processor.setWorkingDirectory(tempDir.getCanonicalPath()); >+ >+ 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); >+ >+ File extractedFile = null; >+ if (entry.getName().endsWith(".jar") && (pack || sign)) { //$NON-NLS-1$ >+ extractedFile = new File(tempDir, entry.getName()); >+ parent = extractedFile.getParentFile(); >+ if (!parent.exists()) >+ parent.mkdirs(); >+ FileOutputStream extracted = new FileOutputStream(extractedFile); >+ Utils.transferStreams(entryStream, extracted, true); >+ >+ processor.clearProcessSteps(); >+ if(repacking || pack) >+ 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() + ".pack.gz"); //$NON-NLS-1$ >+ ZipEntry zipEntry = new ZipEntry(name + ".pack.gz"); //$NON-NLS-1$ >+ 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); >+ } >+ } >+ String pack = properties.getProperty("packing"); //$NON-NLS-1$ >+ packing = (pack != null && Boolean.valueOf(pack).booleanValue()); >+ String sign = properties.getProperty("signing"); //$NON-NLS-1$ >+ signing = (sign == null || Boolean.valueOf(sign).booleanValue()); >+ String repack = properties.getProperty("repacking"); //$NON-NLS-1$ >+ repacking = (repack == null || Boolean.valueOf(repack).booleanValue()); >+ >+ String packExcludes = properties.getProperty("pack.excludes"); //$NON-NLS-1$ >+ if (packExcludes != null) { >+ String[] excludes = packExcludes.split(",\\s*"); //$NON-NLS-1$ >+ packExclusions = new HashSet(); >+ for (int i = 0; i < excludes.length; i++) { >+ packExclusions.add(excludes[i]); >+ } >+ } else { >+ packExclusions = Collections.EMPTY_SET; >+ } >+ >+ String signExcludes = properties.getProperty("sign.excludes"); //$NON-NLS-1$ >+ if (signExcludes != null) { >+ String[] excludes = packExcludes.split(",\\s*"); //$NON-NLS-1$ >+ signExclusions = new HashSet(); >+ for (int i = 0; i < excludes.length; i++) { >+ signExclusions.add(excludes[i]); >+ } >+ } else { >+ signExclusions = Collections.EMPTY_SET; >+ } >+ >+ packUnpackStep = new PackUnpackStep(properties); >+ packStep = new PackStep(properties); >+ signStep = new CommandStep(properties, command, ".jar"); //$NON-NLS-1$ >+ >+ } >+} >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,135 @@ >+/** >+ * >+ */ >+package org.eclipse.update.jarprocessor.internal; >+ >+import java.io.*; >+import java.util.jar.JarFile; >+import org.eclipse.update.jarprocessor.JarProcessor; >+ >+/** >+ * @author aniefer >+ * >+ */ >+public class Utils { >+ >+ public static final String PACKED_SUFFIX = ".pack.gz"; //$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(JarProcessor.PACK200_PROPERTY); >+ String javaHome = System.getProperty("java.home"); //$NON-NLS-1$ >+ if (JarProcessor.NONE.equals(prop)) { >+ return null; >+ } else if (JarProcessor.JRE.equals(prop)) { >+ locations = new String[] {javaHome + "/bin/" + cmd}; //$NON-NLS-1$ >+ } else if (JarProcessor.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; >+ } >+} >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,288 @@ >+/******************************************************************************* >+ * 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 { >+ /** >+ * The system property "org.eclipse.update.jarprocessor.pack200". Set to the location in which to look for the >+ * pack200/unpack200 executables. >+ * Possible values are: >+ * "@jre": look for the executables in java.home/bin >+ * "@path": look for the executables in the system search path >+ * "@none": don't use pack200 >+ * dir : a directory containing pack200 & unpack200 executables >+ */ >+ 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$ >+ >+ 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());// + Utils.PACKED_SUFFIX; >+ replacement = new File(directory, name); >+ in = new FileInputStream(replacement); >+ newEntry = new JarEntry(name); >+ //long time = entry.getTime(); >+// entry = new JarEntry(name); >+// entry.setTime(time); >+ } else { >+ in = jar.getInputStream(entry); >+ newEntry = new JarEntry(entry.getName()); >+ //entry.setCompressedSize(-1); >+ } >+ 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; >+ FileOutputStream out = null; >+ try { >+ in = jar.getInputStream(entry); >+ out = new FileOutputStream(extracted); >+ Utils.transferStreams(in, out, true); //this will close both streams >+ } finally { >+ Utils.close(in); >+ Utils.close(out); >+ } >+ 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; >+ 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$ >+ } >+// if(depth == 0){ >+// JarFile jar = new JarFile(workingFile, false); >+// Map replacements = new HashMap(); >+// extractEntries(jar, tempDir, replacements); >+// >+// //Recreate the jar with replacements >+// File tempJar = null; >+// if(replacements.size() > 0) { >+// tempJar = new File(tempDir, workingFile.getName()); >+// File parent = tempJar.getParentFile(); >+// if(!parent.exists()) >+// parent.mkdirs(); >+// JarOutputStream jarOut = new JarOutputStream(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); >+ >+ --depth; >+ } >+} >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,81 @@ >+/******************************************************************************* >+ * 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 PackUnpackStep extends PackStep { >+// private PackStep pack = null; >+// private UnpackStep unpack = null; >+ >+ public PackUnpackStep(Properties options) { >+ super(options); >+// pack = new PackStep(options); >+// unpack = new UnpackStep(options); >+ } >+ >+ public String recursionEffect(String entryName) { >+ if (canPack() && entryName.endsWith(".jar")) { //$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/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,100 @@ >+/******************************************************************************* >+ * 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); >+ } >+ >+ 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