geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r656537 - in /geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car: AbstractCarMojo.java DependencyListener.java PlanProcessorMojo.java ProjectNode.java
Date Thu, 15 May 2008 08:11:10 GMT
Author: djencks
Date: Thu May 15 01:11:09 2008
New Revision: 656537

URL: http://svn.apache.org/viewvc?rev=656537&view=rev
Log:
GERONIMO-4013 Follow entire dependency tree (not the pruned one maven cooks up) to rely on
dependencies from car ancestors in prefernce to direct dependencies

Added:
    geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/DependencyListener.java
  (with props)
    geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/ProjectNode.java
  (with props)
Modified:
    geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/AbstractCarMojo.java
    geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/PlanProcessorMojo.java

Modified: geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/AbstractCarMojo.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/AbstractCarMojo.java?rev=656537&r1=656536&r2=656537&view=diff
==============================================================================
--- geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/AbstractCarMojo.java
(original)
+++ geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/AbstractCarMojo.java
Thu May 15 01:11:09 2008
@@ -29,8 +29,10 @@
 import java.util.Properties;
 import java.util.Set;
 import java.util.Collections;
+import java.util.HashMap;
 
 import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.handler.DefaultArtifactHandler;
 import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.resolver.ArtifactResolutionException;
 import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
@@ -95,7 +97,9 @@
      * @readonly
      */
     protected ArtifactFactory artifactFactory;
-    protected Set<Artifact> dependencies;// = new DependencyTree();
+    protected Set<Artifact> dependencies;
+    protected Map<Artifact, Artifact> dependencyMap = new HashMap<Artifact, Artifact>();
+    protected ProjectNode projectNode;
 
     //
     // MojoSupport Hooks
@@ -234,6 +238,8 @@
             project.setDependencyArtifacts(project.createArtifacts(artifactFactory, null,
null));
         }
 
+        DependencyListener listener = new DependencyListener();
+
         ArtifactResolutionResult artifactResolutionResult = dependencyHelper.getArtifactCollector().collect(
                 project.getDependencyArtifacts(),
                 project.getArtifact(),
@@ -242,9 +248,13 @@
                 project.getRemoteArtifactRepositories(),
                 dependencyHelper.getArtifactMetadataSource(),
                 null,
-                Collections.emptyList());
+                Collections.singletonList(listener));
 
         dependencies = artifactResolutionResult.getArtifacts();
+        projectNode = listener.getTop();
+        for (Artifact artifact: dependencies) {
+            dependencyMap.put(DependencyListener.shrink(artifact), artifact);
+        }
     }
 
     protected class ArtifactLookupImpl

Added: geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/DependencyListener.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/DependencyListener.java?rev=656537&view=auto
==============================================================================
--- geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/DependencyListener.java
(added)
+++ geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/DependencyListener.java
Thu May 15 01:11:09 2008
@@ -0,0 +1,106 @@
+/*
+ * 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.mavenplugins.car;
+
+import java.util.Stack;
+
+import org.apache.maven.artifact.resolver.ResolutionListener;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.DefaultArtifact;
+import org.apache.maven.artifact.handler.ArtifactHandler;
+import org.apache.maven.artifact.handler.DefaultArtifactHandler;
+import org.apache.maven.artifact.versioning.VersionRange;
+
+/**
+ * @version $Rev:$ $Date:$
+ */
+public class DependencyListener implements ResolutionListener {
+    private static final VersionRange RANGE = VersionRange.createFromVersion("");
+    private static final ArtifactHandler artifactHandler = new DefaultArtifactHandler();
+    private ProjectNode top;
+    private final Stack<ProjectNode> parents = new Stack<ProjectNode>();
+
+    public void testArtifact(Artifact artifact) {
+        if (!parents.isEmpty()) {
+            ProjectNode parent = parents.peek();
+            Artifact shrunk = shrink(artifact);
+            ProjectNode child = new ProjectNode(shrunk);
+            parent.addChild(child);
+        }
+        //else??
+    }
+
+    public void startProcessChildren(Artifact artifact) {
+        Artifact shrunk = shrink(artifact);
+        if (top == null) {
+            top = new ProjectNode(shrunk);
+            parents.push(top);
+        } else {
+            ProjectNode node = parents.peek();
+            for (ProjectNode child: node.getChildNodes()) {
+                if (shrunk.equals(child.getArtifact())) {
+                    parents.push(child);
+                    break;
+                }
+            }
+        }
+    }
+
+    public void endProcessChildren(Artifact artifact) {
+        ProjectNode node = parents.pop();
+        if (!shrink(artifact).equals(node.getArtifact())) {
+            throw new IllegalStateException("Unexpected parent, expected: " + artifact +
" got " + node.getArtifact());
+        }
+    }
+
+    public void includeArtifact(Artifact artifact) {
+    }
+
+    public void omitForNearer(Artifact artifact, Artifact artifact1) {
+    }
+
+    public void updateScope(Artifact artifact, String s) {
+    }
+
+    public void manageArtifact(Artifact artifact, Artifact artifact1) {
+    }
+
+    public void omitForCycle(Artifact artifact) {
+    }
+
+    public void updateScopeCurrentPom(Artifact artifact, String s) {
+    }
+
+    public void selectVersionFromRange(Artifact artifact) {
+    }
+
+    public void restrictRange(Artifact artifact, Artifact artifact1, VersionRange versionRange)
{
+    }
+
+    static Artifact shrink(Artifact artifact) {
+        Artifact shrunk = new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(),
RANGE, artifact.getScope(), artifact.getType(), artifact.getClassifier(), artifactHandler);
+        return shrunk;
+    }
+
+    public ProjectNode getTop() {
+        return top;
+    }
+}

