Author: gscokart
Date: Thu Jun 21 13:35:18 2007
New Revision: 549603

URL: http://svn.apache.org/viewvc?view=rev&rev=549603
Log:
IMPROVEMENT: Buildlist onlydirectdep attribute (IVY-473 and IVY-504) (with 
contribution from Mikkel Bjerg )

Modified:
    incubator/ivy/core/trunk/CHANGES.txt
    incubator/ivy/core/trunk/doc/doc/use/buildlist.html
    incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyBuildList.java
    incubator/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyBuildListTest.java

Modified: incubator/ivy/core/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/incubator/ivy/core/trunk/CHANGES.txt?view=diff&rev=549603&r1=549602&r2=549603
==============================================================================
--- incubator/ivy/core/trunk/CHANGES.txt (original)
+++ incubator/ivy/core/trunk/CHANGES.txt Thu Jun 21 13:35:18 2007
@@ -14,6 +14,7 @@
        Ingo Adler
        Stephane Bailliez
        Karl Baum
+       Mikkel Bjerg
        Jeffrey Blattman
        Matthieu Brouillard
        Kristian Cibulskis
@@ -56,6 +57,7 @@
 - IMPROVEMENT: Allow "main" parameters to be passed directly (instead of using 
-args flag) (IVY-480) (thanks to Archie Cobbs)
 - IMPROVEMENT: Remove @author tags (thanks to Stephane Bailliez)
 - IMPROVEMENT: Remove use of deprecated elements in ivysettings.xml (IVY-505) 
(with contribution from Jan Materne)
+- IMPROVEMENT: Buildlist onlydirectdep attribute (IVY-473 and IVY-504) (with 
contribution from Mikkel Bjerg )
 
 - FIX: Evicted modules report depends on the order of the dependencies 
(IVY-526)
 - FIX: Ivy does not work on Turkish machines (IVY-65)

Modified: incubator/ivy/core/trunk/doc/doc/use/buildlist.html
URL: 
http://svn.apache.org/viewvc/incubator/ivy/core/trunk/doc/doc/use/buildlist.html?view=diff&rev=549603&r1=549602&r2=549603
==============================================================================
--- incubator/ivy/core/trunk/doc/doc/use/buildlist.html (original)
+++ incubator/ivy/core/trunk/doc/doc/use/buildlist.html Thu Jun 21 13:35:18 2007
@@ -43,6 +43,8 @@
 <span class="since">since 2.0</span> By default, all the modules included in a 
circular dependency are grouped together so that any dependency of any module 
in the loop will apear before the modules in the loop.  This garantee that if 
there is a depedendency path between a module A and a module B (but no 
dependency path from B to A), B will alway apear before A even if A is included 
in a loop in the provided set of modules to sort.
 Note that circular dependency can also trigger a failure depending on the 
value configured in the circularDependencyStrategy of your <a 
href="../configuration/conf.html#circularDependencyStrategy">settings</a>
 
+<span class="since">since 2.0</span> When you are specifying root or leaf 
modules you can limit the resulting list to only direct dependencies of the 
roots modules or to modules that directly depends on your leaf modules.
+
 
 <table class="ant">
 <thead>
@@ -55,6 +57,10 @@
     <tr><td>root</td><td><span class="since">since 2.0</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 
2.0.</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 2.0</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 
2.0.</td><td>No. Defaults to no leaf (all modules are used in the build 
list)</td></tr>
+  <tr><td>onlydirectdep</td><td><span class="since">since 2.0</span> true if 
the
+resulting list should be restricted to direct dependencies of root modules or 
modules that directly depends on the leaf modules.<br/>
+This field is ignored when neither root neither leaf is filled.
+     </td><td>No. Defaults to no false</td></tr>
     <tr><td>delimiter</td><td><span class="since">since 2.0</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>

Modified: incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyBuildList.java
URL: 
http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyBuildList.java?view=diff&rev=549603&r1=549602&r2=549603
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyBuildList.java 
(original)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyBuildList.java Thu 
Jun 21 13:35:18 2007
@@ -72,6 +72,8 @@
 
     private boolean excludeLeaf = false;
 
+    private boolean onlydirectdep = false;
+    
     public void addFileset(FileSet buildFiles) {
         buildFileSets.add(buildFiles);
     }
@@ -124,6 +126,15 @@
         this.delimiter = delimiter;
     }
 
