maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jvan...@apache.org
Subject svn commit: r572214 - in /maven/components/trunk: maven-core/src/main/java/org/apache/maven/ maven-core/src/main/java/org/apache/maven/lifecycle/ maven-embedder/src/main/java/org/apache/maven/cli/
Date Mon, 03 Sep 2007 02:35:05 GMT
Author: jvanzyl
Date: Sun Sep  2 19:35:05 2007
New Revision: 572214

URL: http://svn.apache.org/viewvc?rev=572214&view=rev
Log:
o adding a validation method to the lifecycle executor so that I can tell users what is wrong
before actually trying
  to execute the lifecycle. Trying to do this validation shows in detail how tangled some
of our code is as I need
  to create the dispatcher in order to create the session which is required to make the reactorManager
which 
  is required to get the project required to validate the goal name ... yah.

Added:
    maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/TaskValidationResult.java
  (with props)
Modified:
    maven/components/trunk/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
    maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
    maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java
    maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java

Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/DefaultMaven.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/main/java/org/apache/maven/DefaultMaven.java?rev=572214&r1=572213&r2=572214&view=diff
==============================================================================
--- maven/components/trunk/maven-core/src/main/java/org/apache/maven/DefaultMaven.java (original)
+++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/DefaultMaven.java Sun
Sep  2 19:35:05 2007
@@ -37,7 +37,7 @@
 import org.apache.maven.extension.BuildExtensionScanner;
 import org.apache.maven.extension.ExtensionScanningException;
 import org.apache.maven.lifecycle.LifecycleExecutor;
-import org.apache.maven.lifecycle.LifecycleUtils;
+import org.apache.maven.lifecycle.TaskValidationResult;
 import org.apache.maven.monitor.event.DefaultEventDispatcher;
 import org.apache.maven.monitor.event.EventDispatcher;
 import org.apache.maven.monitor.event.MavenEvents;
@@ -171,7 +171,16 @@
     {
         request.setStartTime( new Date() );
 
-        initializeBuildContext( request );
+        MavenExecutionResult result = new DefaultMavenExecutionResult();
+
+        ReactorManager reactorManager = createReactorManager(
+            request,
+            result );
+
+        if ( result.hasExceptions() )
+        {
+            return result;
+        }
 
         EventDispatcher dispatcher = new DefaultEventDispatcher( request.getEventMonitors()
);
 
@@ -181,21 +190,27 @@
             event,
             request.getBaseDirectory() );
 
-        MavenExecutionResult result = new DefaultMavenExecutionResult();
+        MavenSession session = createSession(
+            request,
+            reactorManager,
+            dispatcher );
 
-        getLogger().info( "Scanning for projects..." );
+        for ( Iterator i = request.getGoals().iterator(); i.hasNext(); )
+        {
+            String goal = (String) i.next();
 
-        ReactorManager reactorManager = createReactorManager(
-            request,
-            result );
+            TaskValidationResult tvr = lifecycleExecutor.isTaskValid( goal, session, reactorManager.getTopLevelProject()
);
 
-        // Check and make sure the creation of the reactor manager didn't cause a problem.
+            if ( !tvr.isTaskValid() )
+            {
+                result.addException( new BuildFailureException( tvr.getMessage() ) );
 
-        if ( result.hasExceptions() )
-        {
-            return result;
+                return result;
+            }
         }
 
+        getLogger().info( "Scanning for projects..." );
+
         if ( reactorManager.hasMultipleProjects() )
         {
             getLogger().info( "Reactor build order: " );
@@ -208,10 +223,7 @@
             }
         }
 
-        MavenSession session = createSession(
-            request,
-            reactorManager,
-            dispatcher );
+        initializeBuildContext( request );
 
         try
         {

Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java?rev=572214&r1=572213&r2=572214&view=diff
==============================================================================
--- maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
(original)
+++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java
Sun Sep  2 19:35:05 2007
@@ -532,6 +532,53 @@
         // if NEVER, don't blacklist
         return false;
     }
