Author: jvanzyl
Date: Thu Nov 29 16:02:37 2007
New Revision: 599644

URL: http://svn.apache.org/viewvc?rev=599644&view=rev
Log:
o merging in oleg's latest artifact changes

Removed:
    
maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/metadata/MetadataGraphVertice.java
Modified:
    
maven/artifact/trunk/src/main/java/org/apache/maven/artifact/ArtifactScopeEnum.java
    
maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/metadata/ArtifactMetadata.java
    
maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/metadata/DefaultMetadataResolver.java
    
maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/metadata/MetadataGraph.java
    
maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/metadata/MetadataGraphEdge.java
    
maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/metadata/MetadataResolution.java
    
maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/metadata/MetadataResolutionRequestTypeEnum.java
    
maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/metadata/MetadataResolutionResult.java
    
maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/metadata/MetadataResolver.java
    
maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/metadata/MetadataTreeNode.java

Modified: 
maven/artifact/trunk/src/main/java/org/apache/maven/artifact/ArtifactScopeEnum.java
URL: 
http://svn.apache.org/viewvc/maven/artifact/trunk/src/main/java/org/apache/maven/artifact/ArtifactScopeEnum.java?rev=599644&r1=599643&r2=599644&view=diff
==============================================================================
--- 
maven/artifact/trunk/src/main/java/org/apache/maven/artifact/ArtifactScopeEnum.java
 (original)
+++ 
maven/artifact/trunk/src/main/java/org/apache/maven/artifact/ArtifactScopeEnum.java
 Thu Nov 29 16:02:37 2007
@@ -1,5 +1,13 @@
 package org.apache.maven.artifact;
 
+/**
+ * Type safe reincarnation of Artifact scope. Also supplies the 
<code>DEFAULT_SCOPE<code> as well
+ * as convenience method to deal with scope relationships.
+ * 
+ * @author <a href="[EMAIL PROTECTED]">Oleg Gusakov</a>
+ *
+ */
+
 public enum ArtifactScopeEnum
 {
     compile( 1 ), test( 2 ), runtime( 3 ), provided( 4 ), system( 5 );
@@ -19,6 +27,21 @@
         return id;
     }
 
+
+    /**
+     * Helper method to simplify null processing
+     * 
+     * @return 
+     */
+    public static final ArtifactScopeEnum checkScope( ArtifactScopeEnum scope )
+    {
+       return scope == null ? DEFAULT_SCOPE : scope;
+    }
+    
+    /**
+     * 
+     * @return unsafe String representation of this scope.
+     */
     public String getScope()
     {
         if ( id == 1 )
@@ -43,5 +66,39 @@
         {
             return Artifact.SCOPE_SYSTEM;
         }
+    }
+    
+    private static final ArtifactScopeEnum [][][] _compliancySets = {
+         { { compile  }, { compile, test, runtime, provided, system } }
+       , { { test     }, { compile, test,          provided, system } }
+       , { { runtime  }, { compile,       runtime,           system } }
+       , { { provided }, { compile, test,          provided         } }
+    };
+    
+    /**
+     * scope relationship function. Used by the graph conflict resolution 
policies
+     * 
+     * @param scope
+     * @return true is supplied scope is an inclusive sub-scope of current one.
+     */
+    public boolean encloses( ArtifactScopeEnum scope )
+    {
+       final ArtifactScopeEnum s = checkScope(scope);
+       
+       // system scope is historic only - and simple
+       if( id == system.id )
+               return scope.id == system.id;
+
+       
+       for( ArtifactScopeEnum[][] set : _compliancySets  ) {
+               if( id == set[0][0].id ) {
+                       for( ArtifactScopeEnum ase : set[1] ) {
+                               if( s.id == ase.id )
+                                       return true;
+                       }
+                       break;
+               }
+       }
+       return false;
     }
 }

Modified: 
maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/metadata/ArtifactMetadata.java
URL: 
http://svn.apache.org/viewvc/maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/metadata/ArtifactMetadata.java?rev=599644&r1=599643&r2=599644&view=diff
==============================================================================
--- 
maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/metadata/ArtifactMetadata.java
 (original)
+++ 
maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/metadata/ArtifactMetadata.java
 Thu Nov 29 16:02:37 2007
@@ -1,21 +1,78 @@
 package org.apache.maven.artifact.resolver.metadata;
 
+import java.util.Collection;
+
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.ArtifactScopeEnum;
 
-/** @author Oleg Gusakov */
+/**
+ * Artifact Metadata that is resolved independent of Artifact itself.
+ * 
+ * @author <a href="[EMAIL PROTECTED]">Oleg Gusakov</a>
+ *
+ */
 public class ArtifactMetadata
 {
+       /** 
+        * standard glorified artifact coordinates
+        */
     protected String groupId;
     protected String artifactId;
     protected String version;
     protected String type;
     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 name )
