KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > build > jarprocessor > JarProcessorTask


1 /*******************************************************************************
2  * Copyright (c) 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM - Initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.build.jarprocessor;
12
13 import java.io.File JavaDoc;
14 import java.util.Properties JavaDoc;
15 import org.apache.tools.ant.BuildException;
16 import org.apache.tools.ant.Task;
17 import org.eclipse.update.internal.jarprocessor.Main.Options;
18
19 /**
20  * This task provides massaging facilities for jar files.
21  * It supports: signing, unsigning, normalization, packing
22  * -
23  */

24 public class JarProcessorTask extends Task {
25     private Options options = new Options();
26     private Properties JavaDoc signArgs = new Properties JavaDoc();
27
28     public static final String JavaDoc ALIAS = "alias"; //$NON-NLS-1$
29
public static final String JavaDoc KEYSTORE = "keystore"; //$NON-NLS-1$
30
public static final String JavaDoc STOREPASS = "storepass"; //$NON-NLS-1$
31
public static final String JavaDoc UNSIGN = "unsign"; //$NON-NLS-1$
32
public static final String JavaDoc SIGN = "sign"; //$NON-NLS-1$
33

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

36     public void setAlias(String JavaDoc alias) {
37         signArgs.setProperty(ALIAS, alias);
38     }
39
40     public void setKeystore(String JavaDoc keystore) {
41         signArgs.setProperty(KEYSTORE, keystore);
42     }
43
44     public void setJar(File JavaDoc jar) {
45         options.input = jar;
46         options.outputDir = jar.getParentFile().getAbsolutePath();
47     }
48
49     public void setStorepass(String JavaDoc storepass) {
50         signArgs.setProperty(STOREPASS, storepass);
51     }
52
53     public void setPack(boolean pack) {
54         options.pack = pack;
55     }
56
57     public void setNormalize(boolean normalize) {
58         options.repack = normalize;
59     }
60
61     public void setUnsign(boolean unsign) {
62         if (unsign) {
63             signArgs.put(UNSIGN, Boolean.TRUE.toString());
64             options.signCommand = FAKE_COMMAND;
65         }
66     }
67
68     public void setSign(boolean sign) {
69         if (sign) {
70             signArgs.put(SIGN, Boolean.TRUE.toString());
71             options.signCommand = FAKE_COMMAND;
72         }
73     }
74
75     private void adjustAndValidateConfiguration() {
76         //Sign and pack implies a normalization
77
if (options.signCommand != null && options.pack)
78             options.repack = true;
79
80         //Check that alias, and storepass are set
81
if (options.signCommand != null && signArgs.getProperty(UNSIGN) == null) {
82             if (signArgs.getProperty(ALIAS) == null)
83                 throw new BuildException("Alias must be set"); //$NON-NLS-1$
84

85             if (signArgs.getProperty(STOREPASS) == null)
86                 throw new BuildException("Storepass must be set"); //$NON-NLS-1$
87
}
88     }
89
90     public void execute() {
91         options.processAll = true;
92         adjustAndValidateConfiguration();
93         new AntBasedProcessorExecutor(signArgs, getProject(), getTaskName()).runJarProcessor(options);
94     }
95
96     public void setVerbose(boolean verbose) {
97         options.verbose = verbose;
98     }
99 }
100
Popular Tags