From 6b1334d021ae2003e3505e10078497b599815062 Mon Sep 17 00:00:00 2001 From: fcamblor Date: Sat, 9 Sep 2017 22:39:22 +0200 Subject: [PATCH] shell - trying to fallback to ivy dependency resolution from pom.xml if we detect mvn is not installed on current machine --- .../restx/core/shell/DepsShellCommand.java | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/restx-core-shell/src/main/java/restx/core/shell/DepsShellCommand.java b/restx-core-shell/src/main/java/restx/core/shell/DepsShellCommand.java index 226738063..ead0d44c2 100644 --- a/restx-core-shell/src/main/java/restx/core/shell/DepsShellCommand.java +++ b/restx-core-shell/src/main/java/restx/core/shell/DepsShellCommand.java @@ -37,6 +37,8 @@ */ @Component public class DepsShellCommand extends StdShellCommand { + private static final String MVN_COMMAND = "mvn"; + public DepsShellCommand() { super(ImmutableList.of("deps"), "deps related commands: install / update / manage app dependencies"); } @@ -154,16 +156,25 @@ public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOEx // Then copying dependencies through copy-dependencies plugin ProcessBuilder mavenCmd = new ProcessBuilder( - "mvn", "org.apache.maven.plugins:maven-dependency-plugin:3.0.1:copy-dependencies", + MVN_COMMAND, "org.apache.maven.plugins:maven-dependency-plugin:3.0.1:copy-dependencies", "-DoutputDirectory=" + dependenciesDir.toAbsolutePath(), "-DincludeScope=runtime" ); shell.println("Executing `"+mavenCmd+"` ..."); - mavenCmd.redirectErrorStream(true) - .redirectOutput(ProcessBuilder.Redirect.INHERIT) - .directory(shell.currentLocation().toFile().getAbsoluteFile()) - .start() - .waitFor(); + try { + mavenCmd.redirectErrorStream(true) + .redirectOutput(ProcessBuilder.Redirect.INHERIT) + .directory(shell.currentLocation().toFile().getAbsoluteFile()) + .start() + .waitFor(); + } catch(IOException e) { + if(e.getMessage().startsWith(String.format("Cannot run program \"%s\"", MVN_COMMAND))) { + shell.println("Looks like mvn is not installed here ... trying to fallback installing pom.xml file with Ivy..."); + installDepsFromIvyDescriptor(shell, pomFile); + } else { + Throwables.propagate(e); + } + } } private static void storeModuleDescriptorMD5File(RestxShell shell, ModuleDescriptorType mdType) throws IOException {