Skip to content

Commit 95d5e6c

Browse files
committed
shell - allowing to install deps from module.ivy only file (when both md.restx.json and pom.xml are missing)
1 parent 15e874d commit 95d5e6c

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

Diff for: restx-core-shell/src/main/java/restx/core/shell/DepsShellCommand.java

+19-11
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ public void run(RestxShell shell) throws Exception {
8888
} else if(ModuleDescriptorType.MAVEN.equals(moduleDescriptorTypeWithExistingFile)) {
8989
shell.println("installing deps using maven descriptor...");
9090
installDepsFromMavenDescriptor(shell, ModuleDescriptorType.MAVEN.resolveDescriptorFile(shell.currentLocation()));
91+
} else if(ModuleDescriptorType.IVY.equals(moduleDescriptorTypeWithExistingFile)) {
92+
shell.println("installing deps using ivy descriptor...");
93+
installDepsFromIvyDescriptor(shell, ModuleDescriptorType.IVY.resolveDescriptorFile(shell.currentLocation()));
9194
} else {
9295
throw new IllegalArgumentException("Unsupported deps install for module type "+moduleDescriptorTypeWithExistingFile);
9396
}
@@ -98,29 +101,34 @@ public void run(RestxShell shell) throws Exception {
98101
}
99102

100103
private void installDepsFromModuleDescriptor(RestxShell shell, File mdFile) throws Exception {
101-
Ivy ivy = ShellIvy.loadIvy(shell);
102104
File tempFile = File.createTempFile("restx-md", ".ivy");
103105
try (FileInputStream is = new FileInputStream(mdFile)) {
104106
ModuleDescriptor descriptor = new RestxJsonSupport().parse(is);
105107
try (BufferedWriter w = Files.newWriter(tempFile,Charsets.UTF_8)) {
106108
new IvySupport().generate(descriptor, w);
107109
}
108110

109-
shell.println("resolving dependencies...");
110-
ResolveReport resolveReport = ivy.resolve(tempFile);
111-
112-
shell.println("synchronizing dependencies in " + shell.currentLocation().resolve("target/dependency") + " ...");
113-
ivy.retrieve(resolveReport.getModuleDescriptor().getModuleRevisionId(),
114-
new RetrieveOptions()
115-
.setDestArtifactPattern(
116-
shell.currentLocation().toAbsolutePath() + "/target/dependency/[artifact]-[revision](-[classifier]).[ext]")
117-
.setSync(true)
118-
);
111+
installDepsFromIvyDescriptor(shell, tempFile);
119112
} finally {
120113
tempFile.delete();
121114
}
122115
}
123116

117+
private void installDepsFromIvyDescriptor(RestxShell shell, File ivyFile) throws Exception {
118+
Ivy ivy = ShellIvy.loadIvy(shell);
119+
120+
shell.println("resolving dependencies...");
121+
ResolveReport resolveReport = ivy.resolve(ivyFile);
122+
123+
shell.println("synchronizing dependencies in " + shell.currentLocation().resolve("target/dependency") + " ...");
124+
ivy.retrieve(resolveReport.getModuleDescriptor().getModuleRevisionId(),
125+
new RetrieveOptions()
126+
.setDestArtifactPattern(
127+
shell.currentLocation().toAbsolutePath() + "/target/dependency/[artifact]-[revision](-[classifier]).[ext]")
128+
.setSync(true)
129+
);
130+
}
131+
124132
private void installDepsFromMavenDescriptor(RestxShell shell, File pomFile) throws Exception {
125133
AppSettings appSettings = shell.getFactory().getComponent(AppSettings.class);
126134

Diff for: restx-core-shell/src/main/resources/restx/core/shell/deps.man

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
## deps install
22

3-
Resolve dependencies declared in current module descriptor (in order: either `md.restx.json` or `pom.xml`),
3+
Resolve dependencies declared in current module descriptor (in order: either `md.restx.json`, `pom.xml` or `module.ivy`),
44
and synchronize them in `target/dependency` directory.
55

6-
For `md.restx.json` `module.ivy`, this command uses Apache Ivy under the hood to perform dependency resolution,
6+
For both `md.restx.json` and `module.ivy`, this command uses Apache Ivy under the hood to perform dependency resolution,
77
using settings provided by restx. You can override these Ivy settings by placing a file named ivysettings.xml in your
88
restx shell install location (usually `~/.restx`).
99

0 commit comments

Comments
 (0)