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

The following examples show how to use org.eclipse.debug.core.ILaunchConfiguration#launch() . 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: KubeUtil.java    From codewind-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Starts a separate port forward launch
 */
public static PortForwardInfo launchPortForward(CodewindApplication app, int localPort, int port) throws Exception {
	// Check the app (throws an exception if there is a problem)
	checkApp(app);

	// Get the command
	List<String> commandList = getPortForwardCommand(app, localPort, port);
	String title = NLS.bind(Messages.PortForwardTitle, localPort + ":" + port);

	ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
	ILaunchConfigurationType launchConfigurationType = launchManager.getLaunchConfigurationType(UtilityLaunchConfigDelegate.LAUNCH_CONFIG_ID);
	ILaunchConfigurationWorkingCopy workingCopy = launchConfigurationType.newInstance((IContainer) null, app.name);
	workingCopy.setAttribute(CodewindLaunchConfigDelegate.CONNECTION_ID_ATTR, app.connection.getConid());
	workingCopy.setAttribute(CodewindLaunchConfigDelegate.PROJECT_ID_ATTR, app.projectID);
	workingCopy.setAttribute(UtilityLaunchConfigDelegate.TITLE_ATTR, title);
	workingCopy.setAttribute(UtilityLaunchConfigDelegate.COMMAND_ATTR, commandList);
	CodewindLaunchConfigDelegate.setConfigAttributes(workingCopy, app);
	ILaunchConfiguration launchConfig = workingCopy.doSave();
	ILaunch launch = launchConfig.launch(ILaunchManager.RUN_MODE, new NullProgressMonitor());
	return new PortForwardInfo(localPort, port, launch);
}
 
Example 2
Source File: OtherUtil.java    From codewind-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
public static ILaunch startDiagnostics(String connectionName, String conid, boolean includeEclipseWorkspace, boolean includeProjectInfo, IProgressMonitor monitor) throws IOException, CoreException {
	List<String> options = new ArrayList<String>();
	options.add(CLIUtil.CON_ID_OPTION);
	options.add(conid);
	if (includeEclipseWorkspace) {
		options.add(ECLIPSE_WORKSPACE_OPTION);
		options.add(ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString());
	}
	if (includeProjectInfo) {
		options.add(PROJECTS_OPTION);
	}
	List<String> command = CLIUtil.getCWCTLCommandList(null, DIAGNOSTICS_COLLECT_CMD, options.toArray(new String[options.size()]), null);
	
	ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
	ILaunchConfigurationType launchConfigurationType = launchManager.getLaunchConfigurationType(UtilityLaunchConfigDelegate.LAUNCH_CONFIG_ID);
	ILaunchConfigurationWorkingCopy workingCopy = launchConfigurationType.newInstance((IContainer) null, connectionName);
	workingCopy.setAttribute(UtilityLaunchConfigDelegate.TITLE_ATTR, Messages.UtilGenDiagnosticsTitle);
	workingCopy.setAttribute(UtilityLaunchConfigDelegate.COMMAND_ATTR, command);
	ILaunchConfiguration launchConfig = workingCopy.doSave();
	return launchConfig.launch(ILaunchManager.RUN_MODE, monitor);
}
 
Example 3
Source File: NodeJSDebugLauncher.java    From codewind-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
private IStatus launchInternalDebugSession(CodewindEclipseApplication app, PortForwardInfo pfInfo, IProgressMonitor monitor) {
	try {
		ILaunchConfigurationWorkingCopy workingCopy = getLaunchConfigType().get().newInstance((IContainer) null, app.name);
		workingCopy.setAttribute(ADDRESS_ATTR, app.getDebugConnectHost());
		workingCopy.setAttribute(PORT_ATTR, app.getDebugConnectPort());
		workingCopy.setAttribute(LOCAL_ROOT_ATTR, app.fullLocalPath.toOSString());
		workingCopy.setAttribute(REMOTE_ROOT_ATTR, app.getContainerAppRoot() == null ? "/app" : app.getContainerAppRoot());
		CodewindLaunchConfigDelegate.setConfigAttributes(workingCopy, app);
		ILaunchConfiguration launchConfig = workingCopy.doSave();
		ILaunch launch = launchConfig.launch(ILaunchManager.DEBUG_MODE, monitor);
		if (pfInfo != null && pfInfo.process != null) {
			Map<String, String> attributes = new HashMap<String, String>();
			attributes.put(IProcess.ATTR_PROCESS_TYPE, "codewind.utility");
			String title = NLS.bind(Messages.PortForwardTitle, pfInfo.localPort + ":" + app.getContainerDebugPort());
			launch.addProcess(new RuntimeProcess(launch, pfInfo.process, title, attributes));
			RemoteLaunchConfigDelegate.addDebugEventListener(launch);
		}
		app.setLaunch(launch);
	} catch (CoreException e) {
		return e.getStatus();
	}
	return Status.OK_STATUS;
}
 
