[MNG-6092] warn if prerequisites.maven is used for non-plugin projects
Project: http://git-wip-us.apache.org/repos/asf/maven/repo Commit: http://git-wip-us.apache.org/repos/asf/maven/commit/4604c49e Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/4604c49e Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/4604c49e Branch: refs/heads/MNG-2199-IT Commit: 4604c49ee442fef48c0d3efe35fb85d2f0784131 Parents: 017dcaf Author: Karl Heinz Marbaise <khmarba...@apache.org> Authored: Sat Oct 1 16:29:32 2016 +0200 Committer: Karl Heinz Marbaise <khmarba...@apache.org> Committed: Sun Jan 29 21:16:35 2017 +0100 ---------------------------------------------------------------------- .../java/org/apache/maven/DefaultMaven.java | 62 +++++++++++++------- 1 file changed, 41 insertions(+), 21 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven/blob/4604c49e/maven-core/src/main/java/org/apache/maven/DefaultMaven.java ---------------------------------------------------------------------- diff --git a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java index da17830..15b946e 100644 --- a/maven-core/src/main/java/org/apache/maven/DefaultMaven.java +++ b/maven-core/src/main/java/org/apache/maven/DefaultMaven.java @@ -42,6 +42,7 @@ import org.apache.maven.graph.GraphBuilder; import org.apache.maven.internal.aether.DefaultRepositorySystemSessionFactory; import org.apache.maven.lifecycle.internal.ExecutionEventCatapult; import org.apache.maven.lifecycle.internal.LifecycleStarter; +import org.apache.maven.model.Prerequisites; import org.apache.maven.model.building.ModelProblem; import org.apache.maven.model.building.Result; import org.apache.maven.plugin.LegacySupport; @@ -111,7 +112,7 @@ public class DefaultMaven } catch ( RuntimeException e ) { - //TODO Hack to make the cycle detection the same for the new graph builder + // TODO Hack to make the cycle detection the same for the new graph builder if ( e.getCause() instanceof ProjectCycleException ) { result = addExceptionToResult( new DefaultMavenExecutionResult(), e.getCause() ); @@ -160,7 +161,7 @@ public class DefaultMaven // @SuppressWarnings( "checkstyle:methodlength" ) private MavenExecutionResult doExecute( MavenExecutionRequest request ) - { + { request.setStartTime( new Date() ); MavenExecutionResult result = new DefaultMavenExecutionResult(); @@ -203,11 +204,12 @@ public class DefaultMaven { try { - for ( AbstractMavenLifecycleParticipant listener : getLifecycleParticipants( Collections - .<MavenProject>emptyList() ) ) + // CHECKSTYLE_OFF: LineLength + for ( AbstractMavenLifecycleParticipant listener : getLifecycleParticipants( Collections.<MavenProject>emptyList() ) ) { listener.afterSessionStart( session ); } + // CHECKSTYLE_ON: LineLength } catch ( MavenExecutionException e ) { @@ -217,12 +219,11 @@ public class DefaultMaven eventCatapult.fire( ExecutionEvent.Type.ProjectDiscoveryStarted, session, null ); Result<? extends ProjectDependencyGraph> graphResult = buildGraph( session, result ); - + if ( graphResult.hasErrors() ) { - return addExceptionToResult( result, - Iterables.toArray( graphResult.getProblems(), ModelProblem.class )[0] - .getException() ); + return addExceptionToResult( result, Iterables.toArray( graphResult.getProblems(), + ModelProblem.class )[0].getException() ); } try @@ -283,14 +284,13 @@ public class DefaultMaven // Note that participants may affect the topological order of the projects but it is // not expected that a participant will add or remove projects from the session. // - + graphResult = buildGraph( session, result ); - + if ( graphResult.hasErrors() ) { - return addExceptionToResult( result, - Iterables.toArray( graphResult.getProblems(), ModelProblem.class )[0] - .getException() ); + return addExceptionToResult( result, Iterables.toArray( graphResult.getProblems(), + ModelProblem.class )[0].getException() ); } try @@ -304,6 +304,8 @@ public class DefaultMaven result.setProject( session.getTopLevelProject() ); + validatePrerequisitesForNonMavenPluginProjects( session.getProjects() ); + lifecycleStarter.execute( session ); validateActivatedProfiles( session.getProjects(), request.getActiveProfiles() ); @@ -346,7 +348,7 @@ public class DefaultMaven Thread.currentThread().setContextClassLoader( originalClassLoader ); } } - + public RepositorySystemSession newRepositorySession( MavenExecutionRequest request ) { return repositorySessionFactory.newRepositorySession( request ); @@ -369,8 +371,7 @@ public class DefaultMaven private Collection<AbstractMavenLifecycleParticipant> getLifecycleParticipants( Collection<MavenProject> projects ) { - Collection<AbstractMavenLifecycleParticipant> lifecycleListeners = - new LinkedHashSet<>(); + Collection<AbstractMavenLifecycleParticipant> lifecycleListeners = new LinkedHashSet<>(); ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader(); try @@ -425,6 +426,25 @@ public class DefaultMaven return result; } + private void validatePrerequisitesForNonMavenPluginProjects( List<MavenProject> projects ) + { + for ( MavenProject mavenProject : projects ) + { + if ( !"maven-plugin".equals( mavenProject.getPackaging() ) ) + { + Prerequisites prerequisites = mavenProject.getPrerequisites(); + if ( prerequisites != null && prerequisites.getMaven() != null ) + { + logger.warn( "The project " + mavenProject.getId() + " uses prerequisites" + + " which is only intended for maven-plugin projects " + + "but not for non maven-plugin projects. " + + "For such purposes you should use the maven-enforcer-plugin. " + + "See https://maven.apache.org/enforcer/enforcer-rules/requireMavenVersion.html" ); + } + } + } + } + private void validateActivatedProfiles( List<MavenProject> projects, List<String> activeProfileIds ) { Collection<String> notActivatedProfileIds = new LinkedHashSet<>( activeProfileIds ); @@ -486,7 +506,7 @@ public class DefaultMaven return index; } - private Result<? extends ProjectDependencyGraph> buildGraph( MavenSession session, MavenExecutionResult result ) + private Result<? extends ProjectDependencyGraph> buildGraph( MavenSession session, MavenExecutionResult result ) { Result<? extends ProjectDependencyGraph> graphResult = graphBuilder.build( session ); for ( ModelProblem problem : graphResult.getProblems() ) @@ -506,12 +526,12 @@ public class DefaultMaven ProjectDependencyGraph projectDependencyGraph = graphResult.get(); session.setProjects( projectDependencyGraph.getSortedProjects() ); session.setAllProjects( projectDependencyGraph.getSortedProjects() ); - session.setProjectDependencyGraph( projectDependencyGraph ); + session.setProjectDependencyGraph( projectDependencyGraph ); } - - return graphResult; + + return graphResult; } - + @Deprecated // 5 January 2014 protected Logger getLogger()