1 11 package org.eclipse.pde.ui.launcher; 12 13 import java.io.File ; 14 import java.util.ArrayList ; 15 import java.util.Map ; 16 import java.util.Properties ; 17 18 import org.eclipse.core.runtime.CoreException; 19 import org.eclipse.core.runtime.IPath; 20 import org.eclipse.core.runtime.IProgressMonitor; 21 import org.eclipse.core.runtime.Path; 22 import org.eclipse.core.runtime.Status; 23 import org.eclipse.core.variables.IStringVariableManager; 24 import org.eclipse.core.variables.VariablesPlugin; 25 import org.eclipse.debug.core.ILaunch; 26 import org.eclipse.debug.core.ILaunchConfiguration; 27 import org.eclipse.pde.core.plugin.IPluginModelBase; 28 import org.eclipse.pde.core.plugin.TargetPlatform; 29 import org.eclipse.pde.internal.core.ClasspathHelper; 30 import org.eclipse.pde.internal.core.PDECore; 31 import org.eclipse.pde.internal.core.TargetPlatformHelper; 32 import org.eclipse.pde.internal.core.util.CoreUtility; 33 import org.eclipse.pde.internal.core.util.VersionUtil; 34 import org.eclipse.pde.internal.ui.PDEPlugin; 35 import org.eclipse.pde.internal.ui.PDEUIMessages; 36 import org.eclipse.pde.internal.ui.launcher.LaunchArgumentsHelper; 37 import org.eclipse.pde.internal.ui.launcher.LaunchConfigurationHelper; 38 import org.eclipse.pde.internal.ui.launcher.LaunchPluginValidator; 39 import org.eclipse.pde.internal.ui.launcher.LauncherUtils; 40 import org.osgi.framework.Version; 41 42 49 public class EclipseApplicationLaunchConfiguration extends AbstractPDELaunchConfiguration { 50 51 55 public String [] getProgramArguments(ILaunchConfiguration configuration) throws CoreException { 56 ArrayList programArgs = new ArrayList (); 57 58 if (configuration.getAttribute(IPDELauncherConstants.USE_PRODUCT, false)) { 60 programArgs.add("-product"); programArgs.add(configuration.getAttribute(IPDELauncherConstants.PRODUCT, "")); } else { 63 programArgs.add("-application"); programArgs.add(configuration.getAttribute(IPDELauncherConstants.APPLICATION, TargetPlatform.getDefaultApplication())); 66 } 67 68 String targetWorkspace = LaunchArgumentsHelper.getWorkspaceLocation(configuration); 70 if (targetWorkspace.length() > 0) { 71 programArgs.add("-data"); programArgs.add(targetWorkspace); 73 } 74 75 boolean showSplash = true; 76 Map pluginMap = LaunchPluginValidator.getPluginsToRun(configuration); 77 if (configuration.getAttribute(IPDELauncherConstants.USEFEATURES, false)) { 78 validateFeatures(); 79 IPath installPath = PDEPlugin.getWorkspace().getRoot().getLocation(); 80 programArgs.add("-install"); programArgs.add("file:" + installPath.removeLastSegments(1).addTrailingSeparator().toString()); if (!configuration.getAttribute(IPDELauncherConstants.CONFIG_USE_DEFAULT_AREA, true)) { 83 programArgs.add("-configuration"); programArgs.add("file:" + new Path(getConfigDir(configuration).getPath()).addTrailingSeparator().toString()); } 86 programArgs.add("-update"); programArgs.add("-dev"); programArgs.add(ClasspathHelper.getDevEntriesProperties(getConfigDir(configuration).toString() + "/dev.properties", true)); } else { 91 String productID = LaunchConfigurationHelper.getProductID(configuration); 92 Properties prop = LaunchConfigurationHelper.createConfigIniFile(configuration, 93 productID, pluginMap, getConfigDir(configuration)); 94 showSplash = prop.containsKey("osgi.splashPath") || prop.containsKey("splashLocation"); String brandingId = LaunchConfigurationHelper.getContributingPlugin(productID); 96 TargetPlatform.createPlatformConfiguration( 97 getConfigDir(configuration), 98 (IPluginModelBase[])pluginMap.values().toArray(new IPluginModelBase[pluginMap.size()]), 99 brandingId != null ? (IPluginModelBase) pluginMap.get(brandingId) : null); 100 TargetPlatformHelper.checkPluginPropertiesConsistency(pluginMap, getConfigDir(configuration)); 101 programArgs.add("-configuration"); programArgs.add("file:" + new Path(getConfigDir(configuration).getPath()).addTrailingSeparator().toString()); 104 programArgs.add("-dev"); programArgs.add(ClasspathHelper.getDevEntriesProperties(getConfigDir(configuration).toString() + "/dev.properties", pluginMap)); } 108 IPluginModelBase base = (IPluginModelBase)pluginMap.get(PDECore.PLUGIN_ID); 111 if (base != null && VersionUtil.compareMacroMinorMicro(base.getBundleDescription().getVersion(), new Version("3.3.1")) < 0) programArgs.add("-pdelaunch"); 114 String [] args = super.getProgramArguments(configuration); 115 for (int i = 0; i < args.length; i++) { 116 programArgs.add(args[i]); 117 } 118 119 if (!programArgs.contains("-nosplash") && showSplash) { if (TargetPlatformHelper.getTargetVersion() >= 3.1) { 121 programArgs.add(0, "-launcher"); 123 IPath path = null; 124 if (TargetPlatform.getOS().equals("macosx") ) { path = new Path(TargetPlatform.getLocation()).append("Eclipse.app/Contents/Resources/Splash.app/Contents/MacOS/eclipse"); } else { 127 path = new Path(TargetPlatform.getLocation()).append("eclipse"); } 129 130 programArgs.add(1, path.toOSString()); programArgs.add(2, "-name"); programArgs.add(3, "Eclipse"); programArgs.add(4, "-showsplash"); programArgs.add(5, "600"); } else { 136 programArgs.add(0, "-showsplash"); programArgs.add(1, computeShowsplashArgument()); 138 } 139 } 140 return (String [])programArgs.toArray(new String [programArgs.size()]); 141 } 142 143 private void validateFeatures() throws CoreException { 144 IPath installPath = PDEPlugin.getWorkspace().getRoot().getLocation(); 145 String lastSegment = installPath.lastSegment(); 146 boolean badStructure = lastSegment == null; 147 if (!badStructure) { 148 IPath featuresPath = installPath.removeLastSegments(1).append("features"); badStructure = !lastSegment.equalsIgnoreCase("plugins") || !featuresPath.toFile().exists(); 151 } 152 if (badStructure) { 153 throw new CoreException(LauncherUtils.createErrorStatus(PDEUIMessages.WorkbenchLauncherConfigurationDelegate_badFeatureSetup)); 154 } 155 ensureProductFilesExist(getProductPath()); 157 } 158 159 private IPath getProductPath() { 160 return PDEPlugin.getWorkspace().getRoot().getLocation().removeLastSegments(1); 161 } 162 163 private String computeShowsplashArgument() { 164 IPath eclipseHome = new Path(TargetPlatform.getLocation()); 165 IPath fullPath = eclipseHome.append("eclipse"); return fullPath.toOSString() + " -showsplash 600"; } 168 169 private void ensureProductFilesExist(IPath productArea) { 170 File productDir = productArea.toFile(); 171 File marker = new File (productDir, ".eclipseproduct"); IPath eclipsePath = new Path(TargetPlatform.getLocation()); 173 if (!marker.exists()) 174 CoreUtility.copyFile(eclipsePath, ".eclipseproduct", marker); 176 File configDir = new File (productDir, "configuration"); if (!configDir.exists()) 178 configDir.mkdirs(); 179 File ini = new File (configDir, "config.ini"); if (!ini.exists()) 181 CoreUtility.copyFile(eclipsePath.append("configuration"), "config.ini", ini); } 183 184 188 protected File getConfigDir(ILaunchConfiguration config) { 189 if (fConfigDir == null) { 190 try { 191 if (config.getAttribute(IPDELauncherConstants.USEFEATURES, false) 192 && config.getAttribute(IPDELauncherConstants.CONFIG_USE_DEFAULT_AREA, true)) { 193 String root = getProductPath().toString(); 194 root += "/configuration"; fConfigDir = new File (root); 196 if (!fConfigDir.exists()) 197 fConfigDir.mkdirs(); 198 } else { 199 fConfigDir = LaunchConfigurationHelper.getConfigurationArea(config); 200 } 201 } catch (CoreException e) { 202 fConfigDir = LaunchConfigurationHelper.getConfigurationArea(config); 203 } 204 } 205 return fConfigDir; 206 } 207 208 220 protected void clear(ILaunchConfiguration configuration, IProgressMonitor monitor) throws CoreException { 221 String workspace = LaunchArgumentsHelper.getWorkspaceLocation(configuration); 222 if (!LauncherUtils.clearWorkspace(configuration, workspace, monitor)) 224 throw new CoreException(Status.CANCEL_STATUS); 225 226 if (configuration.getAttribute(IPDELauncherConstants.CONFIG_CLEAR_AREA, false)) 228 CoreUtility.deleteContent(getConfigDir(configuration)); 229 } 230 231 234 protected void preLaunchCheck(ILaunchConfiguration configuration, 235 ILaunch launch, IProgressMonitor monitor) throws CoreException { 236 validateConfigIni(configuration); 237 super.preLaunchCheck(configuration, launch, monitor); 238 } 239 240 private void validateConfigIni(ILaunchConfiguration configuration) throws CoreException { 241 if (!configuration.getAttribute(IPDELauncherConstants.CONFIG_GENERATE_DEFAULT, true)) { 242 String templateLoc = configuration.getAttribute(IPDELauncherConstants.CONFIG_TEMPLATE_LOCATION, ""); IStringVariableManager mgr = VariablesPlugin.getDefault().getStringVariableManager(); 244 templateLoc = mgr.performStringSubstitution(templateLoc); 245 246 File templateFile = new File (templateLoc); 247 if (!templateFile.exists()) { 248 if (!LauncherUtils.generateConfigIni()) 249 throw new CoreException(Status.CANCEL_STATUS); 250 } 253 } 254 } 255 256 259 public String [] getVMArguments(ILaunchConfiguration configuration) 260 throws CoreException { 261 String [] vmArgs = super.getVMArguments(configuration); 262 IPluginModelBase base = (IPluginModelBase)LaunchPluginValidator.getPluginsToRun(configuration).get(PDECore.PLUGIN_ID); 263 if (base != null && VersionUtil.compareMacroMinorMicro(base.getBundleDescription().getVersion(), new Version("3.3.1")) >= 0) { String [] result = new String [vmArgs.length + 1]; 267 System.arraycopy(vmArgs, 0, result, 0, vmArgs.length); 268 result[vmArgs.length] = "-Declipse.pde.launch=true"; return result; 270 } 271 return vmArgs; 272 } 273 274 } 275 | Popular Tags |