Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 591cf8c72902f38d069fbc00c8b76a7c06d0fb8f (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
/*******************************************************************************
 * Copyright (c) 2007, 2009 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.ant;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Properties;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.SignJar;
import org.eclipse.equinox.internal.p2.jarprocessor.SignCommandStep;

public class AntSignCommand extends SignCommandStep {
	private final Project project;
	private final Properties jarSignerArguments;
	private final String antTaskName;

	public AntSignCommand(Properties options, Properties signArguments, Project project, String antTaskName, String command, boolean verbose) {
		super(options, command, verbose);
		this.project = project;
		this.jarSignerArguments = signArguments;
		this.antTaskName = antTaskName;
	}

	public File postProcess(File input, File workingDirectory, List containers) {
		if (command != null && input != null && shouldSign(input, containers)) {
			execute(input);
		}
		return null;
	}

	private void execute(File input) {
		try {
			SignJar jarSigner = new SignJar();
			jarSigner.setJar(input);
			jarSigner.setAlias(jarSignerArguments.getProperty(JarProcessorTask.ALIAS));
			jarSigner.setKeystore(jarSignerArguments.getProperty(JarProcessorTask.KEYSTORE));
			jarSigner.setStorepass(jarSignerArguments.getProperty(JarProcessorTask.STOREPASS));
			jarSigner.setKeypass(jarSignerArguments.getProperty(JarProcessorTask.KEYPASS));
			jarSigner.setProject(project);
			jarSigner.setTaskName(antTaskName);
			jarSigner.execute();
		} catch (BuildException e) {
			if (e.getCause() instanceof IOException) {
				throw new BuildException("The jarsigner could not be found. Make sure to run with the build with a JDK.", e); //$NON-NLS-1$
			}
			throw e;
		}
	}
}

Back to the top