geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r686089 - in /geronimo/server/trunk/buildsupport/car-maven-plugin/src: main/java/org/apache/geronimo/mavenplugins/car/ main/resources/META-INF/plexus/ test/java/org/apache/geronimo/mavenplugins/car/
Date Thu, 14 Aug 2008 23:36:43 GMT
Author: djencks
Date: Thu Aug 14 16:36:42 2008
New Revision: 686089

URL: http://svn.apache.org/viewvc?rev=686089&view=rev
Log:
GERONIMO-4248 add dependency history checking.  Need to check that this doesn't cause build
problems

Added:
    geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/DependencyChangeMojo.java
  (with props)
    geronimo/server/trunk/buildsupport/car-maven-plugin/src/test/java/org/apache/geronimo/mavenplugins/car/DependencyTest.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/Dependency.java
    geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/ModuleId.java
    geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/PlanProcessorMojo.java
    geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/PluginMetadataGeneratorMojo.java
    geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/UseMavenDependencies.java
    geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/resources/META-INF/plexus/components.xml

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=686089&r1=686088&r2=686089&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 Aug 14 16:36:42 2008
@@ -34,6 +34,7 @@
 import java.util.Collection;
 
 import org.apache.geronimo.kernel.repository.*;
+import org.apache.geronimo.system.plugin.model.ArtifactType;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
@@ -350,6 +351,15 @@
         return dependency.getGroupId() + "/" + dependency.getArtifactId() + "/" + dependency.getType();
     }
 
