Java Code Examples for org.eclipse.debug.core.model.IProcess#getLaunch()

The following examples show how to use org.eclipse.debug.core.model.IProcess#getLaunch() . 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: GwtWtpPlugin.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
private void onAfterCodeServerStarted(DebugEvent event) {
  if (!(event.getSource() instanceof IProcess)) {
    return;
  }

  IProcess runtimeProcess = (IProcess) event.getSource();
  final ILaunch launch = runtimeProcess.getLaunch();
  IProcess[] processes = launch.getProcesses();
  final IProcess process = processes[0];

  // Look for the links in the sdm console output
  consoleStreamListenerCodeServer = new IStreamListener() {
    @Override
    public void streamAppended(String text, IStreamMonitor monitor) {
      displayCodeServerUrlInDevMode(launch, text);
    }
  };

  // Listen to Console output
  streamMonitorCodeServer = process.getStreamsProxy().getOutputStreamMonitor();
  streamMonitorCodeServer.addListener(consoleStreamListenerCodeServer);
}
 
Example 3
Source File: PydevIProcessFactory.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
public static String getEncodingFromFrame(PyStackFrame selectedFrame) {
    try {
        IDebugTarget adapter = selectedFrame.getAdapter(IDebugTarget.class);
        if (adapter == null) {
            return "UTF-8";
        }
        IProcess process = adapter.getProcess();
        if (process == null) {
            return "UTF-8";
        }
        ILaunch launch = process.getLaunch();
        if (launch == null) {
            Log.log("Unable to get launch for: " + process);
            return "UTF-8";
        }
        return getEncodingFromLaunch(launch);
    } catch (Exception e) {
        Log.log(e);
        return "UTF-8";
    }
}
 
Example 4
Source File: PythonConsoleLineTracker.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void init(final IConsole console) {
    IProcess process = console.getProcess();
    if (process != null) {
        ILaunch launch = process.getLaunch();
        if (launch != null) {
            initLaunchConfiguration(launch.getLaunchConfiguration());
        }
    }
    this.linkContainer = new ILinkContainer() {

        @Override
        public void addLink(IHyperlink link, int offset, int length) {
            if (length <= 0) {
                // Log.log("Trying to create link with invalid len: " + length);
                return;
            }
            console.addLink(link, offset, length);
        }

        @Override
        public String getContents(int offset, int length) throws BadLocationException {
            return console.getDocument().get(offset, length);
        }
    };
}
 
Example 5
Source File: ErrorLineMatcher.java    From corrosion with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void matchFound(PatternMatchEvent event) {
	try {
		int offset = event.getOffset();
		int length = event.getLength();
		IProcess process = (IProcess) console.getAttribute(IDebugUIConstants.ATTR_CONSOLE_PROCESS);
		if (process != null) {
			ILaunch launch = process.getLaunch();
			String projectAttribute = RustLaunchDelegateTools.PROJECT_ATTRIBUTE;
			String launchConfigurationType = launch.getLaunchConfiguration().getType().getIdentifier();
			if (launchConfigurationType.equals(RustLaunchDelegateTools.CORROSION_DEBUG_LAUNCH_CONFIG_TYPE)) {
				// support debug launch configs
				projectAttribute = ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME;
			}
			String projectName = launch.getLaunchConfiguration().getAttribute(projectAttribute, ""); //$NON-NLS-1$
			if (projectName.trim().isEmpty()) {
				return; // can't determine project so prevent error down
			}
			IWorkspaceRoot myWorkspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
			IProject myProject = myWorkspaceRoot.getProject(projectName);
			String errorString = console.getDocument().get(event.getOffset(), event.getLength());
			String[] coordinates = errorString.split(":"); //$NON-NLS-1$
			IHyperlink link = makeHyperlink(myProject.getFile(coordinates[0]), Integer.parseInt(coordinates[1]),
					Integer.parseInt(coordinates[2]));
			console.addHyperlink(link, offset, length);
		}
	} catch (BadLocationException | CoreException e) {
		// ignore
	}
}
 
Example 6
Source File: XtendFileHyperlink.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
private ILaunch getLaunch() {
  Object _attribute = this.console.getAttribute(IDebugUIConstants.ATTR_CONSOLE_PROCESS);
  final IProcess process = ((IProcess) _attribute);
  if ((process != null)) {
    return process.getLaunch();
  }
  return null;
}
 
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: 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 9
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 10
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);
}