Search in sources :

Example 1 with ILaunchConfigurationType

use of org.eclipse.debug.core.ILaunchConfigurationType in project jop by jop-devel.

the class JOPizer method createJOPizeLaunchConfiguration.

private ILaunchConfiguration createJOPizeLaunchConfiguration(String programArguments) throws CoreException {
    String configName = "JOPize";
    ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
    ILaunchConfigurationType type = manager.getLaunchConfigurationType(IJavaLaunchConfigurationConstants.ID_JAVA_APPLICATION);
    ILaunchConfiguration[] configs = manager.getLaunchConfigurations(type);
    for (ILaunchConfiguration config : configs) {
        if (config.getName().equals(configName)) {
            config.delete();
            break;
        }
    }
    ILaunchConfigurationWorkingCopy workingCopy = type.newInstance(null, configName);
    IVMInstall defaultVMInstall = JavaRuntime.getDefaultVMInstall();
    Map attributes = workingCopy.getAttributes();
    attributes.put(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, "com.jopdesign.build.JOPizer");
    attributes.put(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, programArguments);
    IPreferenceStore prefs = JOPUIPlugin.getDefault().getPreferenceStore();
    String jopHome = prefs.getString(IJOPLaunchConfigurationConstants.ATTR_JOP_HOME);
    IPath jopTools = new Path(jopHome).append(new Path("java/tools/dist/lib/jop-tools.jar"));
    IRuntimeClasspathEntry jopToolsEntry = JavaRuntime.newArchiveRuntimeClasspathEntry(jopTools);
    jopToolsEntry.setClasspathProperty(IRuntimeClasspathEntry.USER_CLASSES);
    IPath jopClasses = new Path(jopHome).append(new Path("java/target/dist/lib/classes.zip"));
    IRuntimeClasspathEntry jopClassesEntry = JavaRuntime.newArchiveRuntimeClasspathEntry(jopClasses);
    jopClassesEntry.setClasspathProperty(IRuntimeClasspathEntry.USER_CLASSES);
    // IClasspathEntry jreEntry = JavaRuntime.getDefaultJREContainerEntry();
    List<String> classpath = new ArrayList<String>();
    classpath.add(jopToolsEntry.getMemento());
    classpath.add(jopClassesEntry.getMemento());
    // classpath.add(jreEntry.get)
    attributes.put(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH, classpath);
    attributes.put(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, false);
    attributes.put(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, "-Dmgci=false");
    workingCopy.setAttributes(attributes);
    System.err.printf("> %s%n", workingCopy.toString());
    return workingCopy;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) ILaunchManager(org.eclipse.debug.core.ILaunchManager) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) IRuntimeClasspathEntry(org.eclipse.jdt.launching.IRuntimeClasspathEntry) IVMInstall(org.eclipse.jdt.launching.IVMInstall) ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) Map(java.util.Map)

Example 2 with ILaunchConfigurationType

use of org.eclipse.debug.core.ILaunchConfigurationType in project tdi-studio-se by Talend.

the class JobLaunchShortcut method createConfiguration.

/**
     * Creates a new configuration associated with the given file.
     * 
     * @param file
     * @return ILaunchConfiguration
     */
private ILaunchConfiguration createConfiguration(ProcessItem file) {
    ILaunchConfiguration config = null;
    String jobId = file.getProperty().getId();
    String jobName = file.getProperty().getLabel();
    String jobVersion = file.getProperty().getVersion();
    ILaunchConfigurationType type = getLaunchManager().getLaunchConfigurationType(TalendDebugUIConstants.JOB_DEBUG_LAUNCH_CONFIGURATION_TYPE);
    //$NON-NLS-1$
    String displayName = jobName + " " + jobVersion;
    try {
        if (type != null) {
            ILaunchConfigurationWorkingCopy wc = type.newInstance(null, getLaunchManager().generateUniqueLaunchConfigurationNameFrom(displayName));
            wc.setAttribute(TalendDebugUIConstants.JOB_NAME, jobName);
            wc.setAttribute(TalendDebugUIConstants.JOB_ID, jobId);
            wc.setAttribute(TalendDebugUIConstants.JOB_VERSION, jobVersion);
            String projectName = ProjectManager.getInstance().getCurrentProject().getLabel();
            wc.setAttribute(TalendDebugUIConstants.CURRENT_PROJECT_NAME, projectName);
            config = wc.doSave();
        }
    } catch (CoreException e) {
        ExceptionHandler.process(e);
    }
    return config;
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) CoreException(org.eclipse.core.runtime.CoreException) ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)

Example 3 with ILaunchConfigurationType

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

the class LaunchConfigurationUtils method createDockerComposeUpLaunchConfiguration.

