This is an automated email from the ASF dual-hosted git repository. khmarbaise pushed a commit to branch MENFORCER-267 in repository https://gitbox.apache.org/repos/asf/maven-enforcer.git
commit ee4dea4ef4070bb966b30ae0bf8a586a6618ab2f Author: Karl Heinz Marbaise <khmarba...@apache.org> AuthorDate: Sat Jan 6 20:50:11 2018 +0100 Continued..not compiling yet. --- enforcer-rules/pom.xml | 4 --- .../plugins/enforcer/AbstractBanDependencies.java | 29 +++++++------------- .../enforcer/BanTransitiveDependencies.java | 5 ++-- .../plugins/enforcer/DependencyConvergence.java | 28 ++++++++----------- .../plugins/enforcer/RequirePluginVersions.java | 9 ------ .../plugins/enforcer/RequireUpperBoundDeps.java | 32 ++++++++-------------- .../enforcer/utils/DependencyVersionMap.java | 4 +-- .../plugins/enforcer/utils/EnforcerRuleUtils.java | 5 +--- .../plugins/enforcer/TestBannedRepositories.java | 1 - 9 files changed, 39 insertions(+), 78 deletions(-) diff --git a/enforcer-rules/pom.xml b/enforcer-rules/pom.xml index abfd146..9b64fca 100644 --- a/enforcer-rules/pom.xml +++ b/enforcer-rules/pom.xml @@ -90,10 +90,6 @@ <artifactId>maven-dependency-tree</artifactId> </dependency> <dependency> - <groupId>org.apache.maven</groupId> - <artifactId>maven-compat</artifactId> - </dependency> - <dependency> <groupId>org.assertj</groupId> <artifactId>assertj-core</artifactId> <scope>test</scope> diff --git a/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AbstractBanDependencies.java b/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AbstractBanDependencies.java index 5bdbaf0..227d5c0 100644 --- a/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AbstractBanDependencies.java +++ b/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/AbstractBanDependencies.java @@ -1,5 +1,8 @@ package org.apache.maven.plugins.enforcer; +import java.util.HashSet; +import java.util.Set; + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -22,15 +25,13 @@ package org.apache.maven.plugins.enforcer; import org.apache.maven.artifact.Artifact; import org.apache.maven.enforcer.rule.api.EnforcerRuleException; import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.logging.Log; -import org.apache.maven.project.MavenProject; import org.apache.maven.shared.dependency.graph.DependencyGraphBuilder; import org.apache.maven.shared.dependency.graph.DependencyGraphBuilderException; import org.apache.maven.shared.dependency.graph.DependencyNode; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; -import java.util.HashSet; -import java.util.Set; /** * Abstract Rule for banning dependencies. @@ -51,11 +52,11 @@ public abstract class AbstractBanDependencies throws EnforcerRuleException { - // get the project - MavenProject project = null; + // get the session + MavenSession session = null; try { - project = (MavenProject) helper.evaluate( "${project}" ); + session = (MavenSession) helper.evaluate( "${session}" ); } catch ( ExpressionEvaluationException eee ) { @@ -68,21 +69,11 @@ public abstract class AbstractBanDependencies } catch ( ComponentLookupException e ) { - // real cause is probably that one of the Maven3 graph builder could not be initiated and fails with a - // ClassNotFoundException - try - { - graphBuilder = - (DependencyGraphBuilder) helper.getComponent( DependencyGraphBuilder.class.getName(), "maven2" ); - } - catch ( ComponentLookupException e1 ) - { throw new EnforcerRuleException( "Unable to lookup DependencyGraphBuilder: ", e ); - } } // get the correct list of dependencies - Set<Artifact> dependencies = getDependenciesToCheck( project ); + Set<Artifact> dependencies = getDependenciesToCheck( session ); // look for banned dependencies Set<Artifact> foundExcludes = checkDependencies( dependencies, helper.getLog() ); @@ -113,12 +104,12 @@ public abstract class AbstractBanDependencies return "Found Banned Dependency: " + artifact.getId() + System.lineSeparator(); } - protected Set<Artifact> getDependenciesToCheck( MavenProject project ) + protected Set<Artifact> getDependenciesToCheck( MavenSession session ) { Set<Artifact> dependencies = null; try { - DependencyNode node = graphBuilder.buildDependencyGraph( project, null ); + DependencyNode node = graphBuilder.buildDependencyGraph( session.getProjectBuildingRequest(), null ); if ( searchTransitive ) { dependencies = getAllDescendants( node ); diff --git a/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/BanTransitiveDependencies.java b/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/BanTransitiveDependencies.java index 6e1dcd4..15388f8 100644 --- a/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/BanTransitiveDependencies.java +++ b/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/BanTransitiveDependencies.java @@ -26,6 +26,7 @@ import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException 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.execution.MavenSession; import org.apache.maven.plugins.enforcer.utils.ArtifactMatcher; import org.apache.maven.project.MavenProject; import org.apache.maven.shared.dependency.graph.DependencyGraphBuilder; @@ -157,8 +158,8 @@ public class BanTransitiveDependencies try { - MavenProject project = (MavenProject) helper.evaluate( "${project}" ); - rootNode = createDependencyGraphBuilder().buildDependencyGraph( project, null ); + MavenSession session = (MavenSession) helper.evaluate( "${session}" ); + rootNode = createDependencyGraphBuilder().buildDependencyGraph( session.getProjectBuildingRequest(), null ); } catch ( Exception e ) { diff --git a/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/DependencyConvergence.java b/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/DependencyConvergence.java index 684f984..3b78612 100644 --- a/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/DependencyConvergence.java +++ b/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/DependencyConvergence.java @@ -24,20 +24,18 @@ 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.execution.MavenSession; 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.apache.maven.shared.dependency.graph.DependencyGraphBuilder; +import org.apache.maven.shared.dependency.graph.DependencyGraphBuilderException; +import org.apache.maven.shared.dependency.graph.DependencyNode; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; @@ -74,17 +72,13 @@ public class DependencyConvergence { 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 ); + MavenSession session = (MavenSession) helper.evaluate( "${session}" ); + DependencyGraphBuilder dependencyTreeBuilder = + (DependencyGraphBuilder) helper.getComponent( DependencyGraphBuilder.class ); ArtifactFilter filter = null; // we need to evaluate all scopes - DependencyNode node = dependencyTreeBuilder.buildDependencyTree( project, repository, factory, - metadataSource, filter, collector ); + + DependencyNode node = dependencyTreeBuilder.buildDependencyGraph(session.getProjectBuildingRequest(), filter ); + return node; } catch ( ExpressionEvaluationException e ) @@ -95,7 +89,7 @@ public class DependencyConvergence { throw new EnforcerRuleException( "Unable to lookup a component " + e.getLocalizedMessage(), e ); } - catch ( DependencyTreeBuilderException e ) + catch ( DependencyGraphBuilderException e ) { throw new EnforcerRuleException( "Could not build dependency tree " + e.getLocalizedMessage(), e ); } diff --git a/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequirePluginVersions.java b/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequirePluginVersions.java index 34f0f20..2437281 100644 --- a/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequirePluginVersions.java +++ b/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequirePluginVersions.java @@ -36,7 +36,6 @@ import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.resolver.ArtifactNotFoundException; import org.apache.maven.artifact.resolver.ArtifactResolutionException; -import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.enforcer.rule.api.EnforcerRuleException; @@ -160,12 +159,6 @@ public class RequirePluginVersions /** The lifecycles. */ private Collection<Lifecycle> lifecycles; - /** The factory. */ - private ArtifactFactory factory; - - /** The resolver. */ - private ArtifactResolver resolver; - /** The local. */ private ArtifactRepository local; @@ -203,8 +196,6 @@ public class RequirePluginVersions session = (MavenSession) helper.evaluate( "${session}" ); pluginManager = (PluginManager) helper.getComponent( PluginManager.class ); - factory = (ArtifactFactory) helper.getComponent( ArtifactFactory.class ); - resolver = (ArtifactResolver) helper.getComponent( ArtifactResolver.class ); local = (ArtifactRepository) helper.evaluate( "${localRepository}" ); remoteRepositories = project.getRemoteArtifactRepositories(); diff --git a/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireUpperBoundDeps.java b/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireUpperBoundDeps.java index 458554a..e56d1b6 100644 --- a/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireUpperBoundDeps.java +++ b/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireUpperBoundDeps.java @@ -26,22 +26,19 @@ import java.util.List; import java.util.Map; 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.artifact.versioning.ArtifactVersion; import org.apache.maven.artifact.versioning.DefaultArtifactVersion; import org.apache.maven.artifact.versioning.OverConstrainedVersionException; import org.apache.maven.enforcer.rule.api.EnforcerRuleException; import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; +import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.logging.Log; 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.apache.maven.shared.dependency.tree.traversal.DependencyNodeVisitor; +import org.apache.maven.shared.dependency.graph.DependencyGraphBuilder; +import org.apache.maven.shared.dependency.graph.DependencyGraphBuilderException; +import org.apache.maven.shared.dependency.graph.DependencyNode; +import org.apache.maven.shared.dependency.graph.traversal.DependencyNodeVisitor; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; @@ -105,18 +102,13 @@ public class RequireUpperBoundDeps { 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 ); + MavenSession session = (MavenSession) helper.evaluate( "${session}" ); + DependencyGraphBuilder dependencyTreeBuilder = + (DependencyGraphBuilder) helper.getComponent( DependencyGraphBuilder.class ); ArtifactFilter filter = null; // we need to evaluate all scopes - DependencyNode node = - dependencyTreeBuilder.buildDependencyTree( project, repository, factory, metadataSource, filter, - collector ); + + DependencyNode node = dependencyTreeBuilder.buildDependencyGraph(session.getProjectBuildingRequest(), filter ); + return node; } catch ( ExpressionEvaluationException e ) @@ -127,7 +119,7 @@ public class RequireUpperBoundDeps { throw new EnforcerRuleException( "Unable to lookup a component " + e.getLocalizedMessage(), e ); } - catch ( DependencyTreeBuilderException e ) + catch ( DependencyGraphBuilderException e ) { throw new EnforcerRuleException( "Could not build dependency tree " + e.getLocalizedMessage(), e ); } diff --git a/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/utils/DependencyVersionMap.java b/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/utils/DependencyVersionMap.java index b6213fa..ec78fc7 100644 --- a/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/utils/DependencyVersionMap.java +++ b/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/utils/DependencyVersionMap.java @@ -26,8 +26,8 @@ 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; +import org.apache.maven.shared.dependency.graph.DependencyNode; +import org.apache.maven.shared.dependency.graph.traversal.DependencyNodeVisitor; /** * @author Brian Fox diff --git a/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/utils/EnforcerRuleUtils.java b/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/utils/EnforcerRuleUtils.java index c122e10..559e187 100644 --- a/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/utils/EnforcerRuleUtils.java +++ b/enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/utils/EnforcerRuleUtils.java @@ -23,7 +23,6 @@ import java.util.List; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; import org.apache.maven.model.Plugin; import org.apache.maven.model.ReportPlugin; @@ -31,6 +30,7 @@ import org.apache.maven.plugin.logging.Log; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; +import org.sonatype.aether.impl.ArtifactResolver; /** * The Class EnforcerRuleUtils. @@ -43,9 +43,6 @@ public class EnforcerRuleUtils /** The factory. */ ArtifactFactory factory; - /** The resolver. */ - ArtifactResolver resolver; - /** The local. */ ArtifactRepository local; diff --git a/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestBannedRepositories.java b/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestBannedRepositories.java index e27ee86..740cf44 100644 --- a/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestBannedRepositories.java +++ b/enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestBannedRepositories.java @@ -23,7 +23,6 @@ import java.util.ArrayList; import java.util.List; import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.DefaultArtifactRepository; import org.apache.maven.enforcer.rule.api.EnforcerRuleException; import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper; import org.codehaus.plexus.PlexusTestCase;