+    protected ArtifactType getModuleId() {
+        ArtifactType artifactType = new ArtifactType();
+        artifactType.setGroupId(project.getGroupId());
+        artifactType.setArtifactId(project.getArtifactId());
+        artifactType.setVersion(project.getVersion());
+        artifactType.setType(project.getArtifact().getType());
+        return artifactType;
+    }
+
 
     private static class Scanner {
         private static enum Accept {

Modified: geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/Dependency.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/Dependency.java?rev=686089&r1=686088&r2=686089&view=diff
==============================================================================
--- geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/Dependency.java
(original)
+++ geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/Dependency.java
Thu Aug 14 16:36:42 2008
@@ -55,7 +55,7 @@
         return dependency;
     }
 
-    public org.apache.geronimo.kernel.repository.Dependency toDependency() {
+    public org.apache.geronimo.kernel.repository.Dependency toKernelDependency() {
         org.apache.geronimo.kernel.repository.Artifact artifact = new org.apache.geronimo.kernel.repository.Artifact(groupId,
artifactId, version, type);
         ImportType importType = getImport() == null? ImportType.ALL: ImportType.getByName(getImport());
         return new org.apache.geronimo.kernel.repository.Dependency(artifact, importType);
@@ -64,4 +64,25 @@
     public String toString() {
         return groupId + ":" + artifactId + ":" + version + ":" + type;
     }
+
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+
+        Dependency that = (Dependency) o;
+        if (!super.equals(that)) return false;
+        return isStart().equals(that.isStart());
+    }
+    //rely on super.hashcode();
+
+    public static Dependency newDependency(DependencyType dependencyType) {
+        Dependency dependency = new Dependency();
+        dependency.setGroupId(dependencyType.getGroupId());
+        dependency.setArtifactId(dependencyType.getArtifactId());
+        dependency.setVersion(dependencyType.getVersion());
+        dependency.setType(dependencyType.getType());
+        dependency.setStart(dependencyType.isStart());
+        dependency.setImport(ImportType.ALL.toString());
+        return dependency;
+    }
 }

Added: geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/DependencyChangeMojo.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/DependencyChangeMojo.java?rev=686089&view=auto
==============================================================================
--- geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/DependencyChangeMojo.java
(added)
+++ geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/DependencyChangeMojo.java
Thu Aug 14 16:36:42 2008
@@ -0,0 +1,142 @@
+/*
+ * 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.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.bind.JAXBException;
+
+import org.apache.geronimo.system.plugin.PluginXmlUtil;
+import org.apache.geronimo.system.plugin.model.ArtifactType;
+import org.apache.geronimo.system.plugin.model.DependencyType;
+import org.apache.geronimo.system.plugin.model.PluginArtifactType;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
+/**
+ * Check if the dependencies have changed
+ *
+ * @version $Rev:$ $Date:$
+ * @goal verify-no-dependency-change
+ * @requiresDependencyResolution runtime
+ */
+public class DependencyChangeMojo extends AbstractCarMojo {
+
+    /**
+     * Dependencies explicitly listed in the car-maven-plugin configuration
+     *
+     * @parameter
+     */
+    private List<Dependency> dependencies = Collections.emptyList();
+
+
+    /**
+     * Whether to fail on changed dependencies
+     * @parameter
+     */
+    private boolean failOnChange=true;
+
+    /**
+     * Location of existing dependency file.
+     *
+     * @parameter expression="${basedir}/src/main/history/dependencies.xml"
+     * @required
+     */
+    private File dependencyFile;
+
+    /**
+     * Configuration of use of maven dependencies.  If missing or if value element is false,
use the explicit list in the car-maven-plugin configuration.
+     * If present and true, use the maven dependencies in the current pom file of scope null,
runtime, or compile.  In addition, the version of the maven
+     * dependency can be included or not depending on the includeVersion element.
+     *
+     * @parameter
+     */
+    private UseMavenDependencies useMavenDependencies;
+
+    public void execute() throws MojoExecutionException, MojoFailureException {
+        boolean useTransitiveDependencies = useMavenDependencies == null? true: useMavenDependencies.isUseTransitiveDependencies();
+        UseMavenDependencies useMavenDependencies = new UseMavenDependencies(true, false,
useTransitiveDependencies);
+
+        try {
+            Collection<Dependency> dependencies = toDependencies(this.dependencies,
useMavenDependencies);
+            if (dependencyFile.exists()) {
+                //read dependency types, convert to dependenciees, compare.
+                FileReader in = new FileReader(dependencyFile);
+                try {
+                    PluginArtifactType pluginArtifactType = PluginXmlUtil.loadPluginArtifactMetadata(in);
+                    PluginArtifactType added = new PluginArtifactType();
+                    for (DependencyType test: pluginArtifactType.getDependency()) {
+                        Dependency testDependency = Dependency.newDependency(test);
+                        if (!dependencies.remove(testDependency)) {
+                            added.getDependency().add(test);
+                        }
+                    }
+                    if (!dependencies.isEmpty() || !added.getDependency().isEmpty()) {
+                        File removedFile = new File(dependencyFile.getParentFile(), "dependencies.removed.xml");
+                        writeDependencies(dependencies,  removedFile);
+                        File addedFile = new File(dependencyFile.getParentFile(), "dependencies.added.xml");
+                        writeDependencies(added,  addedFile);
+                        if (failOnChange) {
+                            throw new MojoFailureException("Dependencies have changed");
+                        }
+                    }
+                } finally {
+                    in.close();
+                }
+            } else {
+                writeDependencies(dependencies,  dependencyFile);
+            }
+        } catch (Exception e) {
+            throw new MojoExecutionException("Could not read or write dependency history
info", e);
+        }
+    }
+
+    private void writeDependencies(Collection<Dependency> dependencies, File file)
throws IOException, XMLStreamException, JAXBException {
+        PluginArtifactType pluginArtifactType = new PluginArtifactType();
+        for (Dependency dependency: dependencies) {
+            pluginArtifactType.getDependency().add(dependency.toDependencyType());
+        }
+        writeDependencies(pluginArtifactType, file);
+    }
+
+    private void writeDependencies(PluginArtifactType pluginArtifactType, File file) throws
IOException, XMLStreamException, JAXBException {
+        pluginArtifactType.setModuleId(getModuleId());
+        File parent = file.getParentFile();
+        if (!parent.exists()) {
+            parent.mkdirs();
+        } else if (!parent.isDirectory()) {
+            throw new IOException("expected dependencies history directory is not a directory:
" + parent);
+        }
+        FileWriter out = new FileWriter(file);
+        try {
+            PluginXmlUtil.writePluginArtifact(pluginArtifactType, out);
+        } finally {
+            out.close();
+        }
+    }
+}

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

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

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

Modified: geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/ModuleId.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/ModuleId.java?rev=686089&r1=686088&r2=686089&view=diff
==============================================================================
--- geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/ModuleId.java
(original)
+++ geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/ModuleId.java
Thu Aug 14 16:36:42 2008
@@ -97,4 +97,29 @@
         artifact.setType(type);
         return artifact;
     }
+
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (!(o instanceof ModuleId)) return false;
+
+        ModuleId moduleId = (ModuleId) o;
+
+        if (artifactId != null ? !artifactId.equals(moduleId.artifactId) : moduleId.artifactId
!= null) return false;
+        if (groupId != null ? !groupId.equals(moduleId.groupId) : moduleId.groupId != null)
return false;
+        if (importType != null ? !importType.equals(moduleId.importType) : moduleId.importType
!= null) return false;
+        if (type != null ? !type.equals(moduleId.type) : moduleId.type != null) return false;
+        if (version != null ? !version.equals(moduleId.version) : moduleId.version != null)
return false;
+
+        return true;
+    }
+
+    public int hashCode() {
+        int result;
+        result = (groupId != null ? groupId.hashCode() : 0);
+        result = 31 * result + (artifactId != null ? artifactId.hashCode() : 0);
+        result = 31 * result + (version != null ? version.hashCode() : 0);
+        result = 31 * result + (type != null ? type.hashCode() : 0);
+        result = 31 * result + (importType != null ? importType.hashCode() : 0);
+        return result;
+    }
 }

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=686089&r1=686088&r2=686089&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 Aug 14 16:36:42 2008
@@ -269,7 +269,7 @@
         LinkedHashSet<org.apache.geronimo.kernel.repository.Dependency> kernelDependencies
