[eclipse-yocto] [PATCH 4/4] Additions to hook into project optional properties to set/get docker settings.

Tim Orling timothy.t.orling at linux.intel.com
Thu Feb 15 21:50:45 PST 2018


From: Scott Lewis <slewis at composent.com>

Signed-off-by: Scott Lewis <slewis at composent.com>
---
 .../org.yocto.docker.launcher/META-INF/MANIFEST.MF |  4 +-
 .../PokyContainerCommandLauncherFactory.java       |  5 +-
 .../org.yocto.remote.docker/META-INF/MANIFEST.MF   |  9 ++-
 .../org/yocto/remote/docker/DockerConnection.java  |  7 +-
 .../org/yocto/remote/docker/DockerImageInfo.java   | 84 ++++++++++++++++++++++
 .../DockerOpenConnectionProgressMonitor.java       | 15 ++++
 .../yocto/remote/docker/DockerProcessBuilder.java  | 57 ++++++++++-----
 .../yocto/remote/docker/DockerRemoteResource.java  | 20 ++++--
 8 files changed, 168 insertions(+), 33 deletions(-)
 create mode 100644 plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerImageInfo.java
 create mode 100644 plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerOpenConnectionProgressMonitor.java

diff --git a/plugins/org.yocto.docker.launcher/META-INF/MANIFEST.MF b/plugins/org.yocto.docker.launcher/META-INF/MANIFEST.MF
index 20906a4ec55..332130fcc5b 100644
--- a/plugins/org.yocto.docker.launcher/META-INF/MANIFEST.MF
+++ b/plugins/org.yocto.docker.launcher/META-INF/MANIFEST.MF
@@ -12,11 +12,11 @@ Require-Bundle: org.eclipse.core.runtime,
  org.eclipse.cdt.managedbuilder.core;bundle-version="8.6.0",
  org.eclipse.core.variables;bundle-version="3.4.0",
  org.eclipse.ui.workbench;bundle-version="3.110.1",
- org.yocto.sdk.ide;bundle-version="1.4.1",
  org.apache.commons.compress;bundle-version="1.6.0",
  org.eclipse.jface;bundle-version="3.13.1",
  org.eclipse.linuxtools.docker.core;bundle-version="3.2.0",
  org.eclipse.ui.console;bundle-version="3.7.1"
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
 Bundle-ActivationPolicy: lazy
-Export-Package: org.yocto.docker.launcher.ui
+Export-Package: org.yocto.docker.launcher,
+ org.yocto.docker.launcher.ui
diff --git a/plugins/org.yocto.docker.launcher/src/org/yocto/docker/launcher/PokyContainerCommandLauncherFactory.java b/plugins/org.yocto.docker.launcher/src/org/yocto/docker/launcher/PokyContainerCommandLauncherFactory.java
index 3d492d4f177..2c73b492078 100644
--- a/plugins/org.yocto.docker.launcher/src/org/yocto/docker/launcher/PokyContainerCommandLauncherFactory.java
+++ b/plugins/org.yocto.docker.launcher/src/org/yocto/docker/launcher/PokyContainerCommandLauncherFactory.java
@@ -16,7 +16,6 @@ import org.eclipse.cdt.core.ICommandLauncherFactory;
 import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.runtime.CoreException;
-import org.yocto.sdk.ide.natures.YoctoSDKProjectNature;
 
 public class PokyContainerCommandLauncherFactory
 		extends ContainerCommandLauncherFactory
