|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2006 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.provisional; |
| 12 |
|
| 13 |
import java.io.File; |
| 14 |
import java.util.HashMap; |
| 15 |
import java.util.Map; |
| 16 |
import org.eclipse.core.runtime.IPlatformRunnable; |
| 17 |
import org.eclipse.core.runtime.Platform; |
| 18 |
import org.eclipse.osgi.util.NLS; |
| 19 |
import org.eclipse.update.internal.core.Messages; |
| 20 |
import org.eclipse.update.internal.jarprocessor.JarProcessor; |
| 21 |
import org.eclipse.update.internal.jarprocessor.Main; |
| 22 |
|
| 23 |
/** |
| 24 |
* The application class used to perform update site optimizations. |
| 25 |
* <p> |
| 26 |
* <b>Note:</b> This class/interface is part of an interim API that is still under development and expected to |
| 27 |
* change significantly before reaching stability. It is being made available at this early stage to solicit feedback |
| 28 |
* from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken |
| 29 |
* (repeatedly) as the API evolves. |
| 30 |
* </p> |
| 31 |
* @since 3.2 |
| 32 |
*/ |
| 33 |
public class SiteOptimizerApplication implements IPlatformRunnable { |
| 34 |
public final static Integer EXIT_ERROR = new Integer(1); |
| 35 |
|
| 36 |
public final static String JAR_PROCESSOR = "-jarProcessor"; //$NON-NLS-1$ |
| 37 |
public final static String DIGEST_BUILDER = "-digestBuilder"; //$NON-NLS-1$ |
| 38 |
public final static String INPUT = "input"; //$NON-NLS-1$ |
| 39 |
public final static String OUTPUT_DIR = "-outputDir"; //$NON-NLS-1$ |
| 40 |
|
| 41 |
public final static String JAR_PROCESSOR_PACK = "-pack"; //$NON-NLS-1$ |
| 42 |
public final static String JAR_PROCESSOR_UNPACK = "-unpack"; //$NON-NLS-1$ |
| 43 |
public final static String JAR_PROCESSOR_REPACK = "-repack"; //$NON-NLS-1$ |
| 44 |
public final static String JAR_PROCESSOR_SIGN = "-sign"; //$NON-NLS-1$ |
| 45 |
|
| 46 |
|
| 47 |
/** |
| 48 |
* Parses the command line in the form: |
| 49 |
* [-key [value]]* [inputvalue] |
| 50 |
* If the last argument does not start with a "-" then it is taken as the input value and not the value for a preceding -key |
| 51 |
* @param args |
| 52 |
* @return |
| 53 |
*/ |
| 54 |
private Map parseCmdLine(String [] args) { |
| 55 |
Map cmds = new HashMap(); |
| 56 |
for (int i = 0; i < args.length; i++) { |
| 57 |
if(i == args.length - 1 && !args[i].startsWith("-")) { //$NON-NLS-1$ |
| 58 |
cmds.put(INPUT, args[i]); |
| 59 |
} else { |
| 60 |
String key = args[i]; |
| 61 |
String val = null; |
| 62 |
if( i < args.length - 2 && !args[i + 1].startsWith("-")){ //$NON-NLS-1$ |
| 63 |
val = args[++i]; |
| 64 |
} |
| 65 |
cmds.put(key, val); |
| 66 |
} |
| 67 |
} |
| 68 |
return cmds; |
| 69 |
} |
| 70 |
|
| 71 |
private boolean runJarProcessor(Map params) { |
| 72 |
Main.Options options = new Main.Options(); |
| 73 |
options.pack = params.containsKey(JAR_PROCESSOR_PACK); |
| 74 |
options.unpack = params.containsKey(JAR_PROCESSOR_UNPACK); |
| 75 |
options.repack = params.containsKey(JAR_PROCESSOR_REPACK); |
| 76 |
options.signCommand = (String) params.get(JAR_PROCESSOR_SIGN); |
| 77 |
options.outputDir = (String) params.get(OUTPUT_DIR); |
| 78 |
|
| 79 |
String problem = null; |
| 80 |
|
| 81 |
String input = (String) params.get(INPUT); |
| 82 |
if(input == null) |
| 83 |
problem = Messages.SiteOptimizer_inputNotSpecified; |
| 84 |
else { |
| 85 |
File inputFile = new File(input); |
| 86 |
if(inputFile.exists()) |
| 87 |
options.input = inputFile; |
| 88 |
else |
| 89 |
problem = NLS.bind(Messages.SiteOptimizer_inputFileNotFound, new String[] {input}); |
| 90 |
} |
| 91 |
|
| 92 |
if (options.unpack) { |
| 93 |
if (!JarProcessor.canPerformUnpack()) { |
| 94 |
problem = Messages.JarProcessor_unpackNotFound; |
| 95 |
} else if (options.pack || options.repack || options.signCommand != null) { |
| 96 |
problem = Messages.JarProcessor_noPackUnpack; |
| 97 |
} |
| 98 |
} else if ((options.pack || options.repack) && !JarProcessor.canPerformPack()) { |
| 99 |
problem = Messages.JarProcessor_packNotFound; |
| 100 |
} |
| 101 |
|
| 102 |
if(problem != null) { |
| 103 |
System.out.println(problem); |
| 104 |
return false; |
| 105 |
} |
| 106 |
|
| 107 |
Main.runJarProcessor(options); |
| 108 |
return true; |
| 109 |
} |
| 110 |
|
| 111 |
private boolean runDigestBuilder(Map params) { |
| 112 |
//TODO |
| 113 |
return true; |
| 114 |
} |
| 115 |
|
| 116 |
/* (non-Javadoc) |
| 117 |
* @see org.eclipse.core.runtime.IPlatformRunnable#run(java.lang.Object) |
| 118 |
*/ |
| 119 |
public Object run(Object args) throws Exception { |
| 120 |
Platform.endSplash(); |
| 121 |
if (args == null) |
| 122 |
return EXIT_ERROR; |
| 123 |
if (args instanceof String[]) { |
| 124 |
Map params = parseCmdLine((String[]) args); |
| 125 |
if(params.containsKey(JAR_PROCESSOR)){ |
| 126 |
if(!runJarProcessor(params)) |
| 127 |
return EXIT_ERROR; |
| 128 |
} |
| 129 |
|
| 130 |
if(params.containsKey(DIGEST_BUILDER)){ |
| 131 |
if(!runDigestBuilder(params)) |
| 132 |
return EXIT_ERROR; |
| 133 |
} |
| 134 |
} |
| 135 |
return IPlatformRunnable.EXIT_OK; |
| 136 |
} |
| 137 |
|
| 138 |
} |