Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 127375 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/update/internal/jarprocessor/Main.java (-11 / +15 lines)
Lines 74-89 Link Here
74
		options.input = new File(args[i]);
74
		options.input = new File(args[i]);
75
75
76
		String problemMessage = null;
76
		String problemMessage = null;
77
		String inputName = options.input.getName();
77
		if (options.unpack) {
78
		if (options.unpack) {
78
			if (!JarProcessor.canPerformUnpack()) {
79
			if (!JarProcessor.canPerformUnpack()) {
79
				problemMessage = "The unpack200 command cannot be found."; //$NON-NLS-1$
80
				problemMessage = "The unpack200 command cannot be found."; //$NON-NLS-1$
80
			} else 	if (options.input.isFile() && !args[i].endsWith(".zip") && !args[i].endsWith(".pack.gz")) { //$NON-NLS-1$ //$NON-NLS-2$
81
			} else 	if (options.input.isFile() && !inputName.endsWith(".zip") && !inputName.endsWith(".pack.gz")) { //$NON-NLS-1$ //$NON-NLS-2$
81
				problemMessage = "Input file is not a pack.gz file."; //$NON-NLS-1$
82
				problemMessage = "Input file is not a pack.gz file."; //$NON-NLS-1$
82
			} else 	if (options.pack || options.repack || options.signCommand != null) {
83
			} else 	if (options.pack || options.repack || options.signCommand != null) {
83
				problemMessage = "Pack, repack or sign cannot be specified with unpack."; //$NON-NLS-1$
84
				problemMessage = "Pack, repack or sign cannot be specified with unpack."; //$NON-NLS-1$
84
			}
85
			}
85
		} else {
86
		} else {
86
			if (options.input.isFile() && !args[i].endsWith(".zip") && !args[i].endsWith(".jar")) { //$NON-NLS-1$ //$NON-NLS-2$
87
			if (options.input.isFile() && !inputName.endsWith(".zip") && !inputName.endsWith(".jar")) { //$NON-NLS-1$ //$NON-NLS-2$
87
				problemMessage = "Input file is not a jar file."; //$NON-NLS-1$
88
				problemMessage = "Input file is not a jar file."; //$NON-NLS-1$
88
			} else	if ((options.pack || options.repack) && !JarProcessor.canPerformPack()) {
89
			} else	if ((options.pack || options.repack) && !JarProcessor.canPerformPack()) {
89
				problemMessage = "The pack200 command can not be found."; //$NON-NLS-1$
90
				problemMessage = "The pack200 command can not be found."; //$NON-NLS-1$
Lines 99-113 Link Here
99
		return options;
100
		return options;
100
	}
101
	}
101
102
102
	/**
103
	public static void runJarProcessor(Options options) {
103
	 * @param args
104
	 * @throws FileNotFoundException 
105
	 */
106
	public static void main(String[] args) {
107
		Options options = processArguments(args);
108
		if (options == null)
109
			return;
110
111
		if (options.input.getName().endsWith(".zip")) { //$NON-NLS-1$
104
		if (options.input.getName().endsWith(".zip")) { //$NON-NLS-1$
112
			ZipProcessor processor = new ZipProcessor();
105
			ZipProcessor processor = new ZipProcessor();
113
			processor.setWorkingDirectory(options.outputDir);
106
			processor.setWorkingDirectory(options.outputDir);
Lines 147-151 Link Here
147
			}
140
			}
148
		}
141
		}
149
	}
142
	}
143
	
144
	/**
145
	 * @param args
146
	 * @throws FileNotFoundException 
147
	 */
148
	public static void main(String[] args) {
149
		Options options = processArguments(args);
150
		if (options == null)
151
			return;
152
		runJarProcessor(options);
153
	}
150
154
151
}
155
}
(-)src/org/eclipse/update/internal/jarprocessor/SignCommandStep.java (-1 / +1 lines)
Lines 65-71 Link Here
65
	private void normalize(File input, File workingDirectory) {
65
	private void normalize(File input, File workingDirectory) {
66
		try {
66
		try {
67
			File tempJar = new File(workingDirectory, "temp_" + input.getName()); //$NON-NLS-1$
67
			File tempJar = new File(workingDirectory, "temp_" + input.getName()); //$NON-NLS-1$
68
			JarFile jar = new JarFile(input);
68
			JarFile jar = new JarFile(input, false);
69
			JarOutputStream jarOut = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(tempJar)));
69
			JarOutputStream jarOut = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(tempJar)));
