Search in sources :

Example 56 with ILaunchManager

use of org.eclipse.debug.core.ILaunchManager in project derby by apache.

the class DerbyUtils method launch.

protected static ILaunch launch(IProject proj, String name, String mainClass, String args, String vmargs, String app) throws CoreException {
    ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
    ILaunchConfigurationType type = null;
    if (app.equalsIgnoreCase(CommonNames.START_DERBY_SERVER)) {
        // type= manager.getLaunchConfigurationType("org.apache.derby.ui.startDerbyServerLaunchConfigurationType");
        type = manager.getLaunchConfigurationType(CommonNames.START_SERVER_LAUNCH_CONFIG_TYPE);
    } else if (app.equalsIgnoreCase(CommonNames.SHUTDOWN_DERBY_SERVER)) {
        // type= manager.getLaunchConfigurationType("org.apache.derby.ui.stopDerbyServerLaunchConfigurationType");
        type = manager.getLaunchConfigurationType(CommonNames.STOP_SERVER_LAUNCH_CONFIG_TYPE);
    } else if (app.equalsIgnoreCase(CommonNames.IJ)) {
        // type= manager.getLaunchConfigurationType("org.apache.derby.ui.ijDerbyLaunchConfigurationType");
        type = manager.getLaunchConfigurationType(CommonNames.IJ_LAUNCH_CONFIG_TYPE);
    } else if (app.equalsIgnoreCase(CommonNames.SYSINFO)) {
        // type= manager.getLaunchConfigurationType("org.apache.derby.ui.sysinfoDerbyLaunchConfigurationType");
        type = manager.getLaunchConfigurationType(CommonNames.SYSINFO_LAUNCH_CONFIG_TYPE);
    } else {
        type = manager.getLaunchConfigurationType(IJavaLaunchConfigurationConstants.ID_JAVA_APPLICATION);
    }
    ILaunchConfiguration config = null;
    // if the configuration already exists, delete it
    ILaunchConfiguration[] configurations = manager.getLaunchConfigurations(type);
    for (int i = 0; i < configurations.length; i++) {
        if (configurations[i].getName().equals(name))
            configurations[i].delete();
    }
    // else create a new one
    if (config == null) {
        ILaunchConfigurationWorkingCopy wc = type.newInstance(null, name);
        wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, proj.getProject().getName());
        // current directory should be the project root
        wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, proj.getProject().getLocation().toString());
        // use the suplied args
        if ((vmargs != null) && !(vmargs.equals(""))) {
            wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, vmargs);
        }
        wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, mainClass);
        wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, args);
        // saves the new config
        config = wc.doSave();
    }
    ILaunch launch = config.launch(ILaunchManager.RUN_MODE, null);
    config.delete();
    return launch;
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) ILaunch(org.eclipse.debug.core.ILaunch) ILaunchManager(org.eclipse.debug.core.ILaunchManager) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)

Example 57 with ILaunchManager

use of org.eclipse.debug.core.ILaunchManager in project webtools.servertools by eclipse.

the class ExternalLaunchConfigurationDelegate method launch.

/* (non-Javadoc)
	 * @see org.eclipse.debug.core.model.ILaunchConfigurationDelegate#launch(org.eclipse.debug.core.ILaunchConfiguration, java.lang.String, org.eclipse.debug.core.ILaunch, org.eclipse.core.runtime.IProgressMonitor)
	 */
public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
    IServer server = ServerUtil.getServer(configuration);
    if (server == null) {
        abort(GenericServerCoreMessages.missingServer, null, IJavaLaunchConfigurationConstants.ERR_INTERNAL_ERROR);
    }
    @SuppressWarnings("null") ExternalServerBehaviour serverBehavior = (ExternalServerBehaviour) server.loadAdapter(ServerBehaviourDelegate.class, null);
    // initialize the server, check the ports and start the PingThread that will check
    // server state
    serverBehavior.setupLaunch(launch, mode, monitor);
    // get the "external" command
    String commandline = configuration.getAttribute(COMMANDLINE, (String) null);
    if (commandline == null || commandline.length() == 0) {
        abort(GenericServerCoreMessages.commandlineUnspecified, null, IJavaLaunchConfigurationConstants.ERR_INTERNAL_ERROR);
    }
    // parse the "external" command into multiple args
    String[] cmdArgs = DebugPlugin.parseArguments(commandline);
    // get the "programArguments", parsed into multiple args
    String[] pgmArgs = DebugPlugin.parseArguments(getProgramArguments(configuration));
    // Create the full array of cmds
    String[] cmds = new String[cmdArgs.length + pgmArgs.length];
    System.arraycopy(cmdArgs, 0, cmds, 0, cmdArgs.length);
    System.arraycopy(pgmArgs, 0, cmds, cmdArgs.length, pgmArgs.length);
    // get a descriptive name for the executable
    String executableName = configuration.getAttribute(EXECUTABLE_NAME, DEFAULT_EXECUTABLE_NAME);
    // get the executable environment
    ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
    String[] env = manager.getEnvironment(configuration);
    // get the working directory
    File workingDir = verifyWorkingDirectory(configuration);
    if (workingDir == null) {
        abort(GenericServerCoreMessages.workingdirUnspecified, null, IJavaLaunchConfigurationConstants.ERR_INTERNAL_ERROR);
    }
    // Launch the executable for the configuration using the Ant Execute class
    try {
        Process process = Execute.launch(null, cmds, env, workingDir, true);
        serverBehavior.startPingThread();
        IProcess runtimeProcess = new RuntimeProcess(launch, process, executableName, null);
        launch.addProcess(runtimeProcess);
        serverBehavior.setProcess(runtimeProcess);
    } catch (IOException ioe) {
        abort(GenericServerCoreMessages.errorLaunchingExecutable, ioe, IJavaLaunchConfigurationConstants.ERR_INTERNAL_ERROR);
    }
    if (mode.equals("debug")) {
        // $NON-NLS-1$
        ILaunchConfigurationWorkingCopy wc = createDebuggingConfig(configuration);
        // if we're launching the debugging we need to wait for the config to start
        // before launching the debugging session
        serverBehavior.setDebuggingConfig(wc, mode, launch, monitor);
    }
}
Also used : IServer(org.eclipse.wst.server.core.IServer) ILaunchManager(org.eclipse.debug.core.ILaunchManager) RuntimeProcess(org.eclipse.debug.core.model.RuntimeProcess) IProcess(org.eclipse.debug.core.model.IProcess) IOException(java.io.IOException) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) RuntimeProcess(org.eclipse.debug.core.model.RuntimeProcess) ServerBehaviourDelegate(org.eclipse.wst.server.core.model.ServerBehaviourDelegate) File(java.io.File) IProcess(org.eclipse.debug.core.model.IProcess)