+    {
+       if( name == null )
+               return;
+       int ind1 = name.indexOf(':');
+       int ind2 = name.lastIndexOf(':');
+       
+       if( ind1 == -1 || ind2 == -1 )
+               return;
+       
+               this.groupId = name.substring(0, ind1);
+       if( ind1 == ind2 )
+       {
+               this.artifactId = name.substring(ind1+1);
+       }
+       else
+       {
+               this.artifactId = name.substring( ind1+1, ind2 );
+               this.version    = name.substring( ind2+1 );
+       }
+    }
+    
     //------------------------------------------------------------------
     public ArtifactMetadata( String groupId,
                              String name,
@@ -23,7 +80,6 @@
     {
         this( groupId, name, version, null );
     }
-
     //------------------------------------------------------------------
     public ArtifactMetadata( String groupId,
                              String name,
@@ -51,12 +107,43 @@
                              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;
     }
 
     //------------------------------------------------------------------
@@ -69,20 +156,19 @@
         }
         */
     }
-
     //------------------------------------------------------------------
-    public void init( ArtifactMetadata af )
-    {
-        setGroupId( af.getGroupId() );
-        setArtifactId( af.getArtifactId() );
-        setVersion( af.getVersion() );
-        setType( af.getType() );
-        setScope( af.getScope() );
-        setClassifier( af.getClassifier() );
-        //setUri( af.getDownloadUrl() );
-
-        this.resolved = af.isResolved();
-    }
+//    public void init( ArtifactMetadata af )
+//    {
+//        setGroupId( af.getGroupId() );
+//        setArtifactId( af.getArtifactId() );
+//        setVersion( af.getVersion() );
+//        setType( af.getType() );
+//        setScope( af.getScope() );
+//        setClassifier( af.getClassifier() );
+//        //setUri( af.getDownloadUrl() );
+//
+//        this.resolved = af.isResolved();
+//    }
 
     //------------------------------------------------------------------
     @Override
@@ -188,19 +274,72 @@
 
     public String getScope()
     {
-        if ( artifactScope == null )
-        {
-            return ArtifactScopeEnum.DEFAULT_SCOPE.getScope();
-        }
-
-        return artifactScope.getScope();
+        return getArtifactScope().getScope();
     }
 
-    public String getDependencyConflictId()
+    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;
     }
-
     //------------------------------------------------------------------
     //------------------------------------------------------------------
 }

Modified: 
maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/metadata/DefaultMetadataResolver.java
URL: 
http://svn.apache.org/viewvc/maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/metadata/DefaultMetadataResolver.java?rev=599644&r1=599643&r2=599644&view=diff
==============================================================================
--- 
maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/metadata/DefaultMetadataResolver.java
 (original)
+++ 
maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/metadata/DefaultMetadataResolver.java
 Thu Nov 29 16:02:37 2007
@@ -1,19 +1,30 @@
 package org.apache.maven.artifact.resolver.metadata;
 
 import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
 import java.util.Set;
 
 import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.ArtifactScopeEnum;
 import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
 import org.apache.maven.artifact.resolver.ArtifactResolutionException;
 import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
 import org.apache.maven.artifact.resolver.ArtifactResolver;
+import org.apache.maven.artifact.resolver.conflict.GraphConflictResolver;
+import org.apache.maven.artifact.transform.ClasspathTransformation;
 import org.codehaus.plexus.logging.AbstractLogEnabled;
 
+
 /**
- * @author Oleg Gusakov
+ * default implementation of the metadata resolver
+ * 
+ * @author <a href="[EMAIL PROTECTED]">Oleg Gusakov</a>
+ *
  * @plexus.component
+ *
  */
 public class DefaultMetadataResolver
     extends AbstractLogEnabled
@@ -30,6 +41,12 @@
     /** @plexus.requirement */
     MetadataSource metadataSource;
 
+    /** @plexus.requirement */
+    GraphConflictResolver conflictResolver;
+
+    /** @plexus.requirement */
+    ClasspathTransformation classpathTransformation;
+
     //------------------------------------------------------------------------
     public MetadataResolutionResult resolveMetadata( MetadataResolutionRequest 
req )
         throws MetadataResolutionException
