Java Code Examples for org.eclipse.debug.core.ILaunchConfiguration#getWorkingCopy()

The following examples show how to use org.eclipse.debug.core.ILaunchConfiguration#getWorkingCopy() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GhidraLaunchTabGroup.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the {@link CommonTab} to use, with the new launch configuration added to the favorites.
 * 
 * @return The {@link CommonTab} to use, with the new launch configuration added to the 
 *   favorites.
 */
private CommonTab getCommonTab() {
	return new CommonTab() {
		@Override
		public void initializeFrom(ILaunchConfiguration config) {
			try {
				ILaunchConfigurationWorkingCopy wc = config.getWorkingCopy();
				GhidraLaunchUtils.setFavorites(wc);
				super.initializeFrom(wc.doSave());
			}
			catch (CoreException e) {
				EclipseMessageUtils.error("Failed to initialize the common tab.", e);
			}
		}
	};
}
 
Example 2
Source File: HybridProjectLaunchShortcut.java    From thym with Eclipse Public License 1.0 6 votes vote down vote up
private void launch(IProject project) {
	try {
		HybridProject hp = HybridProject.getHybridProject(project);
		if(!validateBuildToolsReady() 
				|| !shouldProceedWithLaunch(hp)
				|| !RequirementsUtility.checkCordovaRequirements() ){
			return;
		}
		ILaunchConfiguration launchConfig = findOrCreateLaunchConfiguration(project);
		ILaunchConfigurationWorkingCopy wc = launchConfig.getWorkingCopy();
		updateLaunchConfiguration(wc);
		launchConfig = wc.doSave();
		DebugUITools.launch(launchConfig, "run");
		
	} catch (CoreException e) {
		if (e.getCause() instanceof IOException) {
			Status status = new Status(IStatus.ERROR, HybridUI.PLUGIN_ID,
					"Unable to complete the build for target plarform",
					e.getCause());
			StatusManager.handle(status);
		}else{
			StatusManager.handle(e);
		}
	}
}
 
Example 3
Source File: CordovaCLI.java    From thym with Eclipse Public License 1.0 6 votes vote down vote up
protected ILaunchConfiguration getLaunchConfiguration(String label){
	ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
	ILaunchConfigurationType type = manager.getLaunchConfigurationType(IExternalToolConstants.ID_PROGRAM_LAUNCH_CONFIGURATION_TYPE);
	try {
		ILaunchConfiguration cfg = type.newInstance(null, "cordova");
		ILaunchConfigurationWorkingCopy wc = cfg.getWorkingCopy();
		wc.setAttribute(IProcess.ATTR_PROCESS_LABEL, label);
		if(additionalEnvProps != null && !additionalEnvProps.isEmpty()){
			wc.setAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES,additionalEnvProps);
		}
		cfg = wc.doSave();
		return cfg;
	} catch (CoreException e) {
		e.printStackTrace();
	}
	return null;
}
 
Example 4
Source File: TestabilityCompilationParticipant.java    From testability-explorer with Apache License 2.0 6 votes vote down vote up
@Override
public void buildFinished(IJavaProject project) {
  super.buildFinished(project);
  ILaunchConfiguration launchConfiguration =
      configurationHelper.getLaunchConfiguration(project.getElementName());
  if (launchConfiguration != null) {
    try {
      ILaunchConfigurationWorkingCopy workingCopy = launchConfiguration.getWorkingCopy();
      workingCopy.setAttribute(
          TestabilityConstants.CONFIGURATION_ATTR_RUNNING_IN_COMPILATION_MODE, true);
      ILaunch launch = workingCopy.launch(TestabilityConstants.TESTABILITY_MODE, null);
    } catch (CoreException e) {
      logger.logException(e);
    }
  }
}
 
Example 5
Source File: BOSWebServerManager.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
protected void createLaunchConfiguration(final IServer server, final IProgressMonitor monitor)
        throws CoreException {
    ILaunchConfiguration conf = server.getLaunchConfiguration(false, Repository.NULL_PROGRESS_MONITOR);
    if (conf == null) {
        conf = server.getLaunchConfiguration(true,
                Repository.NULL_PROGRESS_MONITOR);
    }
    ILaunchConfigurationWorkingCopy workingCopy = conf.getWorkingCopy();
    final String args = workingCopy.getAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, "");
    if (!args.contains(tomcatInstanceLocation)) {
        conf = server.getLaunchConfiguration(true,
                Repository.NULL_PROGRESS_MONITOR);
        workingCopy = conf.getWorkingCopy();
    }
    configureLaunchConfiguration(workingCopy);
}
 