Example 58 with ILaunchManager

use of org.eclipse.debug.core.ILaunchManager in project webtools.servertools by eclipse.

the class ServerType method getLaunchConfigurationType.

public ILaunchConfigurationType getLaunchConfigurationType() {
    try {
        String launchConfigId = element.getAttribute("launchConfigId");
        if (launchConfigId == null)
            return null;
        ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
        return launchManager.getLaunchConfigurationType(launchConfigId);
    } catch (Exception e) {
        return null;
    }
}
Also used : ILaunchManager(org.eclipse.debug.core.ILaunchManager) CoreException(org.eclipse.core.runtime.CoreException)

Example 59 with ILaunchManager

use of org.eclipse.debug.core.ILaunchManager in project webtools.servertools by eclipse.

the class ServerPropertiesEditorSection method getExistingLaunch.

public ILaunch getExistingLaunch() {
    ILaunchManager launchManager = getLaunchManager();
    ILaunch[] launches = launchManager.getLaunches();
    int size = launches.length;
    for (int i = 0; i < size; i++) {
        ILaunchConfiguration launchConfig = launches[i].getLaunchConfiguration();
        try {
            if (launchConfig != null) {
                String serverId = launchConfig.getAttribute(GenericServerBehaviour.ATTR_SERVER_ID, (String) null);
                if (fServer.getServer().getId().equals(serverId)) {
                    if (!launches[i].isTerminated())
                        return launches[i];
                }
            }
        } catch (CoreException e) {
        // ignore
        }
    }
    return null;
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) CoreException(org.eclipse.core.runtime.CoreException) ILaunch(org.eclipse.debug.core.ILaunch) ILaunchManager(org.eclipse.debug.core.ILaunchManager)

Example 60 with ILaunchManager

use of org.eclipse.debug.core.ILaunchManager in project liferay-ide by liferay.

the class LaunchHelper method createLaunchConfiguration.

public ILaunchConfigurationWorkingCopy createLaunchConfiguration() throws CoreException {
    ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
    ILaunchConfigurationType type = manager.getLaunchConfigurationType(launchConfigTypeId);
    ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
    String name = launchManager.generateLaunchConfigurationName(getNewLaunchConfigurationName());
    ILaunchConfigurationWorkingCopy launchConfig = type.newInstance(null, name);
    launchConfig.setAttribute("org.eclipse.debug.ui.ATTR_CAPTURE_IN_CONSOLE", isLaunchCaptureInConsole());
    launchConfig.setAttribute("org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND", isLaunchInBackground());
    launchConfig.setAttribute("org.eclipse.debug.ui.ATTR_PRIVATE", isLaunchIsPrivate());
    IRuntimeClasspathEntry[] classpath = getClasspath(launchConfig);
    List<String> mementos = new ArrayList<>(classpath.length);
    for (int i = 0; i < classpath.length; i++) {
        IRuntimeClasspathEntry entry = classpath[i];
        mementos.add(entry.getMemento());
    }
    launchConfig.setAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, Boolean.FALSE);
    launchConfig.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH, mementos);
    if (getMainClass() != null) {
        launchConfig.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, getMainClass());
    }
    if (ListUtil.isNotEmpty(launchArgs)) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < launchArgs.length; i++) {
            sb.append("\"");
            sb.append(launchArgs[i]);
            sb.append("\" ");
        }
        launchConfig.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, sb.toString());
    }
    return launchConfig;
}
Also used : ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) ArrayList(java.util.ArrayList) ILaunchManager(org.eclipse.debug.core.ILaunchManager) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) IRuntimeClasspathEntry(org.eclipse.jdt.launching.IRuntimeClasspathEntry)

Aggregations

ILaunchManager (org.eclipse.debug.core.ILaunchManager)78 ILaunchConfigurationType (org.eclipse.debug.core.ILaunchConfigurationType)53 ILaunchConfigurationWorkingCopy (org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)41 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)37 CoreException (org.eclipse.core.runtime.CoreException)28 ArrayList (java.util.ArrayList)15 ILaunch (org.eclipse.debug.core.ILaunch)14 IPath (org.eclipse.core.runtime.IPath)9 File (java.io.File)7 HashMap (java.util.HashMap)6 Path (org.eclipse.core.runtime.Path)6 IProject (org.eclipse.core.resources.IProject)5 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)5 IOException (java.io.IOException)4 Map (java.util.Map)4 IStatus (org.eclipse.core.runtime.IStatus)4 LinkedList (java.util.LinkedList)3 Status (org.eclipse.core.runtime.Status)3 IProcess (org.eclipse.debug.core.model.IProcess)3 IProcess2 (org.talend.core.model.process.IProcess2)3