Search in sources :

Example 61 with ILaunchConfigurationWorkingCopy

use of org.eclipse.debug.core.ILaunchConfigurationWorkingCopy in project bndtools by bndtools.

the class OSGiJUnitLaunchDelegate method getLaunch.

// A couple of hacks to make sure the JUnit plugin is active and notices our
// launch.
@Override
public ILaunch getLaunch(ILaunchConfiguration configuration, String mode) throws CoreException {
    // start the JUnit plugin
    try {
        Bundle jdtJUnitBundle = BundleUtils.findBundle(Plugin.getDefault().getBundleContext(), JDT_JUNIT_BSN, null);
        if (jdtJUnitBundle == null)
            throw new CoreException(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, MessageFormat.format("Bundle \"{0}\" was not found. Cannot report JUnit results via the Workbench.", JDT_JUNIT_BSN), null));
        jdtJUnitBundle.start();
    } catch (BundleException e) {
        throw new CoreException(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, MessageFormat.format("Error starting bundle \"{0}\". Cannot report JUnit results via the Workbench.", JDT_JUNIT_BSN), null));
    }
    // JUnit plugin ignores the launch unless attribute
    // "org.eclipse.jdt.launching.PROJECT_ATTR" is set.
    ILaunchConfigurationWorkingCopy modifiedConfig = configuration.getWorkingCopy();
    IResource launchResource = LaunchUtils.getTargetResource(configuration);
    if (launchResource != null) {
        String launchProjectName = LaunchUtils.getLaunchProjectName(launchResource);
        IProject launchProject = ResourcesPlugin.getWorkspace().getRoot().getProject(launchProjectName);
        if (!launchProject.exists()) {
            launchProjectName = launchResource.getProject().getName();
        }
        modifiedConfig.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, launchProjectName);
    }
    return super.getLaunch(modifiedConfig.doSave(), mode);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) CoreException(org.eclipse.core.runtime.CoreException) Bundle(org.osgi.framework.Bundle) BundleException(org.osgi.framework.BundleException) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject)

Example 62 with ILaunchConfigurationWorkingCopy

use of org.eclipse.debug.core.ILaunchConfigurationWorkingCopy in project bndtools by bndtools.

the class AbstractLaunchShortcut method launch.

protected void launch(IPath targetPath, IProject targetProject, String mode) {
    IPath tp = targetPath.makeRelative();
    try {
        ILaunchConfiguration config = findLaunchConfig(tp);
        if (config == null) {
            ILaunchConfigurationWorkingCopy wc = createConfiguration(tp, targetProject);
            config = wc.doSave();
        }
        DebugUITools.launch(config, mode);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) IPath(org.eclipse.core.runtime.IPath) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) JavaModelException(org.eclipse.jdt.core.JavaModelException) CoreException(org.eclipse.core.runtime.CoreException)

Example 63 with ILaunchConfigurationWorkingCopy

use of org.eclipse.debug.core.ILaunchConfigurationWorkingCopy in project bndtools by bndtools.

the class AbstractLaunchShortcut method createConfiguration.

protected ILaunchConfigurationWorkingCopy createConfiguration(IPath targetPath, IProject targetProject) throws CoreException {
    ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
    ILaunchConfigurationType configType = manager.getLaunchConfigurationType(launchId);
    ILaunchConfigurationWorkingCopy wc;
    wc = configType.newInstance(null, manager.generateLaunchConfigurationName(targetPath.lastSegment()));
    wc.setAttribute(LaunchConstants.ATTR_LAUNCH_TARGET, targetPath.toString());
    wc.setAttribute(LaunchConstants.ATTR_CLEAN, LaunchConstants.DEFAULT_CLEAN);
    wc.setAttribute(LaunchConstants.ATTR_DYNAMIC_BUNDLES, LaunchConstants.DEFAULT_DYNAMIC_BUNDLES);
    if (targetProject != null) {
        IJavaProject javaProject = JavaCore.create(targetProject);
        if (javaProject.exists()) {
            wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, targetProject.getName());
        }
    }
    return wc;
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) ILaunchManager(org.eclipse.debug.core.ILaunchManager) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)

Example 64 with ILaunchConfigurationWorkingCopy

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

the class LaunchConfigurationUtils method updateLaunchConfigurations.

/**
 * Updates all {@link ILaunchConfiguration} of the given {@code type} where
 * there is an attribute with the given {@code attributeName} of the given
 * {@code oldValue}, and sets the {@code newValue} instead.
 *
 * @param type
 *            the type of {@link ILaunchConfiguration} to find
 * @param attributeName
 *            the name of the attribute to look-up
 * @param oldValue
 *            the old value to match
 * @param newValue
 *            the new value to set
 */