+    public boolean getOnlydirectdep() {
+        return onlydirectdep;
+    }
+
+    public void setOnlydirectdep(boolean onlydirectdep) {
+        this.onlydirectdep = onlydirectdep;
+    }
+
+    
     public void doExecute() throws BuildException {
         if (reference == null) {
             throw new BuildException("reference should be provided in ivy 
build list");
@@ -282,9 +293,11 @@
             processFilterNodeFromRoot(rootmd, toKeep, moduleIdMap);
             // With the excluderoot attribute set to true, take the rootmd out 
of the toKeep set.
             if (excludeRoot) {
+                // Only for logging purposes
                 Message.verbose("Excluded module "
                         + 
rootmd.getModuleRevisionId().getModuleId().getName());
-                toKeep.remove(rootmd);
+            } else {
+                toKeep.add(rootmd);
             }
         }
 
@@ -310,14 +323,17 @@
      *            reference mapping of moduleId to ModuleDescriptor that are 
part of the BuildList
      */
     private void processFilterNodeFromRoot(ModuleDescriptor node, Set toKeep, 
Map moduleIdMap) {
-        toKeep.add(node);
+        //toKeep.add(node);
 
         DependencyDescriptor[] deps = node.getDependencies();
         for (int i = 0; i < deps.length; i++) {
             ModuleId id = deps[i].getDependencyId();
             if (moduleIdMap.get(id) != null) {
-                processFilterNodeFromRoot((ModuleDescriptor) 
moduleIdMap.get(id), toKeep,
-                    moduleIdMap);
+                toKeep.add(moduleIdMap.get(id));
+                if (!getOnlydirectdep()) {
+                    processFilterNodeFromRoot((ModuleDescriptor) 
moduleIdMap.get(id), toKeep,
+                        moduleIdMap);
+                }
             }
         }
     }
@@ -383,7 +399,9 @@
                 ModuleId id = deps[i].getDependencyId();
                 if (node.getModuleRevisionId().getModuleId().equals(id) && 
!toKeep.contains(md)) {
                     toKeep.add(md);
-                    processFilterNodeFromLeaf(md, toKeep, moduleIdMap);
+                    if (!getOnlydirectdep()) {
+                        processFilterNodeFromLeaf(md, toKeep, moduleIdMap);
+                    }
                 }
             }
         }

Modified: 
incubator/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyBuildListTest.java
URL: 
http://svn.apache.org/viewvc/incubator/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyBuildListTest.java?view=diff&rev=549603&r1=549602&r2=549603
==============================================================================
--- incubator/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyBuildListTest.java 
(original)
+++ incubator/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyBuildListTest.java 
Thu Jun 21 13:35:18 2007
@@ -27,6 +27,20 @@
 
 public class IvyBuildListTest extends TestCase {
 
+    /* 
+     * Those tests use the ivy files A , B , C , D , E in test/buildlist
+     * The dependencies are :
+     * A -> C
+     * B has no dependency
+     * C -> B
+     * D -> A , B
+     * E has no dependency
+     */
+
+    //CheckStyle:MagicNumber| OFF   
+    //The test very often use MagicNumber.  Using a constant is less expessif.
+
+    
     public void testSimple() {
         Project p = new Project();
 
@@ -49,6 +63,7 @@
         Path path = (Path) o;
         String[] files = path.list();
         assertNotNull(files);
+        
         assertEquals(5, files.length);
 
         assertEquals(new File("test/buildlist/B/build.xml").getAbsolutePath(), 
new File(files[0])
@@ -86,6 +101,7 @@
         Path path = (Path) o;
         String[] files = path.list();
         assertNotNull(files);
+        
         assertEquals(5, files.length);
 
         assertEquals(new File("test/buildlist/E/build.xml").getAbsolutePath(), 
new File(files[0])
@@ -98,6 +114,7 @@
                 .getAbsolutePath());
         assertEquals(new File("test/buildlist/B/build.xml").getAbsolutePath(), 
new File(files[4])
                 .getAbsolutePath());
+        
     }
 
     public void testWithRoot() {
@@ -154,7 +171,9 @@
         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());
@@ -194,6 +213,40 @@
                 .getAbsolutePath());
     }
 
+    
+    public void testWithRootAndOnlyDirectDep() {
+        Project p = new Project();
+
+        IvyBuildList buildlist = new IvyBuildList();
+        buildlist.setProject(p);
+        buildlist.setRoot("A");
+        buildlist.setOnlydirectdep(true);
+
+        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(2, files.length); // We should have only A and C
+
+        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());
+    }
+
+    
     public void testWithLeaf() {
         Project p = new Project();
 
@@ -217,7 +270,9 @@
         Path path = (Path) o;
         String[] files = path.list();
         assertNotNull(files);
+        
         assertEquals(3, files.length); // B should be filtered out
+        
 
         assertEquals(new File("test/buildlist/C/build.xml").getAbsolutePath(), 
new File(files[0])
                 .getAbsolutePath());
@@ -250,6 +305,7 @@
         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])
@@ -260,6 +316,7 @@
                 .getAbsolutePath());
         assertEquals(new File("test/buildlist/E/build.xml").getAbsolutePath(), 
new File(files[3])
                 .getAbsolutePath());
+        
     }
 
     public void testWithLeafExclude() {
@@ -294,4 +351,38 @@
                 .getAbsolutePath());
     }
 
+    
+    public void testWithLeafAndOnlyDirectDep() {
+        Project p = new Project();
+
+        IvyBuildList buildlist = new IvyBuildList();
+        buildlist.setProject(p);
+        buildlist.setLeaf("C");
+        buildlist.setOnlydirectdep(true);
+
+        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(2, files.length); // We must have only A and C
+
+        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());
+    }
+
 }
+//CheckStyle:MagicNumber| ON
\ No newline at end of file


Reply via email to