KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > equinox > internal > app > CommandLineArgs


1 package org.eclipse.equinox.internal.app;
2
3 public class CommandLineArgs {
4     // obsolete command line args
5
private static final String JavaDoc NO_PACKAGE_PREFIXES = "-noPackagePrefixes"; //$NON-NLS-1$
6
private static final String JavaDoc NO_UPDATE = "-noUpdate"; //$NON-NLS-1$
7
private static final String JavaDoc BOOT = "-boot"; //$NON-NLS-1$
8
private static final String JavaDoc CLASSLOADER_PROPERTIES = "-classloaderProperties"; //$NON-NLS-1$
9
private static final String JavaDoc PLUGINS = "-plugins"; //$NON-NLS-1$
10
private static final String JavaDoc FIRST_USE = "-firstUse"; //$NON-NLS-1$
11
private static final String JavaDoc NEW_UPDATES = "-newUpdates"; //$NON-NLS-1$
12
private static final String JavaDoc UPDATE = "-update"; //$NON-NLS-1$
13
private static final String JavaDoc PASSWORD = "-password"; //$NON-NLS-1$
14
private static final String JavaDoc KEYRING = "-keyring"; //$NON-NLS-1$
15

16     // supported command line args
17
private static final String JavaDoc PRODUCT = "-product"; //$NON-NLS-1$
18
private static final String JavaDoc FEATURE = "-feature"; //$NON-NLS-1$
19
private static final String JavaDoc APPLICATION = "-application"; //$NON-NLS-1$
20

21     // Command line args as seen by the Eclipse runtime. allArgs does NOT
22
// include args consumed by the underlying framework (e.g., OSGi)
23
private static String JavaDoc[] appArgs = new String JavaDoc[0];
24     private static String JavaDoc[] allArgs = new String JavaDoc[0];
25     private static String JavaDoc product;
26     private static String JavaDoc application;
27
28     static String JavaDoc[] processCommandLine(String JavaDoc[] args) {
29         if (args == null)
30             return args;
31         if (args.length == 0)
32             return args;
33         allArgs = args;
34         int[] configArgs = new int[args.length];
35         //need to initialize the first element to something that could not be an index.
36
configArgs[0] = -1;
37         int configArgIndex = 0;
38         for (int i = 0; i < args.length; i++) {
39             boolean found = false;
40             // check for args without parameters (i.e., a flag arg)
41

42             // consume obsolete args for compatibility
43
if (args[i].equalsIgnoreCase(CLASSLOADER_PROPERTIES))
44                 found = true; // ignored
45
if (args[i].equalsIgnoreCase(NO_PACKAGE_PREFIXES))
46                 found = true; // ignored
47
if (args[i].equalsIgnoreCase(PLUGINS))
48                 found = true; // ignored
49
if (args[i].equalsIgnoreCase(FIRST_USE))
50                 found = true; // ignored
51
if (args[i].equalsIgnoreCase(NO_UPDATE))
52                 found = true; // ignored
53
if (args[i].equalsIgnoreCase(NEW_UPDATES))
54                 found = true; // ignored
55
if (args[i].equalsIgnoreCase(UPDATE))
56                 found = true; // ignored
57
if (args[i].equalsIgnoreCase(BOOT))
58                 found = true; // ignored
59
if (args[i].equalsIgnoreCase(KEYRING))
60                 found = true; // ignored
61
if (args[i].equalsIgnoreCase(PASSWORD))
62                 found = true; // ignored
63

64             // done checking obsolete for args. Remember where an arg was found
65
if (found) {
66                 configArgs[configArgIndex++] = i;
67                 // check if the obsolete arg had a second param
68
if (i < (args.length -1) && !args[i + 1].startsWith("-")) //$NON-NLS-1$
69
configArgs[configArgIndex++] = ++i;
70                 continue;
71             }
72
73             // check for args with parameters
74
if (i == args.length - 1 || args[i + 1].startsWith("-")) //$NON-NLS-1$
75
continue;
76             String JavaDoc arg = args[++i];
77
78             // look for the product to run
79
// treat -feature as a synonym for -product for compatibility.
80
if (args[i - 1].equalsIgnoreCase(PRODUCT) || args[i - 1].equalsIgnoreCase(FEATURE)) {
81                 // use the long way to set the property to compile against eeminimum
82
product = arg;
83                 found = true;
84             }
85
86             // look for the application to run.
87
if (args[i - 1].equalsIgnoreCase(APPLICATION)) {
88                 // use the long way to set the property to compile against eeminimum
89
application = arg;
90                 found = true;
91             }
92
93             // done checking for args. Remember where an arg was found
94
if (found) {
95                 configArgs[configArgIndex++] = i - 1;
96                 configArgs[configArgIndex++] = i;
97             }
98         }
99
100         // remove all the arguments consumed by this argument parsing
101
if (configArgIndex == 0) {
102             appArgs = args;
103             return args;
104         }
105         appArgs = new String JavaDoc[args.length - configArgIndex];
106         configArgIndex = 0;
107         int j = 0;
108         for (int i = 0; i < args.length; i++) {
109             if (i == configArgs[configArgIndex])
110                 configArgIndex++;
111             else
112                 appArgs[j++] = args[i];
113         }
114         return appArgs;
115     }
116
117     static String JavaDoc getApplication() {
118         return application;
119     }
120
121     static String JavaDoc getProduct() {
122         return product;
123     }
124
125     public static String JavaDoc[] getApplicationArgs() {
126         return appArgs;
127     }
128
129     public static String JavaDoc[] getAllArgs() {
130         return allArgs;
131     }
132 }
133
Popular Tags