= new LinkedHashSet<org.apache.geronimo.kernel.repository.Dependency>();
         LinkedHashSet<Dependency> dependencies = toDependencies(listedDependencies,
useMavenDependencies);
         for (Dependency dependency: dependencies) {
-            kernelDependencies.add(dependency.toDependency());
+            kernelDependencies.add(dependency.toKernelDependency());
         }
         return kernelDependencies;
     }

Modified: geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/PluginMetadataGeneratorMojo.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/PluginMetadataGeneratorMojo.java?rev=686089&r1=686088&r2=686089&view=diff
==============================================================================
--- geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/PluginMetadataGeneratorMojo.java
(original)
+++ geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/PluginMetadataGeneratorMojo.java
Thu Aug 14 16:36:42 2008
@@ -216,15 +216,10 @@
             }
             metadata.getPluginArtifact().add(instance);
 
-            ArtifactType artifactType = new ArtifactType();
-            artifactType.setGroupId(project.getGroupId());
-            artifactType.setArtifactId(project.getArtifactId());
-            artifactType.setVersion(project.getVersion());
+            ArtifactType artifactType = getModuleId();
             ArtifactType existingArtifact = instance.getModuleId();
             if (existingArtifact != null && existingArtifact.getType() != null) {
                 artifactType.setType(existingArtifact.getType());
-            } else {
-                artifactType.setType(project.getArtifact().getType());
             }
             instance.setModuleId(artifactType);
             addDependencies(instance);

Modified: geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/UseMavenDependencies.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/UseMavenDependencies.java?rev=686089&r1=686088&r2=686089&view=diff
==============================================================================
--- geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/UseMavenDependencies.java
(original)
+++ geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/java/org/apache/geronimo/mavenplugins/car/UseMavenDependencies.java
Thu Aug 14 16:36:42 2008
@@ -40,6 +40,14 @@
      */
     private boolean useTransitiveDependencies;
 