+    
+    public TaskValidationResult isTaskValid( String task, MavenSession session, MavenProject
rootProject )
+    {
+        if ( LifecycleUtils.isValidPhaseName( task ) )
+        {
+            return new TaskValidationResult();
+        }
+        else
+        {
+            MojoDescriptor mojo = null;
+            // definitely a CLI goal, can use prefix
+            try
+            {
+                mojo = getMojoDescriptorForDirectInvocation(
+                    task,
+                    session,
+                    rootProject );
+
+                return new TaskValidationResult();
+            }
+            catch ( PluginLoaderException e )
+            {
+                // TODO: shouldn't hit this, investigate using the same resolution logic
as
+                // others for plugins in the reactor
+
+                return new TaskValidationResult( task, "Cannot find mojo descriptor for:
\'" + task
+                        + "\' - Treating as non-aggregator." );
+            }
+            catch ( LifecycleSpecificationException e )
+            {
+                String message =
+                    "Invalid task '"
+                        + task
+                        + "': you must specify a valid lifecycle phase, or"
+                        + " a goal in the format plugin:goal or pluginGroupId:pluginArtifactId:pluginVersion:goal";
+
+                return new TaskValidationResult( task, message );
+
+            }
+            catch ( LifecycleLoaderException e )
+            {
+                String message = "Cannot find plugin to match task '" + task + "'.";
+
+                return new TaskValidationResult( task, message );
+            }
+        }
+    }
 
     private List segmentTaskListByAggregationNeeds( final List tasks,
                                                     final MavenSession session,
@@ -542,8 +589,8 @@
 
         if ( rootProject != null )
         {
-
             TaskSegment currentSegment = null;
+
             for ( Iterator it = tasks.iterator(); it.hasNext(); )
             {
                 String task = (String) it.next();
@@ -568,7 +615,7 @@
                 else
                 {
                     MojoDescriptor mojo = null;
-                    // definitely a CLI goal, can use prefix
+
                     try
                     {
                         mojo = getMojoDescriptorForDirectInvocation(
@@ -576,37 +623,10 @@
                             session,
                             rootProject );
                     }
-                    catch ( PluginLoaderException e )
+                    catch ( Exception e )
                     {
-                        // TODO: shouldn't hit this, investigate using the same resolution
logic as
-                        // others for plugins in the reactor
-                        getLogger().info(
-                            "Cannot find mojo descriptor for: \'" + task
-                                + "\' - Treating as non-aggregator." );
-
-                        getLogger().debug(
-                            "",
-                            e );
-                    }
-                    catch ( LifecycleSpecificationException e )
-                    {
-                        String message =
-                            "Invalid task '"
-                                + task
-                                + "': you must specify a valid lifecycle phase, or"
-                                + " a goal in the format plugin:goal or pluginGroupId:pluginArtifactId:pluginVersion:goal";
-
-                        throw new BuildFailureException(
-                            message,
-                            e );
-                    }
-                    catch ( LifecycleLoaderException e )
-                    {
-                        String message = "Cannot find plugin to match task '" + task + "'.";
-
-                        throw new BuildFailureException(
-                            message,
-                            e );
+                        // Won't happen as we've validated. So we need to change the code
so that
+                        // we don't have to do this.
                     }
 
                     // if the mojo descriptor was found, determine aggregator status according
to:

Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java?rev=572214&r1=572213&r2=572214&view=diff
==============================================================================
--- maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java
(original)
+++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/LifecycleExecutor.java
Sun Sep  2 19:35:05 2007
@@ -20,6 +20,7 @@
  */
 
 import org.apache.maven.BuildFailureException;
+import org.apache.maven.project.MavenProject;
 import org.apache.maven.execution.MavenSession;
 import org.apache.maven.execution.ReactorManager;
 import org.apache.maven.monitor.event.EventDispatcher;
@@ -31,6 +32,8 @@
 public interface LifecycleExecutor
 {
     String ROLE = LifecycleExecutor.class.getName();
+
+    TaskValidationResult isTaskValid( String task, MavenSession session, MavenProject rootProject
);        
 
     void execute( MavenSession session, ReactorManager rm, EventDispatcher dispatcher )
         throws LifecycleExecutionException, BuildFailureException;

Added: maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/TaskValidationResult.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/TaskValidationResult.java?rev=572214&view=auto
==============================================================================
--- maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/TaskValidationResult.java
(added)
+++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/TaskValidationResult.java
Sun Sep  2 19:35:05 2007
@@ -0,0 +1,35 @@
+package org.apache.maven.lifecycle;
+
+/** @author Jason van Zyl */
+public class TaskValidationResult
+{
+    private String invalidTask;
+
+    private String message;
+
+    public TaskValidationResult()
+    {
+    }
+
+    public TaskValidationResult( String invalidTask, String message )
+    {
+        this.invalidTask = invalidTask;
+
+        this.message = message;
+    }
+
+    public String getInvalidTask()
+    {
+        return invalidTask;
+    }
+
+    public String getMessage()
+    {
+        return message;
+    }
+
+    public boolean isTaskValid()
+    {
+        return invalidTask == null;
+    }
+}

Propchange: maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/TaskValidationResult.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/TaskValidationResult.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java?rev=572214&r1=572213&r2=572214&view=diff
==============================================================================
--- maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
(original)
+++ maven/components/trunk/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
Sun Sep  2 19:35:05 2007
@@ -402,7 +402,9 @@
                                    Exception e,
                                    boolean show )
     {
+        System.err.println();
         System.err.println( message );
+        System.err.println();
 
         if ( show )
         {



Mime
View raw message