You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by jv...@apache.org on 2008/05/25 05:07:03 UTC

svn commit: r659899 [1/2] - in /maven/sandbox/trunk/mercury: ./ src/main/java/org/apache/maven/mercury/representation/ src/main/java/org/apache/maven/mercury/representation/conflict/ src/main/java/org/apache/maven/mercury/representation/transform/ src/...

Author: jvanzyl
Date: Sat May 24 20:07:02 2008
New Revision: 659899

URL: http://svn.apache.org/viewvc?rev=659899&view=rev
Log:
o merging my cut from maven-artifact with mercury

Added:
    maven/sandbox/trunk/mercury/notes.txt   (with props)
    maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/
    maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/ArtifactMetadata.java   (with props)
    maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/DefaultMetadataResolver.java   (with props)
    maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataGraph.java   (with props)
    maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataGraphEdge.java   (with props)
    maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataGraphVertex.java   (with props)
    maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataResolution.java   (with props)
    maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataResolutionException.java   (with props)
    maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataResolutionRequest.java   (with props)
    maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataResolutionRequestTypeEnum.java   (with props)
    maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataResolutionResult.java   (with props)
    maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataResolver.java   (with props)
    maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataRetrievalException.java   (with props)
    maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataSource.java   (with props)
    maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataTreeNode.java   (with props)
    maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/conflict/
    maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/conflict/ConflictResolutionException.java   (with props)
    maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/conflict/ConflictResolutionPolicy.java   (with props)
    maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/conflict/ConflictResolver.java   (with props)
    maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/conflict/DefaultConflictResolutionPolicy.java   (with props)
    maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/conflict/DefaultConflictResolver.java   (with props)
    maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/transform/
    maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/transform/ClasspathContainer.java   (with props)
    maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/transform/ClasspathTransformation.java   (with props)
    maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/transform/DefaultClasspathTransformation.java   (with props)
    maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/transform/MetadataGraphTransformationException.java   (with props)
    maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/version/
    maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/version/ArtifactVersion.java   (with props)
    maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/version/ComparableVersion.java   (with props)
    maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/version/DefaultArtifactVersion.java   (with props)
    maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/retrieve/
    maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/retrieve/ArtifactRetriever.java   (with props)
    maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/retrieve/DefaultArtifactRetriever.java   (with props)
    maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/retrieve/ResolutionRequest.java   (with props)
    maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/retrieve/ResolutionResult.java   (with props)
    maven/sandbox/trunk/mercury/src/main/mdo/
    maven/sandbox/trunk/mercury/src/main/mdo/metadata.mdo
Modified:
    maven/sandbox/trunk/mercury/pom.xml

Added: maven/sandbox/trunk/mercury/notes.txt
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/mercury/notes.txt?rev=659899&view=auto
==============================================================================
--- maven/sandbox/trunk/mercury/notes.txt (added)
+++ maven/sandbox/trunk/mercury/notes.txt Sat May 24 20:07:02 2008
@@ -0,0 +1,107 @@
+Maven Artifact is supposed to be a general artifact mechanism for retrieving, installing, and deploying artifacts
+to repositories. Maven Artifact was originally decoupled from Maven proper and as such carries a lot of baggage
+which prevents it from being used generally and carries many notions that are very specific to Maven itself. Artifacts
+currently have a notion of scope, classifiers, and behavioral attributes such as whether scopes should be inherited.
+For any mechanism to work generally these baked in notions need to be removed, vetted, and then made compatible with
+notions currently in Maven. A list of things that should not be in the Artifact:
+
+ * scope
+ * classifier
+ * dependency filter
+ * dependency trail
+ * resolved
+ * released
+ * optional
+ * available versions
+
+These are all attributes of the target system
+
+*Removal of the ArtifactFactory
+        
+ 3 February 2008 (Sunday)
+
+ I have removed the factory and left only a small set of constructors (which I would like to reduce to one) so that you
+ have a valid artifact after construction. I have also started to hide the VersionRange creation. You just pass in
+ a string and the constructor for the DefaultArtifact will do the right thing. This will ultimately need to be more
+ pluggable as different versioning strategies happen. But variations of the theme like Maven, OSGi, will have their
+ own subclasses and tools to operate on the graphs of dependencies.
+
+ 4 February 2008 (Monday)
+
+ John:
+ Some notes about classifiers taken from the mailing list in a discussion with John about classifiers:
+ I'd tend to disagree about classifier not being a 'core' part of the artifact system...it distinguishes a main
+ artifact from one of its derivatives, and serves as a pretty foundational part of how we retrieve artifacts from existing
+ remote repositories. Without it, I doubt that you can reconstruct the path to some existing artifacts (like sources or javadocs)
+ reliably without bastardizing the version string.
+
+ We can see that the artifact system has certain inescapable identity attributes. Scope is obviously more related
+ to how an artifact is used, since you can't see any trace of scope in the artifact as it's been deployed on a remote
+ repository. Classifier, however, doesn't fit this criteria...it's not a usage marker, but an identity marker.
+
+ The rest I agree with.
+
+ Jason:
+ This is where I think you've already baked in what you think about Maven. Look at how we deploy our derivative
+ artifacts right now. We don't track any of it in the metadata when we deploy. We toss it up there and things hope
+ they are there. Like javadocs, or sources. I think what's more important is that the coordinate be unique and we
+ have a way to associate what ever artifacts together in a scalable way. So you say "I want to associate this artifact
+ with that one, this is how I would like to record that relationship in the metadata.". Subsequently you can query
+ the metadata and know these relationships. We currently don't do this. It generally boils down to a bunch of
+ coordinates in the repository. How we choose to relate them via the metadata. We have all sort of problems with
+ classifiers currently because it was an adhoc method of association. A general model of association would be a
+ superset of what we currently do for classifiers. I agree we need an mechanism for association, I don't think
+ classifiers have worked all that well.
+
+ 5 February 2008 (Tuesday)
+
+ The rework of the artifact resolution mechanism is an attempt to entirely separate 1) the process of metadata retrieval into
+ a tree, 2) converting the tree to a graph by a process of conflict resolution, and 3) retrieving the complete set
+ of artifacts, and ultimately 4) Doing something in a particular fashion withe the retrieved set like make a classpath.
+ Currently we have an incremental processing model that doesn't let a complete graph be formed for analysis
+ which greatly complicates the process whereas having a graph and using standard graph analysis techniques and graph
+ optimization is the only reasonable way forward. There should be no doubt about what needs to be retrieved once the
+ analysis is complete. We could actually create an aggregrate request where instructions are sent to retrieve everything
+ required. The server could send a stream all the artifacts back in one shot.
+
+ What Oleg is attempting to do is create a working solution for 1) and 2) above. Along with the implementation we also
+ have a visualization tool that will help us determine what exactly the correct analysis is. The beauty of this is that
+ regardless of the analysis we arrive at a representation of the complete set can be modeled and we can start working on
+ the optimized retrieval mechanism. We still need to do some work to separate out 4) as we're doing some classpath
+ calculations already which we will need to further decouple but that should be relatively straight forward.
+
+ 7 February 2008 (Friday)
+
+ The number of methods in the artifact factory is simply insane, for each type that we ended up with in Maven just started
+ being effectively hard-coded in the factory which is totally unscalable, any new types with handlers become a nightmare
+ to maintain. I have reduced everything to two constructors in the DefaultArtifact and I would like to reduce it to being
+ one. Right now I have to account for needing to use a version string, or creating a range which is completely confusing
+ to anyone using the API. You should just need one constructor with a version string and everything else should be taken
+ care of for you. Right now there are bits of code all over the place that do the if/else versionRange detection. 
+
+ inheritedScope goes away entirely from the model when a graph is used because the scope selected will be a function of
+ how the graph is processed.
+ 
+ 24 May 2008
+ 
+ 1. Retrieval & Storage 
+    
+    There is the task of retrieving a set of resources from a data source atomically. Simple, and safe retrieval. Period. This has nothing to do with 
+    dependency management per se, but is the basis of any safe and reliable dependency management system. We need to deal with repository corruption
+    and recovery as well. The method employed by GIT with hierarchical checksums provides an efficient means to detect where in a repository corruption
+    has occured to make sure the problem can be correct, shunted around, or simply bring it to the users attention.
+ 
+ 2. Representation Processing 
+ 
+    There is the task of processing the representation of an artifact. In the case of Maven an artifact's representation is encapsulated in
+    a POM. If the representation refers to other representations i.e. dependencies then these have to be taken into account as well. The system
+    may allow transitive processing and this is where the real power of a dependency management system comes into play. The representations are
+    gathered into a tree structure where the flavour of the system imparts special processing on this tree to yield a graph. 
+    
+ Once the representation has been processed and we have a graph, we fall back to the retrieval mechanism to place the desired artifacts in
+ the storage system. Ultimately from this graph, according to the desired purpose we have set of artifacts that we can do something with.
+ 
+Processing
+
+I have come to the conclusion that providing the necessary support for version ranges cannot be done without a SAT solver, as we are 
+approaching an NP complete problem and we're going to end up with an approximation and all the heavy lifting is being done already by SAT4J.