public static void updateLaunchConfigurations(final String type, final String attributeName, final String oldValue, final String newValue) {
    final ILaunchConfigurationType configType = LaunchConfigurationUtils.getLaunchConfigType(type);
    final ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
    try {
        for (ILaunchConfiguration config : manager.getLaunchConfigurations(configType)) {
            try {
                if (// $NON-NLS-1$
                config.getAttribute(attributeName, "").equals(oldValue)) {
                    final ILaunchConfigurationWorkingCopy workingCopy = config.getWorkingCopy();
                    workingCopy.setAttribute(attributeName, newValue);
                    workingCopy.doSave();
                }
            } catch (CoreException e) {
                Activator.logErrorMessage(LaunchMessages.getFormattedString(// $NON-NLS-1$
                "UpdateLaunchConfiguration.named.error", config.getName()), e);
            }
        }
    } catch (CoreException e) {
        Activator.logErrorMessage(// $NON-NLS-1$
        LaunchMessages.getString(// $NON-NLS-1$
        "UpdateLaunchConfiguration.error"), e);
        Activator.logErrorMessage("Failed to retrieve launch configurations after connection name changed", e);
    }
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) CoreException(org.eclipse.core.runtime.CoreException) ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) ILaunchManager(org.eclipse.debug.core.ILaunchManager) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)

Example 65 with ILaunchConfigurationWorkingCopy

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

the class LaunchConfigurationUtils method createBuildImageLaunchConfiguration.

/**
 * Creates a new {@link ILaunchConfiguration} to build an
 * {@link IDockerImage} from a Dockerfile {@link IResource}.
 *
 * @param connection
 *            the connection to use to submit the build
 * @param repoName
 *            the repo/name of the {@link IDockerImage} to build
 * @param dockerfile
 *            the dockerfile to use to build the {@link IDockerImage}
 * @return the created {@link ILaunchConfiguration}
 * @throws CoreException
 */
public static ILaunchConfiguration createBuildImageLaunchConfiguration(final IDockerConnection connection, final String repoName, final IResource dockerfile) throws CoreException {
    final ILaunchConfigurationType configType = LaunchConfigurationUtils.getLaunchConfigType(IBuildDockerImageLaunchConfigurationConstants.CONFIG_TYPE_ID);
    final ILaunchConfigurationWorkingCopy wc = getLaunchConfigurationWorkingCopy(configType, createBuildImageLaunchConfigurationName(repoName, dockerfile));
    wc.setAttribute(IBuildDockerImageLaunchConfigurationConstants.SOURCE_PATH_LOCATION, dockerfile.getFullPath().removeLastSegments(1).toString());
    wc.setAttribute(IBuildDockerImageLaunchConfigurationConstants.SOURCE_PATH_WORKSPACE_RELATIVE_LOCATION, true);
    wc.setAttribute(IDockerImageBuildOptions.DOCKER_CONNECTION, connection.getName());
    wc.setAttribute(IDockerImageBuildOptions.REPO_NAME, repoName);
    return wc.doSave();
}
Also used : ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)

Aggregations

ILaunchConfigurationWorkingCopy (org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)119 Test (org.junit.Test)75 ILaunch (org.eclipse.debug.core.ILaunch)52 IProcess (org.eclipse.debug.core.model.IProcess)49 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)29 ILaunchConfigurationType (org.eclipse.debug.core.ILaunchConfigurationType)18 CoreException (org.eclipse.core.runtime.CoreException)16 IPath (org.eclipse.core.runtime.IPath)12 ILaunchManager (org.eclipse.debug.core.ILaunchManager)10 AbstractTest (org.eclipse.linuxtools.profiling.tests.AbstractTest)8 IProject (org.eclipse.core.resources.IProject)7 Shell (org.eclipse.swt.widgets.Shell)7 ArrayList (java.util.ArrayList)6 Path (org.eclipse.core.runtime.Path)6 ILaunchConfigurationTab (org.eclipse.debug.ui.ILaunchConfigurationTab)5 Version (org.osgi.framework.Version)5 IResource (org.eclipse.core.resources.IResource)4 Launch (org.eclipse.debug.core.Launch)3 MassifViewPart (org.eclipse.linuxtools.internal.valgrind.massif.MassifViewPart)3 Button (org.eclipse.swt.widgets.Button)3