Example 6
Source File: GwtSuperDevModeCodeServerLaunchUtil.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Add or modify the launcherDir program argument in the launch config.
 */
private static ILaunchConfiguration addOrModifyLauncherArgs(ILaunchConfiguration config, String launcherDir,
    String launcherId) throws CoreException {
  ILaunchConfigurationWorkingCopy launchConfigWc = config.getWorkingCopy();

  if (launcherDir != null && launcherDir.trim().isEmpty()) {
    launcherDir = null;
  }

  // Update the launcherDir argument
  GWTLaunchConfigurationWorkingCopy.setCodeServerLauncherDir(launchConfigWc, launcherDir);
  LaunchConfigurationProcessorUtilities.updateViaProcessor(
      new SuperDevModeCodeServerLauncherDirArgumentProcessor(), launchConfigWc);

  // Update the launcherId
  if (launcherId != null) {
    launchConfigWc.setAttribute(GWTLaunchConstants.SUPERDEVMODE_LAUNCH_ID, launcherId);
  }

  config = launchConfigWc.doSave();

  return config;
}
 
Example 7
Source File: GhidraLaunchTabGroup.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the {@link JavaMainTab} to use, with Ghidra's main method pre-configured in.
 * 
 * @return The {@link JavaMainTab} to use, with Ghidra's main method pre-configured in.
 */
private JavaMainTab getJavaMainTab() {
	return new JavaMainTab() {
		@Override
		public void initializeFrom(ILaunchConfiguration config) {
			try {
				ILaunchConfigurationWorkingCopy wc = config.getWorkingCopy();
				GhidraLaunchUtils.setMainTypeName(wc);
				super.initializeFrom(wc.doSave());
			}
			catch (CoreException e) {
				EclipseMessageUtils.error("Failed to initialize the java main tab.", e);
			}
		}
	};
}
 
Example 8
Source File: PythonRunner.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * The debug plugin needs to be notified about our process.
 * It'll then display the appropriate UI.
 */
private static IProcess registerWithDebugPluginForProcessType(String label, ILaunch launch, Process p,
        Map<String, String> processAttributes, PythonRunnerConfig config) {
    processAttributes.put(IProcess.ATTR_PROCESS_TYPE, config.getProcessType());
    processAttributes.put(IProcess.ATTR_PROCESS_LABEL, label);
    processAttributes.put(Constants.PYDEV_CONFIG_RUN, config.run);
    processAttributes.put(IMiscConstants.PYDEV_ADD_RELAUNCH_IPROCESS_ATTR,
            IMiscConstants.PYDEV_ADD_RELAUNCH_IPROCESS_ATTR_TRUE);
    processAttributes.put(DebugPlugin.ATTR_CAPTURE_OUTPUT, "true");

    ILaunchConfiguration launchConfiguration = launch.getLaunchConfiguration();
    boolean found = false;
    try {
        String attribute = launchConfiguration.getAttribute(DebugPlugin.ATTR_PROCESS_FACTORY_ID, (String) null);
        found = PyProcessFactory.PROCESS_FACTORY_ID.equals(attribute);
    } catch (CoreException e1) {
        Log.log(e1);
    }
    if (!found) {
        try {
            ILaunchConfigurationWorkingCopy workingCopy = launchConfiguration.getWorkingCopy();
            workingCopy.setAttribute(DebugPlugin.ATTR_PROCESS_FACTORY_ID, PyProcessFactory.PROCESS_FACTORY_ID);
            workingCopy.doSave();
        } catch (CoreException e) {
            Log.log(e);
        }
    }

    return DebugPlugin.newProcess(launch, p, label, processAttributes);
}
 
Example 9
Source File: WebAppLaunchShortcut.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Turn on GWT Super Dev Mode in the case that dev mode was run first. This depends on which shortcut was used.
 *
 * @param isGwtSuperDevModeEnabled
 */
private ILaunchConfiguration turnOnOrOffSuperDevMode(ILaunchConfiguration config, boolean isGwtSuperDevModeEnabled)
    throws CoreException {
  ILaunchConfigurationWorkingCopy workingCopy = config.getWorkingCopy();

  GWTLaunchConfigurationWorkingCopy.setSuperDevModeEnabled(workingCopy, isGwtSuperDevModeEnabled);
  SuperDevModeArgumentProcessor sdmArgsProcessor = new SuperDevModeArgumentProcessor();
  LaunchConfigurationProcessorUtilities.updateViaProcessor(sdmArgsProcessor, workingCopy);
  workingCopy.doSave();

  return workingCopy;
}
 
