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 (-24 / +34 lines)
Lines 25-30 Link Here
25
		public boolean pack = false;
25
		public boolean pack = false;
26
		public boolean repack = false;
26
		public boolean repack = false;
27
		public boolean unpack = false;
27
		public boolean unpack = false;
28
		public boolean verbose = false;
28
		public File input = null;
29
		public File input = null;
29
	}
30
	}
30
31
Lines 39-44 Link Here
39
		System.out.println("                with repack, sign and pack."); //$NON-NLS-1$
40
		System.out.println("                with repack, sign and pack."); //$NON-NLS-1$
40
		System.out.println();
41
		System.out.println();
41
		System.out.println("-outputDir <dir>  the output directory"); //$NON-NLS-1$
42
		System.out.println("-outputDir <dir>  the output directory"); //$NON-NLS-1$
43
		System.out.println("-verbose        verbose mode "); //$NON-NLS-1$
42
	}
44
	}
43
45
44
	public static Options processArguments(String[] args) {
46
	public static Options processArguments(String[] args) {
Lines 68-95 Link Here
68
					return null;
70
					return null;
69
				}
71
				}
70
				options.outputDir = args[++i];
72
				options.outputDir = args[++i];
73
			} else if (args[i].equals("-verbose")) { //$NON-NLS-1$
74
				options.verbose = true;
71
			}
75
			}
72
		}
76
		}
73
77
74
		options.input = new File(args[i]);
78
		options.input = new File(args[i]);
75
79
76
		String problemMessage = null;
80
		String problemMessage = null;
81
		String inputName = options.input.getName();
77
		if (options.unpack) {
82
		if (options.unpack) {
78
			if (!JarProcessor.canPerformUnpack()) {
83
			if (!JarProcessor.canPerformUnpack()) {
79
				problemMessage = "The unpack200 command cannot be found."; //$NON-NLS-1$
84
				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$
85
			} 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$
86
				problemMessage = "Input file is not a pack.gz file."; //$NON-NLS-1$
82
			} else 	if (options.pack || options.repack || options.signCommand != null) {
87
			} else if (options.pack || options.repack || options.signCommand != null) {
83
				problemMessage = "Pack, repack or sign cannot be specified with unpack."; //$NON-NLS-1$
88
				problemMessage = "Pack, repack or sign cannot be specified with unpack."; //$NON-NLS-1$
84
			}
89
			}
85
		} else {
90
		} else {
86
			if (options.input.isFile() && !args[i].endsWith(".zip") && !args[i].endsWith(".jar")) { //$NON-NLS-1$ //$NON-NLS-2$
91
			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$
92
				problemMessage = "Input file is not a jar file."; //$NON-NLS-1$
88
			} else	if ((options.pack || options.repack) && !JarProcessor.canPerformPack()) {
93
			} else if ((options.pack || options.repack) && !JarProcessor.canPerformPack()) {
89
				problemMessage = "The pack200 command can not be found."; //$NON-NLS-1$
94
				problemMessage = "The pack200 command can not be found."; //$NON-NLS-1$
90
			}
95
			}
91
		}
96
		}
92
		if(problemMessage != null){
97
		if (problemMessage != null) {
93
			System.out.println(problemMessage);
98
			System.out.println(problemMessage);
94
			System.out.println();
99
			System.out.println();
95
			printUsage();
100
			printUsage();
Lines 99-113 Link Here
99
		return options;
104
		return options;
100
	}
105
	}