@@ -38,30 +55,20 @@
         {
             getLogger().debug( "Received request for: " + req.getQuery() );
 
-            MetadataResolutionResult res = new MetadataResolutionResult();
+            MetadataResolutionResult res = new MetadataResolutionResult( 
conflictResolver, classpathTransformation);
 
             if ( req.type == null )
             {
                 throw new MetadataResolutionException( "no type in the 
request" );
             }
 
-            MetadataTreeNode tree = resolveTree( req, null );
-
-            MetadataGraph graph;
-
-            if ( MetadataResolutionRequestTypeEnum.tree.equals( req.type ) )
-            {
-                res.setTree( tree );
-            }
-            if ( MetadataResolutionRequestTypeEnum.graph.equals( req.type ) )
-            {
-                graph = new MetadataGraph( tree );
-
-                res.setTree( tree );
-
-                res.setGraph( graph );
-            }
+            MetadataTreeNode tree = resolveMetadataTree( req.getQuery()
+                                                                               
                , null
+                                                                               
                , req.getLocalRepository()
+                                                                               
                , req.getRemoteRepositories()
+                                                                               
                );
 
+            res.setTree( tree );
             return res;
         }
         catch ( MetadataResolutionException mrEx )
@@ -75,16 +82,18 @@
     }
 
     //------------------------------------------------------------------------
-    private MetadataTreeNode resolveTree( MetadataResolutionRequest req,
-                                          MetadataTreeNode parent )
+    private MetadataTreeNode resolveMetadataTree( ArtifactMetadata query
+                                                                               
        , MetadataTreeNode parent
+                                                                               
        , ArtifactRepository localRepository
+                                                                               
        , List<ArtifactRepository> remoteRepositories
+                                                                               
        )
         throws MetadataResolutionException
     {
         try
         {
-            ArtifactMetadata query = req.getQuery();
 
             Artifact pomArtifact = artifactFactory.createArtifact(
-                query.getGroupId()
+                  query.getGroupId()
                 , query.getArtifactId()
                 , query.getVersion()
                 , null
@@ -93,8 +102,8 @@
 
             getLogger().debug( "resolveMetadata request:"
                 + "\n> artifact   : " + pomArtifact.toString()
-                + "\n> remoteRepos: " + req.getRemoteRepositories()
-                + "\n> localRepo  : " + req.getLocalRepository()
+                + "\n> remoteRepos: " + remoteRepositories
+                + "\n> localRepo  : " + localRepository
             );
 
             String error = null;
@@ -102,28 +111,25 @@
             try
             {
                 ArtifactResolutionRequest arr = new 
ArtifactResolutionRequest();
-
                 arr.setArtifact( pomArtifact );
+                arr.setLocalRepository( localRepository );
+                arr.setRemoteRepostories( remoteRepositories );
 
-                arr.setLocalRepository( req.getLocalRepository() );
-
-                arr.setRemoteRepostories( req.getRemoteRepositories() );
-
-                artifactResolver.resolve( pomArtifact, 
req.getRemoteRepositories() , req.getLocalRepository() );
+                artifactResolver.resolve( pomArtifact, remoteRepositories , 
localRepository );
+//System.out.println("Resolved "+query+" : "+pomArtifact.isResolved() );
 
                 if ( !pomArtifact.isResolved() )
                 {
                     getLogger().info( "*************> Did not resolve " + 
pomArtifact.toString()
                         + "\nURL: " + pomArtifact.getDownloadUrl()
-                        + "\nRepos: " + req.getRemoteRepositories()
-                        + "\nLocal: " + req.getLocalRepository()
+                        + "\nRepos: " + remoteRepositories
+                        + "\nLocal: " + localRepository
                     );
                 }
             }
             catch ( ArtifactResolutionException are )
             {
                 pomArtifact.setResolved( false );
-
                 error = are.getMessage();
             }
             catch ( ArtifactNotFoundException anfe )
@@ -132,45 +138,62 @@
                 error = anfe.getMessage();
             }
 
-            if ( error != null )
+            if( error != null )
             {
                 getLogger().info( "*************> Did not resolve " + 
pomArtifact.toString()
-                    + "\nRepos: " + req.getRemoteRepositories()
-                    + "\nLocal: " + req.getLocalRepository()
+                    + "\nRepos: " + remoteRepositories
+                    + "\nLocal: " + localRepository
                     + "\nerror: " + error
                 );
             }
 
-            if ( pomArtifact.isResolved() )
+            if( pomArtifact.isResolved() )
             {
-                MetadataResolution metadataResolution = 
metadataSource.retrieve( query, req.getLocalRepository(), 
req.getRemoteRepositories() );
-
-                MetadataTreeNode node = new MetadataTreeNode( pomArtifact, 
parent, true, query.getArtifactScope() );
-
-                Set<ArtifactMetadata> dependencies = 
metadataResolution.getDependencies();
+                MetadataResolution metadataResolution = 
metadataSource.retrieve( 
+                                                                               
                                                                query
+                                                                               
                                                                , 
localRepository
+                                                                               
                                                                , 
remoteRepositories
+                                                                               
                                                                );
+                ArtifactMetadata found = 
metadataResolution.getArtifactMetadata();
+                
+                // TODO 
+                // Oleg: this is a shortcut to get AMd artifact location URI
+                // it is only valid because artifact (A) resolution is done 
BEFORE 
+                // Md resolution. 
+                //
+                // Should be done inside Md Source instead
+                //
+                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 )
+                if( dependencies != null && dependencies.size() > 0 )
                 {
-                    ArrayList<MetadataTreeNode> kids = new 
ArrayList<MetadataTreeNode>( dependencies.size() );
-
+                       int nKids = dependencies.size();
+                       node.setNChildren(nKids);
+                       int kidNo = 0;
                     for ( ArtifactMetadata a : dependencies )
                     {
-                        req.query.init( a );
-
-                        req.query.setType( "pom" );
-
-                        kids.add( resolveTree( req, node ) );
+                        MetadataTreeNode kidNode = resolveMetadataTree( a
+                                                                               
                                , node
+                                                                               
                                , localRepository
+                                                                               
                                , remoteRepositories
+                                                                               
                                );
+                        node.addChild( kidNo++, kidNode );
                     }
-                    node.addChildren( kids );
                 }
                 return node;
-            }
-            else
-            {
+            } else {
                 return new MetadataTreeNode( pomArtifact, parent, false, 
query.getArtifactScope() );
             }
         }
