geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r454266 - in /geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/dependency: Dependencies.java DependencyHelper.java DependencyResolutionListener.java DependencyTree.java ResolutionListenerAdapter.java
Date Mon, 09 Oct 2006 03:20:04 GMT
Author: jdillon
Date: Sun Oct  8 20:20:03 2006
New Revision: 454266

URL: http://svn.apache.org/viewvc?view=rev&rev=454266
Log:
Refactor the dependency stuff some more for easier use

Added:
    geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/dependency/DependencyTree.java
  (with props)
    geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/dependency/ResolutionListenerAdapter.java
  (with props)
Modified:
    geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/dependency/Dependencies.java
    geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/dependency/DependencyHelper.java
    geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/dependency/DependencyResolutionListener.java

Modified: geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/dependency/Dependencies.java
URL: http://svn.apache.org/viewvc/geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/dependency/Dependencies.java?view=diff&rev=454266&r1=454265&r2=454266
==============================================================================
--- geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/dependency/Dependencies.java
(original)
+++ geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/dependency/Dependencies.java
Sun Oct  8 20:20:03 2006
@@ -20,7 +20,6 @@
 package org.apache.geronimo.genesis.dependency;
 
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -28,15 +27,10 @@
 
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.ArtifactUtils;
-import org.apache.maven.artifact.factory.ArtifactFactory;
-import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
-import org.apache.maven.artifact.versioning.VersionRange;
-import org.apache.maven.model.Dependency;
-import org.apache.maven.model.DependencyManagement;
+
 import org.apache.maven.project.MavenProject;
-import org.apache.maven.project.ProjectBuildingException;
 
-import org.apache.geronimo.genesis.dependency.DependencyResolutionListener;
+import org.apache.geronimo.genesis.dependency.DependencyTree.Node;
 
 //
 // NOTE: Lifetd from the maven-project-info-plugin
@@ -53,66 +47,39 @@
 
     private DependencyResolutionListener resolvedDependencies;
 
