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 146066 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/update/internal/jarprocessor/IProcessStep.java (-1 / +9 lines)
Lines 11-19 Link Here
11
package org.eclipse.update.internal.jarprocessor;
11
package org.eclipse.update.internal.jarprocessor;
12
12
13
import java.io.File;
13
import java.io.File;
14
import java.util.Properties;
14
15
15
/**
16
/**
16
 * @author aniefer
17
 * @author aniefer@ca.ibm.com
17
 *
18
 *
18
 */
19
 */
19
public interface IProcessStep {
20
public interface IProcessStep {
Lines 50-53 Link Here
50
	 * @return
51
	 * @return
51
	 */
52
	 */
52
	public String getStepName();
53
	public String getStepName();
54
55
	/**
56
	 * Adjust any properties in the eclipse.inf as appropriate for this step
57
	 * @param input
58
	 * @param inf
59
	 */
60
	public void adjustInf(File input, Properties inf);
53
}
61
}
(-)src/org/eclipse/update/internal/jarprocessor/PackUnpackStep.java (-2 / +8 lines)
Lines 16-22 Link Here
16
import java.util.Set;
16
import java.util.Set;
17
17
18
/**
18
/**
19
 * @author aniefer
19
 * @author aniefer@ca.ibm.com
20
 *
20
 *
21
 */
21
 */