Example 4
Source File: FlexMavenPackagedProjectStagingDelegate.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
@Override
protected IPath getDeployArtifact(IPath safeWorkingDirectory, IProgressMonitor monitor)
    throws CoreException {
  SubMonitor subMonitor = SubMonitor.convert(monitor, 100);

  try {
    ILaunchConfiguration config = createMavenPackagingLaunchConfiguration(project);
    ILaunch launch = config.launch("run", subMonitor.newChild(10));
    if (!waitUntilLaunchTerminates(launch, subMonitor.newChild(90))) {
      throw new OperationCanceledException();
    }
    return getFinalArtifactPath(project);
  } catch (InterruptedException ex) {
    throw new OperationCanceledException();
  }
}
 
Example 5
Source File: LaunchConfigCleanerPDETest.java    From eclipse-extras with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testNoCleanupWhenLaunchConfigRenamed() throws CoreException {
  prepareLaunchPreferences( true, launchConfigRule.getPublicTestLaunchConfigType() );
  launchConfigCleaner.install();
  ILaunchConfiguration launchConfig = launchConfigRule.createPublicLaunchConfig().doSave();

  ILaunch launch = launchConfig.launch( RUN_MODE, null );
  String newName = launchConfigRule.renameLaunchConfig( launchConfig );
  launch.terminate();

  assertThat( getLaunchConfigs() ).extracting( "name" ).contains( newName );
}
 
Example 6
Source File: LaunchTerminatorPDETest.java    From eclipse-extras with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testTerminateLaunchesWithRenamedLaunchConfig() throws CoreException {
  ILaunchConfiguration launchConfig = launchConfigRule.createPublicLaunchConfig().doSave();
  ILaunch launch = launchConfig.launch( RUN_MODE, new NullProgressMonitor() );
  launchConfigRule.renameLaunchConfig( launchConfig );

  new LaunchTerminator( launchConfig ).terminateLaunches();

  assertThat( launch.isTerminated() ).isFalse();
}
 
Example 7
Source File: LaunchTerminatorPDETest.java    From eclipse-extras with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testTerminateLaunchesWithDeletedLaunchConfig() throws CoreException {
  ILaunchConfiguration unrelatedLaunchConfig = launchConfigRule.createPrivateLaunchConfig().doSave();
  ILaunch unrelatedLaunch = unrelatedLaunchConfig.launch( RUN_MODE, new NullProgressMonitor() );
  ILaunchConfiguration launchConfig = launchConfigRule.createPublicLaunchConfig().doSave();
  unrelatedLaunchConfig.delete();

  new LaunchTerminator( launchConfig ).terminateLaunches();

  assertThat( unrelatedLaunch.isTerminated() ).isFalse();
}
 
Example 8
Source File: LaunchTerminatorPDETest.java    From eclipse-extras with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testTerminateLaunchesWithUnrelatedLaunch() throws CoreException {
  ILaunchConfiguration unrelatedLaunchConfig = launchConfigRule.createPrivateLaunchConfig().doSave();
  ILaunch unrelatedLaunch = unrelatedLaunchConfig.launch( RUN_MODE, new NullProgressMonitor() );
  ILaunchConfiguration launchConfig = launchConfigRule.createPublicLaunchConfig().doSave();

  new LaunchTerminator( launchConfig ).terminateLaunches();

  assertThat( unrelatedLaunch.isTerminated() ).isFalse();
}
 
Example 9
Source File: LaunchTerminatorPDETest.java    From eclipse-extras with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testTerminateLaunchesWithTerminatedLaunch() throws CoreException {
  ILaunchConfiguration launchConfig = launchConfigRule.createPublicLaunchConfig().doSave();
  ILaunch launch = launchConfig.launch( RUN_MODE, new NullProgressMonitor() );
  launch.terminate();

  new LaunchTerminator( launchConfig ).terminateLaunches();

  assertThat( launch.isTerminated() ).isTrue();
}
 
Example 10
Source File: LaunchTerminatorPDETest.java    From eclipse-extras with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testTerminateLaunchesWithMultipleLaunches() throws CoreException {
  ILaunchConfiguration launchConfig = launchConfigRule.createPublicLaunchConfig().doSave();
  ILaunch launch1 = launchConfig.launch( RUN_MODE, new NullProgressMonitor() );
  ILaunch launch2 = launchConfig.launch( DEBUG_MODE, new NullProgressMonitor() );

  new LaunchTerminator( launchConfig ).terminateLaunches();

  assertThat( launch1.isTerminated() ).isTrue();
  assertThat( launch2.isTerminated() ).isTrue();
}
 
Example 11
Source File: LaunchTerminatorPDETest.java    From eclipse-extras with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testTerminateLaunches() throws CoreException {
  ILaunchConfiguration launchConfig = launchConfigRule.createPublicLaunchConfig().doSave();
  ILaunch launch = launchConfig.launch( RUN_MODE, new NullProgressMonitor() );

  new LaunchTerminator( launchConfig ).terminateLaunches();

  assertThat( launch.isTerminated() ).isTrue();
}
 
Example 12
Source File: LaunchConfigLabelProviderPDETest.java    From eclipse-extras with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testGetImageForRunningLaunchConfig() throws CoreException {
  LaunchConfigLabelProvider labelProvider = createLabelProvider( LIST );
  ILaunchConfiguration launchConfig = launchConfigRule.createPublicLaunchConfig().doSave();

  Image image = labelProvider.getImage( launchConfig );
  launchConfig.launch( RUN_MODE, null );
  Image runningImage = labelProvider.getImage( launchConfig );

  assertThat( runningImage ).isNotNull();
  assertThat( runningImage ).isNotEqualTo( image );
}
 
Example 13
Source File: LaunchConfigCleanerPDETest.java    From eclipse-extras with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testNoCleanupWhenLaunchConfigDeleted() throws CoreException {
  prepareLaunchPreferences( true, launchConfigRule.getPublicTestLaunchConfigType() );
  launchConfigCleaner.install();
  ILaunchConfiguration launchConfig = launchConfigRule.createPublicLaunchConfig().doSave();

  ILaunch launch = launchConfig.launch( RUN_MODE, null );
  launchConfig.delete();
  launch.terminate();

  assertThat( getLaunchConfigs() ).extracting( "name" ).doesNotContain( launchConfig.getName() );
}
 
Example 14
Source File: BuildUtils.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Runs a ant build for project according to specified configuration
 * 
 * @param monitor
 *            progress monitor
 * @param cfg
 *            build configuration name
 * @param project
 *            project to be build (for platform project will build whole
 *            platform)
 */
public static void refreshAndBuild(IProgressMonitor monitor, String cfg, IProject project)
		throws InvocationTargetException {
	boolean isAutoBuildEnabled = isAutoBuildEnabled();
	enableAutoBuild(false);
	String projectLocation = project.getLocation().toString() + File.separator + "build.xml";
	String projectName = project.getName();
	if (!projectName.equals(PLATFORM_NAME)) {
		cfg = cfg + "_" + projectName;
	}
	try {

		ILaunchConfiguration launchCfg = getLaunchConfig(cfg);
		if (launchCfg == null) {
			if (cfg.contains(PLATFORM_BUILD_CONFIG)) {
				launchCfg = createAntBuildConfig(cfg, "all", projectLocation, projectName);
			} else if (cfg.contains(PLATFORM_CLEAN_BUILD_CONFIG)) {
				launchCfg = createAntBuildConfig(cfg, "clean,all", projectLocation, project.getName());
			}
		}
		
		if (launchCfg != null ) {
			launchCfg.launch(ILaunchManager.RUN_MODE, monitor);
		}

		if (cfg.equals(PLATFORM_CLEAN_BUILD_CONFIG)) {
			refreshWorkspaceAndBuild(monitor);
		} else if (!cfg.equals(PLATFORM_CLEAN_BUILD_CONFIG) && !cfg.equals(PLATFORM_BUILD_CONFIG)) { // NOSONAR
			refreshPlatformAndCurrentProject(project);
		}

	} catch (CoreException e) {
		throw new InvocationTargetException(e);
	}

	if (isAutoBuildEnabled) {
		enableAutoBuild(true);
	}
}
 
Example 15
Source File: TestRunConfiguration.java    From corrosion with Eclipse Public License 2.0 5 votes vote down vote up
private static void confirmErrorPopup(ILaunchConfiguration configuration) throws CoreException {
	configuration.launch(ILaunchManager.RUN_MODE, new NullProgressMonitor());
	new DisplayHelper() {
		@Override
		protected boolean condition() {
			return getErrorPopup() != null;
		}
	}.waitForCondition(Display.getDefault(), 15000);

	assertNotNull(getErrorPopup());
}
 
Example 16
Source File: DotnetRunDelegate.java    From aCute with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void launch(IEditorPart editor, String mode) {
	IEditorInput input = editor.getEditorInput();
	IFile file = input.getAdapter(IFile.class);

	try {
		ILaunchConfiguration launchConfig = getLaunchConfiguration(mode, file);
		launchConfig.launch(mode, new NullProgressMonitor());
	} catch (CoreException e) {
		e.printStackTrace();
	}
}
 
