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
This commit is contained in:
Benjamin Bentmann 2009-08-03 10:52:30 +00:00
parent 898653d5fc
commit 381cb0b904
6 changed files with 251 additions and 10 deletions

View File

@ -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;
}
}

View File

@ -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 );
}
}

View File

@ -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;
}
}

View File

@ -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;
@ -41,6 +43,8 @@ public class DefaultMavenExecutionResult
private ExceptionSummary exceptionSummary;
private Map<MavenProject, BuildSummary> 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<MavenProject, BuildSummary>();
}
buildSummaries.put( summary.getProject(), summary );
}
}

View File

@ -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 );
}

View File

@ -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;
@ -149,6 +152,8 @@ 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
@ -200,10 +208,17 @@ 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<MojoDescriptor>() );