Skip to main content
summaryrefslogtreecommitdiffstats
blob: f9b19351ed58ff93737e4eeaba790b052dadc6b7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*******************************************************************************
 * Copyright (c) 2007 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.equinox.internal.p2.jarprocessor.verifier;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Properties;
import org.eclipse.equinox.internal.p2.jarprocessor.CommandStep;
import org.eclipse.equinox.internal.p2.jarprocessor.Utils;

public class VerifyStep extends CommandStep {

	static String verifyCommand = "jarsigner"; //$NON-NLS-1$
	static Boolean canVerify = null;

	public static boolean canVerify() {
		if (canVerify != null)
			return canVerify.booleanValue();

		String javaHome = System.getProperty("java.home"); //$NON-NLS-1$
		String command = javaHome + "/../bin/jarsigner"; //$NON-NLS-1$
		int result = execute(new String[] {command});
		if (result < 0) {
			command = "jarsigner"; //$NON-NLS-1$
			result = execute(new String[] {command});
			if (result < 0) {
				canVerify = Boolean.FALSE;
				return false;
			}
		}
		verifyCommand = command;
		canVerify = Boolean.TRUE;
		return true;
	}

	public VerifyStep(Properties options, boolean verbose) {
		super(options, verifyCommand, ".jar", verbose); //$NON-NLS-1$
	}

	public String getStepName() {
		return "Verify"; //$NON-NLS-1$
	}

	public File postProcess(File input, File workingDirectory, List containers) {
		if (canVerify() && verifyCommand != null) {
			try {
				System.out.print("Verifying " + input.getName() + ":  "); //$NON-NLS-1$ //$NON-NLS-2$
				String[] cmd = new String[] {verifyCommand, "-verify", input.getCanonicalPath()}; //$NON-NLS-1$
				int result = execute(cmd, true);
				if (result != 0 && verbose)
					System.out.println("Error: " + result + " was returned from command: " + Utils.concat(cmd)); //$NON-NLS-1$ //$NON-NLS-2$
			} catch (IOException e) {
				if (verbose)
					e.printStackTrace();
				return null;
			}
			return input;
		}
		return null;
	}

	public File preProcess(File input, File workingDirectory, List containers) {
		return null;
	}

	public String recursionEffect(String entryName) {
		return null;
	}

}

Back to the top