Search in sources :

Example 56 with ILaunchConfigurationType

use of org.eclipse.debug.core.ILaunchConfigurationType in project linuxtools by eclipse.

the class ProfileLaunchShortcut method findLaunchConfiguration.

/**
 * Locate a configuration to relaunch for the given type.  If one cannot be found, create one.
 * @param bin The binary to look launch for.
 * @param mode Launch mode.
 *
 * @return A re-useable config or <code>null</code> if none.
 */
protected ILaunchConfiguration findLaunchConfiguration(IBinary bin, String mode) {
    ILaunchConfiguration configuration = null;
    ILaunchConfigurationType configType = getLaunchConfigType();
    List<ILaunchConfiguration> candidateConfigs = Collections.emptyList();
    try {
        ILaunchConfiguration[] configs = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurations(configType);
        candidateConfigs = new ArrayList<>(configs.length);
        for (ILaunchConfiguration config : configs) {
            IPath programPath = CDebugUtils.getProgramPath(config);
            String projectName = CDebugUtils.getProjectName(config);
            IPath binPath = bin.getResource().getProjectRelativePath();
            if (programPath != null && programPath.equals(binPath)) {
                if (projectName != null && projectName.equals(bin.getCProject().getProject().getName())) {
                    candidateConfigs.add(config);
                }
            }
        }
    } catch (CoreException e) {
        e.printStackTrace();
    }
    // If there are no existing configs associated with the IBinary, create one.
    // If there is exactly one config associated with the IBinary, return it.
    // Otherwise, if there is more than one config associated with the IBinary, prompt the
    // user to choose one.
    int candidateCount = candidateConfigs.size();
    if (candidateCount < 1) {
        configuration = createConfiguration(bin);
    } else if (candidateCount == 1) {
        configuration = candidateConfigs.get(0);
    } else {
        // Prompt the user to choose a config.  A null result means the user
        // cancelled the dialog, in which case this method returns null,
        // since cancelling the dialog should also cancel launching anything.
        configuration = chooseConfiguration(candidateConfigs, mode);
    }
    return configuration;
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType)

Example 57 with ILaunchConfigurationType

use of org.eclipse.debug.core.ILaunchConfigurationType in project linuxtools by eclipse.

the class AbstractTest method createConfiguration.

protected ILaunchConfiguration createConfiguration(IProject proj) throws CoreException {
    String projectName = proj.getName();
    String binPath = "";
    ILaunchConfigurationType configType = getLaunchConfigType();
    ILaunchConfigurationWorkingCopy wc = configType.newInstance(null, getLaunchManager().generateLaunchConfigurationName(projectName));
    if (proj.getLocation() == null) {
        IFileStore fileStore = null;
        try {
            fileStore = EFS.getStore(new URI(proj.getLocationURI() + BIN_DIR + IPath.SEPARATOR + projectName));
        } catch (URISyntaxException e) {
            fail(NLS.bind(Messages.getString("AbstractTest.No_binary"), // $NON-NLS-1$
            projectName));
        }
        if ((fileStore instanceof LocalFile)) {
            fail(NLS.bind(Messages.getString("AbstractTest.No_binary"), // $NON-NLS-1$
            projectName));
        }
        binPath = EFSExtensionManager.getDefault().getPathFromURI(proj.getLocationURI()) + BIN_DIR + IPath.SEPARATOR + proj.getName();
    } else {
        IResource bin = proj.findMember(new Path(BIN_DIR).append(projectName));
        if (bin == null) {
            fail(NLS.bind(Messages.getString("AbstractTest.No_binary"), // $NON-NLS-1$
            projectName));
        }
        binPath = bin.getProjectRelativePath().toString();
        wc.setMappedResources(new IResource[] { bin, proj });
    }
    wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROGRAM_NAME, binPath);
    wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, projectName);
    wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, (String) null);
    // Make launch run in foreground
    wc.setAttribute(IDebugUIConstants.ATTR_LAUNCH_IN_BACKGROUND, false);
    setProfileAttributes(wc);
    return wc.doSave();
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) LocalFile(org.eclipse.core.internal.filesystem.local.LocalFile) ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) IFileStore(org.eclipse.core.filesystem.IFileStore) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) IResource(org.eclipse.core.resources.IResource)

Example 58 with ILaunchConfigurationType

use of org.eclipse.debug.core.ILaunchConfigurationType 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 59 with ILaunchConfigurationType

use of org.eclipse.debug.core.ILaunchConfigurationType in project webtools.sourceediting by eclipse.

the class XSLLaunchShortcut method createConfiguration.

