01: /*******************************************************************************
02: * Copyright (c) 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM - Initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.build.jarprocessor;
11:
12: import java.io.File;
13: import java.io.IOException;
14: import java.util.List;
15: import java.util.Properties;
16: import org.apache.tools.ant.BuildException;
17: import org.apache.tools.ant.Project;
18: import org.apache.tools.ant.taskdefs.SignJar;
19: import org.eclipse.update.internal.jarprocessor.SignCommandStep;
20:
21: public class AntSignCommand extends SignCommandStep {
22: private Project project;
23: private Properties jarSignerArguments;
24: private String antTaskName;
25:
26: public AntSignCommand(Properties options, Properties signArguments,
27: Project project, String antTaskName, String command,
28: boolean verbose) {
29: super (options, command, verbose);
30: this .project = project;
31: this .jarSignerArguments = signArguments;
32: this .antTaskName = antTaskName;
33: }
34:
35: public File postProcess(File input, File workingDirectory,
36: List containers) {
37: if (command != null && input != null
38: && shouldSign(input, containers)) {
39: execute(input);
40: }
41: return null;
42: }
43:
44: private void execute(File input) {
45: try {
46: SignJar jarSigner = new SignJar();
47: jarSigner.setJar(input);
48: jarSigner.setAlias(jarSignerArguments
49: .getProperty(JarProcessorTask.ALIAS));
50: jarSigner.setKeystore(jarSignerArguments
51: .getProperty(JarProcessorTask.KEYSTORE));
52: jarSigner.setStorepass(jarSignerArguments
53: .getProperty(JarProcessorTask.STOREPASS));
54: jarSigner.setProject(project);
55: jarSigner.setTaskName(antTaskName);
56: jarSigner.execute();
57: } catch (BuildException e) {
58: if (e.getCause() instanceof IOException) {
59: throw new BuildException(
60: "The jarsigner could not be found. Make sure to run with the build with a JDK.", e); //$NON-NLS-1$
61: }
62: throw e;
63: }
64: }
65: }
|