[eclipse-yocto] [PATCH 2/4] Added new plugin: org.yocto.remote.docker
Tim Orling
timothy.t.orling at linux.intel.com
Thu Feb 15 21:50:43 PST 2018
From: Scott Lewis <slewis at composent.com>
This plugin contains a minimal implementation of the org.eclipse.remote
API allowing the autotools and other tooling to use an
org.eclipse.remote.IRemoteResource adapter to issue remote commands to a
docker container. Specifically the autotools makefile generation command via
RemoteCommandLauncher line 149. This call to
project.getAdapter(IRemoteResource.class) will now return a DockerRemoteResource
for projects with autotools nature.
Also added new plugin org.yocto.remote.docker.ui to allow testing. It's
necessary to create a new connection prior to creating an autotools
project so that the initial make file generation (done immediately after
build) can be available via a container. Before creating new autotools
project, it's necessary to go to Window->Preferences->Remote
Development->Remote Connections, select 'docker' from drop down at top
of preference page, choose 'Add' button on right hand side, and create a
connection to the bavery/scott:cross image. This UI is available so
that this can be done for testing before the autotools project is
created. Eventually, the creation of the connection must be done as
part of the project creation process.
Signed-off-by: Scott Lewis <slewis at composent.com>
---
.../org.yocto.docker.launcher/META-INF/MANIFEST.MF | 1 +
plugins/org.yocto.remote.docker.ui/.classpath | 7 +
plugins/org.yocto.remote.docker.ui/.project | 28 ++
.../.settings/org.eclipse.jdt.core.prefs | 7 +
.../META-INF/MANIFEST.MF | 12 +
.../org.yocto.remote.docker.ui/build.properties | 5 +
plugins/org.yocto.remote.docker.ui/icons/ssh.png | Bin 0 -> 512 bytes
plugins/org.yocto.remote.docker.ui/plugin.xml | 12 +
.../src/org/yocto/remote/docker/ui/Activator.java | 119 +++++++++
.../remote/docker/ui/DockerConnectionPage.java | 78 ++++++
.../remote/docker/ui/DockerConnectionWizard.java | 70 +++++
.../docker/ui/DockerUIConnectionService.java | 96 +++++++
plugins/org.yocto.remote.docker/.classpath | 7 +
plugins/org.yocto.remote.docker/.project | 28 ++
.../.settings/org.eclipse.jdt.core.prefs | 7 +
.../org.yocto.remote.docker/META-INF/MANIFEST.MF | 14 +
plugins/org.yocto.remote.docker/build.properties | 5 +
plugins/org.yocto.remote.docker/plugin.xml | 75 ++++++
.../src/org/yocto/remote/docker/Activator.java | 105 ++++++++
.../org/yocto/remote/docker/DockerConnection.java | 190 +++++++++++++
.../docker/DockerConnectionProviderService.java | 45 ++++
.../org/yocto/remote/docker/DockerFileStore.java | 296 +++++++++++++++++++++
.../org/yocto/remote/docker/DockerFileSystem.java | 107 ++++++++
.../src/org/yocto/remote/docker/DockerProcess.java | 216 +++++++++++++++
.../yocto/remote/docker/DockerProcessBuilder.java | 127 +++++++++
.../remote/docker/DockerProcessControlService.java | 63 +++++
.../yocto/remote/docker/DockerProcessService.java | 76 ++++++
.../docker/DockerRemoteConnectionHostService.java | 117 ++++++++
.../remote/docker/DockerRemoteFileService.java | 82 ++++++
.../yocto/remote/docker/DockerRemoteProcess.java | 75 ++++++
.../yocto/remote/docker/DockerRemoteResource.java | 44 +++
.../org/yocto/remote/docker/DockerResource.java | 57 ++++
32 files changed, 2171 insertions(+)
create mode 100644 plugins/org.yocto.remote.docker.ui/.classpath
create mode 100644 plugins/org.yocto.remote.docker.ui/.project
create mode 100644 plugins/org.yocto.remote.docker.ui/.settings/org.eclipse.jdt.core.prefs
create mode 100644 plugins/org.yocto.remote.docker.ui/META-INF/MANIFEST.MF
create mode 100644 plugins/org.yocto.remote.docker.ui/build.properties
create mode 100644 plugins/org.yocto.remote.docker.ui/icons/ssh.png
create mode 100644 plugins/org.yocto.remote.docker.ui/plugin.xml
create mode 100644 plugins/org.yocto.remote.docker.ui/src/org/yocto/remote/docker/ui/Activator.java
create mode 100644 plugins/org.yocto.remote.docker.ui/src/org/yocto/remote/docker/ui/DockerConnectionPage.java
create mode 100644 plugins/org.yocto.remote.docker.ui/src/org/yocto/remote/docker/ui/DockerConnectionWizard.java
create mode 100644 plugins/org.yocto.remote.docker.ui/src/org/yocto/remote/docker/ui/DockerUIConnectionService.java
create mode 100644 plugins/org.yocto.remote.docker/.classpath
create mode 100644 plugins/org.yocto.remote.docker/.project
create mode 100644 plugins/org.yocto.remote.docker/.settings/org.eclipse.jdt.core.prefs
create mode 100644 plugins/org.yocto.remote.docker/META-INF/MANIFEST.MF
create mode 100644 plugins/org.yocto.remote.docker/build.properties
create mode 100644 plugins/org.yocto.remote.docker/plugin.xml
create mode 100644 plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/Activator.java
create mode 100644 plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerConnection.java
create mode 100644 plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerConnectionProviderService.java
create mode 100644 plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerFileStore.java
create mode 100644 plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerFileSystem.java
create mode 100644 plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerProcess.java
create mode 100644 plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerProcessBuilder.java
create mode 100644 plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerProcessControlService.java
create mode 100644 plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerProcessService.java
create mode 100644 plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerRemoteConnectionHostService.java
create mode 100644 plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerRemoteFileService.java
create mode 100644 plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerRemoteProcess.java
create mode 100644 plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerRemoteResource.java
create mode 100644 plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerResource.java
diff --git a/plugins/org.yocto.docker.launcher/META-INF/MANIFEST.MF b/plugins/org.yocto.docker.launcher/META-INF/MANIFEST.MF
index 3e29b1f81e7..20906a4ec55 100644
--- a/plugins/org.yocto.docker.launcher/META-INF/MANIFEST.MF
+++ b/plugins/org.yocto.docker.launcher/META-INF/MANIFEST.MF
@@ -19,3 +19,4 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.ui.console;bundle-version="3.7.1"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
+Export-Package: org.yocto.docker.launcher.ui
diff --git a/plugins/org.yocto.remote.docker.ui/.classpath b/plugins/org.yocto.remote.docker.ui/.classpath
new file mode 100644
index 00000000000..eca7bdba8f0
--- /dev/null
+++ b/plugins/org.yocto.remote.docker.ui/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/plugins/org.yocto.remote.docker.ui/.project b/plugins/org.yocto.remote.docker.ui/.project
new file mode 100644
index 00000000000..401f565cc32
--- /dev/null
+++ b/plugins/org.yocto.remote.docker.ui/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.yocto.remote.docker.ui</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/plugins/org.yocto.remote.docker.ui/.settings/org.eclipse.jdt.core.prefs b/plugins/org.yocto.remote.docker.ui/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 00000000000..0c68a61dca8
--- /dev/null
+++ b/plugins/org.yocto.remote.docker.ui/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/plugins/org.yocto.remote.docker.ui/META-INF/MANIFEST.MF b/plugins/org.yocto.remote.docker.ui/META-INF/MANIFEST.MF
new file mode 100644
index 00000000000..0f20df81a87
--- /dev/null
+++ b/plugins/org.yocto.remote.docker.ui/META-INF/MANIFEST.MF
@@ -0,0 +1,12 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Ui
+Bundle-SymbolicName: org.yocto.remote.docker.ui;singleton:=true
+Bundle-Version: 1.0.0.qualifier
+Bundle-Activator: org.yocto.remote.docker.ui.Activator
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.eclipse.remote.core,
+ org.eclipse.remote.ui
+Bundle-RequiredExecutionEnvironment: JavaSE-1.8
+Bundle-ActivationPolicy: lazy
diff --git a/plugins/org.yocto.remote.docker.ui/build.properties b/plugins/org.yocto.remote.docker.ui/build.properties
new file mode 100644
index 00000000000..e9863e281ea
--- /dev/null
+++ b/plugins/org.yocto.remote.docker.ui/build.properties
@@ -0,0 +1,5 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml
diff --git a/plugins/org.yocto.remote.docker.ui/icons/ssh.png b/plugins/org.yocto.remote.docker.ui/icons/ssh.png
new file mode 100644
index 0000000000000000000000000000000000000000..8cbd0a13ba88e93b252aaa2c7484e45831c2fa06
GIT binary patch
literal 512
zcmeAS at N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE)4%caKYZ?lYt_f1s;*b
z3=DinK$vl=HlH+5kiEpy*OmP~E4!!&tKFiHmw-aDnIRD+&iT2ysd*(pE(3#eQEFmI
zYKlU6W=V#EyQgnJie4%^0|R4<r;B5V#p$V&&wE8D3LLF3{+qV$!dgMCklN-8kBn|#
zQZG>5*O~NNi*>2~f(K!jdOIeS3cZ>in&Dy|*L!yE%SV$g<Q1(?|9ke#dzo|U_xbB<
z?%s&8FW~2hU{Y!l5Yw96^ZIrC{U=}Eq^GQ3zhnvn2Lof`$F`RxT!Kqx_*8ta>s>0;
z(UWR)N4>=-TkOxnhYu%i$vO3H`uQzUs~r at A4)b+zEWX%rc(L*%4xq at Jx9^KfD-Zts
zdGyXXrJc<jD&G~(_wK$eZC7{e(aMTMix<}?J=yt4PKDq7>Wi;c3?){w at AC4qI74{(
z)myEz+;-o6cK8?D-Mr~bwplPAIKxpMR54-px%T(R_ZzM~f54~nlvBdA;-VTG_iUxj
zGX0Tk%a*W(|37`8WSXPvg)g7>vrJ{x4>S$=n#+>4V|pmRg2w4d9T_Gur7ElBIvfIR
zlE0a8yMBx at -Doe-S6*HoHsNM?PE)|%xBP97_xCw0>}9e#77mICPgg&ebxsLQ0DRBc
AM*si-
literal 0
HcmV?d00001
diff --git a/plugins/org.yocto.remote.docker.ui/plugin.xml b/plugins/org.yocto.remote.docker.ui/plugin.xml
new file mode 100644
index 00000000000..cd5a15058ab
--- /dev/null
+++ b/plugins/org.yocto.remote.docker.ui/plugin.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension
+ point="org.eclipse.remote.core.remoteServices">
+ <connectionTypeService
+ connectionTypeId="org.yocto.remote.docker.DockerServices"
+ factory="org.yocto.remote.docker.ui.DockerUIConnectionService$Factory"
+ service="org.eclipse.remote.ui.IRemoteUIConnectionService">
+ </connectionTypeService>
+ </extension>
+</plugin>
diff --git a/plugins/org.yocto.remote.docker.ui/src/org/yocto/remote/docker/ui/Activator.java b/plugins/org.yocto.remote.docker.ui/src/org/yocto/remote/docker/ui/Activator.java
new file mode 100644
index 00000000000..197c4df5430
--- /dev/null
+++ b/plugins/org.yocto.remote.docker.ui/src/org/yocto/remote/docker/ui/Activator.java
@@ -0,0 +1,119 @@
+package org.yocto.remote.docker.ui;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.yocto.remote.docker.ui"; //$NON-NLS-1$
+
+ // The shared instance
+ private static Activator plugin;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+ // Image Keys
+ public static final String IMG_CONNECTION_TYPE = PLUGIN_ID + ".connectionType"; //$NON-NLS-1$
+
+ /**
+ * Get unique identifier
+ *
+ * @return
+ * @since 5.0
+ */
+ public static String getUniqueIdentifier() {
+ if (getDefault() == null) {
+ return PLUGIN_ID;
+ }
+ return getDefault().getBundle().getSymbolicName();
+ }
+
+ /**
+ * Logs the specified status with this plug-in's log.
+ *
+ * @param status
+ * status to log
+ */
+ public static void log(IStatus status) {
+ getDefault().getLog().log(status);
+ }
+
+ /**
+ * Logs an internal error with the specified message.
+ *
+ * @param message
+ * the error message to log
+ */
+ public static void log(String message) {
+ log(new Status(IStatus.ERROR, getUniqueIdentifier(), IStatus.ERROR, message, null));
+ }
+
+ /**
+ * Logs an internal error with the specified throwable
+ *
+ * @param e
+ * the exception to be logged
+ */
+ public static void log(Throwable e) {
+ log(new Status(IStatus.ERROR, getUniqueIdentifier(), IStatus.ERROR, e.getMessage(), e));
+ }
+
+ /**
+ * Return the OSGi service with the given service interface.
+ *
+ * @param service service interface
+ * @return the specified service or null if it's not registered
+ */
+ public static <T> T getService(Class<T> service) {
+ BundleContext context = plugin.getBundle().getBundleContext();
+ ServiceReference<T> ref = context.getServiceReference(service);
+ return ref != null ? context.getService(ref) : null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
+ * )
+ */
+ @Override
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ getImageRegistry().put(IMG_CONNECTION_TYPE, imageDescriptorFromPlugin(PLUGIN_ID, "/icons/docker.png")); //$NON-NLS-1$
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
+ * )
+ */
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+}
diff --git a/plugins/org.yocto.remote.docker.ui/src/org/yocto/remote/docker/ui/DockerConnectionPage.java b/plugins/org.yocto.remote.docker.ui/src/org/yocto/remote/docker/ui/DockerConnectionPage.java
new file mode 100644
index 00000000000..056b5bd9092
--- /dev/null
+++ b/plugins/org.yocto.remote.docker.ui/src/org/yocto/remote/docker/ui/DockerConnectionPage.java
@@ -0,0 +1,78 @@
+package org.yocto.remote.docker.ui;
+
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.remote.core.IRemoteConnectionType;
+import org.eclipse.remote.core.IRemoteConnectionWorkingCopy;
+import org.eclipse.remote.core.exception.RemoteConnectionException;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+
+public class DockerConnectionPage extends WizardPage {
+
+ private class DataModifyListener implements ModifyListener {
+ @Override
+ public synchronized void modifyText(ModifyEvent e) {
+ validateFields();
+ getContainer().updateButtons();
+ }
+ }
+
+ private Text fImageName;
+ private String imageName;
+ private final IRemoteConnectionType fConnectionType;
+
+ private final DataModifyListener fDataModifyListener = new DataModifyListener();
+
+ public DockerConnectionPage(IRemoteConnectionType connectionType) {
+ super("New connection");
+ fConnectionType = connectionType;
+ setPageComplete(false);
+ }
+
+ @Override
+ public void createControl(Composite parent) {
+ setDescription("New connection properties");
+ setTitle("New connection");
+ setMessage("Specify properties of a new connection");
+ setErrorMessage(null);
+
+ GridLayout topLayout = new GridLayout(2, false);
+ final Composite topControl = new Composite(parent, SWT.NONE);
+ setControl(topControl);
+ topControl.setLayout(topLayout);
+
+ Label label = new Label(topControl, SWT.NONE);
+ label.setText("Docker image");
+
+ fImageName = new Text(topControl, SWT.BORDER | SWT.SINGLE);
+ fImageName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+ fImageName.setText("bavery/scott:cross");
+ fImageName.addModifyListener(fDataModifyListener);
+ validateFields();
+ }
+
+ public IRemoteConnectionWorkingCopy getConnection() {
+ try {
+ IRemoteConnectionWorkingCopy wc = fConnectionType.newConnection(imageName.trim());
+ wc.save();
+ wc.getOriginal().open(null);
+ return wc;
+ } catch (RemoteConnectionException e) {
+ Activator.log(e);
+ return null;
+ }
+ }
+
+ private void validateFields() {
+ setErrorMessage(null);
+ setPageComplete(true);
+ this.imageName = fImageName.getText();
+ }
+
+}
diff --git a/plugins/org.yocto.remote.docker.ui/src/org/yocto/remote/docker/ui/DockerConnectionWizard.java b/plugins/org.yocto.remote.docker.ui/src/org/yocto/remote/docker/ui/DockerConnectionWizard.java
new file mode 100644
index 00000000000..76ae789e999
--- /dev/null
+++ b/plugins/org.yocto.remote.docker.ui/src/org/yocto/remote/docker/ui/DockerConnectionWizard.java
@@ -0,0 +1,70 @@
+package org.yocto.remote.docker.ui;
+
+import java.util.Set;
+
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.jface.wizard.WizardDialog;
+import org.eclipse.remote.core.IRemoteConnectionType;
+import org.eclipse.remote.core.IRemoteConnectionWorkingCopy;
+import org.eclipse.remote.ui.IRemoteUIConnectionWizard;
+import org.eclipse.swt.widgets.Shell;
+
+public class DockerConnectionWizard extends Wizard implements IRemoteUIConnectionWizard {
+
+ private final Shell fShell;
+ private final DockerConnectionPage fPage;
+
+ public DockerConnectionWizard(Shell shell, IRemoteConnectionType connectionType) {
+ fShell = shell;
+ fPage = new DockerConnectionPage(connectionType);
+ }
+
+ @Override
+ public void addPages() {
+ super.addPages();
+ addPage(fPage);
+ }
+
+ public IRemoteConnectionWorkingCopy open() {
+ WizardDialog dialog = new WizardDialog(fShell, this);
+ dialog.setBlockOnOpen(true);
+ if (dialog.open() == WizardDialog.OK) {
+ return fPage.getConnection();
+ }
+ return null;
+ }
+
+ @Override
+ public IRemoteConnectionWorkingCopy getConnection() {
+ return fPage.getConnection();
+ }
+
+ @Override
+ public boolean performCancel() {
+ return true;
+ }
+
+ @Override
+ public boolean performFinish() {
+ return true;
+ }
+
+ @Override
+ public void setConnection(IRemoteConnectionWorkingCopy connection) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setConnectionName(String name) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setInvalidConnectionNames(Set<String> names) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/plugins/org.yocto.remote.docker.ui/src/org/yocto/remote/docker/ui/DockerUIConnectionService.java b/plugins/org.yocto.remote.docker.ui/src/org/yocto/remote/docker/ui/DockerUIConnectionService.java
new file mode 100644
index 00000000000..f254c4acf26
--- /dev/null
+++ b/plugins/org.yocto.remote.docker.ui/src/org/yocto/remote/docker/ui/DockerUIConnectionService.java
@@ -0,0 +1,96 @@
+package org.yocto.remote.docker.ui;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
+import org.eclipse.jface.operation.IRunnableContext;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.remote.core.IRemoteConnection;
+import org.eclipse.remote.core.IRemoteConnectionType;
+import org.eclipse.remote.core.IRemoteConnectionType.Service;
+import org.eclipse.remote.core.exception.RemoteConnectionException;
+import org.eclipse.remote.ui.AbstractRemoteUIConnectionService;
+import org.eclipse.remote.ui.IRemoteUIConnectionService;
+import org.eclipse.remote.ui.IRemoteUIConnectionWizard;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Shell;
+
+public class DockerUIConnectionService extends AbstractRemoteUIConnectionService {
+
+ private final IRemoteConnectionType fConnectionType;
+
+ public DockerUIConnectionService(IRemoteConnectionType connectionType) {
+ fConnectionType = connectionType;
+ }
+
+ public static class Factory implements IRemoteConnectionType.Service.Factory {
+ @SuppressWarnings("unchecked")
+ @Override
+ public <T extends Service> T getService(IRemoteConnectionType connectionType, Class<T> service) {
+ if (IRemoteUIConnectionService.class.equals(service)) {
+ return (T) new DockerUIConnectionService(connectionType);
+ }
+ return null;
+ }
+ }
+
+ @Override
+ public IRemoteConnectionType getConnectionType() {
+ return fConnectionType;
+ }
+
+ @Override
+ public IRemoteUIConnectionWizard getConnectionWizard(Shell shell) {
+ return new DockerConnectionWizard(shell, fConnectionType);
+ }
+
+ @Override
+ public void openConnectionWithProgress(Shell shell, IRunnableContext context, final IRemoteConnection connection) {
+ if (!connection.isOpen()) {
+ IRunnableWithProgress op = new IRunnableWithProgress() {
+ @Override
+ public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
+ try {
+ connection.open(monitor);
+ } catch (RemoteConnectionException e) {
+ throw new InvocationTargetException(e);
+ }
+ if (monitor.isCanceled()) {
+ throw new InterruptedException();
+ }
+ }
+ };
+ try {
+ if (context != null) {
+ context.run(true, true, op);
+ } else {
+ new ProgressMonitorDialog(shell).run(true, true, op);
+ }
+ } catch (InvocationTargetException e) {
+ ErrorDialog.openError(shell, "Connection error",
+ "Could not open connection",
+ new Status(IStatus.ERROR, Activator.getUniqueIdentifier(), e.getCause().getMessage()));
+ } catch (InterruptedException e) {
+ ErrorDialog.openError(shell, "Connection error",
+ "Could not open connection",
+ new Status(IStatus.ERROR, Activator.getUniqueIdentifier(), e.getMessage()));
+ }
+ }
+ }
+
+ @Override
+ public ILabelProvider getLabelProvider() {
+ return new DefaultLabelProvider() {
+ @Override
+ public Image getImage(Object element) {
+ return Activator.getDefault().getImageRegistry().get(Activator.IMG_CONNECTION_TYPE);
+ }
+ };
+ }
+
+}
diff --git a/plugins/org.yocto.remote.docker/.classpath b/plugins/org.yocto.remote.docker/.classpath
new file mode 100644
index 00000000000..098194ca4b7
--- /dev/null
+++ b/plugins/org.yocto.remote.docker/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/plugins/org.yocto.remote.docker/.project b/plugins/org.yocto.remote.docker/.project
new file mode 100644
index 00000000000..5c235cfcc6d
--- /dev/null
+++ b/plugins/org.yocto.remote.docker/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.yocto.remote.docker</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/plugins/org.yocto.remote.docker/.settings/org.eclipse.jdt.core.prefs b/plugins/org.yocto.remote.docker/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 00000000000..f42de363afa
--- /dev/null
+++ b/plugins/org.yocto.remote.docker/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
+org.eclipse.jdt.core.compiler.compliance=1.7
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.7
diff --git a/plugins/org.yocto.remote.docker/META-INF/MANIFEST.MF b/plugins/org.yocto.remote.docker/META-INF/MANIFEST.MF
new file mode 100644
index 00000000000..47b69dce8cd
--- /dev/null
+++ b/plugins/org.yocto.remote.docker/META-INF/MANIFEST.MF
@@ -0,0 +1,14 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Yocto Docker Remote
+Bundle-SymbolicName: org.yocto.remote.docker;singleton:=true
+Bundle-Version: 1.0.0.qualifier
+Bundle-Activator: org.yocto.remote.docker.Activator
+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
diff --git a/plugins/org.yocto.remote.docker/build.properties b/plugins/org.yocto.remote.docker/build.properties
new file mode 100644
index 00000000000..e9863e281ea
--- /dev/null
+++ b/plugins/org.yocto.remote.docker/build.properties
@@ -0,0 +1,5 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml
diff --git a/plugins/org.yocto.remote.docker/plugin.xml b/plugins/org.yocto.remote.docker/plugin.xml
new file mode 100644
index 00000000000..902bfb6bf2f
--- /dev/null
+++ b/plugins/org.yocto.remote.docker/plugin.xml
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension
+ point="org.eclipse.remote.core.remoteServices">
+ <connectionType
+ canAdd="true"
+ canEdit="false"
+ canRemove="true"
+ id="org.yocto.remote.docker.DockerServices"
+ name="docker"
+ scheme="docker">
+ </connectionType>
+ <connectionService
+ connectionTypeId="org.yocto.remote.docker.DockerServices"
+ factory="org.yocto.remote.docker.DockerConnection$Factory"
+ service="org.eclipse.remote.core.IRemoteConnectionControlService">
+ </connectionService>
+ <connectionService
+ connectionTypeId="org.yocto.remote.docker.DockerServices"
+ factory="org.yocto.remote.docker.DockerConnection$Factory"
+ service="org.eclipse.remote.core.IRemoteConnectionPropertyService">
+ </connectionService>
+ <connectionService
+ connectionTypeId="org.yocto.remote.docker.DockerServices"
+ factory="org.yocto.remote.docker.DockerConnection$Factory"
+ service="org.eclipse.remote.core.IRemoteProcessService">
+ </connectionService>
+ <connectionService
+ connectionTypeId="org.yocto.remote.docker.DockerServices"
+ factory="org.yocto.remote.docker.DockerRemoteFileService$Factory"
+ service="org.eclipse.remote.core.IRemoteFileService">
+ </connectionService>
+ <connectionService
+ connectionTypeId="org.yocto.remote.docker.DockerServices"
+ factory="org.yocto.remote.docker.DockerConnection$Factory"
+ service="org.eclipse.remote.core.IRemoteConnectionHostService">
+ </connectionService>
+ <connectionService
+ connectionTypeId="org.yocto.remote.docker.DockerServices"
+ factory="org.yocto.remote.docker.DockerConnection$Factory"
+ service="org.yocto.remote.docker.DockerConnection">
+ </connectionService>
+ <processService
+ connectionTypeId="org.yocto.remote.docker.DockerServices"
+ factory="org.yocto.remote.docker.DockerProcess$Factory"
+ service="org.eclipse.remote.core.IRemoteProcessControlService">
+ </processService>
+ <processService
+ connectionTypeId="org.yocto.remote.docker.DockerServices"
+ factory="org.yocto.remote.docker.DockerProcess$Factory"
+ service="org.yocto.remote.docker.DockerProcess">
+ </processService>
+ </extension>
+ <extension
+ id="org.yocto.remote.docker.filesystem"
+ point="org.eclipse.core.filesystem.filesystems">
+ <filesystem
+ scheme="docker">
+ <run
+ class="org.yocto.remote.docker.DockerFileSystem">
+ </run>
+ </filesystem>
+ </extension>
+
+ <extension
+ point="org.eclipse.remote.core.remoteResources">
+ <remoteResource
+ class="org.yocto.remote.docker.DockerRemoteResource"
+ nature="org.eclipse.cdt.autotools.core.autotoolsNatureV2">
+ </remoteResource>
+ </extension>
+
+
+</plugin>
diff --git a/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/Activator.java b/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/Activator.java
new file mode 100644
index 00000000000..90b66c26c6d
--- /dev/null
+++ b/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/Activator.java
@@ -0,0 +1,105 @@
+package org.yocto.remote.docker;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Plugin;
+import org.eclipse.core.runtime.Status;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+public class Activator extends Plugin {
+
+ private static final String PLUGIN_ID = "org.yocto.remote.docker"; //$NON-NLS-1$
+
+ // The shared instance
+ private static Activator plugin;
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+ /**
+ * Get unique identifier for this plugin
+ */
+ public static String getUniqueIdentifier() {
+ if (getDefault() == null) {
+ return PLUGIN_ID;
+ }
+ return getDefault().getBundle().getSymbolicName();
+ }
+
+ /**
+ * Logs the specified status with this plug-in's log.
+ *
+ * @param status
+ * status to log
+ */
+ public static void log(IStatus status) {
+ getDefault().getLog().log(status);
+ }
+
+ /**
+ * Logs an internal error with the specified message.
+ *
+ * @param message
+ * the error message to log
+ */
+ public static void log(String message) {
+ log(new Status(IStatus.ERROR, getUniqueIdentifier(), IStatus.ERROR, message, null));
+ }
+
+ /**
+ * Logs an internal error with the specified throwable
+ *
+ * @param e
+ * the exception to be logged
+ */
+ public static void log(Throwable e) {
+ log(new Status(IStatus.ERROR, getUniqueIdentifier(), IStatus.ERROR, e.getMessage(), e));
+ }
+
+ /**
+ * Return the OSGi service with the given service interface.
+ *
+ * @param service service interface
+ * @return the specified service or null if it's not registered
+ */
+ public static <T> T getService(Class<T> service) {
+ BundleContext context = plugin.getBundle().getBundleContext();
+ ServiceReference<T> ref = context.getServiceReference(service);
+ return ref != null ? context.getService(ref) : null;
+ }
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext )
+ */
+ @Override
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext )
+ */
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+}
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
new file mode 100644
index 00000000000..ab04256bb11
--- /dev/null
+++ b/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerConnection.java
@@ -0,0 +1,190 @@
+package org.yocto.remote.docker;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.remote.core.IRemoteConnection;
+import org.eclipse.remote.core.IRemoteConnection.Service;
+import org.eclipse.remote.core.IRemoteConnectionControlService;
+import org.eclipse.remote.core.IRemoteConnectionHostService;
+import org.eclipse.remote.core.IRemoteConnectionPropertyService;
+import org.eclipse.remote.core.IRemoteProcessBuilder;
+import org.eclipse.remote.core.IRemoteProcessService;
+import org.eclipse.remote.core.exception.RemoteConnectionException;
+
+public class DockerConnection implements IRemoteConnectionControlService,
+IRemoteConnectionPropertyService, IRemoteConnectionHostService, IRemoteProcessService {
+
+ private static final Map<IRemoteConnection, DockerConnection> connectionMap = new HashMap<>();
+
+
+ private IRemoteConnection connection;
+ private String workingDir;
+
+ public static class Factory implements IRemoteConnection.Service.Factory {
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public <T extends Service> T getService(IRemoteConnection connection, Class<T> service) {
+ if (DockerConnection.class.equals(service)) {
+ synchronized (connectionMap) {
+ DockerConnection dconnection = connectionMap.get(connection);
+ if (dconnection == null) {
+ dconnection = new DockerConnection(connection);
+ connectionMap.put(connection, dconnection);
+ }
+ return (T) dconnection;
+ }
+ } else if (IRemoteConnectionControlService.class.equals(service)
+ || IRemoteConnectionPropertyService.class.equals(service)
+ || IRemoteProcessService.class.equals(service) || IRemoteConnectionHostService.class.equals(service)) {
+ return (T) connection.getService(DockerConnection.class);
+ } else {
+ return null;
+ }
+ }
+ }
+ public DockerConnection(IRemoteConnection connection) {
+ this.connection = connection;
+ }
+
+ @Override
+ public IRemoteConnection getRemoteConnection() {
+ return connection;
+ }
+
+ private boolean open;
+
+ @Override
+ public void open(IProgressMonitor monitor) throws RemoteConnectionException {
+ open = true;
+ }
+
+ @Override
+ public void close() {
+ open = false;
+ }
+
+ @Override
+ public boolean isOpen() {
+ return open;
+ }
+
+ @Override
+ public String getProperty(String key) {
+ // XXX this needs to be the properties from container
+ String prop = System.getProperty(key);
+ return prop;
+ }
+
+ @Override
+ public Map<String, String> getEnv() {
+ // XXX this needs to be the environment from container
+ Map<String,String> env = System.getenv();
+ return env;
+ }
+
+ @Override
+ public String getEnv(String name) {
+ return getEnv().get(name);
+ }
+
+ @Override
+ public IRemoteProcessBuilder getProcessBuilder(List<String> command) {
+ return new DockerProcessBuilder(connection,command.toArray(new String[command.size()]));
+ }
+
+ @Override
+ public IRemoteProcessBuilder getProcessBuilder(String... command) {
+ return new DockerProcessBuilder(connection,command);
+ }
+
+ @Override
+ public String getWorkingDirectory() {
+ return this.workingDir;
+ }
+
+ @Override
+ public void setWorkingDirectory(String path) {
+ this.workingDir = path;
+ }
+
+ public void getDockerFileService() throws RemoteConnectionException {
+ throw new RemoteConnectionException("Docker remote file service not supported");
+ }
+
+ @Override
+ public String getHostname() {
+ return "local";
+ }
+
+ @Override
+ public int getPort() {
+ return 0;
+ }
+
+ @Override
+ public int getTimeout() {
+ return 0;
+ }
+
+ @Override
+ public String getPassphrase() {
+ return null;
+ }
+
+ @Override
+ public String getPassword() {
+ return null;
+ }
+
+ @Override
+ public boolean usePassword() {
+ return false;
+ }
+
+ @Override
+ public boolean useLoginShell() {
+ return false;
+ }
+
+ @Override
+ public String getUsername() {
+ return "root";
+ }
+
+ @Override
+ public void setHostname(String hostname) {
+ }
+
+ @Override
+ public void setPassphrase(String passphrase) {
+ }
+
+ @Override
+ public void setPassword(String password) {
+ }
+
+ @Override
+ public void setPort(int port) {
+ }
+
+ @Override
+ public void setTimeout(int timeout) {
+ }
+
+ @Override
+ public void setUseLoginShell(boolean useLogingShell) {
+ }
+
+ @Override
+ public void setUsePassword(boolean usePassword) {
+ }
+
+ @Override
+ public void setUsername(String username) {
+ }
+
+}
diff --git a/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerConnectionProviderService.java b/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerConnectionProviderService.java
new file mode 100644
index 00000000000..ce0d37bf9b0
--- /dev/null
+++ b/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerConnectionProviderService.java
@@ -0,0 +1,45 @@
+package org.yocto.remote.docker;
+
+import org.eclipse.remote.core.IRemoteConnectionProviderService;
+import org.eclipse.remote.core.IRemoteConnectionType;
+import org.eclipse.remote.core.IRemoteConnectionType.Service;
+import org.eclipse.remote.core.exception.RemoteConnectionException;
+
+public class DockerConnectionProviderService implements IRemoteConnectionProviderService {
+
+ private static final String dockerConnectionName = "docker";
+
+ private IRemoteConnectionType connectionType;
+
+ public static class Factory implements IRemoteConnectionType.Service.Factory {
+ @SuppressWarnings("unchecked")
+ @Override
+ public <T extends Service> T getService(IRemoteConnectionType connectionType, Class<T> service) {
+ if (service.equals(IRemoteConnectionProviderService.class)) {
+ return (T) new DockerConnectionProviderService(connectionType);
+ }
+ return null;
+ }
+ }
+
+ public DockerConnectionProviderService(IRemoteConnectionType connectionType) {
+ this.connectionType = connectionType;
+ }
+
+ @Override
+ public void init() {
+ if (connectionType.getConnections().isEmpty()) {
+ try {
+ connectionType.newConnection(dockerConnectionName).save();
+ } catch (RemoteConnectionException e) {
+ Activator.log(e.getStatus());
+ }
+ }
+ }
+
+ @Override
+ public IRemoteConnectionType getConnectionType() {
+ return connectionType;
+ }
+
+}
diff --git a/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerFileStore.java b/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerFileStore.java
new file mode 100644
index 00000000000..9b7a88f8507
--- /dev/null
+++ b/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerFileStore.java
@@ -0,0 +1,296 @@
+package org.yocto.remote.docker;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.filesystem.EFS;
+import org.eclipse.core.filesystem.IFileInfo;
+import org.eclipse.core.filesystem.IFileStore;
+import org.eclipse.core.filesystem.provider.FileStore;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.SubMonitor;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.remote.core.IRemoteConnection;
+import org.eclipse.remote.core.IRemoteConnectionType;
+import org.eclipse.remote.core.IRemoteServicesManager;
+import org.eclipse.remote.core.RemoteServicesUtils;
+import org.eclipse.remote.core.exception.RemoteConnectionException;
+
+public class DockerFileStore extends FileStore {
+
+ public static DockerFileStore getInstance(URI uri) {
+ synchronized (instanceMap) {
+ DockerFileStore store = instanceMap.get(uri.toString());
+ if (store == null) {
+ store = new DockerFileStore(uri);
+ instanceMap.put(uri.toString(), store);
+ }
+ return store;
+ }
+ }
+
+ private static Map<String, DockerFileStore> instanceMap = new HashMap<String, DockerFileStore>();
+
+ private final IPath fRemotePath;
+ private final URI fURI;
+
+ private DockerFileStore(URI uri) {
+ fURI = uri;
+ fRemotePath = RemoteServicesUtils.posixPath(uri.getPath());
+ }
+
+ private DockerConnection checkConnection(IProgressMonitor monitor) throws RemoteConnectionException {
+ IRemoteServicesManager manager = Activator.getService(IRemoteServicesManager.class);
+ IRemoteConnectionType connectionType = manager.getConnectionType(fURI);
+ if (connectionType == null) {
+ throw new RemoteConnectionException(NLS.bind("No remote services found for URI: ${0}", fURI));
+ }
+
+ try {
+ IRemoteConnection connection = connectionType.getConnection(fURI);
+ if (connection == null) {
+ throw new RemoteConnectionException(NLS.bind("Invalid connection for URI: ${0}", fURI));
+ }
+ if (!connection.isOpen()) {
+ connection.open(monitor);
+ if (!connection.isOpen()) {
+ throw new RemoteConnectionException("Connection not open to docker");
+ }
+ }
+ return connection.getService(DockerConnection.class);
+ } catch (CoreException e) {
+ throw new RemoteConnectionException(e);
+ }
+ }
+
+ @Override
+ public IFileInfo[] childInfos(int options, IProgressMonitor monitor) throws CoreException {
+ SubMonitor subMon = SubMonitor.convert(monitor, 10);
+ DockerConnection connection = checkConnection(subMon.newChild(1));
+ //ChildInfosCommand command = new ChildInfosCommand(connection, fRemotePath);
+ //return command.getResult(subMon.newChild(9));
+ return new IFileInfo[0];
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.filesystem.provider.FileStore#childNames(int,
+ * org.eclipse.core.runtime.IProgressMonitor)
+ */
+ @Override
+ public String[] childNames(int options, IProgressMonitor monitor) throws CoreException {
+ SubMonitor subMon = SubMonitor.convert(monitor, 10);
+ IFileInfo[] infos = childInfos(options, subMon.newChild(10));
+ String[] names = new String[infos.length];
+ for (int i = 0; i < infos.length; i++) {
+ names[i] = infos[i].getName();
+ }
+ return names;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.filesystem.provider.FileStore#delete(int,
+ * org.eclipse.core.runtime.IProgressMonitor)
+ */
+ @Override
+ public void delete(int options, IProgressMonitor monitor) throws CoreException {
+ SubMonitor subMon = SubMonitor.convert(monitor, 20);
+ DockerConnection connection = checkConnection(subMon.newChild(1));
+ IFileInfo info = fetchInfo(EFS.NONE, subMon.newChild(9));
+ if (!subMon.isCanceled() && info.exists()) {
+ //DeleteCommand command = new DeleteCommand(connection, fRemotePath);
+ //command.getResult(subMon.newChild(10));
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.filesystem.provider.FileStore#fetchInfo(int,
+ * org.eclipse.core.runtime.IProgressMonitor)
+ */
+ @Override
+ public IFileInfo fetchInfo(int options, IProgressMonitor monitor) throws CoreException {
+ SubMonitor subMon = SubMonitor.convert(monitor, 10);
+ DockerConnection connection = checkConnection(subMon.newChild(1));
+ //FetchInfoCommand command = new FetchInfoCommand(connection, fRemotePath);
+ //return command.getResult(subMon.newChild(9));
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.core.filesystem.provider.FileStore#getChild(java.lang.String)
+ */
+ @Override
+ public IFileStore getChild(String name) {
+ URI uri = DockerFileSystem.getURIFor(DockerFileSystem.getConnectionNameFor(fURI), fRemotePath.append(name).toString());
+ return DockerFileStore.getInstance(uri);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.filesystem.provider.FileStore#getName()
+ */
+ @Override
+ public String getName() {
+ return getNameFromPath(fRemotePath);
+ }
+
+ /**
+ * Utility routing to get the file name from an absolute path.
+ *
+ * @param path
+ * path to extract file name from
+ * @return last segment of path, or the full path if it is root
+ */
+ private String getNameFromPath(IPath path) {
+ if (path.isRoot()) {
+ return path.toString();
+ }
+ return path.lastSegment();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.filesystem.provider.FileStore#getParent()
+ */
+ @Override
+ public IFileStore getParent() {
+ if (fRemotePath.isRoot()) {
+ return null;
+ }
+ String parentPath = fRemotePath.toString();
+ if (fRemotePath.segmentCount() > 0) {
+ parentPath = fRemotePath.removeLastSegments(1).toString();
+ }
+ return DockerFileStore.getInstance(DockerFileSystem.getURIFor(DockerFileSystem.getConnectionNameFor(fURI), parentPath));
+ }
+
+ private String getUniqueIdentifier() {
+ return Activator.getUniqueIdentifier();
+ }
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.filesystem.provider.FileStore#mkdir(int,
+ * org.eclipse.core.runtime.IProgressMonitor)
+ */
+ @Override
+ public IFileStore mkdir(int options, IProgressMonitor monitor) throws CoreException {
+ SubMonitor subMon = SubMonitor.convert(monitor, 20);
+ DockerConnection connection = checkConnection(subMon.newChild(1));
+
+ if ((options & EFS.SHALLOW) == EFS.SHALLOW) {
+ IFileStore parent = getParent();
+ if (parent != null && !parent.fetchInfo(EFS.NONE, subMon.newChild(9)).exists()) {
+ throw new CoreException(new Status(IStatus.ERROR, getUniqueIdentifier(), EFS.ERROR_WRITE,
+ NLS.bind("Parent directory does not exist", fRemotePath.toString()), null));
+ }
+ if (subMon.isCanceled()) {
+ return this;
+ }
+ }
+
+ try {
+ //MkdirCommand command = new MkdirCommand(connection, fRemotePath);
+ //command.getResult(subMon.newChild(10));
+ } catch (Exception e) {
+ // Ignore any exceptions
+ }
+ if (!subMon.isCanceled()) {
+ /*
+ * Check if the result exists and is a directory, throw an exception if neither.
+ */
+ IFileInfo info = fetchInfo(EFS.NONE, subMon.newChild(10));
+ if (!subMon.isCanceled()) {
+ if (!info.exists()) {
+ throw new CoreException(new Status(IStatus.ERROR, getUniqueIdentifier(), EFS.ERROR_WRITE,
+ NLS.bind("Directory could not be created", fRemotePath.toString()), null));
+ }
+ if (!info.isDirectory()) {
+ throw new CoreException(new Status(IStatus.ERROR, getUniqueIdentifier(), EFS.ERROR_WRONG_TYPE,
+ NLS.bind("File name ${0} already exists", fRemotePath.toString()), null));
+ }
+ }
+ }
+
+ return this;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.filesystem.provider.FileStore#openInputStream(int,
+ * org.eclipse.core.runtime.IProgressMonitor)
+ */
+ @Override
+ public InputStream openInputStream(int options, IProgressMonitor monitor) throws CoreException {
+ SubMonitor subMon = SubMonitor.convert(monitor, 30);
+ DockerConnection connection = checkConnection(subMon.newChild(1));
+ IFileInfo info = fetchInfo(EFS.NONE, subMon.newChild(9));
+ if (!subMon.isCanceled()) {
+ if (!info.exists()) {
+ throw new CoreException(new Status(IStatus.ERROR, getUniqueIdentifier(), EFS.ERROR_READ,
+ NLS.bind("File ${0} doesn't exist", fRemotePath.toString()), null));
+ }
+ if (info.isDirectory()) {
+ throw new CoreException(new Status(IStatus.ERROR, getUniqueIdentifier(), EFS.ERROR_WRONG_TYPE,
+ NLS.bind("${0} is a directory", fRemotePath.toString()), null));
+ }
+ //GetInputStreamCommand command = new GetInputStreamCommand(connection, fRemotePath);
+ //return command.getResult(subMon.newChild(10));
+ return null;
+ }
+ return null;
+ }
+
+ @Override
+ public OutputStream openOutputStream(int options, IProgressMonitor monitor) throws CoreException {
+ SubMonitor subMon = SubMonitor.convert(monitor, 30);
+ DockerConnection connection = checkConnection(subMon.newChild(1));
+ IFileInfo info = fetchInfo(EFS.NONE, subMon.newChild(9));
+ if (!subMon.isCanceled()) {
+ if (info.isDirectory()) {
+ throw new CoreException(new Status(IStatus.ERROR, getUniqueIdentifier(), EFS.ERROR_WRONG_TYPE,
+ NLS.bind("${0} is a directory", fRemotePath.toString()), null));
+ }
+ //GetOutputStreamCommand command = new GetOutputStreamCommand(connection, options, fRemotePath);
+ //return command.getResult(subMon.newChild(10));
+ return null;
+ }
+ return null;
+ }
+
+ @Override
+ public void putInfo(IFileInfo info, int options, IProgressMonitor monitor) throws CoreException {
+ SubMonitor subMon = SubMonitor.convert(monitor, 10);
+ DockerConnection connection = checkConnection(subMon.newChild(1));
+ //PutInfoCommand command = new PutInfoCommand(connection, info, options, fRemotePath);
+ //command.getResult(subMon.newChild(9));
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.filesystem.provider.FileStore#toURI()
+ */
+ @Override
+ public URI toURI() {
+ return fURI;
+ }
+}
diff --git a/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerFileSystem.java b/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerFileSystem.java
new file mode 100644
index 00000000000..d1a705b474d
--- /dev/null
+++ b/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerFileSystem.java
@@ -0,0 +1,107 @@
+package org.yocto.remote.docker;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.eclipse.core.filesystem.EFS;
+import org.eclipse.core.filesystem.IFileStore;
+import org.eclipse.core.filesystem.provider.FileSystem;
+import org.eclipse.core.runtime.IPath;
+
+public class DockerFileSystem extends FileSystem {
+
+ /**
+ * Return the connection name encoded in the URI.
+ *
+ * @param uri
+ * URI specifying a remote tools connection
+ * @return name of the connection or null if the URI is invalid
+ * @since 4.0
+ */
+ public static String getConnectionNameFor(URI uri) {
+ return uri.getAuthority();
+ }
+
+ /**
+ * Return an URI uniquely naming a remote tools remote resource.
+ *
+ * @param connectionName
+ * remote tools connection name
+ * @param path
+ * absolute path to resource as valid on the remote system
+ * @return an URI uniquely naming the remote resource.
+ */
+ public static URI getURIFor(String connectionName, String path) {
+ try {
+ return new URI("ssh", connectionName, path, null, null); //$NON-NLS-1$
+ } catch (URISyntaxException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * Default constructor.
+ */
+ public DockerFileSystem() {
+ super();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.filesystem.IFileSystem#attributes()
+ */
+ @Override
+ public int attributes() {
+ // Attributes supported by JSch IFileService
+ return EFS.ATTRIBUTE_READ_ONLY | EFS.ATTRIBUTE_EXECUTABLE | EFS.ATTRIBUTE_SYMLINK | EFS.ATTRIBUTE_LINK_TARGET;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.filesystem.provider.FileSystem#canDelete()
+ */
+ @Override
+ public boolean canDelete() {
+ return true;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.filesystem.provider.FileSystem#canWrite()
+ */
+ @Override
+ public boolean canWrite() {
+ return true;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.filesystem.provider.FileSystem#getStore(org.eclipse.core.runtime.IPath)
+ */
+ @Override
+ public IFileStore getStore(IPath path) {
+ return EFS.getNullFileSystem().getStore(path);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.core.filesystem.provider.FileSystem#getStore(java.net.URI)
+ */
+ @Override
+ public IFileStore getStore(URI uri) {
+ try {
+ return DockerFileStore.getInstance(uri);
+ } catch (Exception e) {
+ e.printStackTrace();
+ // Could be an URI format exception
+ //Activator.log(e);
+ return EFS.getNullFileSystem().getStore(uri);
+ }
+ }
+}
diff --git a/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerProcess.java b/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerProcess.java
new file mode 100644
index 00000000000..b5bae72574a
--- /dev/null
+++ b/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerProcess.java
@@ -0,0 +1,216 @@
+package org.yocto.remote.docker;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PipedInputStream;
+import java.io.PipedOutputStream;
+
+import org.eclipse.remote.core.IRemoteProcess;
+import org.eclipse.remote.core.IRemoteProcessControlService;
+
+public class DockerProcess implements IRemoteProcessControlService {
+
+ private static int refCount = 0;
+
+ private final IRemoteProcess remoteProcess;
+ private final Process localProcess;
+ private InputStream procStdout;
+ private InputStream procStderr;
+ private Thread stdoutReader;
+ private Thread stderrReader;
+ private final Thread completedChecker;
+ private volatile boolean isCompleted;
+
+ public static class Factory implements IRemoteProcess.Service.Factory {
+ @SuppressWarnings("unchecked")
+ @Override
+ public <T extends IRemoteProcess.Service> T getService(IRemoteProcess remoteProcess, Class<T> service) {
+ // This little trick creates an instance of this class
+ // then for each interface it implements, it returns the same object.
+ // This works because the connection caches the service so only one gets created.
+ // As a side effect, it makes this class a service too which can be used
+ // by the this plug-in
+ if (DockerProcess.class.equals(service)) {
+ return (T) new DockerProcess(remoteProcess);
+ }
+ if (IRemoteProcessControlService.class.equals(service)) {
+ return (T) remoteProcess.getService(DockerProcess.class);
+ }
+ return null;
+ }
+ }
+
+ /**
+ * Thread to merge stdout and stderr. Keeps refcount so that output stream
+ * is not closed too early.
+ *
+ */
+ private class ProcOutputMerger implements Runnable {
+ private final static int BUF_SIZE = 8192;
+
+ private final InputStream input;
+ private final OutputStream output;
+
+ public ProcOutputMerger(InputStream input, OutputStream output) {
+ this.input = input;
+ this.output = output;
+ synchronized (this.output) {
+ refCount++;
+ }
+ }
+
+ @Override
+ public void run() {
+ int len;
+ byte b[] = new byte[BUF_SIZE];
+
+ try {
+ while ((len = input.read(b)) > 0) {
+ output.write(b, 0, len);
+ }
+ } catch (IOException e) {
+ // Ignore
+ }
+ synchronized (output) {
+ if (--refCount == 0) {
+ try {
+ output.close();
+ } catch (IOException e) {
+ // Ignore
+ }
+ }
+ }
+ }
+ }
+
+ public class NullInputStream extends InputStream {
+ @Override
+ public int read() throws IOException {
+ return -1;
+ }
+
+ @Override
+ public int available() {
+ return 0;
+ }
+ }
+
+ public DockerProcess(IRemoteProcess process) {
+ remoteProcess = process;
+ DockerProcessBuilder builder = (DockerProcessBuilder) process.getProcessBuilder();
+ localProcess = builder.getProcess();
+
+ try {
+ if (process.getProcessBuilder().redirectErrorStream()) {
+ PipedOutputStream pipedOutput = new PipedOutputStream();
+
+ procStderr = new NullInputStream();
+ procStdout = new PipedInputStream(pipedOutput);
+
+ stderrReader = new Thread(new ProcOutputMerger(localProcess.getErrorStream(), pipedOutput));
+ stdoutReader = new Thread(new ProcOutputMerger(localProcess.getInputStream(), pipedOutput));
+
+ stderrReader.start();
+ stdoutReader.start();
+ } else {
+ procStderr = localProcess.getErrorStream();
+ procStdout = localProcess.getInputStream();
+ }
+ } catch (IOException e) {
+ localProcess.destroy();
+ }
+
+ completedChecker = new Thread(new Runnable() {
+ @Override
+ public void run() {
+ while (!isCompleted) {
+ try {
+ localProcess.waitFor();
+ } catch (InterruptedException e) {
+ continue;
+ }
+ isCompleted = true;
+ }
+ }
+
+ });
+ completedChecker.start();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Process#destroy()
+ */
+ @Override
+ public void destroy() {
+ localProcess.destroy();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Process#exitValue()
+ */
+ @Override
+ public int exitValue() {
+ return localProcess.exitValue();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Process#getErrorStream()
+ */
+ @Override
+ public InputStream getErrorStream() {
+ return procStderr;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Process#getInputStream()
+ */
+ @Override
+ public InputStream getInputStream() {
+ return procStdout;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Process#getOutputStream()
+ */
+ @Override
+ public OutputStream getOutputStream() {
+ return localProcess.getOutputStream();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.Process#waitFor()
+ */
+ @Override
+ public int waitFor() throws InterruptedException {
+ return localProcess.waitFor();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.remote.core.RemoteProcess#isCompleted()
+ */
+ @Override
+ public boolean isCompleted() {
+ return isCompleted;
+ }
+
+ @Override
+ public IRemoteProcess getRemoteProcess() {
+ return remoteProcess;
+ }
+
+}
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
new file mode 100644
index 00000000000..4800c51237a
--- /dev/null
+++ b/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerProcessBuilder.java
@@ -0,0 +1,127 @@
+package org.yocto.remote.docker;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Properties;
+
+import org.eclipse.core.filesystem.EFS;
+import org.eclipse.core.filesystem.IFileStore;
+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.Path;
+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.yocto.docker.launcher.ui.PokyContainerLauncher;
+
+public class DockerProcessBuilder extends AbstractRemoteProcessBuilder implements IRemoteProcessBuilder {
+
+ private final Map<String, String> fRemoteEnv = new HashMap<String, String>();
+
+ private Process localProcess;
+
+ public DockerProcessBuilder(IRemoteConnection connection, List<String> command) {
+ super(connection, command);
+ fRemoteEnv.putAll(System.getenv());
+ }
+
+ public DockerProcessBuilder(IRemoteConnection connection, String... command) {
+ this(connection, Arrays.asList(command));
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.remote.core.AbstractRemoteProcessBuilder#directory()
+ */
+ @Override
+ public IFileStore directory() {
+ IFileStore dir = super.directory();
+ if (dir == null) {
+ String userDir = System.getProperty("user.dir"); //$NON-NLS-1$
+ if (userDir != null) {
+ dir = EFS.getLocalFileSystem().getStore(Path.fromOSString(userDir));
+ directory(dir);
+ }
+ }
+ return dir;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.remote.core.AbstractRemoteProcessBuilder#environment()
+ */
+ @Override
+ public Map<String, String> environment() {
+ return fRemoteEnv;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.remote.core.AbstractRemoteProcessBuilder#getSupportedFlags
+ * ()
+ */
+ @Override
+ public int getSupportedFlags() {
+ return NONE;
+ }
+
+ private IProject findProject() throws CoreException {
+ IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
+ if (projects == null)
+ return null;
+ IFileStore dir = directory();
+ File targetFile = dir.toLocalFile(EFS.NONE, null);
+ for (IProject project : projects) {
+ IPath path = project.getLocation();
+ File projectPath = path.toFile();
+ if (project.isOpen() && projectPath.equals(targetFile)) {
+ return project;
+ }
+ }
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.remote.core.IRemoteProcessBuilder#start(int)
+ */
+ @Override
+ public IRemoteProcess start(int flags) throws IOException {
+ String commandArray[] = command().toArray(new String[0]);
+ 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());
+ }
+ return new DockerRemoteProcess(this, getProcess());
+ }
+
+ public Process getProcess() {
+ return localProcess;
+ }
+
+}
diff --git a/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerProcessControlService.java b/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerProcessControlService.java
new file mode 100644
index 00000000000..1be5b096083
--- /dev/null
+++ b/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerProcessControlService.java
@@ -0,0 +1,63 @@
+package org.yocto.remote.docker;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.eclipse.remote.core.IRemoteProcess;
+import org.eclipse.remote.core.IRemoteProcessControlService;
+
+public class DockerProcessControlService implements IRemoteProcessControlService {
+
+ public DockerProcessControlService() {
+ // TODO Auto-generated constructor stub
+ }
+
+ @Override
+ public IRemoteProcess getRemoteProcess() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void destroy() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public int exitValue() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public InputStream getErrorStream() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public InputStream getInputStream() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public OutputStream getOutputStream() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public int waitFor() throws InterruptedException {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public boolean isCompleted() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+}
diff --git a/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerProcessService.java b/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerProcessService.java
new file mode 100644
index 00000000000..a43c571b9dc
--- /dev/null
+++ b/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerProcessService.java
@@ -0,0 +1,76 @@
+package org.yocto.remote.docker;
+
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.runtime.Path;
+import org.eclipse.remote.core.IRemoteConnection;
+import org.eclipse.remote.core.IRemoteProcessBuilder;
+import org.eclipse.remote.core.IRemoteProcessService;
+import org.eclipse.remote.core.IRemoteConnection.Service;
+
+public class DockerProcessService implements IRemoteProcessService {
+
+ private final IRemoteConnection remoteConnection;
+ private String workingDirectory;
+
+ public DockerProcessService(IRemoteConnection remoteConnection) {
+ this.remoteConnection = remoteConnection;
+ }
+
+ public static class Factory implements IRemoteProcessService.Factory {
+ @SuppressWarnings("unchecked")
+ @Override
+ public <T extends Service> T getService(IRemoteConnection remoteConnection, Class<T> service) {
+ if (IRemoteProcessService.class.equals(service)) {
+ return (T) new DockerProcessService(remoteConnection);
+ }
+ return null;
+ }
+ }
+
+ @Override
+ public IRemoteConnection getRemoteConnection() {
+ return remoteConnection;
+ }
+
+ @Override
+ public Map<String, String> getEnv() {
+ return System.getenv();
+ }
+
+ @Override
+ public String getEnv(String name) {
+ return System.getenv(name);
+ }
+
+ @Override
+ public IRemoteProcessBuilder getProcessBuilder(List<String> command) {
+ return new DockerProcessBuilder(remoteConnection, command);
+ }
+
+ @Override
+ public IRemoteProcessBuilder getProcessBuilder(String... command) {
+ return new DockerProcessBuilder(remoteConnection, command);
+ }
+
+ @Override
+ public String getWorkingDirectory() {
+ if (workingDirectory == null) {
+ workingDirectory = System.getProperty("user.home"); //$NON-NLS-1$
+ if (workingDirectory == null) {
+ workingDirectory = System.getProperty("user.dir"); //$NON-NLS-1$
+ if (workingDirectory == null) {
+ workingDirectory = Path.ROOT.toOSString();
+ }
+ }
+ }
+ return workingDirectory;
+ }
+
+ @Override
+ public void setWorkingDirectory(String path) {
+ workingDirectory = path;
+ }
+
+}
diff --git a/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerRemoteConnectionHostService.java b/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerRemoteConnectionHostService.java
new file mode 100644
index 00000000000..56ee19188f4
--- /dev/null
+++ b/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerRemoteConnectionHostService.java
@@ -0,0 +1,117 @@
+package org.yocto.remote.docker;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+import org.eclipse.remote.core.IRemoteConnection;
+import org.eclipse.remote.core.IRemoteConnectionHostService;
+import org.eclipse.remote.core.IRemoteConnection.Service;
+
+public class DockerRemoteConnectionHostService implements IRemoteConnectionHostService {
+
+ private final IRemoteConnection connection;
+
+ public DockerRemoteConnectionHostService(IRemoteConnection connection) {
+ this.connection = connection;
+ }
+
+ public static class Factory implements IRemoteConnectionHostService.Factory {
+ @SuppressWarnings("unchecked")
+ @Override
+ public <T extends Service> T getService(IRemoteConnection remoteConnection, Class<T> service) {
+ if (service.equals(IRemoteConnectionHostService.class)) {
+ return (T) new DockerRemoteConnectionHostService(remoteConnection);
+ }
+ return null;
+ }
+ }
+
+ @Override
+ public IRemoteConnection getRemoteConnection() {
+ return this.connection;
+ }
+
+ @Override
+ public String getHostname() {
+ try {
+ return InetAddress.getLocalHost().getHostName();
+ } catch (UnknownHostException e) {
+ return "unknown"; //$NON-NLS-1$
+ }
+ }
+
+ @Override
+ public String getPassphrase() {
+ return ""; //$NON-NLS-1$
+ }
+
+ @Override
+ public String getPassword() {
+ return ""; //$NON-NLS-1$
+ }
+
+ @Override
+ public int getPort() {
+ return 0;
+ }
+
+ @Override
+ public int getTimeout() {
+ return 0;
+ }
+
+ @Override
+ public boolean useLoginShell() {
+ return true;
+ }
+
+ @Override
+ public String getUsername() {
+ return System.getProperty("user.name"); //$NON-NLS-1$
+ }
+
+ @Override
+ public void setHostname(String hostname) {
+ // Ignored
+ }
+
+ @Override
+ public void setPassphrase(String passphrase) {
+ // Ignored
+ }
+
+ @Override
+ public void setPassword(String password) {
+ // Ignored
+ }
+
+ @Override
+ public void setPort(int port) {
+ // Ignored
+ }
+
+ @Override
+ public void setTimeout(int timeout) {
+ // Ignored
+ }
+
+ @Override
+ public void setUseLoginShell(boolean useLogingShell) {
+ // Ignored
+ }
+
+ @Override
+ public void setUsePassword(boolean usePassword) {
+ // Ignored
+ }
+
+ @Override
+ public void setUsername(String username) {
+ // Ignored
+ }
+
+ @Override
+ public boolean usePassword() {
+ return false;
+ }
+}
diff --git a/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerRemoteFileService.java b/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerRemoteFileService.java
new file mode 100644
index 00000000000..ca16dba8131
--- /dev/null
+++ b/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerRemoteFileService.java
@@ -0,0 +1,82 @@
+package org.yocto.remote.docker;
+
+import java.net.URI;
+
+import org.eclipse.core.filesystem.EFS;
+import org.eclipse.core.filesystem.IFileStore;
+import org.eclipse.core.filesystem.URIUtil;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.remote.core.IRemoteConnection;
+import org.eclipse.remote.core.IRemoteFileService;
+import org.eclipse.remote.core.IRemoteProcessService;
+import org.eclipse.remote.core.IRemoteConnection.Service;
+import org.eclipse.remote.core.exception.RemoteConnectionException;
+
+public class DockerRemoteFileService implements IRemoteFileService {
+
+ private final IRemoteConnection connection;
+
+ public DockerRemoteFileService(IRemoteConnection connection) {
+ this.connection = connection;
+ }
+
+ public static class Factory implements IRemoteFileService.Factory {
+ @SuppressWarnings("unchecked")
+ @Override
+ public <T extends Service> T getService(IRemoteConnection remoteConnection, Class<T> service) {
+ if (IRemoteFileService.class.equals(service)) {
+ if (remoteConnection instanceof DockerConnection)
+ try {
+ ((DockerConnection) remoteConnection).getDockerFileService();
+ } catch (RemoteConnectionException e) {
+ throw new UnsupportedOperationException("docker image does not support remote filesystem");
+ }
+ return (T) new DockerRemoteFileService(remoteConnection);
+ }
+ return null;
+ }
+
+ }
+
+ @Override
+ public IRemoteConnection getRemoteConnection() {
+ return connection;
+ }
+
+ @Override
+ public String getDirectorySeparator() {
+ return System.getProperty("file.separator", "/"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ @Override
+ public IFileStore getResource(String path) {
+ return EFS.getLocalFileSystem().getStore(Path.fromOSString(path));
+ }
+
+ @Override
+ public String getBaseDirectory() {
+ return connection.getService(IRemoteProcessService.class).getWorkingDirectory();
+ }
+
+ @Override
+ public void setBaseDirectory(String path) {
+ connection.getService(IRemoteProcessService.class).setWorkingDirectory(path);
+ }
+
+ @Override
+ public String toPath(URI uri) {
+ return URIUtil.toPath(uri).toString();
+ }
+
+ @Override
+ public URI toURI(IPath path) {
+ return URIUtil.toURI(path);
+ }
+
+ @Override
+ public URI toURI(String path) {
+ return URIUtil.toURI(path);
+ }
+
+}
diff --git a/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerRemoteProcess.java b/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerRemoteProcess.java
new file mode 100644
index 00000000000..00ebdf92b70
--- /dev/null
+++ b/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerRemoteProcess.java
@@ -0,0 +1,75 @@
+package org.yocto.remote.docker;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.eclipse.remote.core.IRemoteConnection;
+import org.eclipse.remote.core.IRemoteProcess;
+import org.eclipse.remote.core.IRemoteProcessBuilder;
+
+public class DockerRemoteProcess implements IRemoteProcess {
+
+ private Process process;
+ private IRemoteProcessBuilder processBuilder;
+
+ public DockerRemoteProcess(IRemoteProcessBuilder builder, Process process) {
+ this.processBuilder = builder;
+ this.process = process;
+ }
+
+ @Override
+ public void destroy() {
+ process.destroy();
+ }
+
+ @Override
+ public int exitValue() {
+ return process.exitValue();
+ }
+
+ @Override
+ public InputStream getErrorStream() {
+ return process.getErrorStream();
+ }
+
+ @Override
+ public InputStream getInputStream() {
+ return process.getInputStream();
+ }
+
+ @Override
+ public OutputStream getOutputStream() {
+ return process.getOutputStream();
+ }
+
+ @Override
+ public <T extends Service> T getService(Class<T> service) {
+ return null;
+ }
+
+ @Override
+ public <T extends Service> boolean hasService(Class<T> service) {
+ return false;
+ }
+
+ @Override
+ public int waitFor() throws InterruptedException {
+ return process.waitFor();
+ }
+
+ @Override
+ public boolean isCompleted() {
+ return !process.isAlive();
+ }
+
+ @Override
+ public IRemoteConnection getRemoteConnection() {
+ return processBuilder.getRemoteConnection();
+ }
+
+ @Override
+ public IRemoteProcessBuilder getProcessBuilder() {
+ return processBuilder;
+ }
+
+}
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
new file mode 100644
index 00000000000..59a8400cf9f
--- /dev/null
+++ b/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerRemoteResource.java
@@ -0,0 +1,44 @@
+package org.yocto.remote.docker;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.remote.core.IRemoteResource;
+
+public class DockerRemoteResource implements IRemoteResource {
+
+ public static final String DOCKER_SCHEME = "docker";
+
+ private IResource resource;
+
+ @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();
+ }
+ return uri;
+ }
+
+ @Override
+ public IResource getResource() {
+ return resource;
+ }
+
+ @Override
+ public void refresh(IProgressMonitor monitor) throws CoreException {
+ resource.refreshLocal(IResource.DEPTH_INFINITE, monitor);
+ }
+
+ @Override
+ public void setResource(IResource resource) {
+ this.resource = resource;
+ }
+
+}
diff --git a/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerResource.java b/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerResource.java
new file mode 100644
index 00000000000..5f730d99f69
--- /dev/null
+++ b/plugins/org.yocto.remote.docker/src/org/yocto/remote/docker/DockerResource.java
@@ -0,0 +1,57 @@
+package org.yocto.remote.docker;
+
+import java.net.URI;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.remote.core.IRemoteResource;
+
+public class DockerResource implements IRemoteResource {
+
+ private IResource fResource;
+
+ public DockerResource(IResource resource) {
+ fResource = resource;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.remote.core.IRemoteResource#getDefaultLocationURI(org.eclipse.core.resources.IResource)
+ */
+ @Override
+ public URI getActiveLocationURI() {
+ return fResource.getLocationURI();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.remote.core.IRemoteResource#getResource()
+ */
+ @Override
+ public IResource getResource() {
+ return fResource;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.remote.core.IRemoteResource#refresh(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ @Override
+ public void refresh(IProgressMonitor monitor) throws CoreException {
+ fResource.refreshLocal(IResource.DEPTH_INFINITE, monitor);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.remote.core.IRemoteResource#setResource(org.eclipse.core.resources.IResource)
+ */
+ @Override
+ public void setResource(IResource resource) {
+ fResource = resource;
+ }
+}
--
2.13.6
More information about the eclipse-yocto
mailing list