Skip to content

Commit 6b1334d

Browse files
committed
shell - trying to fallback to ivy dependency resolution from pom.xml if we detect mvn is not installed on current machine
1 parent 85539e4 commit 6b1334d

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

restx-core-shell/src/main/java/restx/core/shell/DepsShellCommand.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
*/
3838
@Component
3939
public class DepsShellCommand extends StdShellCommand {
40+
private static final String MVN_COMMAND = "mvn";
41+
4042
public DepsShellCommand() {
4143
super(ImmutableList.of("deps"), "deps related commands: install / update / manage app dependencies");
4244
}
@@ -154,16 +156,25 @@ public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOEx
154156

155157
// Then copying dependencies through copy-dependencies plugin
156158
ProcessBuilder mavenCmd = new ProcessBuilder(
157-
"mvn", "org.apache.maven.plugins:maven-dependency-plugin:3.0.1:copy-dependencies",
159+
MVN_COMMAND, "org.apache.maven.plugins:maven-dependency-plugin:3.0.1:copy-dependencies",
158160
"-DoutputDirectory=" + dependenciesDir.toAbsolutePath(), "-DincludeScope=runtime"
159161
);
160162

161163
shell.println("Executing `"+mavenCmd+"` ...");
162-
mavenCmd.redirectErrorStream(true)
163-
.redirectOutput(ProcessBuilder.Redirect.INHERIT)
164-
.directory(shell.currentLocation().toFile().getAbsoluteFile())
165-
.start()
166-
.waitFor();
164+
try {
165+
mavenCmd.redirectErrorStream(true)
166+
.redirectOutput(ProcessBuilder.Redirect.INHERIT)
167+
.directory(shell.currentLocation().toFile().getAbsoluteFile())
168+
.start()
169+
.waitFor();
170+
} catch(IOException e) {
171+
if(e.getMessage().startsWith(String.format("Cannot run program \"%s\"", MVN_COMMAND))) {
172+
shell.println("Looks like mvn is not installed here ... trying to fallback installing pom.xml file with Ivy...");
173+
installDepsFromIvyDescriptor(shell, pomFile);
174+
} else {
175+
Throwables.propagate(e);
176+
}
177+
}
167178
}
168179

169180
private static void storeModuleDescriptorMD5File(RestxShell shell, ModuleDescriptorType mdType) throws IOException {

0 commit comments

Comments
 (0)