101
106
102
	/**
107
	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$
108
		if (options.input.getName().endsWith(".zip")) { //$NON-NLS-1$
112
			ZipProcessor processor = new ZipProcessor();
109
			ZipProcessor processor = new ZipProcessor();
113
			processor.setWorkingDirectory(options.outputDir);
110
			processor.setWorkingDirectory(options.outputDir);
Lines 115-151 Link Here
115
			processor.setPack(options.pack);
112
			processor.setPack(options.pack);
116
			processor.setRepack(options.repack || (options.pack && options.signCommand != null));
113
			processor.setRepack(options.repack || (options.pack && options.signCommand != null));
117
			processor.setUnpack(options.unpack);
114
			processor.setUnpack(options.unpack);
115
			processor.setVerbose(options.verbose);
118
			try {
116
			try {
119
				processor.processZip(options.input);
117
				processor.processZip(options.input);
120
			} catch (ZipException e) {
118
			} catch (ZipException e) {
121
				// TODO Auto-generated catch block
119
				if (options.verbose)
122
				e.printStackTrace();
120
					e.printStackTrace();
123
			} catch (IOException e) {
121
			} catch (IOException e) {
124
				// TODO Auto-generated catch block
122
				if (options.verbose)
125
				e.printStackTrace();
123
					e.printStackTrace();
126
			}
124
			}
127
		} else {
125
		} else {
128
			JarProcessor processor = new JarProcessor();
126
			JarProcessor processor = new JarProcessor();
129
			processor.setWorkingDirectory(options.outputDir);
127
			processor.setWorkingDirectory(options.outputDir);
128
			processor.setVerbose(options.verbose);
130
129
131
			if (options.repack || (options.pack && options.signCommand != null))
130
			if (options.repack || (options.pack && options.signCommand != null))
132
				processor.addProcessStep(new PackUnpackStep(null));
131
				processor.addProcessStep(new PackUnpackStep(null, options.verbose));
133
132
134
			if (options.signCommand != null)
133
			if (options.signCommand != null)
135
				processor.addProcessStep(new SignCommandStep(null, options.signCommand));
134
				processor.addProcessStep(new SignCommandStep(null, options.signCommand, options.verbose));
136
135
137
			if (options.pack)
136
			if (options.pack)
138
				processor.addProcessStep(new PackStep(null));
137
				processor.addProcessStep(new PackStep(null, options.verbose));
139
			else if (options.unpack)
138
			else if (options.unpack)
140
				processor.addProcessStep(new UnpackStep(null));
139
				processor.addProcessStep(new UnpackStep(null, options.verbose));
141
140
142
			try {
141
			try {
143
				processor.process(options.input, options.unpack ? Utils.PACK_GZ_FILTER : Utils.JAR_FILTER);
142
				processor.process(options.input, options.unpack ? Utils.PACK_GZ_FILTER : Utils.JAR_FILTER);
144
			} catch (FileNotFoundException e) {
143
			} catch (FileNotFoundException e) {
145
				// TODO Auto-generated catch block
144
				if (options.verbose)
146
				e.printStackTrace();
145
					e.printStackTrace();
147
			}
146
			}
148
		}
147
		}
149
	}
148
	}
150
149
150
	/**
151
	 * @param args
152
	 * @throws FileNotFoundException 
153
	 */
154
	public static void main(String[] args) {
155
		Options options = processArguments(args);
156
		if (options == null)
157
			return;
158
		runJarProcessor(options);
159
	}
160
151
}
161
}
(-)src/org/eclipse/update/internal/jarprocessor/IProcessStep.java (-3 / +9 lines)
Lines 25-31 Link Here
25
	 * @param entryName
25
	 * @param entryName
26
	 * @return
26
	 * @return
27
	 */
27
	 */
28
	String recursionEffect(String entryName);
28
	public String recursionEffect(String entryName);
29
	
29
	
30
	/**
30
	/**
31
	 * Perform some processing on the input file before the JarProcessor considers the entries for recursion.
31
	 * Perform some processing on the input file before the JarProcessor considers the entries for recursion.
Lines 34-40 Link Here
34
	 * @param workingDirectory
34
	 * @param workingDirectory
35
	 * @return
35
	 * @return
36
	 */
36
	 */
37
	File preProcess(File input, File workingDirectory);
37
	public File preProcess(File input, File workingDirectory);
38
	
38
	
39
	/**
39
	/**
40
	 * Perform some processing on the input file after the JarProcessor returns from recursion
40
	 * Perform some processing on the input file after the JarProcessor returns from recursion
Lines 43-47 Link Here
43
	 * @param workingDirectory
43
	 * @param workingDirectory
44
	 * @return
44
	 * @return
45
	 */
45
	 */
46
	File postProcess(File input, File workingDirectory);
46
	public File postProcess(File input, File workingDirectory);
47
	
48
	/**
49
	 * Return the name of this process step
50
	 * @return
51
	 */
52
	public String getStepName();
47
}
53
}
(-)src/org/eclipse/update/internal/jarprocessor/PackUnpackStep.java (-5 / +16 lines)
Lines 21-34 Link Here
21
 */
21
 */