-        catch ( Exception anyEx )
+        catch( Exception anyEx )
         {
             throw new MetadataResolutionException( anyEx );
         }

Modified: 
maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/metadata/MetadataGraph.java
URL: 
http://svn.apache.org/viewvc/maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/metadata/MetadataGraph.java?rev=599644&r1=599643&r2=599644&view=diff
==============================================================================
--- 
maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/metadata/MetadataGraph.java
 (original)
+++ 
maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/metadata/MetadataGraph.java
 Thu Nov 29 16:02:37 2007
@@ -5,17 +5,61 @@
 import java.util.List;
 import java.util.Map;
 
-/** @author Oleg Gusakov */
+import org.apache.maven.artifact.ArtifactScopeEnum;
+
+/**
+ * maven dependency metadata graph
+ * 
+ * @author <a href="[EMAIL PROTECTED]">Oleg Gusakov</a>
+ *
+ */
 
 public class MetadataGraph
 {
-    MetadataGraphVertice entry;
-    Map<String, MetadataGraphVertice> vertices;
+       public static char DEFAULT_DOMAIN_SEPARATOR = '>';
+       /**
+        * the entry point we started building the graph from
+        */
+    MetadataGraphVertex entry;
+    
+    Map<String, MetadataGraphVertex> vertices;
     Map<String, List<MetadataGraphEdge>> edges;
+    
+    /**
+     *  null in dirty graph, actual scope for transformed graph
+     */
+    ArtifactScopeEnum scope;
 
     //------------------------------------------------------------------------
+    /**
+     * construct graph from a "dirty" tree
+     */
+    public MetadataGraph( int nVertices, int nEdges )
+    throws MetadataResolutionException
+    {
+       edges = new HashMap<String, List<MetadataGraphEdge>>( nEdges );
+       vertices = new HashMap<String, MetadataGraphVertex>( nVertices );
+    }
+    //------------------------------------------------------------------------
+    /**
+     * construct a single vertice
+     */
+    public MetadataGraph( MetadataGraphVertex entry )
+    throws MetadataResolutionException
+    {
+       if( entry == null || entry.getMd() == null )
+               throw new MetadataResolutionException("cannot create a 
MetadataGraph out of empty vertice");
+       vertices = new HashMap<String, MetadataGraphVertex>( 1 );
+       vertices.put( entry.getMd().toDomainString(), entry );
+       
+       this.entry = entry;
+    }
+    //------------------------------------------------------------------------
+    /**
+     * construct graph from a "dirty" tree
+     */
     public MetadataGraph( MetadataTreeNode tree )
-        throws MetadataResolutionException
+    throws MetadataResolutionException
     {
         if ( tree == null )
         {
@@ -23,17 +67,19 @@
         }
 
         int count = countNodes( tree );
-        vertices = new HashMap<String, MetadataGraphVertice>( count );
+        vertices = new HashMap<String, MetadataGraphVertex>( count );
         edges = new HashMap<String, List<MetadataGraphEdge>>( count + ( count 
/ 2 ) );
 
-        processNodes( null, tree, 0 );
+        processNodes( null, tree, 0, 0 );
     }
 
     //------------------------------------------------------------------------
-    private void processNodes( MetadataGraphVertice parentVertice,
-                               MetadataTreeNode node,
-                               int depth )
-        throws MetadataResolutionException
+    private void processNodes(   MetadataGraphVertex parentVertice
+                               , MetadataTreeNode node
+                               , int depth
+                               , int pomOrder
+                                               )
+    throws MetadataResolutionException
     {
         if ( node == null )
         {
@@ -41,15 +87,15 @@
         }
 
         String nodeHash = node.graphHash();
-        MetadataGraphVertice vertice = vertices.get( nodeHash );
+        MetadataGraphVertex vertice = vertices.get( nodeHash );
         if ( vertice == null )
         { // does not exist yet ?
-            vertice = new MetadataGraphVertice( node.md );
+            vertice = new MetadataGraphVertex( node.md );
             vertices.put( nodeHash, vertice );
         }
 
         if ( parentVertice != null )
-        { // then create links
+        { // then create edges
             String edgeId = edgeHash( parentVertice, vertice );
             List<MetadataGraphEdge> edgeList = edges.get( edgeId );
             if ( edgeList == null )
@@ -58,9 +104,12 @@
                 edges.put( edgeId, edgeList );
             }
 
-            MetadataGraphEdge e = new MetadataGraphEdge( node.md.version, 
node.md.artifactScope, depth );
+            ArtifactMetadata md = node.getMd();
+            MetadataGraphEdge e = new MetadataGraphEdge( md.version, 
md.resolved, md.artifactScope, md.artifactUri, depth, pomOrder );
             if ( !edgeList.contains( e ) )
             {
+               e.setSource( parentVertice.getMd() );
+               e.setTarget( md );
                 edgeList.add( e );
             }
             else
@@ -68,6 +117,10 @@
                 e = null;
             }
         }
+        else
+        {
+               entry = vertice;
+        }
 
         MetadataTreeNode[] kids = node.getChildren();
         if ( kids == null || kids.length < 1 )
@@ -75,17 +128,18 @@
             return;
         }
 
-        for ( MetadataTreeNode n : kids )
+        for( int i = 0; i< kids.length; i++ )
         {
-            processNodes( vertice, n, depth + 1 );
+               MetadataTreeNode n = kids[i];
+            processNodes( vertice, n, depth + 1, i );
         }
     }
 
     //------------------------------------------------------------------------
