KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > internal > jarprocessor > SignCommandStep


1 /*******************************************************************************
2  * Copyright (c) 2006-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.update.internal.jarprocessor;
12
13 import java.io.File JavaDoc;
14 import java.io.IOException JavaDoc;
15 import java.util.Iterator JavaDoc;
16 import java.util.List JavaDoc;
17 import java.util.Properties JavaDoc;
18 import java.util.Set JavaDoc;
19
20 public class SignCommandStep extends CommandStep {
21     private Set JavaDoc exclusions = null;
22
23     public SignCommandStep(Properties JavaDoc options, String JavaDoc command) {
24         super(options, command, ".jar", false); //$NON-NLS-1$
25
exclusions = Utils.getSignExclusions(options);
26     }
27
28     public SignCommandStep(Properties JavaDoc options, String JavaDoc command, boolean verbose) {
29         super(options, command, ".jar", verbose); //$NON-NLS-1$
30
exclusions = Utils.getSignExclusions(options);
31     }
32
33     /* (non-Javadoc)
34      * @see org.eclipse.update.jarprocessor.IProcessStep#recursionEffect(java.lang.String)
35      */

36     public String JavaDoc recursionEffect(String JavaDoc entryName) {
37         if (entryName.endsWith(extension) && !exclusions.contains(entryName))
38             return entryName;
39         return null;
40     }
41
42     /* (non-Javadoc)
43      * @see org.eclipse.update.jarprocessor.IProcessStep#preProcess(java.io.File, java.io.File)
44      */

45     public File JavaDoc preProcess(File JavaDoc input, File JavaDoc workingDirectory, List JavaDoc containers) {
46         return null;
47     }
48
49     /* (non-Javadoc)
50      * @see org.eclipse.update.jarprocessor.IProcessStep#postProcess(java.io.File, java.io.File)
51      */

52     public File JavaDoc postProcess(File JavaDoc input, File JavaDoc workingDirectory, List JavaDoc containers) {
53         if (command != null && input != null && shouldSign(input, containers)) {
54             try {
55                 String JavaDoc[] cmd = new String JavaDoc[] {command, input.getCanonicalPath()};
56                 int result = execute(cmd, verbose);
57                 if (result == 0) {
58                     return input;
59                 } else if (verbose) {
60                     System.out.println("Error: " + result + " was returned from command: " + Utils.concat(cmd)); //$NON-NLS-1$ //$NON-NLS-2$
61
}
62             } catch (IOException JavaDoc e) {
63                 if (verbose) {
64                     e.printStackTrace();
65                 }
66             }
67         }
68         return null;
69     }
70
71     public boolean shouldSign(File JavaDoc input, List JavaDoc containers) {
72         Properties JavaDoc inf = null;
73
74         //1: Are we excluded from signing by our parents?
75
//innermost jar is first on the list, it overrides outer jars
76
for (Iterator JavaDoc iterator = containers.iterator(); iterator.hasNext();) {
77             inf = (Properties JavaDoc) iterator.next();
78             if (inf.containsKey(Utils.MARK_EXCLUDE_CHILDREN_SIGN)){
79                 if(Boolean.valueOf(inf.getProperty(Utils.MARK_EXCLUDE_CHILDREN_SIGN)).booleanValue()) {
80                     if (verbose)
81                         System.out.println(input.getName() + "is excluded from signing by its containers."); //$NON-NLS-1$ //$NON-NLS-2$
82
return false;
83                 }
84                 break;
85             }
86         }
87
88         //2: Is this jar itself marked as exclude?
89
inf = Utils.getEclipseInf(input, verbose);
90         if (inf != null && inf.containsKey(Utils.MARK_EXCLUDE_SIGN) && Boolean.valueOf(inf.getProperty(Utils.MARK_EXCLUDE_SIGN)).booleanValue()) {
91             if (verbose)
92                 System.out.println("Excluding " + input.getName() + " from signing."); //$NON-NLS-1$ //$NON-NLS-2$
93
return false;
94         }
95         return true;
96     }
97
98     public String JavaDoc getStepName() {
99         return "Sign"; //$NON-NLS-1$
100
}
101 }
102
Popular Tags