/**
 * Creates an {@link ILaunchConfiguration} for to run the
 * {@code docker-compose up} command.
 *
 * @param connection
 *            the Docker connection to use
 * @param dockerComposeScript
 *            the {@code docker-compose.yml} script
 * @return the created {@link ILaunchConfiguration}
 * @throws CoreException
 *             if something wrong happened when creating the
 *             {@link ILaunchConfiguration}
 */
public static ILaunchConfiguration createDockerComposeUpLaunchConfiguration(final IDockerConnection connection, final IResource dockerComposeScript) throws CoreException {
    final ILaunchConfigurationType configType = LaunchConfigurationUtils.getLaunchConfigType(IDockerComposeLaunchConfigurationConstants.CONFIG_TYPE_ID);
    final ILaunchConfigurationWorkingCopy wc = configType.newInstance(null, DebugPlugin.getDefault().getLaunchManager().generateLaunchConfigurationName(createDockerComposeLaunchConfigurationName(dockerComposeScript)));
    wc.setAttribute(IDockerComposeLaunchConfigurationConstants.WORKING_DIR, dockerComposeScript.getFullPath().removeLastSegments(1).toString());
    wc.setAttribute(IDockerComposeLaunchConfigurationConstants.WORKING_DIR_WORKSPACE_RELATIVE_LOCATION, true);
    wc.setAttribute(IDockerComposeLaunchConfigurationConstants.DOCKER_CONNECTION, connection.getName());
    return wc.doSave();
}
Also used : ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)

Example 4 with ILaunchConfigurationType

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

the class LaunchConfigurationUtils method createRunImageLaunchConfiguration.

/**
 * Creates a new {@link ILaunchConfiguration} for the given
 * {@link IDockerContainer}.
 *
 * @param baseConfigurationName
 *            the base configuration name to use when creating the
 *            {@link ILaunchConfiguration}.
 * @param image
 *            the {@link IDockerImage} used to create the container
 * @param containerName
 *            the actual container name (given by the user or generated by
 *            the Docker daemon)
 * @param containerConfig
 * @param hostConfig
 *            the user-provided {@link IDockerHostConfig} (created
 *            container's one)
 * @param removeWhenExits
 *            flag to indicate if container should be removed when exited
 * @return the generated {@link ILaunchConfiguration}
 */
