You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by be...@apache.org on 2009/08/03 12:52:31 UTC

svn commit: r800292 - in /maven/components/trunk/maven-core/src/main/java/org/apache/maven: execution/ lifecycle/

Author: bentmann
Date: Mon Aug  3 10:52:30 2009
New Revision: 800292

URL: http://svn.apache.org/viewvc?rev=800292&view=rev
Log:
o Tracked build success/failure for reactor projects in execution result

Added:
    maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/BuildFailure.java   (with props)
    maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/BuildSuccess.java   (with props)
    maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/BuildSummary.java   (with props)
Modified:
    maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionResult.java
    maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionResult.java
    maven/components/trunk/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java

Added: maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/BuildFailure.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/BuildFailure.java?rev=800292&view=auto
==============================================================================
--- maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/BuildFailure.java (added)
+++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/BuildFailure.java Mon Aug  3 10:52:30 2009
@@ -0,0 +1,61 @@
+package org.apache.maven.execution;
+
+/*
+ * 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 org.apache.maven.project.MavenProject;
+
+/**
+ * Summarizes the result of a failed project build in the reactor.
+ * 
+ * @author Benjamin Bentmann
+ */
+public class BuildFailure
+    extends BuildSummary
+{
+
+    /**
+     * The cause of the build failure.
+     */
+    private final Throwable cause;
+
+    /**
+     * Creates a new build summary for the specified project.
+     * 
+     * @param project The project being summarized, must not be {@code null}.
+     * @param time The build time of the project in milliseconds.
+     * @param cause The cause of the build failure, may be {@code null}.
+     */
+    public BuildFailure( MavenProject project, long time, Throwable cause )
+    {
+        super( project, time );
+        this.cause = cause;
+    }
+
+    /**
+     * Gets the cause of the build failure.
+     * 
+     * @return The cause of the build failure or {@code null} if unknown.
+     */
+    public Throwable getCause()
+    {
+        return cause;
+    }
+
+}

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

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

Added: maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/BuildSuccess.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/BuildSuccess.java?rev=800292&view=auto
==============================================================================
--- maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/BuildSuccess.java (added)
+++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/BuildSuccess.java Mon Aug  3 10:52:30 2009
@@ -0,0 +1,44 @@
+package org.apache.maven.execution;
+
+/*
+ * 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 org.apache.maven.project.MavenProject;
+
+/**
+ * Summarizes the result of a successful project build in the reactor.
+ * 
+ * @author Benjamin Bentmann
+ */
+public class BuildSuccess
+    extends BuildSummary
+{
+
+    /**
+     * Creates a new build summary for the specified project.
+     * 
+     * @param project The project being summarized, must not be {@code null}.
+     * @param time The build time of the project in milliseconds.
+     */
+    public BuildSuccess( MavenProject project, long time )
+    {
+        super( project, time );
+    }
+
+}

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

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

Added: maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/BuildSummary.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/BuildSummary.java?rev=800292&view=auto
==============================================================================
--- maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/BuildSummary.java (added)
+++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/BuildSummary.java Mon Aug  3 10:52:30 2009
@@ -0,0 +1,78 @@
+package org.apache.maven.execution;
+
+/*
+ * 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 org.apache.maven.project.MavenProject;
+
+/**
+ * Summarizes the result of a project build in the reactor.
+ * 
+ * @author Benjamin Bentmann
+ */
+public abstract class BuildSummary
+{
+
+    /**
+     * The project being summarized.
+     */
+    private final MavenProject project;
+
+    /**
+     * The build time of the project in milliseconds.
+     */
+    private final long time;
+
+    /**
+     * Creates a new build summary for the specified project.
+     * 
+     * @param project The project being summarized, must not be {@code null}.
+     * @param time The build time of the project in milliseconds.
+     */
+    protected BuildSummary( MavenProject project, long time )
+    {
+        if ( project == null )
+        {
+            throw new IllegalArgumentException( "project missing" );
+        }
+        this.project = project;
+        this.time = time;
+    }
+
+    /**
+     * Gets the project being summarized.
+     * 
+     * @return The project being summarized, never {@code null}.
+     */
+    public MavenProject getProject()
+    {
+        return project;
+    }
+
+    /**
+     * Gets the build time of the project in milliseconds.
+     * 
+     * @return The build time of the project in milliseconds.
+     */
+    public long getTime()
+    {
+        return time;
+    }
+
+}

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

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

Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionResult.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionResult.java?rev=800292&r1=800291&r2=800292&view=diff
==============================================================================
--- maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionResult.java (original)
+++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionResult.java Mon Aug  3 10:52:30 2009
@@ -21,7 +21,9 @@
 
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.IdentityHashMap;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
 import org.apache.maven.exception.ExceptionSummary;
@@ -40,7 +42,9 @@
     private List<Throwable> exceptions;
 
     private ExceptionSummary exceptionSummary;
