Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: c057abd21e2e643de8158d4d07e29504eaee64aa (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*******************************************************************************
 * Copyright (c) 2007, 2010 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.util.ArrayList;
import java.util.Properties;
import org.apache.tools.ant.*;
import org.apache.tools.ant.types.FileSet;
import org.eclipse.internal.provisional.equinox.p2.jarprocessor.JarProcessorExecutor.Options;

/**
 * This task provides massaging facilities for jar files.
 * It supports: signing, unsigning, normalization, packing
 * 	- 
 */
public class JarProcessorTask extends Task {
	private final Options options = new Options();
	private final Properties signArgs = new Properties();
	private final ArrayList<File> inputFiles = new ArrayList<File>();

	public static final String ALIAS = "alias"; //$NON-NLS-1$
	public static final String KEYSTORE = "keystore"; //$NON-NLS-1$
	public static final String STOREPASS = "storepass"; //$NON-NLS-1$
	public static final String KEYPASS = "keypass"; //$NON-NLS-1$
	public static final String UNSIGN = "unsign"; //$NON-NLS-1$
	public static final String SIGN = "sign"; //$NON-NLS-1$

	private static final String FAKE_COMMAND = "fake"; //$NON-NLS-1$

	public void setAlias(String alias) {
		signArgs.setProperty(ALIAS, alias);
	}

	public void setKeystore(String keystore) {
		signArgs.setProperty(KEYSTORE, keystore);
	}

	public void setJar(File jar) {
		options.input = jar;
		options.outputDir = jar.getParentFile().getAbsolutePath();
	}

	public void setInputFolder(File folder) {
		options.input = folder;
		options.outputDir = folder.getAbsolutePath();
	}

	public void setStorepass(String storepass) {
		signArgs.setProperty(STOREPASS, storepass);
	}

	public void setKeypass(String keypass) {
		if (keypass != null && keypass.length() > 0 && !keypass.startsWith("${")) //$NON-NLS-1$
			signArgs.setProperty(KEYPASS, keypass);
	}

	public void setPack(boolean pack) {
		options.pack = pack;
	}

	public void setNormalize(boolean normalize) {
		options.repack = normalize;
	}

	public void setUnsign(boolean unsign) {
		if (unsign) {
			signArgs.put(UNSIGN, Boolean.TRUE.toString());
			options.signCommand = FAKE_COMMAND;
		}
	}

	public void setSign(boolean sign) {
		if (sign) {
			signArgs.put(SIGN, Boolean.TRUE.toString());
			options.signCommand = FAKE_COMMAND;
		}
	}

	private void adjustAndValidateConfiguration() {
		//Sign and pack implies a normalization
		if (options.signCommand != null && options.pack)
			options.repack = true;

		//Check that alias, and storepass are set
		if (options.signCommand != null && signArgs.getProperty(UNSIGN) == null) {
			if (signArgs.getProperty(ALIAS) == null)
				throw new BuildException("Alias must be set"); //$NON-NLS-1$

			if (signArgs.getProperty(STOREPASS) == null)
				throw new BuildException("Storepass must be set"); //$NON-NLS-1$
		}
	}

	public void execute() {
		options.processAll = true;
		adjustAndValidateConfiguration();
		AntBasedProcessorExecutor executor = new AntBasedProcessorExecutor(signArgs, getProject(), getTaskName());
		if (inputFiles.size() > 0)
			executor.setInputFiles(inputFiles);
		executor.runJarProcessor(options);
	}

	public void setVerbose(boolean verbose) {
		options.verbose = verbose;
	}

	public void addInputFile(File file) {
		inputFiles.add(file);
	}

	public void addConfiguredFile(FileSet fileset) {
		DirectoryScanner scanner = fileset.getDirectoryScanner(getProject());
		String[] included = scanner.getIncludedFiles();
		for (int i = 0; i < included.length; i++) {
			addInputFile(new File(scanner.getBasedir(), included[i]));
		}
		included = scanner.getIncludedDirectories();
		for (int i = 0; i < included.length; i++) {
			addInputFile(new File(scanner.getBasedir(), included[i]));
		}
	}
}

Back to the top