maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ogusa...@apache.org
Subject svn commit: r718516 - in /maven/mercury/trunk: mercury-maven/mercury-compare-mercury/src/main/java/org/sonatype/maven/plugins/mercury/compare/ mercury-md/mercury-md-sat/src/main/java/org/apache/maven/mercury/metadata/ mercury-md/mercury-md-sat/src/main...
Date Tue, 18 Nov 2008 07:32:08 GMT
Author: ogusakov
Date: Mon Nov 17 23:32:08 2008
New Revision: 718516

URL: http://svn.apache.org/viewvc?rev=718516&view=rev
Log:
added tree-stype conflict resolution for tool integration and as a first step towards OSGi
resolution

Added:
    maven/mercury/trunk/mercury-md/mercury-md-sat/src/main/java/org/apache/maven/mercury/metadata/sat/Messages.properties
Modified:
    maven/mercury/trunk/mercury-maven/mercury-compare-mercury/src/main/java/org/sonatype/maven/plugins/mercury/compare/MercuryResolve.java
    maven/mercury/trunk/mercury-md/mercury-md-sat/src/main/java/org/apache/maven/mercury/metadata/ClasspathContainer.java
    maven/mercury/trunk/mercury-md/mercury-md-sat/src/main/java/org/apache/maven/mercury/metadata/DependencyTreeBuilder.java
    maven/mercury/trunk/mercury-md/mercury-md-sat/src/main/java/org/apache/maven/mercury/metadata/MetadataTreeNode.java
    maven/mercury/trunk/mercury-md/mercury-md-sat/src/main/java/org/apache/maven/mercury/metadata/sat/DefaultSatSolver.java
    maven/mercury/trunk/mercury-md/mercury-md-sat/src/main/java/org/apache/maven/mercury/metadata/sat/SatContext.java
    maven/mercury/trunk/mercury-md/mercury-md-sat/src/main/java/org/apache/maven/mercury/metadata/sat/SatVar.java
    maven/mercury/trunk/mercury-md/mercury-md-sat/src/test/java/org/apache/maven/mercury/metadata/sat/DefaultSatSolverTest.java

Modified: maven/mercury/trunk/mercury-maven/mercury-compare-mercury/src/main/java/org/sonatype/maven/plugins/mercury/compare/MercuryResolve.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-maven/mercury-compare-mercury/src/main/java/org/sonatype/maven/plugins/mercury/compare/MercuryResolve.java?rev=718516&r1=718515&r2=718516&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-maven/mercury-compare-mercury/src/main/java/org/sonatype/maven/plugins/mercury/compare/MercuryResolve.java
(original)
+++ maven/mercury/trunk/mercury-maven/mercury-compare-mercury/src/main/java/org/sonatype/maven/plugins/mercury/compare/MercuryResolve.java
Mon Nov 17 23:32:08 2008
@@ -4,6 +4,7 @@
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileWriter;
+import java.io.StringWriter;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.List;
@@ -140,7 +141,7 @@
     
     MetadataTreeNode root = depBuilder.buildTree( bmd, ArtifactScopeEnum.runtime );
     
-    showNode( root, 0 );
+    MetadataTreeNode.showNode( root, 0 );
     
     long ll = System.currentTimeMillis();
     System.out.println("BuildTree: " + (ll - start) );
@@ -272,19 +273,5 @@
     return false;
   }
   //----------------------------------------------------------------
-  private static final void showNode( MetadataTreeNode n, int level )
-  {
-    for( int i=0; i<level; i++ )
-      System.out.print("  ");
-    
-    System.out.println( level+"."+n.getMd() );
-    
-    if( n.hasChildren() )
-    {
-      for( MetadataTreeNode kid : n.getChildren() )
-        showNode( kid, level+1 );
-    }
-  }
-  //----------------------------------------------------------------
 	//----------------------------------------------------------------
 }

