You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by og...@apache.org on 2009/04/28 01:12:32 UTC

svn commit: r769199 [4/19] - in /maven/mercury/trunk: mercury-ant-tasks/src/main/java/org/apache/maven/mercury/ant/tasks/ mercury-ant-tasks/src/test/java/org/apache/maven/mercury/ant/tasks/ mercury-core/src/main/java/org/apache/maven/mercury/artifact/ ...

Modified: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/DependencyTreeDumper.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/DependencyTreeDumper.java?rev=769199&r1=769198&r2=769199&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/DependencyTreeDumper.java (original)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/DependencyTreeDumper.java Mon Apr 27 23:12:25 2009
@@ -15,15 +15,12 @@
 KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.
-*/
+ */
 
 package org.apache.maven.mercury.metadata;
 
-import java.io.BufferedOutputStream;
-import java.io.BufferedWriter;
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileOutputStream;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.Writer;
@@ -44,26 +41,24 @@
 import org.apache.maven.mercury.util.TimeUtil;
 
 /**
- *
- *
  * @author Oleg Gusakov
  * @version $Id$
- *
  */
 public class DependencyTreeDumper
 {
     String _dumpFileName;
+
     File _dumpFile;
+
     Writer _wr;
-    
+
     public DependencyTreeDumper( String name )
     {
         _dumpFileName = name;
     }
-    
+
     /**
-     * this one does not work because the writer runs out of stack memory on
-     * huge trees
+     * this one does not work because the writer runs out of stack memory on huge trees
      * 
      * @param scope
      * @param artifacts
@@ -73,213 +68,214 @@
      * @param result
      * @throws MetadataTreeException
      */
-    public synchronized void realDump( ArtifactScopeEnum   scope
-                      , ArtifactQueryList artifacts
-                      , ArtifactInclusionList inclusions
-                      , ArtifactExclusionList exclusions
-                      , MetadataTreeNode dirty
-                      , List<ArtifactMetadata> result
-                    )
-    throws MetadataTreeException
+    public synchronized void realDump( ArtifactScopeEnum scope, ArtifactQueryList artifacts,
+                                       ArtifactInclusionList inclusions, ArtifactExclusionList exclusions,
+                                       MetadataTreeNode dirty, List<ArtifactMetadata> result )
+        throws MetadataTreeException
     {
         try
         {
-            if( artifacts == null || artifacts.getMetadataList() == null  )
+            if ( artifacts == null || artifacts.getMetadataList() == null )
                 return;
-            
+
             Forest forest;
-            if( _dumpFile.exists() )
+            if ( _dumpFile.exists() )
             {
-                forest = new ForrestXpp3Reader().read( new FileInputStream(_dumpFile) );
+                forest = new ForrestXpp3Reader().read( new FileInputStream( _dumpFile ) );
             }
             else
                 forest = new Forest();
-            
+
             Tree tree = new Tree();
-            
+
             forest.addTree( tree );
-            
+
             tree.setScope( scope == null ? "null" : scope.toString() );
-            
+
             tree.setTimestamp( TimeUtil.getUTCTimestamp() );
-            
-            for( ArtifactMetadata md : artifacts.getMetadataList() )
+
+            for ( ArtifactMetadata md : artifacts.getMetadataList() )
             {
                 Node n = new Node();
                 n.setName( md.toString() );
                 n.setScope( md.getScope() );
                 tree.addRequest( n );
             }
-            
-            if( inclusions != null )
-                for( ArtifactMetadata md : inclusions.getMetadataList() )
+
+            if ( inclusions != null )
+                for ( ArtifactMetadata md : inclusions.getMetadataList() )
                 {
                     Node n = new Node();
                     n.setName( md.toString() );
                     n.setScope( md.getScope() );
                     tree.addInclusion( n );
-                    
+
                 }
-                    
-            if( exclusions != null )
-                for( ArtifactMetadata md : exclusions.getMetadataList() )
+
+            if ( exclusions != null )
+                for ( ArtifactMetadata md : exclusions.getMetadataList() )
                 {
                     Node n = new Node();
                     n.setName( md.toString() );
                     n.setScope( md.getScope() );
                     tree.addExclusion( n );
-                    
+
                 }
-            
+
             Node root = createNode( dirty, 0L );
-            
+
             tree.addDirtyTree( root );
-            
-            if( result != null )
-                for( ArtifactMetadata md : result )
+
+            if ( result != null )
+                for ( ArtifactMetadata md : result )
                 {
                     Node n = new Node();
                     n.setName( md.toString() );
                     n.setScope( md.getScope() );
                     tree.addResult( n );
                 }
-            
-            new ForrestXpp3Writer().write( new FileWriter(_dumpFile), forest );
+
+            new ForrestXpp3Writer().write( new FileWriter( _dumpFile ), forest );
         }
-        catch (Exception e)
+        catch ( Exception e )
         {
-            throw new MetadataTreeException(e);
+            throw new MetadataTreeException( e );
         }
     }
-    
-    public synchronized void dump( ArtifactScopeEnum   scope
-                      , ArtifactQueryList artifacts
-                      , ArtifactInclusionList inclusions
-                      , ArtifactExclusionList exclusions
-                      , MetadataTreeNode dirty
-                      , List<ArtifactMetadata> result
-                    )
-    throws MetadataTreeException
+
+    public synchronized void dump( ArtifactScopeEnum scope, ArtifactQueryList artifacts,
+                                   ArtifactInclusionList inclusions, ArtifactExclusionList exclusions,
+                                   MetadataTreeNode dirty, List<ArtifactMetadata> result )
+        throws MetadataTreeException
     {
         try
         {
-            _dumpFile = new File(_dumpFileName+"-"+TimeUtil.getUTCTimestamp()+"-"+System.currentTimeMillis()+".xml" );
-            _wr = new FileWriter(_dumpFile);
+            _dumpFile =
+                new File( _dumpFileName + "-" + TimeUtil.getUTCTimestamp() + "-" + System.currentTimeMillis() + ".xml" );
+            _wr = new FileWriter( _dumpFile );
             _wr.write( "<tree>\n" );
         }
         catch ( IOException e )
         {
-            throw new MetadataTreeException(e);
+            throw new MetadataTreeException( e );
         }
         try
         {
-            if( artifacts != null && artifacts.getMetadataList() != null  )
+            if ( artifacts != null && artifacts.getMetadataList() != null )
             {
-                if( scope != null )
-                    _wr.write( "<scope>"+scope+"</scope>\n" );
-                
-                _wr.write( "<timestamp>"+ TimeUtil.getUTCTimestamp() +"</timestamp>\n" );
-                
+                if ( scope != null )
+                    _wr.write( "<scope>" + scope + "</scope>\n" );
+
+                _wr.write( "<timestamp>" + TimeUtil.getUTCTimestamp() + "</timestamp>\n" );
+
                 _wr.write( "<request>\n" );
-                for( ArtifactMetadata md : artifacts.getMetadataList() )
+                for ( ArtifactMetadata md : artifacts.getMetadataList() )
                 {
-                    _wr.write( "  <node scope='"+md.getScope()+"'>"+md.toString()+"</node>\n" );
+                    _wr.write( "  <node scope='" + md.getScope() + "'>" + md.toString() + "</node>\n" );
                 }
                 _wr.write( "</request>\n" );
-                
-                if( inclusions != null )
+
+                if ( inclusions != null )
                 {
                     _wr.write( "<inclusions>\n" );
-                    for( ArtifactMetadata md : inclusions.getMetadataList() )
+                    for ( ArtifactMetadata md : inclusions.getMetadataList() )
                     {
-                        _wr.write( "  <inclusion>"+md.toString()+"</inclusion>\n" );
+                        _wr.write( "  <inclusion>" + md.toString() + "</inclusion>\n" );
                     }
                     _wr.write( "</inclusions>\n" );
                 }
-                        
-                if( exclusions != null )
+
+                if ( exclusions != null )
                 {
                     _wr.write( "<exclusions>\n" );
-                    for( ArtifactMetadata md : exclusions.getMetadataList() )
+                    for ( ArtifactMetadata md : exclusions.getMetadataList() )
                     {
-                        _wr.write( "  <exclusion>"+md.toString()+"</exclusion>\n" );
+                        _wr.write( "  <exclusion>" + md.toString() + "</exclusion>\n" );
                     }
                     _wr.write( "</exclusions>\n" );
                 }
-                
+
                 _wr.write( "<source>\n" );
                 showNode( dirty, 0L );
                 _wr.write( "</source>\n" );
-                
-                if( result != null )
+
+                if ( result != null )
                 {
                     TreeSet<String> ts = new TreeSet<String>();
-                    for( ArtifactMetadata md : result )
+                    for ( ArtifactMetadata md : result )
                         ts.add( md.toString() );
-                        
+
                     _wr.write( "<result>\n" );
-                    for( String name : ts )
+                    for ( String name : ts )
                     {
-                        _wr.write( "  <node>"+name+"</node>\n" );
+                        _wr.write( "  <node>" + name + "</node>\n" );
                     }
                     _wr.write( "</result>\n" );
                 }
-                
+
             }
         }
-        catch (Exception e)
+        catch ( Exception e )
         {
-            throw new MetadataTreeException(e);
+            throw new MetadataTreeException( e );
         }
         finally
         {
-            if( _wr != null )
-                try { _wr.write( "</tree>\n" );_wr.flush(); _wr.close(); } catch( Exception ee ) {}
-                
+            if ( _wr != null )
+                try
+                {
+                    _wr.write( "</tree>\n" );
+                    _wr.flush();
+                    _wr.close();
+                }
+                catch ( Exception ee )
+                {
+                }
+
             _wr = null;
         }
     }
-    
+
     private void showNode( MetadataTreeNode mtn, long level )
-    throws IOException
+        throws IOException
     {
-        if( mtn == null )
+        if ( mtn == null )
             return;
-        
+
         ArtifactMetadata md = mtn.getMd();
-        for( int i=0; i<level; i++ )
+        for ( int i = 0; i < level; i++ )
             _wr.write( "  " );
-            
-        _wr.write( "  <node level='"+level+"'>"+md.toString()+"</node>\n" );
-        
-        if( mtn.hasChildren() )
+
+        _wr.write( "  <node level='" + level + "'>" + md.toString() + "</node>\n" );
+
+        if ( mtn.hasChildren() )
         {
             _wr.write( "  <kids>\n" );
-            for( MetadataTreeNode kid : mtn.getChildren() )
-                showNode( kid, level+1 );
+            for ( MetadataTreeNode kid : mtn.getChildren() )
+                showNode( kid, level + 1 );
             _wr.write( "  </kids>\n" );
         }
     }
-    
+
     private static Node createNode( MetadataTreeNode mtn, long level )
     {
-        if( mtn == null )
+        if ( mtn == null )
             return null;
-        
+
         Node n = new Node();
-        
+
         ArtifactMetadata md = mtn.getMd();
-        
+
         n.setName( md.toString() );
-        
+
         n.setLevel( level );
-        
-        if( mtn.hasChildren() )
+
+        if ( mtn.hasChildren() )
         {
-            for( MetadataTreeNode kid : mtn.getChildren() )
-                n.addChildren( createNode( kid, level+1 ) );
+            for ( MetadataTreeNode kid : mtn.getChildren() )
+                n.addChildren( createNode( kid, level + 1 ) );
         }
-        
+
         return n;
 
     }

Modified: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/MetadataRetrievalException.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/MetadataRetrievalException.java?rev=769199&r1=769198&r2=769199&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/MetadataRetrievalException.java (original)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/MetadataRetrievalException.java Mon Apr 27 23:12:25 2009
@@ -23,7 +23,7 @@
 
 /**
  * Error while retrieving repository metadata from the repository.
- *
+ * 
  * @author Jason van Zyl
  * @version $Id$
  */
@@ -43,15 +43,12 @@
         this( null, cause, null );
     }
 