22
public class PackUnpackStep extends PackStep {
22
public class PackUnpackStep extends PackStep {
23
	private Set exclusions = null;
23
	private Set exclusions = null;
24
	
24
25
	public PackUnpackStep(Properties options) {
25
	public PackUnpackStep(Properties options) {
26
		super(options);
26
		super(options);
27
		exclusions = Utils.getPackExclusions(options);
27
		exclusions = Utils.getPackExclusions(options);
28
	}
28
	}
29
29
30
	public PackUnpackStep(Properties options, boolean verbose) {
31
		super(options, verbose);
32
		exclusions = Utils.getPackExclusions(options);
33
	}
34
30
	public String recursionEffect(String entryName) {
35
	public String recursionEffect(String entryName) {
31
		if (canPack() && entryName.endsWith(".jar") &&  !exclusions.contains(entryName)) { //$NON-NLS-1$
36
		if (canPack() && entryName.endsWith(".jar") && !exclusions.contains(entryName)) { //$NON-NLS-1$
32
			return entryName;
37
			return entryName;
33
		}
38
		}
34
		return null;
39
		return null;
Lines 47-62 Link Here
47
				cmd[1] = "-r"; //$NON-NLS-1$
52
				cmd[1] = "-r"; //$NON-NLS-1$
48
				System.arraycopy(tmp, 1, cmd, 2, tmp.length - 1);
53
				System.arraycopy(tmp, 1, cmd, 2, tmp.length - 1);
49
54
50
				int result = execute(cmd);
55
				int result = execute(cmd, verbose);
51
				if (result == 0 && tempFile.exists()) {
56
				if (result == 0 && tempFile.exists()) {
52
					File finalFile = new File(workingDirectory, input.getName());
57
					File finalFile = new File(workingDirectory, input.getName());
53
					if(finalFile.exists())
58
					if (finalFile.exists())
54
						finalFile.delete();
59
						finalFile.delete();
55
					tempFile.renameTo(finalFile);
60
					tempFile.renameTo(finalFile);
56
					return finalFile;
61
					return finalFile;
62
				} else if (verbose) {
63
					System.out.println("Error: " + result + " was returned from command: " + Utils.concat(cmd)); //$NON-NLS-1$ //$NON-NLS-2$
57
				}
64
				}
58
			} catch (IOException e) {
65
			} catch (IOException e) {
59
				//didn't work
66
				if (verbose)
67
					e.printStackTrace();
60
				return null;
68
				return null;
61
			}
69
			}
62
		}
70
		}
Lines 70-73 Link Here
70
		return null;
78
		return null;
71
	}
79
	}
72
80
81
	public String getStepName() {
82
		return "Repack"; //$NON-NLS-1$
83
	}
