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
|
/*******************************************************************************
* 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.util.Properties;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
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();
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();
new AntBasedProcessorExecutor(signArgs, getProject(), getTaskName()).runJarProcessor(options);
}
public void setVerbose(boolean verbose) {
options.verbose = verbose;
}
}
|