Example 10
Source File: WebAppLaunchDelegate.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * In the case of a project with an unmanaged WAR directory or when the project is not a web app but the main type
 * takes a WAR argument, we need to check at launch-time whether the launch config has a runtime WAR. If it does not,
 * then we ask the user for one and insert it into the launch config.
 *
 * @param configuration
 *          the launch configuration that may be written to
 * @return true to continue the launch, false to abort silently
 * @throws CoreException
 */
private boolean ensureWarArgumentExistenceInCertainCases(ILaunchConfiguration configuration) throws CoreException {
  IJavaProject javaProject = getJavaProject(configuration);
  if (javaProject != null) {
    IProject project = javaProject.getProject();
    boolean isWebApp = WebAppUtilities.isWebApp(project);
    if ((isWebApp && !WebAppUtilities.hasManagedWarOut(project))
        || (!isWebApp && WarArgumentProcessor.doesMainTypeTakeWarArgument(configuration))) {

      List<String> args = LaunchConfigurationProcessorUtilities.parseProgramArgs(configuration);
      WarParser parser = WarArgumentProcessor.WarParser.parse(args, javaProject);

      if (!(parser.isSpecifiedWithWarArg || parser.isWarDirValid)) {
        // The project's output WAR dir is unknown, so ask the user
        IPath warDir = WebAppUtilities.getWarOutLocationOrPrompt(project);
        if (warDir == null) {
          return false;
        }

        // The processor will update to the proper argument style
        // for the
        // current project nature(s)
        WarArgumentProcessor warArgProcessor = new WarArgumentProcessor();
        warArgProcessor.setWarDirFromLaunchConfigCreation(warDir.toOSString());

        ILaunchConfigurationWorkingCopy wc = configuration.getWorkingCopy();
        LaunchConfigurationProcessorUtilities.updateViaProcessor(warArgProcessor, wc);
        wc.doSave();
      }
    }
  }

  return true;
}
 
Example 11
Source File: WebAppLaunchDelegate.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @return Returns {@code}false if unsuccessful in adding the VM arguments and the launch should be cancelled.
 */
@Deprecated
private boolean addVmArgs(ILaunchConfiguration configuration) throws CoreException {
  IProject project = getJavaProject(configuration).getProject();

  ILaunchConfigurationWorkingCopy workingCopy = configuration.getWorkingCopy();
  String vmArgs = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, "");

  return true;
}
 
Example 12
Source File: GwtWtpPlugin.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private String setLauncherIdToWtpRunTimeLaunchConfig(ILaunchConfiguration launchConfig) {
  String launcherId = getLaunchId();

  logMessage("setLauncherIdToWtpRunTimeLaunchConfig: Adding server launcherId id=" + getLaunchId());

  try {
    ILaunchConfigurationWorkingCopy launchConfigWorkingCopy = launchConfig.getWorkingCopy();
    launchConfigWorkingCopy.setAttribute(GWTLaunchConstants.SUPERDEVMODE_LAUNCH_ID, launcherId);
    launchConfigWorkingCopy.doSave();
  } catch (CoreException e) {
    logError("posiblyLaunchGwtSuperDevModeCodeServer: Couldn't add server Launcher Id attribute.", e);
  }

  return launcherId;
}
 
Example 13
Source File: LaunchConfigCleanerPDETest.java    From eclipse-extras with Eclipse Public License 1.0 5 votes vote down vote up
private ILaunchConfiguration storeLaunchConfigInWorkspace( ILaunchConfiguration launchConfig )
  throws CoreException
{
  ILaunchConfigurationWorkingCopy workingCopy = launchConfig.getWorkingCopy();
  workingCopy.setContainer( projectHelper.getProject() );
  return workingCopy.doSave();
}
 
