KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > ui > launcher > EquinoxLaunchConfiguration


1 /*******************************************************************************
2  * Copyright (c) 2005, 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.ui.launcher;
12
13 import java.io.File JavaDoc;
14 import java.util.ArrayList JavaDoc;
15 import java.util.HashMap JavaDoc;
16 import java.util.Iterator JavaDoc;
17 import java.util.Map JavaDoc;
18 import java.util.Properties JavaDoc;
19
20 import org.eclipse.core.runtime.CoreException;
21 import org.eclipse.core.runtime.IProgressMonitor;
22 import org.eclipse.core.runtime.Path;
23 import org.eclipse.debug.core.ILaunch;
24 import org.eclipse.debug.core.ILaunchConfiguration;
25 import org.eclipse.pde.core.plugin.IFragmentModel;
26 import org.eclipse.pde.core.plugin.IPluginModelBase;
27 import org.eclipse.pde.core.plugin.PluginRegistry;
28 import org.eclipse.pde.core.plugin.TargetPlatform;
29 import org.eclipse.pde.internal.core.ClasspathHelper;
30 import org.eclipse.pde.internal.core.util.CoreUtility;
31 import org.eclipse.pde.internal.ui.IPDEUIConstants;
32 import org.eclipse.pde.internal.ui.PDEUIMessages;
33 import org.eclipse.pde.internal.ui.launcher.BundleLauncherHelper;
34 import org.eclipse.pde.internal.ui.launcher.LaunchConfigurationHelper;
35 import org.eclipse.pde.internal.ui.launcher.LaunchPluginValidator;
36 import org.eclipse.pde.internal.ui.launcher.LauncherUtils;
37 import org.eclipse.pde.internal.ui.launcher.OSGiValidationOperation;
38
39 /**
40  * A launch delegate for launching the Equinox framework
41  * <p>
42  * Clients may subclass and instantiate this class.
43  * </p>
44  * @since 3.2
45  */