Propchange: maven/sandbox/trunk/mercury/notes.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/trunk/mercury/notes.txt
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: maven/sandbox/trunk/mercury/pom.xml
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/mercury/pom.xml?rev=659899&r1=659898&r2=659899&view=diff
==============================================================================
--- maven/sandbox/trunk/mercury/pom.xml (original)
+++ maven/sandbox/trunk/mercury/pom.xml Sat May 24 20:07:02 2008
@@ -31,10 +31,48 @@
         <configuration>
           <source>1.5</source>
           <target>1.5</target>
-          <verbose>false</verbose>
         </configuration>
       </plugin>
       <plugin>
+        <groupId>org.codehaus.modello</groupId>
+        <artifactId>modello-maven-plugin</artifactId>
+        <version>1.0-alpha-17</version>
+        <configuration>
+          <version>1.0.0</version>
+          <model>src/main/mdo/metadata.mdo</model>
+        </configuration>
+        <executions>
+          <execution>
+            <id>site-docs</id>
+            <phase>pre-site</phase>
+            <goals>
+              <goal>xdoc</goal>
+              <goal>xsd</goal>
+            </goals>
+          </execution>
+          <execution>
+            <id>standard</id>
+            <goals>
+              <goal>java</goal>
+              <goal>xpp3-reader</goal>
+              <goal>xpp3-writer</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+      <plugin>
+        <groupId>org.codehaus.plexus</groupId>
+        <artifactId>plexus-maven-plugin</artifactId>
+        <version>1.3.8</version>
+        <executions>
+          <execution>
+            <goals>
+              <goal>descriptor</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>      
+      <plugin>
         <groupId>com.google.code.maven-license-plugin</groupId>
         <artifactId>maven-license-plugin</artifactId>
         <configuration>
@@ -52,6 +90,11 @@
   </build>
   <dependencies>
     <dependency>
+      <groupId>org.codehaus.plexus</groupId>
+      <artifactId>plexus-container-default</artifactId>
+      <version>1.0-alpha-43</version>
+    </dependency>  
+    <dependency>
       <groupId>org.mortbay.jetty</groupId>
       <artifactId>jetty-client</artifactId>
       <version>7.0.0pre0</version>

Added: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/ArtifactMetadata.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/ArtifactMetadata.java?rev=659899&view=auto
==============================================================================
--- maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/ArtifactMetadata.java (added)
+++ maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/ArtifactMetadata.java Sat May 24 20:07:02 2008
@@ -0,0 +1,273 @@
+package org.apache.maven.mercury.representation;
+
+import java.util.Collection;
+
+import org.apache.maven.mercury.Artifact;
+import org.apache.maven.mercury.ArtifactScopeEnum;
+
+/*
+ * Artifact Metadata that is resolved independent of Artifact itself.
+ * 
+ * @author <a href="oleg@codehaus.org">Oleg Gusakov</a>
+ */
+public class ArtifactMetadata
+{
+    /** 
+     * standard glorified artifact coordinates
+     */
+    protected String groupId;
+
+    protected String artifactId;
+
+    protected String version;
+
+    protected String type = "jar";
+
+    protected ArtifactScopeEnum artifactScope;
+
+    protected String classifier;
+
+    /** 
+     * explanation: why this MD was chosen over it's siblings
+     * in the resulting structure (classpath for now) 
+     */
+    protected String why;
+
+    /** dependencies of the artifact behind this metadata */
+    protected Collection<ArtifactMetadata> dependencies;
+
+    /** metadata URI */
+    protected String uri;
+
+    /** is metadata found anywhere */
+    protected boolean resolved = false;
+
+    /** does the actual artifact for this metadata exists */
+    protected boolean artifactExists = false;
+
+    /** artifact URI */
+    protected String artifactUri;
+
+    /** error message  */
+    private String error;
+
+    public ArtifactMetadata( String groupId, String name, String version )
+    {
+        this( groupId, name, version, null );
+    }
+
+    public ArtifactMetadata( String groupId, String name, String version, String type )
+    {
+        this( groupId, name, version, type, null );
+    }
+
+    public ArtifactMetadata( String groupId, String name, String version, String type, ArtifactScopeEnum artifactScope )
+    {
+        this( groupId, name, version, type, artifactScope, null );
+    }
+
+    public ArtifactMetadata( String groupId, String name, String version, String type, ArtifactScopeEnum artifactScope, String classifier )
+    {
+        this( groupId, name, version, type, artifactScope, classifier, null );
+    }
+
+    public ArtifactMetadata( String groupId, String name, String version, String type, ArtifactScopeEnum artifactScope, String classifier, String artifactUri )
+    {
+        this( groupId, name, version, type, artifactScope, classifier, artifactUri, null, true, null );
+    }
+
+    public ArtifactMetadata( String groupId, String name, String version, String type, ArtifactScopeEnum artifactScope, String classifier, String artifactUri, String why, boolean resolved,
+                             String error )
+    {
+        this.groupId = groupId;
+        this.artifactId = name;
+        this.version = version;
+        this.type = type;
+        this.artifactScope = artifactScope;
+        this.classifier = classifier;
+        this.artifactUri = artifactUri;
+        this.why = why;
+        this.resolved = resolved;
+        this.error = error;
+    }
+
+    public ArtifactMetadata( String groupId, String name, String version, String type, String scopeString, String classifier, String artifactUri, String why, boolean resolved, String error )
+    {
+        this( groupId, name, version, type, scopeString == null ? ArtifactScopeEnum.DEFAULT_SCOPE : ArtifactScopeEnum.valueOf( scopeString ), classifier, artifactUri, why, resolved, error );
+    }
+
+    public ArtifactMetadata( Artifact af )
+    {
+    }
+
+    @Override
+    public String toString()
+    {
+        return groupId + ":" + artifactId + ":" + version;
+    }
+
+    public String toDomainString()
+    {
+        return groupId + ":" + artifactId;
+    }
+
+    public String getGroupId()
+    {
+        return groupId;
+    }
+
+    public void setGroupId( String groupId )
+    {
+        this.groupId = groupId;
+    }
+
+    public String getArtifactId()
+    {
+        return artifactId;
+    }
+
+    public void setArtifactId( String name )
+    {
+        this.artifactId = name;
+    }
+
+    public String getVersion()
+    {
+        return version;
+    }
+
+    public void setVersion( String version )
+    {
+        this.version = version;
+    }
+
+    public String getType()
+    {
+        return type;
+    }
+
+    public String getCheckedType()
+    {
+        return type == null ? "jar" : type;
+    }
+
+    public void setType( String type )
+    {
+        this.type = type;
+    }
+
+    public ArtifactScopeEnum getArtifactScope()
+    {
+        return artifactScope == null ? ArtifactScopeEnum.DEFAULT_SCOPE : artifactScope;
+    }
+
+    public void setArtifactScope( ArtifactScopeEnum artifactScope )
+    {
+        this.artifactScope = artifactScope;
+    }
+
+    public void setScope( String scope )
+    {
+        this.artifactScope = scope == null ? ArtifactScopeEnum.DEFAULT_SCOPE : ArtifactScopeEnum.valueOf( scope );
+    }
+
+    public String getClassifier()
+    {
+        return classifier;
+    }
+
+    public void setClassifier( String classifier )
+    {
+        this.classifier = classifier;
+    }
+
+    public boolean isResolved()
+    {
+        return resolved;
+    }
+
+    public void setResolved( boolean resolved )
+    {
+        this.resolved = resolved;
+    }
+
+    public String getUri()
+    {
+        return uri;
+    }
+
+    public void setUri( String uri )
+    {
+        this.uri = uri;
+    }
+
+    public String getScope()
+    {
+        return getArtifactScope().getScope();
+    }
+
+    public ArtifactScopeEnum getScopeAsEnum()
+    {
+        return artifactScope == null ? ArtifactScopeEnum.DEFAULT_SCOPE : artifactScope;
+    }
+
+    public boolean isArtifactExists()
+    {
+        return artifactExists;
+    }
+
+    public void setArtifactExists( boolean artifactExists )
+    {
+        this.artifactExists = artifactExists;
+    }
+
+    public Collection<ArtifactMetadata> getDependencies()
+    {
+        return dependencies;
+    }
+
+    public void setDependencies( Collection<ArtifactMetadata> dependencies )
+    {
+        this.dependencies = dependencies;
+    }
+
+    public String getArtifactUri()
+    {
+        return artifactUri;
+    }
+
+    public void setArtifactUri( String artifactUri )
+    {
+        this.artifactUri = artifactUri;
+    }
+
+    public String getWhy()
+    {
+        return why;
+    }
+
+    public void setWhy( String why )
+    {
+        this.why = why;
+    }
+
+    public String getError()
+    {
+        return error;
+    }
+
+    public void setError( String error )
+    {
+        this.error = error;
+    }
+
+    public boolean isError()
+    {
+        return error == null;
+    }
+
+    public String getDependencyConflictId()
+    {
+        return groupId + ":" + artifactId;
+    }
+}