+    public UseMavenDependencies() {
+    }
+
+    public UseMavenDependencies(boolean value, boolean includeVersion, boolean useTransitiveDependencies)
{
+        this.value = value;
+        this.includeVersion = includeVersion;
+        this.useTransitiveDependencies = useTransitiveDependencies;
+    }
 
     public boolean isValue() {
         return value;

Modified: geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/resources/META-INF/plexus/components.xml
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/resources/META-INF/plexus/components.xml?rev=686089&r1=686088&r2=686089&view=diff
==============================================================================
--- geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/resources/META-INF/plexus/components.xml
(original)
+++ geronimo/server/trunk/buildsupport/car-maven-plugin/src/main/resources/META-INF/plexus/components.xml
Thu Aug 14 16:36:42 2008
@@ -40,7 +40,8 @@
                             </process-resources>
                             <compile>
                                 org.apache.geronimo.buildsupport:car-maven-plugin:validate-configuration,
-                                org.apache.geronimo.buildsupport:car-maven-plugin:prepare-plan
+                                org.apache.geronimo.buildsupport:car-maven-plugin:prepare-plan,
+                                org.apache.geronimo.buildsupport:car-maven-plugin:verify-no-dependency-change
                             </compile>
                             <package>
                                 org.apache.geronimo.buildsupport:car-maven-plugin:package,

Added: geronimo/server/trunk/buildsupport/car-maven-plugin/src/test/java/org/apache/geronimo/mavenplugins/car/DependencyTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/buildsupport/car-maven-plugin/src/test/java/org/apache/geronimo/mavenplugins/car/DependencyTest.java?rev=686089&view=auto
==============================================================================
--- geronimo/server/trunk/buildsupport/car-maven-plugin/src/test/java/org/apache/geronimo/mavenplugins/car/DependencyTest.java
(added)
+++ geronimo/server/trunk/buildsupport/car-maven-plugin/src/test/java/org/apache/geronimo/mavenplugins/car/DependencyTest.java
Thu Aug 14 16:36:42 2008
@@ -0,0 +1,80 @@
+/*
+ * 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 junit.framework.TestCase;
+import org.apache.geronimo.system.plugin.model.DependencyType;
+
+/**
+ * @version $Rev:$ $Date:$
+ */
+public class DependencyTest extends TestCase {
+    
+    public void testEquals() throws Exception {
+        Dependency d1 = newDependency(null);
+        Dependency d2 = newDependency(null);
+        assertTrue(d1.equals(d2));
+        d1.setStart(true);
+        assertTrue(d1.equals(d2));
+        d2.setStart(true);
+        assertTrue(d1.equals(d2));
+        Dependency d3 = newDependency(null);
+        Dependency d4 = newDependency("1.1");
+        assertFalse(d3.equals(d4));
+        Dependency d5 = newDependency("1.1");
+        Dependency d6 = newDependency("1.1");
+        assertTrue(d5.equals(d6));
+    }
+    public void testStart() throws Exception {
+        Dependency d1 = newDependency(null, null);
+        Dependency d2 = newDependency(null, null);
+        assertTrue(d1.equals(d2));
+        d1.setStart(true);
+        assertTrue(d1.equals(d2));
+        d2.setStart(true);
+        assertTrue(d1.equals(d2));
+        d1.setStart(false);
+        assertFalse(d1.equals(d2));
+        d2.setStart(null);
+        assertFalse(d1.equals(d2));
+    }
+
+    public void testDependencyTypeConversion() throws Exception {
+        Dependency d1 = newDependency(null);
+        DependencyType td = d1.toDependencyType();
+        Dependency d2 = Dependency.newDependency(td);
+        assertTrue(d1.equals(d2));
+    }
+
+    private Dependency newDependency(String version) {
+        return newDependency(version, null);
+    }
+    private Dependency newDependency(String version, Boolean start) {
+        Dependency d = new Dependency();
+        d.setGroupId("foo");
+        d.setArtifactId("bar");
+        d.setVersion(version);
+        d.setType("car");
+        d.setStart(start);
+        d.setImport("ALL");
+        return d;
+    }
+}

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

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

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



Mime
View raw message