Java Code Examples for org.eclipse.debug.core.ILaunch#getLaunchConfiguration()

The following examples show how to use org.eclipse.debug.core.ILaunch#getLaunchConfiguration() . 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: TestResultsView.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Invoked when user performs {@link #actionStop}.
 */
protected void performStop() {
	IProcess process = DebugUITools.getCurrentProcess();
	if (process == null) {
		return;
	}
	final TestSession session = from(registeredSessions).firstMatch(s -> s.root == currentRoot).orNull();
	if (null != session) {
		ILaunch launch = process.getLaunch();
		ILaunchConfiguration runningConfig = launch.getLaunchConfiguration();
		ILaunchConfiguration sessionConfig = getLaunchConfigForSession(session, null);
		if (runningConfig.getName() == sessionConfig.getName()) { // we use "==" since the name is the same instance
			List<ITerminate> targets = collectTargets(process);
			targets.add(process);
			DebugCommandService service = DebugCommandService
					.getService(PlatformUI.getWorkbench().getActiveWorkbenchWindow());
			service.executeCommand(ITerminateHandler.class, targets.toArray(), null);
			session.root.stopRunning();
			refreshActions();
		}
	}
}
 
Example 2
Source File: LocalAppEngineServerLaunchConfigurationDelegate.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
void checkConflictingLaunches(ILaunchConfigurationType launchConfigType, String mode,
    RunConfiguration runConfig, ILaunch[] launches) throws CoreException {

  for (ILaunch launch : launches) {
    if (launch.isTerminated()
        || launch.getLaunchConfiguration() == null
        || launch.getLaunchConfiguration().getType() != launchConfigType) {
      continue;
    }
    IServer otherServer = ServerUtil.getServer(launch.getLaunchConfiguration());
    List<Path> paths = new ArrayList<>();
    RunConfiguration otherRunConfig =
        generateServerRunConfiguration(launch.getLaunchConfiguration(), otherServer, mode, paths);
    IStatus conflicts = checkConflicts(runConfig, otherRunConfig,
        new MultiStatus(Activator.PLUGIN_ID, 0,
            Messages.getString("conflicts.with.running.server", otherServer.getName()), //$NON-NLS-1$
            null));
    if (!conflicts.isOK()) {
      throw new CoreException(StatusUtil.filter(conflicts));
    }
  }
}
 
Example 3
Source File: LaunchConfiguration.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Create a new instance.
 * 
 * @param name The name of the launch configuration.
 * @param model The model associated with this launch configuration
 */
LaunchConfiguration(ILaunch launch, String name, WebAppDebugModel model) {
  id = model.getModelNodeNextId();
  this.launch = launch;
  this.name = name;
  this.model = model;

  // We're caching the type ID as
  // ModelLabelProvider.getLaunchConfigurationImage() may request it even
  // after the actual launch configuration has been deleted.
  String typeId = WebAppLaunchConfiguration.TYPE_ID;
  ILaunchConfiguration launchConfiguration = launch.getLaunchConfiguration();
  if (launchConfiguration != null) {
    try {
      typeId = launchConfiguration.getType().getIdentifier();
    } catch (CoreException e) {
      GWTPluginLog.logError(e,
          "Could not determine the launch configuration type");
    }
  }

  this.launchTypeId = typeId;
}
 
Example 4
Source File: CodewindLaunchListener.java    From codewind-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void launchesTerminated(ILaunch[] launches) {
	for (ILaunch launch : launches) {
		ILaunchConfiguration config = launch.getLaunchConfiguration();
		try {
			if (config.hasAttribute(CodewindLaunchConfigDelegate.CONNECTION_ID_ATTR) && config.hasAttribute(CodewindLaunchConfigDelegate.PROJECT_ID_ATTR)) {
				CodewindConnection conn = CodewindConnectionManager.getConnectionById(config.getAttribute(CodewindLaunchConfigDelegate.CONNECTION_ID_ATTR, ""));
				CodewindApplication app = conn == null ? null : conn.getAppByID(config.getAttribute(CodewindLaunchConfigDelegate.PROJECT_ID_ATTR, ""));
				if (app != null) {
					app.launchTerminated(launch);
				}
			}
		} catch (CoreException e) {
			Logger.logError("An error occurred trying to look up the application for a launch configuration", e);
		}
	}
}
 
