You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by kh...@apache.org on 2016/10/01 15:04:02 UTC

maven git commit: [MNG-6092] warn if prerequisites.maven is used for non-plugin projects

Repository: maven
Updated Branches:
  refs/heads/master 62e840fc4 -> c10d813c6


[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/c10d813c
Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/c10d813c
Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/c10d813c

Branch: refs/heads/master
Commit: c10d813c69818a81a0b202b7bc48533db83e6e96
Parents: 62e840f
Author: Karl Heinz Marbaise <kh...@apache.org>
Authored: Sat Oct 1 16:29:32 2016 +0200
Committer: Karl Heinz Marbaise <kh...@apache.org>
Committed: Sat Oct 1 17:01:46 2016 +0200

----------------------------------------------------------------------
 .../java/org/apache/maven/DefaultMaven.java     | 60 +++++++++++++-------
 1 file changed, 39 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven/blob/c10d813c/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..d6f58b8 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,8 +204,7 @@ public class DefaultMaven
     {
         try
         {
-            for ( AbstractMavenLifecycleParticipant listener : getLifecycleParticipants( Collections
-                .<MavenProject>emptyList() ) )
+            for ( AbstractMavenLifecycleParticipant listener : getLifecycleParticipants( Collections.<MavenProject>emptyList() ) )
             {
                 listener.afterSessionStart( session );
             }
@@ -217,12 +217,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 +282,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 +302,8 @@ public class DefaultMaven
 
             result.setProject( session.getTopLevelProject() );
 
+            validatePrerequisitesForNonMavenPluginProjects( session.getProjects() );
+
             lifecycleStarter.execute( session );
 
             validateActivatedProfiles( session.getProjects(), request.getActiveProfiles() );
@@ -346,7 +346,7 @@ public class DefaultMaven
             Thread.currentThread().setContextClassLoader( originalClassLoader );
         }
     }
-    
+
     public RepositorySystemSession newRepositorySession( MavenExecutionRequest request )
     {
         return repositorySessionFactory.newRepositorySession( request );
@@ -369,8 +369,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 +424,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 +504,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 +524,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()