incubator-ivy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xav...@apache.org
Subject svn commit: r493450 - in /incubator/ivy/trunk: CHANGES.txt doc/doc/use/buildlist.html src/java/fr/jayasoft/ivy/ant/IvyBuildList.java test/buildlist/E/ test/buildlist/E/build.xml test/buildlist/E/ivy.xml test/java/fr/jayasoft/ivy/ant/IvyBuildListTest.java
Date Sat, 06 Jan 2007 11:49:08 GMT
Author: xavier
Date: Sat Jan  6 03:49:07 2007
New Revision: 493450

URL: http://svn.apache.org/viewvc?view=rev&rev=493450
Log:
IMPROVE: Ability to have multiple roots in the <ivy:buildfilelist> task (IVY-340) (thanks
to Matt Inger)

Added:
    incubator/ivy/trunk/test/buildlist/E/
    incubator/ivy/trunk/test/buildlist/E/build.xml
    incubator/ivy/trunk/test/buildlist/E/ivy.xml
Modified:
    incubator/ivy/trunk/CHANGES.txt
    incubator/ivy/trunk/doc/doc/use/buildlist.html
    incubator/ivy/trunk/src/java/fr/jayasoft/ivy/ant/IvyBuildList.java
    incubator/ivy/trunk/test/java/fr/jayasoft/ivy/ant/IvyBuildListTest.java

Modified: incubator/ivy/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ivy/trunk/CHANGES.txt?view=diff&rev=493450&r1=493449&r2=493450
==============================================================================
--- incubator/ivy/trunk/CHANGES.txt (original)
+++ incubator/ivy/trunk/CHANGES.txt Sat Jan  6 03:49:07 2007
@@ -9,6 +9,7 @@
 =====================================
 - IMPROVE: Please typedef CacheResolver as "cache" for us (IVY-359)
 - IMPROVE: ivy:retrieve should be able to create symlinks (IVY-353) (thanks to John Williams)
+- IMPROVE: Ability to have multiple roots in the <ivy:buildfilelist> task (IVY-340)
(thanks to Matt Inger)
 
 - FIX: IOException during publish causes NullPointerException (IVY-371)
 - FIX: Comments in ivy.xml duplicated (IVY-336) (thanks to Gilles Scokart)

Modified: incubator/ivy/trunk/doc/doc/use/buildlist.html
URL: http://svn.apache.org/viewvc/incubator/ivy/trunk/doc/doc/use/buildlist.html?view=diff&rev=493450&r1=493449&r2=493450
==============================================================================
--- incubator/ivy/trunk/doc/doc/use/buildlist.html (original)
+++ incubator/ivy/trunk/doc/doc/use/buildlist.html Sat Jan  6 03:49:07 2007
@@ -15,6 +15,8 @@
 <span class="since">since 1.4.1</span> A leaf attribute can also be used to include,
among all the modules found, only the one that have dependencies (either direct or transitive)
on a leaf module. This can also be used with the excludeleaf attribute, which when set to
true will exclude the leaf itself from the list.
 
 <span class="since">since 1.4</span> The ivy.sorted.modules property is set in
the ant at the end of the task with a comma separated list of ordered modules. This can be
useful for debug or information purpose.
+
+<span class="since">since 1.5</span> The root and leaf attributes can be a delimited
list of modules to use as roots.  These modules, and all their dependencies will be included
in the build list.
 <table class="ant">
 <thead>
     <tr><th class="ant-att">Attribute</th><th class="ant-desc">Description</th><th
class="ant-req">Required</th></tr>
@@ -23,9 +25,10 @@
     <tr><td>reference</td><td>the reference of the path to set</td>
         <td>Yes</td></tr>
     <tr><td>ivyfilepath</td><td>the relative path from files to order
to corresponding ivy files</td><td>No. Defaults to ${ivy.buildlist.ivyfilepath}</td></tr>
-    <tr><td>root</td><td><span class="since">since 1.3</span>
the name of the module which should be considered as the root of the buildlist</td><td>No.
Defaults to no root (all modules are used in the build list)</td></tr>
+    <tr><td>root</td><td><span class="since">since 1.5</span>
the names of the modules which should be considered as the root of the buildlist. <br/><span
class="since">since 1.3</span> Was limited to only one module name before 1.5.</td><td>No.
Defaults to no root (all modules are used in the build list)</td></tr>
     <tr><td>excluderoot</td><td><span class="since">since 1.3</span>
