From 3414343c299e65a33a928987879869c99863d08d Mon Sep 17 00:00:00 2001 From: Roland Grunberg Date: Wed, 3 Feb 2016 14:46:41 -0500 Subject: Lookup for docker-machine and the VM driver should consult PATH first. Don't wipe out the PATH set by the system when setting user-specified PATH entry preferences. Instead append additional entries to it. Change-Id: I48bb1b82a6f908e07da0ef85d61fe1e530c5ed63 Reviewed-on: https://git.eclipse.org/r/65843 Tested-by: Hudson CI Reviewed-by: Xavier Coulon (cherry picked from commit 8e0c5a02c780f16b4708b9f2aff3c3d4fa2f20c7) Reviewed-on: https://git.eclipse.org/r/65887 Reviewed-by: Jeff Johnston --- .../internal/docker/core/DockerMachine.java | 25 ++++++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'containers/org.eclipse.linuxtools.docker.core/src/org/eclipse') 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 ece5f92791..2ffe5a7438 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 @@ -15,6 +15,8 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -92,20 +94,29 @@ public class DockerMachine { final String[] args, final String... extraPaths) { try { final String[] command = new String[args.length + 1]; - command[0] = dockerMachineInstallDir - + (dockerMachineInstallDir.endsWith(File.separator) ? "" //$NON-NLS-1$ - : File.separator) - + "docker-machine"; + + command[0] = Paths.get(dockerMachineInstallDir, "docker-machine").toString(); //$NON-NLS-1$ + final String envPath = System.getenv("PATH"); //$NON-NLS-1$ + if (envPath != null) { + for (String dir : envPath.split(File.pathSeparator)) { + Path dmPath = Paths.get(dir, "docker-machine"); //$NON-NLS-1$ + if (dmPath.toFile().exists()) { + command[0] = dmPath.toString(); + break; + } + } + } + System.arraycopy(args, 0, command, 1, args.length); final ProcessBuilder processBuilder = new ProcessBuilder(command); final Map environment = processBuilder .environment(); - final StringBuilder path = new StringBuilder( - dockerMachineInstallDir); + final StringBuilder path = new StringBuilder(); for (String extraPath : extraPaths) { path.append(File.pathSeparator).append(extraPath); } - environment.put("PATH", path.toString()); + String newEnvPath = environment.get("PATH") + path.toString(); //$NON-NLS-1$ + environment.put("PATH", newEnvPath); //$NON-NLS-1$ final Process p = processBuilder.start(); p.waitFor(); if (p.exitValue() == 0) { -- cgit v1.2.3