-    public MetadataRetrievalException( String message,
-                                       Throwable cause )
+    public MetadataRetrievalException( String message, Throwable cause )
     {
         this( message, cause, null );
     }
 
-    public MetadataRetrievalException( String message,
-                                       Throwable cause,
-                                       ArtifactMetadata artifact )
+    public MetadataRetrievalException( String message, Throwable cause, ArtifactMetadata artifact )
     {
         super( message, cause );
 

Modified: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/MetadataTreeArtifactFilter.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/MetadataTreeArtifactFilter.java?rev=769199&r1=769198&r2=769199&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/MetadataTreeArtifactFilter.java (original)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/MetadataTreeArtifactFilter.java Mon Apr 27 23:12:25 2009
@@ -21,12 +21,11 @@
 import org.apache.maven.mercury.artifact.ArtifactMetadata;
 
 /**
- * This is a member of a chain of filters that can stop an ArtifactMetadata 
- * from reaching the resolution tree
+ * This is a member of a chain of filters that can stop an ArtifactMetadata from reaching the resolution tree
  * 
  * @author Oleg Gusakov
  */
 public interface MetadataTreeArtifactFilter
 {
-  public boolean veto( ArtifactMetadata md );
+    public boolean veto( ArtifactMetadata md );
 }

Modified: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/MetadataTreeArtifactFilterMap.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/MetadataTreeArtifactFilterMap.java?rev=769199&r1=769198&r2=769199&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/MetadataTreeArtifactFilterMap.java (original)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/MetadataTreeArtifactFilterMap.java Mon Apr 27 23:12:25 2009
@@ -15,7 +15,7 @@
 KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.
-*/
+ */
 
 package org.apache.maven.mercury.metadata;
 
@@ -26,31 +26,28 @@
 import org.apache.maven.mercury.util.Util;
 
 /**
- *
- *
  * @author Oleg Gusakov
  * @version $Id$
- *
  */
 public class MetadataTreeArtifactFilterMap
     implements MetadataTreeArtifactFilter
 {
     Map<String, Collection<String>> _vetos;
-    
-    public MetadataTreeArtifactFilterMap(Map<String, Collection<String>> vetos)
+
+    public MetadataTreeArtifactFilterMap( Map<String, Collection<String>> vetos )
     {
         _vetos = vetos;
     }
-    
+
     public boolean veto( ArtifactMetadata md )
     {
         String key = md.toManagementString();
-        
+
         Collection<String> ver = _vetos.get( key );
-        
-        if( Util.isEmpty( ver ) )
+
+        if ( Util.isEmpty( ver ) )
             return false;
-        
+
         return ver.contains( md.getVersion() );
     }
 

Modified: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/MetadataTreeCircularDependencyException.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/MetadataTreeCircularDependencyException.java?rev=769199&r1=769198&r2=769199&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/MetadataTreeCircularDependencyException.java (original)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/MetadataTreeCircularDependencyException.java Mon Apr 27 23:12:25 2009
@@ -19,31 +19,30 @@
 package org.apache.maven.mercury.metadata;
 
 /**
- * 
  * @author Oleg Gusakov
  * @version $Id$
  */
 public class MetadataTreeCircularDependencyException
-extends MetadataTreeException
+    extends MetadataTreeException
 {
 
-  public MetadataTreeCircularDependencyException()
-  {
-  }
-
-  public MetadataTreeCircularDependencyException(String message)
-  {
-    super(message);
-  }
-
-  public MetadataTreeCircularDependencyException(Throwable cause)
-  {
-    super(cause);
-  }
-
-  public MetadataTreeCircularDependencyException(String message, Throwable cause)
-  {
-    super(message, cause);
-  }
+    public MetadataTreeCircularDependencyException()
+    {
+    }
+
+    public MetadataTreeCircularDependencyException( String message )
+    {
+        super( message );
+    }
+
+    public MetadataTreeCircularDependencyException( Throwable cause )
+    {
+        super( cause );
+    }
+
+    public MetadataTreeCircularDependencyException( String message, Throwable cause )
+    {
+        super( message, cause );
+    }
 
 }

Modified: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/MetadataTreeException.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/MetadataTreeException.java?rev=769199&r1=769198&r2=769199&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/MetadataTreeException.java (original)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/MetadataTreeException.java Mon Apr 27 23:12:25 2009
@@ -19,7 +19,6 @@
 package org.apache.maven.mercury.metadata;
 
 /**
- * 
  * @author Oleg Gusakov
  * @version $Id$
  */
@@ -27,23 +26,23 @@
     extends Exception
 {
 
-  public MetadataTreeException()
-  {
-  }
-
-  public MetadataTreeException(String message)
-  {
-    super(message);
-  }
-
-  public MetadataTreeException(Throwable cause)
-  {
-    super(cause);
-  }
-
-  public MetadataTreeException(String message, Throwable cause)
-  {
-    super(message, cause);
-  }
+    public MetadataTreeException()
+    {
+    }
+
+    public MetadataTreeException( String message )
+    {
+        super( message );
+    }
+
+    public MetadataTreeException( Throwable cause )
+    {
+        super( cause );
+    }
+
+    public MetadataTreeException( String message, Throwable cause )
+    {
+        super( message, cause );
+    }
 
 }

Modified: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/MetadataTreeNodeGAComparator.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/MetadataTreeNodeGAComparator.java?rev=769199&r1=769198&r2=769199&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/MetadataTreeNodeGAComparator.java (original)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/MetadataTreeNodeGAComparator.java Mon Apr 27 23:12:25 2009
@@ -29,12 +29,12 @@
  * @version $Id$
  */
 public class MetadataTreeNodeGAComparator
-implements Comparator<MetadataTreeNode>
+    implements Comparator<MetadataTreeNode>
 {
 
-  public int compare(MetadataTreeNode n1, MetadataTreeNode n2)
-  {
-    return n1.getMd().getGA().compareTo( n2.getMd().getGA() );
-  }
+    public int compare( MetadataTreeNode n1, MetadataTreeNode n2 )
+    {
+        return n1.getMd().getGA().compareTo( n2.getMd().getGA() );
+    }
 
 }

Modified: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/MetadataTreeNodeGAVComparator.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/MetadataTreeNodeGAVComparator.java?rev=769199&r1=769198&r2=769199&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/MetadataTreeNodeGAVComparator.java (original)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/MetadataTreeNodeGAVComparator.java Mon Apr 27 23:12:25 2009
@@ -29,12 +29,12 @@
  * @version $Id$
  */
 public class MetadataTreeNodeGAVComparator
-implements Comparator<MetadataTreeNode>
+    implements Comparator<MetadataTreeNode>
 {
 
-  public int compare(MetadataTreeNode n1, MetadataTreeNode n2)
-  {
-    return n1.getMd().getGAV().compareTo( n2.getMd().getGAV() );
-  }
+    public int compare( MetadataTreeNode n1, MetadataTreeNode n2 )
+    {
+        return n1.getMd().getGAV().compareTo( n2.getMd().getGAV() );
+    }
 
 }

Modified: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/sat/DefaultSatSolver.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/sat/DefaultSatSolver.java?rev=769199&r1=769198&r2=769199&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/sat/DefaultSatSolver.java (original)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/sat/DefaultSatSolver.java Mon Apr 27 23:12:25 2009
@@ -57,608 +57,615 @@
  * @version $Id$
  */
 public class DefaultSatSolver
-implements SatSolver
+    implements SatSolver
 {
-  private static final IMercuryLogger LOG = MercuryLoggerManager.getLogger( DefaultSatSolver.class ); 
-  private static final Language LANG = new DefaultLanguage( DefaultSatSolver.class );
-  
-  protected SatContext _context;
-  protected IPBSolver _solver = SolverFactory.newEclipseP2();
-  protected MetadataTreeNode _root;
-  
-  protected EventManager _eventManager;
-
-  public static final BigInteger TWO = new BigInteger("2");
-  
-  protected static final Comparator<MetadataTreeNode> gaComparator = new MetadataTreeNodeGAComparator();
-  //-----------------------------------------------------------------------
-  public static SatSolver create( MetadataTreeNode tree )
-  throws SatException
-  {
-    return new DefaultSatSolver( tree );
-  }
-  //-----------------------------------------------------------------------
-  public static SatSolver create( MetadataTreeNode tree, EventManager eventManager )
-  throws SatException
-  {
-    return new DefaultSatSolver( tree, eventManager );
-  }
-  //-----------------------------------------------------------------------
-  public DefaultSatSolver( MetadataTreeNode tree, EventManager eventManager )
-  throws SatException
-  {
-    this._eventManager = eventManager;
-    GenericEvent event = null;
-    
-    if( tree == null)
-      throw new SatException( LANG.getMessage( "null.tree.arg" ) );
-    
-    try
-    {
-      if( _eventManager != null )
-        event = new GenericEvent( EventTypeEnum.satSolver, EVENT_CREATE_SOLVER, tree.toString() );
-        
-      if( tree.getId() == 0 )
-        MetadataTreeNode.reNumber( tree, 1 );
-      
-      int nNodes = tree.countDistinctNodes();
-  
-      LOG.debug( "SatContext: # of variables: "+nNodes );
-  
-      _context = new SatContext( nNodes );
-      _solver.newVar( tree.countNodes() );
-      _root = tree;
-      
-      try
-      {
-        addNode( tree );
-      }
-      catch (ContradictionException e)
-      {
-        throw new SatException(e);
-      }
-    }
-    finally
-    {
-      if( _eventManager != null )
-      {
-        event.stop();
-        _eventManager.fireEvent( event );
-      }
-    }
-  }
-  //-----------------------------------------------------------------------
-  public DefaultSatSolver( MetadataTreeNode tree )
-  throws SatException
-  {
-    this( tree, null );
-  }
-  //-----------------------------------------------------------------------
-  public final void applyPolicies( List<Comparator<MetadataTreeNode>> comparators )
-  throws SatException
-  {
-    if( comparators == null || comparators.size() < 1 )
-      return;
-    
-    if( _root == null )
-      throw new SatException( "cannot apply policies to a null tree" );
-    
-    // TODO og: assumption - around 128 GA's per tree. If more - map reallocates - slow down.
-    // TODO og: MERCURY-40
-    Map<String, List<MetadataTreeNode>> buckets = new LinkedHashMap<String, List<MetadataTreeNode>>(128);
-    fillBuckets( buckets, _root );
-    sortBuckets( buckets, comparators );
-    useBuckets( buckets );
-  }
-  //-----------------------------------------------------------------------
-  private void useBuckets( Map<String, List<MetadataTreeNode>> buckets )
-  throws SatException
-  {
-    if( buckets == null || buckets.size() < 1 )
-      return;
-    
-    IVecInt vars            = new VecInt( 128 );
-    IVec<BigInteger> coeffs = new Vec<BigInteger>( 128 );
-    
-    int count = 0;
-    
-    for( String key : buckets.keySet() )
-    {
-      List<MetadataTreeNode> bucket = buckets.get( key );
-  
-// oleg: ? this is needed if optimization is "maximize"       
-//      Collections.reverse(  bucket );
-      
-      int bucketSize = bucket.size(); 
-      
-      boolean bigBucket = bucketSize > 1;
-
-if( LOG.isDebugEnabled() )
-    LOG.debug( "\n\nBucket "+key );
-
-      IVecInt bucketVars = new VecInt( bucketSize );
-      
-      for( int i=0; i<bucketSize; i++ )
-      {
-        MetadataTreeNode n  = bucket.get(i);
-
-if( LOG.isDebugEnabled() )
-    LOG.debug( n.toString() );
-
-        SatVar var = _context.findOrAdd(n);
-        int varLiteral = var.getLiteral(); 
-        
-        bucketVars.push( varLiteral );
-        
-        if( bigBucket )
-        {
-          vars.push( varLiteral );
-          
-          BigInteger cf = TWO.pow( count++ );
-          
-          coeffs.push( cf );
-
-if( LOG.isDebugEnabled() )
-    LOG.debug( "    "+cf+" x"+var.getLiteral() );
-        }
-
-      }
-
-      try
-      {
-        if( bucketVars != null && !bucketVars.isEmpty() )
-        {
-          _solver.addAtMost( bucketVars, 1 );
-          _solver.addAtLeast( bucketVars, 1 );
-        }
-      }
-      catch( ContradictionException e )
-      {
-        throw new SatException(e);
-      }
-      
-if( LOG.isDebugEnabled() )
-  LOG.debug( "\n" );
-    }
-
-    if( vars.isEmpty() )
-      return;
-    
-    _solver.setObjectiveFunction( new ObjectiveFunction( vars, coeffs ) );
-  }
-  //-----------------------------------------------------------------------
-  protected static final void sortBuckets(
-        Map<String, List<MetadataTreeNode>> buckets
-      , List<Comparator<MetadataTreeNode>> comparators
-                                          )
-  {
-    Comparator<MetadataTreeNode> lastComparator;
-    for( List<MetadataTreeNode> bucket : buckets.values() )
-    {
-      lastComparator = gaComparator;
-      for( Comparator<MetadataTreeNode> comparator : comparators )
-      {
-        sortBucket( bucket, comparator, lastComparator );
-        lastComparator = comparator;
-      }
-      // due to the nature of Comparator need to reverse the result
-      // as the best fit is now last
-      Collections.reverse( bucket );
-
-      // the best fit now first, and we don't need duplicate GAVs
-      removeDuplicateGAVs( bucket );
-
-    }
-  }
-  //-----------------------------------------------------------------------
-  // remove duplicates, preserving the order. The first one is the most fit,
-  // so need to delete from tail
-  protected static final void removeDuplicateGAVs( List<MetadataTreeNode> bucket )
-  {
-    if( bucket == null || bucket.size() < 2 )
-      return;
-
-    Comparator<MetadataTreeNode> gav = new MetadataTreeNodeGAVComparator();
-    
-    int len = bucket.size();
-    int [] dups = new int[ len-1 ];
-    int cnt = 0;
-    
-    for( int i=1; i<len; i++ )
-    {
-      MetadataTreeNode ti = bucket.get(i);
-      
-      for( int j=0; j<i; j++ )
-        if( gav.compare( ti, bucket.get(j) ) == 0 )
-        {
-          dups[cnt++] = i;
-          break;
-        }
-    }
-    
-    if( cnt > 0 )
-      for( int i=0; i<cnt; i++ )
-        bucket.remove( dups[cnt-i-1] );
-  }
-  //-----------------------------------------------------------------------
-  /**
-   * reorders the bucket's lastComparator equal subsets with comparator.
-   */
-  protected static final void sortBucket(
-               List<MetadataTreeNode> bucket
-               , Comparator<MetadataTreeNode> comparator
-               , Comparator<MetadataTreeNode> lastComparator
-               )
-  {
-    if( bucket == null || bucket.size() < 2 )
-      return;
-    
-    int bLen = bucket.size();
-    MetadataTreeNode [] temp = bucket.toArray( new MetadataTreeNode[ bLen ] );
-    
-    int wStart = -1;
-    int wLen = 0;
-    MetadataTreeNode [] work = new MetadataTreeNode[ bLen ];
-    
-    MetadataTreeNode lastNode = null;
-    for( int i=0; i<bLen; i++ )
-    {
-      MetadataTreeNode n = temp[i];
-      
-      if( lastNode == null )
-      {
-        lastNode = n;
-        continue;
-      }
-      
-      if( lastComparator.compare(lastNode, n) == 0 )
-      {
-        if( wLen == 0 )
-        {
-          work[ wLen++ ] = lastNode;
-          wStart = i-1;
-        }
-        
-        work[ wLen++ ] = n;
-
-        lastNode = n;
-
-        if( i < (bLen-1) )
-          continue;
-      }
-      
-      if( wLen > 0 ) // eq list formed
-      {
-        reorder( work, wLen, comparator );
-        for( int j=0; j<wLen; j++ )
-          temp[ wStart+j ] = work[ j ];
-        wLen = 0;
-        wStart = -1;
-      }
-      
-      lastNode = n;
-    }
-    
-    bucket.clear();
-    for( int i=0; i<bLen; i++ )
-      bucket.add( temp[ i ] );
-  }
-  //-----------------------------------------------------------------------
-  private static final void reorder(
-                          MetadataTreeNode[] work
-                          , int wLen
-                          , Comparator<MetadataTreeNode> comparator
-                                   )
-  {
-    MetadataTreeNode[] temp = new MetadataTreeNode[ wLen ];
-    
-    for( int i=0; i< wLen; i++ )
-      temp[i] = work[i];
-    
-    Arrays.sort( temp, comparator );
-    
-    for( int i=0; i<wLen; i++ )
-      work[i] = temp[i];
-    
-  }
-  //-----------------------------------------------------------------------
-  protected static final void fillBuckets(
-        Map<String, List<MetadataTreeNode>> buckets
-      , MetadataTreeNode node
-                          )
-  {
-    String ga = node.getMd().getGA();
-    List<MetadataTreeNode> bucket = buckets.get(ga);
-    if( bucket == null )
-    {
-      // TODO og: assumption - around 32 GAVs per GA
-      bucket = new ArrayList<MetadataTreeNode>( 32 );
-      buckets.put( ga, bucket );
-    }
-    
-    bucket.add( node );
-    
-    if( ! node.hasChildren() )
-      return;
-    
-    for( MetadataTreeNode kid : node.getChildren() )
-    {
-      fillBuckets( buckets, kid );
-    }
-  }
-  //-----------------------------------------------------------------------
-  private final void addPB( IVecInt lits, IVec<BigInteger> coeff, boolean ge, BigInteger cardinality )
-  throws ContradictionException
-  {
-    _solver.addPseudoBoolean( lits, coeff, ge, cardinality );
-    
-if( LOG.isDebugEnabled() )
-  LOG.debug("PB: ");
-    
-    for( int i=0; i<lits.size(); i++ )
-    {
-      int co = Integer.parseInt( ""+coeff.get(i) );
-      String sign = co < 0 ? "-" : "+";
-      int    val = Math.abs(co);
-      String space = val == 1 ? "" : " ";
-      
-if( LOG.isDebugEnabled() )
-  LOG.debug( " " + sign + (val==1?"":val) + space  + "x"+lits.get(i) );
-    }
-if( LOG.isDebugEnabled() )
-  LOG.debug(( ge ? " >= " : " < ")+" "+cardinality );
-  }
-  //-----------------------------------------------------------------------
-  private final Map<ArtifactMetadata, List<MetadataTreeNode>> processChildren(
-                                                        List<ArtifactMetadata> queries
-                                                        , List<MetadataTreeNode> children
-                                                                              )
-  throws SatException
-  {
-    if( queries == null || queries.size() < 1 )
-      return null;
-    
-    if( children == null || children.size() < 1 )
-      throw new SatException("there are queries, but not results. Queries: "+queries);
-    
-    // TODO og: MERCURY-40
-    Map<ArtifactMetadata, List<MetadataTreeNode>> res = new LinkedHashMap<ArtifactMetadata, List<MetadataTreeNode>>( queries.size() );
-
-    for( ArtifactMetadata q : queries )
-    {
-      List<MetadataTreeNode> bucket = new ArrayList<MetadataTreeNode>(4);
-      String queryGA = q.getGA();
-      
-      for( MetadataTreeNode tn : children )
-      {
-        if( tn.getMd() == null )
-          throw new SatException("resulting tree node without metadata for query "+q );
-        
-        if( queryGA.equals( tn.getMd().getGA()) )
-        {
-          bucket.add(tn);
-        }
-      }
-      
-      if( bucket.size() < 1 )
-        throw new SatException("No children for query "+queryGA );
-      
-      res.put( q, bucket );
-    }
-
-    return res;
-  } 
-  //-----------------------------------------------------------------------
-  private final void addNode( MetadataTreeNode node )
-  throws ContradictionException, SatException
-  {
-    if( node == null )
-      return;
-    
-    if( node.getMd() == null )
-      throw new SatException("found a node without metadata");
-    
-    SatVar nodeLit = _context.findOrAdd( node );
-
-    // this one is a must :)
-    if( node.getParent() == null )
-      addPB( SatHelper.getSmallOnes( nodeLit.getLiteral() ), SatHelper.getBigOnes(1,false), true, BigInteger.ONE );
-    
-    if( ! node.hasChildren() )
-      return;
-    
-    Map<ArtifactMetadata,List<MetadataTreeNode>> kids = processChildren( node.getQueries(), node.getChildren() );
-    
-    // leaf node in this scope
-    if( kids == null )
-      return;
-    
-    for( Map.Entry<ArtifactMetadata,List<MetadataTreeNode>> kid : kids.entrySet() )
-    {
-      ArtifactMetadata query = kid.getKey();
-      
-      List<MetadataTreeNode> range = kid.getValue();
-
-      if( range.size() > 1 )
-      {
-        addRange( nodeLit.getLiteral(), range, query.isOptional() );
-        for( MetadataTreeNode tn : range )
-        {
-          addNode( tn );
-        }
-      }
-      else
-      {
-        MetadataTreeNode child = range.get(0);
-        SatVar kidLit = _context.findOrAdd( child );
-        
-        addPB( SatHelper.getSmallOnes( new int [] { nodeLit.getLiteral(), kidLit.getLiteral() } )
-            , SatHelper.getBigOnes( 1, -1 )
-            , true, BigInteger.ZERO
-            );
-//        addRange( nodeLit.getLiteral(), range, query.isOptional() );
-        addNode( child );
-      }
-
-    }
-  }
-  //-----------------------------------------------------------------------
-  private final int [] addRange( int parentLiteral, List<MetadataTreeNode> range, boolean optional )
-  throws ContradictionException, SatException
-  {
-    SatVar literal;
-    
-    int [] literals = new int[ range.size() ];
-    
-    int count = 0;
-    
-    for( MetadataTreeNode tn : range )
-    {
-      literal = _context.findOrAdd( tn );
-      literals[count++] = literal.getLiteral();
-
-      // implication to parent
-      addPB( SatHelper.getSmallOnes( new int [] { parentLiteral, literal.getLiteral() } )
-          , SatHelper.getBigOnes( 1, -1 )
-          , true, BigInteger.ZERO
-          );
-    }
-    
-    IVecInt rangeVector = SatHelper.getSmallOnes( literals );
-    
-    if( optional ) // Sxi >= 0
-    {
-if( LOG.isDebugEnabled() )
-  LOG.debug( "optional range: atMost 1: "+ SatHelper.vectorToString( rangeVector) );
-    
-      _solver.addAtMost( rangeVector, 1 );
-    }
-    else // Sxi = 1
-    {
-if( LOG.isDebugEnabled() )
-  LOG.debug( "range: " + SatHelper.vectorToString( rangeVector) );
-
-    IConstr atLeast = _solver.addAtLeast( rangeVector, 1 );
-    if( LOG.isDebugEnabled() )
-      LOG.debug( "atLeast: " + SatHelper.vectorToString( atLeast) );
-
-    IConstr atMost  = _solver.addAtMost( rangeVector, 1 );
-    if( LOG.isDebugEnabled() )
-      LOG.debug( "atMost: " + SatHelper.vectorToString( atMost) );
-
-    }
-    
-    return literals;
-  }
-  //-----------------------------------------------------------------------
-  public final List<ArtifactMetadata> solve()
-  throws SatException
-  {
-    List<ArtifactMetadata> res = null;
-    GenericEvent event = null;
-    
-    try
-    {
-      if( _eventManager != null )
-        event = new GenericEvent( EventTypeEnum.satSolver, EVENT_SOLVE, _root.toString() );
-      
-      if( _solver.isSatisfiable() )
-      {
-        res = new ArrayList<ArtifactMetadata>( _root.countNodes() );
-        
-        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" );
-
-        for( int i : model )
-          if( i > 0 )
-            res.add( _context.getMd( i ) );
-      }
-      else // not satisfied
-      {
-          throw new SatException( LANG.getMessage( "no.solution", _root.toString() ));
-      }
-    }
-    catch (TimeoutException e)
-    {
-      throw new SatException( e );
-    }
-    finally
-    {
-      if( _eventManager != null )
-      {
-        event.stop();
-        _eventManager.fireEvent( event );
-      }
-    }
-    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 );
-    }
-    
-  }
-  //-----------------------------------------------------------------------
-  public void register( MercuryEventListener listener )
-  {
-    if( _eventManager == null )
-      _eventManager = new EventManager();
-
-    _eventManager.register( listener );
-  }
-
-  public void setEventManager( EventManager eventManager )
-  {
-    _eventManager = eventManager;
-  }
-
-  public void unRegister( MercuryEventListener listener )
-  {
-    if( _eventManager != null )
-      _eventManager.unRegister( listener );
-  }
-  //-----------------------------------------------------------------------
+    private static final IMercuryLogger LOG = MercuryLoggerManager.getLogger( DefaultSatSolver.class );
+
+    private static final Language LANG = new DefaultLanguage( DefaultSatSolver.class );
+
+    protected SatContext _context;
+
+    protected IPBSolver _solver = SolverFactory.newEclipseP2();
+
+    protected MetadataTreeNode _root;
+
+    protected EventManager _eventManager;
+
+    public static final BigInteger TWO = new BigInteger( "2" );
+
+    protected static final Comparator<MetadataTreeNode> gaComparator = new MetadataTreeNodeGAComparator();
+
+    // -----------------------------------------------------------------------
+    public static SatSolver create( MetadataTreeNode tree )
+        throws SatException
+    {
+        return new DefaultSatSolver( tree );
+    }
+
+    // -----------------------------------------------------------------------
+    public static SatSolver create( MetadataTreeNode tree, EventManager eventManager )
+        throws SatException
+    {
+        return new DefaultSatSolver( tree, eventManager );
+    }
+
+    // -----------------------------------------------------------------------
+    public DefaultSatSolver( MetadataTreeNode tree, EventManager eventManager )
+        throws SatException
+    {
+        this._eventManager = eventManager;
+        GenericEvent event = null;
+
+        if ( tree == null )
+            throw new SatException( LANG.getMessage( "null.tree.arg" ) );
+
+        try
+        {
+            if ( _eventManager != null )
+                event = new GenericEvent( EventTypeEnum.satSolver, EVENT_CREATE_SOLVER, tree.toString() );
+
+            if ( tree.getId() == 0 )
+                MetadataTreeNode.reNumber( tree, 1 );
+
+            int nNodes = tree.countDistinctNodes();
+
+            LOG.debug( "SatContext: # of variables: " + nNodes );
+
+            _context = new SatContext( nNodes );
+            _solver.newVar( tree.countNodes() );
+            _root = tree;
+
+            try
+            {
+                addNode( tree );
+            }
+            catch ( ContradictionException e )
+            {
+                throw new SatException( e );
+            }
+        }
+        finally
+        {
+            if ( _eventManager != null )
+            {
+                event.stop();
+                _eventManager.fireEvent( event );
+            }
+        }
+    }
+
+    // -----------------------------------------------------------------------
+    public DefaultSatSolver( MetadataTreeNode tree )
+        throws SatException
+    {
+        this( tree, null );
+    }
+
+    // -----------------------------------------------------------------------
+    public final void applyPolicies( List<Comparator<MetadataTreeNode>> comparators )
+        throws SatException
+    {
+        if ( comparators == null || comparators.size() < 1 )
+            return;
+
+        if ( _root == null )
+            throw new SatException( "cannot apply policies to a null tree" );
+
+        // TODO og: assumption - around 128 GA's per tree. If more - map reallocates - slow down.
+        // TODO og: MERCURY-40
+        Map<String, List<MetadataTreeNode>> buckets = new LinkedHashMap<String, List<MetadataTreeNode>>( 128 );
+        fillBuckets( buckets, _root );
+        sortBuckets( buckets, comparators );
+        useBuckets( buckets );
+    }
+
+    // -----------------------------------------------------------------------
+    private void useBuckets( Map<String, List<MetadataTreeNode>> buckets )
+        throws SatException
+    {
+        if ( buckets == null || buckets.size() < 1 )
+            return;
+
+        IVecInt vars = new VecInt( 128 );
+        IVec<BigInteger> coeffs = new Vec<BigInteger>( 128 );
+
+        int count = 0;
+
+        for ( String key : buckets.keySet() )
+        {
+            List<MetadataTreeNode> bucket = buckets.get( key );
+
+            // oleg: ? this is needed if optimization is "maximize"
+            // Collections.reverse( bucket );
+
+            int bucketSize = bucket.size();
+
+            boolean bigBucket = bucketSize > 1;
+
+            if ( LOG.isDebugEnabled() )
+                LOG.debug( "\n\nBucket " + key );
+
+            IVecInt bucketVars = new VecInt( bucketSize );
+
+            for ( int i = 0; i < bucketSize; i++ )
+            {
+                MetadataTreeNode n = bucket.get( i );
+
+                if ( LOG.isDebugEnabled() )
+                    LOG.debug( n.toString() );
+
+                SatVar var = _context.findOrAdd( n );
+                int varLiteral = var.getLiteral();
+
+                bucketVars.push( varLiteral );
+
+                if ( bigBucket )
+                {
+                    vars.push( varLiteral );
+
+                    BigInteger cf = TWO.pow( count++ );
+
+                    coeffs.push( cf );
+
+                    if ( LOG.isDebugEnabled() )
+                        LOG.debug( "    " + cf + " x" + var.getLiteral() );
+                }
+
+            }
+
+            try
+            {
+                if ( bucketVars != null && !bucketVars.isEmpty() )
+                {
+                    _solver.addAtMost( bucketVars, 1 );
+                    _solver.addAtLeast( bucketVars, 1 );
+                }
+            }
+            catch ( ContradictionException e )
+            {
+                throw new SatException( e );
+            }
+
+            if ( LOG.isDebugEnabled() )
+                LOG.debug( "\n" );
+        }
+
+        if ( vars.isEmpty() )
+            return;
+
+        _solver.setObjectiveFunction( new ObjectiveFunction( vars, coeffs ) );
+    }
+
+    // -----------------------------------------------------------------------
+    protected static final void sortBuckets( Map<String, List<MetadataTreeNode>> buckets,
+                                             List<Comparator<MetadataTreeNode>> comparators )
+    {
+        Comparator<MetadataTreeNode> lastComparator;
+        for ( List<MetadataTreeNode> bucket : buckets.values() )
+        {
+            lastComparator = gaComparator;
+            for ( Comparator<MetadataTreeNode> comparator : comparators )
+            {
+                sortBucket( bucket, comparator, lastComparator );
+                lastComparator = comparator;
+            }
+            // due to the nature of Comparator need to reverse the result
+            // as the best fit is now last
+            Collections.reverse( bucket );
+
+            // the best fit now first, and we don't need duplicate GAVs
+            removeDuplicateGAVs( bucket );
+
+        }
+    }
+
+    // -----------------------------------------------------------------------
+    // remove duplicates, preserving the order. The first one is the most fit,
+    // so need to delete from tail
+    protected static final void removeDuplicateGAVs( List<MetadataTreeNode> bucket )
+    {
+        if ( bucket == null || bucket.size() < 2 )
+            return;
+
+        Comparator<MetadataTreeNode> gav = new MetadataTreeNodeGAVComparator();
+
+        int len = bucket.size();
+        int[] dups = new int[len - 1];
+        int cnt = 0;
+
+        for ( int i = 1; i < len; i++ )
+        {
+            MetadataTreeNode ti = bucket.get( i );
+
+            for ( int j = 0; j < i; j++ )
+                if ( gav.compare( ti, bucket.get( j ) ) == 0 )
+                {
+                    dups[cnt++] = i;
+                    break;
+                }
+        }
+
+        if ( cnt > 0 )
+            for ( int i = 0; i < cnt; i++ )
+                bucket.remove( dups[cnt - i - 1] );
+    }
+
+    // -----------------------------------------------------------------------
+    /**
+     * reorders the bucket's lastComparator equal subsets with comparator.
+     */
+    protected static final void sortBucket( List<MetadataTreeNode> bucket, Comparator<MetadataTreeNode> comparator,
+                                            Comparator<MetadataTreeNode> lastComparator )
+    {
+        if ( bucket == null || bucket.size() < 2 )
+            return;
+
+        int bLen = bucket.size();
+        MetadataTreeNode[] temp = bucket.toArray( new MetadataTreeNode[bLen] );
+
+        int wStart = -1;
+        int wLen = 0;
+        MetadataTreeNode[] work = new MetadataTreeNode[bLen];
+
+        MetadataTreeNode lastNode = null;
+        for ( int i = 0; i < bLen; i++ )
+        {
+            MetadataTreeNode n = temp[i];
+
+            if ( lastNode == null )
+            {
+                lastNode = n;
+                continue;
+            }
+
+            if ( lastComparator.compare( lastNode, n ) == 0 )
+            {
+                if ( wLen == 0 )
+                {
+                    work[wLen++] = lastNode;
+                    wStart = i - 1;
+                }
+
+                work[wLen++] = n;
+
+                lastNode = n;
+
+                if ( i < ( bLen - 1 ) )
+                    continue;
+            }
+
+            if ( wLen > 0 ) // eq list formed
+            {
+                reorder( work, wLen, comparator );
+                for ( int j = 0; j < wLen; j++ )
+                    temp[wStart + j] = work[j];
+                wLen = 0;
+                wStart = -1;
+            }
+
+            lastNode = n;
+        }
+
+        bucket.clear();
+        for ( int i = 0; i < bLen; i++ )
+            bucket.add( temp[i] );
+    }
+
+    // -----------------------------------------------------------------------
+    private static final void reorder( MetadataTreeNode[] work, int wLen, Comparator<MetadataTreeNode> comparator )
+    {
+        MetadataTreeNode[] temp = new MetadataTreeNode[wLen];
+
+        for ( int i = 0; i < wLen; i++ )
+            temp[i] = work[i];
+
+        Arrays.sort( temp, comparator );
+
+        for ( int i = 0; i < wLen; i++ )
+            work[i] = temp[i];
+
+    }
+
+    // -----------------------------------------------------------------------
+    protected static final void fillBuckets( Map<String, List<MetadataTreeNode>> buckets, MetadataTreeNode node )
+    {
+        String ga = node.getMd().getGA();
+        List<MetadataTreeNode> bucket = buckets.get( ga );
+        if ( bucket == null )
+        {
+            // TODO og: assumption - around 32 GAVs per GA
+            bucket = new ArrayList<MetadataTreeNode>( 32 );
+            buckets.put( ga, bucket );
+        }
+
+        bucket.add( node );
+
+        if ( !node.hasChildren() )
+            return;
+
+        for ( MetadataTreeNode kid : node.getChildren() )
+        {
+            fillBuckets( buckets, kid );
+        }
+    }
+
+    // -----------------------------------------------------------------------
+    private final void addPB( IVecInt lits, IVec<BigInteger> coeff, boolean ge, BigInteger cardinality )
+        throws ContradictionException
+    {
+        _solver.addPseudoBoolean( lits, coeff, ge, cardinality );
+
+        if ( LOG.isDebugEnabled() )
+            LOG.debug( "PB: " );
+
+        for ( int i = 0; i < lits.size(); i++ )
+        {
+            int co = Integer.parseInt( "" + coeff.get( i ) );
+            String sign = co < 0 ? "-" : "+";
+            int val = Math.abs( co );
+            String space = val == 1 ? "" : " ";
+
+            if ( LOG.isDebugEnabled() )
+                LOG.debug( " " + sign + ( val == 1 ? "" : val ) + space + "x" + lits.get( i ) );
+        }
+        if ( LOG.isDebugEnabled() )
+            LOG.debug( ( ge ? " >= " : " < " ) + " " + cardinality );
+    }
+
+    // -----------------------------------------------------------------------
+    private final Map<ArtifactMetadata, List<MetadataTreeNode>> processChildren( List<ArtifactMetadata> queries,
+                                                                                 List<MetadataTreeNode> children )
+        throws SatException
+    {
+        if ( queries == null || queries.size() < 1 )
+            return null;
+
+        if ( children == null || children.size() < 1 )
+            throw new SatException( "there are queries, but not results. Queries: " + queries );
+
+        // TODO og: MERCURY-40
+        Map<ArtifactMetadata, List<MetadataTreeNode>> res =
+            new LinkedHashMap<ArtifactMetadata, List<MetadataTreeNode>>( queries.size() );
+
+        for ( ArtifactMetadata q : queries )
+        {
+            List<MetadataTreeNode> bucket = new ArrayList<MetadataTreeNode>( 4 );
+            String queryGA = q.getGA();
+
+            for ( MetadataTreeNode tn : children )
+            {
+                if ( tn.getMd() == null )
+                    throw new SatException( "resulting tree node without metadata for query " + q );
+
+                if ( queryGA.equals( tn.getMd().getGA() ) )
+                {
+                    bucket.add( tn );
+                }
+            }
+
+            if ( bucket.size() < 1 )
+                throw new SatException( "No children for query " + queryGA );
+
+            res.put( q, bucket );
+        }
+
+        return res;
+    }
+
+    // -----------------------------------------------------------------------
+    private final void addNode( MetadataTreeNode node )
+        throws ContradictionException, SatException
+    {
+        if ( node == null )
+            return;
+
+        if ( node.getMd() == null )
+            throw new SatException( "found a node without metadata" );
+
+        SatVar nodeLit = _context.findOrAdd( node );
+
+        // this one is a must :)
+        if ( node.getParent() == null )
+            addPB( SatHelper.getSmallOnes( nodeLit.getLiteral() ), SatHelper.getBigOnes( 1, false ), true,
+                   BigInteger.ONE );
+
+        if ( !node.hasChildren() )
+            return;
+
+        Map<ArtifactMetadata, List<MetadataTreeNode>> kids = processChildren( node.getQueries(), node.getChildren() );
+
+        // leaf node in this scope
+        if ( kids == null )
+            return;
+
+        for ( Map.Entry<ArtifactMetadata, List<MetadataTreeNode>> kid : kids.entrySet() )
+        {
+            ArtifactMetadata query = kid.getKey();
+
+            List<MetadataTreeNode> range = kid.getValue();
+
+            if ( range.size() > 1 )
+            {
+                addRange( nodeLit.getLiteral(), range, query.isOptional() );
+                for ( MetadataTreeNode tn : range )
+                {
+                    addNode( tn );
+                }
+            }
+            else
+            {
+                MetadataTreeNode child = range.get( 0 );
+                SatVar kidLit = _context.findOrAdd( child );
+
+                addPB( SatHelper.getSmallOnes( new int[] { nodeLit.getLiteral(), kidLit.getLiteral() } ),
+                       SatHelper.getBigOnes( 1, -1 ), true, BigInteger.ZERO );
+                // addRange( nodeLit.getLiteral(), range, query.isOptional() );
+                addNode( child );
+            }
+
+        }
+    }
+
+    // -----------------------------------------------------------------------
+    private final int[] addRange( int parentLiteral, List<MetadataTreeNode> range, boolean optional )
+        throws ContradictionException, SatException
+    {
+        SatVar literal;
+
+        int[] literals = new int[range.size()];
+
+        int count = 0;
+
+        for ( MetadataTreeNode tn : range )
+        {
+            literal = _context.findOrAdd( tn );
+            literals[count++] = literal.getLiteral();
+
+            // implication to parent
+            addPB( SatHelper.getSmallOnes( new int[] { parentLiteral, literal.getLiteral() } ),
+                   SatHelper.getBigOnes( 1, -1 ), true, BigInteger.ZERO );
+        }
+
+        IVecInt rangeVector = SatHelper.getSmallOnes( literals );
+
+        if ( optional ) // Sxi >= 0
+        {
+            if ( LOG.isDebugEnabled() )
+                LOG.debug( "optional range: atMost 1: " + SatHelper.vectorToString( rangeVector ) );
+
+            _solver.addAtMost( rangeVector, 1 );
+        }
+        else
+        // Sxi = 1
+        {
+            if ( LOG.isDebugEnabled() )
+                LOG.debug( "range: " + SatHelper.vectorToString( rangeVector ) );
+
+            IConstr atLeast = _solver.addAtLeast( rangeVector, 1 );
+            if ( LOG.isDebugEnabled() )
+                LOG.debug( "atLeast: " + SatHelper.vectorToString( atLeast ) );
+
+            IConstr atMost = _solver.addAtMost( rangeVector, 1 );
+            if ( LOG.isDebugEnabled() )
+                LOG.debug( "atMost: " + SatHelper.vectorToString( atMost ) );
+
+        }
+
+        return literals;
+    }
+
+    // -----------------------------------------------------------------------
+    public final List<ArtifactMetadata> solve()
+        throws SatException
+    {
+        List<ArtifactMetadata> res = null;
+        GenericEvent event = null;
+
+        try
+        {
+            if ( _eventManager != null )
+                event = new GenericEvent( EventTypeEnum.satSolver, EVENT_SOLVE, _root.toString() );
+
+            if ( _solver.isSatisfiable() )
+            {
+                res = new ArrayList<ArtifactMetadata>( _root.countNodes() );
+
+                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" );
+
+                for ( int i : model )
+                    if ( i > 0 )
+                        res.add( _context.getMd( i ) );
+            }
+            else
+            // not satisfied
+            {
+                throw new SatException( LANG.getMessage( "no.solution", _root.toString() ) );
+            }
+        }
+        catch ( TimeoutException e )
+        {
+            throw new SatException( e );
+        }
+        finally
+        {
+            if ( _eventManager != null )
+            {
+                event.stop();
+                _eventManager.fireEvent( event );
+            }
+        }
+        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 );
+        }
+
+    }
+
+    // -----------------------------------------------------------------------
+    public void register( MercuryEventListener listener )
+    {
+        if ( _eventManager == null )
+            _eventManager = new EventManager();
+
+        _eventManager.register( listener );
+    }
+
+    public void setEventManager( EventManager eventManager )
+    {
+        _eventManager = eventManager;
+    }
+
+    public void unRegister( MercuryEventListener listener )
+    {
+        if ( _eventManager != null )
+            _eventManager.unRegister( listener );
+    }
+    // -----------------------------------------------------------------------
 }

Modified: maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/sat/DependencyConflictException.java
URL: http://svn.apache.org/viewvc/maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/sat/DependencyConflictException.java?rev=769199&r1=769198&r2=769199&view=diff
==============================================================================
--- maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/sat/DependencyConflictException.java (original)
+++ maven/mercury/trunk/mercury-core/src/main/java/org/apache/maven/mercury/metadata/sat/DependencyConflictException.java Mon Apr 27 23:12:25 2009
@@ -15,16 +15,13 @@
 KIND, either express or implied.  See the License for the
 specific language governing permissions and limitations
 under the License.
-*/
+ */
 
 package org.apache.maven.mercury.metadata.sat;
 
 /**
- *
- *
  * @author Oleg Gusakov
  * @version $Id$
- *
  */
 public class DependencyConflictException
     extends SatException