|
Lines 15-26
Link Here
|
| 15 |
import java.util.jar.*; |
15 |
import java.util.jar.*; |
| 16 |
|
16 |
|
| 17 |
/** |
17 |
/** |
| 18 |
* @author aniefer |
18 |
* @author aniefer@ca.ibm.com |
| 19 |
* |
19 |
* |
| 20 |
*/ |
20 |
*/ |
| 21 |
public class Utils { |
21 |
public class Utils { |
|
|
22 |
public static final String SIGN_EXCLUDES = "sign.excludes"; //$NON-NLS-1$ |
| 23 |
public static final String PACK_EXCLUDES = "pack.excludes"; //$NON-NLS-1$ |
| 22 |
public static final String MARK_FILE_NAME = "META-INF/eclipse.inf"; //$NON-NLS-1$ |
24 |
public static final String MARK_FILE_NAME = "META-INF/eclipse.inf"; //$NON-NLS-1$ |
| 23 |
public static final String MARK_PROPERTY = "pack200.conditioned"; //$NON-NLS-1$ |
25 |
public static final String MARK_PROPERTY = "pack200.conditioned"; //$NON-NLS-1$ |
|
|
26 |
public static final String MARK_EXCLUDE = "jarprocessor.exclude"; //$NON-NLS-1$ |
| 27 |
public static final String MARK_EXCLUDE_PACK = "jarprocessor.exclude.pack"; //$NON-NLS-1$ |
| 28 |
public static final String MARK_EXCLUDE_SIGN = "jarprocessor.exclude.sign"; //$NON-NLS-1$ |
| 29 |
public static final String MARK_JARPROCESSOR_VERSION = "jarprocessor.version"; //$NON-NLS-1$ |
| 30 |
public static final String PACK_ARGS = "pack200.args"; //$NON-NLS-1$ |
| 31 |
|
| 24 |
public static final String PACK200_PROPERTY = "org.eclipse.update.jarprocessor.pack200"; //$NON-NLS-1$ |
32 |
public static final String PACK200_PROPERTY = "org.eclipse.update.jarprocessor.pack200"; //$NON-NLS-1$ |
| 25 |
public static final String JRE = "@jre"; //$NON-NLS-1$ |
33 |
public static final String JRE = "@jre"; //$NON-NLS-1$ |
| 26 |
public static final String PATH = "@path"; //$NON-NLS-1$ |
34 |
public static final String PATH = "@path"; //$NON-NLS-1$ |
|
Lines 151-157
Link Here
|
| 151 |
if (properties == null) |
159 |
if (properties == null) |
| 152 |
return Collections.EMPTY_SET; |
160 |
return Collections.EMPTY_SET; |
| 153 |
|
161 |
|
| 154 |
String packExcludes = properties.getProperty("pack.excludes"); //$NON-NLS-1$ |
162 |
String packExcludes = properties.getProperty(PACK_EXCLUDES); |
| 155 |
if (packExcludes != null) { |
163 |
if (packExcludes != null) { |
| 156 |
String[] excludes = toStringArray(packExcludes, ","); //$NON-NLS-1$ |
164 |
String[] excludes = toStringArray(packExcludes, ","); //$NON-NLS-1$ |
| 157 |
Set packExclusions = new HashSet(); |
165 |
Set packExclusions = new HashSet(); |
|
Lines 166-172
Link Here
|
| 166 |
public static Set getSignExclusions(Properties properties) { |
174 |
public static Set getSignExclusions(Properties properties) { |
| 167 |
if (properties == null) |
175 |
if (properties == null) |
| 168 |
return Collections.EMPTY_SET; |
176 |
return Collections.EMPTY_SET; |
| 169 |
String signExcludes = properties.getProperty("sign.excludes"); //$NON-NLS-1$ |
177 |
String signExcludes = properties.getProperty(SIGN_EXCLUDES); |
| 170 |
if (signExcludes != null) { |
178 |
if (signExcludes != null) { |
| 171 |
String[] excludes = toStringArray(signExcludes, ","); //$NON-NLS-1$ |
179 |
String[] excludes = toStringArray(signExcludes, ","); //$NON-NLS-1$ |
| 172 |
Set signExclusions = new HashSet(); |
180 |
Set signExclusions = new HashSet(); |
|
Lines 193-232
Link Here
|
| 193 |
int count = tokenizer.countTokens(); |
201 |
int count = tokenizer.countTokens(); |
| 194 |
String[] result = new String[count]; |
202 |
String[] result = new String[count]; |
| 195 |
for (int i = 0; i < count; i++) { |
203 |
for (int i = 0; i < count; i++) { |
| 196 |
result[i] = tokenizer.nextToken(); |
204 |
result[i] = tokenizer.nextToken().trim(); |
| 197 |
} |
205 |
} |
| 198 |
return result; |
206 |
return result; |
| 199 |
} |
207 |
} |
| 200 |
|
208 |
|
| 201 |
public static boolean isUnmarkedJar(File jarFile) { |
209 |
/** |
| 202 |
if(jarFile == null || !jarFile.exists()) |
210 |
* Get the properties from the eclipse.inf file from the given jar. If the file is not a jar, null is returned. |
| 203 |
return false; |
211 |
* If the file is a jar, but does not contain an eclipse.inf file, an empty Properties object is returned. |
| 204 |
|
212 |
* @param jarFile |
| 205 |
boolean result = true; |
213 |
* @return |
| 206 |
JarFile jar = null; |
214 |
*/ |
|
|
215 |
public static Properties getEclipseInf(File jarFile) { |
| 216 |
if (jarFile == null || !jarFile.exists()) |
| 217 |
return null; |
| 207 |
|
218 |
|
|
|
219 |
JarFile jar = null; |
| 208 |
try { |
220 |
try { |
| 209 |
jar = new JarFile(jarFile, false); |
221 |
jar = new JarFile(jarFile, false); |
| 210 |
} catch (IOException e1) { |
|
|
| 211 |
//not a jar |
| 212 |
return false; |
| 213 |
} |
| 214 |
|
| 215 |
try { |
| 216 |
JarEntry mark = jar.getJarEntry(MARK_FILE_NAME); |
222 |
JarEntry mark = jar.getJarEntry(MARK_FILE_NAME); |
| 217 |
if (mark != null) { |
223 |
if (mark != null) { |
| 218 |
InputStream in = jar.getInputStream(mark); |
224 |
InputStream in = jar.getInputStream(mark); |
| 219 |
Properties props = new Properties(); |
225 |
Properties props = new Properties(); |
| 220 |
props.load(in); |
226 |
props.load(in); |
| 221 |
in.close(); |
227 |
in.close(); |
| 222 |
String value = props.getProperty(MARK_PROPERTY); |
228 |
return props; |
| 223 |
result = !Boolean.valueOf(value).booleanValue(); |
|
|
| 224 |
} |
229 |
} |
|
|
230 |
return new Properties(); |
| 225 |
} catch (IOException e) { |
231 |
} catch (IOException e) { |
| 226 |
return false; |
232 |
//not a jar |
| 227 |
} finally { |
233 |
} finally { |
| 228 |
close(jar); |
234 |
close(jar); |
| 229 |
} |
235 |
} |
| 230 |
return result; |
236 |
return null; |
|
|
237 |
} |
| 238 |
|
| 239 |
public static boolean shouldSkipJar(File input, boolean processAll, boolean verbose) { |
| 240 |
Properties inf = getEclipseInf(input); |
| 241 |
if (inf == null) { |
| 242 |
//not a jar, could be a pack.gz |
| 243 |
return false; |
| 244 |
} |
| 245 |
String exclude = inf.getProperty(MARK_EXCLUDE); |
| 246 |
|
| 247 |
//was marked as exclude, we should skip |
| 248 |
if (exclude != null && Boolean.valueOf(exclude).booleanValue()) |
| 249 |
return true; |
| 250 |
|
| 251 |
//process all was set, don't skip |
| 252 |
if (processAll) |
| 253 |
return false; |
| 254 |
|
| 255 |
//otherwise, we skip if not marked marked |
| 256 |
String marked = inf.getProperty(MARK_PROPERTY); |
| 257 |
boolean skip = !Boolean.valueOf(marked).booleanValue(); |
| 258 |
|
| 259 |
String version = inf.getProperty(MARK_JARPROCESSOR_VERSION); |
| 260 |
if (marked != null && verbose) { |
| 261 |
if (version == null) { |
| 262 |
//no version == 1.0.0 |
| 263 |
version = "1.0.0"; //$NON-NLS-1$ |
| 264 |
} |
| 265 |
if (!JarProcessor.PROCESSOR_VERSION.equals(version)) { |
| 266 |
System.out.println("Warning: " + input.getName() + " was conditioned with JarProcessor version " + version); //$NON-NLS-1$ //$NON-NLS-2$ |
| 267 |
} |
| 268 |
} |
| 269 |
return skip; |
| 270 |
} |
| 271 |
|
| 272 |
public static void storeProperties(Properties props, OutputStream stream) { |
| 273 |
PrintStream printStream = new PrintStream(stream); |
| 274 |
printStream.println("#Processed using Jarprocessor version " + JarProcessor.PROCESSOR_VERSION); //$NON-NLS-1$ |
| 275 |
SortedMap sorted = new TreeMap(props); |
| 276 |
for (Iterator iter = sorted.keySet().iterator(); iter.hasNext();) { |
| 277 |
String key = (String) iter.next(); |
| 278 |
printStream.print(key); |
| 279 |
printStream.print(" = "); //$NON-NLS-1$ |
| 280 |
printStream.println(sorted.get(key)); |
| 281 |
} |
| 282 |
printStream.flush(); |
| 231 |
} |
283 |
} |
| 232 |
} |
284 |
} |