Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
shell - allowing to install deps from module.ivy only file (when both…
… md.restx.json and pom.xml are missing)
  • Loading branch information
fcamblor committed Aug 27, 2017
1 parent 15e874d commit 95d5e6c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
Expand Up @@ -88,6 +88,9 @@ public void run(RestxShell shell) throws Exception {
} else if(ModuleDescriptorType.MAVEN.equals(moduleDescriptorTypeWithExistingFile)) {
shell.println("installing deps using maven descriptor...");
installDepsFromMavenDescriptor(shell, ModuleDescriptorType.MAVEN.resolveDescriptorFile(shell.currentLocation()));
} else if(ModuleDescriptorType.IVY.equals(moduleDescriptorTypeWithExistingFile)) {
shell.println("installing deps using ivy descriptor...");
installDepsFromIvyDescriptor(shell, ModuleDescriptorType.IVY.resolveDescriptorFile(shell.currentLocation()));
} else {
throw new IllegalArgumentException("Unsupported deps install for module type "+moduleDescriptorTypeWithExistingFile);
}
Expand All @@ -98,29 +101,34 @@ public void run(RestxShell shell) throws Exception {
}

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

shell.println("resolving dependencies...");
ResolveReport resolveReport = ivy.resolve(tempFile);

shell.println("synchronizing dependencies in " + shell.currentLocation().resolve("target/dependency") + " ...");
ivy.retrieve(resolveReport.getModuleDescriptor().getModuleRevisionId(),
new RetrieveOptions()
.setDestArtifactPattern(
shell.currentLocation().toAbsolutePath() + "/target/dependency/[artifact]-[revision](-[classifier]).[ext]")
.setSync(true)
);
installDepsFromIvyDescriptor(shell, tempFile);
} finally {
tempFile.delete();
}
}

private void installDepsFromIvyDescriptor(RestxShell shell, File ivyFile) throws Exception {
Ivy ivy = ShellIvy.loadIvy(shell);

shell.println("resolving dependencies...");
ResolveReport resolveReport = ivy.resolve(ivyFile);

shell.println("synchronizing dependencies in " + shell.currentLocation().resolve("target/dependency") + " ...");
ivy.retrieve(resolveReport.getModuleDescriptor().getModuleRevisionId(),
new RetrieveOptions()
.setDestArtifactPattern(
shell.currentLocation().toAbsolutePath() + "/target/dependency/[artifact]-[revision](-[classifier]).[ext]")
.setSync(true)
);
}

private void installDepsFromMavenDescriptor(RestxShell shell, File pomFile) throws Exception {
AppSettings appSettings = shell.getFactory().getComponent(AppSettings.class);

Expand Down
4 changes: 2 additions & 2 deletions restx-core-shell/src/main/resources/restx/core/shell/deps.man
@@ -1,9 +1,9 @@
## deps install

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

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

Expand Down

0 comments on commit 95d5e6c

Please sign in to comment.