KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > launching > macosx > MacOSXLaunchingPlugin


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 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 Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.launching.macosx;
12
13 import java.io.IOException JavaDoc;
14 import java.util.MissingResourceException JavaDoc;
15 import java.util.ResourceBundle JavaDoc;
16
17 import org.eclipse.core.runtime.Plugin;
18 import org.eclipse.jface.util.Assert;
19
20
21 public class MacOSXLaunchingPlugin extends Plugin {
22     
23     private static MacOSXLaunchingPlugin fgPlugin;
24     private static final String JavaDoc RESOURCE_BUNDLE= "org.eclipse.jdt.internal.launching.macosx.MacOSXLauncherMessages";//$NON-NLS-1$
25
private static ResourceBundle JavaDoc fgResourceBundle= ResourceBundle.getBundle(RESOURCE_BUNDLE);
26
27     public MacOSXLaunchingPlugin() {
28         super();
29         Assert.isTrue(fgPlugin == null);
30         fgPlugin= this;
31     }
32     
33     public static MacOSXLaunchingPlugin getDefault() {
34         return fgPlugin;
35     }
36     
37     static String JavaDoc getString(String JavaDoc key) {
38         try {
39             return fgResourceBundle.getString(key);
40         } catch (MissingResourceException JavaDoc e) {
41             return "!" + key + "!";//$NON-NLS-2$ //$NON-NLS-1$
42
}
43     }
44
45     /*
46      * Convenience method which returns the unique identifier of this plugin.
47      */

48     static String JavaDoc getUniqueIdentifier() {
49         if (getDefault() == null) {
50             // If the default instance is not yet initialized,
51
// return a static identifier. This identifier must
52
// match the plugin id defined in plugin.xml
53
return "org.eclipse.jdt.launching.macosx"; //$NON-NLS-1$
54
}
55         return getDefault().getBundle().getSymbolicName();
56     }
57
58     static String JavaDoc[] wrap(Class JavaDoc clazz, String JavaDoc[] cmdLine) {
59         
60         for (int i= 0; i < cmdLine.length; i++) {
61             // test whether we depend on SWT
62
if (useSWT(cmdLine[i]))
63                 return createSWTlauncher(clazz, cmdLine, cmdLine[0]);
64         }
65         return cmdLine;
66     }
67     
68     /*
69      * Heuristics: returns true if given argument refers to SWT.
70      */

71     private static boolean useSWT(String JavaDoc arg) {
72         return arg.indexOf("swt.jar") >= 0 || //$NON-NLS-1$
73
arg.indexOf("org.eclipse.swt") >= 0 || //$NON-NLS-1$
74
"-ws".equals(arg); //$NON-NLS-1$
75
}
76     
77     /*
78      * Returns path to executable.
79      */

80     static String JavaDoc[] createSWTlauncher(Class JavaDoc clazz, String JavaDoc[] cmdLine, String JavaDoc vmVersion) {
81         
82         // the following property is defined if Eclipse is started via java_swt
83
String JavaDoc java_swt= System.getProperty("org.eclipse.swtlauncher"); //$NON-NLS-1$
84

85         if (java_swt == null) {
86             // not started via java_swt -> now we require that the VM supports the "-XstartOnFirstThread" option
87
String JavaDoc[] newCmdLine= new String JavaDoc[cmdLine.length+1];
88             int argCount= 0;
89             newCmdLine[argCount++]= cmdLine[0];
90             newCmdLine[argCount++]= "-XstartOnFirstThread"; //$NON-NLS-1$
91
for (int i= 1; i < cmdLine.length; i++)
92                 newCmdLine[argCount++]= cmdLine[i];
93             return newCmdLine;
94         }
95         
96         try {
97             // copy java_swt to /tmp in order to get the app name right
98
Process JavaDoc process= Runtime.getRuntime().exec(new String JavaDoc[] { "/bin/cp", java_swt, "/tmp" }); //$NON-NLS-1$ //$NON-NLS-2$
99
process.waitFor();
100             java_swt= "/tmp/java_swt"; //$NON-NLS-1$
101
} catch (IOException JavaDoc e) {
102             // ignore and run java_swt in place
103
} catch (InterruptedException JavaDoc e) {
104             // ignore and run java_swt in place
105
}
106         
107         String JavaDoc[] newCmdLine= new String JavaDoc[cmdLine.length+1];
108         int argCount= 0;
109         newCmdLine[argCount++]= java_swt;
110         newCmdLine[argCount++]= "-XXvm=" + vmVersion; //$NON-NLS-1$
111
for (int i= 1; i < cmdLine.length; i++)
112             newCmdLine[argCount++]= cmdLine[i];
113         
114         return newCmdLine;
115     }
116 }
117
Popular Tags