true if the root defined should be excluded from the list</td><td>No. Defaults
to false</td></tr>
-    <tr><td>leaf</td><td><span class="since">since 1.4.1</span>
the name of the module which should be considered as the leaf of the buildlist</td><td>No.
Defaults to no leaf (all modules are used in the build list)</td></tr>
+    <tr><td>leaf</td><td><span class="since">since 1.5</span>
the names of the modules which should be considered as the leaf of the buildlist. <br/><span
class="since">since 1.4.1</span> Was limited to only one module name before 1.5.</td><td>No.
Defaults to no leaf (all modules are used in the build list)</td></tr>
+    <tr><td>delimiter</td><td><span class="since">since 1.5</span>
delimiter to use when specifying multiple module names in the root and leaf properties.</td><td>No.
Defaults to the comma (,) character.</td></tr>
     <tr><td>excludeleaf</td><td><span class="since">since 1.4.1</span>
true if the leaf defined should be excluded from the list</td><td>No. Defaults
to false</td></tr>
     <tr><td>haltonerror</td><td>true to halt the build when an invalid
ivy file is encountered, false to continue</td><td>No. Defaults to true</td></tr>
     <tr><td>skipbuildwithoutivy</td><td>true to skip files of the
fileset with no corresponding ivy file, false otherwise. If false the file with no corresponding
ivy file will be considered as independent of the other and put at the beginning of the built
filelist.</td><td>No. Defaults to false</td></tr>

Modified: incubator/ivy/trunk/src/java/fr/jayasoft/ivy/ant/IvyBuildList.java
URL: http://svn.apache.org/viewvc/incubator/ivy/trunk/src/java/fr/jayasoft/ivy/ant/IvyBuildList.java?view=diff&rev=493450&r1=493449&r2=493450
==============================================================================
--- incubator/ivy/trunk/src/java/fr/jayasoft/ivy/ant/IvyBuildList.java (original)
+++ incubator/ivy/trunk/src/java/fr/jayasoft/ivy/ant/IvyBuildList.java Sat Jan  6 03:49:07
2007
@@ -17,6 +17,7 @@
 import java.util.ListIterator;
 import java.util.Map;
 import java.util.Set;
+import java.util.StringTokenizer;
 
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.DirectoryScanner;
@@ -46,6 +47,7 @@
     private String _root = "*";
     private boolean _excludeRoot = false;
     private String _leaf = "*";
+    private String _delimiter = ",";
     private boolean _excludeLeaf = false;
 
 
@@ -93,6 +95,14 @@
 		_excludeLeaf = excludeLeaf;
 	}
 
