From 49c2109ff63c93c2e6e06ec6d2ef53e5b74e40e3 Mon Sep 17 00:00:00 2001 From: Jeff Date: Tue, 27 Jun 2017 13:01:18 -0700 Subject: [PATCH] Fix specs detection for Container Build feature - sometimes specs detection will be for a non-active build configuration so the project cannot be used to determine eligibility for the command launcher - change ICommandLauncherFactory to accept an object in its getCommandLauncher method which can either be an IProject or ICConfigurationDesription - change ContainerCommandLauncherFactory to accept an Object instead of IProject in its getCommandLauncher() method - cast the Object received either to be an IProject or ICConfigurationDescription to determine if the build should occur in a Container or not - fix CommandLauncherManager.getCommandLauncher() to accept and pass on an Object to the list of ICommandLauncherFactory instances - fix AbstractBuiltinSpecsDetector to pass in the current configuration description when getting the CommandLauncher since the current configuration may not be the active configuration --- .../AbstractBuiltinSpecsDetector.java | 4 ++-- .../cdt/core/CommandLauncherManager.java | 4 ++-- .../cdt/core/ICommandLauncherFactory.java | 8 ++++---- .../ContainerCommandLauncherFactory.java | 20 ++++++++++++++++--- 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/language/settings/providers/AbstractBuiltinSpecsDetector.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/language/settings/providers/AbstractBuiltinSpecsDetector.java index c89e5edf07b..ca31fcc4d65 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/language/settings/providers/AbstractBuiltinSpecsDetector.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/language/settings/providers/AbstractBuiltinSpecsDetector.java @@ -657,7 +657,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti } console.start(currentProject); - ICommandLauncher launcher = CommandLauncherManager.getInstance().getCommandLauncher(); + ICommandLauncher launcher = CommandLauncherManager.getInstance().getCommandLauncher(currentCfgDescription); launcher.setProject(currentProject); IPath program = new Path(""); //$NON-NLS-1$ @@ -766,7 +766,7 @@ public abstract class AbstractBuiltinSpecsDetector extends AbstractLanguageSetti // so collect them to save later when output finishes if (entries != null) { for (ICLanguageSettingEntry entry : entries) { - if (!detectedSettingEntries.contains(entry)) { + if (detectedSettingEntries != null && !detectedSettingEntries.contains(entry)) { detectedSettingEntries.add(entry); } } 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 1e6084a78ef..8378a371332 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 @@ -166,11 +166,11 @@ public class CommandLauncherManager { * @param project - optional input to determine launcher. * @return an ICommandLauncher for running commands */ - public ICommandLauncher getCommandLauncher(IProject project) { + public ICommandLauncher getCommandLauncher(Object object) { // loop through list of factories and return first launcher // returned for (ICommandLauncherFactory factory : factories) { - ICommandLauncher launcher = factory.getCommandLauncher(project); + ICommandLauncher launcher = factory.getCommandLauncher(object); if (launcher != null) { return 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 1eaf567000f..8ea8d5b4394 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 @@ -21,11 +21,11 @@ import org.eclipse.core.resources.IProject; public interface ICommandLauncherFactory { /** - * Get a Command Launcher for a project (optional) - * @param project - optional parameter to help determine appropriate launcher - * @return ICommandLauncher or null if not appropriate for project + * Get a Command Launcher for an object (IProject or IConfiguration) (optional) + * @param object - optional parameter to help determine appropriate launcher + * @return ICommandLauncher or null if not appropriate for object */ - public ICommandLauncher getCommandLauncher(IProject project); + public ICommandLauncher getCommandLauncher(Object object); /** * Register language setting entries for a project 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 8ed61068f76..a077584902d 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 @@ -39,10 +39,24 @@ public class ContainerCommandLauncherFactory implements ICommandLauncherFactory { @Override - public ICommandLauncher getCommandLauncher(IProject project) { + public ICommandLauncher getCommandLauncher(Object object) { // check if container build enablement has been checked - ICConfigurationDescription cfgd = CoreModel.getDefault() - .getProjectDescription(project).getActiveConfiguration(); + ICConfigurationDescription cfgd = null; + // We use an object because it could be an IProject, implying the + // active configuration, but it could be an ICConfigurationDescription + // as is used when computing specs for non-active configurations. We + // don't want to force callers to have to declare + // ICConfigurationDescription + // which is part of Managed build. + if (object instanceof IProject) { + IProject project = (IProject) object; + cfgd = CoreModel.getDefault().getProjectDescription(project) + .getActiveConfiguration(); + } else if (object instanceof ICConfigurationDescription) { + cfgd = (ICConfigurationDescription) object; + } else { + return null; + } IConfiguration cfg = ManagedBuildManager .getConfigurationForDescription(cfgd); IOptionalBuildProperties props = cfg.getOptionalBuildProperties();