From a5efa2c5f84198593abbecdff59f04856eb680f4 Mon Sep 17 00:00:00 2001 From: Jason van Zyl Date: Wed, 25 Mar 2009 15:40:52 +0000 Subject: [PATCH] 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 --- .../lifecycle/LifecycleExecutorTest.java | 56 ++++---- .../test-custom-lifecycle-buildplan/pom.xml | 10 -- .../resources/META-INF/plexus/components.xml | 31 ----- .../test-extension/pom.xml | 73 ---------- .../test-extension/repo.xml | 22 --- .../maven/core/test/MyArtifactFactory.java | 128 ------------------ .../resources/META-INF/plexus/components.xml | 9 -- .../pom.xml | 44 ------ .../repo.xml | 22 --- .../resources/META-INF/plexus/components.xml | 31 ----- 10 files changed, 28 insertions(+), 398 deletions(-) delete mode 100644 maven-core/src/test/repository-projects/test-custom-lifecycle-buildplan/pom.xml delete mode 100644 maven-core/src/test/repository-projects/test-custom-lifecycle-buildplan/src/main/resources/META-INF/plexus/components.xml delete mode 100644 maven-core/src/test/repository-projects/test-extension/pom.xml delete mode 100644 maven-core/src/test/repository-projects/test-extension/repo.xml delete mode 100644 maven-core/src/test/repository-projects/test-extension/src/main/java/org/apache/maven/core/test/MyArtifactFactory.java delete mode 100644 maven-core/src/test/repository-projects/test-extension/src/main/resources/META-INF/plexus/components.xml delete mode 100644 maven-core/src/test/repository-projects/test-lifecycle-and-artifactHandler/pom.xml delete mode 100644 maven-core/src/test/repository-projects/test-lifecycle-and-artifactHandler/repo.xml delete mode 100644 maven-core/src/test/repository-projects/test-lifecycle-and-artifactHandler/src/main/resources/META-INF/plexus/components.xml diff --git a/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java b/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java index 5fc8510f21..228439ceff 100644 --- a/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java +++ b/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java @@ -41,26 +41,38 @@ 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() ) - { - pom = new File( getBasedir(), "src/test/pom.xml" ); - FileUtils.copyFile( pom, targetPom ); - } } + protected String getProjectsDirectory() + { + 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() { assertNotNull( lifecycleExecutor.getLifecyclePhases() ); @@ -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 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() ); diff --git a/maven-core/src/test/repository-projects/test-custom-lifecycle-buildplan/pom.xml b/maven-core/src/test/repository-projects/test-custom-lifecycle-buildplan/pom.xml deleted file mode 100644 index df5ae16dc0..0000000000 --- a/maven-core/src/test/repository-projects/test-custom-lifecycle-buildplan/pom.xml +++ /dev/null @@ -1,10 +0,0 @@ - - 4.0.0 - org.apache.maven.core.test - test-custom-lifecycle-buildPlan - jar - 1 - test-custom-lifecycle-buildPlan - - diff --git a/maven-core/src/test/repository-projects/test-custom-lifecycle-buildplan/src/main/resources/META-INF/plexus/components.xml b/maven-core/src/test/repository-projects/test-custom-lifecycle-buildplan/src/main/resources/META-INF/plexus/components.xml deleted file mode 100644 index 78c341784a..0000000000 --- a/maven-core/src/test/repository-projects/test-custom-lifecycle-buildplan/src/main/resources/META-INF/plexus/components.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - org.apache.maven.artifact.handler.ArtifactHandler - test - org.apache.maven.artifact.handler.DefaultArtifactHandler - - test - jar - java - true - - - - org.apache.maven.lifecycle.mapping.LifecycleMapping - test - org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping - - - - default - - org.apache.maven.plugins:maven-deploy-plugin:deploy - org.apache.maven.plugins:maven-install-plugin:install - - - - - - - diff --git a/maven-core/src/test/repository-projects/test-extension/pom.xml b/maven-core/src/test/repository-projects/test-extension/pom.xml deleted file mode 100644 index 70114e72b6..0000000000 --- a/maven-core/src/test/repository-projects/test-extension/pom.xml +++ /dev/null @@ -1,73 +0,0 @@ - - 4.0.0 - org.apache.maven.core.test - test-extension - jar - 1 - test-extension - - - - org.apache.maven.artifact - maven-artifact - 3.0-SNAPSHOT - - - org.codehaus.plexus - plexus-utils - 1.1 - - - org.codehaus.plexus - plexus - 1.0.11 - pom - - - org.codehaus.plexus - plexus-component-api - 1.0-alpha-16 - - - org.codehaus.plexus - plexus-container-default - 1.0-alpha-16 - - - - - - - maven-assembly-plugin - 2.2-beta-2-SNAPSHOT - - - repo-assembly - package - - single - - - - repo.xml - - test-extension - true - ${pom.basedir}/../../resources/org/apache/maven/extension - true - - - - - - - - - - dummy - file:///tmp/dummy-repo - - - - diff --git a/maven-core/src/test/repository-projects/test-extension/repo.xml b/maven-core/src/test/repository-projects/test-extension/repo.xml deleted file mode 100644 index 85774a1d9b..0000000000 --- a/maven-core/src/test/repository-projects/test-extension/repo.xml +++ /dev/null @@ -1,22 +0,0 @@ - - repo - - dir - - false - - - runtime - / - - - - - target - /org/apache/maven/core/test/test-extension/1 - - test-extension* - - - - \ No newline at end of file diff --git a/maven-core/src/test/repository-projects/test-extension/src/main/java/org/apache/maven/core/test/MyArtifactFactory.java b/maven-core/src/test/repository-projects/test-extension/src/main/java/org/apache/maven/core/test/MyArtifactFactory.java deleted file mode 100644 index 50aef62bba..0000000000 --- a/maven-core/src/test/repository-projects/test-extension/src/main/java/org/apache/maven/core/test/MyArtifactFactory.java +++ /dev/null @@ -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 ); - } -} diff --git a/maven-core/src/test/repository-projects/test-extension/src/main/resources/META-INF/plexus/components.xml b/maven-core/src/test/repository-projects/test-extension/src/main/resources/META-INF/plexus/components.xml deleted file mode 100644 index b3a4987d84..0000000000 --- a/maven-core/src/test/repository-projects/test-extension/src/main/resources/META-INF/plexus/components.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - org.apache.maven.artifact.factory.ArtifactFactory - test - org.apache.maven.core.test.MyArtifactFactory - - - diff --git a/maven-core/src/test/repository-projects/test-lifecycle-and-artifactHandler/pom.xml b/maven-core/src/test/repository-projects/test-lifecycle-and-artifactHandler/pom.xml deleted file mode 100644 index d9e4cde9a1..0000000000 --- a/maven-core/src/test/repository-projects/test-lifecycle-and-artifactHandler/pom.xml +++ /dev/null @@ -1,44 +0,0 @@ - - 4.0.0 - org.apache.maven.core.test - test-lifecycle-and-artifactHandler - jar - 1 - test-lifecycle-and-artifactHandler - - - - - maven-assembly-plugin - 2.2-beta-2-SNAPSHOT - - - repo-assembly - package - - single - - - - repo.xml - - test-extension - true - ${pom.basedir}/../../resources/org/apache/maven/extension - true - - - - - - - - - - dummy - file:///tmp/dummy-repo - - - - diff --git a/maven-core/src/test/repository-projects/test-lifecycle-and-artifactHandler/repo.xml b/maven-core/src/test/repository-projects/test-lifecycle-and-artifactHandler/repo.xml deleted file mode 100644 index b73a929225..0000000000 --- a/maven-core/src/test/repository-projects/test-lifecycle-and-artifactHandler/repo.xml +++ /dev/null @@ -1,22 +0,0 @@ - - repo - - dir - - false - - - runtime - / - - - - - target - /org/apache/maven/core/test/test-lifecycle-and-artifactHandler/1 - - test-lifecycle-and-artifactHandler* - - - - \ No newline at end of file diff --git a/maven-core/src/test/repository-projects/test-lifecycle-and-artifactHandler/src/main/resources/META-INF/plexus/components.xml b/maven-core/src/test/repository-projects/test-lifecycle-and-artifactHandler/src/main/resources/META-INF/plexus/components.xml deleted file mode 100644 index 09e3ad6b8e..0000000000 --- a/maven-core/src/test/repository-projects/test-lifecycle-and-artifactHandler/src/main/resources/META-INF/plexus/components.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - org.apache.maven.artifact.handler.ArtifactHandler - test - org.apache.maven.artifact.handler.DefaultArtifactHandler - - test - jar - java - true - - - - org.apache.maven.lifecycle.mapping.LifecycleMapping - test - org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping - - - - default - - org.apache.maven.plugins:maven-install-plugin:install - org.apache.maven.plugins:maven-deploy-plugin:deploy - - - - - - -