From 379e33af43ddae0181320cc0ba86c17d714019a7 Mon Sep 17 00:00:00 2001 From: Jeff Date: Wed, 28 Jun 2017 14:37:02 -0700 Subject: [PATCH] More Windows fixes for Container build - change ICommandLauncherFactory to have two getCommandLauncher() methods that take an IProject and an ICConfigurationDescription rather than one method that takes an Object - change CommandLauncherManager and ContainerCommandLauncherFactory classes to have the same two methods - fix ContainerPropertyTab to add Elf and GNU Elf binary parsers when build in Container is chosen so that output executables are treated as Binaries by the CDT project --- .../cdt/core/CommandLauncherManager.java | 27 +++++++++++-- .../cdt/core/ICommandLauncherFactory.java | 16 ++++++-- .../ContainerCommandLauncherFactory.java | 40 ++++++++++++------- .../docker/launcher/ContainerPropertyTab.java | 33 +++++++++++++-- 4 files changed, 90 insertions(+), 26 deletions(-) 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 8378a371332..a1b36ce78c4 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 @@ -15,6 +15,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Properties; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; @@ -160,17 +161,37 @@ public class CommandLauncherManager { } } + /** * Get a command launcher. * - * @param project - optional input to determine launcher. + * @param project - IProject to determine launcher for. * @return an ICommandLauncher for running commands */ - public ICommandLauncher getCommandLauncher(Object object) { + public ICommandLauncher getCommandLauncher(IProject project) { // loop through list of factories and return first launcher // returned for (ICommandLauncherFactory factory : factories) { - ICommandLauncher launcher = factory.getCommandLauncher(object); + ICommandLauncher launcher = factory.getCommandLauncher(project); + if (launcher != null) { + return launcher; + } + } + // default to local CommandLauncher + return new CommandLauncher(); + } + + /** + * Get a command launcher. + * + * @param cfgd - ICConfigurationDescription to get command launcher for. + * @return an ICommandLauncher for running commands + */ + public ICommandLauncher getCommandLauncher(ICConfigurationDescription cfgd) { + // loop through list of factories and return first launcher + // returned + for (ICommandLauncherFactory factory : factories) { + ICommandLauncher launcher = factory.getCommandLauncher(cfgd); 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 8ea8d5b4394..7da2397e784 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.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.core.resources.IProject; @@ -21,11 +22,18 @@ import org.eclipse.core.resources.IProject; public interface ICommandLauncherFactory { /** - * 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 + * Get a Command Launcher for a project (based on active configuration) + * @param project - IProject to get command launcher for + * @return ICommandLauncher */ - public ICommandLauncher getCommandLauncher(Object object); + public ICommandLauncher getCommandLauncher(IProject project); + + /** + * Get a Command Launcher for a build configuration descriptor + * @param cfgd - ICConfigurationDescription to get command launcher for + * @return ICommandLauncher + */ + public ICommandLauncher getCommandLauncher(ICConfigurationDescription cfgd); /** * 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 a077584902d..a5453eeb8c8 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,24 +39,34 @@ public class ContainerCommandLauncherFactory implements ICommandLauncherFactory { @Override - public ICommandLauncher getCommandLauncher(Object object) { + public ICommandLauncher getCommandLauncher(IProject project) { // check if container build enablement has been checked - 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) + ICConfigurationDescription 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(); + if (props != null) { + String enablementProperty = props.getProperty( + 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 ICommandLauncher getCommandLauncher( + ICConfigurationDescription cfgd) { + // check if container build enablement has been checked IConfiguration cfg = ManagedBuildManager .getConfigurationForDescription(cfgd); IOptionalBuildProperties props = cfg.getOptionalBuildProperties(); diff --git a/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/internal/docker/launcher/ContainerPropertyTab.java b/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/internal/docker/launcher/ContainerPropertyTab.java index 3d2496f4eba..247c8a63869 100644 --- a/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/internal/docker/launcher/ContainerPropertyTab.java +++ b/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/internal/docker/launcher/ContainerPropertyTab.java @@ -12,6 +12,7 @@ package org.eclipse.cdt.internal.docker.launcher; import java.io.File; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -21,9 +22,11 @@ import java.util.Set; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvider; import org.eclipse.cdt.core.language.settings.providers.ILanguageSettingsProvidersKeeper; +import org.eclipse.cdt.core.model.CoreModelUtil; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICMultiConfigDescription; import org.eclipse.cdt.core.settings.model.ICResourceDescription; +import org.eclipse.cdt.core.settings.model.ICTargetPlatformSetting; import org.eclipse.cdt.internal.docker.launcher.ContainerPropertyVolumesModel.MountType; import org.eclipse.cdt.managedbuilder.buildproperties.IOptionalBuildProperties; import org.eclipse.cdt.managedbuilder.core.IConfiguration; @@ -82,6 +85,9 @@ public class ContainerPropertyTab extends AbstractCBuildPropertyTab public final static String VOLUME_SEPARATOR = "|"; //$NON-NLS-1$ + private final static String GNU_ELF_PARSER_ID = "org.eclipse.cdt.core.GNU_ELF"; //$NON-NLS-1$ + private final static String ELF_PARSER_ID = "org.eclipse.cdt.core.ELF"; //$NON-NLS-1$ + private Combo imageCombo; private Combo connectionSelector; private Button enableButton; @@ -104,6 +110,7 @@ public class ContainerPropertyTab extends AbstractCBuildPropertyTab private List displayedImages = new ArrayList<>(); private IConfiguration iCfg; + private ICConfigurationDescription iCfgd; private final DataBindingContext dbc = new DataBindingContext(); private final ContainerPropertyVolumesModel model; @@ -156,6 +163,7 @@ public class ContainerPropertyTab extends AbstractCBuildPropertyTab enableButton.setText(Messages.ContainerPropertyTab_Enable_Msg); iCfg = getCfg(); + iCfgd = getResDesc().getConfiguration(); gd = new GridData(GridData.FILL_HORIZONTAL); gd.horizontalSpan = 5; @@ -572,6 +580,20 @@ public class ContainerPropertyTab extends AbstractCBuildPropertyTab p.setProperty(ContainerCommandLauncher.CONTAINER_BUILD_ENABLED, Boolean.toString(enableButton.getSelection())); } + // if enabled, make sure we have ELF binary parsers specified + if (enabled) { + String[] ids = CoreModelUtil + .getBinaryParserIds(page.getCfgsEditable()); + List idList = new ArrayList<>(Arrays.asList(ids)); + if (!idList.contains(GNU_ELF_PARSER_ID)) { + idList.add(GNU_ELF_PARSER_ID); + } + if (!idList.contains(ELF_PARSER_ID)) { + idList.add(ELF_PARSER_ID); + } + CoreModelUtil.setBinaryParserIds(page.getCfgsEditable(), + idList.toArray(new String[0])); + } } private void setImageId(String imageId) { @@ -783,6 +805,12 @@ public class ContainerPropertyTab extends AbstractCBuildPropertyTab IOptionalBuildProperties prop1 = cfg01.getOptionalBuildProperties(); IOptionalBuildProperties prop2 = cfg02.getOptionalBuildProperties(); boolean needToRecalculate = false; + + ICTargetPlatformSetting tps = c1.getTargetPlatformSetting(); + String[] pids = tps.getBinaryParserIds(); + ICTargetPlatformSetting tps2 = c2.getTargetPlatformSetting(); + tps2.setBinaryParserIds(pids); + String enablementProperty = prop1 .getProperty(ContainerCommandLauncher.CONTAINER_BUILD_ENABLED); String enablementProperty2 = prop2 @@ -816,14 +844,10 @@ public class ContainerPropertyTab extends AbstractCBuildPropertyTab String volumesProperty = prop1 .getProperty(ContainerCommandLauncher.VOLUMES_ID); - String volumesProperty2 = prop2 - .getProperty(ContainerCommandLauncher.VOLUMES_ID); prop2.setProperty(ContainerCommandLauncher.VOLUMES_ID, volumesProperty); String selectedVolumesProperty = prop1 .getProperty(ContainerCommandLauncher.SELECTED_VOLUMES_ID); - String selectedVolumesProperty2 = prop2 - .getProperty(ContainerCommandLauncher.SELECTED_VOLUMES_ID); prop2.setProperty(ContainerCommandLauncher.SELECTED_VOLUMES_ID, selectedVolumesProperty); @@ -944,6 +968,7 @@ public class ContainerPropertyTab extends AbstractCBuildPropertyTab if (cfgd == null) return; iCfg = getCfg(cfgd.getConfiguration()); + iCfgd = cfgd.getConfiguration(); multiChange = false;