Propchange: geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/DependencyListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/DependencyListener.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/DependencyListener.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/PlanProcessorMojo.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/PlanProcessorMojo.java?rev=656537&r1=656536&r2=656537&view=diff
==============================================================================
--- geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/PlanProcessorMojo.java
(original)
+++ geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/PlanProcessorMojo.java
Thu May 15 01:11:09 2008
@@ -34,7 +34,6 @@
 import org.apache.geronimo.kernel.repository.Artifact;
 import org.apache.geronimo.kernel.repository.Environment;
 import org.apache.geronimo.kernel.repository.ImportType;
-import org.apache.maven.project.MavenProject;
 import org.apache.maven.project.ProjectBuildingException;
 import org.apache.maven.project.artifact.InvalidDependencyVersionException;
 import org.apache.maven.artifact.resolver.ArtifactResolutionException;
@@ -269,22 +268,29 @@
                 dependencies.add(gdep);
             }
         } else {
-            List<org.apache.maven.model.Dependency> artifacts = project.getDependencies();
-            processProject(dependencies, artifacts, dependencyHelper.getDependencies(project).getRootNode(),
useMavenDependencies.isUseTransitiveDependencies());
+            LinkedHashSet<org.apache.geronimo.kernel.repository.Dependency> carDependencies
= new LinkedHashSet<org.apache.geronimo.kernel.repository.Dependency>();
+            getDependencies(project);
+            processProject(dependencies, carDependencies, projectNode, useMavenDependencies.isUseTransitiveDependencies());
+            dependencies.removeAll(carDependencies);
         }
 
         return dependencies;
     }
 
-    private void processProject(LinkedHashSet<org.apache.geronimo.kernel.repository.Dependency>
dependencies, List<org.apache.maven.model.Dependency> artifacts, DependencyTree.Node
node, boolean useTransitiveDependencies) {
-        List<DependencyTree.Node> includedNodes = node.getChildren();
-        for (DependencyTree.Node childNode : includedNodes) {
+    private void processProject(LinkedHashSet<org.apache.geronimo.kernel.repository.Dependency>
dependencies, LinkedHashSet<org.apache.geronimo.kernel.repository.Dependency> carDependencies,
ProjectNode node, boolean useTransitiveDependencies) {
+        List<ProjectNode> includedNodes = node.getChildNodes();
+        for (ProjectNode childNode : includedNodes) {
             org.apache.maven.artifact.Artifact artifact = childNode.getArtifact();
             if (includeDependency(artifact)) {
-                org.apache.geronimo.kernel.repository.Dependency gdep = toGeronimoDependency(artifact,
useMavenDependencies.isIncludeVersion());
+                org.apache.geronimo.kernel.repository.Dependency gdep = toGeronimoDependency(dependencyMap.get(artifact),
useMavenDependencies.isIncludeVersion());
                 dependencies.add(gdep);
-                if (useTransitiveDependencies && !artifact.getType().equalsIgnoreCase("car"))
{
-                    processProject(dependencies, artifacts, childNode, useTransitiveDependencies);
+                if (useTransitiveDependencies) {
+
+                    if (artifact.getType().equalsIgnoreCase("car")) {
+                        processProject(carDependencies, carDependencies, childNode, useTransitiveDependencies);
+                    } else {
+                        processProject(dependencies, carDependencies, childNode, useTransitiveDependencies);
+                    }
                 }
             }
         }

Added: geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/ProjectNode.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/ProjectNode.java?rev=656537&view=auto
==============================================================================
--- geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/ProjectNode.java
(added)
+++ geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/ProjectNode.java
Thu May 15 01:11:09 2008
@@ -0,0 +1,52 @@
+/*
+ * 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.mavenplugins.car;
+
+import java.util.List;
+import java.util.ArrayList;
+
+import org.apache.maven.artifact.Artifact;
+
+/**
+ * @version $Rev:$ $Date:$
+ */
+public class ProjectNode {
+
+
+    private final org.apache.maven.artifact.Artifact artifact;
+    private final List<ProjectNode> childNodes = new ArrayList<ProjectNode>();
+
+    public ProjectNode(Artifact artifact) {
+        this.artifact = artifact;
+    }
+
+    public void addChild(ProjectNode child) {
+        childNodes.add(child);
+    }
+
+    public List<ProjectNode> getChildNodes() {
+        return childNodes;
+    }
+
+    public Artifact getArtifact() {
+        return artifact;
+    }
+}

Propchange: geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/ProjectNode.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/ProjectNode.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/ProjectNode.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message