|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2007 IBM Corporation and others. All rights reserved. This |
| 3 |
* program and the accompanying materials are made available under the terms of |
| 4 |
* the Eclipse Public License v1.0 which accompanies this distribution, and is |
| 5 |
* available at http://www.eclipse.org/legal/epl-v10.html |
| 6 |
* |
| 7 |
* Contributors: IBM - Initial API and implementation |
| 8 |
******************************************************************************/ |
| 9 |
|
| 10 |
package org.eclipse.update.internal.jarprocessor.verifier; |
| 11 |
|
| 12 |
import java.io.File; |
| 13 |
import java.io.FileNotFoundException; |
| 14 |
import java.io.IOException; |
| 15 |
import java.util.Properties; |
| 16 |
|
| 17 |
import org.eclipse.update.internal.jarprocessor.JarProcessor; |
| 18 |
import org.eclipse.update.internal.jarprocessor.JarProcessorExecutor; |
| 19 |
import org.eclipse.update.internal.jarprocessor.UnpackStep; |
| 20 |
import org.eclipse.update.internal.jarprocessor.Utils; |
| 21 |
|
| 22 |
public class Verifier extends JarProcessorExecutor { |
| 23 |
|
| 24 |
private static void printUsage() { |
| 25 |
System.out.println("This tool verifies that unpacking a pack.gz file with the jarprocessor results in a valid jar file."); //$NON-NLS-1$ |
| 26 |
System.out.println("Usage: java -cp jarprocessor.jar org.eclipse.update.internal.jarprocessor.verifier.Verifier -dir <workingDirectory> input [input]"); //$NON-NLS-1$ |
| 27 |
System.out.println(""); //$NON-NLS-1$ |
| 28 |
System.out.println("-dir : specifies a working directory where pack.gz files can be temporarily unpacked"); //$NON-NLS-1$ |
| 29 |
System.out.println("input : a list of directories and/or pack.gz files to verify."); //$NON-NLS-1$ |
| 30 |
|
| 31 |
} |
| 32 |
|
| 33 |
public static void main(String[] args) { |
| 34 |
if (!VerifyStep.canVerify()) { |
| 35 |
System.out.println("Can't find jarsigner. Please adjust your system path or use a jdk."); |
| 36 |
printUsage(); |
| 37 |
return; |
| 38 |
} |
| 39 |
|
| 40 |
String workingDirectory = null; |
| 41 |
String [] input; |
| 42 |
|
| 43 |
if(args.length == 0) { |
| 44 |
workingDirectory = "."; |
| 45 |
input = new String[] {"."}; |
| 46 |
}else { |
| 47 |
int idx = 0; |
| 48 |
if(args[0] == "-help"){ |
| 49 |
printUsage(); |
| 50 |
return; |
| 51 |
} |
| 52 |
if (args[idx] == "-dir") { |
| 53 |
workingDirectory = args[++idx]; |
| 54 |
idx++; |
| 55 |
} else { |
| 56 |
workingDirectory = "temp"; |
| 57 |
} |
| 58 |
|
| 59 |
input = new String[args.length - idx]; |
| 60 |
System.arraycopy(args, idx, input, 0, args.length - idx); |
| 61 |
} |
| 62 |
|
| 63 |
File workingDir = new File(workingDirectory); |
| 64 |
boolean clear = false; |
| 65 |
if( workingDir.exists()) { |
| 66 |
workingDir = new File( workingDir, "jarprocessor.verifier.temp"); |
| 67 |
clear = true; |
| 68 |
} |
| 69 |
|
| 70 |
Verifier verifier = new Verifier(); |
| 71 |
verifier.verify(workingDir, input); |
| 72 |
|
| 73 |
if(clear) |
| 74 |
workingDir.deleteOnExit(); |
| 75 |
} |
| 76 |
|
| 77 |
public void verify(final File workingDirectory, String[] input) { |
| 78 |
Properties options = new Properties(); |
| 79 |
|
| 80 |
JarProcessor unpacker = new JarProcessor(); |
| 81 |
unpacker.addProcessStep(new UnpackStep(options, false)); |
| 82 |
unpacker.setWorkingDirectory(workingDirectory.getAbsolutePath()); |
| 83 |
|
| 84 |
/* There is no need to use a full processor to do the verification unless we want to verify nested jars as well. |
| 85 |
* So for now, use a custom processor to just call the verify step directly. |
| 86 |
*/ |
| 87 |
final VerifyStep verifyStep = new VerifyStep(options, false); |
| 88 |
JarProcessor verifier = new JarProcessor() { |
| 89 |
public File processJar(File input) throws IOException { |
| 90 |
return verifyStep.postProcess(input, workingDirectory, null); |
| 91 |
} |
| 92 |
}; |
| 93 |
|
| 94 |
for (int i = 0; i < input.length; i++) { |
| 95 |
File inputFile = new File(input[i]); |
| 96 |
if (inputFile.exists()) { |
| 97 |
try { |
| 98 |
process(inputFile, Utils.PACK_GZ_FILTER, true, unpacker, verifier); |
| 99 |
} catch (FileNotFoundException e) { |
| 100 |
e.printStackTrace(); |
| 101 |
} |
| 102 |
} |
| 103 |
} |
| 104 |
Utils.clear(workingDirectory); |
| 105 |
} |
| 106 |
} |