Example 14
Source File: TypeScriptCompilerLaunchHelper.java    From typescript.java with MIT License 5 votes vote down vote up
public static void launch(IFile tsconfigFile, String mode) {
	ILaunchConfigurationType tscLaunchConfigurationType = DebugPlugin.getDefault().getLaunchManager()
			.getLaunchConfigurationType(TypeScriptCompilerLaunchConstants.LAUNCH_CONFIGURATION_ID);
	try {
		// Check if configuration already exists
		ILaunchConfiguration[] configurations = DebugPlugin.getDefault().getLaunchManager()
				.getLaunchConfigurations(tscLaunchConfigurationType);

		ILaunchConfiguration existingConfiguraion = chooseLaunchConfiguration(configurations, tsconfigFile);

		if (existingConfiguraion != null) {
			ILaunchConfigurationWorkingCopy wc = existingConfiguraion.getWorkingCopy();
			existingConfiguraion = wc.doSave();
			DebugUITools.launch(existingConfiguraion, mode);
			// Creating Launch Configuration from scratch
		} else {
			IProject project = tsconfigFile.getProject();
			ILaunchConfigurationWorkingCopy newConfiguration = createEmptyLaunchConfiguration(
					project.getName() + " [" + tsconfigFile.getProjectRelativePath().toString() + "]"); //$NON-NLS-1$ //$NON-NLS-2$
			newConfiguration.setAttribute(TypeScriptCompilerLaunchConstants.BUILD_PATH, getBuildPath(tsconfigFile));
			newConfiguration.doSave();
			DebugUITools.launch(newConfiguration, mode);
		}

	} catch (CoreException e) {
		TypeScriptCorePlugin.logError(e, e.getMessage());
	}

}
 
Example 15
Source File: PythonRunnerConfigTestWorkbench.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
public void testOverridingResourceLocation() throws Exception {
    ILaunchConfiguration config = new JythonLaunchShortcut().createDefaultLaunchConfiguration(FileOrResource
            .createArray(new IResource[] { mod1 }));
    ILaunchConfigurationWorkingCopy configCopy = config.getWorkingCopy();
    String customResourcePath = "/foo/bar/acme.py";
    configCopy.setAttribute(Constants.ATTR_ALTERNATE_LOCATION, customResourcePath);
    PythonRunnerConfig runnerConfig = new PythonRunnerConfig(configCopy, ILaunchManager.RUN_MODE,
            PythonRunnerConfig.RUN_JYTHON);
    assertEquals(Path.fromOSString(customResourcePath), runnerConfig.resource[0]);
}
 
Example 16
Source File: PythonRunnerConfigTestWorkbench.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
public void testPythonCommandLine() throws Exception {
    PythonNature nature = PythonNature.getPythonNature(mod1);

    // Create a temporary variable for testing
    IStringVariableManager variableManager = VariablesPlugin.getDefault().getStringVariableManager();
    IValueVariable myCustomVariable = variableManager.newValueVariable("pydev_python_runner_config_test_var", "",
            true, "my_custom_value");
    variableManager.addVariables(new IValueVariable[] { myCustomVariable });

    try {
        IInterpreterManager manager = InterpreterManagersAPI.getPythonInterpreterManager(true);
        InterpreterInfo info = (InterpreterInfo) manager.getDefaultInterpreterInfo(false);
        info.setEnvVariables(new String[] { "MY_CUSTOM_VAR_FOR_TEST=FOO", "MY_CUSTOM_VAR_FOR_TEST2=FOO2",
                "MY_CUSTOM_VAR_WITH_VAR=${pydev_python_runner_config_test_var}" });

        // Make sure variable hasn't been expanded too early
        assertTrue(arrayContains(info.getEnvVariables(),
                "MY_CUSTOM_VAR_WITH_VAR=${pydev_python_runner_config_test_var}"));

        PythonRunnerConfig runnerConfig = createConfig();
        assertTrue(arrayContains(runnerConfig.envp, "MY_CUSTOM_VAR_FOR_TEST=FOO"));
        assertTrue(arrayContains(runnerConfig.envp, "MY_CUSTOM_VAR_FOR_TEST2=FOO2"));
        assertTrue(arrayContains(runnerConfig.envp, "MY_CUSTOM_VAR_WITH_VAR=my_custom_value"));

        String[] argv = runnerConfig.getCommandLine(false);
        assertFalse(arrayContains(argv, PythonRunnerConfig.getRunFilesScript()));
        assertTrue(arrayContains(argv, mod1.getLocation().toOSString()));

        nature.setVersion(IPythonNature.Versions.PYTHON_VERSION_LATEST, IPythonNature.DEFAULT_INTERPRETER);
        assertEquals(manager.getDefaultInterpreterInfo(false).getExecutableOrJar(), nature.getProjectInterpreter()
                .getExecutableOrJar());
        runnerConfig = createConfig();
        argv = runnerConfig.getCommandLine(false);
        assertEquals(manager.getDefaultInterpreterInfo(false).getExecutableOrJar(), argv[0]);

        IInterpreterManager interpreterManager = nature.getRelatedInterpreterManager();

        InterpreterInfo info2 = new InterpreterInfo(IPythonNature.PYTHON_VERSION_2_6, "c:\\interpreter\\py25.exe",
                new ArrayList<String>());
        interpreterManager.setInfos(new IInterpreterInfo[] { info, info2 }, null, null);

        nature.setVersion(IPythonNature.Versions.PYTHON_VERSION_LATEST, "c:\\interpreter\\py25.exe");
        assertEquals("c:\\interpreter\\py25.exe", nature.getProjectInterpreter().getExecutableOrJar());
        runnerConfig = createConfig();
        argv = runnerConfig.getCommandLine(false);
        assertEquals("c:\\interpreter\\py25.exe", argv[0]);
        nature.setVersion(IPythonNature.Versions.PYTHON_VERSION_LATEST, IPythonNature.DEFAULT_INTERPRETER);

        ILaunchConfiguration config;
        config = new LaunchShortcut().createDefaultLaunchConfiguration(FileOrResource
                .createArray(new IResource[] { mod1 }));
        ILaunchConfigurationWorkingCopy workingCopy = config.getWorkingCopy();
        HashMap<String, String> map = new HashMap<String, String>();
        map.put("VAR_SPECIFIED_IN_LAUNCH", "BAR");
        map.put("MY_CUSTOM_VAR_FOR_TEST2", "BAR2"); //The one in the launch configuration always has preference.
        workingCopy.setAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, map);
        config = workingCopy.doSave();

        runnerConfig = new PythonRunnerConfig(config, ILaunchManager.RUN_MODE, PythonRunnerConfig.RUN_REGULAR);
        assertTrue(arrayContains(runnerConfig.envp, "VAR_SPECIFIED_IN_LAUNCH=BAR"));
        assertTrue(arrayContains(runnerConfig.envp, "MY_CUSTOM_VAR_FOR_TEST=FOO"));
        assertTrue(arrayContains(runnerConfig.envp, "MY_CUSTOM_VAR_FOR_TEST2=BAR2"));
        assertTrue(arrayContains(runnerConfig.envp, "MY_CUSTOM_VAR_WITH_VAR=my_custom_value"));
    } catch (Throwable e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    } finally {
        //restore the default!
        nature.setVersion(IPythonNature.Versions.PYTHON_VERSION_LATEST, IPythonNature.DEFAULT_INTERPRETER);
        variableManager.removeVariables(new IValueVariable[] { myCustomVariable });
    }
}
 