Example 5
Source File: TerminateLaunchesActionPDETest.java    From eclipse-extras with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testRunWithMultipleLaunchConfigs() throws Exception {
  ILaunch launch1 = runLaunchConfig();
  ILaunch launch2 = runLaunchConfig();
  ILaunchConfiguration launchConfig1 = launch1.getLaunchConfiguration();
  ILaunchConfiguration launchConfig2 = launch2.getLaunchConfiguration();
  action.setSelection( new StructuredSelection( new Object[] { launchConfig1, launchConfig2 } ) );

  action.run();
  waitForTerminateLaunchesJob();

  assertThat( launch1.isTerminated() ).isTrue();
  assertThat( launch2.isTerminated() ).isTrue();
}
 
Example 6
Source File: RuntimeProcessExtension.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
public static String calcExtendedProcessLabel(IProcess process) {
	ILaunch launch = process.getLaunch();
	
	StringBuffer buffer = new StringBuffer();
	
	if (process.isTerminated()) {
		try {
			int exitValue = process.getExitValue();
			buffer.append("<exit code: " + exitValue + "> ");
		} catch (DebugException e) {
			// Should not happen
		}
	}
	
	ILaunchConfiguration launchConfiguration = launch.getLaunchConfiguration();
	if (launchConfiguration != null) {
		buffer.append(launchConfiguration.getName());

		try {
			ILaunchConfigurationType launchConfigType = launchConfiguration.getType();
			if (launchConfigType != null) {
				String type = launchConfigType.getName();

				buffer.append(" [");
				buffer.append(type);
				buffer.append("] ");
			}
		} catch (CoreException ce) {
			EclipseCore.logStatus(ce);
		}
	}
	buffer.append(process.getLabel());
	return buffer.toString();
}
 
Example 7
Source File: PythonConsoleLineTracker.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
private void updateProjectAndWorkingDir() {
    if (updatedProjectAndWorkingDir) {
        return;
    }
    IProcess process = DebugUITools.getCurrentProcess();
    if (process != null) {
        ILaunch launch = process.getLaunch();
        if (launch != null) {
            updatedProjectAndWorkingDir = true;
            ILaunchConfiguration lc = launch.getLaunchConfiguration();
            initLaunchConfiguration(lc);
        }
    }
}
 
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: LaunchConfigurationContent.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private IProject getProject(LaunchConfiguration launchConfig) {
  if (launchConfig == null) {
    return null;
  }

  ILaunch launch = launchConfig.getLaunch();
  if (launch == null) {
    return null;
  }

  ILaunchConfiguration lc = launch.getLaunchConfiguration();
  if (lc == null) {
    return null;
  }

  IJavaProject project;
  try {
    project = JavaRuntime.getJavaProject(lc);
  } catch (CoreException e) {
    return null;
  }
  if (project == null) {
    return null;
  }

  return project.getProject();
}
 
Example 10
Source File: GwtWtpPlugin.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private IServer getServerFromLaunchConfig(ILaunch launch) {
  ILaunchConfiguration launchConfig = launch.getLaunchConfiguration();
  if (launchConfig == null) {
    return null;
  }

  IServer server = null;
  try {
    server = ServerUtil.getServer(launchConfig);
  } catch (CoreException e) {
    logError("getServerFromLaunchConfig: Getting the WTP server error.", e);
    return null;
  }
  return server;
}
 
Example 11
Source File: LaunchConfigCleaner.java    From eclipse-extras with Eclipse Public License 1.0 5 votes vote down vote up
private void launchTerminated( ILaunch launch ) {
  ILaunchConfiguration terminatedLaunchConfig = launch.getLaunchConfiguration();
  if( terminatedLaunchConfig != null ) {
    try {
      launchTerminated( terminatedLaunchConfig );
    } catch( CoreException ce ) {
      handleCoreException( ce );
    }
  }
}
 