46 public class EquinoxLaunchConfiguration extends AbstractPDELaunchConfiguration {
47     
48     // used to generate the dev classpath entries
49
// key is bundle ID, value is a model
50
protected Map JavaDoc fAllBundles;
51     
52     // key is a model, value is startLevel:autoStart
53
private Map JavaDoc fModels;
54
55     /*
56      * (non-Javadoc)
57      * @see org.eclipse.pde.ui.launcher.AbstractPDELaunchConfiguration#getProgramArguments(org.eclipse.debug.core.ILaunchConfiguration)
58      */

59     public String JavaDoc[] getProgramArguments(ILaunchConfiguration configuration) throws CoreException {
60         ArrayList JavaDoc programArgs = new ArrayList JavaDoc();
61     
62         programArgs.add("-dev"); //$NON-NLS-1$
63
programArgs.add(ClasspathHelper.getDevEntriesProperties(getConfigDir(configuration).toString() + "/dev.properties", fAllBundles)); //$NON-NLS-1$
64

65         saveConfigurationFile(configuration);
66         programArgs.add("-configuration"); //$NON-NLS-1$
67
programArgs.add("file:" + new Path(getConfigDir(configuration).getPath()).addTrailingSeparator().toString()); //$NON-NLS-1$
68

69         String JavaDoc[] args = super.getProgramArguments(configuration);
70         for (int i = 0; i < args.length; i++) {
71             programArgs.add(args[i]);
72         }
73         return (String JavaDoc[])programArgs.toArray(new String JavaDoc[programArgs.size()]);
74     }
75     
76     private void saveConfigurationFile(ILaunchConfiguration configuration) throws CoreException {
77         Properties JavaDoc properties = new Properties JavaDoc();
78         properties.setProperty("osgi.install.area", "file:" + TargetPlatform.getLocation()); //$NON-NLS-1$ //$NON-NLS-2$
79
properties.setProperty("osgi.configuration.cascaded", "false"); //$NON-NLS-1$ //$NON-NLS-2$
80
properties.put("osgi.framework", LaunchConfigurationHelper.getBundleURL("org.eclipse.osgi", fAllBundles)); //$NON-NLS-1$ //$NON-NLS-2$
81
int start = configuration.getAttribute(IPDELauncherConstants.DEFAULT_START_LEVEL, 4);
82         properties.put("osgi.bundles.defaultStartLevel", Integer.toString(start)); //$NON-NLS-1$
83
boolean autostart = configuration.getAttribute(IPDELauncherConstants.DEFAULT_AUTO_START, true);
84         String JavaDoc bundles = getBundles(autostart);
85         if (bundles.length() > 0)
86             properties.put("osgi.bundles", bundles); //$NON-NLS-1$
87
if (!"3.3".equals(configuration.getAttribute(IPDEUIConstants.LAUNCHER_PDE_VERSION, ""))) { //$NON-NLS-1$ //$NON-NLS-2$
88
properties.put("eclipse.ignoreApp", "true"); //$NON-NLS-1$ //$NON-NLS-2$
89
properties.put("osgi.noShutdown", "true"); //$NON-NLS-1$ //$NON-NLS-2$
90
}
91         LaunchConfigurationHelper.save(new File JavaDoc(getConfigDir(configuration), "config.ini"), properties); //$NON-NLS-1$
92
}
93     
94     private String JavaDoc getBundles(boolean defaultAuto) {
95         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
96         Iterator JavaDoc iter = fModels.keySet().iterator();
97         while (iter.hasNext()) {
98             IPluginModelBase model = (IPluginModelBase)iter.next();
99             String JavaDoc id = model.getPluginBase().getId();
100             if (!"org.eclipse.osgi".equals(id)) { //$NON-NLS-1$
101
if (buffer.length() > 0)
102                     buffer.append(","); //$NON-NLS-1$
103
buffer.append("reference:"); //$NON-NLS-1$
104
buffer.append(LaunchConfigurationHelper.getBundleURL(model));
105                 
106                 // fragments must not be started or have a start level
107
if (model instanceof IFragmentModel)
108                     continue;
109                 
110                 String JavaDoc data = fModels.get(model).toString();
111                 int index = data.indexOf(':');
112                 String JavaDoc level = index > 0 ? data.substring(0, index) : "default"; //$NON-NLS-1$
113
String JavaDoc auto = index > 0 && index < data.length() - 1 ? data.substring(index + 1) : "default"; //$NON-NLS-1$
114
if ("default".equals(auto)) //$NON-NLS-1$
115
auto = Boolean.toString(defaultAuto);
116                 if (!level.equals("default") || "true".equals(auto)) //$NON-NLS-1$ //$NON-NLS-2$
117
buffer.append("@"); //$NON-NLS-1$
118

119                 if (!level.equals("default")) { //$NON-NLS-1$
120
buffer.append(level);
121                     if ("true".equals(auto)) //$NON-NLS-1$
122
buffer.append(":"); //$NON-NLS-1$
123
}
124                 if ("true".equals(auto)) { //$NON-NLS-1$
125
buffer.append("start"); //$NON-NLS-1$
126
}
127             }
128         }
129         return buffer.toString();
130     }
131             
132     /*
133      * (non-Javadoc)
134      * @see org.eclipse.pde.ui.launcher.AbstractPDELaunchConfiguration#preLaunchCheck(org.eclipse.debug.core.ILaunchConfiguration, org.eclipse.debug.core.ILaunch, org.eclipse.core.runtime.IProgressMonitor)
135      */

136     protected void preLaunchCheck(ILaunchConfiguration configuration, ILaunch launch,
137             IProgressMonitor monitor) throws CoreException {
138         fModels = BundleLauncherHelper.getMergedMap(configuration);
139         fAllBundles = new HashMap JavaDoc(fModels.size());
140         Iterator JavaDoc iter = fModels.keySet().iterator();
141         while (iter.hasNext()) {
142             IPluginModelBase model = (IPluginModelBase)iter.next();
143             fAllBundles.put(model.getPluginBase().getId(), model);
144         }
145         
146         if (!fAllBundles.containsKey("org.eclipse.osgi")) { //$NON-NLS-1$
147
// implicitly add it
148
IPluginModelBase model = PluginRegistry.findModel("org.eclipse.osgi"); //$NON-NLS-1$
149
if (model != null) {
150                 fModels.put(model, "default:default"); //$NON-NLS-1$
151
fAllBundles.put("org.eclipse.osgi", model); //$NON-NLS-1$
152
} else {
153                 String JavaDoc message = PDEUIMessages.EquinoxLaunchConfiguration_oldTarget;
154                 throw new CoreException(LauncherUtils.createErrorStatus(message));
155             }
156         }
157         super.preLaunchCheck(configuration, launch, monitor);
158     }
159     
160     /*
161      * (non-Javadoc)
162      * @see org.eclipse.pde.ui.launcher.AbstractPDELaunchConfiguration#validatePluginDependencies(org.eclipse.debug.core.ILaunchConfiguration, org.eclipse.core.runtime.IProgressMonitor)
163      */

164     protected void validatePluginDependencies(ILaunchConfiguration configuration, IProgressMonitor monitor) throws CoreException {
165         OSGiValidationOperation op = new OSGiValidationOperation(configuration);
166         LaunchPluginValidator.runValidationOperation(op, monitor);
167     }
168     
169     /**
170      * Clears the configuration area if the area exists and that option is selected.
171      *
172      * @param configuration
173      * the launch configuration
174      * @param monitor
175      * the progress monitor
176      * @throws CoreException
177      * if unable to retrieve launch attribute values
178      * @since 3.3
179      */

180     protected void clear(ILaunchConfiguration configuration, IProgressMonitor monitor)
181             throws CoreException {
182         // clear config area, if necessary
183
if (configuration.getAttribute(IPDELauncherConstants.CONFIG_CLEAR_AREA, false))
184             CoreUtility.deleteContent(getConfigDir(configuration));
185     }
186
187 }
188
Popular Tags