mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
Bug 536317 - Deadlock at start with launchbar and docker tooling enabled
- fix ContainerTargetTypeProvider changeEvent() to start a Job and return immediately so it will not cause a DockerConnection to be held in multi-threading - move the DockerConnectionManager addConnectionListener call to end of init() method so the fetching of images won't cause a notification event to occur - at end of init(), call CBuildConfigurationManager.recheckConfigs() to make sure any disabled configuration due to a missing IDockerConnection is now put in the configs master list and removed from the noconfigs list - make similar changes to ContainerGCCToolChainProvider Change-Id: Idc120d613b99ec365522f5e7bf5da82d1b362425
This commit is contained in:
parent
147335653f
commit
2bcd06f097
2 changed files with 203 additions and 132 deletions
|
@ -21,7 +21,11 @@ import org.eclipse.cdt.core.build.ICBuildConfigurationManager;
|
||||||
import org.eclipse.cdt.core.build.ICBuildConfigurationManager2;
|
import org.eclipse.cdt.core.build.ICBuildConfigurationManager2;
|
||||||
import org.eclipse.cdt.debug.core.CDebugCorePlugin;
|
import org.eclipse.cdt.debug.core.CDebugCorePlugin;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.Platform;
|
import org.eclipse.core.runtime.Platform;
|
||||||
|
import org.eclipse.core.runtime.Status;
|
||||||
|
import org.eclipse.core.runtime.jobs.Job;
|
||||||
import org.eclipse.launchbar.core.ILaunchBarManager;
|
import org.eclipse.launchbar.core.ILaunchBarManager;
|
||||||
import org.eclipse.launchbar.core.target.ILaunchTarget;
|
import org.eclipse.launchbar.core.target.ILaunchTarget;
|
||||||
import org.eclipse.launchbar.core.target.ILaunchTargetManager;
|
import org.eclipse.launchbar.core.target.ILaunchTargetManager;
|
||||||
|
@ -60,7 +64,6 @@ public class ContainerTargetTypeProvider
|
||||||
}
|
}
|
||||||
IDockerConnection[] connections = DockerConnectionManager.getInstance()
|
IDockerConnection[] connections = DockerConnectionManager.getInstance()
|
||||||
.getConnections();
|
.getConnections();
|
||||||
DockerConnectionManager.getInstance().addConnectionManagerListener(this);
|
|
||||||
Map<String, IDockerConnection> establishedConnectionMap = new HashMap<>();
|
Map<String, IDockerConnection> establishedConnectionMap = new HashMap<>();
|
||||||
Set<String> imageNames = new HashSet<>();
|
Set<String> imageNames = new HashSet<>();
|
||||||
for (IDockerConnection connection : connections) {
|
for (IDockerConnection connection : connections) {
|
||||||
|
@ -74,7 +77,9 @@ public class ContainerTargetTypeProvider
|
||||||
for (IDockerImage image : images) {
|
for (IDockerImage image : images) {
|
||||||
if (!image.isDangling() && !image.isIntermediateImage()) {
|
if (!image.isDangling() && !image.isIntermediateImage()) {
|
||||||
String imageName = "[" //$NON-NLS-1$
|
String imageName = "[" //$NON-NLS-1$
|
||||||
+ image.repoTags().get(0).replace(':', '_') + "]"; //$NON-NLS-1$
|
+ image.repoTags().get(0).replace(':', '_')
|
||||||
|
// .replace('/', '_')
|
||||||
|
+ "]"; //$NON-NLS-1$
|
||||||
if (imageNames.contains(imageName)) {
|
if (imageNames.contains(imageName)) {
|
||||||
imageName += "[" + connection.getName() + "]"; //$NON-NLS-1$ //$NON-NLS-2$
|
imageName += "[" + connection.getName() + "]"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
}
|
}
|
||||||
|
@ -102,12 +107,28 @@ public class ContainerTargetTypeProvider
|
||||||
// remove any launch targets for closed/disabled connections
|
// remove any launch targets for closed/disabled connections
|
||||||
ILaunchTarget[] targets = targetManager.getLaunchTargetsOfType(TYPE_ID);
|
ILaunchTarget[] targets = targetManager.getLaunchTargetsOfType(TYPE_ID);
|
||||||
for (ILaunchTarget target : targets) {
|
for (ILaunchTarget target : targets) {
|
||||||
|
try {
|
||||||
String uri = target.getAttribute(
|
String uri = target.getAttribute(
|
||||||
IContainerLaunchTarget.ATTR_CONNECTION_URI, ""); //$NON-NLS-1$
|
IContainerLaunchTarget.ATTR_CONNECTION_URI, ""); //$NON-NLS-1$
|
||||||
if (!establishedConnectionMap.containsKey(uri)) {
|
if (!establishedConnectionMap.containsKey(uri)) {
|
||||||
targetManager.removeLaunchTarget(target);
|
targetManager.removeLaunchTarget(target);
|
||||||
}
|
}
|
||||||
|
} catch (IllegalStateException e) {
|
||||||
|
// ignore
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// add a Docker Connection listener to handle enablement/disablement of
|
||||||
|
// Connections
|
||||||
|
DockerConnectionManager.getInstance()
|
||||||
|
.addConnectionManagerListener(this);
|
||||||
|
|
||||||
|
// call the recheckConfigs method in case any disabled targets are now
|
||||||
|
// ok
|
||||||
|
ICBuildConfigurationManager mgr = CCorePlugin
|
||||||
|
.getService(ICBuildConfigurationManager.class);
|
||||||
|
ICBuildConfigurationManager2 manager = (ICBuildConfigurationManager2) mgr;
|
||||||
|
manager.recheckConfigs();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
launchbarManager.setActiveLaunchTarget(defaultTarget);
|
launchbarManager.setActiveLaunchTarget(defaultTarget);
|
||||||
|
@ -124,8 +145,12 @@ public class ContainerTargetTypeProvider
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void changeEvent(IDockerConnection connection,
|
public synchronized void changeEvent(final IDockerConnection connection,
|
||||||
int type) {
|
final int type) {
|
||||||
|
Job checkConfigs = new Job("Check configs") { //$NON-NLS-1$
|
||||||
|
@Override
|
||||||
|
protected IStatus run(IProgressMonitor monitor) {
|
||||||
|
|
||||||
ICBuildConfigurationManager mgr = CCorePlugin
|
ICBuildConfigurationManager mgr = CCorePlugin
|
||||||
.getService(ICBuildConfigurationManager.class);
|
.getService(ICBuildConfigurationManager.class);
|
||||||
ICBuildConfigurationManager2 manager = (ICBuildConfigurationManager2) mgr;
|
ICBuildConfigurationManager2 manager = (ICBuildConfigurationManager2) mgr;
|
||||||
|
@ -136,17 +161,21 @@ public class ContainerTargetTypeProvider
|
||||||
.getService(ILaunchBarManager.class);
|
.getService(ILaunchBarManager.class);
|
||||||
ILaunchTarget defaultTarget = null;
|
ILaunchTarget defaultTarget = null;
|
||||||
try {
|
try {
|
||||||
defaultTarget = launchbarManager.getActiveLaunchTarget();
|
defaultTarget = launchbarManager
|
||||||
|
.getActiveLaunchTarget();
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
|
|
||||||
List<IDockerImage> images = connection.getImages();
|
List<IDockerImage> images = connection.getImages();
|
||||||
for (IDockerImage image : images) {
|
for (IDockerImage image : images) {
|
||||||
if (!image.isDangling() && !image.isIntermediateImage()) {
|
if (!image.isDangling()
|
||||||
|
&& !image.isIntermediateImage()) {
|
||||||
|
|
||||||
String imageName = "[" //$NON-NLS-1$
|
String imageName = "[" //$NON-NLS-1$
|
||||||
+ image.repoTags().get(0).replace(':', '_') + "]"; //$NON-NLS-1$
|
+ image.repoTags().get(0).replace(':', '_')
|
||||||
|
// .replace('/', '_')
|
||||||
|
+ "]"; //$NON-NLS-1$
|
||||||
String imageName2 = imageName + "[" //$NON-NLS-1$
|
String imageName2 = imageName + "[" //$NON-NLS-1$
|
||||||
+ connection.getName() + "]"; //$NON-NLS-1$
|
+ connection.getName() + "]"; //$NON-NLS-1$
|
||||||
ILaunchTarget target = targetManager
|
ILaunchTarget target = targetManager
|
||||||
|
@ -154,23 +183,29 @@ public class ContainerTargetTypeProvider
|
||||||
if (target != null) {
|
if (target != null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
target = targetManager.getLaunchTarget(TYPE_ID, imageName);
|
target = targetManager.getLaunchTarget(TYPE_ID,
|
||||||
|
imageName);
|
||||||
if (target != null) {
|
if (target != null) {
|
||||||
if (target.getAttribute(
|
if (target.getAttribute(
|
||||||
IContainerLaunchTarget.ATTR_CONNECTION_URI, "")
|
IContainerLaunchTarget.ATTR_CONNECTION_URI,
|
||||||
.equals(connection.getUri())) {
|
"").equals(connection.getUri())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
imageName = imageName2;
|
imageName = imageName2;
|
||||||
}
|
}
|
||||||
target = targetManager.addLaunchTarget(TYPE_ID, imageName);
|
target = targetManager.addLaunchTarget(TYPE_ID,
|
||||||
ILaunchTargetWorkingCopy wc = target.getWorkingCopy();
|
imageName);
|
||||||
wc.setAttribute(ILaunchTarget.ATTR_OS, CONTAINER_LINUX);
|
ILaunchTargetWorkingCopy wc = target
|
||||||
|
.getWorkingCopy();
|
||||||
|
wc.setAttribute(ILaunchTarget.ATTR_OS,
|
||||||
|
CONTAINER_LINUX);
|
||||||
wc.setAttribute(ILaunchTarget.ATTR_ARCH,
|
wc.setAttribute(ILaunchTarget.ATTR_ARCH,
|
||||||
Platform.getOSArch());
|
Platform.getOSArch());
|
||||||
wc.setAttribute(IContainerLaunchTarget.ATTR_CONNECTION_URI,
|
wc.setAttribute(
|
||||||
|
IContainerLaunchTarget.ATTR_CONNECTION_URI,
|
||||||
connection.getUri());
|
connection.getUri());
|
||||||
wc.setAttribute(IContainerLaunchTarget.ATTR_IMAGE_ID,
|
wc.setAttribute(
|
||||||
|
IContainerLaunchTarget.ATTR_IMAGE_ID,
|
||||||
image.repoTags().get(0));
|
image.repoTags().get(0));
|
||||||
|
|
||||||
wc.save();
|
wc.save();
|
||||||
|
@ -180,7 +215,8 @@ public class ContainerTargetTypeProvider
|
||||||
// reset the default target back again
|
// reset the default target back again
|
||||||
if (defaultTarget != null) {
|
if (defaultTarget != null) {
|
||||||
try {
|
try {
|
||||||
launchbarManager.setActiveLaunchTarget(defaultTarget);
|
launchbarManager
|
||||||
|
.setActiveLaunchTarget(defaultTarget);
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
DockerLaunchUIPlugin.log(e);
|
DockerLaunchUIPlugin.log(e);
|
||||||
}
|
}
|
||||||
|
@ -203,6 +239,11 @@ public class ContainerTargetTypeProvider
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return Status.OK_STATUS;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
checkConfigs.setUser(true);
|
||||||
|
checkConfigs.schedule();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,11 @@ import org.eclipse.cdt.docker.launcher.ContainerTargetTypeProvider;
|
||||||
import org.eclipse.cdt.docker.launcher.DockerLaunchUIPlugin;
|
import org.eclipse.cdt.docker.launcher.DockerLaunchUIPlugin;
|
||||||
import org.eclipse.cdt.docker.launcher.IContainerLaunchTarget;
|
import org.eclipse.cdt.docker.launcher.IContainerLaunchTarget;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.Platform;
|
import org.eclipse.core.runtime.Platform;
|
||||||
|
import org.eclipse.core.runtime.Status;
|
||||||
|
import org.eclipse.core.runtime.jobs.Job;
|
||||||
import org.eclipse.launchbar.core.target.ILaunchTarget;
|
import org.eclipse.launchbar.core.target.ILaunchTarget;
|
||||||
import org.eclipse.linuxtools.docker.core.DockerConnectionManager;
|
import org.eclipse.linuxtools.docker.core.DockerConnectionManager;
|
||||||
import org.eclipse.linuxtools.docker.core.IDockerConnection;
|
import org.eclipse.linuxtools.docker.core.IDockerConnection;
|
||||||
|
@ -58,8 +62,6 @@ public class ContainerGCCToolChainProvider
|
||||||
this.toolChainManager = manager;
|
this.toolChainManager = manager;
|
||||||
IDockerConnection[] connections = DockerConnectionManager.getInstance()
|
IDockerConnection[] connections = DockerConnectionManager.getInstance()
|
||||||
.getConnections();
|
.getConnections();
|
||||||
DockerConnectionManager.getInstance()
|
|
||||||
.addConnectionManagerListener(this);
|
|
||||||
Map<String, IDockerConnection> connectionMap = new HashMap<>();
|
Map<String, IDockerConnection> connectionMap = new HashMap<>();
|
||||||
for (IDockerConnection connection : connections) {
|
for (IDockerConnection connection : connections) {
|
||||||
connectionMap.put(connection.getUri(), connection);
|
connectionMap.put(connection.getUri(), connection);
|
||||||
|
@ -80,6 +82,7 @@ public class ContainerGCCToolChainProvider
|
||||||
// following can be used for naming build configurations
|
// following can be used for naming build configurations
|
||||||
properties.put(CONTAINER_LINUX_CONFIG_ID,
|
properties.put(CONTAINER_LINUX_CONFIG_ID,
|
||||||
image.repoTags().get(0).replace(':', '_'));
|
image.repoTags().get(0).replace(':', '_'));
|
||||||
|
// .replace('/', '_'));
|
||||||
|
|
||||||
ContainerGCCToolChain toolChain = new ContainerGCCToolChain(
|
ContainerGCCToolChain toolChain = new ContainerGCCToolChain(
|
||||||
"gcc-img-" + image.id().substring(0, 19), //$NON-NLS-1$
|
"gcc-img-" + image.id().substring(0, 19), //$NON-NLS-1$
|
||||||
|
@ -90,11 +93,30 @@ public class ContainerGCCToolChainProvider
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// add a Docker Connection listener to handle enablement/disablement of
|
||||||
|
// Connections
|
||||||
|
DockerConnectionManager.getInstance()
|
||||||
|
.addConnectionManagerListener(this);
|
||||||
|
|
||||||
|
// call the recheckConfigs method in case any disabled targets are now
|
||||||
|
// ok
|
||||||
|
ICBuildConfigurationManager mgr = CCorePlugin
|
||||||
|
.getService(ICBuildConfigurationManager.class);
|
||||||
|
ICBuildConfigurationManager2 cbuildmanager = (ICBuildConfigurationManager2) mgr;
|
||||||
|
cbuildmanager.recheckConfigs();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void changeEvent(IDockerConnection connection,
|
public synchronized void changeEvent(IDockerConnection connection,
|
||||||
int type) {
|
int type) {
|
||||||
|
|
||||||
|
final ContainerGCCToolChainProvider provider = this;
|
||||||
|
|
||||||
|
Job checkConfigs = new Job("Check configs") { //$NON-NLS-1$
|
||||||
|
@Override
|
||||||
|
protected IStatus run(IProgressMonitor monitor) {
|
||||||
|
|
||||||
ICBuildConfigurationManager mgr = CCorePlugin
|
ICBuildConfigurationManager mgr = CCorePlugin
|
||||||
.getService(ICBuildConfigurationManager.class);
|
.getService(ICBuildConfigurationManager.class);
|
||||||
ICBuildConfigurationManager2 manager = (ICBuildConfigurationManager2) mgr;
|
ICBuildConfigurationManager2 manager = (ICBuildConfigurationManager2) mgr;
|
||||||
|
@ -103,7 +125,8 @@ public class ContainerGCCToolChainProvider
|
||||||
|| type == IDockerConnectionManagerListener.ENABLE_EVENT) {
|
|| type == IDockerConnectionManagerListener.ENABLE_EVENT) {
|
||||||
List<IDockerImage> images = connection.getImages();
|
List<IDockerImage> images = connection.getImages();
|
||||||
for (IDockerImage image : images) {
|
for (IDockerImage image : images) {
|
||||||
if (!image.isDangling() && !image.isIntermediateImage()) {
|
if (!image.isDangling()
|
||||||
|
&& !image.isIntermediateImage()) {
|
||||||
|
|
||||||
Map<String, String> properties = new HashMap<>();
|
Map<String, String> properties = new HashMap<>();
|
||||||
|
|
||||||
|
@ -111,13 +134,16 @@ public class ContainerGCCToolChainProvider
|
||||||
ContainerTargetTypeProvider.CONTAINER_LINUX);
|
ContainerTargetTypeProvider.CONTAINER_LINUX);
|
||||||
properties.put(ILaunchTarget.ATTR_ARCH,
|
properties.put(ILaunchTarget.ATTR_ARCH,
|
||||||
Platform.getOSArch());
|
Platform.getOSArch());
|
||||||
properties.put(IContainerLaunchTarget.ATTR_CONNECTION_URI,
|
properties.put(
|
||||||
|
IContainerLaunchTarget.ATTR_CONNECTION_URI,
|
||||||
connection.getUri());
|
connection.getUri());
|
||||||
properties.put(IContainerLaunchTarget.ATTR_IMAGE_ID,
|
properties.put(IContainerLaunchTarget.ATTR_IMAGE_ID,
|
||||||
image.repoTags().get(0));
|
image.repoTags().get(0));
|
||||||
// following can be used for naming build configurations
|
// following can be used for naming build
|
||||||
|
// configurations
|
||||||
properties.put(CONTAINER_LINUX_CONFIG_ID,
|
properties.put(CONTAINER_LINUX_CONFIG_ID,
|
||||||
image.repoTags().get(0).replace(':', '_'));
|
image.repoTags().get(0).replace(':', '_'));
|
||||||
|
// .replace('/', '_'));
|
||||||
|
|
||||||
|
|
||||||
Collection<IToolChain> toolChains;
|
Collection<IToolChain> toolChains;
|
||||||
|
@ -126,8 +152,8 @@ public class ContainerGCCToolChainProvider
|
||||||
.getToolChainsMatching(properties);
|
.getToolChainsMatching(properties);
|
||||||
if (toolChains.isEmpty()) {
|
if (toolChains.isEmpty()) {
|
||||||
ContainerGCCToolChain toolChain = new ContainerGCCToolChain(
|
ContainerGCCToolChain toolChain = new ContainerGCCToolChain(
|
||||||
"gcc-img-" + image.id().substring(0, 19), //$NON-NLS-1$
|
"gcc-img-" + image.id().substring(0, //$NON-NLS-1$
|
||||||
this, properties, null);
|
19), provider, properties, null);
|
||||||
toolChainManager.addToolChain(toolChain);
|
toolChainManager.addToolChain(toolChain);
|
||||||
}
|
}
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
|
@ -156,7 +182,11 @@ public class ContainerGCCToolChainProvider
|
||||||
DockerLaunchUIPlugin.log(e1);
|
DockerLaunchUIPlugin.log(e1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return Status.OK_STATUS;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
checkConfigs.setUser(true);
|
||||||
|
checkConfigs.schedule();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue