mirror of
https://github.com/apache/maven.git
synced 2025-02-25 03:45:09 +00:00
Building maven projects works; it runs all integration test projects,
and when one fails (FAIL_AT_END) the build of this project fails too. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@279336 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
69c6305347
commit
fdc4461eb7
@ -18,14 +18,15 @@
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
import org.apache.maven.execution.MavenExecutionResponse;
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
|
|
||||||
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
|
|
||||||
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
|
|
||||||
import org.apache.maven.execution.MavenSession;
|
import org.apache.maven.execution.MavenSession;
|
||||||
|
import org.apache.maven.execution.ReactorManager;
|
||||||
|
import org.apache.maven.lifecycle.LifecycleExecutionException;
|
||||||
|
import org.apache.maven.lifecycle.LifecycleExecutor;
|
||||||
import org.apache.maven.plugin.AbstractMojo;
|
import org.apache.maven.plugin.AbstractMojo;
|
||||||
import org.apache.maven.plugin.MojoExecutionException;
|
import org.apache.maven.plugin.MojoExecutionException;
|
||||||
import org.apache.maven.profiles.DefaultProfileManager;
|
import org.apache.maven.profiles.DefaultProfileManager;
|
||||||
@ -34,6 +35,7 @@
|
|||||||
import org.apache.maven.project.ProjectBuildingException;
|
import org.apache.maven.project.ProjectBuildingException;
|
||||||
import org.apache.maven.settings.Settings;
|
import org.apache.maven.settings.Settings;
|
||||||
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
|
||||||
|
import org.codehaus.plexus.util.dag.CycleDetectedException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @goal fork
|
* @goal fork
|
||||||
@ -45,6 +47,11 @@
|
|||||||
public class ForkMojo
|
public class ForkMojo
|
||||||
extends AbstractMojo
|
extends AbstractMojo
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @parameter expression="${component.org.apache.maven.lifecycle.LifecycleExecutor}"
|
||||||
|
*/
|
||||||
|
private LifecycleExecutor lifecycleExecutor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @parameter expression="${session}"
|
* @parameter expression="${session}"
|
||||||
*/
|
*/
|
||||||
@ -55,7 +62,6 @@ public class ForkMojo
|
|||||||
*/
|
*/
|
||||||
private Settings settings;
|
private Settings settings;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @parameter expression="${project}"
|
* @parameter expression="${project}"
|
||||||
*/
|
*/
|
||||||
@ -64,71 +70,103 @@ public class ForkMojo
|
|||||||
/**
|
/**
|
||||||
* @parameter expression="${project.basedir}/src/it/"
|
* @parameter expression="${project.basedir}/src/it/"
|
||||||
*/
|
*/
|
||||||
private File projectsDir;
|
private File integrationTestsDirectory;
|
||||||
|
|
||||||
|
|
||||||
private ArtifactRepository artifactRepo;
|
|
||||||
|
|
||||||
private MavenProjectBuilder projectBuilder;
|
|
||||||
|
|
||||||
|
|
||||||
public void execute()
|
public void execute()
|
||||||
throws MojoExecutionException
|
throws MojoExecutionException
|
||||||
{
|
|
||||||
initComponents();
|
|
||||||
|
|
||||||
buildProjects( listITPoms() );
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initComponents()
|
|
||||||
throws MojoExecutionException
|
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
artifactRepo = createLocalRepository();
|
buildProjects();
|
||||||
|
|
||||||
projectBuilder = (MavenProjectBuilder)
|
|
||||||
session.getContainer().lookup( MavenProjectBuilder.ROLE );
|
|
||||||
|
|
||||||
if ( projectBuilder == null )
|
|
||||||
throw new MojoExecutionException( "Lookup for MavenProjectBuilder returned null" );
|
|
||||||
}
|
}
|
||||||
catch (ComponentLookupException e)
|
catch ( CycleDetectedException e )
|
||||||
{
|
{
|
||||||
throw new MojoExecutionException( "Cannot get a MavenProjectBuilder", e);
|
throw new MojoExecutionException( "Error building projects", e );
|
||||||
|
}
|
||||||
|
catch ( LifecycleExecutionException e )
|
||||||
|
{
|
||||||
|
throw new MojoExecutionException( "Error building projects", e );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buildProjects( List poms )
|
private void buildProjects()
|
||||||
|
throws CycleDetectedException, LifecycleExecutionException, MojoExecutionException
|
||||||
{
|
{
|
||||||
getLog().info( "Building " + poms.size() + " integration test projects.." );
|
List projects = collectProjects();
|
||||||
|
|
||||||
|
ReactorManager rm = new ReactorManager( projects );
|
||||||
|
|
||||||
|
rm.setFailureBehavior( ReactorManager.FAIL_AT_END );
|
||||||
|
|
||||||
|
List goals = Collections.singletonList( "package" );
|
||||||
|
|
||||||
|
MavenSession forkedSession = new MavenSession(
|
||||||
|
session.getContainer(), session.getSettings(),
|
||||||
|
session.getLocalRepository(),
|
||||||
|
session.getEventDispatcher(),
|
||||||
|
rm, goals, integrationTestsDirectory.toString()
|
||||||
|
);
|
||||||
|
|
||||||
|
MavenExecutionResponse response = lifecycleExecutor.execute( forkedSession,
|
||||||
|
rm, forkedSession.getEventDispatcher()
|
||||||
|
);
|
||||||
|
|
||||||
|
if ( response.isExecutionFailure() )
|
||||||
|
{
|
||||||
|
throw new MojoExecutionException(
|
||||||
|
"Integration test failed" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List collectProjects()
|
||||||
|
throws MojoExecutionException
|
||||||
|
{
|
||||||
|
List projects = new ArrayList();
|
||||||
|
|
||||||
|
MavenProjectBuilder projectBuilder;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
projectBuilder = (MavenProjectBuilder)
|
||||||
|
session.getContainer().lookup( MavenProjectBuilder.ROLE );
|
||||||
|
}
|
||||||
|
catch ( ComponentLookupException e )
|
||||||
|
{
|
||||||
|
throw new MojoExecutionException( "Cannot get a MavenProjectBuilder", e );
|
||||||
|
}
|
||||||
|
|
||||||
|
List poms = listITPoms();
|
||||||
|
|
||||||
for ( Iterator i = poms.iterator(); i.hasNext(); )
|
for ( Iterator i = poms.iterator(); i.hasNext(); )
|
||||||
{
|
{
|
||||||
|
File pom = (File) i.next();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
MavenProject p = buildProject( (File) i.next() );
|
MavenProject p = projectBuilder.build(
|
||||||
|
pom, session.getLocalRepository(),
|
||||||
|
new DefaultProfileManager( session.getContainer() ) );
|
||||||
|
|
||||||
|
getLog().debug( "Adding project " + p.getId() );
|
||||||
|
|
||||||
|
projects.add( p );
|
||||||
|
|
||||||
getLog().info("Building " + p.getId() );
|
|
||||||
}
|
}
|
||||||
catch (ProjectBuildingException e)
|
catch (ProjectBuildingException e)
|
||||||
{
|
{
|
||||||
getLog().error("Build Error", e);
|
throw new MojoExecutionException( "Error loading " + pom, e );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private MavenProject buildProject( File pom )
|
return projects;
|
||||||
throws ProjectBuildingException
|
|
||||||
{
|
|
||||||
return projectBuilder.build( pom, artifactRepo, new DefaultProfileManager(
|
|
||||||
session.getContainer() ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private List listITPoms()
|
private List listITPoms()
|
||||||
{
|
{
|
||||||
List poms = new ArrayList();
|
List poms = new ArrayList();
|
||||||
|
|
||||||
File [] children = projectsDir.listFiles();
|
File [] children = integrationTestsDirectory.listFiles();
|
||||||
|
|
||||||
for ( int i = 0; i < children.length; i++ )
|
for ( int i = 0; i < children.length; i++ )
|
||||||
{
|
{
|
||||||
@ -140,53 +178,9 @@ private List listITPoms()
|
|||||||
{
|
{
|
||||||
poms.add( pomFile );
|
poms.add( pomFile );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return poms;
|
return poms;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Duplicate code from MavenCli, slightly modified.
|
|
||||||
|
|
||||||
private ArtifactRepository createLocalRepository()
|
|
||||||
throws ComponentLookupException
|
|
||||||
{
|
|
||||||
ArtifactRepositoryLayout repositoryLayout = (ArtifactRepositoryLayout)
|
|
||||||
session.getContainer().lookup( ArtifactRepositoryLayout.ROLE, "default" );
|
|
||||||
|
|
||||||
ArtifactRepositoryFactory artifactRepositoryFactory = (ArtifactRepositoryFactory)
|
|
||||||
session.getContainer().lookup(
|
|
||||||
ArtifactRepositoryFactory.ROLE );
|
|
||||||
|
|
||||||
String url = "file://" + settings.getLocalRepository();
|
|
||||||
ArtifactRepository localRepository = new DefaultArtifactRepository( "local", url, repositoryLayout );
|
|
||||||
|
|
||||||
boolean snapshotPolicySet = false;
|
|
||||||
|
|
||||||
if ( settings.isOffline() )
|
|
||||||
{
|
|
||||||
artifactRepositoryFactory.setGlobalEnable( false );
|
|
||||||
snapshotPolicySet = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* can't do this here.. :(
|
|
||||||
if ( !snapshotPolicySet && commandLine.hasOption( CLIManager.UPDATE_SNAPSHOTS ) )
|
|
||||||
{
|
|
||||||
artifactRepositoryFactory.setGlobalUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( commandLine.hasOption( CLIManager.CHECKSUM_FAILURE_POLICY ) )
|
|
||||||
{
|
|
||||||
artifactRepositoryFactory.setGlobalChecksumPolicy( ArtifactRepositoryPolicy.CHECKSUM_POLICY_FAIL );
|
|
||||||
}
|
|
||||||
else if ( commandLine.hasOption( CLIManager.CHECKSUM_WARNING_POLICY ) )
|
|
||||||
{
|
|
||||||
artifactRepositoryFactory.setGlobalChecksumPolicy( ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN );
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
return localRepository;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user