73
}
84
}
(-)src/org/eclipse/update/internal/jarprocessor/CommandStep.java (-5 / +20 lines)
Lines 10-16 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.update.internal.jarprocessor;
11
package org.eclipse.update.internal.jarprocessor;
12
12
13
import java.io.IOException;
14
import java.util.Properties;
13
import java.util.Properties;
15
14
16
/**
15
/**
Lines 21-41 Link Here
21
	protected String command = null;
20
	protected String command = null;
22
	protected String extension = null;
21
	protected String extension = null;
23
	private  Properties options = null;
22
	private  Properties options = null;
23
	protected boolean verbose = false;
24
	
24
	
25
	public CommandStep(Properties options, String command, String extension) {
25
	public CommandStep(Properties options, String command, String extension, boolean verbose) {
26
		this.command = command;
26
		this.command = command;
27
		this.extension = extension;
27
		this.extension = extension;
28
		this.options = options;
28
		this.options = options;
29
		this.verbose = verbose;
29
	}
30
	}
30
31
31
	protected static int execute(String[] cmd) throws IOException {
32
	protected static int execute(String[] cmd) {
33
		return execute(cmd, false);
34
	}
35
	
36
	protected static int execute(String[] cmd, boolean verbose) {
32
		Runtime runtime = Runtime.getRuntime();
37
		Runtime runtime = Runtime.getRuntime();
33
		Process proc = runtime.exec(cmd);
38
		Process proc = null;
39
		try {
40
			proc = runtime.exec(cmd);
41
		} catch (Exception e) {
42
			if(verbose) {
43
				System.out.println("Error executing command " + Utils.concat(cmd)); //$NON-NLS-1$
44
				e.printStackTrace();
45
			}
46
			return -1;
47
		}
34
		try {
48
		try {
35
			int result = proc.waitFor();
49
			int result = proc.waitFor();
36
			return result;
50
			return result;
37
		} catch (InterruptedException e) {
51
		} catch (InterruptedException e) {
38
			//ignore
52
			if(verbose)
53
				e.printStackTrace();
39
		}
54
		}
40
		return -1;
55
		return -1;
41
	}
56
	}
(-)src/org/eclipse/update/internal/jarprocessor/UnpackStep.java (-12 / +19 lines)
Lines 38-52 Link Here
38
		for (int i = 0; i < locations.length; i++) {
38
		for (int i = 0; i < locations.length; i++) {
39
			if (locations[i] == null)
39
			if (locations[i] == null)
40
				continue;
40
				continue;
41
			try {
41
			result = execute(new String[] {locations[i], "-V"}); //$NON-NLS-1$
42
				result = execute(new String[] {locations[i], "-V"}); //$NON-NLS-1$
42
			if (result == 0) {
43
				if (result == 0) {
43
				unpackCommand = locations[i];
44
					unpackCommand = locations[i];
44
				canUnpack = Boolean.TRUE;
45
					canUnpack = Boolean.TRUE;
45
				return true;
46
					return true;
47
				}
48
			} catch (IOException e) {
49
				//no good
50
			}
46
			}
51
		}
47
		}
52
48
Lines 55-61 Link Here
55
	}
51
	}
56
52
57
	public UnpackStep(Properties options) {
53
	public UnpackStep(Properties options) {
58
		super(options, null, null);
54
		super(options, null, null, false);
55
	}
56
57
	public UnpackStep(Properties options, boolean verbose) {
58
		super(options, null, null, verbose);
59
	}
59
	}
60
60
61
	/* (non-Javadoc)
61
	/* (non-Javadoc)
Lines 89-97 Link Here
89
					} else {
89
					} else {
90
						cmd = new String[] {unpackCommand, input.getCanonicalPath(), unpacked.getCanonicalPath()};
90
						cmd = new String[] {unpackCommand, input.getCanonicalPath(), unpacked.getCanonicalPath()};
91
					}
91
					}
92
					execute(cmd);
92
					int result = execute(cmd, verbose);
93
					if (result != 0 && verbose)
94
						System.out.println("Error: " + result + " was returned from command: " + Utils.concat(cmd)); //$NON-NLS-1$ //$NON-NLS-2$
93
				} catch (IOException e) {
95
				} catch (IOException e) {
94
					//didn't work
96
					if (verbose)
97
						e.printStackTrace();
95
					return null;
98
					return null;
96
				}
99
				}
97
				return unpacked;
100
				return unpacked;
Lines 106-109 Link Here
106
	public File postProcess(File input, File workingDirectory) {
109
	public File postProcess(File input, File workingDirectory) {
107
		return null;
110
		return null;
108
	}
111
	}
112
113
	public String getStepName() {
114
		return "Unpack"; //$NON-NLS-1$
115
	}
109
}
116
}
(-)src/org/eclipse/update/internal/jarprocessor/JarProcessor.java (-3 / +20 lines)
Lines 22-27 Link Here
22
	private List steps = new ArrayList();
22
	private List steps = new ArrayList();
23
	private String workingDirectory = ""; //$NON-NLS-1$
23
	private String workingDirectory = ""; //$NON-NLS-1$
24
	private int depth = -1;
24
	private int depth = -1;
25
	private boolean verbose = false;
25
26
26
	static public JarProcessor getUnpackProcessor(Properties properties) {
27
	static public JarProcessor getUnpackProcessor(Properties properties) {
27
		if (!canPerformUnpack())
28
		if (!canPerformUnpack())
Lines 54-59 Link Here
54
	public void setWorkingDirectory(String dir) {
55
	public void setWorkingDirectory(String dir) {
55
		workingDirectory = dir;
56
		workingDirectory = dir;
56
	}
57
	}
58
	
59
	public void setVerbose(boolean verbose) {
60
		this.verbose = verbose;
61
	}
57
62
58
	public void addProcessStep(IProcessStep step) {
63
	public void addProcessStep(IProcessStep step) {
59
		steps.add(step);
64
		steps.add(step);
Lines 74-80 Link Here
74
			files = new File[] {input};
79
			files = new File[] {input};
75
		}
80
		}
76
		for (int i = 0; i < files.length; i++) {
81
		for (int i = 0; i < files.length; i++) {
77
			System.out.println("Processing " + files[i].getName()); //$NON-NLS-1$
78
			if (files[i].isDirectory()) {
82
			if (files[i].isDirectory()) {
79
				String dir = getWorkingDirectory();
83
				String dir = getWorkingDirectory();
80
				setWorkingDirectory(dir + "/" + files[i].getName()); //$NON-NLS-1$
84
				setWorkingDirectory(dir + "/" + files[i].getName()); //$NON-NLS-1$
Lines 84-91 Link Here
84
				try {
88
				try {
85
					processJar(files[i]);
89
					processJar(files[i]);
86
				} catch (IOException e) {
90
				} catch (IOException e) {
87
					// TODO Auto-generated catch block
91
					if(verbose)
88
					e.printStackTrace();
92
						e.printStackTrace();
89
				}
93
				}
90
			}
94
			}
91
		}
95
		}
Lines 154-159 Link Here
154
				String name = entry.getName();
158
				String name = entry.getName();
155
				String newName = recursionEffect(name);
159
				String newName = recursionEffect(name);
156
				if (newName != null) {
160
				if (newName != null) {
161
					if(verbose){
162
						for(int i = 0; i <= depth; i++)
163
							System.out.print("  "); //$NON-NLS-1$
164
						System.out.println("Processing nested file: " + name); //$NON-NLS-1$
165
					}
157
					//extract entry to temp directory
166
					//extract entry to temp directory
158
					File extracted = new File(tempDir, name);
167
					File extracted = new File(tempDir, name);
159
					File parentDir = extracted.getParentFile();
168
					File parentDir = extracted.getParentFile();
Lines 216-221 Link Here
216
		if (!workingDir.exists())
225
		if (!workingDir.exists())
217
			workingDir.mkdirs();
226
			workingDir.mkdirs();
218
227
228
		if(depth == 0 && verbose) {
229
			System.out.print("Running "); //$NON-NLS-1$ 
230
			for (Iterator iter = steps.iterator(); iter.hasNext();) {
231
				IProcessStep step = (IProcessStep) iter.next();
232
				System.out.print(step.getStepName() + " "); //$NON-NLS-1$
233
			}
234
			System.out.println("on " + input.getPath()); //$NON-NLS-1$
235
		}
219
		//pre
236
		//pre
220
		File workingFile = preProcess(input, workingDir);
237
		File workingFile = preProcess(input, workingDir);
221
238
(-)src/org/eclipse/update/internal/jarprocessor/PackStep.java (-12 / +20 lines)
Lines 36-50 Link Here
36
		for (int i = 0; i < locations.length; i++) {
36
		for (int i = 0; i < locations.length; i++) {
37
			if (locations[i] == null)
37
			if (locations[i] == null)
38
				continue;
38
				continue;
39
			try {
39
			result = execute(new String[] {locations[i], "-V"}); //$NON-NLS-1$
40
				result = execute(new String[] {locations[i], "-V"}); //$NON-NLS-1$
40
			if (result == 0) {
41
				if (result == 0) {
41
				packCommand = locations[i];
42
					packCommand = locations[i];
42
				canPack = Boolean.TRUE;
43
					canPack = Boolean.TRUE;
43
				return true;
44
					return true;
45
				}
46
			} catch (IOException e) {
47
				//no good
48
			}
44
			}
49
		}
45
		}
50
46
Lines 53-59 Link Here
53
	}
49
	}
54
50
55
	public PackStep(Properties options) {
51
	public PackStep(Properties options) {
56
		super(options, null, null);
52
		super(options, null, null, false);
53
		exclusions = Utils.getPackExclusions(options);
54
	}
55
56
	public PackStep(Properties options, boolean verbose) {
57
		super(options, null, null, verbose);
57
		exclusions = Utils.getPackExclusions(options);
58
		exclusions = Utils.getPackExclusions(options);
58
	}
59
	}
59
60
Lines 73-81 Link Here
73
			File outputFile = new File(workingDirectory, input.getName() + Utils.PACKED_SUFFIX);
74
			File outputFile = new File(workingDirectory, input.getName() + Utils.PACKED_SUFFIX);
74
			try {
75
			try {
75
				String[] cmd = getCommand(input, outputFile);
76
				String[] cmd = getCommand(input, outputFile);
76
				execute(cmd);
77
				int result = execute(cmd, verbose);
78
				if (result != 0 && verbose)
79
					System.out.println("Error: " + result + " was returned from command: " + Utils.concat(cmd)); //$NON-NLS-1$ //$NON-NLS-2$
77
			} catch (IOException e) {
80
			} catch (IOException e) {
78
				//didn't work
81
				if (verbose)
82
					e.printStackTrace();
79
				return null;
83
				return null;
80
			}
84
			}
81
			return outputFile;
85
			return outputFile;
Lines 98-101 Link Here
98
		}
102
		}
99
		return cmd;
103
		return cmd;
100
	}
104
	}
105
106
	public String getStepName() {
107
		return "Pack"; //$NON-NLS-1$
108
	}
101
}
109
}
(-)src/org/eclipse/update/internal/jarprocessor/ZipProcessor.java (-6 / +20 lines)
Lines 34-39 Link Here
34
	private boolean signing = false;
34
	private boolean signing = false;
35
	private boolean repacking = false;
35
	private boolean repacking = false;
36
	private boolean unpacking = false;
36
	private boolean unpacking = false;
37
	private boolean verbose = false;
37
38
38
	public void setWorkingDirectory(String dir) {
39
	public void setWorkingDirectory(String dir) {
39
		workingDirectory = dir;
40
		workingDirectory = dir;
Lines 62-74 Link Here
62
		this.unpacking = unpack;
63
		this.unpacking = unpack;
63
	}
64
	}
64
65
66
	public void setVerbose(boolean verbose) {
67
		this.verbose = verbose;
68
	}
69
65
	public void processZip(File zipFile) throws ZipException, IOException {
70
	public void processZip(File zipFile) throws ZipException, IOException {
71
		if (verbose)
72
			System.out.println("Processing " + zipFile.getPath()); //$NON-NLS-1$
66
		ZipFile zip = new ZipFile(zipFile);
73
		ZipFile zip = new ZipFile(zipFile);
67
		initialize(zip);
74
		initialize(zip);
68
75
69
		String extension = unpacking ? "pack.gz" : ".jar"; //$NON-NLS-1$ //$NON-NLS-2$
76
		String extension = unpacking ? "pack.gz" : ".jar"; //$NON-NLS-1$ //$NON-NLS-2$
70
		File tempDir = new File(getWorkingDirectory(), "temp_" + zipFile.getName()); //$NON-NLS-1$
77
		File tempDir = new File(getWorkingDirectory(), "temp_" + zipFile.getName()); //$NON-NLS-1$
71
		JarProcessor processor = new JarProcessor();
78
		JarProcessor processor = new JarProcessor();
79
		processor.setVerbose(verbose);
72
		processor.setWorkingDirectory(tempDir.getCanonicalPath());
80
		processor.setWorkingDirectory(tempDir.getCanonicalPath());
73
		if (unpacking) {
81
		if (unpacking) {
74
			processor.addProcessStep(unpackStep);
82
			processor.addProcessStep(unpackStep);
Lines 97-102 Link Here
97
					parent = extractedFile.getParentFile();
105
					parent = extractedFile.getParentFile();
98
					if (!parent.exists())
106
					if (!parent.exists())
99
						parent.mkdirs();
107
						parent.mkdirs();
108
					if (verbose)
109
						System.out.println("Extracting " + entry.getName()); //$NON-NLS-1$
100
					FileOutputStream extracted = new FileOutputStream(extractedFile);
110
					FileOutputStream extracted = new FileOutputStream(extractedFile);
101
					Utils.transferStreams(entryStream, extracted, true);
111
					Utils.transferStreams(entryStream, extracted, true);
102
112
Lines 127-132 Link Here
127
						}
137
						}
128
					}
138
					}
129
					entryStream = new FileInputStream(extractedFile);
139
					entryStream = new FileInputStream(extractedFile);
140
					if (verbose) {
141
						System.out.println("Adding " + entry.getName() + " to " + outputFile.getPath()); //$NON-NLS-1$ //$NON-NLS-2$
142
						System.out.println();
143
					}
130
				}
144
				}
131
				ZipEntry newEntry = new ZipEntry(name);
145
				ZipEntry newEntry = new ZipEntry(name);
132
				zipOut.putNextEntry(newEntry);
146
				zipOut.putNextEntry(newEntry);
Lines 158-165 Link Here
158
				stream = zip.getInputStream(entry);
172
				stream = zip.getInputStream(entry);
159
				properties.load(stream);
173
				properties.load(stream);
160
			} catch (IOException e) {
174
			} catch (IOException e) {
161
				// TODO Auto-generated catch block
175
				if (verbose)
162
				e.printStackTrace();
176
					e.printStackTrace();
163
			} finally {
177
			} finally {
164
				Utils.close(stream);
178
				Utils.close(stream);
165
			}
179
			}
Lines 168-176 Link Here
168
		packExclusions = Utils.getPackExclusions(properties);
182
		packExclusions = Utils.getPackExclusions(properties);
169
		signExclusions = Utils.getSignExclusions(properties);
183
		signExclusions = Utils.getSignExclusions(properties);
170
184
171
		packUnpackStep = new PackUnpackStep(properties);
185
		packUnpackStep = new PackUnpackStep(properties, verbose);
172
		packStep = new PackStep(properties);
186
		packStep = new PackStep(properties, verbose);
173
		signStep = new SignCommandStep(properties, command);
187
		signStep = new SignCommandStep(properties, command, verbose);
174
		unpackStep = new UnpackStep(properties);
188
		unpackStep = new UnpackStep(properties, verbose);
175
	}
189
	}
176
}
190
}
(-)src/org/eclipse/update/internal/jarprocessor/SignCommandStep.java (-6 / +21 lines)
Lines 22-28 Link Here
22
	private Set exclusions = null;
22
	private Set exclusions = null;
23
23
24
	public SignCommandStep(Properties options, String command) {
24
	public SignCommandStep(Properties options, String command) {
25
		super(options, command, ".jar"); //$NON-NLS-1$
25
		super(options, command, ".jar", false); //$NON-NLS-1$
26
		exclusions = Utils.getSignExclusions(options);
27
	}
28
29
	public SignCommandStep(Properties options, String command, boolean verbose) {
30
		super(options, command, ".jar", verbose); //$NON-NLS-1$
26
		exclusions = Utils.getSignExclusions(options);
31
		exclusions = Utils.getSignExclusions(options);
27
	}
32
	}
28
33
Lines 49-62 Link Here
49
		if (command != null) {
54
		if (command != null) {
50
			try {
55
			try {
51
				String[] cmd = new String[] {command, input.getCanonicalPath()};
56
				String[] cmd = new String[] {command, input.getCanonicalPath()};
52
				int result = execute(cmd);
57
				int result = execute(cmd, verbose);
53
				if (result == 0) {
58
				if (result == 0) {
54
					normalize(input, workingDirectory);
59
					normalize(input, workingDirectory);
55
					return input;
60
					return input;
61
				} else if (verbose) {
62
					System.out.println("Error: " + result + " was returned from command: " + Utils.concat(cmd)); //$NON-NLS-1$ //$NON-NLS-2$
56
				}
63
				}
57
			} catch (IOException e) {
64
			} catch (IOException e) {
58
				//boo
65
				if (verbose) {
59
				e.printStackTrace();
66
					e.printStackTrace();
67
				}
60
			}
68
			}
61
		}
69
		}
62
		return null;
70
		return null;
Lines 65-71 Link Here
65
	private void normalize(File input, File workingDirectory) {
73
	private void normalize(File input, File workingDirectory) {
66
		try {
74
		try {
67
			File tempJar = new File(workingDirectory, "temp_" + input.getName()); //$NON-NLS-1$
75
			File tempJar = new File(workingDirectory, "temp_" + input.getName()); //$NON-NLS-1$
68
			JarFile jar = new JarFile(input);
76
			JarFile jar = new JarFile(input, false);
69
			JarOutputStream jarOut = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(tempJar)));
77
			JarOutputStream jarOut = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(tempJar)));
70
			InputStream in = null;
78
			InputStream in = null;
71
			try {
79
			try {
Lines 88-94 Link Here
88
			input.delete();
96
			input.delete();
89
			tempJar.renameTo(input);
97
			tempJar.renameTo(input);
90
		} catch (IOException e) {
98
		} catch (IOException e) {
91
			//boo
99
			if (verbose) {
100
				System.out.println("Error normalizing jar " + input.getName()); //$NON-NLS-1$
101
				e.printStackTrace();
102
			}
92
		}
103
		}
93
	}
104
	}
105
106
	public String getStepName() {
107
		return "Sign"; //$NON-NLS-1$
108
	}
94
}
109
}
(-)src/org/eclipse/update/internal/jarprocessor/Utils.java (+10 lines)
Lines 175-178 Link Here
175
		}
175
		}
176
		return Collections.EMPTY_SET;
176
		return Collections.EMPTY_SET;
177
	}
177
	}
178
	
179
	public static String concat(String [] array){
180
		StringBuffer buffer = new StringBuffer();
181
		for (int i = 0; i < array.length; i++) {
182
			if( i > 0 )
183
				buffer.append(' ');
184
			buffer.append(array[i]);
185
		}
186
		return buffer.toString();
187
	}
178
}
188
}
(-)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.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/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 (+140 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
	public final static String VERBOSE = "-verbose"; //$NON-NLS-1$
41
	
42
	public final static String JAR_PROCESSOR_PACK = "-pack"; //$NON-NLS-1$
43
	public final static String JAR_PROCESSOR_UNPACK = "-unpack"; //$NON-NLS-1$
44
	public final static String JAR_PROCESSOR_REPACK = "-repack"; //$NON-NLS-1$
45
	public final static String JAR_PROCESSOR_SIGN = "-sign"; //$NON-NLS-1$
46
47
	
48
	/**
49
	 * Parses the command line in the form:
50
	 *  [-key [value]]* [inputvalue]
51
	 *  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
52
	 * @param args
53
	 * @return
54
	 */
