KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > launcher > EquinoxInitializer


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 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.pde.internal.ui.launcher;
12
13 import java.util.HashMap JavaDoc;
14 import java.util.Map JavaDoc;
15 import java.util.Properties JavaDoc;
16 import java.util.StringTokenizer JavaDoc;
17
18 import org.eclipse.core.runtime.Preferences;
19 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
20 import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
21 import org.eclipse.pde.internal.core.ICoreConstants;
22 import org.eclipse.pde.internal.core.PDECore;
23 import org.eclipse.pde.internal.core.TargetPlatformHelper;
24 import org.eclipse.pde.internal.ui.IPDEUIConstants;
25 import org.eclipse.pde.ui.launcher.IPDELauncherConstants;
26 import org.eclipse.pde.ui.launcher.OSGiLaunchConfigurationInitializer;
27
28 public class EquinoxInitializer extends OSGiLaunchConfigurationInitializer {
29     
30     private Map JavaDoc fStartLevels;
31
32     public void initialize(ILaunchConfigurationWorkingCopy configuration) {
33         super.initialize(configuration);
34         initializeProgramArguments(configuration);
35         initializeVMArguments(configuration);
36         initializeTracing(configuration);
37     }
38
39     private void initializeProgramArguments(ILaunchConfigurationWorkingCopy configuration) {
40         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(LaunchArgumentsHelper.getInitialProgramArguments());
41         if (buffer.length() > 0) {
42             if (buffer.indexOf("-console") == -1) { //$NON-NLS-1$
43
buffer.append(" -console"); //$NON-NLS-1$
44
}
45         } else {
46             buffer.append("-console"); //$NON-NLS-1$
47
}
48         configuration.setAttribute(IPDEUIConstants.APPEND_ARGS_EXPLICITLY, true);
49         configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, buffer.toString()); //$NON-NLS-1$
50
}
51     
52     private void initializeVMArguments(ILaunchConfigurationWorkingCopy configuration) {
53         configuration.setAttribute(IPDEUIConstants.LAUNCHER_PDE_VERSION, "3.3"); //$NON-NLS-1$
54
Preferences preferences = PDECore.getDefault().getPluginPreferences();
55         StringBuffer JavaDoc vmArgs = new StringBuffer JavaDoc(preferences.getString(ICoreConstants.VM_ARGS));
56         if (vmArgs.indexOf("-Declipse.ignoreApp") == -1) { //$NON-NLS-1$
57
if (vmArgs.length() > 0)
58                 vmArgs.append(" "); //$NON-NLS-1$
59
vmArgs.append("-Declipse.ignoreApp=true"); //$NON-NLS-1$
60
}
61         if (vmArgs.indexOf("-Dosgi.noShutdown") == -1) { //$NON-NLS-1$
62
vmArgs.append(" -Dosgi.noShutdown=true"); //$NON-NLS-1$
63
}
64         configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, vmArgs.toString());
65     }
66     
67     private void initializeTracing(ILaunchConfigurationWorkingCopy configuration) {
68         configuration.setAttribute(IPDELauncherConstants.TRACING_CHECKED,
69                                    IPDELauncherConstants.TRACING_NONE);
70     }
71     
72     protected void initializeBundleState(ILaunchConfigurationWorkingCopy configuration) {
73         initializeBundleState();
74         super.initializeBundleState(configuration);
75     }
76     
77     protected String JavaDoc getAutoStart(String JavaDoc bundleID) {
78         if (fStartLevels.containsKey(bundleID)) {
79             String JavaDoc value = fStartLevels.get(bundleID).toString();
80             return value.substring(value.indexOf(":") + 1); //$NON-NLS-1$
81
}
82         return super.getAutoStart(bundleID);
83     }
84     
85     protected String JavaDoc getStartLevel(String JavaDoc bundleID) {
86         if (fStartLevels.containsKey(bundleID)) {
87             String JavaDoc value = fStartLevels.get(bundleID).toString();
88             return value.substring(0, value.indexOf(":")); //$NON-NLS-1$
89
}
90         return super.getStartLevel(bundleID);
91     }
92
93     
94     private void initializeBundleState() {
95         if (fStartLevels == null)
96             fStartLevels = new HashMap JavaDoc();
97         Properties JavaDoc props = TargetPlatformHelper.getConfigIniProperties();
98         if (props != null) {
99             String JavaDoc value = (String JavaDoc)props.get("osgi.bundles"); //$NON-NLS-1$
100
if (value != null) {
101                 StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(value, ","); //$NON-NLS-1$
102
while (tokenizer.hasMoreTokens()) {
103                     String JavaDoc tokenValue = tokenizer.nextToken();
104                     int index = tokenValue.indexOf("@"); //$NON-NLS-1$
105
if (index > 0) {
106                         String JavaDoc bundle = tokenValue.substring(0,index).trim();
107                         fStartLevels.put(bundle, getStartValue(tokenValue.substring(index)));
108                     }
109                 }
110             }
111         }
112     }
113         
114     private String JavaDoc getStartValue(String JavaDoc value) {
115         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(value);
116         StringBuffer JavaDoc result = new StringBuffer JavaDoc(":"); //$NON-NLS-1$
117

118         int index = value.indexOf("start"); //$NON-NLS-1$
119
result.append(Boolean.toString(index != -1));
120         
121         if (index != -1)
122             buffer.delete(index, index + 5);
123         
124         int colon = value.indexOf(':');
125         if (colon != -1)
126             buffer.deleteCharAt(colon);
127         
128         // delete the first char '@'
129
buffer.deleteCharAt(0);
130         
131         try {
132             result.insert(0, Integer.parseInt(buffer.toString().trim()));
133         } catch (NumberFormatException JavaDoc e) {
134             result.insert(0, DEFAULT);
135         }
136         return result.toString();
137     }
138
139 }
140
Popular Tags