-    public static String edgeHash( MetadataGraphVertice v1,
-                                   MetadataGraphVertice v2 )
+    public static String edgeHash( MetadataGraphVertex v1,
+                                   MetadataGraphVertex v2 )
     {
-        return v1.md.toDomainString() + ">" + v2.md.toDomainString();
+        return v1.md.toDomainString() + DEFAULT_DOMAIN_SEPARATOR + 
v2.md.toDomainString();
 //             return h1.compareTo(h2) > 0
 //                             ? h1.hashCode()+""+h2.hashCode()
 //                             : h2.hashCode()+""+h1.hashCode()
@@ -93,6 +147,38 @@
     }
 
     //------------------------------------------------------------------------
+    public MetadataGraph addVertice( MetadataGraphVertex v )
+    {
+       if( v == null || v.getMd() == null )
+               return this;
+   
+       if( vertices == null )
+               vertices = new HashMap<String, MetadataGraphVertex>();
+       vertices.put(v.getMd().toDomainString(), v );
+       
+       return this;
+    }
+    //------------------------------------------------------------------------
+    public MetadataGraph addEdge( String key, MetadataGraphEdge e )
+    {
+       if( e == null )
+               return this;
+   
+       if( edges == null )
+               edges = new HashMap<String, List<MetadataGraphEdge>>();
+       
+       List<MetadataGraphEdge> eList = edges.get(key);
+       if( eList == null ) {
+               eList = new ArrayList<MetadataGraphEdge>();
+               edges.put( key, eList );
+       }
+       
+       if( ! eList.contains(e) )
+               eList.add(e);
+       
+       return this;
+    }
+    //------------------------------------------------------------------------
     private static int countNodes( MetadataTreeNode tree )
     {
         if ( tree == null )
@@ -115,22 +201,22 @@
     }
 
     //------------------------------------------------------------------------
-    public MetadataGraphVertice getEntry()
+    public MetadataGraphVertex getEntry()
     {
         return entry;
     }
 
-    public void setEntry( MetadataGraphVertice entry )
+    public void setEntry( MetadataGraphVertex entry )
     {
         this.entry = entry;
     }
 
-    public Map<String, MetadataGraphVertice> getVertices()
+    public Map<String, MetadataGraphVertex> getVertices()
     {
         return vertices;
     }
 