Example 12
Source File: Model.java    From tlaplus with MIT License 5 votes vote down vote up
public boolean isRunning() {
	final ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
	final ILaunch[] launches = launchManager.getLaunches();
	for (int i = 0; i < launches.length; i++) {
		final ILaunch launch = launches[i];
		if (launch.getLaunchConfiguration() != null
				&& launch.getLaunchConfiguration().contentsEqual(this.launchConfig)) {
			if (!launch.isTerminated()) {
				return true;
			}
		}
	}
	return false;
}
 
Example 13
Source File: LaunchEvent.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
public LaunchEvent(ILaunch launch) {
	this.launch = launch;

	ILaunchConfiguration launchConfiguration = launch.getLaunchConfiguration();
	try {
		IResource[] mappedResources = launchConfiguration.getMappedResources();
		for (IResource iResource : mappedResources) {
			launchedFile = iResource.getName();
			launchedProject = iResource.getProject();
		}
	} catch (CoreException e) {
		e.printStackTrace();
	}
}
 
Example 14
Source File: BaseTest.java    From codewind-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected ILaunch getLaunch(CodewindApplication app) throws Exception {
	for (ILaunch launch : DebugPlugin.getDefault().getLaunchManager().getLaunches()) {
		ILaunchConfiguration config = launch.getLaunchConfiguration();
		if (config != null && CodewindLaunchConfigDelegate.LAUNCH_CONFIG_ID.equals(config.getType().getIdentifier()) &&
				app.projectID.equals(config.getAttribute(CodewindLaunchConfigDelegate.PROJECT_ID_ATTR, "")) &&
				app.connection.getConid().equals(config.getAttribute(CodewindLaunchConfigDelegate.CONNECTION_ID_ATTR, ""))) {
			return launch;
		}
	}
	return null;
}
 
Example 15
Source File: GwtWtpPlugin.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Start or stop processes automatically. Start or stop the CodeServer.
 */
private void onDebugEvent(DebugEvent event) throws CoreException {
  if (!(event.getSource() instanceof IProcess)) {
    return;
  }

  IProcess runtimeProcess = (IProcess) event.getSource();
  ILaunch launch = runtimeProcess.getLaunch();
  ILaunchConfiguration launchConfig = launch.getLaunchConfiguration();
  if (launchConfig == null) {
    return;
  }

  IServer server = getServerFromLaunchConfig(launch);
  ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
  ILaunchConfigurationType sdmCodeServerType = launchManager
      .getLaunchConfigurationType(GwtSuperDevModeLaunchConfiguration.TYPE_ID);

  if (launchConfig.getType().equals(sdmCodeServerType)) {
    if (event.getKind() == DebugEvent.CREATE) {
      onAfterCodeServerStarted(event);
    } else if (event.getKind() == DebugEvent.TERMINATE) {
      onAfterCodeServerTerminated(event);
    }
  }

  // pass along the event to server started.
  if (server != null && server.getServerState() == IServer.STATE_STARTING) {
    debugEvent = event;
    startedCodeServer = false; // safety reset
  }

  // WTP Server Start/Stop
  if (server != null && serverListener == null) { // listen for server started. It throws two events...
    serverListener = new IServerListener() {
      @Override
      public void serverChanged(ServerEvent event) {
        if (event.getState() == IServer.STATE_STARTED && !startedCodeServer) {
          startedCodeServer = true;
          onServerStarted(debugEvent);
        }
      }
    };
    server.addServerListener(serverListener);
  }

  if (server != null
      && (server.getServerState() == IServer.STATE_STOPPING || server.getServerState() == IServer.STATE_STOPPED)) {
    // Server Stop: Delineate event for Server Launching and then possibly terminate SDM
    onServerStopped(event);
    serverListener = null;
    startedCodeServer = false;

    onAfterWebServerTerminated(event);
  }
}
 
Example 16
Source File: GwtWtpPlugin.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Possibly start the GWT Super Dev Mode CodeServer. <br/>
 * <br/>
 * This starts as separate process, which allows for custom args modification. <br/>
 * It adds a launcher id to both processes for reference. <br/>
 * 1. Get it from classic launch config <br/>
 * 2. Get it from server VM properties <br/>
 */