70
			InputStream in = null;
70
			InputStream in = null;
71
			try {
71
			try {
(-)src/org/eclipse/update/internal/core/messages.properties (-1 / +5 lines)
Lines 336-342 Link Here
336
SiteFilePluginContentConsumer_unableToDelete=Unable to delete {0}
336
SiteFilePluginContentConsumer_unableToDelete=Unable to delete {0}
337
SiteFilePackedPluginContentConsumer_unableToDelete=Unable to delete {0}
337
SiteFilePackedPluginContentConsumer_unableToDelete=Unable to delete {0}
338
338
339
339
JarProcessor_unpackNotFound = The unpack200 command cannot be found.
340
JarProcessor_noPackUnpack = Pack, repack or sign cannot be specified with unpack.
341
JarProcessor_packNotFound = The pack200 command cannot be found.
342
SiteOptimizer_inputNotSpecified = No input file was specified;
343
SiteOptimizer_inputFileNotFound = The input file \"{0}\" was not found.
340
344
341
HttpResponse_rangeExpected = Server does not support ranges.
345
HttpResponse_rangeExpected = Server does not support ranges.
342
HttpResponse_wrongRange = Server returned wrong range.
346
HttpResponse_wrongRange = Server returned wrong range.
(-)src/org/eclipse/update/internal/core/FeaturePackagedContentProvider.java (-9 / +14 lines)
Lines 17-22 Link Here
17
import org.eclipse.osgi.util.NLS;
17
import org.eclipse.osgi.util.NLS;
18
import org.eclipse.update.core.*;
18
import org.eclipse.update.core.*;
19
import org.eclipse.update.internal.jarprocessor.JarProcessor;
19
import org.eclipse.update.internal.jarprocessor.JarProcessor;
20
import org.eclipse.update.internal.jarprocessor.Utils;
20
import org.eclipse.update.internal.security.JarVerifier;
21
import org.eclipse.update.internal.security.JarVerifier;
21
import org.eclipse.update.internal.verifier.CertVerifier;
22
import org.eclipse.update.internal.verifier.CertVerifier;
22
23
Lines 41-48 Link Here
41
	/*
42
	/*
42
	 * Constructor 
43
	 * Constructor 
43
	 */
44
	 */
44
	public FeaturePackagedContentProvider(URL url) {
45
	public FeaturePackagedContentProvider(URL url, ISite site) {
45
		super(url);
46
		super(url);
47
		if (site instanceof ExtendedSite) {
48
			this.siteModel = (ExtendedSite) site;
49
		}
46
	}
50
	}
47
51
48
	/*
52
	/*
Lines 64-76 Link Here
64
		return jarVerifier;
68
		return jarVerifier;
65
	}
69
	}
66
70
67
	public void setFeature(IFeature feature) {
68
		super.setFeature(feature);
69
		ISite featureSite = feature.getSite();
70
		if(featureSite instanceof ExtendedSite){
71
			siteModel = (ExtendedSite) featureSite;
72
		}
73
	}
74
	/*
71
	/*
75
	 * @see IFeatureContentProvider#getFeatureManifestReference()
72
	 * @see IFeatureContentProvider#getFeatureManifestReference()
76
	 */
73
	 */
Lines 227-234 Link Here
227
					JarProcessor processor = JarProcessor.getUnpackProcessor(null);
224
					JarProcessor processor = JarProcessor.getUnpackProcessor(null);
228
					processor.setWorkingDirectory(tempFile.getParent());
225
					processor.setWorkingDirectory(tempFile.getParent());
229
	
226
	
230
					File packedFile = new File(tempFile.toString() + ".pack.gz"); //$NON-NLS-1$
227
					File packedFile = new File(tempFile.toString() + Utils.PACKED_SUFFIX);
231
					tempFile.renameTo(packedFile);
228
					tempFile.renameTo(packedFile);
229
					
230
					if (monitor != null) {
231
						monitor.saveState();
232
						monitor.subTask(Messages.JarContentReference_Unpacking + " " + reference.getIdentifier() + Utils.PACKED_SUFFIX);  //$NON-NLS-1$
233
						monitor.showCopyDetails(false);
234
					}
232
					//unpacking the jar will strip the ".pack.gz" and leave us back with the original filename
235
					//unpacking the jar will strip the ".pack.gz" and leave us back with the original filename
233
					processor.processJar(packedFile);
236
					processor.processJar(packedFile);
234
	
237
	
Lines 237-242 Link Here
237
				} finally {
240
				} finally {
238
					LockManager.returnLock(packed);
241
					LockManager.returnLock(packed);
239
					LockManager.returnLock(key);
242
					LockManager.returnLock(key);
243
					if(monitor != null)
244
						monitor.restoreState();
240
				}
245
				}
