Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'containers/org.eclipse.linuxtools.docker.core')
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerMachine.java37
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/Messages.java27
-rw-r--r--containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/Messages.properties11
3 files changed, 73 insertions, 2 deletions
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerMachine.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerMachine.java
index 2ffe5a7438..9073a07c09 100644
--- a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerMachine.java
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/DockerMachine.java
@@ -24,6 +24,7 @@ import java.util.Map;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.linuxtools.docker.core.Activator;
+import org.eclipse.osgi.util.NLS;
/**
* Utility class to discover Docker machines using the 'docker-machine' command
@@ -88,13 +89,14 @@ public class DockerMachine {
*
* @param args
* command arguments
- * @return the lines read in the {@link Process}' {@link InputStream}
+ * @return the lines read in the {@link Process}' {@link InputStream} or an
+ * empty array if the {@code docker-machine} command could not be
+ * found in the {@code PATH}.
*/
private static String[] execute(final String dockerMachineInstallDir,
final String[] args, final String... extraPaths) {
try {
final String[] command = new String[args.length + 1];
-
command[0] = Paths.get(dockerMachineInstallDir, "docker-machine").toString(); //$NON-NLS-1$
final String envPath = System.getenv("PATH"); //$NON-NLS-1$
if (envPath != null) {
@@ -117,6 +119,18 @@ public class DockerMachine {
}
String newEnvPath = environment.get("PATH") + path.toString(); //$NON-NLS-1$
environment.put("PATH", newEnvPath); //$NON-NLS-1$
+ // check that the 'docker-machine' can be found in PATH
+ final boolean dockerMachineCommandExists = checkPathToDockerMachine(
+ newEnvPath);
+ if (!dockerMachineCommandExists) {
+ // log a warning and exit
+ Activator
+ .log(new Status(IStatus.WARNING, Activator.PLUGIN_ID,
+ NLS.bind(
+ Messages.Docker_Machine_Command_Not_Found,
+ newEnvPath)));
+ return new String[0];
+ }
final Process p = processBuilder.start();
p.waitFor();
if (p.exitValue() == 0) {
@@ -147,4 +161,23 @@ public class DockerMachine {
return new String[0];
}
+ /**
+ * Checks that the 'docker-machine' command exists in the given {@code path}
+ *
+ * @param path
+ * to path to use to look for the 'docker-machine' command
+ * @return <code>true</code> if the command was found, <code>false</code>
+ * otherwise.
+ */
+ public static boolean checkPathToDockerMachine(final String path) {
+ for (String pathFragment : path.split(File.pathSeparator)) {
+ final File pathToDockerMachine = new File(pathFragment,
+ "docker-machine"); //$NON-NLS-1$
+ if (pathToDockerMachine.exists()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
}
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/Messages.java b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/Messages.java
new file mode 100644
index 0000000000..16f4ba9451
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/Messages.java
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Red Hat.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat - Initial Contribution
+ *******************************************************************************/
+package org.eclipse.linuxtools.internal.docker.core;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+
+ public static String Docker_Machine_Command_Not_Found;
+
+ static {
+ // Initialize resource bundle.
+ NLS.initializeMessages(Messages.class.getName(), Messages.class);
+ }
+
+ private Messages() {
+ }
+
+}
diff --git a/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/Messages.properties b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/Messages.properties
new file mode 100644
index 0000000000..596ae83d10
--- /dev/null
+++ b/containers/org.eclipse.linuxtools.docker.core/src/org/eclipse/linuxtools/internal/docker/core/Messages.properties
@@ -0,0 +1,11 @@
+#################################################################################
+# Copyright (c) 2016 Red Hat Inc.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+# Red Hat - Initial Contribution
+#################################################################################
+Docker_Machine_Command_Not_Found=The '''docker-machine''' command could not be located in {0} \ No newline at end of file

Back to the top