diff options
5 files changed, 96 insertions, 6 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 diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/preferences/DockerMachinePreferencePage.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/preferences/DockerMachinePreferencePage.java index 3bc9d4f16a..357df2df42 100644 --- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/preferences/DockerMachinePreferencePage.java +++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/preferences/DockerMachinePreferencePage.java @@ -15,6 +15,8 @@ import org.eclipse.jface.preference.FieldEditorPreferencePage; import org.eclipse.jface.preference.StringFieldEditor; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.linuxtools.docker.ui.Activator; +import org.eclipse.linuxtools.internal.docker.core.DockerMachine; +import org.eclipse.osgi.util.NLS; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; @@ -81,6 +83,22 @@ public class DockerMachinePreferencePage extends FieldEditorPreferencePage } /** + * Checks that the {@code docker-machine} command exists in the specified + * directory + */ + @Override + public boolean isValid() { + if (!DockerMachine.checkPathToDockerMachine( + this.dockerMachineInstallDir.getStringValue())) { + setErrorMessage(NLS.bind( + org.eclipse.linuxtools.internal.docker.core.Messages.Docker_Machine_Command_Not_Found, + this.dockerMachineInstallDir.getStringValue())); + return false; + } + return super.isValid(); + } + + /** * Subclass of the {@link DirectoryFieldEditor} but with the * {@link StringFieldEditor#VALIDATE_ON_KEY_STROKE} validation strategy. */ diff --git a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/NewDockerConnectionPage.java b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/NewDockerConnectionPage.java index 1b78e8675c..2e5224ce25 100644 --- a/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/NewDockerConnectionPage.java +++ b/containers/org.eclipse.linuxtools.docker.ui/src/org/eclipse/linuxtools/internal/docker/ui/wizards/NewDockerConnectionPage.java @@ -664,8 +664,9 @@ public class NewDockerConnectionPage extends WizardPage { @Override public void widgetSelected(SelectionEvent e) { - if (getDockerMachineInstallDir().equals("") - || getVMDriverInstallDir().equals("")) { + if (!DockerMachine + .checkPathToDockerMachine(getDockerMachineInstallDir()) + || getVMDriverInstallDir().equals("")) { //$NON-NLS-1$ final boolean confirm = MessageDialog.openConfirm( getShell(), WizardMessages.getString( @@ -679,8 +680,8 @@ public class NewDockerConnectionPage extends WizardPage { DOCKER_MACHINE_PREFERENCE_PAGE_ID }, null).open(); // after user input data, check again - if (getDockerMachineInstallDir().equals("") - || getVMDriverInstallDir().equals("")) { + if (getDockerMachineInstallDir().equals("") //$NON-NLS-1$ + || getVMDriverInstallDir().equals("")) { //$NON-NLS-1$ return; } } else { |