protected void onServerStarted(DebugEvent event) {
  onAfterWebServerStarted(event);

  IProcess runtimeProcess = (IProcess) event.getSource();
  ILaunch launch = runtimeProcess.getLaunch();
  ILaunchConfiguration launchConfig = launch.getLaunchConfiguration();
  String launchMode = launch.getLaunchMode();

  IServer server = null;
  try {
    server = ServerUtil.getServer(launchConfig);
  } catch (CoreException e) {
    logError("possiblyLaunchGwtSuperDevModeCodeServer: Could get the WTP server.", e);
    return;
  }

  if (server == null) {
    logMessage("possiblyLaunchGwtSuperDevModeCodeServer: No WTP server runtime found.");
    return;
  }

  IFacetedProject gwtFacetedProject = GwtFacetUtils.getGwtFacetedProject(server);

  // If one of the server modules has a gwt facet
  if (gwtFacetedProject == null) {
    logMessage("possiblyLaunchGwtSuperDevModeCodeServer: Does not have a GWT Facet.");
    return;
  }

  // Sync Option - the sync is off, ignore stopping the server
  if (!GWTProjectProperties.getFacetSyncCodeServer(gwtFacetedProject.getProject())) {
    logMessage("possiblyLaunchGwtSuperDevModeCodeServer: GWT Facet project properties, the code server sync is off.");
    return;
  }

  /**
   * Get the war output path for the `-launcherDir` in SDM launcher
   */
  String launcherDir = getLauncherDirectory(server, launchConfig, gwtFacetedProject);

  // LauncherId used to reference and terminate the the process
  String launcherId = setLauncherIdToWtpRunTimeLaunchConfig(launchConfig);

  logMessage("possiblyLaunchGwtSuperDevModeCodeServer: Launching GWT Super Dev Mode CodeServer. launcherId="
      + launcherId + " launcherDir=" + launcherDir);

  // Just in case
  if (launchMode == null) {
    // run the code server, no need to debug it
    launchMode = "run";
  }

  if (launcherId == null) { // ids to link two processes together
    logMessage("possiblyLaunchGwtSuperDevModeCodeServer: No launcherId.");
  }
  
  // Add server urls to DevMode view for easy clicking on
  addServerUrlsToDevModeView(launch);

  // Creates ore launches an existing Super Dev Mode Code Server process
  GwtSuperDevModeCodeServerLaunchUtil.launch(gwtFacetedProject.getProject(), launchMode, launcherDir, launcherId);
}
 
Example 17
Source File: ViewerManager.java    From texlipse with Eclipse Public License 1.0 4 votes vote down vote up
/**
    * Closes the target output document using the DDE command from the
    * default viewer, or the most recently launched preview. This method
    * is probably fragile since the process and launches handling in
    * Texlipse is too weak to always know what documents are locked and
    * needs closing.  
    * 
    * @throws CoreException
    */
   public static void closeOutputDocument() throws CoreException {
	
       ViewerAttributeRegistry registry = new ViewerAttributeRegistry();
	
   	// Check to see if we have a running launch configuration which should
       // override the DDE close command
 	ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
    ILaunch[] launches = manager.getLaunches();
    
    for (int i = 0; i < launches.length; i++) {
    	ILaunch l = launches[i];
    	ILaunchConfiguration configuration = l.getLaunchConfiguration();
    	if (configuration != null && configuration.exists() && configuration.getType().getIdentifier().equals(
    			TexLaunchConfigurationDelegate.CONFIGURATION_ID)) {
    		Map regMap = configuration.getAttributes();
	        registry.setValues(regMap);
	        break;
    	}
	}
    
   	ViewerManager mgr = new ViewerManager(registry, null);    	
	
	 if (!mgr.initialize()) {
         return;
     }
	
	// Can only close documents opened by DDE commands themselves
	Process process = mgr.getExisting();        
	if (process != null) {       
		mgr.sendDDECloseCommand();
           
		try {
               Thread.sleep(500); // A small delay required
           } catch (InterruptedException e) {
               // swallow
           }

           returnFocusToEclipse(false);
	}
}
 
Example 18
Source File: RustGDBLaunchWrapper.java    From corrosion with Eclipse Public License 2.0 4 votes vote down vote up
public RustGDBLaunchWrapper(ILaunch launch) {
	super(launch.getLaunchConfiguration(), launch.getLaunchMode(), launch.getSourceLocator());
}