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 193568
Collapse All | Expand All

(-)customBuildCallbacks.xml (-1 / +1 lines)
Lines 81-87 Link Here
81
		<delete file="${dest}/jarprocessor.jar" failonerror="false"/>
81
		<delete file="${dest}/jarprocessor.jar" failonerror="false"/>
82
		<jar destfile="${dest}/jarprocessor.jar">
82
		<jar destfile="${dest}/jarprocessor.jar">
83
			<fileset dir="${target.folder}">
83
			<fileset dir="${target.folder}">
84
				<include name="org/eclipse/update/internal/jarprocessor/*"/>
84
				<include name="org/eclipse/update/internal/jarprocessor/**"/>
85
				<exclude name="**/jarprocessor.jardesc"/>
85
				<exclude name="**/jarprocessor.jardesc"/>
86
			</fileset>
86
			</fileset>
87
			<fileset dir="${basedir}" includes="about.html" />
87
			<fileset dir="${basedir}" includes="about.html" />
(-)jarprocessor/org/eclipse/update/internal/jarprocessor/verifier/VerifyStep.java (+79 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others. All rights reserved. This
3
 * program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Contributors: IBM - Initial API and implementation
8
 ******************************************************************************/
9
10
package org.eclipse.update.internal.jarprocessor.verifier;
11
12
import java.io.File;
13
import java.io.IOException;
14
import java.util.List;
15
import java.util.Properties;
16
17
import org.eclipse.update.internal.jarprocessor.CommandStep;
18
import org.eclipse.update.internal.jarprocessor.Utils;
19
20
public class VerifyStep extends CommandStep {
21
22
	static String verifyCommand = "jarsigner";
23
	static Boolean canVerify = null;
24
25
	public static boolean canVerify() {
26
		if (canVerify != null)
27
			return canVerify.booleanValue();
28
29
		String javaHome = System.getProperty("java.home"); //$NON-NLS-1$
30
		String command = javaHome + "/../bin/jarsigner";
31
		int result = execute(new String[] {command}); //$NON-NLS-1$ ;
32
		if (result < 0) {
33
			command = "jarsigner";
34
			result = execute(new String[] {command}); //$NON-NLS-1$ ;
35
			if (result < 0) {
36
				canVerify = Boolean.FALSE;
37
				return false;
38
			}
39
		}
40
		verifyCommand = command;
41
		canVerify = Boolean.TRUE;
42
		return true;
43
	}
44
45
	public VerifyStep(Properties options, boolean verbose) {
46
		super(options, verifyCommand, ".jar", verbose);
47
	}
48
49
	public String getStepName() {
50
		return "Verify";
51
	}
52
53
	public File postProcess(File input, File workingDirectory, List containers) {
54
		if (canVerify() && verifyCommand != null) {
55
			try {
56
				System.out.print("Verifying " + input.getName() + ":  ");
57
				String[] cmd = new String[] {verifyCommand, "-verify", input.getCanonicalPath()};
58
				int result = execute(cmd, true);
59
				if (result != 0 && verbose)
60
					System.out.println("Error: " + result + " was returned from command: " + Utils.concat(cmd)); //$NON-NLS-1$ //$NON-NLS-2$
61
			} catch (IOException e) {
62
				if (verbose)
63
					e.printStackTrace();
64
				return null;
65
			}
66
			return input;
67
		}
68
		return null;
69
	}
70
71
	public File preProcess(File input, File workingDirectory, List containers) {
72
		return null;
73
	}
74
75
	public String recursionEffect(String entryName) {
76
		return null;
77
	}
78
79
}
(-)jarprocessor/org/eclipse/update/internal/jarprocessor/verifier/Verifier.java (+106 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others. All rights reserved. This
3
 * program and the accompanying materials are made available under the terms of
4
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
5
 * available at http://www.eclipse.org/legal/epl-v10.html
6
 * 
7
 * Contributors: IBM - Initial API and implementation
8
 ******************************************************************************/
9
10
package org.eclipse.update.internal.jarprocessor.verifier;
11
12
import java.io.File;
13
import java.io.FileNotFoundException;
14
import java.io.IOException;
15
import java.util.Properties;
16
17
import org.eclipse.update.internal.jarprocessor.JarProcessor;
18
import org.eclipse.update.internal.jarprocessor.JarProcessorExecutor;
19
import org.eclipse.update.internal.jarprocessor.UnpackStep;
20
import org.eclipse.update.internal.jarprocessor.Utils;
21
22
public class Verifier extends JarProcessorExecutor {
23
24
	private static void printUsage() {
25
		System.out.println("This tool verifies that unpacking a pack.gz file with the jarprocessor results in a valid jar file."); //$NON-NLS-1$
26
		System.out.println("Usage: java -cp jarprocessor.jar org.eclipse.update.internal.jarprocessor.verifier.Verifier -dir <workingDirectory> input [input]"); //$NON-NLS-1$
27
		System.out.println(""); //$NON-NLS-1$
28
		System.out.println("-dir : specifies a working directory where pack.gz files can be temporarily unpacked"); //$NON-NLS-1$
29
		System.out.println("input : a list of directories and/or pack.gz files to verify."); //$NON-NLS-1$
30
31
	}
32
33
	public static void main(String[] args) {
34
		if (!VerifyStep.canVerify()) {
35
			System.out.println("Can't find jarsigner.  Please adjust your system path or use a jdk.");
36
			printUsage();
37
			return;
38
		}
39
40
		String workingDirectory = null;
41
		String [] input;
42
		
43
		if(args.length == 0) {
44
			workingDirectory = ".";
45
			input = new String[] {"."};
46
		}else {
47
			int idx = 0;
48
			if(args[0] == "-help"){
49
				printUsage();
50
				return;
51
			}
52
			if (args[idx] == "-dir") {
53
				workingDirectory = args[++idx];
54
				idx++;
55
			} else {
56
				workingDirectory = "temp";
57
			}
58
59
			input = new String[args.length - idx];
60
			System.arraycopy(args, idx, input, 0, args.length - idx);
61
		}
62
		
63
		File workingDir = new File(workingDirectory);
64
		boolean clear = false;
65
		if( workingDir.exists()) {
66
			workingDir = new File( workingDir, "jarprocessor.verifier.temp");
67
			clear = true;
68
		}
69
		
70
		Verifier verifier = new Verifier();
71
		verifier.verify(workingDir, input);
72
		
73
		if(clear)
74
			workingDir.deleteOnExit();
75
	}
76
77
	public void verify(final File workingDirectory, String[] input) {
78
		Properties options = new Properties();
79
80
		JarProcessor unpacker = new JarProcessor();
81
		unpacker.addProcessStep(new UnpackStep(options, false));
82
		unpacker.setWorkingDirectory(workingDirectory.getAbsolutePath());
83
84
		/* There is no need to use a full processor to do the verification unless we want to verify nested jars as well.
85
		 * So for now, use a custom processor to just call the verify step directly.
86
		 */
87
		final VerifyStep verifyStep = new VerifyStep(options, false);
88
		JarProcessor verifier = new JarProcessor() {
89
			public File processJar(File input) throws IOException {
90
				return verifyStep.postProcess(input, workingDirectory, null);
91
			}
92
		};
93
94
		for (int i = 0; i < input.length; i++) {
95
			File inputFile = new File(input[i]);
96
			if (inputFile.exists()) {
97
				try {
98
					process(inputFile, Utils.PACK_GZ_FILTER, true, unpacker, verifier);
99
				} catch (FileNotFoundException e) {
100
					e.printStackTrace();
101
				}
102
			}
103
		}
104
		Utils.clear(workingDirectory);
105
	}
106
}

Return to bug 193568