241
			}
246
			}
242
		}
247
		}
(-)src/org/eclipse/update/internal/core/FeaturePackagedFactory.java (-1 / +1 lines)
Lines 35-41 Link Here
35
			
35
			
36
					
36
					
37
		try {	
37
		try {	
38
			IFeatureContentProvider contentProvider = new FeaturePackagedContentProvider(url);	
38
			IFeatureContentProvider contentProvider = new FeaturePackagedContentProvider(url, site);	
39
			ContentReference manifest = contentProvider.getFeatureManifestReference(null/*IProgressMonitor*/);
39
			ContentReference manifest = contentProvider.getFeatureManifestReference(null/*IProgressMonitor*/);
40
			featureStream = manifest.getInputStream();
40
			featureStream = manifest.getInputStream();
41
			feature = (Feature)parseFeature(featureStream);
41
			feature = (Feature)parseFeature(featureStream);
(-)src/org/eclipse/update/internal/core/Messages.java (+7 lines)
Lines 335-340 Link Here
335
	public static String HttpResponse_wrongRange;
335
	public static String HttpResponse_wrongRange;
336
	public static String DefaultSiteParser_mirrors;
336
	public static String DefaultSiteParser_mirrors;
337
	public static String FeatureExecutableContentProvider_UnableToRetriveArchiveContentRef;
337
	public static String FeatureExecutableContentProvider_UnableToRetriveArchiveContentRef;
338
	
339
	public static String JarProcessor_unpackNotFound;
340
	public static String JarProcessor_noPackUnpack;
341
	public static String JarProcessor_packNotFound;
342
	
343
	public static String SiteOptimizer_inputNotSpecified;
344
	public static String SiteOptimizer_inputFileNotFound;
338
345
339
	static {
346
	static {
340
		NLS.initializeMessages(BUNDLE_NAME, Messages.class);
347
		NLS.initializeMessages(BUNDLE_NAME, Messages.class);
(-)plugin.xml (+9 lines)
Lines 72-77 Link Here
72
         </run>
72
         </run>
73
      </application>
73
      </application>
74
   </extension>
74
   </extension>
75
      <extension
76
         id="siteOptimizer"
77
         point="org.eclipse.core.runtime.applications">
78
      <application>
79
         <run
80
               class="org.eclipse.update.internal.provisional.SiteOptimizerApplication">
81
         </run>
82
      </application>
83
   </extension>
75
	<extension
84
	<extension
76
			id="updateCoreProductProvider"
85
			id="updateCoreProductProvider"
77
			name="%productProviderName"
86
			name="%productProviderName"
(-)src/org/eclipse/update/internal/provisional/SiteOptimizerApplication.java (+138 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM - Initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.update.internal.provisional;
12
13
import java.io.File;
14
import java.util.HashMap;
15
import java.util.Map;
16
import org.eclipse.core.runtime.IPlatformRunnable;
17
import org.eclipse.core.runtime.Platform;
18
import org.eclipse.osgi.util.NLS;
19
import org.eclipse.update.internal.core.Messages;
20
import org.eclipse.update.internal.jarprocessor.JarProcessor;
21
import org.eclipse.update.internal.jarprocessor.Main;
22
23
/**
24
 * The application class used to perform update site optimizations.
25
 * <p>
26
 * <b>Note:</b> This class/interface is part of an interim API that is still under development and expected to
27
 * change significantly before reaching stability. It is being made available at this early stage to solicit feedback
28
 * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken
29
 * (repeatedly) as the API evolves.
30
 * </p>
31
 * @since 3.2
32
 */
33
public class SiteOptimizerApplication implements IPlatformRunnable {
34
	public final static Integer EXIT_ERROR = new Integer(1);
35
	
36
	public final static String JAR_PROCESSOR = "-jarProcessor"; //$NON-NLS-1$
37
	public final static String DIGEST_BUILDER = "-digestBuilder"; //$NON-NLS-1$
38
	public final static String INPUT = "input"; //$NON-NLS-1$
39
	public final static String OUTPUT_DIR = "-outputDir"; //$NON-NLS-1$
40
	
41
	public final static String JAR_PROCESSOR_PACK = "-pack"; //$NON-NLS-1$
42
	public final static String JAR_PROCESSOR_UNPACK = "-unpack"; //$NON-NLS-1$
43
	public final static String JAR_PROCESSOR_REPACK = "-repack"; //$NON-NLS-1$
44
	public final static String JAR_PROCESSOR_SIGN = "-sign"; //$NON-NLS-1$
45
46
	
47
	/**
48
	 * Parses the command line in the form:
49
	 *  [-key [value]]* [inputvalue]
50
	 *  If the last argument does not start with a "-" then it is taken as the input value and not the value for a preceding -key
51
	 * @param args
52
	 * @return
53
	 */
54
	private Map parseCmdLine(String [] args) {
55
		Map cmds = new HashMap();
56
		for (int i = 0; i < args.length; i++) {
57
			if(i == args.length - 1 && !args[i].startsWith("-")) { //$NON-NLS-1$
58
				cmds.put(INPUT, args[i]);
59
			} else {
60
				String key = args[i];
61
				String val = null;
62
				if( i < args.length - 2 && !args[i + 1].startsWith("-")){ //$NON-NLS-1$
63
					val = args[++i];
64
				}
65
				cmds.put(key, val);
66
			}
67
		}
68
		return cmds;
69
	}
70
	
71
	private boolean runJarProcessor(Map params) {
72
		Main.Options options = new Main.Options();
73
		options.pack = params.containsKey(JAR_PROCESSOR_PACK);
74
		options.unpack = params.containsKey(JAR_PROCESSOR_UNPACK);
75
		options.repack = params.containsKey(JAR_PROCESSOR_REPACK);
76
		options.signCommand = (String) params.get(JAR_PROCESSOR_SIGN);
77
		options.outputDir = (String) params.get(OUTPUT_DIR);
78
		
79
		String problem = null;
80
		
81
		String input = (String) params.get(INPUT);
82
		if(input == null)
83
			problem = Messages.SiteOptimizer_inputNotSpecified;
84
		else {
85
			File inputFile = new File(input);
86
			if(inputFile.exists())
87
				options.input = inputFile;
88
			else 
89
				problem = NLS.bind(Messages.SiteOptimizer_inputFileNotFound, new String[] {input});
90
		}
91
		
92
		if (options.unpack) {
93
			if (!JarProcessor.canPerformUnpack()) {
94
				problem = Messages.JarProcessor_unpackNotFound;
95
			} else 	if (options.pack || options.repack || options.signCommand != null) {
96
				problem = Messages.JarProcessor_noPackUnpack;
97
			}
98
		} else if ((options.pack || options.repack) && !JarProcessor.canPerformPack()) {
99
			problem = Messages.JarProcessor_packNotFound;
100
		}
101
	
102
		if(problem != null) {
103
			System.out.println(problem);
104
			return false;
105
		}
106
		
107
		Main.runJarProcessor(options);
108
		return true;
109
	}
110
	
111
	private boolean runDigestBuilder(Map params) {
112
		//TODO
113
		return true;
114
	}
115
	
116
	/* (non-Javadoc)
117
	 * @see org.eclipse.core.runtime.IPlatformRunnable#run(java.lang.Object)
118
	 */
119
	public Object run(Object args) throws Exception {
120
		Platform.endSplash();
121
		if (args == null)
122
			return EXIT_ERROR;
123
		if (args instanceof String[]) {
124
			Map params = parseCmdLine((String[]) args);
125
			if(params.containsKey(JAR_PROCESSOR)){
126
				if(!runJarProcessor(params))
127
					return EXIT_ERROR;
128
			}
129
			
130
			if(params.containsKey(DIGEST_BUILDER)){
131
				if(!runDigestBuilder(params))
132
					return EXIT_ERROR;
133
			}
134
		}
135
		return IPlatformRunnable.EXIT_OK;
136
	}
137
138
}

Return to bug 127375