55
	private Map parseCmdLine(String [] args) {
56
		Map cmds = new HashMap();
57
		for (int i = 0; i < args.length; i++) {
58
			if(i == args.length - 1 && !args[i].startsWith("-")) { //$NON-NLS-1$
59
				cmds.put(INPUT, args[i]);
60
			} else {
61
				String key = args[i];
62
				String val = null;
63
				if( i < args.length - 2 && !args[i + 1].startsWith("-")){ //$NON-NLS-1$
64
					val = args[++i];
65
				}
66
				cmds.put(key, val);
67
			}
68
		}
69
		return cmds;
70
	}
71
	
72
	private boolean runJarProcessor(Map params) {
73
		Main.Options options = new Main.Options();
74
		options.pack = params.containsKey(JAR_PROCESSOR_PACK);
75
		options.unpack = params.containsKey(JAR_PROCESSOR_UNPACK);
76
		options.repack = params.containsKey(JAR_PROCESSOR_REPACK);
77
		options.verbose = params.containsKey(VERBOSE);
78
		options.signCommand = (String) params.get(JAR_PROCESSOR_SIGN);
79
		options.outputDir = (String) params.get(OUTPUT_DIR);
80
		
81
		String problem = null;
82
		
83
		String input = (String) params.get(INPUT);
84
		if(input == null)
85
			problem = Messages.SiteOptimizer_inputNotSpecified;
86
		else {
87
			File inputFile = new File(input);
88
			if(inputFile.exists())
89
				options.input = inputFile;
90
			else 
91
				problem = NLS.bind(Messages.SiteOptimizer_inputFileNotFound, new String[] {input});
92
		}
93
		
94
		if (options.unpack) {
95
			if (!JarProcessor.canPerformUnpack()) {
96
				problem = Messages.JarProcessor_unpackNotFound;
97
			} else 	if (options.pack || options.repack || options.signCommand != null) {
98
				problem = Messages.JarProcessor_noPackUnpack;
99
			}
100
		} else if ((options.pack || options.repack) && !JarProcessor.canPerformPack()) {
101
			problem = Messages.JarProcessor_packNotFound;
102
		}
103
	
104
		if(problem != null) {
105
			System.out.println(problem);
106
			return false;
107
		}
108
		
109
		Main.runJarProcessor(options);
110
		return true;
111
	}
112
	
113
	private boolean runDigestBuilder(Map params) {
114
		//TODO
115
		return true;
116
	}
117
	
118
	/* (non-Javadoc)
119
	 * @see org.eclipse.core.runtime.IPlatformRunnable#run(java.lang.Object)
120
	 */
121
	public Object run(Object args) throws Exception {
122
		Platform.endSplash();
123
		if (args == null)
124
			return EXIT_ERROR;
125
		if (args instanceof String[]) {
126
			Map params = parseCmdLine((String[]) args);
127
			if(params.containsKey(JAR_PROCESSOR)){
128
				if(!runJarProcessor(params))
129
					return EXIT_ERROR;
130
			}
131
			
132
			if(params.containsKey(DIGEST_BUILDER)){
133
				if(!runDigestBuilder(params))
134
					return EXIT_ERROR;
135
			}
136
		}
137
		return IPlatformRunnable.EXIT_OK;
138
	}
139
140
}

Return to bug 127375