From ecd6d97cc6608a4577a5a84056d3b63970b7d015 Mon Sep 17 00:00:00 2001 From: Xavier Hanin Date: Tue, 25 Oct 2005 18:13:06 +0000 Subject: [PATCH] NEW: ability to use a dependency instead of an ivy file in standalone mode (IVY-96) git-svn-id: https://svn.apache.org/repos/asf/incubator/ivy/trunk@484060 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 1 + src/java/fr/jayasoft/ivy/Main.java | 38 ++++++++++++++++--- .../ivy/xml/XmlModuleDescriptorWriter.java | 30 ++++++++++++++- 3 files changed, 62 insertions(+), 7 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 0a1e9649..3993ef10 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,4 @@ +- NEW: ability to use a dependency instead of an ivy file in standalone mode (IVY-96) - NEW: ability to output a path of dependencies in cache from the standalone mode (IVY-92) - NEW: it is now possible to reference existing resolver in resolver containers (IVY-35) - NEW: overwrite attribute in the publish task now let force overwrite of read only files (IVY-83) diff --git a/src/java/fr/jayasoft/ivy/Main.java b/src/java/fr/jayasoft/ivy/Main.java index cb7efd6e..3c20954f 100644 --- a/src/java/fr/jayasoft/ivy/Main.java +++ b/src/java/fr/jayasoft/ivy/Main.java @@ -29,6 +29,7 @@ import fr.jayasoft.ivy.url.URLHandlerDispatcher; import fr.jayasoft.ivy.url.URLHandlerRegistry; import fr.jayasoft.ivy.util.DefaultMessageImpl; import fr.jayasoft.ivy.util.Message; +import fr.jayasoft.ivy.xml.XmlModuleDescriptorWriter; import fr.jayasoft.ivy.xml.XmlReportParser; /** @@ -61,6 +62,10 @@ public class Main { .hasArg() .withDescription( "use given file as ivy file" ) .create( "ivy" ); + Option dependency = OptionBuilder.withArgName( "organisation module revision" ) + .hasArgs() + .withDescription( "use this instead of ivy file to do the rest of the work with this as a dependency." ) + .create( "dependency" ); Option confs = OptionBuilder.withArgName( "configurations" ) .hasArgs() .withDescription( "resolve given configurations" ) @@ -122,6 +127,7 @@ public class Main { options.addOption(confs); options.addOption(cache); options.addOption(ivyfile); + options.addOption(dependency); options.addOption(retrieve); options.addOption(cachepath); options.addOption(revision); @@ -191,12 +197,7 @@ public class Main { } else if (!cache.isDirectory()) { error(options, cache+" is not a directory"); } - File ivyfile = new File(ivy.substitute(line.getOptionValue("ivy", "ivy.xml"))); - if (!ivyfile.exists()) { - error(options, "ivy file not found: "+ivyfile); - } else if (ivyfile.isDirectory()) { - error(options, "ivy file is not a file: "+ivyfile); - } + String[] confs; if (line.hasOption("confs")) { confs = line.getOptionValues("confs"); @@ -204,6 +205,31 @@ public class Main { confs = new String[] {"*"}; } + File ivyfile; + if (line.hasOption("dependency")) { + String[] dep = line.getOptionValues("dependency"); + if (dep.length != 3) { + error(options, "dependency should be expressed with exactly 3 arguments: organisation module revision"); + } + ivyfile = File.createTempFile("ivy", ".xml"); + ivyfile.deleteOnExit(); + DefaultModuleDescriptor md = DefaultModuleDescriptor.newDefaultInstance(ModuleRevisionId.newInstance(dep[0], "standalone", "working")); + DefaultDependencyDescriptor dd = new DefaultDependencyDescriptor(md, ModuleRevisionId.newInstance(dep[0], dep[1], dep[2]), false, false, true); + for (int i = 0; i < confs.length; i++) { + dd.addDependencyConfiguration("default", confs[i]); + } + md.addDependency(dd); + XmlModuleDescriptorWriter.write(md, ivyfile); + confs = new String[] {"default"}; + } else { + ivyfile = new File(ivy.substitute(line.getOptionValue("ivy", "ivy.xml"))); + if (!ivyfile.exists()) { + error(options, "ivy file not found: "+ivyfile); + } else if (ivyfile.isDirectory()) { + error(options, "ivy file is not a file: "+ivyfile); + } + } + Date date = new Date(); ModuleDescriptor md = ivy.resolve( diff --git a/src/java/fr/jayasoft/ivy/xml/XmlModuleDescriptorWriter.java b/src/java/fr/jayasoft/ivy/xml/XmlModuleDescriptorWriter.java index 35d2b909..901ad359 100644 --- a/src/java/fr/jayasoft/ivy/xml/XmlModuleDescriptorWriter.java +++ b/src/java/fr/jayasoft/ivy/xml/XmlModuleDescriptorWriter.java @@ -10,6 +10,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintWriter; +import fr.jayasoft.ivy.DependencyDescriptor; import fr.jayasoft.ivy.Ivy; import fr.jayasoft.ivy.ModuleDescriptor; @@ -34,7 +35,34 @@ public class XmlModuleDescriptorWriter { out.println("\t\tresolver=\""+md.getResolverName()+"\""); out.println("\t\tdefault=\""+(md.isDefault()?"true":"false")+"\""); out.println("\t/>"); - out.println(""); + DependencyDescriptor[] dds = md.getDependencies(); + if (dds.length > 0) { + out.println("\t"); + for (int i = 0; i < dds.length; i++) { + out.print("\t\t"); + for (int k = 0; k < depConfs.length; k++) { + out.print(depConfs[k]); + if (k+1 < depConfs.length) { + out.print(","); + } + } + if (j+1 < modConfs.length) { + out.print(";"); + } + } + out.println("\"/>"); + } + out.println("\t"); + } + out.println(""); } finally { out.close(); }