22
public class PackUnpackStep extends PackStep {
22
public class PackUnpackStep extends PackStep {
Lines 44-52 Link Here
44
	 */
44
	 */
45
	public File postProcess(File input, File workingDirectory) {
45
	public File postProcess(File input, File workingDirectory) {
46
		if (canPack() && packCommand != null) {
46
		if (canPack() && packCommand != null) {
47
			Properties inf = Utils.getEclipseInf(input);
48
			if (inf != null && inf.containsKey(Utils.MARK_EXCLUDE_PACK) && Boolean.valueOf(inf.getProperty(Utils.MARK_EXCLUDE_PACK)).booleanValue()) {
49
				if (verbose)
50
					System.out.println("Excluding " + input.getName() + " from " + getStepName()); //$NON-NLS-1$ //$NON-NLS-2$
51
				return null;
52
			}
47
			File tempFile = new File(workingDirectory, "temp_" + input.getName()); //$NON-NLS-1$
53
			File tempFile = new File(workingDirectory, "temp_" + input.getName()); //$NON-NLS-1$
48
			try {
54
			try {
49
				String[] tmp = getCommand(input, tempFile);
55
				String[] tmp = getCommand(input, tempFile, inf);
50
				String[] cmd = new String[tmp.length + 1];
56
				String[] cmd = new String[tmp.length + 1];
51
				cmd[0] = tmp[0];
57
				cmd[0] = tmp[0];
52
				cmd[1] = "-r"; //$NON-NLS-1$
58
				cmd[1] = "-r"; //$NON-NLS-1$
(-)src/org/eclipse/update/internal/jarprocessor/ZipProcessor.java (-2 / +2 lines)
Lines 15-21 Link Here
15
import java.util.zip.*;
15
import java.util.zip.*;
16
16
17
/**
17
/**
18
 * @author aniefer
18
 * @author aniefer@ca.ibm.com
19
 *
19
 *
20
 */
20
 */
21
public class ZipProcessor {
21
public class ZipProcessor {
Lines 116-122 Link Here
116
					FileOutputStream extracted = new FileOutputStream(extractedFile);
116
					FileOutputStream extracted = new FileOutputStream(extractedFile);
117
					Utils.transferStreams(entryStream, extracted, true);
117
					Utils.transferStreams(entryStream, extracted, true);
118
118
119
					boolean skip = !processAll && Utils.isUnmarkedJar(extractedFile);
119
					boolean skip = Utils.shouldSkipJar(extractedFile, processAll, verbose);
120
					if (skip) {
120
					if (skip) {
121
						//skipping this file 
121
						//skipping this file 
122
						entryStream = new FileInputStream(extractedFile);
122
						entryStream = new FileInputStream(extractedFile);
(-)src/org/eclipse/update/internal/jarprocessor/SignCommandStep.java (-1 / +7 lines)
Lines 15-21 Link Here
15
import java.util.jar.*;
15
import java.util.jar.*;
16
16
17
/**
17
/**
18
 * @author aniefer
18
 * @author aniefer@ca.ibm.com
19
 *
19
 *
20
 */
20
 */
21
public class SignCommandStep extends CommandStep {
21
public class SignCommandStep extends CommandStep {
Lines 52-57 Link Here
52
	 */
52
	 */
53
	public File postProcess(File input, File workingDirectory) {
53
	public File postProcess(File input, File workingDirectory) {
54
		if (command != null) {
54
		if (command != null) {
55
			Properties inf = Utils.getEclipseInf(input);
56
			if (inf != null && inf.containsKey(Utils.MARK_EXCLUDE_SIGN) && Boolean.valueOf(inf.getProperty(Utils.MARK_EXCLUDE_SIGN)).booleanValue()) {
57
				if(verbose)
58
					System.out.println("Excluding " + input.getName() + " from signing."); //$NON-NLS-1$ //$NON-NLS-2$
59
				return null;
60
			}
55
			try {
61
			try {
56
				String[] cmd = new String[] {command, input.getCanonicalPath()};
62
				String[] cmd = new String[] {command, input.getCanonicalPath()};
57
				int result = execute(cmd, verbose);
63
				int result = execute(cmd, verbose);
(-)src/org/eclipse/update/internal/jarprocessor/Utils.java (-20 / +66 lines)
Lines 15-26 Link Here
15
import java.util.jar.*;
15
import java.util.jar.*;
16
16
17
/**
17
/**
18
 * @author aniefer
18
 * @author aniefer@ca.ibm.com
19
 *
19
 *
20
 */
20
 */
21
public class Utils {
21
public class Utils {
22
	public static final String SIGN_EXCLUDES = "sign.excludes"; //$NON-NLS-1$
23
	public static final String PACK_EXCLUDES = "pack.excludes"; //$NON-NLS-1$
22
	public static final String MARK_FILE_NAME = "META-INF/eclipse.inf"; //$NON-NLS-1$
24
	public static final String MARK_FILE_NAME = "META-INF/eclipse.inf"; //$NON-NLS-1$
23
	public static final String MARK_PROPERTY = "pack200.conditioned"; //$NON-NLS-1$
25
	public static final String MARK_PROPERTY = "pack200.conditioned"; //$NON-NLS-1$
26
	public static final String MARK_EXCLUDE = "jarprocessor.exclude"; //$NON-NLS-1$
27
	public static final String MARK_EXCLUDE_PACK = "jarprocessor.exclude.pack"; //$NON-NLS-1$
28
	public static final String MARK_EXCLUDE_SIGN = "jarprocessor.exclude.sign"; //$NON-NLS-1$
29
	public static final String MARK_JARPROCESSOR_VERSION = "jarprocessor.version"; //$NON-NLS-1$
30
	public static final String PACK_ARGS = "pack200.args"; //$NON-NLS-1$
31
24
	public static final String PACK200_PROPERTY = "org.eclipse.update.jarprocessor.pack200"; //$NON-NLS-1$
32
	public static final String PACK200_PROPERTY = "org.eclipse.update.jarprocessor.pack200"; //$NON-NLS-1$
25
	public static final String JRE = "@jre"; //$NON-NLS-1$
33
	public static final String JRE = "@jre"; //$NON-NLS-1$
26
	public static final String PATH = "@path"; //$NON-NLS-1$
34
	public static final String PATH = "@path"; //$NON-NLS-1$
Lines 151-157 Link Here
151
		if (properties == null)
159
		if (properties == null)
152
			return Collections.EMPTY_SET;
160
			return Collections.EMPTY_SET;
153
161
154
		String packExcludes = properties.getProperty("pack.excludes"); //$NON-NLS-1$
162
		String packExcludes = properties.getProperty(PACK_EXCLUDES);
155
		if (packExcludes != null) {
163
		if (packExcludes != null) {
156
			String[] excludes = toStringArray(packExcludes, ","); //$NON-NLS-1$
164
			String[] excludes = toStringArray(packExcludes, ","); //$NON-NLS-1$
157
			Set packExclusions = new HashSet();
165
			Set packExclusions = new HashSet();
Lines 166-172 Link Here
166
	public static Set getSignExclusions(Properties properties) {
174
	public static Set getSignExclusions(Properties properties) {
167
		if (properties == null)
175
		if (properties == null)
168
			return Collections.EMPTY_SET;
176
			return Collections.EMPTY_SET;
169
		String signExcludes = properties.getProperty("sign.excludes"); //$NON-NLS-1$
177
		String signExcludes = properties.getProperty(SIGN_EXCLUDES);
170
		if (signExcludes != null) {
178
		if (signExcludes != null) {
171
			String[] excludes = toStringArray(signExcludes, ","); //$NON-NLS-1$
179
			String[] excludes = toStringArray(signExcludes, ","); //$NON-NLS-1$
172
			Set signExclusions = new HashSet();
180
			Set signExclusions = new HashSet();
Lines 193-232 Link Here
193
		int count = tokenizer.countTokens();
201
		int count = tokenizer.countTokens();
194
		String[] result = new String[count];
202
		String[] result = new String[count];
195
		for (int i = 0; i < count; i++) {
203
		for (int i = 0; i < count; i++) {
196
			result[i] = tokenizer.nextToken();
204
			result[i] = tokenizer.nextToken().trim();
197
		}
205
		}
198
		return result;
206
		return result;
199
	}
207
	}
200
208
201
	public static boolean isUnmarkedJar(File jarFile) {
209
	/**
202
		if(jarFile == null || !jarFile.exists())
210
	 * Get the properties from the eclipse.inf file from the given jar.  If the file is not a jar, null is returned.
203
			return false;
211
	 * If the file is a jar, but does not contain an eclipse.inf file, an empty Properties object is returned.
204
		
212
	 * @param jarFile
205
		boolean result = true;
213
	 * @return
206
		JarFile jar = null;
214
	 */
215
	public static Properties getEclipseInf(File jarFile) {
216
		if (jarFile == null || !jarFile.exists())
217
			return null;
207
218
219
		JarFile jar = null;
208
		try {
220
		try {
209
			jar = new JarFile(jarFile, false);
221
			jar = new JarFile(jarFile, false);
210
		} catch (IOException e1) {
211
			//not a jar
212
			return false;
213
		}
214
215
		try {
216
			JarEntry mark = jar.getJarEntry(MARK_FILE_NAME);
222
			JarEntry mark = jar.getJarEntry(MARK_FILE_NAME);
217
			if (mark != null) {
223
			if (mark != null) {
218
				InputStream in = jar.getInputStream(mark);
224
				InputStream in = jar.getInputStream(mark);
219
				Properties props = new Properties();
225
				Properties props = new Properties();
220
				props.load(in);
226
				props.load(in);
221
				in.close();
227
				in.close();
222
				String value = props.getProperty(MARK_PROPERTY);
228
				return props;
223
				result = !Boolean.valueOf(value).booleanValue();
224
			}
229
			}
230
			return new Properties();
225
		} catch (IOException e) {
231
		} catch (IOException e) {
226
			return false;
232
			//not a jar
227
		} finally {
233
		} finally {
228
			close(jar);
234
			close(jar);
229
		}
235
		}
230
		return result;
236
		return null;
237
	}
238
239
	public static boolean shouldSkipJar(File input, boolean processAll, boolean verbose) {
240
		Properties inf = getEclipseInf(input);
241
		if (inf == null) {
242
			//not a jar, could be a pack.gz
243
			return false;
244
		}
245
		String exclude = inf.getProperty(MARK_EXCLUDE);
246
247
		//was marked as exclude, we should skip
248
		if (exclude != null && Boolean.valueOf(exclude).booleanValue())
249
			return true;
250
251
		//process all was set, don't skip
252
		if (processAll)
253
			return false;
254
255
		//otherwise, we skip if not marked marked
256
		String marked = inf.getProperty(MARK_PROPERTY);
257
		return !Boolean.valueOf(marked).booleanValue();
258
	}
259
260
	/**
261
	 * Stores the given properties in the output stream.  We store the properties 
262
	 * in sorted order so that the signing hash doesn't change if the properties didn't change. 
263
	 * @param props
264
	 * @param stream
265
	 */
266
	public static void storeProperties(Properties props, OutputStream stream) {
267
		PrintStream printStream = new PrintStream(stream);
268
		printStream.println("#Processed using Jarprocessor"); //$NON-NLS-1$
269
		SortedMap sorted = new TreeMap(props);
270
		for (Iterator iter = sorted.keySet().iterator(); iter.hasNext();) {
271
			String key = (String) iter.next();
272
			printStream.print(key);
273
			printStream.print(" = "); //$NON-NLS-1$
274
			printStream.println(sorted.get(key));
275
		}
276
		printStream.flush();
231
	}
277
	}
232
}
278
}
(-)src/org/eclipse/update/internal/jarprocessor/CommandStep.java (-1 / +6 lines)
Lines 10-19 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.update.internal.jarprocessor;
11
package org.eclipse.update.internal.jarprocessor;
12
12
13
import java.io.File;
13
import java.util.Properties;
14
import java.util.Properties;
14
15
15
/**
16
/**
16
 * @author aniefer
17
 * @author aniefer@ca.ibm.com
17
 *
18
 *
18
 */
19
 */
19
public abstract class CommandStep implements IProcessStep {
20
public abstract class CommandStep implements IProcessStep {
Lines 60-63 Link Here
60
			options = new Properties();
61
			options = new Properties();
61
		return options;
62
		return options;
62
	}
63
	}
64
	
65
	public void adjustInf(File input, Properties inf) {
66
		//nothing
67
	}
63
}
68
}
(-)src/org/eclipse/update/internal/jarprocessor/JarProcessor.java (-19 / +20 lines)
Lines 15-21 Link Here
15
import java.util.jar.*;
15
import java.util.jar.*;
16
16
17
/**
17
/**
18
 * @author aniefer
18
 * @author aniefer@ca.ibm.com
19
 *
19
 *
20
 */
20
 */
21
public class JarProcessor {
21
public class JarProcessor {
Lines 24-30 Link Here
24
	private int depth = -1;
24
	private int depth = -1;
25
	private boolean verbose = false;
25
	private boolean verbose = false;
26
	private boolean processAll = false;
26
	private boolean processAll = false;
27
	private boolean shouldMarkJars = false;
28
27
29
	static public JarProcessor getUnpackProcessor(Properties properties) {
28
	static public JarProcessor getUnpackProcessor(Properties properties) {
30
		if (!canPerformUnpack())
29
		if (!canPerformUnpack())
Lines 68-80 Link Here
68
67
69
	public void addProcessStep(IProcessStep step) {
68
	public void addProcessStep(IProcessStep step) {
70
		steps.add(step);
69
		steps.add(step);
71
		if(step instanceof PackUnpackStep)
72
			shouldMarkJars = true;
73
	}
70
	}
74
71
75
	public void clearProcessSteps() {
72
	public void clearProcessSteps() {
76
		steps.clear();
73
		steps.clear();
77
		shouldMarkJars = false;
78
	}
74
	}
79
75
80
	public void process(File input, FileFilter filter) throws FileNotFoundException {
76
	public void process(File input, FileFilter filter) throws FileNotFoundException {
Lines 114-120 Link Here
114
	 * @param directory - location to find file for new entryName
110
	 * @param directory - location to find file for new entryName
115
	 * @throws IOException
111
	 * @throws IOException
116
	 */
112
	 */
117
	private void recreateJar(JarFile jar, JarOutputStream outputJar, Map replacements, File directory) throws IOException {
113
	private void recreateJar(JarFile jar, JarOutputStream outputJar, Map replacements, File directory, Properties inf) throws IOException {
118
		InputStream in = null;
114
		InputStream in = null;
119
		boolean marked = false;
115
		boolean marked = false;
120
		try {
116
		try {
Lines 133-145 Link Here
133
				}
129
				}
134
				newEntry.setTime(entry.getTime());
130
				newEntry.setTime(entry.getTime());
135
				outputJar.putNextEntry(newEntry);
131
				outputJar.putNextEntry(newEntry);
136
				if (shouldMarkJars && entry.getName().equals(Utils.MARK_FILE_NAME)) {
132
				if (entry.getName().equals(Utils.MARK_FILE_NAME)) {
137
					Properties props = new Properties();
133
					//The eclipse.inf file was read in earlier, don't need to reread it, just write it out now
138
					props.load(in);
134
					Utils.storeProperties(inf, outputJar);
139
					String val = props.getProperty(Utils.MARK_PROPERTY);
140
					if(val == null || !Boolean.valueOf(val).booleanValue())
141
						props.setProperty(Utils.MARK_PROPERTY, "true"); //$NON-NLS-1$
142
					props.store(outputJar, null);
143
					marked = true;
135
					marked = true;
144
				} else {
136
				} else {
145
					Utils.transferStreams(in, outputJar, false);
137
					Utils.transferStreams(in, outputJar, false);
Lines 152-163 Link Here
152
					replacement.delete();
144
					replacement.delete();
153
				}
145
				}
154
			}
146
			}
155
			if (shouldMarkJars && !marked) {
147
			if (!marked) {
156
				JarEntry entry = new JarEntry(Utils.MARK_FILE_NAME);
148
				JarEntry entry = new JarEntry(Utils.MARK_FILE_NAME);
157
				Properties props = new Properties();
158
				props.setProperty(Utils.MARK_PROPERTY, "true"); //$NON-NLS-1$
159
				outputJar.putNextEntry(entry);
149
				outputJar.putNextEntry(entry);
160
				props.store(outputJar, null);
150
				Utils.storeProperties(inf, outputJar);
161
				outputJar.closeEntry();
151
				outputJar.closeEntry();
162
			}
152
			}
163
		} finally {
153
		} finally {
Lines 246-251 Link Here
246
		return input;
236
		return input;
247
	}
237
	}
248
238
239
	private void adjustInf(File input, Properties inf) {
240
		for (Iterator iter = steps.iterator(); iter.hasNext();) {
241
			IProcessStep step = (IProcessStep) iter.next();
242
			step.adjustInf(input, inf);
243
		}
244
	}
245
249
	public void processJar(File input) throws IOException {
246
	public void processJar(File input) throws IOException {
250
		++depth;
247
		++depth;
251
		long lastModified = input.lastModified();
248
		long lastModified = input.lastModified();
Lines 253-259 Link Here
253
		if (!workingDir.exists())
250
		if (!workingDir.exists())
254
			workingDir.mkdirs();
251
			workingDir.mkdirs();
255
252
256
		boolean skip = !processAll && Utils.isUnmarkedJar(input);
253
		boolean skip = Utils.shouldSkipJar(input, processAll, verbose);
257
		if (depth == 0 && verbose) {
254
		if (depth == 0 && verbose) {
258
			if (skip)
255
			if (skip)
259
				System.out.println("Skipping " + input.getPath()); //$NON-NLS-1$
256
				System.out.println("Skipping " + input.getPath()); //$NON-NLS-1$
Lines 289-294 Link Here
289
		Map replacements = new HashMap();
286
		Map replacements = new HashMap();
290
		extractEntries(jar, tempDir, replacements);
287
		extractEntries(jar, tempDir, replacements);
291
288
289
		Properties inf = Utils.getEclipseInf(workingFile);
290
		if (inf != null)
291
			adjustInf(workingFile, inf);
292
292
		//Recreate the jar with replacements.  This also has the effect of normalizing the jar, so we want to do this even if
293
		//Recreate the jar with replacements.  This also has the effect of normalizing the jar, so we want to do this even if
293
		//we aren't actually replacing anything
294
		//we aren't actually replacing anything
294
		File tempJar = null;
295
		File tempJar = null;
Lines 297-303 Link Here
297
		if (!parent.exists())
298
		if (!parent.exists())
298
			parent.mkdirs();
299
			parent.mkdirs();
299
		JarOutputStream jarOut = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(tempJar)));
300
		JarOutputStream jarOut = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(tempJar)));
300
		recreateJar(jar, jarOut, replacements, tempDir);
301
		recreateJar(jar, jarOut, replacements, tempDir, inf);
301
302
302
		jar.close();
303
		jar.close();
303
		if (tempJar != null) {
304
		if (tempJar != null) {
(-)src/org/eclipse/update/internal/jarprocessor/PackStep.java (-4 / +32 lines)
Lines 71-79 Link Here
71
71
72
	public File postProcess(File input, File workingDirectory) {
72
	public File postProcess(File input, File workingDirectory) {
73
		if (canPack() && packCommand != null) {
73
		if (canPack() && packCommand != null) {
74
			Properties inf = Utils.getEclipseInf(input);
75
			if (inf != null && inf.containsKey(Utils.MARK_EXCLUDE_PACK) && Boolean.valueOf(inf.getProperty(Utils.MARK_EXCLUDE_PACK)).booleanValue()) {
76
				if(verbose)
77
					System.out.println("Excluding " + input.getName() + " from " + getStepName()); //$NON-NLS-1$ //$NON-NLS-2$
78
				return null;
79
			}
74
			File outputFile = new File(workingDirectory, input.getName() + Utils.PACKED_SUFFIX);
80
			File outputFile = new File(workingDirectory, input.getName() + Utils.PACKED_SUFFIX);
75
			try {
81
			try {
76
				String[] cmd = getCommand(input, outputFile);
82
				String[] cmd = getCommand(input, outputFile, inf);
77
				int result = execute(cmd, verbose);
83
				int result = execute(cmd, verbose);
78
				if (result != 0 && verbose)
84
				if (result != 0 && verbose)
79
					System.out.println("Error: " + result + " was returned from command: " + Utils.concat(cmd)); //$NON-NLS-1$ //$NON-NLS-2$
85
					System.out.println("Error: " + result + " was returned from command: " + Utils.concat(cmd)); //$NON-NLS-1$ //$NON-NLS-2$
Lines 87-96 Link Here
87
		return null;
93
		return null;
88
	}
94
	}
89
95
90
	protected String[] getCommand(File input, File outputFile) throws IOException {
96
	protected String[] getCommand(File input, File outputFile, Properties inf) throws IOException {
91
		String[] cmd = null;
97
		String[] cmd = null;
92
		String arguments = getOptions().getProperty(input.getName() + ".pack.args"); //$NON-NLS-1$
98
		String arguments = null;
93
		if (arguments != null) {
99
		if (inf != null && inf.containsKey(Utils.PACK_ARGS)) {
100
			arguments = inf.getProperty(Utils.PACK_ARGS);
101
		} else {
102
			arguments = getOptions().getProperty(input.getName() + ".pack.args"); //$NON-NLS-1$
103
		}
104
		if (arguments != null && arguments.length() > 0) {
94
			String[] args = Utils.toStringArray(arguments, ","); //$NON-NLS-1$
105
			String[] args = Utils.toStringArray(arguments, ","); //$NON-NLS-1$
95
			cmd = new String[3 + args.length];
106
			cmd = new String[3 + args.length];
96
			cmd[0] = packCommand;
107
			cmd[0] = packCommand;
Lines 106-109 Link Here
106
	public String getStepName() {
117
	public String getStepName() {
107
		return "Pack"; //$NON-NLS-1$
118
		return "Pack"; //$NON-NLS-1$
108
	}
119
	}
120
	
121
	public void adjustInf(File input, Properties inf) {
122
		if (input == null || inf == null)
123
			return;
124
125
		if (inf.containsKey(Utils.MARK_EXCLUDE_PACK) && Boolean.valueOf(inf.getProperty(Utils.MARK_EXCLUDE_PACK)).booleanValue()) {
126
			return;
127
		}
128
129
		inf.put(Utils.MARK_PROPERTY, "true"); //$NON-NLS-1$
130
		String arguments = inf.getProperty(Utils.PACK_ARGS);
131
		if (arguments == null) {
132
			arguments = getOptions().getProperty(input.getName() + ".pack.args"); //$NON-NLS-1$
133
			if (arguments != null)
134
				inf.put(Utils.PACK_ARGS, arguments);
135
		}
136
	}
109
}
137
}

Return to bug 146066