1 11 package org.eclipse.pde.ui.launcher; 12 13 import java.io.File ; 14 import java.util.ArrayList ; 15 import java.util.HashMap ; 16 import java.util.Iterator ; 17 import java.util.Map ; 18 import java.util.Properties ; 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 46 public class EquinoxLaunchConfiguration extends AbstractPDELaunchConfiguration { 47 48 protected Map fAllBundles; 51 52 private Map fModels; 54 55 59 public String [] getProgramArguments(ILaunchConfiguration configuration) throws CoreException { 60 ArrayList programArgs = new ArrayList (); 61 62 programArgs.add("-dev"); programArgs.add(ClasspathHelper.getDevEntriesProperties(getConfigDir(configuration).toString() + "/dev.properties", fAllBundles)); 65 saveConfigurationFile(configuration); 66 programArgs.add("-configuration"); programArgs.add("file:" + new Path(getConfigDir(configuration).getPath()).addTrailingSeparator().toString()); 69 String [] args = super.getProgramArguments(configuration); 70 for (int i = 0; i < args.length; i++) { 71 programArgs.add(args[i]); 72 } 73 return (String [])programArgs.toArray(new String [programArgs.size()]); 74 } 75 76 private void saveConfigurationFile(ILaunchConfiguration configuration) throws CoreException { 77 Properties properties = new Properties (); 78 properties.setProperty("osgi.install.area", "file:" + TargetPlatform.getLocation()); properties.setProperty("osgi.configuration.cascaded", "false"); properties.put("osgi.framework", LaunchConfigurationHelper.getBundleURL("org.eclipse.osgi", fAllBundles)); int start = configuration.getAttribute(IPDELauncherConstants.DEFAULT_START_LEVEL, 4); 82 properties.put("osgi.bundles.defaultStartLevel", Integer.toString(start)); boolean autostart = configuration.getAttribute(IPDELauncherConstants.DEFAULT_AUTO_START, true); 84 String bundles = getBundles(autostart); 85 if (bundles.length() > 0) 86 properties.put("osgi.bundles", bundles); if (!"3.3".equals(configuration.getAttribute(IPDEUIConstants.LAUNCHER_PDE_VERSION, ""))) { properties.put("eclipse.ignoreApp", "true"); properties.put("osgi.noShutdown", "true"); } 91 LaunchConfigurationHelper.save(new File (getConfigDir(configuration), "config.ini"), properties); } 93 94 private String getBundles(boolean defaultAuto) { 95 StringBuffer buffer = new StringBuffer (); 96 Iterator iter = fModels.keySet().iterator(); 97 while (iter.hasNext()) { 98 IPluginModelBase model = (IPluginModelBase)iter.next(); 99 String id = model.getPluginBase().getId(); 100 if (!"org.eclipse.osgi".equals(id)) { if (buffer.length() > 0) 102 buffer.append(","); buffer.append("reference:"); buffer.append(LaunchConfigurationHelper.getBundleURL(model)); 105 106 if (model instanceof IFragmentModel) 108 continue; 109 110 String data = fModels.get(model).toString(); 111 int index = data.indexOf(':'); 112 String level = index > 0 ? data.substring(0, index) : "default"; String auto = index > 0 && index < data.length() - 1 ? data.substring(index + 1) : "default"; if ("default".equals(auto)) auto = Boolean.toString(defaultAuto); 116 if (!level.equals("default") || "true".equals(auto)) buffer.append("@"); 119 if (!level.equals("default")) { buffer.append(level); 121 if ("true".equals(auto)) buffer.append(":"); } 124 if ("true".equals(auto)) { buffer.append("start"); } 127 } 128 } 129 return buffer.toString(); 130 } 131 132 136 protected void preLaunchCheck(ILaunchConfiguration configuration, ILaunch launch, 137 IProgressMonitor monitor) throws CoreException { 138 fModels = BundleLauncherHelper.getMergedMap(configuration); 139 fAllBundles = new HashMap (fModels.size()); 140 Iterator 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")) { IPluginModelBase model = PluginRegistry.findModel("org.eclipse.osgi"); if (model != null) { 150 fModels.put(model, "default:default"); fAllBundles.put("org.eclipse.osgi", model); } else { 153 String message = PDEUIMessages.EquinoxLaunchConfiguration_oldTarget; 154 throw new CoreException(LauncherUtils.createErrorStatus(message)); 155 } 156 } 157 super.preLaunchCheck(configuration, launch, monitor); 158 } 159 160 164 protected void validatePluginDependencies(ILaunchConfiguration configuration, IProgressMonitor monitor) throws CoreException { 165 OSGiValidationOperation op = new OSGiValidationOperation(configuration); 166 LaunchPluginValidator.runValidationOperation(op, monitor); 167 } 168 169 180 protected void clear(ILaunchConfiguration configuration, IProgressMonitor monitor) 181 throws CoreException { 182 if (configuration.getAttribute(IPDELauncherConstants.CONFIG_CLEAR_AREA, false)) 184 CoreUtility.deleteContent(getConfigDir(configuration)); 185 } 186 187 } 188 | Popular Tags |