public static ILaunchConfiguration createRunImageLaunchConfiguration(final IDockerImage image, final IDockerContainerConfig containerConfig, final IDockerHostConfig hostConfig, final String containerName, final boolean removeWhenExits) {
    try {
        final ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
        final ILaunchConfigurationType type = manager.getLaunchConfigurationType(IRunDockerImageLaunchConfigurationConstants.CONFIG_TYPE_ID);
        final String imageName = createRunImageLaunchConfigurationName(image);
        // using the image repo + first tag
        final ILaunchConfigurationWorkingCopy workingCopy = getLaunchConfigurationWorkingCopy(type, imageName);
        workingCopy.setAttribute(CREATION_DATE, DATE_FORMAT.format(new Date()));
        workingCopy.setAttribute(CONNECTION_NAME, image.getConnection().getName());
        workingCopy.setAttribute(IMAGE_ID, image.id());
        workingCopy.setAttribute(IMAGE_NAME, createRunImageLaunchConfigurationName(image));
        if (containerName != null && !containerName.isEmpty()) {
            workingCopy.setAttribute(CONTAINER_NAME, containerName);
        }
        // if we know the raw command string, use it since the container
        // config will remove quotes to split up command properly
        DockerContainerConfig config = (DockerContainerConfig) containerConfig;
        if (config.rawcmd() != null) {
            workingCopy.setAttribute(COMMAND, config.rawcmd());
        } else {
            workingCopy.setAttribute(COMMAND, toString(containerConfig.cmd()));
        }
        workingCopy.setAttribute(ENTRYPOINT, toString(containerConfig.entrypoint()));
        // selected ports
        workingCopy.setAttribute(PUBLISH_ALL_PORTS, hostConfig.publishAllPorts());
        // format: <containerPort><type>:<hostIP>:<hostPort>
        if (hostConfig.publishAllPorts()) {
            final IDockerImageInfo imageInfo = image.getConnection().getImageInfo(image.id());
            if (imageInfo != null) {
                workingCopy.setAttribute(PUBLISHED_PORTS, serializePortBindings(imageInfo.containerConfig().exposedPorts()));
            }
        } else {
            workingCopy.setAttribute(PUBLISHED_PORTS, serializePortBindings(hostConfig.portBindings()));
        }
        // links (with format being: "<containerName>:<containerAlias>")
        workingCopy.setAttribute(LINKS, hostConfig.links());
        // env variables
        workingCopy.setAttribute(ENV_VARIABLES, containerConfig.env());
        // labels
        workingCopy.setAttribute(LABELS, containerConfig.labels());
        // volumes
        final List<String> volumes = new ArrayList<>();
        // volumes from other containers
        for (String volumeFrom : hostConfig.volumesFrom()) {
            final DataVolumeModel volume = DataVolumeModel.parseVolumeFrom(volumeFrom);
            if (volume != null) {
                volumes.add(volume.toString());
            }
        }
        // bindings to host directory or file
        for (String bind : hostConfig.binds()) {
            final DataVolumeModel volume = DataVolumeModel.parseHostBinding(bind);
            if (volume != null) {
                volumes.add(volume.toString());
            }
        }
        // TODO: container path declaration
        workingCopy.setAttribute(DATA_VOLUMES, volumes);
        // options
        workingCopy.setAttribute(AUTO_REMOVE, removeWhenExits);
        workingCopy.setAttribute(ALLOCATE_PSEUDO_CONSOLE, containerConfig.tty());
        workingCopy.setAttribute(INTERACTIVE, containerConfig.openStdin());
        workingCopy.setAttribute(PRIVILEGED, hostConfig.privileged());
        workingCopy.setAttribute(READONLY, ((DockerHostConfig) hostConfig).readonlyRootfs());
        if (hostConfig.networkMode() != null)
            workingCopy.setAttribute(NETWORK_MODE, hostConfig.networkMode());
        // resources limitations
        if (containerConfig.memory() != null) {
            workingCopy.setAttribute(ENABLE_LIMITS, true);
            // memory in containerConfig is expressed in bytes
            workingCopy.setAttribute(MEMORY_LIMIT, Long.toString(containerConfig.memory().longValue() / MB));
        }
        if (containerConfig.cpuShares() != null) {
            workingCopy.setAttribute(ENABLE_LIMITS, true);
            workingCopy.setAttribute(CPU_PRIORITY, containerConfig.cpuShares().toString());
        }
        return workingCopy.doSave();
    } catch (CoreException e) {
        Activator.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, LaunchMessages.getString(// $NON-NLS-1$
        "RunDockerImageLaunchConfiguration.creation.failure"), e));
    }
    return null;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) DataVolumeModel(org.eclipse.linuxtools.internal.docker.ui.wizards.DataVolumeModel) DockerContainerConfig(org.eclipse.linuxtools.internal.docker.core.DockerContainerConfig) IDockerContainerConfig(org.eclipse.linuxtools.docker.core.IDockerContainerConfig) CoreException(org.eclipse.core.runtime.CoreException) ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) ArrayList(java.util.ArrayList) ILaunchManager(org.eclipse.debug.core.ILaunchManager) IDockerImageInfo(org.eclipse.linuxtools.docker.core.IDockerImageInfo) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) Date(java.util.Date)

Example 5 with ILaunchConfigurationType

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

the class PerfOpenData method createDefaultConfiguration.

/**
 * Create an ILaunchConfiguration instance given the project's name.
 *
 * @param projectName
 * @return ILaunchConfiguration based on String projectName
 */
private ILaunchConfiguration createDefaultConfiguration(String projectName) {
    ILaunchConfiguration config = null;
    try {
        ILaunchConfigurationType configType = getLaunchConfigType();
        ILaunchConfigurationWorkingCopy wc = configType.newInstance(null, getLaunchManager().generateLaunchConfigurationName(projectName));
        wc.setAttribute(ICDTLaunchConfigurationConstants.ATTR_PROJECT_NAME, projectName);
        config = wc;
    } catch (CoreException e) {
        PerfCore.logException(e);
    }
    return config;
}
Also used : ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) CoreException(org.eclipse.core.runtime.CoreException) ILaunchConfigurationType(org.eclipse.debug.core.ILaunchConfigurationType) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)

Aggregations

ILaunchConfigurationType (org.eclipse.debug.core.ILaunchConfigurationType)86 ILaunchConfigurationWorkingCopy (org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)57 ILaunchManager (org.eclipse.debug.core.ILaunchManager)52 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)48 CoreException (org.eclipse.core.runtime.CoreException)41 ArrayList (java.util.ArrayList)20 IPath (org.eclipse.core.runtime.IPath)8 HashMap (java.util.HashMap)6 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 Map (java.util.Map)5 IProject (org.eclipse.core.resources.IProject)5 List (java.util.List)4 IResource (org.eclipse.core.resources.IResource)4 IStatus (org.eclipse.core.runtime.IStatus)4 IOException (java.io.IOException)3 WorkflowProject (com.centurylink.mdw.plugin.project.model.WorkflowProject)2 LaunchHelper (com.liferay.ide.core.util.LaunchHelper)2