1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-30 21:55:31 +02:00

Bug 530468 - Support passing CBuildConfiguration to Cmd Launcher Factory

- add new ICBuildCommandLauncher interface
- add new defaulted method to ICommandLauncherFactory interface
- add code to look at Build Configuration properties in
  ContainerCommandLauncherFactory
- add new methods to CommandLauncherManager and
  ContainerCommandLauncher
- add an update dialog call in ContainerTab
- add calls to set and get CBuildConfiguration to
  ContainerCommandLauncher

Change-Id: If95fafe592c7ea4580bae1a15d168d1163e132fd
This commit is contained in:
Jeff Johnston 2018-01-29 16:13:38 -05:00
parent 1d9e549ae7
commit 55fb64151b
6 changed files with 126 additions and 14 deletions

View file

@ -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<ICommandLauncherFactory> 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.
*

View file

@ -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

View file

@ -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);
}

View file

@ -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;
}

View file

@ -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<String, String> 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<? extends ICLanguageSettingEntry> langEntries) {

View file

@ -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();