diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CommandLauncherManager.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CommandLauncherManager.java index a090891c4aa..c8e9bd83922 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CommandLauncherManager.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CommandLauncherManager.java @@ -17,6 +17,7 @@ import java.util.List; import java.util.Map; import java.util.Properties; +import org.eclipse.cdt.core.build.ICBuildConfiguration; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.core.resources.IProject; @@ -34,6 +35,8 @@ import org.eclipse.core.runtime.Platform; */ public class CommandLauncherManager { + public final static String CONTAINER_BUILD_ENABLED = "container.build.enabled"; //$NON-NLS-1$ + private static CommandLauncherManager instance; private List factories = new ArrayList<>(); @@ -187,6 +190,32 @@ public class CommandLauncherManager { return new CommandLauncher(); } + /** + * Get a command launcher. + * + * @param config - ICBuildConfiguration to determine launcher for. + * @return an ICommandLauncher for running commands + */ + public ICommandLauncher getCommandLauncher(ICBuildConfiguration config) { + // loop through list of factories and return launcher returned with + // highest priority + int highestPriority = -1; + ICommandLauncher bestLauncher = null; + for (ICommandLauncherFactory factory : factories) { + ICommandLauncher launcher = factory.getCommandLauncher(config); + if (launcher != null) { + if (priorityMapping.get(factory) > highestPriority) { + bestLauncher = launcher; + } + } + } + if (bestLauncher != null) { + return bestLauncher; + } + // default to local CommandLauncher + return new CommandLauncher(); + } + /** * Get a command launcher. * diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICommandLauncherFactory.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICommandLauncherFactory.java index e1399886f78..7ab4429e920 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICommandLauncherFactory.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/ICommandLauncherFactory.java @@ -12,6 +12,7 @@ package org.eclipse.cdt.core; import java.util.List; +import org.eclipse.cdt.core.build.ICBuildConfiguration; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.core.resources.IProject; @@ -35,6 +36,15 @@ public interface ICommandLauncherFactory { */ public ICommandLauncher getCommandLauncher(ICConfigurationDescription cfgd); + /** + * Get a Command Launcher for a build configuration descriptor + * @param cfg - ICBuildConfiguration to get command launcher for + * @return ICommandLauncher or null + */ + public default ICommandLauncher getCommandLauncher(ICBuildConfiguration cfg) { + return null; + } + /** * Register language setting entries for a project * @param project - IProject used in obtaining language setting entries diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/ICBuildCommandLauncher.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/ICBuildCommandLauncher.java new file mode 100644 index 00000000000..8171fb9c0b8 --- /dev/null +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/ICBuildCommandLauncher.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2018 Red Hat Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Red Hat Inc. - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.core.build; + +public interface ICBuildCommandLauncher { + + /** + * Get registered CBuildConfiguration + * + * @return ICBuildConfiguration or null + */ + public ICBuildConfiguration getBuildConfiguration(); + + /** + * Register a CBuildConfiguration for this command launcher + * + * @param config - CBuildConfiguration to register + */ + public void setBuildConfiguration(ICBuildConfiguration config); + +} diff --git a/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/docker/launcher/ContainerCommandLauncher.java b/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/docker/launcher/ContainerCommandLauncher.java index 43a906fd8a2..003ae70cbda 100644 --- a/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/docker/launcher/ContainerCommandLauncher.java +++ b/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/docker/launcher/ContainerCommandLauncher.java @@ -11,6 +11,8 @@ import java.util.Map; import java.util.Properties; import org.eclipse.cdt.core.ICommandLauncher; +import org.eclipse.cdt.core.build.ICBuildCommandLauncher; +import org.eclipse.cdt.core.build.ICBuildConfiguration; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.internal.core.ProcessClosure; @@ -35,7 +37,8 @@ import org.osgi.service.prefs.Preferences; @SuppressWarnings("restriction") public class ContainerCommandLauncher - implements ICommandLauncher, IErrorMessageHolder { + implements ICommandLauncher, ICBuildCommandLauncher, + IErrorMessageHolder { public final static String CONTAINER_BUILD_ENABLED = DockerLaunchUIPlugin.PLUGIN_ID + ".containerbuild.property.enablement"; //$NON-NLS-1$ @@ -55,6 +58,7 @@ public class ContainerCommandLauncher private boolean fShowCommand; private String fErrorMessage; private Properties fEnvironment; + private ICBuildConfiguration fBuildConfig; private String[] commandArgs; private String fImageName = ""; //$NON-NLS-1$ @@ -81,6 +85,16 @@ public class ContainerCommandLauncher return fProject; } + @Override + public void setBuildConfiguration(ICBuildConfiguration config) { + this.fBuildConfig = config; + } + + @Override + public ICBuildConfiguration getBuildConfiguration() { + return fBuildConfig; + } + @SuppressWarnings("unused") private String getImageName() { return fImageName; @@ -236,17 +250,30 @@ public class ContainerCommandLauncher boolean keepContainer = prefs.getBoolean( PreferenceConstants.KEEP_CONTAINER_AFTER_LAUNCH, false); - ICConfigurationDescription cfgd = CoreModel.getDefault() - .getProjectDescription(fProject).getActiveConfiguration(); - IConfiguration cfg = ManagedBuildManager - .getConfigurationForDescription(cfgd); - if (cfg == null) { - return null; + ICBuildConfiguration buildCfg = getBuildConfiguration(); + String selectedVolumeString = null; + String connectionName = null; + String imageName = null; + if (buildCfg != null) { + selectedVolumeString = buildCfg.getProperty(SELECTED_VOLUMES_ID); + connectionName = buildCfg.getProperty(CONNECTION_ID); + imageName = buildCfg.getProperty(IMAGE_ID); + } else { + ICConfigurationDescription cfgd = CoreModel.getDefault() + .getProjectDescription(fProject).getActiveConfiguration(); + IConfiguration cfg = ManagedBuildManager + .getConfigurationForDescription(cfgd); + if (cfg == null) { + return null; + } + IOptionalBuildProperties props = cfg.getOptionalBuildProperties(); + selectedVolumeString = props.getProperty(SELECTED_VOLUMES_ID); + connectionName = props + .getProperty(ContainerCommandLauncher.CONNECTION_ID); + imageName = props.getProperty(ContainerCommandLauncher.IMAGE_ID); } - IOptionalBuildProperties props = cfg.getOptionalBuildProperties(); // Add any specified volumes to additional dir list - String selectedVolumeString = props.getProperty(SELECTED_VOLUMES_ID); if (selectedVolumeString != null && !selectedVolumeString.isEmpty()) { String[] selectedVolumes = selectedVolumeString .split(VOLUME_SEPARATOR_REGEX); @@ -264,13 +291,9 @@ public class ContainerCommandLauncher } } - String connectionName = props - .getProperty(ContainerCommandLauncher.CONNECTION_ID); if (connectionName == null) { return null; } - String imageName = props - .getProperty(ContainerCommandLauncher.IMAGE_ID); if (imageName == null) { return null; } diff --git a/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/docker/launcher/ContainerCommandLauncherFactory.java b/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/docker/launcher/ContainerCommandLauncherFactory.java index fa1bae38e19..4c0d8079b45 100644 --- a/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/docker/launcher/ContainerCommandLauncherFactory.java +++ b/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/docker/launcher/ContainerCommandLauncherFactory.java @@ -16,10 +16,12 @@ import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.Set; import org.eclipse.cdt.core.ICommandLauncher; import org.eclipse.cdt.core.ICommandLauncherFactory; +import org.eclipse.cdt.core.build.ICBuildConfiguration; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.settings.model.CIncludePathEntry; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; @@ -93,6 +95,26 @@ public class ContainerCommandLauncherFactory return null; } + @Override + public ICommandLauncher getCommandLauncher(ICBuildConfiguration cfgd) { + // check if container build enablement has been checked + Map props = cfgd.getProperties(); + if (props != null) { + String enablementProperty = props + .get(ContainerCommandLauncher.CONTAINER_BUILD_ENABLED); + if (enablementProperty != null) { + boolean enableContainer = Boolean + .parseBoolean(enablementProperty); + // enablement has occurred, we can return a + // ContainerCommandLauncher + if (enableContainer) { + return new ContainerCommandLauncher(); + } + } + } + return null; + } + @Override public void registerLanguageSettingEntries(IProject project, List langEntries) { diff --git a/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/internal/docker/launcher/ContainerTab.java b/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/internal/docker/launcher/ContainerTab.java index 26b6915b331..ab76710de35 100644 --- a/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/internal/docker/launcher/ContainerTab.java +++ b/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/internal/docker/launcher/ContainerTab.java @@ -82,7 +82,6 @@ public class ContainerTab extends AbstractLaunchConfigurationTab implements connectionUri = connection.getUri(); if (!connectionName.equals(connection.getName())) { setErrorMessage(null); - updateLaunchConfigurationDialog(); initializeImageCombo(); } connectionName = connection.getName();