@@ -31,7 +30,7 @@ public class PokyContainerCommandLauncherFactory
 
 		// only return extended container command launcher for projects with Yocto SDK nature
 		try {
-			if (project.getNature(YoctoSDKProjectNature.YoctoSDK_NATURE_ID) == null)
+			if (project.getNature("org.yocto.sdk.ide.YoctoSDKNature") == null)
 				return null;
 		} catch (CoreException e) {
 			// Do nothing if project does not exist, or isn't open, or doesn't contain the Yocto SDK nature.
@@ -47,7 +46,7 @@ public class PokyContainerCommandLauncherFactory
 
 		// Add extra check to make sure project has Yocto SDK nature before resolving the command launcher
 		try {
-			if (cfgd.getProjectDescription().getProject().getNature(YoctoSDKProjectNature.YoctoSDK_NATURE_ID) == null)
+			if (cfgd.getProjectDescription().getProject().getNature("org.yocto.sdk.ide.YoctoSDKNature") == null)
 				return null;
 		} catch (CoreException e) {
 			// Do nothing if project does not exist, or isn't open, or doesn't contain the Yocto SDK nature.
diff --git a/plugins/org.yocto.remote.docker/META-INF/MANIFEST.MF b/plugins/org.yocto.remote.docker/META-INF/MANIFEST.MF
index 47b69dce8cd..d87fe12e641 100644
--- a/plugins/org.yocto.remote.docker/META-INF/MANIFEST.MF
+++ b/plugins/org.yocto.remote.docker/META-INF/MANIFEST.MF
@@ -8,7 +8,14 @@ Require-Bundle: org.eclipse.core.runtime,
  org.eclipse.remote.core,
  org.eclipse.core.filesystem,
  org.eclipse.core.resources,
- org.yocto.docker.launcher,
  org.eclipse.linuxtools.docker.ui;bundle-version="3.2.0"
 Bundle-RequiredExecutionEnvironment: JavaSE-1.7
 Bundle-ActivationPolicy: lazy
+Import-Package: org.eclipse.cdt.core.model,
+ org.eclipse.cdt.core.settings.model,
+ org.eclipse.cdt.docker.launcher,
+ org.eclipse.cdt.managedbuilder.buildproperties,
+ org.eclipse.cdt.managedbuilder.core,
+ org.yocto.docker.launcher,
+ org.yocto.docker.launcher.ui
+Export-Package: org.yocto.remote.docker;version="1.0.0"
diff --git a/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerConnection.java b/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerConnection.java
index ab04256bb11..d9d41f5c5cc 100644
--- a/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerConnection.java
+++ b/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerConnection.java
@@ -57,9 +57,14 @@ IRemoteConnectionPropertyService, IRemoteConnectionHostService, IRemoteProcessSe
 
 	private boolean open;
 
+	private DockerImageInfo imageInfo;
+
 	@Override
 	public void open(IProgressMonitor monitor) throws RemoteConnectionException {
-		open = true;
+		if (monitor instanceof DockerOpenConnectionProgressMonitor) {
+			this.imageInfo = ((DockerOpenConnectionProgressMonitor) monitor).getDockerImageInfo();
+			open = true;
+		}
 	}
 
 	@Override
diff --git a/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerImageInfo.java b/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerImageInfo.java
new file mode 100644
index 00000000000..7911e9a7c18
--- /dev/null
+++ b/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerImageInfo.java
@@ -0,0 +1,84 @@
+package org.yocto.remote.docker;
+
+import org.eclipse.cdt.core.model.CoreModel;
+import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
+import org.eclipse.cdt.core.settings.model.ICProjectDescription;
+import org.eclipse.cdt.managedbuilder.buildproperties.IOptionalBuildProperties;
+import org.eclipse.cdt.managedbuilder.core.IConfiguration;
+import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
+import org.eclipse.core.resources.IProject;
+import org.yocto.docker.launcher.ContainerCommandLauncher;
+
+public class DockerImageInfo {
+
+	public static IOptionalBuildProperties getOptionalBuildProperties(IProject project) {
+		ICProjectDescription cpd = CoreModel.getDefault()
+				.getProjectDescription(project);
+		if (cpd == null)
+			return null;
+		ICConfigurationDescription cfgd = cpd.getActiveConfiguration();
+		IConfiguration cfg = ManagedBuildManager
+				.getConfigurationForDescription(cfgd);
+		if (cfg == null)
+			return null;
+		return cfg.getOptionalBuildProperties();
+	}
+
+	private final boolean enabled;
+	private final String connectionName;
+	private final String imageName;
+
+	public DockerImageInfo(boolean enabled, String connectionName, String imageName) {
+		this.enabled = enabled;
+		this.connectionName = connectionName;
+		this.imageName = imageName;
+	}
+
+	public DockerImageInfo() {
+		this.enabled = false;
+		this.connectionName = null;
+		this.imageName = null;
+	}
+
+	public boolean isEnabled() {
+		return this.enabled;
+	}
+
+	public String getConnectionName() {
+		return this.connectionName;
+	}
+
+	public String getImageName() {
+		return this.imageName;
+	}
+
+	public static DockerImageInfo readFromProject(IProject project) {
+		IOptionalBuildProperties obp = getOptionalBuildProperties(project);
+		if (obp != null) {
+			String enablementProperty = obp.getProperty(
+					ContainerCommandLauncher.CONTAINER_BUILD_ENABLED);
+			if (enablementProperty != null) {
+				boolean enableContainer = Boolean
+						.parseBoolean(enablementProperty);
+				if (enableContainer) {
+					String connection = obp.getProperty(ContainerCommandLauncher.CONNECTION_ID);
+					if (connection != null) {
+						String imageName = obp.getProperty(ContainerCommandLauncher.IMAGE_ID);
+						if (imageName != null)
+							return new DockerImageInfo(enableContainer,connection,imageName);
+					}
+				}
+			}
+		}
+		return new DockerImageInfo();
+	}
+
+	public void writeToProject(IProject project) {
+		IOptionalBuildProperties obp = getOptionalBuildProperties(project);
+		if (obp != null) {
+			obp.setProperty(ContainerCommandLauncher.CONTAINER_BUILD_ENABLED,String.valueOf(isEnabled()));
+			obp.setProperty(ContainerCommandLauncher.CONNECTION_ID, getConnectionName());
+			obp.setProperty(ContainerCommandLauncher.IMAGE_ID, getImageName());
+		}
+	}
+}
\ No newline at end of file
diff --git a/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerOpenConnectionProgressMonitor.java b/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerOpenConnectionProgressMonitor.java
new file mode 100644
index 00000000000..91a2b2f7f2c
--- /dev/null
+++ b/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerOpenConnectionProgressMonitor.java
@@ -0,0 +1,15 @@
+package org.yocto.remote.docker;
+
+import org.eclipse.core.runtime.NullProgressMonitor;
+
+public class DockerOpenConnectionProgressMonitor extends NullProgressMonitor {
+	private final DockerImageInfo dockerImageInfo;
+
+	public DockerOpenConnectionProgressMonitor(DockerImageInfo dockerImageInfo) {
+		this.dockerImageInfo = dockerImageInfo;
+	}
+
+	public DockerImageInfo getDockerImageInfo() {
+		return this.dockerImageInfo;
+	}
+}
\ No newline at end of file
diff --git a/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerProcessBuilder.java b/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerProcessBuilder.java
index 4800c51237a..982bc2ebfd7 100644
--- a/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerProcessBuilder.java
+++ b/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerProcessBuilder.java
@@ -15,11 +15,14 @@ import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
 import org.eclipse.remote.core.AbstractRemoteProcessBuilder;
 import org.eclipse.remote.core.IRemoteConnection;
 import org.eclipse.remote.core.IRemoteProcess;
 import org.eclipse.remote.core.IRemoteProcessBuilder;
+import org.eclipse.remote.core.exception.RemoteConnectionException;
 import org.yocto.docker.launcher.ui.PokyContainerLauncher;
 
 public class DockerProcessBuilder extends AbstractRemoteProcessBuilder implements IRemoteProcessBuilder {
@@ -85,11 +88,11 @@ public class DockerProcessBuilder extends AbstractRemoteProcessBuilder implement
 		for (IProject project : projects) {
 			IPath path = project.getLocation();
 			File projectPath = path.toFile();
-			if (project.isOpen() && projectPath.equals(targetFile)) {
+			if (project.isOpen() && projectPath.equals(targetFile))
 				return project;
-			}
 		}
-		return null;
+		throw new CoreException(
+				new Status(IStatus.ERROR, "org.yocto.remote.docker", "Cannot find project for docker remote process"));
 	}
 
 	/*
@@ -99,24 +102,40 @@ public class DockerProcessBuilder extends AbstractRemoteProcessBuilder implement
 	 */
 	@Override
 	public IRemoteProcess start(int flags) throws IOException {
-		String commandArray[] = command().toArray(new String[0]);
+		IProject project;
 		try {
-			IProject project = findProject();
-			String workingDir = project.getLocation().toPortableString();
-			StringBuffer cmdbuf = new StringBuffer();
-			for (String cmd : commandArray)
-				cmdbuf.append(cmd).append(" ");
-			Map<String, String> env = environment();
-			Properties envp = new Properties();
-			for (Entry<String, String> entry : env.entrySet())
-				envp.put(entry.getKey(), entry.getValue()); // $NON-NLS-1$
-			String connectionName = "unix:///var/run/docker.sock";
-			String imageName = this.getRemoteConnection().getName();
-			localProcess = new PokyContainerLauncher().runCommand(connectionName, imageName, project, null, cmdbuf.toString(), workingDir,
-					workingDir, null, env, null, false, true, null, false, 0);
-		} catch (CoreException e) {
-			throw new IOException(e.getMessage());
+			project = findProject();
+		} catch (CoreException e1) {
+			throw new IOException("Could not find project for remote process start");
 		}
+		DockerImageInfo imageInfo = DockerImageInfo.readFromProject(project);
+		if (imageInfo == null)
+			throw new IOException("Could not find DockerImageInfo for project=" + project);
+		if (!imageInfo.isEnabled())
+			throw new IOException("DockerImageInfo is not enabled for project=" + project);
+		IRemoteConnection connection = getRemoteConnection();
+		if (connection == null)
+			throw new IOException("Could not find docker connection for project=" + project);
+		if (!connection.isOpen())
+			try {
+				connection.open(new DockerOpenConnectionProgressMonitor(imageInfo));
+			} catch (RemoteConnectionException e) {
+				throw new IOException("Could not open remote connection for project=" + project);
+			}
+		// Now connected
+		String commandArray[] = command().toArray(new String[0]);
+		String workingDir = project.getLocation().toPortableString();
+		StringBuffer cmdbuf = new StringBuffer();
+		for (String cmd : commandArray)
+			cmdbuf.append(cmd).append(" ");
+		Map<String, String> env = environment();
+		Properties envp = new Properties();
+		for (Entry<String, String> entry : env.entrySet())
+			envp.put(entry.getKey(), entry.getValue()); // $NON-NLS-1$
+		String connectionName = imageInfo.getConnectionName();
+		String imageName = imageInfo.getImageName();
+		localProcess = new PokyContainerLauncher().runCommand(connectionName, imageName, project, null,
+				cmdbuf.toString(), workingDir, workingDir, null, env, null, false, true, null, false, 0);
 		return new DockerRemoteProcess(this, getProcess());
 	}
 
diff --git a/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerRemoteResource.java b/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerRemoteResource.java
index 59a8400cf9f..59ca5a25533 100644
--- a/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerRemoteResource.java
+++ b/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerRemoteResource.java
@@ -3,6 +3,7 @@ package org.yocto.remote.docker;
 import java.net.URI;
 import java.net.URISyntaxException;
 
+import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
@@ -16,14 +17,19 @@ public class DockerRemoteResource implements IRemoteResource {
 
 	@Override
 	public URI getActiveLocationURI() {
-		URI uri = null;
-		try {
-			uri = new URI(DOCKER_SCHEME,"bavery/scott:cross",resource.getLocation().toPortableString(),null,null);
-		} catch (URISyntaxException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
+		DockerImageInfo imageInfo = DockerImageInfo.readFromProject((IProject) this.resource);
+		if (imageInfo.isEnabled()) {
+			String imageName = imageInfo.getImageName();
+			if (imageName != null)
+				try {
+					return new URI(DOCKER_SCHEME,imageName,resource.getLocation().toPortableString(),null,null);
+				} catch (URISyntaxException e) {
+					// should never happen
+					e.printStackTrace();
+					return this.resource.getLocationURI();
+				}
 		}
-		return uri;
+		return this.resource.getLocationURI();
 	}
 
 	@Override
-- 
2.13.6



More information about the eclipse-yocto mailing list