o finished a pattern for the testing of lifecycles, now it's time to create tests for the plugin manager and default maven component

git-svn-id: https://svn.apache.org/repos/asf/maven/components/branches/MNG-2766@758309 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2009-03-25 15:40:52 +00:00
parent 52c9295a42
commit a5efa2c5f8
10 changed files with 28 additions and 398 deletions

View File

@ -42,24 +42,36 @@ public class LifecycleExecutorTest
@Requirement
private DefaultLifecycleExecutor lifecycleExecutor;
File pom;
File targetPom;
protected void setUp()
throws Exception
{
// Components
projectBuilder = lookup( MavenProjectBuilder.class );
repositorySystem = lookup( RepositorySystem.class );
pluginManager = lookup( PluginManager.class );
lifecycleExecutor = (DefaultLifecycleExecutor) lookup( LifecycleExecutor.class );
targetPom = new File( getBasedir(), "target/lifecycle-executor/pom-plugin.xml" );
}
if ( !targetPom.exists() )
protected String getProjectsDirectory()
{
pom = new File( getBasedir(), "src/test/pom.xml" );
FileUtils.copyFile( pom, targetPom );
return "src/test/projects/lifecycle-executor";
}
protected File getProject( String name )
throws Exception
{
File source = new File( new File( getBasedir(), getProjectsDirectory() ), name );
File target = new File( new File ( getBasedir(), "target" ), name );
if ( !target.exists() )
{
FileUtils.copyDirectoryStructure( source, target );
}
return new File( target, "pom.xml" );
}
// -----------------------------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------------------------
public void testLifecyclePhases()
{
@ -73,18 +85,10 @@ public class LifecycleExecutorTest
public void testLifecycleQueryingUsingADefaultLifecyclePhase()
throws Exception
{
// This stuff all needs to be reduced, reduced, reduced
String base = "projects/lifecycle-executor/project-with-additional-lifecycle-elements";
File sourceDirectory = new File( getBasedir(), "src/test/" + base );
File targetDirectory = new File( getBasedir(), "target/" + base );
FileUtils.copyDirectoryStructure( sourceDirectory, targetDirectory );
File targetPom = new File( targetDirectory, "pom.xml" );
MavenSession session = createMavenSession( targetPom );
File pom = getProject( "project-with-additional-lifecycle-elements" );
MavenSession session = createMavenSession( pom );
assertEquals( "project-with-additional-lifecycle-elements", session.getCurrentProject().getArtifactId() );
assertEquals( "1.0-SNAPSHOT", session.getCurrentProject().getVersion() );
// So this is wrong if we already have the session, which contains a request, which in turn contains
// the goals we are trying to run
List<MojoDescriptor> lifecyclePlan = lifecycleExecutor.calculateLifecyclePlan( "package", session );
// resources:resources
@ -109,12 +113,8 @@ public class LifecycleExecutorTest
public void testLifecycleExecutionUsingADefaultLifecyclePhase()
throws Exception
{
String base = "projects/lifecycle-executor/project-with-additional-lifecycle-elements";
File sourceDirectory = new File( getBasedir(), "src/test/" + base );
File targetDirectory = new File( getBasedir(), "target/" + base );
FileUtils.copyDirectoryStructure( sourceDirectory, targetDirectory );
File targetPom = new File( targetDirectory, "pom.xml" );
MavenSession session = createMavenSession( targetPom );
File pom = getProject( "project-with-additional-lifecycle-elements" );
MavenSession session = createMavenSession( pom );
assertEquals( "project-with-additional-lifecycle-elements", session.getCurrentProject().getArtifactId() );
assertEquals( "1.0-SNAPSHOT", session.getCurrentProject().getVersion() );
lifecycleExecutor.execute( session );
@ -134,7 +134,7 @@ public class LifecycleExecutorTest
public void testRemoteResourcesPlugin()
throws Exception
{
MavenSession session = createMavenSession( targetPom );
MavenSession session = createMavenSession( getProject( "project-with-inheritance" ) );
String pluginArtifactId = "remote-resources";
String goal = "process";
MojoDescriptor mojoDescriptor = lifecycleExecutor.getMojoDescriptor( pluginArtifactId + ":" + goal, session, session.getCurrentProject() );
@ -146,7 +146,7 @@ public class LifecycleExecutorTest
public void testSurefirePlugin()
throws Exception
{
MavenSession session = createMavenSession( targetPom );
MavenSession session = createMavenSession( getProject( "project-with-inheritance" ) );
String pluginArtifactId = "surefire";
String goal = "test";
MojoDescriptor mojoDescriptor = lifecycleExecutor.getMojoDescriptor( pluginArtifactId + ":" + goal, session, session.getCurrentProject() );

View File

@ -1,10 +0,0 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.core.test</groupId>
<artifactId>test-custom-lifecycle-buildPlan</artifactId>
<packaging>jar</packaging>
<version>1</version>
<name>test-custom-lifecycle-buildPlan</name>
</project>

View File

@ -1,31 +0,0 @@
<component-set>
<components>
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>test</role-hint>
<implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
<configuration>
<type>test</type>
<extension>jar</extension>
<language>java</language>
<addedToClasspath>true</addedToClasspath>
</configuration>
</component>
<component>
<role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
<role-hint>test</role-hint>
<implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation>
<configuration>
<lifecycles>
<lifecycle>
<id>default</id>
<phases>
<install>org.apache.maven.plugins:maven-deploy-plugin:deploy</install>
<deploy>org.apache.maven.plugins:maven-install-plugin:install</deploy>
</phases>
</lifecycle>
</lifecycles>
</configuration>
</component>
</components>
</component-set>

View File

@ -1,73 +0,0 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.core.test</groupId>
<artifactId>test-extension</artifactId>
<packaging>jar</packaging>
<version>1</version>
<name>test-extension</name>
<dependencies>
<dependency>
<groupId>org.apache.maven.artifact</groupId>
<artifactId>maven-artifact</artifactId>
<version>3.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus</artifactId>
<version>1.0.11</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-api</artifactId>
<version>1.0-alpha-16</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-container-default</artifactId>
<version>1.0-alpha-16</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-2-SNAPSHOT</version>
<executions>
<execution>
<id>repo-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>repo.xml</descriptor>
</descriptors>
<finalName>test-extension</finalName>
<appendAssemblyId>true</appendAssemblyId>
<outputDirectory>${pom.basedir}/../../resources/org/apache/maven/extension</outputDirectory>
<ignoreDirFormatExtensions>true</ignoreDirFormatExtensions>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<id>dummy</id>
<url>file:///tmp/dummy-repo</url>
</repository>
</distributionManagement>
</project>

View File

@ -1,22 +0,0 @@
<assembly>
<id>repo</id>
<formats>
<format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<repositories>
<repository>
<scope>runtime</scope>
<outputDirectory>/</outputDirectory>
</repository>
</repositories>
<fileSets>
<fileSet>
<directory>target</directory>
<outputDirectory>/org/apache/maven/core/test/test-extension/1</outputDirectory>
<includes>
<include>test-extension*</include>
</includes>
</fileSet>
</fileSets>
</assembly>

View File

@ -1,128 +0,0 @@
package org.apache.maven.core.test;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.handler.DefaultArtifactHandler;
import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DefaultArtifact;
public class MyArtifactFactory
implements ArtifactFactory
{
private static final boolean OPTIONAL = false;
private static final ArtifactHandler HANDLER = new DefaultArtifactHandler( "jar" );
private static final String CLASSIFIER = null;
private static final String TYPE = "jar";
private static final String SCOPE = Artifact.SCOPE_COMPILE;
private static final VersionRange VERSION = VersionRange.createFromVersion( "1.1.1" );
private static final String AID = "test-artifact";
private static final String GID = "test.group";
public Artifact createArtifact( String groupId,
String artifactId,
String version,
String scope,
String type )
{
return new DefaultArtifact( GID, AID, VERSION, SCOPE, TYPE, CLASSIFIER, HANDLER, OPTIONAL );
}
public Artifact createArtifactWithClassifier( String groupId,
String artifactId,
String version,
String type,
String classifier )
{
return new DefaultArtifact( GID, AID, VERSION, SCOPE, TYPE, CLASSIFIER, HANDLER, OPTIONAL );
}
public Artifact createBuildArtifact( String groupId,
String artifactId,
String version,
String packaging )
{
return new DefaultArtifact( GID, AID, VERSION, SCOPE, TYPE, CLASSIFIER, HANDLER, OPTIONAL );
}
public Artifact createDependencyArtifact( String groupId,
String artifactId,
VersionRange versionRange,
String type,
String classifier,
String scope )
{
return new DefaultArtifact( GID, AID, VERSION, SCOPE, TYPE, CLASSIFIER, HANDLER, OPTIONAL );
}
public Artifact createDependencyArtifact( String groupId,
String artifactId,
VersionRange versionRange,
String type,
String classifier,
String scope,
boolean optional )
{
return new DefaultArtifact( GID, AID, VERSION, SCOPE, TYPE, CLASSIFIER, HANDLER, OPTIONAL );
}
public Artifact createDependencyArtifact( String groupId,
String artifactId,
VersionRange versionRange,
String type,
String classifier,
String scope,
String inheritedScope )
{
return new DefaultArtifact( GID, AID, VERSION, SCOPE, TYPE, CLASSIFIER, HANDLER, OPTIONAL );
}
public Artifact createDependencyArtifact( String groupId,
String artifactId,
VersionRange versionRange,
String type,
String classifier,
String scope,
String inheritedScope,
boolean optional )
{
return new DefaultArtifact( GID, AID, VERSION, SCOPE, TYPE, CLASSIFIER, HANDLER, OPTIONAL );
}
public Artifact createExtensionArtifact( String groupId,
String artifactId,
VersionRange versionRange )
{
return new DefaultArtifact( GID, AID, VERSION, SCOPE, TYPE, CLASSIFIER, HANDLER, OPTIONAL );
}
public Artifact createParentArtifact( String groupId,
String artifactId,
String version )
{
return new DefaultArtifact( GID, AID, VERSION, SCOPE, TYPE, CLASSIFIER, HANDLER, OPTIONAL );
}
public Artifact createPluginArtifact( String groupId,
String artifactId,
VersionRange versionRange )
{
return new DefaultArtifact( GID, AID, VERSION, SCOPE, TYPE, CLASSIFIER, HANDLER, OPTIONAL );
}
public Artifact createProjectArtifact( String groupId,
String artifactId,
String version )
{
return new DefaultArtifact( GID, AID, VERSION, SCOPE, TYPE, CLASSIFIER, HANDLER, OPTIONAL );
}
public Artifact createProjectArtifact( String groupId,
String artifactId,
String version,
String scope )
{
return new DefaultArtifact( GID, AID, VERSION, SCOPE, TYPE, CLASSIFIER, HANDLER, OPTIONAL );
}
}

View File

@ -1,9 +0,0 @@
<component-set>
<components>
<component>
<role>org.apache.maven.artifact.factory.ArtifactFactory</role>
<role-hint>test</role-hint>
<implementation>org.apache.maven.core.test.MyArtifactFactory</implementation>
</component>
</components>
</component-set>

View File

@ -1,44 +0,0 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.core.test</groupId>
<artifactId>test-lifecycle-and-artifactHandler</artifactId>
<packaging>jar</packaging>
<version>1</version>
<name>test-lifecycle-and-artifactHandler</name>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-2-SNAPSHOT</version>
<executions>
<execution>
<id>repo-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>repo.xml</descriptor>
</descriptors>
<finalName>test-extension</finalName>
<appendAssemblyId>true</appendAssemblyId>
<outputDirectory>${pom.basedir}/../../resources/org/apache/maven/extension</outputDirectory>
<ignoreDirFormatExtensions>true</ignoreDirFormatExtensions>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<id>dummy</id>
<url>file:///tmp/dummy-repo</url>
</repository>
</distributionManagement>
</project>

View File

@ -1,22 +0,0 @@
<assembly>
<id>repo</id>
<formats>
<format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<repositories>
<repository>
<scope>runtime</scope>
<outputDirectory>/</outputDirectory>
</repository>
</repositories>
<fileSets>
<fileSet>
<directory>target</directory>
<outputDirectory>/org/apache/maven/core/test/test-lifecycle-and-artifactHandler/1</outputDirectory>
<includes>
<include>test-lifecycle-and-artifactHandler*</include>
</includes>
</fileSet>
</fileSets>
</assembly>

View File

@ -1,31 +0,0 @@
<component-set>
<components>
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>test</role-hint>
<implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
<configuration>
<type>test</type>
<extension>jar</extension>
<language>java</language>
<addedToClasspath>true</addedToClasspath>
</configuration>
</component>
<component>
<role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
<role-hint>test</role-hint>
<implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation>
<configuration>
<lifecycles>
<lifecycle>
<id>default</id>
<phases>
<install>org.apache.maven.plugins:maven-install-plugin:install</install>
<deploy>org.apache.maven.plugins:maven-deploy-plugin:deploy</deploy>
</phases>
</lifecycle>
</lifecycles>
</configuration>
</component>
</components>
</component-set>