Example 17
Source File: BuildICEHandler.java    From ice with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {

	// Get the Launch Manager
	ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();

	if (manager != null) {
		IProject aggregatorProject = ResourcesPlugin.getWorkspace().getRoot().getProject("org.eclipse.ice.aggregator");

		if (aggregatorProject != null) {
			// Get the Launch Configurations files
			IFile mvnInstall = aggregatorProject.getFile("Build ICE.launch");

			// Get the Launch Configuration from those files
			ILaunchConfiguration installConfig = manager.getLaunchConfiguration(mvnInstall);

			// Create and launch the Job. 
			Job job = new WorkspaceJob("Building ICE") {

				@Override
				public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
					installConfig.launch(ILaunchManager.RUN_MODE, monitor);
					return Status.OK_STATUS;
				}

			};
			job.schedule();
		} else {
			logger.info("Info: Could not build ICE because it hasn't been cloned yet. Please clone ICE to the current workspace.");
		}
	} else {
		logger.error("Error in launching the ICE Build - Could not get the Launch Manager.");
	}
	return null;
}
 
Example 18
Source File: TerminateLaunchesActionPDETest.java    From eclipse-extras with Eclipse Public License 1.0 4 votes vote down vote up
private ILaunch runLaunchConfig() throws CoreException {
  ILaunchConfiguration launchConfig = launchConfigRule.createPublicLaunchConfig().doSave();
  return launchConfig.launch( RUN_MODE, null );
}
 
Example 19
Source File: ExportGhidraModuleWizard.java    From ghidra with Apache License 2.0 4 votes vote down vote up
/**
 * Exports the given Ghidra module project to an extension zip file.
 *  
 * @param javaProject The Ghidra module project to export.
 * @param gradleDistribution The Gradle distribution to use to export.
 * @param monitor The monitor to use during export.
 * @throws InvocationTargetException if an error occurred during export.
 */
private void export(IJavaProject javaProject, GradleDistribution gradleDistribution,
		IProgressMonitor monitor)
		throws InvocationTargetException {
	try {
		IProject project = javaProject.getProject();
		info("Exporting " + project.getName());
		monitor.beginTask("Exporting " + project.getName(), 2);

		// Get path to Ghidra installation directory
		String ghidraInstallDirPath = project.getFolder(
			GhidraProjectUtils.GHIDRA_FOLDER_NAME).getLocation().toOSString();
		
		// Get project's java.  Gradle should use the same version.
		// TODO: It's more correct to get this from the project's classpath, since Ghidra's
		// saved Java home can change from launch to launch.  
		GhidraApplicationLayout ghidraLayout = new GhidraApplicationLayout(new File(ghidraInstallDirPath));
		File javaHomeDir = new JavaConfig(
			ghidraLayout.getApplicationInstallationDir().getFile(false)).getSavedJavaHome();
		if(javaHomeDir == null) {
			throw new IOException("Failed to get the Java home associated with the project.  " +
				"Perform a \"Link Ghidra\" operation on the project and try again.");
		}

		// Setup the Gradle build attributes
		List<String> tasks = new ArrayList<>();
		String workingDir = project.getLocation().toOSString();
		String gradleDist = gradleDistribution.toString();
		String gradleUserHome = "";
		String javaHome = javaHomeDir.getAbsolutePath();
		List<String> jvmArgs = new ArrayList<>();
		List<String> gradleArgs =
			Arrays.asList(new String[] { "-PGHIDRA_INSTALL_DIR=" + ghidraInstallDirPath });
		boolean showExecutionView = false;
		boolean showConsoleView = true;
		boolean overrideWorkspaceSettings = true;
		boolean isOffline = true;
		boolean isBuildScansEnabled = false;
		GradleRunConfigurationAttributes gradleAttributes =
			new GradleRunConfigurationAttributes(tasks, workingDir, gradleDist, gradleUserHome,
				javaHome, jvmArgs, gradleArgs, showExecutionView, showConsoleView,
				overrideWorkspaceSettings, isOffline, isBuildScansEnabled);

		// Launch Gradle
		GradleLaunchConfigurationManager lm = CorePlugin.gradleLaunchConfigurationManager();
		ILaunchConfiguration lc = lm.getOrCreateRunConfiguration(gradleAttributes);
		lc.launch(ILaunchManager.RUN_MODE, monitor, true, true);
		lc.delete();

		monitor.worked(1);

		project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
		monitor.worked(1);

		info("Finished exporting " + project.getName());
	}
	catch (IOException | ParseException | CoreException e) {
		throw new InvocationTargetException(e);
	}
	finally {
		monitor.done();
	}
}
 
Example 20
Source File: RustLaunchDelegateTools.java    From corrosion with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Launches the given launch configuration
 *
 * @param launchConfig
 * @param mode
 */
public static void launch(ILaunchConfiguration launchConfig, String mode) throws CoreException {
	if (launchConfig != null) {
		launchConfig.launch(mode, new NullProgressMonitor());
	}
}