Example 17
Source File: DefaultWorkingDirectoryMigrator.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 4 votes vote down vote up
public void migrate(IProject project) {
  try {
    List<ILaunchConfiguration> configs = LaunchConfigurationUtilities.getLaunchConfigurations(project);
    for (ILaunchConfiguration config : configs) {

      // This it not a web app launch config
      if (!WebAppLaunchConfiguration.TYPE_ID.equals(config.getType().getIdentifier())) {
        continue;
      }

      String workingDir = config.getAttribute(
          IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY,
          (String) null);
      // This is already set to the default working dir
      if (workingDir == null) {
        continue;
      }

      IJavaProject javaProject = LaunchConfigurationUtilities.getJavaProject(config);
      if (javaProject == null) {
        continue;
      }

      String warDir = WarArgumentProcessor.WarParser.parse(
          LaunchConfigurationProcessorUtilities.parseProgramArgs(config),
          javaProject).unverifiedWarDir;
      if (warDir == null) {
        continue;
      }

      IPath warDirPath = new Path(warDir);
      IPath workingDirPath = new Path(workingDir).makeRelative();
      // The WAR dir is absolute, but working dir can be workspace-relative.
      // We force the workingDirPath to be relative because the
      // warDirPath.removeFirstSegments returns a relative path.
      int numSegmentsToRemove = warDirPath.segmentCount()
          - workingDirPath.segmentCount();
      if (numSegmentsToRemove < 0
          || !warDirPath.removeFirstSegments(numSegmentsToRemove).equals(
          workingDirPath)) {
        continue;
      }

      // Working dir matches the WAR dir, set to default working dir
      ILaunchConfigurationWorkingCopy workingCopy = config.getWorkingCopy();
      workingCopy.setAttribute(
          IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY,
          (String) null);
      workingCopy.doSave();
    }

  } catch (CoreException e) {
    CorePluginLog.logWarning(e, "Could not migrate " + project.getName()
        + " to use the default working directory");
  }
}
 
