Skip to main content
summaryrefslogtreecommitdiffstats
path: root/launch
diff options
context:
space:
mode:
authorJeff Johnston2018-04-19 18:34:33 -0400
committerJeff Johnston2018-04-20 12:44:27 -0400
commitb56078ed968e2f0ff871fa0acdf14f7adfa72aab (patch)
treef2997a55b2b8f650f409315c8b2f332507fb642a /launch
parentec9361bd4550fa3cc3398961aa358d3df25fe512 (diff)
downloadorg.eclipse.cdt-b56078ed968e2f0ff871fa0acdf14f7adfa72aab.tar.gz
org.eclipse.cdt-b56078ed968e2f0ff871fa0acdf14f7adfa72aab.tar.xz
org.eclipse.cdt-b56078ed968e2f0ff871fa0acdf14f7adfa72aab.zip
Bug 533842 - Fix Launchbar for enabled/disabled Docker Connections
- fix CMakeBuildConfigurationProvider to not verify if a toolchain file exists which doesn't occur for Container Build configurations - add new ICBuildConfigurationManager2 interface that adds new recheckConfigs() method, make CBuildConfigurationManager implement this new interface - add new recheckConfigs() method to CBuildConfigurationManager so that if a Docker Connection is enabled, the list of invalid configs can be rechecked and those that are now valid can be removed from the noconfigs list - have ContainerGCCToolChainProvider implement IDockerConnectionManagerListener and register itself as a listener during init - add new changeEvent() method as part of a listener that will add toolchains for connections that are added/enabled and similarly will delete toolchains for connections that are removed/disabled - do the same with ContainerTargetTypeProvider (making it be an IDockerConnectionManagerListener and adding/deleting targets based on whether a Docker Connection is added/enabled or deleted/disabled - as well during the init process of ContainerTargetTypeProvider remove any targets for Connections that aren't established Change-Id: Id5e9415eaa770ef7f6ba1ddd11312ed003585391
Diffstat (limited to 'launch')
-rw-r--r--launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/docker/launcher/ContainerTargetTypeProvider.java113
-rw-r--r--launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/internal/docker/launcher/ui/launchbar/ContainerGCCToolChainProvider.java84
2 files changed, 195 insertions, 2 deletions
diff --git a/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/docker/launcher/ContainerTargetTypeProvider.java b/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/docker/launcher/ContainerTargetTypeProvider.java
index 516f939607..73b40a4452 100644
--- a/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/docker/launcher/ContainerTargetTypeProvider.java
+++ b/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/docker/launcher/ContainerTargetTypeProvider.java
@@ -10,10 +10,15 @@
*******************************************************************************/
package org.eclipse.cdt.docker.launcher;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.build.ICBuildConfigurationManager;
+import org.eclipse.cdt.core.build.ICBuildConfigurationManager2;
import org.eclipse.cdt.debug.core.CDebugCorePlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Platform;
@@ -24,7 +29,9 @@ import org.eclipse.launchbar.core.target.ILaunchTargetProvider;
import org.eclipse.launchbar.core.target.ILaunchTargetWorkingCopy;
import org.eclipse.launchbar.core.target.TargetStatus;
import org.eclipse.linuxtools.docker.core.DockerConnectionManager;
+import org.eclipse.linuxtools.docker.core.EnumDockerConnectionState;
import org.eclipse.linuxtools.docker.core.IDockerConnection;
+import org.eclipse.linuxtools.docker.core.IDockerConnectionManagerListener;
import org.eclipse.linuxtools.docker.core.IDockerImage;
/**
@@ -32,13 +39,17 @@ import org.eclipse.linuxtools.docker.core.IDockerImage;
* @author jjohnstn
*
*/
-public class ContainerTargetTypeProvider implements ILaunchTargetProvider {
+public class ContainerTargetTypeProvider
+ implements ILaunchTargetProvider, IDockerConnectionManagerListener {
public static final String TYPE_ID = "org.eclipse.cdt.docker.launcher.launchTargetType.container"; //$NON-NLS-1$
public static final String CONTAINER_LINUX = "linux-container"; //$NON-NLS-1$
+ private ILaunchTargetManager targetManager;
+
@Override
public void init(ILaunchTargetManager targetManager) {
+ this.targetManager = targetManager;
ILaunchBarManager launchbarManager = CDebugCorePlugin
.getService(ILaunchBarManager.class);
ILaunchTarget defaultTarget = null;
@@ -49,8 +60,13 @@ public class ContainerTargetTypeProvider implements ILaunchTargetProvider {
}
IDockerConnection[] connections = DockerConnectionManager.getInstance()
.getConnections();
+ Map<String, IDockerConnection> establishedConnectionMap = new HashMap<>();
Set<String> imageNames = new HashSet<>();
for (IDockerConnection connection : connections) {
+ if (connection
+ .getState() == EnumDockerConnectionState.ESTABLISHED) {
+ establishedConnectionMap.put(connection.getUri(), connection);
+ }
List<IDockerImage> images = connection.getImages();
for (IDockerImage image : images) {
if (!image.isDangling() && !image.isIntermediateImage()) {
@@ -79,11 +95,25 @@ public class ContainerTargetTypeProvider implements ILaunchTargetProvider {
}
}
}
+
+ // remove any launch targets for closed/disabled connections
+ ILaunchTarget[] targets = targetManager.getLaunchTargetsOfType(TYPE_ID);
+ for (ILaunchTarget target : targets) {
+ String uri = target.getAttribute(
+ IContainerLaunchTarget.ATTR_CONNECTION_URI, ""); //$NON-NLS-1$
+ if (!establishedConnectionMap.containsKey(uri)) {
+ targetManager.removeLaunchTarget(target);
+ }
+ }
+
try {
launchbarManager.setActiveLaunchTarget(defaultTarget);
} catch (CoreException e) {
DockerLaunchUIPlugin.log(e);
}
+
+ DockerConnectionManager.getInstance()
+ .addConnectionManagerListener(this);
}
@Override
@@ -92,4 +122,85 @@ public class ContainerTargetTypeProvider implements ILaunchTargetProvider {
return TargetStatus.OK_STATUS;
}
+ @Override
+ public void changeEvent(IDockerConnection connection, int type) {
+ ICBuildConfigurationManager mgr = CCorePlugin
+ .getService(ICBuildConfigurationManager.class);
+ ICBuildConfigurationManager2 manager = (ICBuildConfigurationManager2) mgr;
+
+ if (type == IDockerConnectionManagerListener.ADD_EVENT
+ || type == IDockerConnectionManagerListener.ENABLE_EVENT) {
+ ILaunchBarManager launchbarManager = CDebugCorePlugin
+ .getService(ILaunchBarManager.class);
+ ILaunchTarget defaultTarget = null;
+ try {
+ defaultTarget = launchbarManager.getActiveLaunchTarget();
+ } catch (CoreException e) {
+ // ignore
+ }
+
+ List<IDockerImage> images = connection.getImages();
+ for (IDockerImage image : images) {
+ if (!image.isDangling() && !image.isIntermediateImage()) {
+
+ String imageName = "[" //$NON-NLS-1$
+ + image.repoTags().get(0).replace(':', '_') + "]"; //$NON-NLS-1$
+ String imageName2 = imageName + "[" //$NON-NLS-1$
+ + connection.getName() + "]"; //$NON-NLS-1$
+ ILaunchTarget target = targetManager
+ .getLaunchTarget(TYPE_ID, imageName2);
+ if (target != null) {
+ continue;
+ }
+ target = targetManager.getLaunchTarget(TYPE_ID, imageName);
+ if (target != null) {
+ if (target.getAttribute(
+ IContainerLaunchTarget.ATTR_CONNECTION_URI, "")
+ .equals(connection.getUri())) {
+ continue;
+ }
+ imageName = imageName2;
+ }
+ target = targetManager.addLaunchTarget(TYPE_ID, imageName);
+ ILaunchTargetWorkingCopy wc = target.getWorkingCopy();
+ wc.setAttribute(ILaunchTarget.ATTR_OS, CONTAINER_LINUX);
+ wc.setAttribute(ILaunchTarget.ATTR_ARCH,
+ Platform.getOSArch());
+ wc.setAttribute(IContainerLaunchTarget.ATTR_CONNECTION_URI,
+ connection.getUri());
+ wc.setAttribute(IContainerLaunchTarget.ATTR_IMAGE_ID,
+ image.repoTags().get(0));
+
+ wc.save();
+ }
+ }
+
+ // reset the default target back again
+ if (defaultTarget != null) {
+ try {
+ launchbarManager.setActiveLaunchTarget(defaultTarget);
+ } catch (CoreException e) {
+ DockerLaunchUIPlugin.log(e);
+ }
+
+ }
+
+ // Re-evaluate config list in case a build config was marked
+ // invalid and is now enabled
+ manager.recheckConfigs();
+ } else if (type == IDockerConnectionManagerListener.REMOVE_EVENT
+ || type == IDockerConnectionManagerListener.DISABLE_EVENT) {
+ String connectionURI = connection.getUri();
+ ILaunchTarget[] targets = targetManager
+ .getLaunchTargetsOfType(TYPE_ID);
+ for (ILaunchTarget target : targets) {
+ String uri = target.getAttribute(
+ IContainerLaunchTarget.ATTR_CONNECTION_URI, ""); //$NON-NLS-1$
+ if (connectionURI.equals(uri)) {
+ targetManager.removeLaunchTarget(target);
+ }
+ }
+ }
+ }
+
}
diff --git a/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/internal/docker/launcher/ui/launchbar/ContainerGCCToolChainProvider.java b/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/internal/docker/launcher/ui/launchbar/ContainerGCCToolChainProvider.java
index b7392d20e0..aba09ca8f8 100644
--- a/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/internal/docker/launcher/ui/launchbar/ContainerGCCToolChainProvider.java
+++ b/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/internal/docker/launcher/ui/launchbar/ContainerGCCToolChainProvider.java
@@ -10,19 +10,26 @@
*******************************************************************************/
package org.eclipse.cdt.internal.docker.launcher.ui.launchbar;
+import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.build.ICBuildConfigurationManager;
+import org.eclipse.cdt.core.build.ICBuildConfigurationManager2;
+import org.eclipse.cdt.core.build.IToolChain;
import org.eclipse.cdt.core.build.IToolChainManager;
import org.eclipse.cdt.core.build.IToolChainProvider;
import org.eclipse.cdt.docker.launcher.ContainerTargetTypeProvider;
+import org.eclipse.cdt.docker.launcher.DockerLaunchUIPlugin;
import org.eclipse.cdt.docker.launcher.IContainerLaunchTarget;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Platform;
import org.eclipse.launchbar.core.target.ILaunchTarget;
import org.eclipse.linuxtools.docker.core.DockerConnectionManager;
import org.eclipse.linuxtools.docker.core.IDockerConnection;
+import org.eclipse.linuxtools.docker.core.IDockerConnectionManagerListener;
import org.eclipse.linuxtools.docker.core.IDockerImage;
/**
@@ -32,11 +39,14 @@ import org.eclipse.linuxtools.docker.core.IDockerImage;
* @since 1.2
*
*/
-public class ContainerGCCToolChainProvider implements IToolChainProvider {
+public class ContainerGCCToolChainProvider
+ implements IToolChainProvider, IDockerConnectionManagerListener {
public static final String PROVIDER_ID = "org.eclipse.cdt.docker.launcher.gcc.provider"; //$NON-NLS-1$
public static final String CONTAINER_LINUX_CONFIG_ID = "linux-container-id"; //$NON-NLS-1$
+ private IToolChainManager toolChainManager;
+
@Override
public String getId() {
return PROVIDER_ID;
@@ -44,9 +54,12 @@ public class ContainerGCCToolChainProvider implements IToolChainProvider {
@Override
public void init(IToolChainManager manager) throws CoreException {
+ this.toolChainManager = manager;
IDockerConnection[] connections = DockerConnectionManager.getInstance()
.getConnections();
+ Map<String, IDockerConnection> connectionMap = new HashMap<>();
for (IDockerConnection connection : connections) {
+ connectionMap.put(connection.getUri(), connection);
List<IDockerImage> images = connection.getImages();
for (IDockerImage image : images) {
if (!image.isDangling() && !image.isIntermediateImage()) {
@@ -73,6 +86,75 @@ public class ContainerGCCToolChainProvider implements IToolChainProvider {
}
}
}
+
+ DockerConnectionManager.getInstance()
+ .addConnectionManagerListener(this);
+ }
+
+ @Override
+ public void changeEvent(IDockerConnection connection, int type) {
+ ICBuildConfigurationManager mgr = CCorePlugin
+ .getService(ICBuildConfigurationManager.class);
+ ICBuildConfigurationManager2 manager = (ICBuildConfigurationManager2) mgr;
+
+ if (type == IDockerConnectionManagerListener.ADD_EVENT
+ || type == IDockerConnectionManagerListener.ENABLE_EVENT) {
+ List<IDockerImage> images = connection.getImages();
+ for (IDockerImage image : images) {
+ if (!image.isDangling() && !image.isIntermediateImage()) {
+
+ Map<String, String> properties = new HashMap<>();
+
+ properties.put(ILaunchTarget.ATTR_OS,
+ ContainerTargetTypeProvider.CONTAINER_LINUX);
+ properties.put(ILaunchTarget.ATTR_ARCH,
+ Platform.getOSArch());
+ properties.put(IContainerLaunchTarget.ATTR_CONNECTION_URI,
+ connection.getUri());
+ properties.put(IContainerLaunchTarget.ATTR_IMAGE_ID,
+ image.repoTags().get(0));
+ // following can be used for naming build configurations
+ properties.put(CONTAINER_LINUX_CONFIG_ID,
+ image.repoTags().get(0).replace(':', '_'));
+
+
+ Collection<IToolChain> toolChains;
+ try {
+ toolChains = toolChainManager
+ .getToolChainsMatching(properties);
+ if (toolChains.isEmpty()) {
+ ContainerGCCToolChain toolChain = new ContainerGCCToolChain(
+ "gcc-img-" + image.id().substring(0, 19), //$NON-NLS-1$
+ this, properties, null);
+ toolChainManager.addToolChain(toolChain);
+ }
+ } catch (CoreException e) {
+ DockerLaunchUIPlugin.log(e);
+ }
+ }
+ }
+ // Re-evaluate config list in case a build config was marked
+ // invalid and is now enabled
+ manager.recheckConfigs();
+ } else if (type == IDockerConnectionManagerListener.REMOVE_EVENT
+ || type == IDockerConnectionManagerListener.DISABLE_EVENT) {
+ try {
+ String connectionURI = connection.getUri();
+ Collection<IToolChain> toolChains = toolChainManager
+ .getAllToolChains();
+ for (IToolChain toolChain : toolChains) {
+ String uri = toolChain.getProperty(
+ IContainerLaunchTarget.ATTR_CONNECTION_URI);
+ if (connectionURI.equals(uri)) {
+ toolChainManager.removeToolChain(toolChain);
+ }
+ }
+ } catch (CoreException e1) {
+ // TODO Auto-generated catch block
+ DockerLaunchUIPlugin.log(e1);
+ }
+ }
+
}
}

Back to the top