Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 9b06da109a60c6e28acc14618168f3c67c60ebb0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*******************************************************************************
 * Copyright (c) 2006-2007 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     IBM - Initial API and implementation
 *******************************************************************************/
package org.eclipse.equinox.internal.p2.jarprocessor;

import java.io.File;
import org.eclipse.internal.provisional.equinox.p2.jarprocessor.JarProcessor;
import org.eclipse.internal.provisional.equinox.p2.jarprocessor.JarProcessorExecutor;

public class Main {

	private static void printUsage() {
		System.out.println("[-option ...]... input"); //$NON-NLS-1$
		System.out.println("The following options are supported:"); //$NON-NLS-1$
		System.out.println("-processAll     process all jars, regardless of whether they were previously normalized"); //$NON-NLS-1$
		System.out.println("                By default only normalized jars will be processed."); //$NON-NLS-1$
		System.out.println("-repack         normalize jars "); //$NON-NLS-1$
		System.out.println("-sign <command> sign jars using <command>"); //$NON-NLS-1$
		System.out.println("-pack           pack the jars.  pack and repack are redundant unless"); //$NON-NLS-1$
		System.out.println("                sign is also specified."); //$NON-NLS-1$
		System.out.println("-unpack         unpack pack.gz files. Unpack is mutually exclusive"); //$NON-NLS-1$
		System.out.println("                with repack, sign and pack."); //$NON-NLS-1$
		System.out.println();
		System.out.println("-outputDir <dir>  the output directory"); //$NON-NLS-1$
		System.out.println("-verbose        verbose mode "); //$NON-NLS-1$
	}

	public static JarProcessorExecutor.Options processArguments(String[] args) {
		if (args.length == 0) {
			printUsage();
			return null;
		}

		JarProcessorExecutor.Options options = new JarProcessorExecutor.Options();
		int i = 0;
		for (; i < args.length - 1; i++) {
			if (args[i].equals("-pack")) {//$NON-NLS-1$
				options.pack = true;
			} else if (args[i].equals("-unpack")) { //$NON-NLS-1$
				options.unpack = true;
			} else if (args[i].equals("-sign") && i < args.length - 2) { //$NON-NLS-1$
				if (args[i + 1].startsWith("-")) { //$NON-NLS-1$
					printUsage();
					return null;
				}
				options.signCommand = args[++i];
			} else if (args[i].equals("-repack")) { //$NON-NLS-1$
				options.repack = true;
			} else if (args[i].equals("-outputDir") && i < args.length - 2) { //$NON-NLS-1$
				if (args[i + 1].startsWith("-")) { //$NON-NLS-1$
					printUsage();
					return null;
				}
				options.outputDir = args[++i];
			} else if (args[i].equals("-verbose")) { //$NON-NLS-1$
				options.verbose = true;
			}  else if (args[i].equals("-processAll")) { //$NON-NLS-1$
				options.processAll = true;
			} 
		}

		options.input = new File(args[i]);

		String problemMessage = null;
		String inputName = options.input.getName();
		if (options.unpack) {
			if (!JarProcessor.canPerformUnpack()) {
				problemMessage = "The unpack200 command cannot be found."; //$NON-NLS-1$
			} else 	if (options.input.isFile() && !inputName.endsWith(".zip") && !inputName.endsWith(".pack.gz")) { //$NON-NLS-1$ //$NON-NLS-2$
				problemMessage = "Input file is not a pack.gz file."; //$NON-NLS-1$
			} else 	if (options.pack || options.repack || options.signCommand != null) {
				problemMessage = "Pack, repack or sign cannot be specified with unpack."; //$NON-NLS-1$
			}
		} else {
			if (options.input.isFile() && !inputName.endsWith(".zip") && !inputName.endsWith(".jar")) { //$NON-NLS-1$ //$NON-NLS-2$
				problemMessage = "Input file is not a jar file."; //$NON-NLS-1$
			} else	if ((options.pack || options.repack) && !JarProcessor.canPerformPack()) {
				problemMessage = "The pack200 command can not be found."; //$NON-NLS-1$
			}
		}
		if(problemMessage != null){
			System.out.println(problemMessage);
			System.out.println();
			printUsage();
			return null;
		}

		return options;
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		JarProcessorExecutor.Options options = processArguments(args);
		if (options == null)
			return;
		new JarProcessorExecutor().runJarProcessor(options);
	}

}

Back to the top