Modified: maven/mercury/trunk/mercury-md/mercury-md-sat/src/main/java/org/apache/maven/mercury/metadata/ClasspathContainer.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-md/mercury-md-sat/src/main/java/org/apache/maven/mercury/metadata/ClasspathContainer.java?rev=718516&r1=718515&r2=718516&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-md/mercury-md-sat/src/main/java/org/apache/maven/mercury/metadata/ClasspathContainer.java
(original)
+++ maven/mercury/trunk/mercury-md/mercury-md-sat/src/main/java/org/apache/maven/mercury/metadata/ClasspathContainer.java
Mon Nov 17 23:32:08 2008
@@ -70,7 +70,8 @@
         for ( ArtifactMetadata md : classpath )
         {
           // TODO Oleg: is null for query good here ??
-            node = new MetadataTreeNode( md, parent, null, md.isResolved(), md.getArtifactScope()
);
+            node = new MetadataTreeNode( md, parent, null, md.isResolved() );
+            
             if ( tree == null )
             {
                 tree = node;

Modified: maven/mercury/trunk/mercury-md/mercury-md-sat/src/main/java/org/apache/maven/mercury/metadata/DependencyTreeBuilder.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-md/mercury-md-sat/src/main/java/org/apache/maven/mercury/metadata/DependencyTreeBuilder.java?rev=718516&r1=718515&r2=718516&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-md/mercury-md-sat/src/main/java/org/apache/maven/mercury/metadata/DependencyTreeBuilder.java
(original)
+++ maven/mercury/trunk/mercury-md/mercury-md-sat/src/main/java/org/apache/maven/mercury/metadata/DependencyTreeBuilder.java
Mon Nov 17 23:32:08 2008
@@ -35,7 +35,7 @@
 class DependencyTreeBuilder
 implements DependencyBuilder
 {
-  Language _lang = new DefaultLanguage(DependencyTreeBuilder.class);
+  private static final Language _lang = new DefaultLanguage(DependencyTreeBuilder.class);
   private static final IMercuryLogger _log = MercuryLoggerManager.getLogger( DependencyTreeBuilder.class
); 
   
   private Collection<MetadataTreeArtifactFilter> _filters;
@@ -106,7 +106,7 @@
     
     MetadataTreeNode root = createNode( startMD, null, startMD, treeScope );
     
-//    adjustSoftRanges( root );
+    MetadataTreeNode.reNumber( root, 1 );
     
     return root;
   }
@@ -144,24 +144,6 @@
     
   }
   //-----------------------------------------------------
-  private MetadataTreeNode deepCopy( MetadataTreeNode node, ArtifactScopeEnum scope )
-  {
-    MetadataTreeNode res = new MetadataTreeNode( node.getMd()
-                                                , node.getParent()
-                                                , node.getQuery()
-                                                , true
-                                                , scope
-                                                );
-    if( node.hasChildren() )
-      for( MetadataTreeNode kid : node.children )
-      {
-        MetadataTreeNode deepKid = deepCopy( kid, scope );
-        res.addChild( deepKid );
-      }
-    
-    return res;
-  }
-  //-----------------------------------------------------
   private MetadataTreeNode createNode( ArtifactBasicMetadata nodeMD, MetadataTreeNode parent,
ArtifactBasicMetadata nodeQuery, ArtifactScopeEnum globalScope )
   throws MetadataTreeException
   {
@@ -169,11 +151,10 @@
 
     ArtifactMetadata mr;
     
-// TODO: og - removed this optimization as it may break something
     MetadataTreeNode existingNode = existingNodes.get( nodeQuery.toString() );
     
     if( existingNode != null )
-      return deepCopy( existingNode, globalScope );
+      return MetadataTreeNode.deepCopy( existingNode );
     
     try
     {

Modified: maven/mercury/trunk/mercury-md/mercury-md-sat/src/main/java/org/apache/maven/mercury/metadata/MetadataTreeNode.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-md/mercury-md-sat/src/main/java/org/apache/maven/mercury/metadata/MetadataTreeNode.java?rev=718516&r1=718515&r2=718516&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-md/mercury-md-sat/src/main/java/org/apache/maven/mercury/metadata/MetadataTreeNode.java
(original)
+++ maven/mercury/trunk/mercury-md/mercury-md-sat/src/main/java/org/apache/maven/mercury/metadata/MetadataTreeNode.java
Mon Nov 17 23:32:08 2008
@@ -1,5 +1,9 @@
 package org.apache.maven.mercury.metadata;
 
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.StringWriter;
+import java.io.Writer;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.TreeSet;
@@ -41,6 +45,11 @@
   MetadataTreeNode parent;
   
   /**
+   * node unique id, used to identify this node in external tree manipulations, such as 

+   */
+  int id;
+  
+  /**
    * query node - the one that originated this actual node
    */
   ArtifactBasicMetadata query;
@@ -108,16 +117,15 @@
   /**
    * pointers to parent and query are a must. 
    */
-  public MetadataTreeNode(   ArtifactMetadata md,
-                             MetadataTreeNode parent,
-                             ArtifactBasicMetadata query,
-                             boolean resolved,
-                             ArtifactScopeEnum scope
+  public MetadataTreeNode( ArtifactMetadata md
+                           , MetadataTreeNode parent
+                           , ArtifactBasicMetadata query
+                           , boolean resolved
                          )
   {
         if ( md != null )
         {
-            md.setArtifactScope( ArtifactScopeEnum.checkScope(scope) );
+            md.setArtifactScope( ArtifactScopeEnum.checkScope(md.getArtifactScope()) );
             md.setResolved(resolved);
         }
 
@@ -128,7 +136,7 @@
   //------------------------------------------------------------------------
   public MetadataTreeNode( ArtifactMetadata md, MetadataTreeNode parent, ArtifactBasicMetadata
query )
   {
-    this( md, parent, query, true, ArtifactScopeEnum.compile );
+    this( md, parent, query, true );
   }
   //------------------------------------------------------------------------
   /**
@@ -249,6 +257,91 @@
       return queries;
     }
     //------------------------------------------------------------------------
+    public static final MetadataTreeNode deepCopy( MetadataTreeNode node )
+    {
+      MetadataTreeNode res = new MetadataTreeNode( node.getMd()
+                                                  , node.getParent()
+                                                  , node.getQuery()
+                                                  , true
+                                                  );
+      res.setId( node.getId() );
+      
+      if( node.hasChildren() )
+        for( MetadataTreeNode kid : node.children )
+        {
+          MetadataTreeNode deepKid = deepCopy( kid );
+          res.addChild( deepKid );
+        }
+      
+      return res;
+    }
+    //----------------------------------------------------------------
+    /**
+     * helper method to print the tree into a Writer
+     */
+    public static final void showNode( MetadataTreeNode n, int level, Writer wr )
+    throws IOException
+    {
+      for( int i=0; i<level; i++ )
+        wr.write("  ");
+      
+      wr.write( level+"."+n.getMd()+"\n" );
+      
+      if( n.hasChildren() )
+      {
+        for( MetadataTreeNode kid : n.getChildren() )
+          showNode( kid, level+1, wr );
+      }
+    }
+    //----------------------------------------------------------------
+    /**
+     * helper method to print the tree into sysout
+     */
+    public static final void showNode( MetadataTreeNode n, int level )
+    throws IOException
+    {
+      StringWriter sw = new StringWriter();
+      MetadataTreeNode.showNode( n, 0, sw );
+      System.out.println( sw.toString() );
+    }
     //------------------------------------------------------------------------
+    public int getId()
+    {
+      return id;
+    }
+    public void setId( int id )
+    {
+      this.id = id;
+    }
+    //------------------------------------------------------------------------
+    public static void reNumber( MetadataTreeNode node, int startNum )
+    {
+      reNum( node, new Counter(startNum) );
+    }
+    //------------------------------------------------------------------------
+    private static void reNum( MetadataTreeNode node, Counter num )
+    {
+      node.setId( num.next() );
 
+      if( node.hasChildren() )
+        for( MetadataTreeNode kid : node.getChildren() )
+          reNum( kid, num );
+    }
+    //------------------------------------------------------------------------
+    //------------------------------------------------------------------------
+}
+//------------------------------------------------------------------------
+class Counter
+{
+  int n;
+  
+  public Counter( int n )
+  {
+    this.n = n;
+  }
+  
+  int next()
+  {
+    return n++;
+  }
 }

Modified: maven/mercury/trunk/mercury-md/mercury-md-sat/src/main/java/org/apache/maven/mercury/metadata/sat/DefaultSatSolver.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-md/mercury-md-sat/src/main/java/org/apache/maven/mercury/metadata/sat/DefaultSatSolver.java?rev=718516&r1=718515&r2=718516&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-md/mercury-md-sat/src/main/java/org/apache/maven/mercury/metadata/sat/DefaultSatSolver.java
(original)
+++ maven/mercury/trunk/mercury-md/mercury-md-sat/src/main/java/org/apache/maven/mercury/metadata/sat/DefaultSatSolver.java
Mon Nov 17 23:32:08 2008
@@ -19,6 +19,7 @@
 import org.apache.maven.mercury.metadata.MetadataTreeNodeGAVComparator;
 import org.codehaus.plexus.lang.DefaultLanguage;
 import org.codehaus.plexus.lang.Language;
+import org.omg.stub.java.rmi._Remote_Stub;
 import org.sat4j.core.Vec;
 import org.sat4j.core.VecInt;
 import org.sat4j.pb.IPBSolver;
@@ -59,11 +60,14 @@
     if( tree == null)
       throw new SatException("cannot create a solver for an empty [null] tree");
     
+    if( tree.getId() == 0 )
+      MetadataTreeNode.reNumber( tree, 1 );
+    
     int nNodes = tree.countDistinctNodes();
 _log.debug( "SatContext: # of variables: "+nNodes );
 
     _context = new SatContext( nNodes );
-    _solver.newVar( _context.varCount );
+    _solver.newVar( tree.countNodes() );
     _root = tree;
     
     try
@@ -500,7 +504,7 @@
     {
       if( _solver.isSatisfiable() )
       {
-        res = new ArrayList<ArtifactMetadata>( _context.varCount );
+        res = new ArrayList<ArtifactMetadata>( _root.countNodes() );
         
         int [] model = _solver.model();
 
@@ -531,5 +535,40 @@
     return res;
   }
   //-----------------------------------------------------------------------
+  public final MetadataTreeNode solveAsTree()
+  throws SatException
+  {
+    try
+    {
+      if( _solver.isSatisfiable() )
+      {
+        int [] model = _solver.model();
+
+if( _log.isDebugEnabled() )
+  if( model != null )
+  {
+    StringBuilder sb = new StringBuilder();
+    String comma = "";
+    for( int m : model )
+    {
+      sb.append( comma+m );
+      comma = ", ";
+    }
+    _log.debug( '['+sb.toString()+']' );
+  }
+  else 
+    _log.debug( "model is null" );
+
+        return _context.getSolutionSubtree( _root, model );
+      }
+      return null;
+    }
+    catch (TimeoutException e)
+    {
+      throw new SatException( e );
+    }
+    
+  }
+  //-----------------------------------------------------------------------
   //-----------------------------------------------------------------------
 }

Added: maven/mercury/trunk/mercury-md/mercury-md-sat/src/main/java/org/apache/maven/mercury/metadata/sat/Messages.properties
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-md/mercury-md-sat/src/main/java/org/apache/maven/mercury/metadata/sat/Messages.properties?rev=718516&view=auto
==============================================================================
--- maven/mercury/trunk/mercury-md/mercury-md-sat/src/main/java/org/apache/maven/mercury/metadata/sat/Messages.properties
(added)
+++ maven/mercury/trunk/mercury-md/mercury-md-sat/src/main/java/org/apache/maven/mercury/metadata/sat/Messages.properties
Mon Nov 17 23:32:08 2008
@@ -0,0 +1,4 @@
+null.tree=tree root is null
+null.tree.md=tree root metadata is null
+null.model=model is null
+empty.model=model is null

Modified: maven/mercury/trunk/mercury-md/mercury-md-sat/src/main/java/org/apache/maven/mercury/metadata/sat/SatContext.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-md/mercury-md-sat/src/main/java/org/apache/maven/mercury/metadata/sat/SatContext.java?rev=718516&r1=718515&r2=718516&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-md/mercury-md-sat/src/main/java/org/apache/maven/mercury/metadata/sat/SatContext.java
(original)
+++ maven/mercury/trunk/mercury-md/mercury-md-sat/src/main/java/org/apache/maven/mercury/metadata/sat/SatContext.java
Mon Nov 17 23:32:08 2008
@@ -9,6 +9,8 @@
 import org.apache.maven.mercury.logging.IMercuryLogger;
 import org.apache.maven.mercury.logging.MercuryLoggerManager;
 import org.apache.maven.mercury.metadata.MetadataTreeNode;
+import org.codehaus.plexus.lang.DefaultLanguage;
+import org.codehaus.plexus.lang.Language;
 
  /**
   * This class hold all variables fed to the SAT solver. Because of the
@@ -18,10 +20,10 @@
   */
 class SatContext
 {
+  private static final Language _lang = new DefaultLanguage(SatContext.class);
   private static final IMercuryLogger _log = MercuryLoggerManager.getLogger( SatContext.class
);
 
   Map<MetadataTreeNode,SatVar> variables;
-  int varCount = 0;
   //-----------------------------------------------------------------------
   public SatContext( int estimatedTreeSize )
   {
@@ -42,9 +44,8 @@
         _log.debug( var.toString() );
       return var;
     }
-
     
-    var = new SatVar( n, ++varCount );
+    var = new SatVar( n );
     variables.put( n, var );
     
   if( _log.isDebugEnabled() )
@@ -62,6 +63,65 @@
     return null;
   }
   //-----------------------------------------------------------------------
+  private static final boolean isSolution( int m, int [] model )
+  {
+    for( int mm : model )
+      if( mm == m )
+        return true;
+    
+    return false;
+  }
+  //-----------------------------------------------------------------------
+  public MetadataTreeNode getSolutionSubtree( MetadataTreeNode tree, int [] model )
+  {
+    if( tree == null )
+      throw new IllegalArgumentException( _lang.getMessage( "null.tree" ) );
+    
+    if( tree.getMd() == null )
+      throw new IllegalArgumentException( _lang.getMessage( "null.tree.md" ) );
+    
+    if( model == null )
+      throw new IllegalArgumentException( _lang.getMessage( "null.model" ) );
+    
+    if( model.length < 1 )
+      throw new IllegalArgumentException( _lang.getMessage( "empty.model" ) );
+    
+    int sz = 0;
+    
+    for( int m : model )
+      if( m > 0 )
+        ++sz;
+      
+    if( sz == 0)
+      return null;
+    
+    MetadataTreeNode res = MetadataTreeNode.deepCopy( tree );
+    
+    cleanTree( res, model );
+    
+    return res;
+  }
+  //-----------------------------------------------------------------------
+  private static final void cleanTree( MetadataTreeNode tn, int [] model )
+  {
+    if( ! tn.hasChildren() )
+      return;
+    
+    List<MetadataTreeNode> badKids = new ArrayList<MetadataTreeNode>();
+    
+    for( MetadataTreeNode kid : tn.getChildren() )
+      if( ! isSolution( kid.getId(), model ) )
+        badKids.add( kid );
+      
+    tn.getChildren().removeAll( badKids );
+      
+    if( ! tn.hasChildren() )
+      return;
+      
+    for( MetadataTreeNode kid : tn.getChildren() )
+      cleanTree( kid, model );
+  }
+  //-----------------------------------------------------------------------
 //  @Override
 //  public String toString()
 //  {

Modified: maven/mercury/trunk/mercury-md/mercury-md-sat/src/main/java/org/apache/maven/mercury/metadata/sat/SatVar.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-md/mercury-md-sat/src/main/java/org/apache/maven/mercury/metadata/sat/SatVar.java?rev=718516&r1=718515&r2=718516&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-md/mercury-md-sat/src/main/java/org/apache/maven/mercury/metadata/sat/SatVar.java
(original)
+++ maven/mercury/trunk/mercury-md/mercury-md-sat/src/main/java/org/apache/maven/mercury/metadata/sat/SatVar.java
Mon Nov 17 23:32:08 2008
@@ -12,7 +12,7 @@
   int _literal;
   boolean _optional;
   //---------------------------------------------------------------------
-  public SatVar( MetadataTreeNode n, int literal )
+  public SatVar( MetadataTreeNode n )
   throws SatException
   {
     if( n == null
@@ -30,7 +30,7 @@
       throw new SatException("Cannot create SatVar from a null Metadata: "+md);
 
     this._node = n;
-    this._literal = literal;
+    this._literal = n.getId();
   }
   //---------------------------------------------------------------------
   public ArtifactMetadata getMd()

Modified: maven/mercury/trunk/mercury-md/mercury-md-sat/src/test/java/org/apache/maven/mercury/metadata/sat/DefaultSatSolverTest.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-md/mercury-md-sat/src/test/java/org/apache/maven/mercury/metadata/sat/DefaultSatSolverTest.java?rev=718516&r1=718515&r2=718516&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-md/mercury-md-sat/src/test/java/org/apache/maven/mercury/metadata/sat/DefaultSatSolverTest.java
(original)
+++ maven/mercury/trunk/mercury-md/mercury-md-sat/src/test/java/org/apache/maven/mercury/metadata/sat/DefaultSatSolverTest.java
Mon Nov 17 23:32:08 2008
@@ -1,5 +1,7 @@
 package org.apache.maven.mercury.metadata.sat;
 
+import java.io.IOException;
+import java.io.StringWriter;
 import java.util.ArrayList;
 import java.util.Comparator;
 import java.util.HashMap;
@@ -13,6 +15,8 @@
 import org.apache.maven.mercury.artifact.ArtifactScopeEnum;
 import org.apache.maven.mercury.metadata.ClassicDepthComparator;
 import org.apache.maven.mercury.metadata.ClassicVersionComparator;
+import org.apache.maven.mercury.metadata.DependencyBuilder;
+import org.apache.maven.mercury.metadata.DependencyBuilderFactory;
 import org.apache.maven.mercury.metadata.MetadataTreeNode;
 
 /**
@@ -66,6 +70,57 @@
     return -a + b;
   }
   //----------------------------------------------------------------------
+  //       d:d:1 - c:c:[2,4)
+  //      / 
+  // a:a:1
+  //      \     
+  //       b:b:2 - c:c:1
+  //----------------------------------------------------------------------
+  public void testReNumeration()
+  throws SatException, IOException
+  {
+    title = "testReNumeration";
+    System.out.println("\n\n==========================\n"+title+"\n");
+    
+    MetadataTreeNode na1 = new MetadataTreeNode( a1, null, null )
+      .addQuery(d1)
+      .addQuery(b2)
+    ;
+    
+    ArtifactBasicMetadata c2q = new ArtifactBasicMetadata("t:c:[2,4)");
+    
+    MetadataTreeNode nd1 = new MetadataTreeNode( d1, na1, d1 )
+      .addQuery( c2q )
+    ;
+    MetadataTreeNode nb2 = new MetadataTreeNode( b2, na1, b2 )
+      .addQuery( c1 )
+    ;
+    
+    MetadataTreeNode nc2 = new MetadataTreeNode( c2, nd1, c2q );
+
+    MetadataTreeNode nc1 = new MetadataTreeNode( c1, nb2, c1 );
+    
+    na1
+      .addChild(nd1)
+      .addChild(nb2)
+    ;
+    
+    nd1
+      .addChild(nc2)
+    ;
+    
+    nb2
+      .addChild(nc1)
+    ;
+    
+    MetadataTreeNode.reNumber( na1, 1 );
+    
+    assertEquals( 1, na1.getId() );
+    
+    assertEquals( 2, nd1.getId() );
+    
+  }
+  //----------------------------------------------------------------------
   public void testOptimization()
   throws SatException
   {
@@ -431,6 +486,68 @@
     assertTrue( res.contains( b2 ) );
     assertTrue( res.contains( c2 ) );
   }
+  
+  //----------------------------------------------------------------------
+  //       d:d:1 - c:c:[2,4)
+  //      / 
+  // a:a:1
+  //      \     
+  //       b:b:2 - c:c:1
+  //----------------------------------------------------------------------
+  public void testSolveAsTree()
+  throws SatException, IOException
+  {
+    title = "testSolveAsTree";
+    System.out.println("\n\n==========================\n"+title+"\n");
+    
+    MetadataTreeNode na1 = new MetadataTreeNode( a1, null, null )
+      .addQuery(d1)
+      .addQuery(b2)
+    ;
+    
+    ArtifactBasicMetadata c2q = new ArtifactBasicMetadata("t:c:[2,4)");
+    
+    MetadataTreeNode nd1 = new MetadataTreeNode( d1, na1, d1 )
+      .addQuery( c2q )
+    ;
+    MetadataTreeNode nb2 = new MetadataTreeNode( b2, na1, b2 )
+      .addQuery( c1 )
+    ;
+    
+    MetadataTreeNode nc2 = new MetadataTreeNode( c2, nd1, c2q );
+
+    MetadataTreeNode nc1 = new MetadataTreeNode( c1, nb2, c1 );
+    
+    na1
+      .addChild(nd1)
+      .addChild(nb2)
+    ;
+    
+    nd1
+      .addChild(nc2)
+    ;
+    
+    nb2
+      .addChild(nc1)
+    ;
+    
+    List<Comparator<MetadataTreeNode>> cl = new ArrayList<Comparator<MetadataTreeNode>>(2);
+    cl.add( new ClassicDepthComparator() );
+    cl.add( new ClassicVersionComparator() );
+
+    ss = (DefaultSatSolver) DefaultSatSolver.create(na1);
+    
+    ss.applyPolicies( cl );
+
+    MetadataTreeNode res = ss.solveAsTree();
+    
+    assertNotNull( res );
+    
+    MetadataTreeNode.showNode( res, 0 );
+    
+    assertEquals( 4, res.countNodes() );
+    
+  }
   //----------------------------------------------------------------------
   //----------------------------------------------------------------------
 }



Mime
View raw message