-    public void setVertices( Map<String, MetadataGraphVertice> vertices )
+    public void setVertices( Map<String, MetadataGraphVertex> vertices )
     {
         this.vertices = vertices;
     }
@@ -144,6 +230,32 @@
     {
         this.edges = edges;
     }
+       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()
+                       || edges == null
+                       || edges.isEmpty()
+               ;
+       }
     //------------------------------------------------------------------------
     //------------------------------------------------------------------------
 }

Modified: 
maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/metadata/MetadataGraphEdge.java
URL: 
http://svn.apache.org/viewvc/maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/metadata/MetadataGraphEdge.java?rev=599644&r1=599643&r2=599644&view=diff
==============================================================================
--- 
maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/metadata/MetadataGraphEdge.java
 (original)
+++ 
maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/metadata/MetadataGraphEdge.java
 Thu Nov 29 16:02:37 2007
@@ -2,24 +2,54 @@
 
 import org.apache.maven.artifact.ArtifactScopeEnum;
 
-/** @author Oleg Gusakov */
+
+/**
+ * metadata graph edge - combination of version, scope and depth define 
+ * an edge in the graph
+ * 
+ * @author <a href="[EMAIL PROTECTED]">Oleg Gusakov</a>
+ *
+ */
+
 public class MetadataGraphEdge
 {
-    String version;
+    String            version;
     ArtifactScopeEnum scope;
-    int depth = -1;
+    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
+     */
+    ArtifactMetadata  source;
+    ArtifactMetadata  target;
 
-    public MetadataGraphEdge( String version,
-                              ArtifactScopeEnum scope,
-                              int depth )
+    
//----------------------------------------------------------------------------
+    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 )
     {
@@ -37,6 +67,9 @@
     }
 
     
//----------------------------------------------------------------------------
+    /**
+     * used to eliminate exact duplicates in the edge list
+     */
     @Override
     public boolean equals( Object o )
     {
@@ -45,8 +78,10 @@
             MetadataGraphEdge e = (MetadataGraphEdge) o;
             return
                 objectsEqual( version, e.version )
-                    && objectsEqual( scope, e.scope )
-                    && depth == e.depth
+                && ArtifactScopeEnum.checkScope(scope).getScope().equals( 
+                               ArtifactScopeEnum.checkScope(e.scope).getScope()
+                                                                               
                                                )
+                && depth == e.depth
                 ;
         }
         return false;
@@ -82,6 +117,57 @@
     {
         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 ArtifactMetadata getSource()
+       {
+               return source;
+       }
+       public void setSource(ArtifactMetadata source)
+       {
+               this.source = source;
+       }
+       public ArtifactMetadata getTarget()
+       {
+               return target;
+       }
+       public void setTarget(ArtifactMetadata target)
+       {
+               this.target = target;
+       }
+       @Override
+       public String toString()
+       {
+               return "[version="+version+", scope="+(scope == null ? "null" : 
scope.getScope())+", depth="+depth+"]";
+       }
     
//----------------------------------------------------------------------------
     
//----------------------------------------------------------------------------
 }

Modified: 
maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/metadata/MetadataResolution.java
URL: 
http://svn.apache.org/viewvc/maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/metadata/MetadataResolution.java?rev=599644&r1=599643&r2=599644&view=diff
==============================================================================
--- 
maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/metadata/MetadataResolution.java
 (original)
+++ 
maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/metadata/MetadataResolution.java
 Thu Nov 29 16:02:37 2007
@@ -1,27 +1,54 @@
 package org.apache.maven.artifact.resolver.metadata;
 
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.repository.ArtifactRepository;
+import java.util.Collection;
 
-import java.util.Set;
+import org.apache.maven.artifact.repository.ArtifactRepository;
 
-/** @author Jason van Zyl */
+/**
+ * 
+ * @author Jason van Zyl
+ *  
+ */
 public class MetadataResolution
 {
-    private Set<ArtifactMetadata> dependencies;
+    /** resolved MD  */
+    private ArtifactMetadata artifactMetadata;
 
-    private Set<ArtifactRepository> metadataRepositories;
-
-    public MetadataResolution( Set<ArtifactMetadata> dependencies,
-                               Set<ArtifactRepository> metadataRepositories )
+    /** repositories, added by this POM  */
+    private Collection<ArtifactRepository> metadataRepositories;
+    //-------------------------------------------------------------------
+    public MetadataResolution( ArtifactMetadata artifactMetadata )
     {
-        this.dependencies = dependencies;
-
-        this.metadataRepositories = metadataRepositories;
+        this.artifactMetadata = artifactMetadata;
     }
-
-    public Set<ArtifactMetadata> getDependencies()
+    //-------------------------------------------------------------------
+    public MetadataResolution( ArtifactMetadata artifactMetadata,
+               Collection<ArtifactRepository> metadataRepositories )
     {
-        return dependencies;
+       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;
+       }
+    //-------------------------------------------------------------------
+    //-------------------------------------------------------------------
 }