private ILaunchConfiguration createConfiguration() {
    ILaunchConfiguration config = null;
    try {
        ILaunchConfigurationType configType = getConfigurationType();
        // $NON-NLS-1$
        String lastSegment = xmlFile != null ? xmlFile.getName() : xmlFilePath != null ? xmlFilePath.lastSegment() : "XSLTransformation";
        ILaunchConfigurationWorkingCopy wc = configType.newInstance(null, getLaunchManager().generateUniqueLaunchConfigurationNameFrom(lastSegment));
        if (xmlFile != null)
            wc.setAttribute(XSLLaunchConfigurationConstants.ATTR_INPUT_FILE, // $NON-NLS-1$ //$NON-NLS-2$
            "${workspace_loc:" + xmlFile.getFullPath().toPortableString() + "}");
        else
            wc.setAttribute(XSLLaunchConfigurationConstants.ATTR_INPUT_FILE, xmlFilePath.toPortableString());
        wc.setAttribute(XSLLaunchConfigurationConstants.ATTR_USE_DEFAULT_OUTPUT_FILE, true);
        wc.setAttribute(XSLLaunchConfigurationConstants.ATTR_OPEN_FILE, true);
        if (pipeline == null)
            pipeline = new LaunchPipeline();
        for (IFile element : xslFiles) {
            pipeline.addTransformDef(new LaunchTransform(element.getFullPath().toPortableString(), LaunchTransform.RESOURCE_TYPE));
        }
        if (xslFilePath != null) {
            pipeline.addTransformDef(new LaunchTransform(xslFilePath, LaunchTransform.EXTERNAL_TYPE));
        }
        if (!pipeline.getTransformDefs().isEmpty()) {
            LaunchTransform lastDef = pipeline.getTransformDefs().get(pipeline.getTransformDefs().size() - 1);
            String outputFormat = guessOutputMethod(lastDef);
            if (outputFormat != null) {
                wc.setAttribute(XSLLaunchConfigurationConstants.ATTR_DEFAULT_OUTPUT_METHOD, outputFormat);
            }
        }
        wc.setAttribute(XSLLaunchConfigurationConstants.ATTR_PIPELINE, pipeline.toXML());
        if (xmlFile != null)
            wc.setMappedResources(new IResource[] { xmlFile.getProject() });
        config = wc.doSave();
    } catch (CoreException exception) {
        MessageDialog.openError(getShell(), Messages.XSLLaunchShortcut_6, exception.getStatus().getMessage());
    }
    return config;
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) LaunchTransform(org.eclipse.wst.xsl.launching.config.LaunchTransform) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) LaunchPipeline(org.eclipse.wst.xsl.launching.config.LaunchPipeline) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) IResource(org.eclipse.core.resources.IResource)

Example 60 with ILaunchConfigurationType

use of org.eclipse.debug.core.ILaunchConfigurationType in project webtools.sourceediting by eclipse.

the class XSLDebugUILaunchListener method launchesTerminated.

public void launchesTerminated(ILaunch[] launches) {
    for (ILaunch launch : launches) {
        ILaunchConfigurationType configType = null;
        try {
            configType = launch.getLaunchConfiguration().getType();
        } catch (CoreException e) {
        // do nothing
        }
        if (configType != null && XSL_LAUNCH_CONFIGURATION_TYPE.equals(configType.getIdentifier())) {
            try {
                BaseLaunchHelper launchHelper = new BaseLaunchHelper(launch.getLaunchConfiguration());
                File file = launchHelper.getTarget();
                IFile ifile = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(new Path(file.getAbsolutePath()));
                if (ifile != null) {
                    // refresh this workspace file..
                    try {
                        ifile.refreshLocal(IResource.DEPTH_ZERO, new NullProgressMonitor());
                    } catch (CoreException e) {
                        XSLDebugUIPlugin.log(e);
                    }
                }
                openFileIfRequired(launchHelper);
            } catch (CoreException e) {
                XSLDebugUIPlugin.log(e);
            }
        }
    }
}
Also used : Path(org.eclipse.core.runtime.Path) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) ILaunch(org.eclipse.debug.core.ILaunch) BaseLaunchHelper(org.eclipse.wst.xsl.launching.config.BaseLaunchHelper) File(java.io.File) IFile(org.eclipse.core.resources.IFile)

Aggregations

ILaunchConfigurationType (org.eclipse.debug.core.ILaunchConfigurationType)91 ILaunchConfigurationWorkingCopy (org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)62 ILaunchManager (org.eclipse.debug.core.ILaunchManager)54 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)50 CoreException (org.eclipse.core.runtime.CoreException)43 ArrayList (java.util.ArrayList)19 HashMap (java.util.HashMap)8 IPath (org.eclipse.core.runtime.IPath)8 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)6 Path (org.eclipse.core.runtime.Path)6 ILaunch (org.eclipse.debug.core.ILaunch)6 File (java.io.File)5 IOException (java.io.IOException)5 Map (java.util.Map)5 IProject (org.eclipse.core.resources.IProject)5 IResource (org.eclipse.core.resources.IResource)4 IStatus (org.eclipse.core.runtime.IStatus)4 List (java.util.List)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 WorkflowProject (com.centurylink.mdw.plugin.project.model.WorkflowProject)2