Example 18
Source File: LaunchConfigurationUtils.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
public static void modifyLaunchConfiguration(ILaunchConfiguration config,
		IClosure<ILaunchConfigurationWorkingCopy> configWorkingCopyAccessor) throws CoreException {
	ILaunchConfigurationWorkingCopy workingCopy = config.getWorkingCopy();
	configWorkingCopyAccessor.execute(workingCopy);
	workingCopy.doSave();
}
 
Example 19
Source File: ViewerConfigDialog.java    From texlipse with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Check that the config is valid.
 * Close the dialog is the config is valid.
 */
protected void okPressed() {
    
    if (!validateFields())
        return;
    
    String name = nameField.getText();
    registry.setActiveViewer(nameField.getText());
    registry.setCommand(fileField.getText());
    registry.setArguments(argsField.getText());        
    registry.setDDEViewCommand(ddeViewGroup.command.getText());
    registry.setDDEViewServer(ddeViewGroup.server.getText());
    registry.setDDEViewTopic(ddeViewGroup.topic.getText());
    registry.setDDECloseCommand(ddeCloseGroup.command.getText());
    registry.setDDECloseServer(ddeCloseGroup.server.getText());
    registry.setDDECloseTopic(ddeCloseGroup.topic.getText());
    registry.setFormat(formatChooser.getItem(formatChooser.getSelectionIndex()));
    registry.setInverse(inverseSearchValues[inverseChooser.getSelectionIndex()]);
    registry.setForward(forwardChoice.getSelection());
    
    // Ask user if launch configs should be updated
    try {
        ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
        if (manager != null) {
            ILaunchConfigurationType type = manager.getLaunchConfigurationType(
                TexLaunchConfigurationDelegate.CONFIGURATION_ID);
            if (type != null) {
                ILaunchConfiguration[] configs = manager.getLaunchConfigurations(type);
                if (configs != null) {
                    // Check all configurations
                    int returnCode = 0;
                    MessageDialogWithToggle md = null;
                    for (int i = 0; i < configs.length ; i++) {
                        ILaunchConfiguration c = configs[i];
                        if (c.getType().getIdentifier().equals(TexLaunchConfigurationDelegate.CONFIGURATION_ID)) {
                            if (c.getAttribute("viewerCurrent", "").equals(name)) {
                                // We've found a config which was based on this viewer 
                                if (0 == returnCode) {
                                    String message = MessageFormat.format(
                                        TexlipsePlugin.getResourceString("preferenceViewerUpdateConfigurationQuestion"),
                                        new Object[] { c.getName() });
                                    md = MessageDialogWithToggle.openYesNoCancelQuestion(getShell(),
                                        TexlipsePlugin.getResourceString("preferenceViewerUpdateConfigurationTitle"), message,
                                        TexlipsePlugin.getResourceString("preferenceViewerUpdateConfigurationAlwaysApply"),
                                        false, null, null);
                                    
                                    if (md.getReturnCode() == MessageDialogWithToggle.CANCEL)
                                        return;
                                    
                                    returnCode = md.getReturnCode();
                                } 
                                    
                                // If answer was yes, update each config with latest values from registry
                                if (returnCode == IDialogConstants.YES_ID) {
                                    ILaunchConfigurationWorkingCopy workingCopy = c.getWorkingCopy();
                                    workingCopy.setAttributes(registry.asMap());

                                    // We need to set at least one attribute using a one-shot setter method
                                    // because the method setAttributes does not mark the config as dirty. 
                                    // A dirty config is required for a doSave to do anything useful. 
                                    workingCopy.setAttribute("viewerCurrent", name);
                                    workingCopy.doSave();
                                }
                                
                                // Reset return-code if we should be asked again
                                if (!md.getToggleState()) {
                                    returnCode = 0;
                                }
                            }
                        }
                    }
                }
            }
        }
    } catch (CoreException e) {
        // Something wrong with the config, or could not read attributes, so swallow and skip
    }

    setReturnCode(OK);
    close();
}
 
Example 20
Source File: AbstractLangDebugLaunchConfigurationDelegate.java    From goclipse with Eclipse Public License 1.0 3 votes vote down vote up
@Override
public ILaunch getLaunchForDebugMode(ILaunchConfiguration configuration, String mode) throws CoreException {
	
	ILaunchConfigurationWorkingCopy workingCopy = configuration.getWorkingCopy();
	
	setAttributes(workingCopy);
	
	workingCopy.doSave();
	
	return gdbLaunchDelegate.getLaunch(configuration, mode);
}