Modified: 
maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/metadata/MetadataResolutionRequestTypeEnum.java
URL: 
http://svn.apache.org/viewvc/maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/metadata/MetadataResolutionRequestTypeEnum.java?rev=599644&r1=599643&r2=599644&view=diff
==============================================================================
--- 
maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/metadata/MetadataResolutionRequestTypeEnum.java
 (original)
+++ 
maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/metadata/MetadataResolutionRequestTypeEnum.java
 Thu Nov 29 16:02:37 2007
@@ -2,7 +2,7 @@
 
 public enum MetadataResolutionRequestTypeEnum
 {
-    tree( 1 ), graph( 2 ), noConflictGraph( 3 ), subGraph( 4 );
+    tree( 1 ), graph( 2 ), classpathCompile( 3 ), classpathTest( 4 ), 
classpathRuntime( 5 );
 
     private int id;
 

Modified: 
maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/metadata/MetadataResolutionResult.java
URL: 
http://svn.apache.org/viewvc/maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/metadata/MetadataResolutionResult.java?rev=599644&r1=599643&r2=599644&view=diff
==============================================================================
--- 
maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/metadata/MetadataResolutionResult.java
 (original)
+++ 
maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/metadata/MetadataResolutionResult.java
 Thu Nov 29 16:02:37 2007
@@ -1,45 +1,93 @@
 package org.apache.maven.artifact.resolver.metadata;
 
-import org.apache.maven.artifact.Artifact;
-
-/** @author Oleg Gusakov */
+import org.apache.maven.artifact.ArtifactScopeEnum;
+import 
org.apache.maven.artifact.resolver.conflict.GraphConflictResolutionException;
+import org.apache.maven.artifact.resolver.conflict.GraphConflictResolver;
+import org.apache.maven.artifact.transform.ClasspathContainer;
+import org.apache.maven.artifact.transform.ClasspathTransformation;
+import 
org.apache.maven.artifact.transform.MetadataGraphTransformationException;
+
+/** 
+ * This object is tinted with ClasspathTransformation and 
GraphConflictResolver. 
+ * Get rid of them after debugging
+ * 
+ * @author <a href="[EMAIL PROTECTED]">Oleg Gusakov</a>
+ */
 public class MetadataResolutionResult
 {
-    MetadataTreeNode root;
-    MetadataGraph graph;
+    MetadataTreeNode treeRoot;
+    ClasspathTransformation classpathTransformation;
+    GraphConflictResolver conflictResolver;
 
     
//----------------------------------------------------------------------------
     public MetadataResolutionResult()
     {
     }
-
     
//----------------------------------------------------------------------------
     public MetadataResolutionResult( MetadataTreeNode root )
     {
-        this.root = root;
+        this.treeRoot = root;
+    }
+    
//----------------------------------------------------------------------------
+    public MetadataResolutionResult( GraphConflictResolver conflictResolver, 
ClasspathTransformation cpt )
+    {
+        this.classpathTransformation = cpt;
+        this.conflictResolver = conflictResolver;
     }
-
     
//----------------------------------------------------------------------------
     public MetadataTreeNode getTree()
     {
-        return root;
+        return treeRoot;
     }
 
     public void setTree( MetadataTreeNode root )
     {
-        this.root = root;
+        this.treeRoot = root;
     }
 
+    
//----------------------------------------------------------------------------
     public MetadataGraph getGraph()
+    throws MetadataResolutionException
     {
-        return graph;
+        return treeRoot == null ? null : new MetadataGraph(treeRoot);
     }
-
-    public void setGraph( MetadataGraph graph )
+    
//----------------------------------------------------------------------------
+    public MetadataGraph getGraph( ArtifactScopeEnum scope )
+    throws MetadataResolutionException, GraphConflictResolutionException
     {
-        this.graph = graph;
+       if( treeRoot == null )
+               return null;
+       
+       if( conflictResolver == null )
+               return null;
+       
+        return conflictResolver.resolveConflicts( getGraph(), scope );
+    }
+    
//----------------------------------------------------------------------------
+    public ClasspathContainer getClasspath( ArtifactScopeEnum scope )
+    throws MetadataGraphTransformationException, MetadataResolutionException
+    {
+        if( classpathTransformation == null )
+               return null;
+        
+        MetadataGraph dirtyGraph = getGraph();
+        if( dirtyGraph == null )
+               return null;
+        
+        ClasspathContainer cpc = classpathTransformation.transform( 
dirtyGraph, scope, false );
+        
+        return cpc;
+    }
+
+    public MetadataTreeNode getClasspathTree( ArtifactScopeEnum scope )
+    throws MetadataGraphTransformationException, MetadataResolutionException
+    {
+        ClasspathContainer cpc = getClasspath(scope);
+        if( cpc == null )
+               return null;
+        
+        return cpc.getClasspathAsTree();
     }
-
     
//----------------------------------------------------------------------------
     
//----------------------------------------------------------------------------
 }

Modified: 
maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/metadata/MetadataResolver.java
URL: 
http://svn.apache.org/viewvc/maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/metadata/MetadataResolver.java?rev=599644&r1=599643&r2=599644&view=diff
==============================================================================
--- 
maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/metadata/MetadataResolver.java
 (original)
+++ 
maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/metadata/MetadataResolver.java
 Thu Nov 29 16:02:37 2007
@@ -1,10 +1,23 @@
 package org.apache.maven.artifact.resolver.metadata;
 
-/** @author Oleg Gusakov */
+
+/**
+ * entry point into metadata resolution component
+ * 
+ * @author <a href="[EMAIL PROTECTED]">Oleg Gusakov</a>
+ *
+ */
 public interface MetadataResolver
 {
     String ROLE = MetadataResolver.class.getName();
 
+    /**
+     * collect all dependency metadata into one "dirty" graph
+     * 
+     * @param request
+     * @return
+     * @throws MetadataResolutionException
+     */
     MetadataResolutionResult resolveMetadata( MetadataResolutionRequest 
request )
         throws MetadataResolutionException;
 }

Modified: 
maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/metadata/MetadataTreeNode.java
URL: 
http://svn.apache.org/viewvc/maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/metadata/MetadataTreeNode.java?rev=599644&r1=599643&r2=599644&view=diff
==============================================================================
--- 
maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/metadata/MetadataTreeNode.java
 (original)
+++ 
maven/artifact/trunk/src/main/java/org/apache/maven/artifact/resolver/metadata/MetadataTreeNode.java
 Thu Nov 29 16:02:37 2007
@@ -8,18 +8,27 @@
 public class MetadataTreeNode
 {
     ArtifactMetadata md; // this node
-
     MetadataTreeNode parent; // papa of cause
 
+    /** default # of children. Used for tree creation optimization only */
+    int nChildren = 8;
+
     MetadataTreeNode[] children; // of cause
 
-    boolean resolved = false; // if current node was resolved
+    public int getNChildren()
+       {
+               return nChildren;
+       }
+
+       public void setNChildren(int children)
+       {
+               nChildren = children;
+       }
 
-    //------------------------------------------------------------------------
+       
//------------------------------------------------------------------------
     public MetadataTreeNode()
     {
     }
-
     //------------------------------------------------------------------------
     public MetadataTreeNode( ArtifactMetadata md,
                              MetadataTreeNode parent,
@@ -29,13 +38,12 @@
         if ( md != null )
         {
             md.setArtifactScope( scope );
+            md.setResolved(resolved);
         }
 
         this.md = md;
         this.parent = parent;
-        this.resolved = resolved;
     }
-
     //------------------------------------------------------------------------
     public MetadataTreeNode( Artifact af,
                              MetadataTreeNode parent,
@@ -44,21 +52,18 @@
     {
         this( new ArtifactMetadata( af ), parent, resolved, scope );
     }
-
     //------------------------------------------------------------------------
-    public void addChildren( List<MetadataTreeNode> kidList )
+    public void addChild( int index, MetadataTreeNode kid )
     {
-        if ( kidList == null || kidList.size() < 1 )
+        if ( kid == null )
         {
             return;
         }
 
-        children = new MetadataTreeNode[kidList.size()];
-        int i = 0;
-        for ( MetadataTreeNode n : kidList )
-        {
-            children[i++] = n;
-        }
+        if( children == null )
+               children = new MetadataTreeNode[nChildren];
+        
+        children[index % nChildren] = kid;
     }
 
     //------------------------------------------------------------------
@@ -67,7 +72,6 @@
     {
         return md == null ? "no metadata" : md.toString();
     }
-
     //------------------------------------------------------------------
     public String graphHash()
         throws MetadataResolutionException
@@ -107,16 +111,6 @@
     public void setParent( MetadataTreeNode parent )
     {
         this.parent = parent;
-    }
-
-    public boolean isResolved()
-    {
-        return resolved;
-    }
-
-    public void setResolved( boolean resolved )
-    {
-        this.resolved = resolved;
     }
 
     public MetadataTreeNode[] getChildren()


Reply via email to