Author: brianf Date: Thu Oct 28 01:30:16 2010 New Revision: 1028163 URL: http://svn.apache.org/viewvc?rev=1028163&view=rev Log: MENFORCER-107 - dependencies_converge rule based on patch from Rex Hoffman
Added: maven/enforcer/trunk/enforcer-rules/src/it/builds_a_pom_noop/ maven/enforcer/trunk/enforcer-rules/src/it/builds_a_pom_noop/module/ maven/enforcer/trunk/enforcer-rules/src/it/builds_a_pom_noop/module/pom.xml (with props) maven/enforcer/trunk/enforcer-rules/src/it/builds_a_pom_noop/pom.xml (with props) maven/enforcer/trunk/enforcer-rules/src/it/dependencies_converge/ maven/enforcer/trunk/enforcer-rules/src/it/dependencies_converge/module/ maven/enforcer/trunk/enforcer-rules/src/it/dependencies_converge/module/pom.xml (with props) maven/enforcer/trunk/enforcer-rules/src/it/dependencies_converge/pom.xml (with props) maven/enforcer/trunk/enforcer-rules/src/it/dependencies_not_converging/ maven/enforcer/trunk/enforcer-rules/src/it/dependencies_not_converging/invoker.properties (with props) maven/enforcer/trunk/enforcer-rules/src/it/dependencies_not_converging/module/ maven/enforcer/trunk/enforcer-rules/src/it/dependencies_not_converging/module/pom.xml (with props) maven/enforcer/trunk/enforcer-rules/src/it/dependencies_not_converging/pom.xml (with props) maven/enforcer/trunk/enforcer-rules/src/it/dependencies_not_converging_test_scope/ maven/enforcer/trunk/enforcer-rules/src/it/dependencies_not_converging_test_scope/invoker.properties (with props) maven/enforcer/trunk/enforcer-rules/src/it/dependencies_not_converging_test_scope/module/ maven/enforcer/trunk/enforcer-rules/src/it/dependencies_not_converging_test_scope/module/pom.xml (with props) maven/enforcer/trunk/enforcer-rules/src/it/dependencies_not_converging_test_scope/pom.xml (with props) maven/enforcer/trunk/enforcer-rules/src/it/settings.xml (with props) maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/DependencyConvergence.java (with props) maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/utils/DependencyVersionMap.java (with props) maven/enforcer/trunk/enforcer-rules/src/site/apt/dependencyConvergence.apt.vm (with props) maven/enforcer/trunk/enforcer-rules/src/site/apt/rules/specific-dependencies-converge.apt (with props) Modified: maven/enforcer/trunk/enforcer-rules/pom.xml maven/enforcer/trunk/enforcer-rules/src/site/apt/index.apt maven/enforcer/trunk/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequirePluginVersions.java Modified: maven/enforcer/trunk/enforcer-rules/pom.xml URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-rules/pom.xml?rev=1028163&r1=1028162&r2=1028163&view=diff ============================================================================== --- maven/enforcer/trunk/enforcer-rules/pom.xml (original) +++ maven/enforcer/trunk/enforcer-rules/pom.xml Thu Oct 28 01:30:16 2010 @@ -85,6 +85,16 @@ <groupId>easymock</groupId> <artifactId>easymock</artifactId> </dependency> + <dependency> + <groupId>org.apache.maven.shared</groupId> + <artifactId>maven-dependency-tree</artifactId> + <version>1.2</version> + </dependency> + <dependency> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-i18n</artifactId> + <version>1.0-beta-6</version> + </dependency> </dependencies> <build> @@ -111,6 +121,33 @@ </execution> </executions> </plugin> + <plugin> + <artifactId>maven-invoker-plugin</artifactId> + <version>1.5</version> + <configuration> + <debug>true</debug> + <projectsDirectory>src/it</projectsDirectory> + <cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo> + <pomIncludes> + <pomInclude>*/pom.xml</pomInclude> + </pomIncludes> + <postBuildHookScript>verify</postBuildHookScript> + <localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath> + <settingsFile>src/it/settings.xml</settingsFile> + <goals> + <goal>verify</goal> + </goals> + </configuration> + <executions> + <execution> + <id>integration-test</id> + <goals> + <goal>install</goal> + <goal>run</goal> + </goals> + </execution> + </executions> + </plugin> <!--plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>shitty-maven-plugin</artifactId> Added: maven/enforcer/trunk/enforcer-rules/src/it/builds_a_pom_noop/module/pom.xml URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-rules/src/it/builds_a_pom_noop/module/pom.xml?rev=1028163&view=auto ============================================================================== --- maven/enforcer/trunk/enforcer-rules/src/it/builds_a_pom_noop/module/pom.xml (added) +++ maven/enforcer/trunk/enforcer-rules/src/it/builds_a_pom_noop/module/pom.xml Thu Oct 28 01:30:16 2010 @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>test</groupId> + <artifactId>TestParent</artifactId> + <version>1.0-SNAPSHOT</version> + </parent> + <artifactId>TestModule</artifactId> + <version>1.0-SNAPSHOT</version> +</project> Propchange: maven/enforcer/trunk/enforcer-rules/src/it/builds_a_pom_noop/module/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/enforcer/trunk/enforcer-rules/src/it/builds_a_pom_noop/module/pom.xml ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/enforcer/trunk/enforcer-rules/src/it/builds_a_pom_noop/pom.xml URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-rules/src/it/builds_a_pom_noop/pom.xml?rev=1028163&view=auto ============================================================================== --- maven/enforcer/trunk/enforcer-rules/src/it/builds_a_pom_noop/pom.xml (added) +++ maven/enforcer/trunk/enforcer-rules/src/it/builds_a_pom_noop/pom.xml Thu Oct 28 01:30:16 2010 @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <groupId>test</groupId> + <artifactId>TestParent</artifactId> + <version>1.0-SNAPSHOT</version> + <packaging>pom</packaging> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-enforcer-plugin</artifactId> + <version>@project.version@</version> + <executions> + <execution> + <id>enforce</id> + <configuration> + <rules> + <DependencyConvergence/> + </rules> + </configuration> + <goals> + <goal>enforce</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> \ No newline at end of file Propchange: maven/enforcer/trunk/enforcer-rules/src/it/builds_a_pom_noop/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/enforcer/trunk/enforcer-rules/src/it/builds_a_pom_noop/pom.xml ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/enforcer/trunk/enforcer-rules/src/it/dependencies_converge/module/pom.xml URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-rules/src/it/dependencies_converge/module/pom.xml?rev=1028163&view=auto ============================================================================== --- maven/enforcer/trunk/enforcer-rules/src/it/dependencies_converge/module/pom.xml (added) +++ maven/enforcer/trunk/enforcer-rules/src/it/dependencies_converge/module/pom.xml Thu Oct 28 01:30:16 2010 @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>test</groupId> + <artifactId>TestParent</artifactId> + <version>1.0-SNAPSHOT</version> + </parent> + <artifactId>TestModule</artifactId> + <version>1.0-SNAPSHOT</version> +</project> Propchange: maven/enforcer/trunk/enforcer-rules/src/it/dependencies_converge/module/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/enforcer/trunk/enforcer-rules/src/it/dependencies_converge/module/pom.xml ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/enforcer/trunk/enforcer-rules/src/it/dependencies_converge/pom.xml URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-rules/src/it/dependencies_converge/pom.xml?rev=1028163&view=auto ============================================================================== --- maven/enforcer/trunk/enforcer-rules/src/it/dependencies_converge/pom.xml (added) +++ maven/enforcer/trunk/enforcer-rules/src/it/dependencies_converge/pom.xml Thu Oct 28 01:30:16 2010 @@ -0,0 +1,49 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <groupId>test</groupId> + <artifactId>TestParent</artifactId> + <version>1.0</version> + <packaging>jar</packaging> + <dependencies> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-jdk14</artifactId> + <version>1.6.1</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-nop</artifactId> + <version>1.6.0</version> + <exclusions> + <exclusion> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + </exclusion> + </exclusions> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-enforcer-plugin</artifactId> + <version>@project.version@</version> + <executions> + <execution> + <id>enforce</id> + <configuration> + <rules> + <DependencyConvergenceRule/> + </rules> + </configuration> + <goals> + <goal>enforce</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> \ No newline at end of file Propchange: maven/enforcer/trunk/enforcer-rules/src/it/dependencies_converge/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/enforcer/trunk/enforcer-rules/src/it/dependencies_converge/pom.xml ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/enforcer/trunk/enforcer-rules/src/it/dependencies_not_converging/invoker.properties URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-rules/src/it/dependencies_not_converging/invoker.properties?rev=1028163&view=auto ============================================================================== --- maven/enforcer/trunk/enforcer-rules/src/it/dependencies_not_converging/invoker.properties (added) +++ maven/enforcer/trunk/enforcer-rules/src/it/dependencies_not_converging/invoker.properties Thu Oct 28 01:30:16 2010 @@ -0,0 +1 @@ +invoker.buildResult=failure \ No newline at end of file Propchange: maven/enforcer/trunk/enforcer-rules/src/it/dependencies_not_converging/invoker.properties ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/enforcer/trunk/enforcer-rules/src/it/dependencies_not_converging/invoker.properties ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/enforcer/trunk/enforcer-rules/src/it/dependencies_not_converging/module/pom.xml URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-rules/src/it/dependencies_not_converging/module/pom.xml?rev=1028163&view=auto ============================================================================== --- maven/enforcer/trunk/enforcer-rules/src/it/dependencies_not_converging/module/pom.xml (added) +++ maven/enforcer/trunk/enforcer-rules/src/it/dependencies_not_converging/module/pom.xml Thu Oct 28 01:30:16 2010 @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>test</groupId> + <artifactId>TestParent</artifactId> + <version>1.0-SNAPSHOT</version> + </parent> + <artifactId>TestModule</artifactId> + <version>1.1-SNAPSHOT</version> +</project> Propchange: maven/enforcer/trunk/enforcer-rules/src/it/dependencies_not_converging/module/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/enforcer/trunk/enforcer-rules/src/it/dependencies_not_converging/module/pom.xml ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/enforcer/trunk/enforcer-rules/src/it/dependencies_not_converging/pom.xml URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-rules/src/it/dependencies_not_converging/pom.xml?rev=1028163&view=auto ============================================================================== --- maven/enforcer/trunk/enforcer-rules/src/it/dependencies_not_converging/pom.xml (added) +++ maven/enforcer/trunk/enforcer-rules/src/it/dependencies_not_converging/pom.xml Thu Oct 28 01:30:16 2010 @@ -0,0 +1,43 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <groupId>test</groupId> + <artifactId>TestParent</artifactId> + <version>1.0-SNAPSHOT</version> + <packaging>jar</packaging> + <dependencies> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-jdk14</artifactId> + <version>1.6.1</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-nop</artifactId> + <version>1.6.0</version> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-enforcer-plugin</artifactId> + <version>@project.version@</version> + <executions> + <execution> + <id>enforce</id> + <configuration> + <rules> + <DependencyConvergence/> + </rules> + </configuration> + <goals> + <goal>enforce</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> \ No newline at end of file Propchange: maven/enforcer/trunk/enforcer-rules/src/it/dependencies_not_converging/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/enforcer/trunk/enforcer-rules/src/it/dependencies_not_converging/pom.xml ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/enforcer/trunk/enforcer-rules/src/it/dependencies_not_converging_test_scope/invoker.properties URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-rules/src/it/dependencies_not_converging_test_scope/invoker.properties?rev=1028163&view=auto ============================================================================== --- maven/enforcer/trunk/enforcer-rules/src/it/dependencies_not_converging_test_scope/invoker.properties (added) +++ maven/enforcer/trunk/enforcer-rules/src/it/dependencies_not_converging_test_scope/invoker.properties Thu Oct 28 01:30:16 2010 @@ -0,0 +1 @@ +invoker.buildResult=failure \ No newline at end of file Propchange: maven/enforcer/trunk/enforcer-rules/src/it/dependencies_not_converging_test_scope/invoker.properties ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/enforcer/trunk/enforcer-rules/src/it/dependencies_not_converging_test_scope/invoker.properties ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/enforcer/trunk/enforcer-rules/src/it/dependencies_not_converging_test_scope/module/pom.xml URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-rules/src/it/dependencies_not_converging_test_scope/module/pom.xml?rev=1028163&view=auto ============================================================================== --- maven/enforcer/trunk/enforcer-rules/src/it/dependencies_not_converging_test_scope/module/pom.xml (added) +++ maven/enforcer/trunk/enforcer-rules/src/it/dependencies_not_converging_test_scope/module/pom.xml Thu Oct 28 01:30:16 2010 @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>test</groupId> + <artifactId>TestParent</artifactId> + <version>1.0-SNAPSHOT</version> + </parent> + <artifactId>TestModule</artifactId> + <version>1.1-SNAPSHOT</version> +</project> Propchange: maven/enforcer/trunk/enforcer-rules/src/it/dependencies_not_converging_test_scope/module/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/enforcer/trunk/enforcer-rules/src/it/dependencies_not_converging_test_scope/module/pom.xml ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/enforcer/trunk/enforcer-rules/src/it/dependencies_not_converging_test_scope/pom.xml URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-rules/src/it/dependencies_not_converging_test_scope/pom.xml?rev=1028163&view=auto ============================================================================== --- maven/enforcer/trunk/enforcer-rules/src/it/dependencies_not_converging_test_scope/pom.xml (added) +++ maven/enforcer/trunk/enforcer-rules/src/it/dependencies_not_converging_test_scope/pom.xml Thu Oct 28 01:30:16 2010 @@ -0,0 +1,44 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <groupId>test</groupId> + <artifactId>TestParent</artifactId> + <version>1.0-SNAPSHOT</version> + <packaging>jar</packaging> + <dependencies> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-jdk14</artifactId> + <version>1.6.1</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-nop</artifactId> + <version>1.6.0</version> + <scope>test</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-enforcer-plugin</artifactId> + <version>@project.version@</version> + <executions> + <execution> + <id>enforce</id> + <configuration> + <rules> + <DependencyConvergence/> + </rules> + </configuration> + <goals> + <goal>enforce</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> \ No newline at end of file Propchange: maven/enforcer/trunk/enforcer-rules/src/it/dependencies_not_converging_test_scope/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/enforcer/trunk/enforcer-rules/src/it/dependencies_not_converging_test_scope/pom.xml ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/enforcer/trunk/enforcer-rules/src/it/settings.xml URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-rules/src/it/settings.xml?rev=1028163&view=auto ============================================================================== --- maven/enforcer/trunk/enforcer-rules/src/it/settings.xml (added) +++ maven/enforcer/trunk/enforcer-rules/src/it/settings.xml Thu Oct 28 01:30:16 2010 @@ -0,0 +1,55 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- +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. +--> + +<settings> + <profiles> + <profile> + <id>it-repo</id> + <activation> + <activeByDefault>true</activeByDefault> + </activation> + <repositories> + <repository> + <id>local.central</id> + <url>@localRepositoryUrl@</url> + <releases> + <enabled>true</enabled> + </releases> + <snapshots> + <enabled>true</enabled> + </snapshots> + </repository> + </repositories> + <pluginRepositories> + <pluginRepository> + <id>local.central</id> + <url>@localRepositoryUrl@</url> + <releases> + <enabled>true</enabled> + </releases> + <snapshots> + <enabled>true</enabled> + </snapshots> + </pluginRepository> + </pluginRepositories> + </profile> + </profiles> +</settings> \ No newline at end of file Propchange: maven/enforcer/trunk/enforcer-rules/src/it/settings.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/enforcer/trunk/enforcer-rules/src/it/settings.xml ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/DependencyConvergence.java URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/DependencyConvergence.java?rev=1028163&view=auto ============================================================================== --- maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/DependencyConvergence.java (added) +++ maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/DependencyConvergence.java Thu Oct 28 01:30:16 2010 @@ -0,0 +1,190 @@ +package org.apache.maven.plugins.enforcer; +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.metadata.ArtifactMetadataSource; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.resolver.ArtifactCollector; +import org.apache.maven.artifact.resolver.filter.ArtifactFilter; +import org.apache.maven.enforcer.rule.api.EnforcerRule; +import org.apache.maven.enforcer.rule.api.EnforcerRuleException; +import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.plugins.enforcer.utils.DependencyVersionMap; +import org.apache.maven.project.MavenProject; +import org.apache.maven.shared.dependency.tree.DependencyNode; +import org.apache.maven.shared.dependency.tree.DependencyTreeBuilder; +import org.apache.maven.shared.dependency.tree.DependencyTreeBuilderException; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; +import org.codehaus.plexus.i18n.I18N; + +/** + * @author <a href="mailto:r...@e-hoffman.org">Rex Hoffman</a> + */ +public class DependencyConvergence implements EnforcerRule { + + private static Log log; + + private static I18N i18n; + + /** + * Uses the {...@link EnforcerRuleHelper} to populate the values of the {...@link DependencyTreeBuilder#buildDependencyTree(MavenProject, ArtifactRepository, ArtifactFactory, ArtifactMetadataSource, ArtifactFilter, ArtifactCollector)} + * factory method. <br/> + * + * This method simply exists to hide all the ugly lookup that the {...@link EnforcerRuleHelper} has to do. + * + * @param helper + * @return a Dependency Node which is the root of the project's dependency tree + * @throws EnforcerRuleException + */ + private DependencyNode getNode(EnforcerRuleHelper helper) throws EnforcerRuleException { + try { + MavenProject project = (MavenProject) helper.evaluate("${project}"); + DependencyTreeBuilder dependencyTreeBuilder = (DependencyTreeBuilder) helper.getComponent(DependencyTreeBuilder.class); + ArtifactRepository repository = (ArtifactRepository)helper.evaluate("${localRepository}"); + ArtifactFactory factory = (ArtifactFactory)helper.getComponent(ArtifactFactory.class); + ArtifactMetadataSource metadataSource = (ArtifactMetadataSource)helper.getComponent(ArtifactMetadataSource.class); + ArtifactCollector collector = (ArtifactCollector)helper.getComponent(ArtifactCollector.class); + ArtifactFilter filter = null; //we need to evaluate all scopes + DependencyNode node = dependencyTreeBuilder.buildDependencyTree(project, repository, factory, metadataSource, filter, collector); + return node; + } catch (ExpressionEvaluationException e) { + throw new EnforcerRuleException("Unable to lookup an expression " + e.getLocalizedMessage(), e); + } catch (ComponentLookupException e){ + throw new EnforcerRuleException("Unable to lookup a component " + e.getLocalizedMessage(), e); + } catch (DependencyTreeBuilderException e){ + throw new EnforcerRuleException("Could not build dependency tree " + e.getLocalizedMessage(), e); + } + } + + public void execute(EnforcerRuleHelper helper) throws EnforcerRuleException { + if (log == null){ + log = helper.getLog(); + } + try { + if (i18n == null){ + i18n = (I18N) helper.getComponent(I18N.class); + } + DependencyNode node = getNode(helper); + MavenProject project = (MavenProject) helper.evaluate("${project}"); + DependencyVersionMap visitor = new DependencyVersionMap(project.getArtifact().isRelease(), log); + node.accept(visitor); + List<CharSequence> errorMsgs = new ArrayList<CharSequence>(); + errorMsgs.addAll(getConvergenceErrorMsgs(visitor.getConflictedVersionNumbers())); + for (CharSequence errorMsg : errorMsgs) { + log.error(errorMsg); + } + if (errorMsgs.size() > 0) { + throw new EnforcerRuleException("Failed while enforcing releasability the error(s) are " + errorMsgs); + } + } catch (ExpressionEvaluationException e) { + throw new EnforcerRuleException("Unable to lookup an expression " + e.getLocalizedMessage(), e); + } catch (ComponentLookupException e){ + throw new EnforcerRuleException("Unable to lookup a component " + e.getLocalizedMessage(), e); + } catch (Exception e){ + throw new EnforcerRuleException(e.getLocalizedMessage(), e); + } + } + + private String getFullArtifactName(Artifact artifact){ + return artifact.getGroupId() + ":" + artifact.getArtifactId() + artifact.getVersion(); + } + + private StringBuilder buildTreeString(DependencyNode node) { + List<String> loc = new ArrayList<String>(); + DependencyNode currentNode = node; + while (currentNode != null) { + loc.add(getFullArtifactName(node.getArtifact())); + currentNode = currentNode.getParent(); + } + Collections.reverse(loc); + StringBuilder builder = new StringBuilder(); + for (int i = 0; i < loc.size(); i++) { + for (int j = 0; j < i; j++){ + builder.append(" "); + } + builder.append("+-"+loc.get(i)); + builder.append("\n"); + } + return builder; + } + + private List<String> getConvergenceErrorMsgs(List<List<DependencyNode>> errors) { + List<String> errorMsgs = new ArrayList<String>(); + for (List<DependencyNode> nodeList : errors){ + errorMsgs.add(buildConvergenceErrorMsg(nodeList)); + } + return errorMsgs; + } + + private String buildConvergenceErrorMsg(List<DependencyNode> nodeList){ + StringBuilder builder = new StringBuilder(); + builder.append("\nDependency convergence error for "+getFullArtifactName(nodeList.get(0).getArtifact())+" paths to dependency are:\n"); + if (nodeList.size() > 0){ + builder.append(buildTreeString(nodeList.get(0))); + } + for (DependencyNode node: nodeList){ + builder.append("and\n"); + builder.append(buildTreeString(node)); + } + return builder.toString(); + } + + /** + * If your rule is cacheable, you must return a unique id when parameters or + * conditions change that would cause the result to be different. Multiple + * cached results are stored based on their id. + * + * The easiest way to do this is to return a hash computed from the values of + * your parameters. + * + * If your rule is not cacheable, then the result here is not important, you + * may return anything. + */ + public String getCacheId() { + return ""; + } + + /** + * This tells the system if the results are cacheable at all. Keep in mind + * that during forked builds and other things, a given rule may be executed + * more than once for the same project. This means that even things that + * change from project to project may still be cacheable in certain instances. + */ + public boolean isCacheable() { + return false; + } + + /** + * If the rule is cacheable and the same id is found in the cache, the stored + * results are passed to this method to allow double checking of the results. + * Most of the time this can be done by generating unique ids, but sometimes + * the results of objects returned by the helper need to be queried. You may + * for example, store certain objects in your rule and then query them later. + */ + public boolean isResultValid(EnforcerRule arg0) { + return false; + } +} Propchange: maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/DependencyConvergence.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/DependencyConvergence.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/utils/DependencyVersionMap.java URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/utils/DependencyVersionMap.java?rev=1028163&view=auto ============================================================================== --- maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/utils/DependencyVersionMap.java (added) +++ maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/utils/DependencyVersionMap.java Thu Oct 28 01:30:16 2010 @@ -0,0 +1,122 @@ +package org.apache.maven.plugins.enforcer.utils; +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.shared.dependency.tree.DependencyNode; +import org.apache.maven.shared.dependency.tree.traversal.DependencyNodeVisitor; + +public class DependencyVersionMap implements DependencyNodeVisitor { + + private boolean demandReleasedVersions = false; + + private Map<String, List<DependencyNode>> idsToNode; + + private List<DependencyNode> snapshots; + + public DependencyVersionMap(Log log){ + idsToNode = new HashMap<String, List<DependencyNode>>(); + snapshots = new ArrayList<DependencyNode>(); + } + + public DependencyVersionMap(boolean demandReleasedVersions, Log log){ + this(log); + this.demandReleasedVersions = demandReleasedVersions; + } + + public boolean visit(DependencyNode node) { + addDependency(node); + if (containsConflicts(node)){ + return false; + } + if (demandReleasedVersions){ + if (node.getArtifact().isSnapshot()){ + snapshots.add(node); + return false; + } + } + return true; + } + + public boolean endVisit(DependencyNode node) { + return true; + } + + private String constructKey(DependencyNode node){ + return constructKey(node.getArtifact()); + } + + private String constructKey(Artifact artifact){ + return artifact.getGroupId()+":"+artifact.getArtifactId(); + } + + public void addDependency(DependencyNode node) { + String key = constructKey(node); + if (node.getArtifact().isSnapshot()){ + snapshots.add(node); + } + List<DependencyNode> nodes = idsToNode.get(key); + if (nodes == null){ + nodes = new ArrayList<DependencyNode>(); + idsToNode.put(key,nodes); + } + nodes.add(node); + } + + public List<DependencyNode> getSnapshots(){ + return snapshots; + } + + private boolean containsConflicts(DependencyNode node){ + return containsConflicts(node.getArtifact()); + } + + private boolean containsConflicts(Artifact artifact){ + return containsConflicts(idsToNode.get(constructKey(artifact))); + } + + private boolean containsConflicts(List<DependencyNode> nodes){ + String version = null; + for (DependencyNode node : nodes){ + if (version == null){ + version = node.getArtifact().getVersion(); + } else { + if (version.compareTo(node.getArtifact().getVersion()) != 0){ + return true; + } + } + } + return false; + } + + public List<List<DependencyNode>> getConflictedVersionNumbers(){ + List<List<DependencyNode>> output = new ArrayList<List<DependencyNode>>(); + for (List<DependencyNode> nodes : idsToNode.values()) { + if(containsConflicts(nodes)){ + output.add(nodes); + } + } + return output; + } +} Propchange: maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/utils/DependencyVersionMap.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/enforcer/trunk/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/utils/DependencyVersionMap.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Added: maven/enforcer/trunk/enforcer-rules/src/site/apt/dependencyConvergence.apt.vm URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-rules/src/site/apt/dependencyConvergence.apt.vm?rev=1028163&view=auto ============================================================================== --- maven/enforcer/trunk/enforcer-rules/src/site/apt/dependencyConvergence.apt.vm (added) +++ maven/enforcer/trunk/enforcer-rules/src/site/apt/dependencyConvergence.apt.vm Thu Oct 28 01:30:16 2010 @@ -0,0 +1,115 @@ + ~~ 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. + + ----- + Comparing against a specific artifact + ----- + ----- + 2008-09-13 + ----- + + This rule requires that dependency version numbers converge. If it has two dependencies, A and B, both depending on the same artifact, c, this rule will fail the build if A depends on a different version of C then the version of C depended on by B. + + Here is a concrete example. + + This will cause a build to fail. + +----------------------------------------------------------------------------------- + + <dependencies> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-jdk14</artifactId> + <version>1.6.1</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-nop</artifactId> + <version>1.6.0</version> + </dependency> + </dependencies> +----------------------------------------------------------------------------------- + + With this being logged during compilation + +----------------------------------------------------------------------------------- +Dependency convergence error for org.slf4j:slf4j-api1.6.1 paths to dependency are: + ++-org.slf4j:slf4j-api1.6.1 + +-org.slf4j:slf4j-api1.6.1 + +-org.slf4j:slf4j-api1.6.1 +and ++-org.slf4j:slf4j-api1.6.0 + +-org.slf4j:slf4j-api1.6.0 + +-org.slf4j:slf4j-api1.6.0 + +----------------------------------------------------------------------------------- + + And this will succeed. + +----------------------------------------------------------------------------------- + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-jdk14</artifactId> + <version>1.6.1</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-nop</artifactId> + <version>1.6.0</version> + <exclusions> + <exclusion> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + </exclusion> + </exclusions> + </dependency> +----------------------------------------------------------------------------------- + + + Here is how a project should be setup to use this rule + +----------------------------------------------------------------------------------- +<project> + ... + <build> + <plugins> + ... + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-enforcer-plugin</artifactId> + <version><version>${project.version}</version></version> + <executions> + <execution> + <id>enforce</id> + <configuration> + <rules> + <DependencyConvergenceRule/> + </rules> + </configuration> + <goals> + <goal>enforce</goal> + </goals> + </execution> + </executions> + </plugin> + ... + </plugins> + </build> + ... +</project> +----------------------------------------------------------------------------------- Propchange: maven/enforcer/trunk/enforcer-rules/src/site/apt/dependencyConvergence.apt.vm ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/enforcer/trunk/enforcer-rules/src/site/apt/dependencyConvergence.apt.vm ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Modified: maven/enforcer/trunk/enforcer-rules/src/site/apt/index.apt URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-rules/src/site/apt/index.apt?rev=1028163&r1=1028162&r2=1028163&view=diff ============================================================================== --- maven/enforcer/trunk/enforcer-rules/src/site/apt/index.apt (original) +++ maven/enforcer/trunk/enforcer-rules/src/site/apt/index.apt Thu Oct 28 01:30:16 2010 @@ -34,6 +34,8 @@ Standard Rules * {{{./bannedDependencies.html}bannedDependencies}} - enforces that excluded dependencies aren't included. * bannedPlugins - enforces that excluded plugins aren't included. + + * {{{./dependencyConvergence.html}dependencyConvergence}} - ensure all dependencies converge to the same version. * {{{./evaluateBeanshell.html}evaluateBeanshell}} - evaluates a beanshell script. Added: maven/enforcer/trunk/enforcer-rules/src/site/apt/rules/specific-dependencies-converge.apt URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-rules/src/site/apt/rules/specific-dependencies-converge.apt?rev=1028163&view=auto ============================================================================== --- maven/enforcer/trunk/enforcer-rules/src/site/apt/rules/specific-dependencies-converge.apt (added) +++ maven/enforcer/trunk/enforcer-rules/src/site/apt/rules/specific-dependencies-converge.apt Thu Oct 28 01:30:16 2010 @@ -0,0 +1,122 @@ + ~~ 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. + + ----- + Comparing against a specific artifact + ----- + ----- + 2008-09-13 + ----- + + This rule demands that dependency version number converge. If it has two dependencies, A and B, both depending on the same artifact, c, this rule will fail the build if A depends on a different version of C then the version of C depended on by B. + + Here is a concrete example. + + This will cause a build to fail. + +----------------------------------------------------------------------------------- + + <dependencies> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-jdk14</artifactId> + <version>1.6.1</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-nop</artifactId> + <version>1.6.0</version> + </dependency> + </dependencies> +----------------------------------------------------------------------------------- + + With this being logged during compilation + +----------------------------------------------------------------------------------- +Dependency convergence error for org.slf4j:slf4j-api1.6.1 paths to dependency are: + ++-org.slf4j:slf4j-api1.6.1 + +-org.slf4j:slf4j-api1.6.1 + +-org.slf4j:slf4j-api1.6.1 +and ++-org.slf4j:slf4j-api1.6.0 + +-org.slf4j:slf4j-api1.6.0 + +-org.slf4j:slf4j-api1.6.0 + +----------------------------------------------------------------------------------- + + And this will succeed. + +----------------------------------------------------------------------------------- + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-jdk14</artifactId> + <version>1.6.1</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-nop</artifactId> + <version>1.6.0</version> + <exclusions> + <exclusion> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + </exclusion> + </exclusions> + </dependency> +----------------------------------------------------------------------------------- + + + Here is how a project should be setup to use this rule + +----------------------------------------------------------------------------------- +<project> + ... + <build> + <plugins> + ... + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-enforcer-plugin</artifactId> + <version>1.0-beta-1</version> + <dependencies> + <dependency> + <groupId>org.apache.maven.enforcer.rules</groupId> + <artifactId>maven-enforce-noconflicts</artifactId> + <version>1.0.0</version> + </dependency> + </dependencies> + <executions> + <execution> + <id>enforce</id> + <configuration> + <rules> + <myCustomRule implementation="org.apache.maven.enforcer.rule.DependencyConvergenceRule" /> + </rules> + </configuration> + <goals> + <goal>enforce</goal> + </goals> + </execution> + </executions> + </plugin> + ... + </plugins> + </build> + ... +</project> +----------------------------------------------------------------------------------- Propchange: maven/enforcer/trunk/enforcer-rules/src/site/apt/rules/specific-dependencies-converge.apt ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/enforcer/trunk/enforcer-rules/src/site/apt/rules/specific-dependencies-converge.apt ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Modified: maven/enforcer/trunk/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequirePluginVersions.java URL: http://svn.apache.org/viewvc/maven/enforcer/trunk/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequirePluginVersions.java?rev=1028163&r1=1028162&r2=1028163&view=diff ============================================================================== --- maven/enforcer/trunk/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequirePluginVersions.java (original) +++ maven/enforcer/trunk/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequirePluginVersions.java Thu Oct 28 01:30:16 2010 @@ -336,12 +336,12 @@ public class TestRequirePluginVersions { RequirePluginVersions rule = new RequirePluginVersions(); - Set plugins = new HashSet(); + Set <Plugin> plugins = new HashSet<Plugin>(); plugins.add( EnforcerTestUtils.newPlugin( "group", "a-artifact", "1.0" ) ); plugins.add( EnforcerTestUtils.newPlugin( "group", "foo", null ) ); plugins.add( EnforcerTestUtils.newPlugin( "group", "foo2", "" ) ); - List unchecked = new ArrayList(); + List<String> unchecked = new ArrayList<String>(); //intentionally inserting spaces to make sure they are handled correctly. unchecked.add( "group : a-artifact" );