Permalink
Browse files

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 26, 2017
1 parent 15e874d commit 95d5e6c1f3a79fb07464f4072cd5d12f518df246
@@ -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);
}
@@ -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);
@@ -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`).

0 comments on commit 95d5e6c

Please sign in to comment.