+	public String getDelimiter() {
+		return _delimiter;
+	}
+	
+	public void setDelimiter(String delimiter) {
+		_delimiter = delimiter;
+	}
+	
     public void execute() throws BuildException {
         if (_reference == null) {
             throw new BuildException("reference should be provided in ivy build list");
@@ -109,9 +119,27 @@
         Map buildFiles = new HashMap(); // Map (ModuleDescriptor -> File buildFile)
         Collection mds = new ArrayList();
         List independent = new ArrayList();
-        ModuleDescriptor rootModuleDescriptor = null;
-        ModuleDescriptor leafModuleDescriptor = null;
 
+        Set rootModuleNames = new HashSet();
+        if (!"*".equals(_root)) {
+        	StringTokenizer st = new StringTokenizer(_root, _delimiter);
+        	while (st.hasMoreTokens()) {
+        		rootModuleNames.add(st.nextToken());
+        	}
+        }
+        
+        Set leafModuleNames = new HashSet();
+        if (! "*".equals(_leaf)) {
+        	StringTokenizer st = new StringTokenizer(_leaf, _delimiter);
+        	while (st.hasMoreTokens()) {
+        		leafModuleNames.add(st.nextToken());
+        	}
+        }
+        
+        List leafModuleDescriptors = new ArrayList();
+        List rootModuleDescriptors = new ArrayList();
+
+        
         for (ListIterator iter = _buildFiles.listIterator(); iter.hasNext();) {
             FileSet fs = (FileSet)iter.next();
             DirectoryScanner ds = fs.getDirectoryScanner(getProject());
@@ -132,11 +160,13 @@
                         ModuleDescriptor md = ModuleDescriptorParserRegistry.getInstance().parseDescriptor(ivy,
ivyFile.toURL(), doValidate(ivy));
                         buildFiles.put(md, buildFile);
                         mds.add(md);
-                        if (_root.equals(md.getModuleRevisionId().getName())) {
-                            rootModuleDescriptor = md;
+
+                        if (rootModuleNames.contains(md.getModuleRevisionId().getModuleId().getName()))
{
+                        	rootModuleDescriptors.add(md);
                         }
-                        if (_leaf.equals(md.getModuleRevisionId().getName())) {
-                            leafModuleDescriptor = md;
+
+                        if (leafModuleNames.contains(md.getModuleRevisionId().getModuleId().getName()))
{
+                        	leafModuleDescriptors.add(md);
                         }
 
                     } catch (Exception ex) {
@@ -151,21 +181,22 @@
                 }
             }
         }
-
-        if (!"*".equals(_root) && rootModuleDescriptor == null) {
-            throw new BuildException("unable to find root module " + _root + " in build fileset");
-        }
-        if (!"*".equals(_leaf) && leafModuleDescriptor == null) {
-            throw new BuildException("unable to find leaf module " + _leaf + " in build fileset");
-        }
-
-        if (rootModuleDescriptor != null) {
-            Message.info("Filtering modules based on root " + rootModuleDescriptor.getModuleRevisionId().getName());
-            mds = filterModulesFromRoot(mds, rootModuleDescriptor);
-        }
-        if (leafModuleDescriptor != null) {
-            Message.info("Filtering modules based on leaf " + leafModuleDescriptor.getModuleRevisionId().getName());
-            mds = filterModulesFromLeaf(mds, leafModuleDescriptor);
+        
+        if (!"*".equals(_root) && rootModuleDescriptors.size() != rootModuleNames.size())
{
+            throw new BuildException("unable to find one or more root modules " +  rootModuleNames
+ " in build fileset");
+        }
+        
+        if (!"*".equals(_leaf) && leafModuleDescriptors.size() != leafModuleNames.size())
{
+            throw new BuildException("unable to find one or more leaf modules " + leafModuleNames
+ " in build fileset");
+        }
+
+        if (! rootModuleDescriptors.isEmpty()) {
+            Message.info("Filtering modules based on roots " + rootModuleNames);
+            mds = filterModulesFromRoot(mds, rootModuleDescriptors);
+        }
+        if (! leafModuleDescriptors.isEmpty()) {
+            Message.info("Filtering modules based on leafs " + leafModuleNames);
+            mds = filterModulesFromLeaf(mds, leafModuleDescriptors);
         }
 
         List sortedModules = ivy.sortModuleDescriptors(mds);
@@ -200,7 +231,7 @@
      * @param rootmd root module
      * @return filtered list of modules
      */
-    private Collection filterModulesFromRoot(Collection mds, ModuleDescriptor rootmd) {
+    private Collection filterModulesFromRoot(Collection mds, List rootmds) {
         // Make a map of ModuleId objects -> ModuleDescriptors
         Map moduleIdMap = new HashMap();
         for (Iterator iter = mds.iterator(); iter.hasNext();) {
@@ -210,13 +241,18 @@
 
         // recursively process the nodes
         Set toKeep = new HashSet();
-        processFilterNodeFromRoot(rootmd, toKeep, moduleIdMap);
-
-        // With the excluderoot attribute set to true, take the rootmd out of the toKeep
set.
-        if (_excludeRoot) {
-            Message.verbose("Excluded module " + rootmd.getModuleRevisionId().getModuleId().getName());
-            toKeep.remove(rootmd);
+        
+        Iterator it = rootmds.iterator();
+        while (it.hasNext()) {
+        	ModuleDescriptor rootmd = (ModuleDescriptor) it.next();
+            processFilterNodeFromRoot(rootmd, toKeep, moduleIdMap);
+            // With the excluderoot attribute set to true, take the rootmd out of the toKeep
set.
+            if (_excludeRoot) {
+                Message.verbose("Excluded module " + rootmd.getModuleRevisionId().getModuleId().getName());
+                toKeep.remove(rootmd);
+            }
         }
+        
 
         // just for logging
         for (Iterator iter = toKeep.iterator(); iter.hasNext();) {
@@ -255,7 +291,7 @@
      * @param leafmd leaf module
      * @return filtered list of modules
      */
-    private Collection filterModulesFromLeaf(Collection mds, ModuleDescriptor leafmd) {
+    private Collection filterModulesFromLeaf(Collection mds, List leafmds) {
         // Make a map of ModuleId objects -> ModuleDescriptors
         Map moduleIdMap = new HashMap();
         for (Iterator iter = mds.iterator(); iter.hasNext();) {
@@ -265,13 +301,17 @@
 
         // recursively process the nodes
         Set toKeep = new HashSet();
-        // With the excludeleaf attribute set to true, take the rootmd out of the toKeep
set.
-        if (_excludeLeaf) {
-        	Message.verbose("Excluded module " + leafmd.getModuleRevisionId().getModuleId().getName());
-        } else {
-        	toKeep.add(leafmd);
+        Iterator it = leafmds.iterator();
+        while (it.hasNext()) {
+        	ModuleDescriptor leafmd = (ModuleDescriptor) it.next();
+            // With the excludeleaf attribute set to true, take the rootmd out of the toKeep
set.
+            if (_excludeLeaf) {
+            	Message.verbose("Excluded module " + leafmd.getModuleRevisionId().getModuleId().getName());
+            } else {
+            	toKeep.add(leafmd);
+            }
+            processFilterNodeFromLeaf(leafmd, toKeep, moduleIdMap);
         }
-        processFilterNodeFromLeaf(leafmd, toKeep, moduleIdMap);
 
 
         // just for logging

Added: incubator/ivy/trunk/test/buildlist/E/build.xml
URL: http://svn.apache.org/viewvc/incubator/ivy/trunk/test/buildlist/E/build.xml?view=auto&rev=493450
==============================================================================
    (empty)

Added: incubator/ivy/trunk/test/buildlist/E/ivy.xml
URL: http://svn.apache.org/viewvc/incubator/ivy/trunk/test/buildlist/E/ivy.xml?view=auto&rev=493450
==============================================================================
--- incubator/ivy/trunk/test/buildlist/E/ivy.xml (added)
+++ incubator/ivy/trunk/test/buildlist/E/ivy.xml Sat Jan  6 03:49:07 2007
@@ -0,0 +1,3 @@
+<ivy-module version="1.2">
+	<info organisation="jayasoft" module="E"/>
+</ivy-module>

Modified: incubator/ivy/trunk/test/java/fr/jayasoft/ivy/ant/IvyBuildListTest.java
URL: http://svn.apache.org/viewvc/incubator/ivy/trunk/test/java/fr/jayasoft/ivy/ant/IvyBuildListTest.java?view=diff&rev=493450&r1=493449&r2=493450
==============================================================================
--- incubator/ivy/trunk/test/java/fr/jayasoft/ivy/ant/IvyBuildListTest.java (original)
+++ incubator/ivy/trunk/test/java/fr/jayasoft/ivy/ant/IvyBuildListTest.java Sat Jan  6 03:49:07
2007
@@ -37,12 +37,13 @@
         Path path = (Path)o;
         String[] files = path.list();
         assertNotNull(files);
-        assertEquals(4, files.length);
+        assertEquals(5, files.length);
         
         assertEquals(new File("test/buildlist/B/build.xml").getAbsolutePath(), new File(files[0]).getAbsolutePath());
         assertEquals(new File("test/buildlist/C/build.xml").getAbsolutePath(), new File(files[1]).getAbsolutePath());
         assertEquals(new File("test/buildlist/A/build.xml").getAbsolutePath(), new File(files[2]).getAbsolutePath());
         assertEquals(new File("test/buildlist/D/build.xml").getAbsolutePath(), new File(files[3]).getAbsolutePath());
+        assertEquals(new File("test/buildlist/E/build.xml").getAbsolutePath(), new File(files[4]).getAbsolutePath());
     }
 
     public void testReverse() {
@@ -68,12 +69,13 @@
         Path path = (Path)o;
         String[] files = path.list();
         assertNotNull(files);
-        assertEquals(4, files.length);
+        assertEquals(5, files.length);
         
-        assertEquals(new File("test/buildlist/D/build.xml").getAbsolutePath(), new File(files[0]).getAbsolutePath());
-        assertEquals(new File("test/buildlist/A/build.xml").getAbsolutePath(), new File(files[1]).getAbsolutePath());
-        assertEquals(new File("test/buildlist/C/build.xml").getAbsolutePath(), new File(files[2]).getAbsolutePath());
-        assertEquals(new File("test/buildlist/B/build.xml").getAbsolutePath(), new File(files[3]).getAbsolutePath());
+        assertEquals(new File("test/buildlist/E/build.xml").getAbsolutePath(), new File(files[0]).getAbsolutePath());
+        assertEquals(new File("test/buildlist/D/build.xml").getAbsolutePath(), new File(files[1]).getAbsolutePath());
+        assertEquals(new File("test/buildlist/A/build.xml").getAbsolutePath(), new File(files[2]).getAbsolutePath());
+        assertEquals(new File("test/buildlist/C/build.xml").getAbsolutePath(), new File(files[3]).getAbsolutePath());
+        assertEquals(new File("test/buildlist/B/build.xml").getAbsolutePath(), new File(files[4]).getAbsolutePath());
     }
 
     public void testWithRoot() {
@@ -105,6 +107,36 @@
         assertEquals(new File("test/buildlist/C/build.xml").getAbsolutePath(), new File(files[1]).getAbsolutePath());
     }
 
+    public void testWithTwoRoots() {
+        Project p = new Project();
+
+        IvyBuildList buildlist = new IvyBuildList();
+        buildlist.setProject(p);
+        buildlist.setRoot("C,E");
+
+        FileSet fs = new FileSet();
+        fs.setDir(new File("test/buildlist"));
+        fs.setIncludes("**/build.xml");
+        buildlist.addFileset(fs);
+
+        buildlist.setReference("ordered.build.files");
+
+        buildlist.execute();
+
+        Object o = p.getReference("ordered.build.files");
+        assertNotNull(o);
+        assertTrue(o instanceof Path);
+
+        Path path = (Path)o;
+        String[] files = path.list();
+        assertNotNull(files);
+        assertEquals(3, files.length); // A and D should be filtered out
+
+        assertEquals(new File("test/buildlist/B/build.xml").getAbsolutePath(), new File(files[0]).getAbsolutePath());
+        assertEquals(new File("test/buildlist/C/build.xml").getAbsolutePath(), new File(files[1]).getAbsolutePath());
+        assertEquals(new File("test/buildlist/E/build.xml").getAbsolutePath(), new File(files[2]).getAbsolutePath());
+    }
+
     public void testWithRootExclude() {
         Project p = new Project();
 
@@ -162,6 +194,37 @@
         assertEquals(new File("test/buildlist/C/build.xml").getAbsolutePath(), new File(files[0]).getAbsolutePath());
         assertEquals(new File("test/buildlist/A/build.xml").getAbsolutePath(), new File(files[1]).getAbsolutePath());
         assertEquals(new File("test/buildlist/D/build.xml").getAbsolutePath(), new File(files[2]).getAbsolutePath());
+    }
+
+    public void testWithTwoLeafs() {
+        Project p = new Project();
+
+        IvyBuildList buildlist = new IvyBuildList();
+        buildlist.setProject(p);
+        buildlist.setLeaf("C,E");
+
+        FileSet fs = new FileSet();
+        fs.setDir(new File("test/buildlist"));
+        fs.setIncludes("**/build.xml");
+        buildlist.addFileset(fs);
+
+        buildlist.setReference("ordered.build.files");
+
+        buildlist.execute();
+
+        Object o = p.getReference("ordered.build.files");
+        assertNotNull(o);
+        assertTrue(o instanceof Path);
+
+        Path path = (Path)o;
+        String[] files = path.list();
+        assertNotNull(files);
+        assertEquals(4, files.length); // B should be filtered out
+
+        assertEquals(new File("test/buildlist/C/build.xml").getAbsolutePath(), new File(files[0]).getAbsolutePath());
+        assertEquals(new File("test/buildlist/A/build.xml").getAbsolutePath(), new File(files[1]).getAbsolutePath());
+        assertEquals(new File("test/buildlist/D/build.xml").getAbsolutePath(), new File(files[2]).getAbsolutePath());
+        assertEquals(new File("test/buildlist/E/build.xml").getAbsolutePath(), new File(files[3]).getAbsolutePath());
     }
 
     public void testWithLeafExclude() {



Mime
View raw message