From 381cb0b90461dfb8063fb32506932a5d39c789fe Mon Sep 17 00:00:00 2001 From: Benjamin Bentmann Date: Mon, 3 Aug 2009 10:52:30 +0000 Subject: [PATCH] o Tracked build success/failure for reactor projects in execution result git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@800292 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/maven/execution/BuildFailure.java | 61 +++++++++++++++ .../apache/maven/execution/BuildSuccess.java | 44 +++++++++++ .../apache/maven/execution/BuildSummary.java | 78 +++++++++++++++++++ .../DefaultMavenExecutionResult.java | 21 ++++- .../maven/execution/MavenExecutionResult.java | 16 ++++ .../lifecycle/DefaultLifecycleExecutor.java | 41 +++++++--- 6 files changed, 251 insertions(+), 10 deletions(-) create mode 100644 maven-core/src/main/java/org/apache/maven/execution/BuildFailure.java create mode 100644 maven-core/src/main/java/org/apache/maven/execution/BuildSuccess.java create mode 100644 maven-core/src/main/java/org/apache/maven/execution/BuildSummary.java diff --git a/maven-core/src/main/java/org/apache/maven/execution/BuildFailure.java b/maven-core/src/main/java/org/apache/maven/execution/BuildFailure.java new file mode 100644 index 0000000000..82da4dc0e6 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/execution/BuildFailure.java @@ -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; + } + +} diff --git a/maven-core/src/main/java/org/apache/maven/execution/BuildSuccess.java b/maven-core/src/main/java/org/apache/maven/execution/BuildSuccess.java new file mode 100644 index 0000000000..6d9d7d7652 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/execution/BuildSuccess.java @@ -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 ); + } + +} diff --git a/maven-core/src/main/java/org/apache/maven/execution/BuildSummary.java b/maven-core/src/main/java/org/apache/maven/execution/BuildSummary.java new file mode 100644 index 0000000000..93754d8478 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/execution/BuildSummary.java @@ -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; + } + +} diff --git a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionResult.java b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionResult.java index b70c2b7cd2..bee87ced4a 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionResult.java +++ b/maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionResult.java @@ -21,7 +21,9 @@ package org.apache.maven.execution; 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 @@ public class DefaultMavenExecutionResult private List exceptions; private ExceptionSummary exceptionSummary; - + + private Map buildSummaries; + public MavenExecutionResult setProject( MavenProject project ) { this.project = project; @@ -110,4 +114,19 @@ public class DefaultMavenExecutionResult { 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(); + } + buildSummaries.put( summary.getProject(), summary ); + } + } diff --git a/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionResult.java b/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionResult.java index 8d426b5e97..ae6dff0362 100644 --- a/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionResult.java +++ b/maven-core/src/main/java/org/apache/maven/execution/MavenExecutionResult.java @@ -52,4 +52,20 @@ public interface MavenExecutionResult 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 ); + } diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java index f75b23fe20..1726388f93 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/DefaultLifecycleExecutor.java @@ -35,7 +35,10 @@ import org.apache.maven.artifact.repository.ArtifactRepository; 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 @@ public class DefaultLifecycleExecutor { // TODO: Use a listener here instead of loggers - logger.info( "Build Order:" ); + logger.info( "Build Order:" ); logger.info( "" ); @@ -148,7 +151,9 @@ public class DefaultLifecycleExecutor } ClassLoader oldContextClassLoader = Thread.currentThread().getContextClassLoader(); - + + MavenExecutionResult result = session.getResult(); + for ( MavenProject currentProject : session.getProjects() ) { if ( session.isBlackListed( currentProject ) ) @@ -161,6 +166,8 @@ public class DefaultLifecycleExecutor logger.info( "Building " + currentProject.getName() ); + long buildStartTime = System.currentTimeMillis(); + try { session.setCurrentProject( currentProject ); @@ -171,7 +178,8 @@ public class DefaultLifecycleExecutor 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 @@ public class DefaultLifecycleExecutor { 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 @@ public class DefaultLifecycleExecutor // // 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 @@ public class DefaultLifecycleExecutor pluginDescriptor.setClassRealm( pluginManager.getPluginRealm( session, pluginDescriptor ) ); } - mojoExecution.setMojoDescriptor( mojoDescriptor ); - populateMojoExecutionConfiguration( project, mojoExecution, false ); calculateForkedExecutions( mojoExecution, session, project, new HashSet() );