-    
+
+    private Map<MavenProject, BuildSummary> buildSummaries;
+
     public MavenExecutionResult setProject( MavenProject project )
     {
         this.project = project;
@@ -110,4 +114,19 @@
     {
         return exceptionSummary;
     }
+
+    public BuildSummary getBuildSummary( MavenProject project )
+    {
+        return ( buildSummaries != null ) ? buildSummaries.get( project ) : null;
+    }
+
+    public void addBuildSummary( BuildSummary summary )
+    {
+        if ( buildSummaries == null )
+        {
+            buildSummaries = new IdentityHashMap<MavenProject, BuildSummary>();
+        }
+        buildSummaries.put( summary.getProject(), summary );
+    }
+
 }

Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionResult.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionResult.java?rev=800292&r1=800291&r2=800292&view=diff
==============================================================================
--- maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionResult.java (original)
+++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionResult.java Mon Aug  3 10:52:30 2009
@@ -52,4 +52,20 @@
         
     MavenExecutionResult setExceptionSummary( ExceptionSummary exceptionSummary );
     ExceptionSummary getExceptionSummary();
+
+    /**
+     * Gets the build summary for the specified project.
+     * 
+     * @param project The project to get the build summary for, must not be {@code null}.
+     * @return The build summary for the project or {@code null} if the project has not been built (yet).
+     */
+    BuildSummary getBuildSummary( MavenProject project );
+
+    /**
+     * Add the specified build summary.
+     * 
+     * @param summary The build summary to add, must not be {@code null}.
+     */
+    void addBuildSummary( BuildSummary summary );
+
 }

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=800292&r1=800291&r2=800292&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 Mon Aug  3 10:52:30 2009
@@ -35,7 +35,10 @@
 import org.apache.maven.artifact.repository.metadata.Metadata;
 import org.apache.maven.artifact.repository.metadata.RepositoryMetadataReadException;
 import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
+import org.apache.maven.execution.BuildFailure;
+import org.apache.maven.execution.BuildSuccess;
 import org.apache.maven.execution.MavenExecutionRequest;
+import org.apache.maven.execution.MavenExecutionResult;
 import org.apache.maven.execution.MavenSession;
 import org.apache.maven.lifecycle.mapping.LifecycleMapping;
 import org.apache.maven.model.Dependency;
@@ -122,7 +125,7 @@
     {
         // TODO: Use a listener here instead of loggers
         
-        logger.info(  "Build Order:" );
+        logger.info( "Build Order:" );
         
         logger.info( "" );
         
@@ -148,7 +151,9 @@
         }
 
         ClassLoader oldContextClassLoader = Thread.currentThread().getContextClassLoader();
-                
+
+        MavenExecutionResult result = session.getResult();
+
         for ( MavenProject currentProject : session.getProjects() )
         {
             if ( session.isBlackListed( currentProject ) )
@@ -161,6 +166,8 @@
 
             logger.info( "Building " + currentProject.getName() );
 
+            long buildStartTime = System.currentTimeMillis();
+
             try
             {
                 session.setCurrentProject( currentProject );
@@ -171,7 +178,8 @@
                     Thread.currentThread().setContextClassLoader( projectRealm );
                 }
 
-                MavenExecutionPlan executionPlan = calculateExecutionPlan( session, goals.toArray( new String[] {} ) );
+                MavenExecutionPlan executionPlan =
+                    calculateExecutionPlan( session, goals.toArray( new String[goals.size()] ) );
 
                 //TODO: once we have calculated the build plan then we should accurately be able to download
                 // the project dependencies. Having it happen in the plugin manager is a tangled mess. We can optimize this
@@ -199,11 +207,18 @@
                 {
                     execute( currentProject, session, mojoExecution );
                 }
-                
+
+                long buildEndTime = System.currentTimeMillis();
+
+                result.addBuildSummary( new BuildSuccess( currentProject, buildEndTime - buildStartTime ) );
             }
             catch ( Exception e )
             {
-                session.getResult().addException( e );
+                result.addException( e );
+
+                long buildEndTime = System.currentTimeMillis();
+
+                result.addBuildSummary( new BuildFailure( currentProject, buildEndTime - buildStartTime, e ) );
 
                 if ( MavenExecutionRequest.REACTOR_FAIL_NEVER.equals( session.getReactorFailureBehavior() ) )
                 {
@@ -298,8 +313,18 @@
             //
             // org.apache.maven.plugins:maven-remote-resources-plugin:1.0:process
             //                        
-            MojoDescriptor mojoDescriptor = pluginManager.getMojoDescriptor( mojoExecution.getPlugin(), mojoExecution.getGoal(), session
-                .getLocalRepository(), project.getPluginArtifactRepositories() );
+
+            MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
+
+            if ( mojoDescriptor == null )
+            {
+                mojoDescriptor =
+                    pluginManager.getMojoDescriptor( mojoExecution.getPlugin(), mojoExecution.getGoal(),
+                                                     session.getLocalRepository(),
+                                                     project.getPluginArtifactRepositories() );
+
+                mojoExecution.setMojoDescriptor( mojoDescriptor );
+            }
 
             PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
             if ( pluginDescriptor.getPlugin().isExtensions() )
@@ -307,8 +332,6 @@
                 pluginDescriptor.setClassRealm( pluginManager.getPluginRealm( session, pluginDescriptor ) );
             }
 
-            mojoExecution.setMojoDescriptor( mojoDescriptor );
-
             populateMojoExecutionConfiguration( project, mojoExecution, false );
 
             calculateForkedExecutions( mojoExecution, session, project, new HashSet<MojoDescriptor>() );