-    public Dependencies(MavenProject project, DependencyResolutionListener listener) {
-        this.projectDependencies = listener.getRootNode().getChildren();
+    public Dependencies(final MavenProject project, final DependencyResolutionListener listener)
{
+        assert project != null;
+        assert listener != null;
+
+        this.projectDependencies = listener.getDependencyTree().getRootNode().getChildren();
         this.resolvedDependencies = listener;
 
         //
         // Workaround to ensure proper File objects in the Artifacts from the DependencyResolutionListener
         //
         Map projectMap = new HashMap();
-        Iterator it = project.getArtifacts().iterator();
-        while (it.hasNext()) {
-            Artifact artifact = (Artifact) it.next();
+        Iterator iter = project.getArtifacts().iterator();
+
+        while (iter.hasNext()) {
+            Artifact artifact = (Artifact) iter.next();
             projectMap.put(ArtifactUtils.versionlessKey(artifact), artifact);
         }
 
-        mapArtifactFiles(listener.getRootNode(), projectMap);
+        mapArtifactFiles(listener.getDependencyTree().getRootNode(), projectMap);
     }
 
-    public static Map getManagedVersionMap(MavenProject project, ArtifactFactory factory)
throws ProjectBuildingException {
-        DependencyManagement dependencyManagement = project.getDependencyManagement();
-        Map managedVersionMap;
-
-        if (dependencyManagement != null && dependencyManagement.getDependencies()
!= null) {
-            managedVersionMap = new HashMap();
-            for (Iterator i = dependencyManagement.getDependencies().iterator(); i.hasNext();)
{
-                Dependency d = (Dependency) i.next();
-
-                try {
-                    VersionRange versionRange = VersionRange.createFromVersionSpec(d.getVersion());
-                    Artifact artifact = factory.createDependencyArtifact(
-                            d.getGroupId(),
-                            d.getArtifactId(),
-                            versionRange,
-                            d.getType(),
-                            d.getClassifier(),
-                            d.getScope());
-                    managedVersionMap.put(d.getManagementKey(), artifact);
-                }
-                catch (InvalidVersionSpecificationException e) {
-                    throw new ProjectBuildingException(project.getId(),
-                            "Unable to parse version '" + d.getVersion() +
-                            "' for dependency '" + d.getManagementKey() + "': " + e.getMessage(),
e);
-                }
-            }
-        }
-        else {
-            managedVersionMap = Collections.EMPTY_MAP;
-        }
-
-        return managedVersionMap;
-    }
+    private void mapArtifactFiles(final Node node, final Map projectMap) {
+        assert node != null;
+        assert projectMap != null;
 
-    private void mapArtifactFiles(DependencyResolutionListener.Node node, Map projectMap)
{
         List childs = node.getChildren();
         if ((childs == null) || childs.isEmpty()) {
             return;
         }
 
-        Iterator it = childs.iterator();
-        while (it.hasNext()) {
-            DependencyResolutionListener.Node anode = (DependencyResolutionListener.Node)
it.next();
+        Iterator iter = childs.iterator();
+        while (iter.hasNext()) {
+            Node anode = (Node) iter.next();
             String key = ArtifactUtils.versionlessKey(anode.getArtifact());
             Artifact projartifact = (Artifact) projectMap.get(key);
             if (projartifact != null) {
@@ -140,8 +107,8 @@
     public List getAllDependencies() {
         List deps = new ArrayList();
 
-        for (Iterator it = resolvedDependencies.getArtifacts().iterator(); it.hasNext();)
{
-            DependencyResolutionListener.Node node = (DependencyResolutionListener.Node)
it.next();
+        for (Iterator iter = resolvedDependencies.getArtifacts().iterator(); iter.hasNext();)
{
+            Node node = (Node) iter.next();
             Artifact artifact = node.getArtifact();
             deps.add(artifact);
         }
@@ -163,7 +130,7 @@
         return dependenciesByScope;
     }
 
-    public DependencyResolutionListener.Node getResolvedRoot() {
-        return resolvedDependencies.getRootNode();
+    public Node getResolvedRoot() {
+        return resolvedDependencies.getDependencyTree().getRootNode();
     }
 }

Modified: geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/dependency/DependencyHelper.java
URL: http://svn.apache.org/viewvc/geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/dependency/DependencyHelper.java?view=diff&rev=454266&r1=454265&r2=454266
==============================================================================
--- geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/dependency/DependencyHelper.java
(original)
+++ geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/dependency/DependencyHelper.java
Sun Oct  8 20:20:03 2006
@@ -21,6 +21,8 @@
 
 import java.util.Map;
 import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
 
 import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
 import org.apache.maven.artifact.resolver.ArtifactCollector;
@@ -29,9 +31,14 @@
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
 import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.versioning.VersionRange;
+import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
+import org.apache.maven.artifact.Artifact;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.project.ProjectBuildingException;
 import org.apache.maven.project.artifact.InvalidDependencyVersionException;
+import org.apache.maven.model.DependencyManagement;
+import org.apache.maven.model.Dependency;
 
 import org.codehaus.plexus.PlexusContainer;
 import org.codehaus.plexus.PlexusConstants;
@@ -59,28 +66,29 @@
 
     private PlexusContainer container;
 
+    private ArtifactRepository repository;
+
     //
     // TODO: Figure out how to get ${localRepository} injected so we don't need it passed
in.
     //
 
-    /**
-     * ???
-     *
-     * @param project       The maven project
-     * @param repository    The local maven repository
-     * @return
-     * 
-     * @throws ProjectBuildingException
-     * @throws ArtifactResolutionException
-     * @throws InvalidDependencyVersionException
-     */
-    public DependencyResolutionListener resolveProject(final MavenProject project, final
ArtifactRepository repository)
-        throws ProjectBuildingException, ArtifactResolutionException, InvalidDependencyVersionException
+    public void setArtifactRepository(final ArtifactRepository repository) {
+        this.repository = repository;
+    }
+
+    private ArtifactRepository getArtifactRepository() {
+        if (repository == null) {
+            throw new IllegalStateException("Not initialized; missing ArtifactRepository");
+        }
+        return repository;
+    }
+
+    public DependencyTree getDependencies(final MavenProject project)
+        throws ProjectBuildingException, InvalidDependencyVersionException, ArtifactResolutionException
     {
         assert project != null;
-        assert repository != null;
-        
-        Map managedVersions = Dependencies.getManagedVersionMap(project, artifactFactory);
+
+        Map managedVersions = getManagedVersionMap(project, artifactFactory);
         DependencyResolutionListener listener = new DependencyResolutionListener();
 
         if (project.getDependencyArtifacts() == null) {
@@ -91,13 +99,52 @@
                 project.getDependencyArtifacts(),
                 project.getArtifact(),
                 managedVersions,
-                repository,
+                getArtifactRepository(),
                 project.getRemoteArtifactRepositories(),
                 artifactMetadataSource,
                 null,
                 Collections.singletonList(listener));
+        
+        return listener.getDependencyTree();
+    }
+
+    public static Map getManagedVersionMap(final MavenProject project, final ArtifactFactory
factory) throws ProjectBuildingException {
+        assert project != null;
+        assert factory != null;
+
+        DependencyManagement dependencyManagement = project.getDependencyManagement();
+        Map managedVersionMap;
+
+        if (dependencyManagement != null && dependencyManagement.getDependencies()
!= null) {
+            managedVersionMap = new HashMap();
+            Iterator iter = dependencyManagement.getDependencies().iterator();
+
+            while (iter.hasNext()) {
+                Dependency d = (Dependency) iter.next();
+
+                try {
+                    VersionRange versionRange = VersionRange.createFromVersionSpec(d.getVersion());
+                    Artifact artifact = factory.createDependencyArtifact(
+                            d.getGroupId(),
+                            d.getArtifactId(),
+                            versionRange,
+                            d.getType(),
+                            d.getClassifier(),
+                            d.getScope());
+                    managedVersionMap.put(d.getManagementKey(), artifact);
+                }
+                catch (InvalidVersionSpecificationException e) {
+                    throw new ProjectBuildingException(project.getId(),
+                            "Unable to parse version '" + d.getVersion() +
+                            "' for dependency '" + d.getManagementKey() + "': " + e.getMessage(),
e);
+                }
+            }
+        }
+        else {
+            managedVersionMap = Collections.EMPTY_MAP;
+        }
 
-        return listener;
+        return managedVersionMap;
     }
 
     //

Modified: geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/dependency/DependencyResolutionListener.java
URL: http://svn.apache.org/viewvc/geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/dependency/DependencyResolutionListener.java?view=diff&rev=454266&r1=454265&r2=454266
==============================================================================
--- geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/dependency/DependencyResolutionListener.java
(original)
+++ geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/dependency/DependencyResolutionListener.java
Sun Oct  8 20:20:03 2006
@@ -19,16 +19,14 @@
 
 package org.apache.geronimo.genesis.dependency;
 
-import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 import java.util.Stack;
 
 import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.resolver.ResolutionListener;
-import org.apache.maven.artifact.versioning.VersionRange;
+
+import org.apache.geronimo.genesis.dependency.DependencyTree.Node;
 
 //
 // NOTE: Lifetd from the maven-project-info-plugin
@@ -40,38 +38,46 @@
  * @version $Rev$ $Date$
  */
 public class DependencyResolutionListener
-    implements ResolutionListener
+    extends ResolutionListenerAdapter
 {
+    private DependencyTree tree = new DependencyTree();
+
+    private int currentDepth = 0;
+
     private Stack parents = new Stack();
 
     private Map artifacts = new HashMap();
 
-    private Node rootNode;
-
-    private int currentDepth = 0;
+    public DependencyTree getDependencyTree() {
+        return tree;
+    }
 
-    public void testArtifact(Artifact artifact) {
-        // intentionally blank
+    public Collection getArtifacts() {
+        return artifacts.values();
     }
+    
+    //
+    // ResolutionListener
+    //
 
-    public void startProcessChildren(Artifact artifact) {
+    public void startProcessChildren(final Artifact artifact) {
         Node node = (Node) artifacts.get(artifact.getDependencyConflictId());
 
         node.depth = currentDepth++;
         if (parents.isEmpty()) {
-            rootNode = node;
+            tree.rootNode = node;
         }
 
         parents.push(node);
     }
 
-    public void endProcessChildren(Artifact artifact) {
-        Node check = (Node) parents.pop();
-        assert artifact.equals(check.artifact);
+    public void endProcessChildren(final Artifact artifact) {
+        Node node = (Node) parents.pop();
+        assert artifact.equals(node.artifact);
         currentDepth--;
     }
 
-    public void omitForNearer(Artifact omitted, Artifact kept) {
+    public void omitForNearer(final Artifact omitted, final Artifact kept) {
         assert omitted.getDependencyConflictId().equals(kept.getDependencyConflictId());
 
         Node prev = (Node) artifacts.get(omitted.getDependencyConflictId());
@@ -85,11 +91,11 @@
         includeArtifact(kept);
     }
 
-    public void omitForCycle(Artifact artifact) {
+    public void omitForCycle(final Artifact artifact) {
         // intentionally blank
     }
 
-    public void includeArtifact(Artifact artifact) {
+    public void includeArtifact(final Artifact artifact) {
         if (artifacts.containsKey(artifact.getDependencyConflictId())) {
             Node prev = (Node) artifacts.get(artifact.getDependencyConflictId());
             if (prev.parent != null) {
@@ -108,13 +114,12 @@
         artifacts.put(artifact.getDependencyConflictId(), node);
     }
 
-    public void updateScope(Artifact artifact, String scope) {
+    public void updateScope(final Artifact artifact, final String scope) {
         Node node = (Node) artifacts.get(artifact.getDependencyConflictId());
-
         node.artifact.setScope(scope);
     }
 
-    public void manageArtifact(Artifact artifact, Artifact replacement) {
+    public void manageArtifact(final Artifact artifact, final Artifact replacement) {
         Node node = (Node) artifacts.get(artifact.getDependencyConflictId());
 
         if (node != null) {
@@ -125,48 +130,5 @@
                 node.artifact.setScope(replacement.getScope());
             }
         }
-    }
-
-    public void updateScopeCurrentPom(Artifact artifact, String key) {
-        // intentionally blank
-    }
-
-    public void selectVersionFromRange(Artifact artifact) {
-        // intentionally blank
-    }
-
-    public void restrictRange(Artifact artifact, Artifact artifact1, VersionRange versionRange)
{
-        // intentionally blank
-    }
-
-    public Collection getArtifacts() {
-        return artifacts.values();
-    }
-
-    public static class Node
-    {
-        private Node parent;
-
-        private List children = new ArrayList();
-
-        private Artifact artifact;
-
-        private int depth;
-
-        public List getChildren() {
-            return children;
-        }
-
-        public Artifact getArtifact() {
-            return artifact;
-        }
-
-        public int getDepth() {
-            return depth;
-        }
-    }
-
-    public Node getRootNode() {
-        return rootNode;
     }
 }

Added: geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/dependency/DependencyTree.java
URL: http://svn.apache.org/viewvc/geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/dependency/DependencyTree.java?view=auto&rev=454266
==============================================================================
--- geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/dependency/DependencyTree.java
(added)
+++ geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/dependency/DependencyTree.java
Sun Oct  8 20:20:03 2006
@@ -0,0 +1,76 @@
+/*
+ * 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.
+ */
+
+package org.apache.geronimo.genesis.dependency;
+
+import java.util.Stack;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Collection;
+import java.util.List;
+import java.util.ArrayList;
+
+import org.apache.maven.artifact.Artifact;
+
+/**
+ * ???
+ *
+ * @version $Rev$ $Date$
+ */
+public class DependencyTree
+{
+    Map artifacts = new HashMap();
+
+    Node rootNode;
+
+    public Collection getArtifacts() {
+        return artifacts.values();
+    }
+
+    public Node getRootNode() {
+        return rootNode;
+    }
+
+    //
+    // Node
+    //
+
+    public static class Node
+    {
+        Node parent;
+
+        List children = new ArrayList();
+
+        Artifact artifact;
+
+        int depth;
+
+        public List getChildren() {
+            return children;
+        }
+
+        public Artifact getArtifact() {
+            return artifact;
+        }
+
+        public int getDepth() {
+            return depth;
+        }
+    }
+}

Propchange: geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/dependency/DependencyTree.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/dependency/DependencyTree.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/dependency/DependencyTree.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/dependency/ResolutionListenerAdapter.java
URL: http://svn.apache.org/viewvc/geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/dependency/ResolutionListenerAdapter.java?view=auto&rev=454266
==============================================================================
--- geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/dependency/ResolutionListenerAdapter.java
(added)
+++ geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/dependency/ResolutionListenerAdapter.java
Sun Oct  8 20:20:03 2006
@@ -0,0 +1,77 @@
+/*
+ * 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.
+ */
+
+package org.apache.geronimo.genesis.dependency;
+
+import org.apache.maven.artifact.resolver.ResolutionListener;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.versioning.VersionRange;
+
+/**
+ * ???
+ *
+ * @version $Rev$ $Date$
+ */
+public class ResolutionListenerAdapter
+    implements ResolutionListener
+{
+    public void testArtifact(Artifact artifact) {
+        // empty
+    }
+
+    public void startProcessChildren(Artifact artifact) {
+        // empty
+    }
+
+    public void endProcessChildren(Artifact artifact) {
+        // empty
+    }
+
+    public void includeArtifact(Artifact artifact) {
+        // empty
+    }
+
+    public void omitForNearer(Artifact artifact, Artifact artifact1) {
+        // empty
+    }
+
+    public void updateScope(Artifact artifact, String string) {
+        // empty
+    }
+
+    public void manageArtifact(Artifact artifact, Artifact artifact1) {
+        // empty
+    }
+
+    public void omitForCycle(Artifact artifact) {
+        // empty
+    }
+
+    public void updateScopeCurrentPom(Artifact artifact, String string) {
+        // empty
+    }
+
+    public void selectVersionFromRange(Artifact artifact) {
+        // empty
+    }
+
+    public void restrictRange(Artifact artifact, Artifact artifact1, VersionRange versionRange)
{
+        // empty
+    }
+}

Propchange: geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/dependency/ResolutionListenerAdapter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/dependency/ResolutionListenerAdapter.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/genesis/trunk/plugins/plugin-support/src/main/java/org/apache/geronimo/genesis/dependency/ResolutionListenerAdapter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message