Propchange: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/ArtifactMetadata.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/ArtifactMetadata.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/DefaultMetadataResolver.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/DefaultMetadataResolver.java?rev=659899&view=auto
==============================================================================
--- maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/DefaultMetadataResolver.java (added)
+++ maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/DefaultMetadataResolver.java Sat May 24 20:07:02 2008
@@ -0,0 +1,98 @@
+package org.apache.maven.mercury.representation;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.maven.mercury.Artifact;
+import org.apache.maven.mercury.ArtifactRepository;
+import org.apache.maven.mercury.DefaultArtifact;
+import org.apache.maven.mercury.retrieve.ArtifactRetriever;
+import org.apache.maven.mercury.retrieve.ResolutionRequest;
+import org.apache.maven.mercury.retrieve.ResolutionResult;
+
+/*
+ * default implementation of the metadata resolver
+ * 
+ * @author Oleg Gusakov
+ * 
+ * @plexus.component
+ */
+public class DefaultMetadataResolver
+    implements MetadataResolver
+{
+    //------------------------------------------------------------------------
+
+    /** @plexus.requirement */
+    ArtifactRetriever artifactResolver;
+
+    /** @plexus.requirement */
+    MetadataSource metadataSource;
+
+    //------------------------------------------------------------------------
+    public MetadataResolutionResult resolveMetadata( MetadataResolutionRequest request )
+        throws MetadataResolutionException
+    {
+        MetadataResolutionResult result = new MetadataResolutionResult();
+
+        MetadataTreeNode tree = resolveMetadataTree( request.getQuery(), null, request.getLocalRepository(), request.getRemoteRepositories() );
+
+        result.setTree( tree );
+
+        return result;
+    }
+
+    //------------------------------------------------------------------------
+    private MetadataTreeNode resolveMetadataTree( ArtifactMetadata query, MetadataTreeNode parent, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
+        throws MetadataResolutionException
+    {
+        try
+        {
+            Artifact pomArtifact = new DefaultArtifact( query.getGroupId(), query.getArtifactId(), query.getVersion(), query.getType(), null, false, query.getScope(), null );
+
+            ResolutionRequest request = new ResolutionRequest().setArtifact( pomArtifact ).setLocalRepository( localRepository ).setRemoteRepostories( remoteRepositories );
+
+            ResolutionResult result = artifactResolver.retrieve( request );
+
+            // Here we just need to deal with basic retrieval problems.
+            if ( result.hasExceptions() )
+            {
+                pomArtifact.setResolved( false );
+            }
+
+            if ( pomArtifact.isResolved() )
+            {
+                MetadataResolution metadataResolution = metadataSource.retrieve( query, localRepository, remoteRepositories );
+                ArtifactMetadata found = metadataResolution.getArtifactMetadata();
+
+                if ( pomArtifact.getFile() != null && pomArtifact.getFile().toURI() != null )
+                {
+                    found.setArtifactUri( pomArtifact.getFile().toURI().toString() );
+                }
+
+                MetadataTreeNode node = new MetadataTreeNode( found, parent, true, found.getScopeAsEnum() );
+                Collection<ArtifactMetadata> dependencies = metadataResolution.getArtifactMetadata().getDependencies();
+
+                if ( dependencies != null && dependencies.size() > 0 )
+                {
+                    int numberOfChildren = dependencies.size();
+                    node.setNChildren( numberOfChildren );
+                    int kidNo = 0;
+                    for ( ArtifactMetadata a : dependencies )
+                    {
+                        MetadataTreeNode kidNode = resolveMetadataTree( a, node, localRepository, remoteRepositories );
+                        node.addChild( kidNo++, kidNode );
+                    }
+                }
+                return node;
+            }
+            else
+            {
+                return new MetadataTreeNode( pomArtifact, parent, false, query.getArtifactScope() );
+            }
+        }
+        catch ( Exception anyEx )
+        {
+            throw new MetadataResolutionException( anyEx );
+        }
+    }
+}

Propchange: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/DefaultMetadataResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/DefaultMetadataResolver.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataGraph.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataGraph.java?rev=659899&view=auto
==============================================================================
--- maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataGraph.java (added)
+++ maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataGraph.java Sat May 24 20:07:02 2008
@@ -0,0 +1,462 @@
+package org.apache.maven.mercury.representation;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeSet;
+
+import org.apache.maven.mercury.ArtifactScopeEnum;
+
+
+/**
+ * maven dependency metadata graph
+ * 
+ * @author <a href="oleg@codehaus.org">Oleg Gusakov</a>
+ *
+ */
+
+public class MetadataGraph
+{
+	public static int DEFAULT_VERTICES = 32;
+	public static int DEFAULT_EDGES    = 64;
+	
+	// flags to indicate the granularity of vertices
+	private boolean versionedVertices = false;
+	private boolean scopedVertices    = false;
+	/**
+	 * the entry point we started building the graph from
+	 */
+    MetadataGraphVertex entry;
+    
+    // graph vertices
+    TreeSet< MetadataGraphVertex >  vertices;
+
+    /** 
+     * incident and excident edges per node
+     */
+    Map<MetadataGraphVertex, List<MetadataGraphEdge>> incidentEdges;
+    Map<MetadataGraphVertex, List<MetadataGraphEdge>> excidentEdges;
+    
+    /**
+     *  null in dirty graph, actual 
+     *  scope for conflict-resolved graph
+     */
+    ArtifactScopeEnum scope;
+
+    //------------------------------------------------------------------------
+    /**
+     * init graph
+     */
+    public MetadataGraph( int nVertices )
+    {
+    	init( nVertices, 2*nVertices );
+    }
+    public MetadataGraph( int nVertices, int nEdges )
+    {
+    	init( nVertices, nEdges );
+    }
+    //------------------------------------------------------------------------
+    /**
+     * construct a single vertex
+     */
+    public MetadataGraph( MetadataGraphVertex entry )
+    throws MetadataResolutionException
+    {
+    	checkVertex(entry);
+    	checkVertices(1);
+
+    	entry.setCompareVersion( versionedVertices );
+    	entry.setCompareScope( scopedVertices );
+
+    	vertices.add( entry );
+    	this.entry = entry;
+    }
+    //------------------------------------------------------------------------
+    /**
+     * construct graph from a "dirty" tree
+     */
+    public MetadataGraph( MetadataTreeNode tree )
+    throws MetadataResolutionException
+    {
+    	this( tree, false, false );
+    }
+    //------------------------------------------------------------------------
+    /**
+     * construct graph from a "dirty" tree
+     * 
+     * @param tree "dirty" tree root
+     * @param versionedVertices true if graph nodes should be versioned (different versions -> different nodes)
+     * @param scopedVertices true if graph nodes should be versioned and scoped (different versions and/or scopes -> different nodes)
+     * 
+     */
+    public MetadataGraph( MetadataTreeNode tree, boolean versionedVertices, boolean scopedVertices )
+    throws MetadataResolutionException
+    {
+        if ( tree == null )
+        {
+            throw new MetadataResolutionException( "tree is null" );
+        }
+
+        setVersionedVertices(versionedVertices);
+        setScopedVertices(scopedVertices);
+        
+        this.versionedVertices = scopedVertices || versionedVertices;
+        this.scopedVertices = scopedVertices;
+        
+        int count = countNodes( tree );
+
+        init( count, count + ( count / 2 ) );
+
+        processTreeNodes( null, tree, 0, 0 );
+    }
+    //------------------------------------------------------------------------
+    private void processTreeNodes(   MetadataGraphVertex parentVertex
+                               , MetadataTreeNode node
+                               , int depth
+                               , int pomOrder
+    						)
+    throws MetadataResolutionException
+    {
+        if ( node == null )
+        {
+            return;
+        }
+
+        MetadataGraphVertex vertex = new MetadataGraphVertex( node.md, versionedVertices, scopedVertices );
+        if( ! vertices.contains(vertex) )
+        {
+        	vertices.add(vertex);
+        }
+
+        if( parentVertex != null ) // then create the edge
+        { 
+            ArtifactMetadata md = node.getMd();
+            MetadataGraphEdge e = new MetadataGraphEdge( md.version, md.resolved, md.artifactScope, md.artifactUri, depth, pomOrder );
+            addEdge( parentVertex, vertex, e);
+        }
+        else
+        {
+        	entry = vertex;
+        }
+
+        MetadataTreeNode[] kids = node.getChildren();
+        if ( kids == null || kids.length < 1 )
+        {
+            return;
+        }
+
+        for( int i = 0; i< kids.length; i++ )
+        {
+        	MetadataTreeNode n = kids[i];
+            processTreeNodes( vertex, n, depth + 1, i );
+        }
+    }
+    //------------------------------------------------------------------------
+    public MetadataGraphVertex findVertex( ArtifactMetadata md )
+    {
+    	if( md == null || vertices == null || vertices.size() < 1 )
+    		return null;
+    	
+    	MetadataGraphVertex v = new MetadataGraphVertex(md);
+    	v.setCompareVersion(versionedVertices);
+    	v.setCompareScope(scopedVertices);
+
+    	for( MetadataGraphVertex gv : vertices  )
+    	{
+    		if( gv.equals(v) )
+    			return gv;
+    	}
+    	
+    	return null;
+    }
+    //------------------------------------------------------------------------
+    public MetadataGraphVertex addVertex( ArtifactMetadata md )
+    {
+    	if( md == null )
+    		return null;
+   
+    	checkVertices();
+    	
+    	MetadataGraphVertex v = findVertex(md);
+    	if( v != null)
+    		return v;
+    	
+    	v = new MetadataGraphVertex(md);
+    	
+    	v.setCompareVersion(versionedVertices);
+    	v.setCompareScope(scopedVertices);
+
+    	vertices.add( v );
+    	return v;
+    }
+    //------------------------------------------------------------------------
+    /**
+     * init graph
+     */
+    private void init( int nVertices, int nEdges )
+    {
+    	int nV = nVertices;
+    	if( nVertices < 1 )
+    		nV = 1;
+ 
+    	checkVertices(nV);
+
+    	int nE = nVertices;
+    	if( nEdges <= nV )
+    		nE = 2*nE;
+ 
+    	checkEdges(nE);
+    }
+
+    private void checkVertices()
+    {
+    	checkVertices(DEFAULT_VERTICES);
+    }
+
+    private void checkVertices( int nVertices )
+    {
+    	if( vertices == null )
+    		vertices = new TreeSet<MetadataGraphVertex>();
+    }
+    private void checkEdges()
+    {
+    	int count = DEFAULT_EDGES;
+    	
+    	if( vertices != null )
+    		count = vertices.size() + vertices.size() / 2;
+
+    	checkEdges( count );
+    }
+    private void checkEdges( int nEdges )
+    {
+    	if( incidentEdges == null )
+    		incidentEdges = new HashMap<MetadataGraphVertex, List<MetadataGraphEdge>>( nEdges );
+    	if( excidentEdges == null )
+    		excidentEdges = new HashMap<MetadataGraphVertex, List<MetadataGraphEdge>>( nEdges );
+    }
+    //------------------------------------------------------------------------
+    private static void checkVertex( MetadataGraphVertex v )
+    throws MetadataResolutionException
+    {
+    	if( v == null )
+    		throw new MetadataResolutionException( "null vertex" );
+    	if( v.getMd() == null )
+    		throw new MetadataResolutionException( "vertex without metadata" );
+    }
+    //------------------------------------------------------------------------
+    private static void checkEdge( MetadataGraphEdge e )
+    throws MetadataResolutionException
+    {
+    	if( e == null )
+    		throw new MetadataResolutionException( "badly formed edge" );
+    }
+    //------------------------------------------------------------------------
+    public List<MetadataGraphEdge> getEdgesBetween(
+    							  MetadataGraphVertex vFrom
+    							, MetadataGraphVertex vTo
+    							)
+    {
+    	List<MetadataGraphEdge> edges = getIncidentEdges(vTo);
+    	if( edges == null || edges.isEmpty() )
+    		return null;
+    	
+    	List<MetadataGraphEdge> res = new ArrayList<MetadataGraphEdge>( edges.size() );
+    	
+    	for( MetadataGraphEdge e : edges )
+    	{
+    		if( e.getSource().equals(vFrom) )
+    			res.add(e);
+    	}
+    	
+    	return res;
+    }
+    //------------------------------------------------------------------------
+    public MetadataGraph addEdge( MetadataGraphVertex vFrom
+    							, MetadataGraphVertex vTo
+    							, MetadataGraphEdge e
+    							)
+    throws MetadataResolutionException
+    {
+    	checkVertex(vFrom);
+    	checkVertex(vTo);
+
+    	checkVertices();
+    	
+    	checkEdge(e);
+    	checkEdges();
+    	
+    	e.setSource(vFrom);
+    	e.setTarget(vTo);
+
+    	vFrom.setCompareVersion(versionedVertices);
+    	vFrom.setCompareScope(scopedVertices);
+    	
+    	List<MetadataGraphEdge> exList = excidentEdges.get(vFrom);
+    	if( exList == null ) {
+    		exList = new ArrayList<MetadataGraphEdge>();
+    		excidentEdges.put( vFrom, exList );
+    	}
+    	
+    	if( !exList.contains(e) )
+    		exList.add(e);
+    	
+    	List<MetadataGraphEdge> inList = incidentEdges.get(vTo);
+    	if( inList == null ) {
+    		inList = new ArrayList<MetadataGraphEdge>();
+    		incidentEdges.put( vTo, inList );
+    	}
+    	
+    	if( !inList.contains(e) )
+    		inList.add(e);
+    	
+    	return this;
+    }
+    //------------------------------------------------------------------------
+    public MetadataGraph removeVertex( MetadataGraphVertex v )
+    {
+    	if( vertices!= null && v != null )
+    		vertices.remove(v);
+    	
+    	if( incidentEdges!= null )
+    		incidentEdges.remove(v);
+    	
+    	if( excidentEdges!= null )
+    		excidentEdges.remove(v);
+
+    	return this;
+    		
+    }
+    //------------------------------------------------------------------------
+    private static int countNodes( MetadataTreeNode tree )
+    {
+        if ( tree == null )
+        {
+            return 0;
+        }
+
+        int count = 1;
+        MetadataTreeNode[] kids = tree.getChildren();
+        if ( kids == null || kids.length < 1 )
+        {
+            return count;
+        }
+        for ( MetadataTreeNode n : kids )
+        {
+            count += countNodes( n );
+        }
+
+        return count;
+    }
+
+    //------------------------------------------------------------------------
+    public MetadataGraphVertex getEntry()
+    {
+        return entry;
+    }
+
+    public void setEntry( MetadataGraphVertex entry )
+    {
+        this.entry = entry;
+    }
+
+    public TreeSet<MetadataGraphVertex> getVertices()
+    {
+        return vertices;
+    }
+    
+	public List<MetadataGraphEdge> getIncidentEdges( MetadataGraphVertex vertex )
+	{
+		checkEdges();
+		return incidentEdges.get(vertex);
+	}
+    
+	public List<MetadataGraphEdge> getExcidentEdges( MetadataGraphVertex vertex )
+	{
+		checkEdges();
+		return excidentEdges.get(vertex);
+	}
+    
+    public boolean isVersionedVertices()
+	{
+		return versionedVertices;
+	}
+	public void setVersionedVertices(boolean versionedVertices)
+	{
+		this.versionedVertices = versionedVertices;
+	}
+	public boolean isScopedVertices()
+	{
+		return scopedVertices;
+	}
+	public void setScopedVertices(boolean scopedVertices)
+	{
+		this.scopedVertices = scopedVertices;
+
+		// scoped graph is versioned by definition
+		if( scopedVertices )
+			versionedVertices = true;
+	}
+	public ArtifactScopeEnum getScope()
+	{
+		return scope;
+	}
+	public void setScope(ArtifactScopeEnum scope)
+	{
+		this.scope = scope;
+	}
+    //------------------------------------------------------------------------
+	public boolean isEmpty()
+	{
+		return
+			entry == null
+			|| vertices == null
+			|| vertices.isEmpty()
+		;
+	}
+    //------------------------------------------------------------------------
+	public boolean isEmptyEdges()
+	{
+		return
+			   isEmpty()
+			|| incidentEdges == null
+			|| incidentEdges.isEmpty()
+		;
+	}
+    //------------------------------------------------------------------------
+	@Override
+	public String toString()
+	{
+		StringBuilder sb = new StringBuilder(512);
+		if( isEmpty() )
+			return "empty";
+		for( MetadataGraphVertex v : vertices )
+		{
+			sb.append("Vertex:  "+v.getMd().toString()+ "\n");
+			List<MetadataGraphEdge> ins = getIncidentEdges(v);
+			if( ins != null )
+				for( MetadataGraphEdge e : ins )
+				{
+					sb.append("       from :  "+e.toString()+"\n");
+				}
+			else
+				sb.append("      no entries\n");
+				
+			List<MetadataGraphEdge> outs = getExcidentEdges(v);
+			if( outs != null )
+				for( MetadataGraphEdge e : outs )
+				{
+					sb.append("        to :  "+e.toString()+ "\n");
+				}
+			else
+				sb.append("      no exit\n");
+				
+			sb.append("-------------------------------------------------\n");
+		}
+		sb.append("=============================================================\n");
+		return sb.toString();
+	}
+	
+    //------------------------------------------------------------------------
+    //------------------------------------------------------------------------
+}

Propchange: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataGraph.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataGraph.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataGraphEdge.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataGraphEdge.java?rev=659899&view=auto
==============================================================================
--- maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataGraphEdge.java (added)
+++ maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataGraphEdge.java Sat May 24 20:07:02 2008
@@ -0,0 +1,180 @@
+package org.apache.maven.mercury.representation;
+
+import org.apache.maven.mercury.ArtifactScopeEnum;
+
+
+/**
+ * metadata graph edge - combination of version, scope and depth define 
+ * an edge in the graph
+ * 
+ * @author <a href="oleg@codehaus.org">Oleg Gusakov</a>
+ *
+ */
+
+public class MetadataGraphEdge
+{
+    String            version;
+    ArtifactScopeEnum scope;
+    int               depth = -1;
+    int               pomOrder = -1;
+    boolean           resolved = true;
+    String            artifactUri;
+    
+    /**
+     * capturing where this link came from
+     * and where it is linked to.
+     * 
+     *   In the first implementation only source used for explanatory function
+     */
+    MetadataGraphVertex  source;
+    MetadataGraphVertex  target;
+
+    //----------------------------------------------------------------------------
+    public MetadataGraphEdge( String version
+    						, boolean resolved
+                            , ArtifactScopeEnum scope
+                            , String artifactUri
+                            , int depth
+                            , int pomOrder
+                            )
+    {
+        super();
+        this.version = version;
+        this.scope = scope;
+        this.artifactUri = artifactUri;
+        this.depth = depth;
+        this.resolved = resolved;
+        this.pomOrder = pomOrder;
+    }
+    //----------------------------------------------------------------------------
+    /**
+     * helper for equals
+     */
+    private static boolean objectsEqual( Object o1,
+                                         Object o2 )
+    {
+        if ( o1 == null && o2 == null )
+        {
+            return true;
+        }
+        if ( ( o1 == null && o2 != null )
+            || ( o1 != null && o2 == null )
+            )
+        {
+            return false;
+        }
+        return o1.equals( o2 );
+    }
+
+    //----------------------------------------------------------------------------
+    /**
+     * used to eliminate exact duplicates in the edge list
+     */
+    @Override
+    public boolean equals( Object o )
+    {
+        if ( o instanceof MetadataGraphEdge )
+        {
+            MetadataGraphEdge e = (MetadataGraphEdge) o;
+            
+            return
+                objectsEqual( version, e.version )
+                && ArtifactScopeEnum.checkScope(scope).getScope().equals( 
+                		ArtifactScopeEnum.checkScope(e.scope).getScope()
+                														)
+                && depth == e.depth
+                ;
+        }
+        return false;
+    }
+
+    //----------------------------------------------------------------------------
+    public String getVersion()
+    {
+        return version;
+    }
+
+    public void setVersion( String version )
+    {
+        this.version = version;
+    }
+
+    public ArtifactScopeEnum getScope()
+    {
+        return scope;
+    }
+
+    public void setScope( ArtifactScopeEnum scope )
+    {
+        this.scope = scope;
+    }
+
+    public int getDepth()
+    {
+        return depth;
+    }
+
+    public void setDepth( int depth )
+    {
+        this.depth = depth;
+    }
+
+	public boolean isResolved()
+	{
+		return resolved;
+	}
+
+	public void setResolved(boolean resolved)
+	{
+		this.resolved = resolved;
+	}
+
+	public int getPomOrder()
+	{
+		return pomOrder;
+	}
+
+	public void setPomOrder(int pomOrder)
+	{
+		this.pomOrder = pomOrder;
+	}
+
+	public String getArtifactUri()
+	{
+		return artifactUri;
+	}
+	public void setArtifactUri(String artifactUri)
+	{
+		this.artifactUri = artifactUri;
+	}
+	
+	public MetadataGraphVertex getSource()
+	{
+		return source;
+	}
+	public void setSource(MetadataGraphVertex source)
+	{
+		this.source = source;
+	}
+	public MetadataGraphVertex getTarget()
+	{
+		return target;
+	}
+	public void setTarget(MetadataGraphVertex target)
+	{
+		this.target = target;
+	}
+	@Override
+	public String toString()
+	{
+		return "[ " 
+				+ "FROM:("+( source==null?"no source":(source.md==null?"no source MD":source.md.toString()) )+") "
+				+ "TO:("+( target==null?"no target":(target.md==null?"no target MD":target.md.toString()) )+") "
+					+"version="+version
+					+", scope="+(scope == null ? "null" : scope.getScope())
+					+", depth="+depth+"]"
+				;
+	}
+    //----------------------------------------------------------------------------
+    //----------------------------------------------------------------------------
+}

Propchange: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataGraphEdge.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataGraphEdge.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataGraphVertex.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataGraphVertex.java?rev=659899&view=auto
==============================================================================
--- maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataGraphVertex.java (added)
+++ maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataGraphVertex.java Sat May 24 20:07:02 2008
@@ -0,0 +1,165 @@
+package org.apache.maven.mercury.representation;
+
+import org.apache.maven.mercury.ArtifactScopeEnum;
+
+
+/**
+ * metadata graph vertice - just a wrapper around artifact's metadata
+ * 
+ * @author <a href="oleg@codehaus.org">Oleg Gusakov</a>
+ *
+ */
+
+public class MetadataGraphVertex
+implements Comparable<MetadataGraphVertex>
+{
+    ArtifactMetadata md;
+
+    // indications to use these in comparrison
+    private boolean compareVersion = false;
+    private boolean compareScope   = false;
+    
+	public MetadataGraphVertex( ArtifactMetadata md )
+    {
+        super();
+        this.md = md;
+    }
+    
+	public MetadataGraphVertex( ArtifactMetadata md, boolean compareVersion, boolean compareScope )
+    {
+        this(md);
+        this.compareVersion = compareVersion;
+        this.compareScope = compareScope;
+    }
+
+    public ArtifactMetadata getMd()
+    {
+        return md;
+    }
+
+    public void setMd( ArtifactMetadata md )
+    {
+        this.md = md;
+    }
+	//---------------------------------------------------------------------
+    public boolean isCompareVersion()
+	{
+		return compareVersion;
+	}
+
+	public void setCompareVersion(boolean compareVersion)
+	{
+		this.compareVersion = compareVersion;
+	}
+
+	public boolean isCompareScope()
+	{
+		return compareScope;
+	}
+
+	public void setCompareScope(boolean compareScope)
+	{
+		this.compareScope = compareScope;
+	}
+
+	//---------------------------------------------------------------------
+	@Override
+	public String toString()
+	{
+		return "["+ (md == null ? "no metadata" : md.toString()) + "]";
+	}
+	//---------------------------------------------------------------------
+	private static int compareStrings( String s1, String s2 )
+	{
+		if( s1 == null && s2 == null )
+			return 0;
+
+		if( s1 == null && s2 != null )
+			return -1;
+
+		if( s1 != null && s2 == null )
+			return 1;
+		
+		return s1.compareTo(s2);
+	}
+	//---------------------------------------------------------------------
+	public int compareTo(MetadataGraphVertex vertex)
+	{
+		if( vertex == null || vertex.getMd() == null )
+			return 1;
+		
+		ArtifactMetadata vmd = vertex.getMd();
+
+		if( vmd == null )
+		{
+			if( md == null )
+				return 0;
+			else
+				return 1;
+		}
+		
+		int g = compareStrings( md.groupId, vmd.groupId );
+		
+		if( g == 0 )
+		{
+			int a = compareStrings( md.artifactId, vmd.artifactId );
+			if( a == 0 )
+			{
+				if( compareVersion )
+				{
+					int v = compareStrings( md.version, vmd.version );
+					if( v == 0) {
+						if( compareScope ) {
+							String s1 = ArtifactScopeEnum.checkScope( md.artifactScope).getScope();
+							String s2 = ArtifactScopeEnum.checkScope(vmd.artifactScope).getScope();
+							return s1.compareTo(s2);
+						}
+						else
+							return 0;
+					}
+					else
+						return v;
+				}
+				else
+					return 0;
+			}
+			else
+				return a;
+		}
+		
+		return g;
+	}
+	//---------------------------------------------------------------------
+	@Override
+	public boolean equals(Object vo)
+	{
+		if( vo == null || !(vo instanceof MetadataGraphVertex) )
+			return false;
+		return compareTo( (MetadataGraphVertex)vo ) == 0;
+	}
+	//---------------------------------------------------------------------
+
+	@Override
+	public int hashCode()
+	{
+		if( md == null )
+			return super.hashCode();
+		StringBuilder hashString = new StringBuilder(128);
+		hashString.append( md.groupId+"|" );
+		hashString.append( md.artifactId+"|" );
+		
+		if( compareVersion )
+			hashString.append(md.version + "|");
+		
+		if( compareScope )
+			hashString.append(md.getArtifactScope() + "|");
+		
+		return  hashString.toString().hashCode();
+
+//		BASE64Encoder b64 = new BASE64Encoder();
+//		return  b64.encode( hashString.toString().getBytes() ).hashCode();
+	}
+	
+	//---------------------------------------------------------------------
+	//---------------------------------------------------------------------
+}

Propchange: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataGraphVertex.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataGraphVertex.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataResolution.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataResolution.java?rev=659899&view=auto
==============================================================================
--- maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataResolution.java (added)
+++ maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataResolution.java Sat May 24 20:07:02 2008
@@ -0,0 +1,54 @@
+package org.apache.maven.mercury.representation;
+
+import java.util.Collection;
+
+import org.apache.maven.mercury.ArtifactRepository;
+
+/**
+ * 
+ * @author Jason van Zyl
+ *  
+ */
+public class MetadataResolution
+{
+    /** resolved MD  */
+    private ArtifactMetadata artifactMetadata;
+
+    /** repositories, added by this POM  */
+    private Collection<ArtifactRepository> metadataRepositories;
+    //-------------------------------------------------------------------
+    public MetadataResolution( ArtifactMetadata artifactMetadata )
+    {
+        this.artifactMetadata = artifactMetadata;
+    }
+    //-------------------------------------------------------------------
+    public MetadataResolution( ArtifactMetadata artifactMetadata,
+    		Collection<ArtifactRepository> metadataRepositories )
+    {
+    	this( artifactMetadata );
+        this.metadataRepositories = metadataRepositories;
+    }
+    //-------------------------------------------------------------------
+	public Collection<ArtifactRepository> getMetadataRepositories()
+	{
+		return metadataRepositories;
+	}
+
+	public void setMetadataRepositories(
+			Collection<ArtifactRepository> metadataRepositories)
+	{
+		this.metadataRepositories = metadataRepositories;
+	}
+    //-------------------------------------------------------------------
+	public ArtifactMetadata getArtifactMetadata()
+	{
+		return artifactMetadata;
+	}
+
+	public void setArtifactMetadata(ArtifactMetadata artifactMetadata)
+	{
+		this.artifactMetadata = artifactMetadata;
+	}
+    //-------------------------------------------------------------------
+    //-------------------------------------------------------------------
+}

Propchange: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataResolution.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataResolution.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataResolutionException.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataResolutionException.java?rev=659899&view=auto
==============================================================================
--- maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataResolutionException.java (added)
+++ maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataResolutionException.java Sat May 24 20:07:02 2008
@@ -0,0 +1,31 @@
+package org.apache.maven.mercury.representation;
+
+public class MetadataResolutionException
+    extends Exception
+{
+
+    public MetadataResolutionException()
+    {
+        // TODO Auto-generated constructor stub
+    }
+
+    public MetadataResolutionException( String message )
+    {
+        super( message );
+        // TODO Auto-generated constructor stub
+    }
+
+    public MetadataResolutionException( Throwable cause )
+    {
+        super( cause );
+        // TODO Auto-generated constructor stub
+    }
+
+    public MetadataResolutionException( String message,
+                                        Throwable cause )
+    {
+        super( message, cause );
+        // TODO Auto-generated constructor stub
+    }
+
+}

Propchange: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataResolutionException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataResolutionException.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataResolutionRequest.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataResolutionRequest.java?rev=659899&view=auto
==============================================================================
--- maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataResolutionRequest.java (added)
+++ maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataResolutionRequest.java Sat May 24 20:07:02 2008
@@ -0,0 +1,62 @@
+package org.apache.maven.mercury.representation;
+
+import java.util.List;
+
+import org.apache.maven.mercury.ArtifactRepository;
+
+
+/** @author Oleg Gusakov */
+public class MetadataResolutionRequest
+{
+    protected ArtifactMetadata query;
+    protected ArtifactRepository localRepository;
+    protected List<ArtifactRepository> remoteRepositories;
+
+    //--------------------------------------------------------------------
+    public MetadataResolutionRequest()
+    {
+    }
+
+    //--------------------------------------------------------------------
+    public MetadataResolutionRequest( ArtifactMetadata query,
+                                      ArtifactRepository localRepository,
+                                      List<ArtifactRepository> remoteRepositories )
+    {
+        this.query = query;
+        this.localRepository = localRepository;
+        this.remoteRepositories = remoteRepositories;
+    }
+
+    //--------------------------------------------------------------------
+    public ArtifactMetadata getQuery()
+    {
+        return query;
+    }
+
+    public void setQuery( ArtifactMetadata query )
+    {
+        this.query = query;
+    }
+
+    public ArtifactRepository getLocalRepository()
+    {
+        return localRepository;
+    }
+
+    public void setLocalRepository( ArtifactRepository localRepository )
+    {
+        this.localRepository = localRepository;
+    }
+
+    public List<ArtifactRepository> getRemoteRepositories()
+    {
+        return remoteRepositories;
+    }
+
+    public void setRemoteRepositories( List<ArtifactRepository> remoteRepositories )
+    {
+        this.remoteRepositories = remoteRepositories;
+    }
+    //--------------------------------------------------------------------
+    //--------------------------------------------------------------------
+}

Propchange: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataResolutionRequest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataResolutionRequest.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataResolutionRequestTypeEnum.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataResolutionRequestTypeEnum.java?rev=659899&view=auto
==============================================================================
--- maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataResolutionRequestTypeEnum.java (added)
+++ maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataResolutionRequestTypeEnum.java Sat May 24 20:07:02 2008
@@ -0,0 +1,26 @@
+package org.apache.maven.mercury.representation;
+
+public enum MetadataResolutionRequestTypeEnum
+{
+      tree( 1 )
+    , graph( 2 )
+    , classpathCompile( 3 )
+    , classpathTest( 4 )
+    , classpathRuntime( 5 )
+    , versionedGraph( 6 )
+    , scopedGraph( 7 )
+    ;
+
+    private int id;
+
+    // Constructor
+    MetadataResolutionRequestTypeEnum( int id )
+    {
+        this.id = id;
+    }
+
+    int getId()
+    {
+        return id;
+    }
+}

Propchange: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataResolutionRequestTypeEnum.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataResolutionRequestTypeEnum.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataResolutionResult.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataResolutionResult.java?rev=659899&view=auto
==============================================================================
--- maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataResolutionResult.java (added)
+++ maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataResolutionResult.java Sat May 24 20:07:02 2008
@@ -0,0 +1,130 @@
+package org.apache.maven.mercury.representation;
+
+import org.apache.maven.mercury.ArtifactScopeEnum;
+import org.apache.maven.mercury.representation.conflict.ConflictResolutionException;
+import org.apache.maven.mercury.representation.conflict.ConflictResolver;
+import org.apache.maven.mercury.representation.transform.ClasspathContainer;
+import org.apache.maven.mercury.representation.transform.ClasspathTransformation;
+import org.apache.maven.mercury.representation.transform.MetadataGraphTransformationException;
+import org.codehaus.plexus.PlexusContainer;
+import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
+
+/** 
+ * This object is tinted with ClasspathTransformation and GraphConflictResolver. 
+ * Get rid of them after debugging
+ * 
+ * @author <a href="oleg@codehaus.org">Oleg Gusakov</a>
+ */
+public class MetadataResolutionResult
+{
+    MetadataTreeNode treeRoot;
+    
+    /** 
+     * these components are are initialized on demand by
+     * explicit call of the initTreeProcessing() 
+     */ 
+    ClasspathTransformation classpathTransformation;
+    ConflictResolver conflictResolver;
+
+    //----------------------------------------------------------------------------
+    public MetadataResolutionResult( )
+    {
+    }
+    //----------------------------------------------------------------------------
+    public MetadataResolutionResult( MetadataTreeNode root )
+    {
+        this.treeRoot = root;
+    }
+    //----------------------------------------------------------------------------
+    public MetadataTreeNode getTree()
+    {
+        return treeRoot;
+    }
+    //----------------------------------------------------------------------------
+    public void setTree( MetadataTreeNode root )
+    {
+        this.treeRoot = root;
+    }
+    
+    public void initTreeProcessing( PlexusContainer plexus )
+    throws ComponentLookupException
+    {
+        classpathTransformation = (ClasspathTransformation)plexus.lookup(ClasspathTransformation.class);
+        conflictResolver = (ConflictResolver)plexus.lookup(ConflictResolver.class);
+    }
+    //----------------------------------------------------------------------------
+    public MetadataGraph getGraph()
+    throws MetadataResolutionException
+    {
+        return treeRoot == null ? null : new MetadataGraph(treeRoot);
+    }
+    //----------------------------------------------------------------------------
+    public MetadataGraph getGraph( ArtifactScopeEnum scope )
+    throws MetadataResolutionException, ConflictResolutionException
+    {
+    	if( treeRoot == null )
+    		return null;
+    	
+    	if( conflictResolver == null )
+    		return null;
+    	
+        return conflictResolver.resolveConflicts( getGraph(), scope );
+    }
+    //----------------------------------------------------------------------------
+    public MetadataGraph getGraph( MetadataResolutionRequestTypeEnum requestType )
+    throws MetadataResolutionException, ConflictResolutionException
+    {
+    	if( requestType == null )
+    		return null;
+    	
+    	if( treeRoot == null )
+    		return null;
+    	
+    	if( conflictResolver == null )
+    		return null;
+    	
+    	if( requestType.equals(MetadataResolutionRequestTypeEnum.classpathCompile) )
+    		return conflictResolver.resolveConflicts( getGraph(), ArtifactScopeEnum.compile );
+    	else if( requestType.equals(MetadataResolutionRequestTypeEnum.classpathRuntime) )
+    		return conflictResolver.resolveConflicts( getGraph(), ArtifactScopeEnum.runtime );
+    	else if( requestType.equals(MetadataResolutionRequestTypeEnum.classpathRuntime) )
+    		return conflictResolver.resolveConflicts( getGraph(), ArtifactScopeEnum.test );
+    	else if( requestType.equals(MetadataResolutionRequestTypeEnum.classpathRuntime) )
+    		return conflictResolver.resolveConflicts( getGraph(), ArtifactScopeEnum.test );
+    	else if( requestType.equals(MetadataResolutionRequestTypeEnum.graph) )
+    		return getGraph();
+    	else if( requestType.equals(MetadataResolutionRequestTypeEnum.versionedGraph) ) {
+    		return new MetadataGraph( getTree(), true, false );
+    	}
+    	else if( requestType.equals(MetadataResolutionRequestTypeEnum.scopedGraph) ) {
+    		return new MetadataGraph( getTree(), true, true );
+    	}
+		return null;
+    }
+    //----------------------------------------------------------------------------
+    public ClasspathContainer getClasspath( ArtifactScopeEnum scope )
+    throws MetadataGraphTransformationException, MetadataResolutionException
+    {
+        if( classpathTransformation == null )
+        	return null;
+        
+        MetadataGraph dirtyGraph = getGraph();
+        if( dirtyGraph == null )
+        	return null;
+        
+        return classpathTransformation.transform( dirtyGraph, scope, false );
+    }
+    
+    //----------------------------------------------------------------------------
+    public MetadataTreeNode getClasspathTree( ArtifactScopeEnum scope )
+    throws MetadataGraphTransformationException, MetadataResolutionException
+    {
+        ClasspathContainer cpc = getClasspath(scope);
+        if( cpc == null )
+        	return null;
+        
+        return cpc.getClasspathAsTree();
+    }
+    //----------------------------------------------------------------------------
+    //----------------------------------------------------------------------------
+}

Propchange: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataResolutionResult.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataResolutionResult.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataResolver.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataResolver.java?rev=659899&view=auto
==============================================================================
--- maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataResolver.java (added)
+++ maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataResolver.java Sat May 24 20:07:02 2008
@@ -0,0 +1,22 @@
+package org.apache.maven.mercury.representation;
+
+/**
+ * entry point into metadata resolution component
+ * 
+ * @author Jason van Zyl
+ * @author Oleg Gusakov
+ */
+public interface MetadataResolver
+{
+    String ROLE = MetadataResolver.class.getName();
+
+    /**
+     * collect all dependency metadata into one "dirty" tree
+     * 
+     * @param request
+     * @return
+     * @throws MetadataResolutionException
+     */
+    MetadataResolutionResult resolveMetadata( MetadataResolutionRequest request )
+        throws MetadataResolutionException;
+}

Propchange: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataResolver.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataRetrievalException.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataRetrievalException.java?rev=659899&view=auto
==============================================================================
--- maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataRetrievalException.java (added)
+++ maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataRetrievalException.java Sat May 24 20:07:02 2008
@@ -0,0 +1,63 @@
+package org.apache.maven.mercury.representation;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Error while retrieving repository metadata from the repository.
+ *
+ * @author Jason van Zyl
+ * @version $Id$
+ */
+public class MetadataRetrievalException
+    extends Exception
+{
+
+    private ArtifactMetadata artifact;
+
+    public MetadataRetrievalException( String message )
+    {
+        this( message, null, null );
+    }
+
+    public MetadataRetrievalException( Throwable cause )
+    {
+        this( null, cause, null );
+    }
+
+    public MetadataRetrievalException( String message,
+                                       Throwable cause )
+    {
+        this( message, cause, null );
+    }
+
+    public MetadataRetrievalException( String message,
+                                       Throwable cause,
+                                       ArtifactMetadata artifact )
+    {
+        super( message, cause );
+
+        this.artifact = artifact;
+    }
+
+    public ArtifactMetadata getArtifactMetadata()
+    {
+        return artifact;
+    }
+}
\ No newline at end of file

Propchange: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataRetrievalException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataRetrievalException.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataSource.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataSource.java?rev=659899&view=auto
==============================================================================
--- maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataSource.java (added)
+++ maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataSource.java Sat May 24 20:07:02 2008
@@ -0,0 +1,41 @@
+package org.apache.maven.mercury.representation;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.List;
+
+import org.apache.maven.mercury.ArtifactRepository;
+
+/**
+ * Provides some metadata operations, like querying the remote repository for a list of versions available for an
+ * artifact.
+ *
+ * @author Jason van Zyl
+ * @version $Id$
+ */
+public interface MetadataSource
+{
+    String ROLE = MetadataSource.class.getName();
+
+    MetadataResolution retrieve( ArtifactMetadata artifact,
+                                 ArtifactRepository localRepository,
+                                 List<ArtifactRepository> remoteRepositories )
+        throws MetadataRetrievalException;
+}
\ No newline at end of file

Propchange: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataSource.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataSource.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataTreeNode.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataTreeNode.java?rev=659899&view=auto
==============================================================================
--- maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataTreeNode.java (added)
+++ maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataTreeNode.java Sat May 24 20:07:02 2008
@@ -0,0 +1,132 @@
+package org.apache.maven.mercury.representation;
+
+import org.apache.maven.mercury.Artifact;
+import org.apache.maven.mercury.ArtifactScopeEnum;
+/**
+ * metadata [dirty] Tree
+ * 
+ * @author <a href="oleg@codehaus.org">Oleg Gusakov</a>
+ *
+ */
+
+public class MetadataTreeNode
+{
+    ArtifactMetadata md; // this node
+
+    MetadataTreeNode parent; // papa
+
+    /** default # of children. Used for tree creation optimization only */
+    int nChildren = 8;
+
+    MetadataTreeNode[] children; // of cause
+
+    public int getNChildren()
+	{
+		return nChildren;
+	}
+
+	public void setNChildren(int children)
+	{
+		nChildren = children;
+	}
+
+	//------------------------------------------------------------------------
+    public MetadataTreeNode()
+    {
+    }
+    //------------------------------------------------------------------------
+    public MetadataTreeNode( ArtifactMetadata md,
+                             MetadataTreeNode parent,
+                             boolean resolved,
+                             ArtifactScopeEnum scope )
+    {
+        if ( md != null )
+        {
+            md.setArtifactScope( ArtifactScopeEnum.checkScope(scope) );
+            md.setResolved(resolved);
+        }
+
+        this.md = md;
+        this.parent = parent;
+    }
+    //------------------------------------------------------------------------
+    public MetadataTreeNode( Artifact af,
+                             MetadataTreeNode parent,
+                             boolean resolved,
+                             ArtifactScopeEnum scope
+                           )
+    {
+        this( new ArtifactMetadata( af ), parent, resolved, scope );
+    }
+    //------------------------------------------------------------------------
+    public void addChild( int index, MetadataTreeNode kid )
+    {
+        if ( kid == null )
+        {
+            return;
+        }
+
+        if( children == null )
+        	children = new MetadataTreeNode[nChildren];
+        
+        children[index % nChildren] = kid;
+    }
+    //------------------------------------------------------------------
+    @Override
+    public String toString()
+    {
+        return md == null ? "no metadata" : md.toString();
+    }
+    //------------------------------------------------------------------
+    public String graphHash()
+        throws MetadataResolutionException
+    {
+        if ( md == null )
+        {
+            throw new MetadataResolutionException( "treenode without metadata, parent: "
+                + ( parent == null ? "null" : parent.toString() )
+            );
+        }
+
+        return md.groupId + ":" + md.artifactId;
+    }
+
+    //------------------------------------------------------------------------
+    public boolean hasChildren()
+    {
+        return children != null;
+    }
+    //------------------------------------------------------------------------
+    public ArtifactMetadata getMd()
+    {
+        return md;
+    }
+
+    public void setMd( ArtifactMetadata md )
+    {
+        this.md = md;
+    }
+
+    public MetadataTreeNode getParent()
+    {
+        return parent;
+    }
+
+    public void setParent( MetadataTreeNode parent )
+    {
+        this.parent = parent;
+    }
+
+    public MetadataTreeNode[] getChildren()
+    {
+        return children;
+    }
+
+    public void setChildren( MetadataTreeNode[] children )
+    {
+        this.children = children;
+    }
+    //------------------------------------------------------------------------
+    //------------------------------------------------------------------------
+
+}

Propchange: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataTreeNode.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/MetadataTreeNode.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/conflict/ConflictResolutionException.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/conflict/ConflictResolutionException.java?rev=659899&view=auto
==============================================================================
--- maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/conflict/ConflictResolutionException.java (added)
+++ maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/conflict/ConflictResolutionException.java Sat May 24 20:07:02 2008
@@ -0,0 +1,32 @@
+package org.apache.maven.mercury.representation.conflict;
+
+/**
+ * 
+ * @author <a href="mailto:oleg@codehaus.org">Oleg Gusakov</a>
+ * 
+ * @version $Id$
+ */
+
+public class ConflictResolutionException
+extends Exception
+{
+	public ConflictResolutionException()
+	{
+	}
+
+	public ConflictResolutionException(String message)
+	{
+		super(message);
+	}
+
+	public ConflictResolutionException(Throwable cause)
+	{
+		super(cause);
+	}
+
+	public ConflictResolutionException(String message, Throwable cause)
+	{
+		super(message, cause);
+	}
+
+}

Propchange: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/conflict/ConflictResolutionException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/conflict/ConflictResolutionException.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/conflict/ConflictResolutionPolicy.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/conflict/ConflictResolutionPolicy.java?rev=659899&view=auto
==============================================================================
--- maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/conflict/ConflictResolutionPolicy.java (added)
+++ maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/conflict/ConflictResolutionPolicy.java Sat May 24 20:07:02 2008
@@ -0,0 +1,18 @@
+package org.apache.maven.mercury.representation.conflict;
+
+import org.apache.maven.mercury.representation.MetadataGraphEdge;
+
+/*
+ * MetadataGraph edge selection policy. Complements GraphConflictResolver by being injected into it
+ * 
+ * @author <a href="mailto:oleg@codehaus.org">Oleg Gusakov</a>
+ * 
+ * @version $Id$
+ */
+
+public interface ConflictResolutionPolicy
+{
+    static String ROLE = ConflictResolutionPolicy.class.getName();
+
+    public MetadataGraphEdge apply( MetadataGraphEdge e1, MetadataGraphEdge e2 );
+}

Propchange: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/conflict/ConflictResolutionPolicy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/conflict/ConflictResolutionPolicy.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/conflict/ConflictResolver.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/conflict/ConflictResolver.java?rev=659899&view=auto
==============================================================================
--- maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/conflict/ConflictResolver.java (added)
+++ maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/conflict/ConflictResolver.java Sat May 24 20:07:02 2008
@@ -0,0 +1,47 @@
+package org.apache.maven.mercury.representation.conflict;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License. You may obtain a
+ * copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+import org.apache.maven.mercury.ArtifactScopeEnum;
+import org.apache.maven.mercury.representation.MetadataGraph;
+
+/*
+ * Resolves conflicts in the supplied dependency graph. Different implementations will implement
+ * different conflict resolution policies.
+ * 
+ * @author <a href="mailto:oleg@codehaus.org">Oleg Gusakov</a>
+ * 
+ * @version $Id$
+ */
+public interface ConflictResolver
+{
+    static String ROLE = ConflictResolver.class.getName();
+
+    /**
+     * Cleanses the supplied graph by leaving only one directed versioned edge\
+     * between any two nodes, if multiple exists. Uses scope relationships, defined 
+     * in <code>ArtifactScopeEnum</code>
+     *
+     * @param graph the "dirty" graph to be simplified via conflict resolution
+     * @param scope scope for which the graph should be resolved
+     * 
+     * @return resulting "clean" graph for the specified scope
+     * 
+     * @since 3.0
+     */
+    MetadataGraph resolveConflicts( MetadataGraph graph, ArtifactScopeEnum scope )
+        throws ConflictResolutionException;
+}

Propchange: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/conflict/ConflictResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/conflict/ConflictResolver.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/conflict/DefaultConflictResolutionPolicy.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/conflict/DefaultConflictResolutionPolicy.java?rev=659899&view=auto
==============================================================================
--- maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/conflict/DefaultConflictResolutionPolicy.java (added)
+++ maven/sandbox/trunk/mercury/src/main/java/org/apache/maven/mercury/representation/conflict/DefaultConflictResolutionPolicy.java Sat May 24 20:07:02 2008
@@ -0,0 +1,59 @@
+package org.apache.maven.mercury.representation.conflict;
+
+import org.apache.maven.mercury.representation.MetadataGraphEdge;
+import org.apache.maven.mercury.representation.version.ArtifactVersion;
+import org.apache.maven.mercury.representation.version.DefaultArtifactVersion;
+
+/*
+ * 
+ * @plexus.component
+ * 
+ * @author <a href="mailto:oleg@codehaus.org">Oleg Gusakov</a>
+ * 
+ * @version $Id$
+ */
+
+public class DefaultConflictResolutionPolicy
+    implements ConflictResolutionPolicy
+{
+    /**
+     * artifact, closer to the entry point, is selected
+     * 
+     * @plexus.configuration default-value="true"
+     */
+    private boolean closerFirst = true;
+
+    /**
+     * newer artifact is selected
+     * 
+     * @plexus.configuration default-value="true"
+     */
+    private boolean newerFirst = true;
+
+    public MetadataGraphEdge apply( MetadataGraphEdge e1, MetadataGraphEdge e2 )
+    {
+        int depth1 = e1.getDepth();
+        int depth2 = e2.getDepth();
+
+        if ( depth1 == depth2 )
+        {
+            ArtifactVersion v1 = new DefaultArtifactVersion( e1.getVersion() );
+            ArtifactVersion v2 = new DefaultArtifactVersion( e2.getVersion() );
+
+            if ( newerFirst )
+            {
+                return v1.compareTo( v2 ) > 0 ? e1 : e2;
+            }
+
+            return v1.compareTo( v2 ) > 0 ? e2 : e1;
+        }
+
+        if ( closerFirst )
+        {
+            return depth1 < depth2 ? e1 : e2;
+        }
+
+        return depth1 < depth2 ? e2 : e1;
+    }
+
+}