You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by kr...@apache.org on 2010/04/08 13:29:09 UTC
svn commit: r931884 [6/7] - in /maven/maven-3/trunk:
maven-compat/src/test/java/org/apache/maven/project/
maven-core/src/main/java/org/apache/maven/
maven-core/src/main/java/org/apache/maven/artifact/repository/
maven-core/src/main/java/org/apache/mave...
Modified: maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java?rev=931884&r1=931883&r2=931884&view=diff
==============================================================================
--- maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java (original)
+++ maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java Thu Apr 8 11:29:07 2010
@@ -1,30 +1,74 @@
-package org.apache.maven.lifecycle;
+/*
+ * 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 java.io.File;
-import java.util.ArrayList;
-import java.util.List;
+
+package org.apache.maven.lifecycle;
import org.apache.maven.AbstractCoreMavenComponentTestCase;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.exception.ExceptionHandler;
import org.apache.maven.execution.MavenSession;
+import org.apache.maven.lifecycle.internal.ExecutionPlanItem;
+import org.apache.maven.lifecycle.internal.LifecycleExecutionPlanCalculator;
+import org.apache.maven.lifecycle.internal.LifecycleTaskSegmentCalculator;
+import org.apache.maven.lifecycle.internal.LifecycleTaskSegmentCalculatorImpl;
+import org.apache.maven.lifecycle.internal.MojoDescriptorCreator;
import org.apache.maven.model.Plugin;
+import org.apache.maven.plugin.InvalidPluginDescriptorException;
import org.apache.maven.plugin.MojoExecution;
+import org.apache.maven.plugin.MojoNotFoundException;
+import org.apache.maven.plugin.PluginDescriptorParsingException;
+import org.apache.maven.plugin.PluginManagerException;
+import org.apache.maven.plugin.PluginNotFoundException;
+import org.apache.maven.plugin.PluginResolutionException;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
+import org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException;
+import org.apache.maven.plugin.version.PluginVersionResolutionException;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.util.xml.Xpp3Dom;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
public class LifecycleExecutorTest
extends AbstractCoreMavenComponentTestCase
{
@Requirement
private DefaultLifecycleExecutor lifecycleExecutor;
-
+
+ @Requirement
+ private LifecycleTaskSegmentCalculatorImpl lifeCycleTaskSegmentCalculator;
+
+ @Requirement
+ private LifecycleExecutionPlanCalculator lifeCycleExecutionPlanCalculator;
+
+ @Requirement
+ private MojoDescriptorCreator mojoDescriptorCreator;
+
+
protected void setUp()
throws Exception
{
super.setUp();
lifecycleExecutor = (DefaultLifecycleExecutor) lookup( LifecycleExecutor.class );
+ lifeCycleTaskSegmentCalculator =
+ (LifecycleTaskSegmentCalculatorImpl) lookup( LifecycleTaskSegmentCalculator.class );
+ lifeCycleExecutionPlanCalculator = lookup( LifecycleExecutionPlanCalculator.class );
+ mojoDescriptorCreator = lookup( MojoDescriptorCreator.class );
lookup( ExceptionHandler.class );
}
@@ -40,11 +84,11 @@ public class LifecycleExecutorTest
{
return "src/test/projects/lifecycle-executor";
}
-
+
// -----------------------------------------------------------------------------------------------
// Tests which exercise the lifecycle executor when it is dealing with default lifecycle phases.
// -----------------------------------------------------------------------------------------------
-
+
public void testCalculationOfBuildPlanWithIndividualTaskWherePluginIsSpecifiedInThePom()
throws Exception
{
@@ -54,12 +98,14 @@ public class LifecycleExecutorTest
MavenSession session = createMavenSession( pom );
assertEquals( "project-basic", session.getCurrentProject().getArtifactId() );
assertEquals( "1.0", session.getCurrentProject().getVersion() );
- List<MojoExecution> executionPlan = lifecycleExecutor.calculateExecutionPlan( session, "resources:resources" ).getExecutions();
+ List<MojoExecution> executionPlan = getExecutions( calculateExecutionPlan( session, "resources:resources" ) );
assertEquals( 1, executionPlan.size() );
MojoExecution mojoExecution = executionPlan.get( 0 );
assertNotNull( mojoExecution );
- assertEquals( "org.apache.maven.plugins", mojoExecution.getMojoDescriptor().getPluginDescriptor().getGroupId() );
- assertEquals( "maven-resources-plugin", mojoExecution.getMojoDescriptor().getPluginDescriptor().getArtifactId() );
+ assertEquals( "org.apache.maven.plugins",
+ mojoExecution.getMojoDescriptor().getPluginDescriptor().getGroupId() );
+ assertEquals( "maven-resources-plugin",
+ mojoExecution.getMojoDescriptor().getPluginDescriptor().getArtifactId() );
assertEquals( "0.1", mojoExecution.getMojoDescriptor().getPluginDescriptor().getVersion() );
}
@@ -72,15 +118,16 @@ public class LifecycleExecutorTest
MavenSession session = createMavenSession( pom );
assertEquals( "project-basic", session.getCurrentProject().getArtifactId() );
assertEquals( "1.0", session.getCurrentProject().getVersion() );
- List<MojoExecution> executionPlan = lifecycleExecutor.calculateExecutionPlan( session, "clean" ).getExecutions();
+ List<MojoExecution> executionPlan = getExecutions( calculateExecutionPlan( session, "clean" ) );
assertEquals( 1, executionPlan.size() );
MojoExecution mojoExecution = executionPlan.get( 0 );
assertNotNull( mojoExecution );
- assertEquals( "org.apache.maven.plugins", mojoExecution.getMojoDescriptor().getPluginDescriptor().getGroupId() );
+ assertEquals( "org.apache.maven.plugins",
+ mojoExecution.getMojoDescriptor().getPluginDescriptor().getGroupId() );
assertEquals( "maven-clean-plugin", mojoExecution.getMojoDescriptor().getPluginDescriptor().getArtifactId() );
assertEquals( "0.1", mojoExecution.getMojoDescriptor().getPluginDescriptor().getVersion() );
}
-
+
public void testCalculationOfBuildPlanWithIndividualTaskOfTheCleanCleanGoal()
throws Exception
{
@@ -90,15 +137,26 @@ public class LifecycleExecutorTest
MavenSession session = createMavenSession( pom );
assertEquals( "project-basic", session.getCurrentProject().getArtifactId() );
assertEquals( "1.0", session.getCurrentProject().getVersion() );
- List<MojoExecution> executionPlan = lifecycleExecutor.calculateExecutionPlan( session, "clean:clean" ).getExecutions();
+ List<MojoExecution> executionPlan = getExecutions( calculateExecutionPlan( session, "clean:clean" ) );
assertEquals( 1, executionPlan.size() );
MojoExecution mojoExecution = executionPlan.get( 0 );
assertNotNull( mojoExecution );
- assertEquals( "org.apache.maven.plugins", mojoExecution.getMojoDescriptor().getPluginDescriptor().getGroupId() );
+ assertEquals( "org.apache.maven.plugins",
+ mojoExecution.getMojoDescriptor().getPluginDescriptor().getGroupId() );
assertEquals( "maven-clean-plugin", mojoExecution.getMojoDescriptor().getPluginDescriptor().getArtifactId() );
assertEquals( "0.1", mojoExecution.getMojoDescriptor().getPluginDescriptor().getVersion() );
}
+ List<MojoExecution> getExecutions( MavenExecutionPlan mavenExecutionPlan )
+ {
+ List<MojoExecution> result = new ArrayList<MojoExecution>();
+ for ( ExecutionPlanItem executionPlanItem : mavenExecutionPlan )
+ {
+ result.add( executionPlanItem.getMojoExecution() );
+ }
+ return result;
+ }
+
// We need to take in multiple lifecycles
public void testCalculationOfBuildPlanTasksOfTheCleanLifecycleAndTheInstallLifecycle()
throws Exception
@@ -107,8 +165,8 @@ public class LifecycleExecutorTest
MavenSession session = createMavenSession( pom );
assertEquals( "project-with-additional-lifecycle-elements", session.getCurrentProject().getArtifactId() );
assertEquals( "1.0", session.getCurrentProject().getVersion() );
- List<MojoExecution> executionPlan = lifecycleExecutor.calculateExecutionPlan( session, "clean", "install" ).getExecutions();
-
+ List<MojoExecution> executionPlan = getExecutions( calculateExecutionPlan( session, "clean", "install" ) );
+
//[01] clean:clean
//[02] resources:resources
//[03] compiler:compile
@@ -121,7 +179,7 @@ public class LifecycleExecutorTest
//[10] install:install
//
assertEquals( 10, executionPlan.size() );
-
+
assertEquals( "clean:clean", executionPlan.get( 0 ).getMojoDescriptor().getFullGoalName() );
assertEquals( "resources:resources", executionPlan.get( 1 ).getMojoDescriptor().getFullGoalName() );
assertEquals( "compiler:compile", executionPlan.get( 2 ).getMojoDescriptor().getFullGoalName() );
@@ -130,8 +188,8 @@ public class LifecycleExecutorTest
assertEquals( "compiler:testCompile", executionPlan.get( 5 ).getMojoDescriptor().getFullGoalName() );
assertEquals( "it:generate-test-metadata", executionPlan.get( 6 ).getMojoDescriptor().getFullGoalName() );
assertEquals( "surefire:test", executionPlan.get( 7 ).getMojoDescriptor().getFullGoalName() );
- assertEquals( "jar:jar", executionPlan.get( 8 ).getMojoDescriptor().getFullGoalName() );
- assertEquals( "install:install", executionPlan.get( 9 ).getMojoDescriptor().getFullGoalName() );
+ assertEquals( "jar:jar", executionPlan.get( 8 ).getMojoDescriptor().getFullGoalName() );
+ assertEquals( "install:install", executionPlan.get( 9 ).getMojoDescriptor().getFullGoalName() );
}
// We need to take in multiple lifecycles
@@ -142,15 +200,15 @@ public class LifecycleExecutorTest
MavenSession session = createMavenSession( pom );
assertEquals( "project-with-multiple-executions", session.getCurrentProject().getArtifactId() );
assertEquals( "1.0.1", session.getCurrentProject().getVersion() );
-
- MavenExecutionPlan plan = lifecycleExecutor.calculateExecutionPlan( session, "clean", "install" );
-
+
+ MavenExecutionPlan plan = calculateExecutionPlan( session, "clean", "install" );
+
assertTrue( plan.getRequiredResolutionScopes().contains( Artifact.SCOPE_COMPILE ) );
assertTrue( plan.getRequiredResolutionScopes().contains( Artifact.SCOPE_RUNTIME ) );
assertTrue( plan.getRequiredResolutionScopes().contains( Artifact.SCOPE_TEST ) );
-
- List<MojoExecution> executions = plan.getExecutions();
-
+
+ List<MojoExecution> executions = getExecutions( plan );
+
//[01] clean:clean
//[02] modello:xpp3-writer
//[03] modello:java
@@ -168,9 +226,9 @@ public class LifecycleExecutorTest
//[15] plugin:addPluginArtifactMetadata
//[16] install:install
//
-
- assertEquals( 16, executions.size() );
-
+
+ assertEquals( 16, executions.size() );
+
assertEquals( "clean:clean", executions.get( 0 ).getMojoDescriptor().getFullGoalName() );
assertEquals( "it:xpp3-writer", executions.get( 1 ).getMojoDescriptor().getFullGoalName() );
assertEquals( "it:java", executions.get( 2 ).getMojoDescriptor().getFullGoalName() );
@@ -184,23 +242,27 @@ public class LifecycleExecutorTest
assertEquals( "resources:testResources", executions.get( 10 ).getMojoDescriptor().getFullGoalName() );
assertEquals( "compiler:testCompile", executions.get( 11 ).getMojoDescriptor().getFullGoalName() );
assertEquals( "surefire:test", executions.get( 12 ).getMojoDescriptor().getFullGoalName() );
- assertEquals( "jar:jar", executions.get( 13 ).getMojoDescriptor().getFullGoalName() );
- assertEquals( "plugin:addPluginArtifactMetadata", executions.get( 14 ).getMojoDescriptor().getFullGoalName() );
+ assertEquals( "jar:jar", executions.get( 13 ).getMojoDescriptor().getFullGoalName() );
+ assertEquals( "plugin:addPluginArtifactMetadata", executions.get( 14 ).getMojoDescriptor().getFullGoalName() );
assertEquals( "install:install", executions.get( 15 ).getMojoDescriptor().getFullGoalName() );
-
- assertEquals( "src/main/mdo/remote-resources.mdo", new MojoExecutionXPathContainer( executions.get( 1 ) ).getValue( "configuration/models[1]/model" ) );
- assertEquals( "src/main/mdo/supplemental-model.mdo", new MojoExecutionXPathContainer( executions.get( 4 ) ).getValue( "configuration/models[1]/model" ) );
- }
-
+
+ assertEquals( "src/main/mdo/remote-resources.mdo",
+ new MojoExecutionXPathContainer( executions.get( 1 ) ).getValue(
+ "configuration/models[1]/model" ) );
+ assertEquals( "src/main/mdo/supplemental-model.mdo",
+ new MojoExecutionXPathContainer( executions.get( 4 ) ).getValue(
+ "configuration/models[1]/model" ) );
+ }
+
public void testLifecycleQueryingUsingADefaultLifecyclePhase()
throws Exception
- {
+ {
File pom = getProject( "project-with-additional-lifecycle-elements" );
MavenSession session = createMavenSession( pom );
assertEquals( "project-with-additional-lifecycle-elements", session.getCurrentProject().getArtifactId() );
assertEquals( "1.0", session.getCurrentProject().getVersion() );
- List<MojoExecution> executionPlan = lifecycleExecutor.calculateExecutionPlan( session, "package" ).getExecutions();
-
+ List<MojoExecution> executionPlan = getExecutions( calculateExecutionPlan( session, "package" ) );
+
//[01] resources:resources
//[02] compiler:compile
//[03] it:generate-metadata
@@ -211,7 +273,7 @@ public class LifecycleExecutorTest
//[08] jar:jar
//
assertEquals( 8, executionPlan.size() );
-
+
assertEquals( "resources:resources", executionPlan.get( 0 ).getMojoDescriptor().getFullGoalName() );
assertEquals( "compiler:compile", executionPlan.get( 1 ).getMojoDescriptor().getFullGoalName() );
assertEquals( "it:generate-metadata", executionPlan.get( 2 ).getMojoDescriptor().getFullGoalName() );
@@ -219,48 +281,74 @@ public class LifecycleExecutorTest
assertEquals( "compiler:testCompile", executionPlan.get( 4 ).getMojoDescriptor().getFullGoalName() );
assertEquals( "it:generate-test-metadata", executionPlan.get( 5 ).getMojoDescriptor().getFullGoalName() );
assertEquals( "surefire:test", executionPlan.get( 6 ).getMojoDescriptor().getFullGoalName() );
- assertEquals( "jar:jar", executionPlan.get( 7 ).getMojoDescriptor().getFullGoalName() );
- }
-
+ assertEquals( "jar:jar", executionPlan.get( 7 ).getMojoDescriptor().getFullGoalName() );
+ }
+
public void testLifecyclePluginsRetrievalForDefaultLifecycle()
throws Exception
{
- List<Plugin> plugins = new ArrayList<Plugin>( lifecycleExecutor.getPluginsBoundByDefaultToAllLifecycles( "jar" ) );
-
+ List<Plugin> plugins =
+ new ArrayList<Plugin>( lifecycleExecutor.getPluginsBoundByDefaultToAllLifecycles( "jar" ) );
+
assertEquals( 8, plugins.size() );
}
-
+
public void testPluginConfigurationCreation()
throws Exception
{
File pom = getProject( "project-with-additional-lifecycle-elements" );
MavenSession session = createMavenSession( pom );
MojoDescriptor mojoDescriptor =
- lifecycleExecutor.getMojoDescriptor( "org.apache.maven.its.plugins:maven-it-plugin:0.1:java",
- session, session.getCurrentProject() );
- Xpp3Dom dom = lifecycleExecutor.convert( mojoDescriptor );
+ mojoDescriptorCreator.getMojoDescriptor( "org.apache.maven.its.plugins:maven-it-plugin:0.1:java", session,
+ session.getCurrentProject() );
+ Xpp3Dom dom = MojoDescriptorCreator.convert( mojoDescriptor );
System.out.println( dom );
}
+ // Todo: This method is kind of an oddity. It is only called from the LifecycleExecutorTest, hence it should
+ // really not exist, or at least be moved into the test class.
+
+ MavenExecutionPlan calculateExecutionPlan( MavenSession session, String... tasks )
+ throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
+ MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
+ PluginManagerException, LifecyclePhaseNotFoundException, LifecycleNotFoundException,
+ PluginVersionResolutionException
+ {
+ List<org.apache.maven.lifecycle.internal.TaskSegment> taskSegments =
+ lifeCycleTaskSegmentCalculator.calculateTaskSegments( session, Arrays.asList( tasks ) );
+
+ org.apache.maven.lifecycle.internal.TaskSegment mergedSegment =
+ new org.apache.maven.lifecycle.internal.TaskSegment( false );
+
+ for ( org.apache.maven.lifecycle.internal.TaskSegment taskSegment : taskSegments )
+ {
+ mergedSegment.getTasks().addAll( taskSegment.getTasks() );
+ }
+
+ return lifeCycleExecutionPlanCalculator.calculateExecutionPlan( session, session.getCurrentProject(),
+ mergedSegment.getTasks() );
+ }
+
+
public void testPluginPrefixRetrieval()
throws Exception
{
File pom = getProject( "project-basic" );
MavenSession session = createMavenSession( pom );
- Plugin plugin = lifecycleExecutor.findPluginForPrefix( "resources", session );
+ Plugin plugin = mojoDescriptorCreator.findPluginForPrefix( "resources", session );
assertEquals( "org.apache.maven.plugins", plugin.getGroupId() );
assertEquals( "maven-resources-plugin", plugin.getArtifactId() );
- }
-
+ }
+
// Prefixes
-
+
public void testFindingPluginPrefixforCleanClean()
throws Exception
{
File pom = getProject( "project-basic" );
MavenSession session = createMavenSession( pom );
- Plugin plugin = lifecycleExecutor.findPluginForPrefix( "clean", session );
+ Plugin plugin = mojoDescriptorCreator.findPluginForPrefix( "clean", session );
assertNotNull( plugin );
}
-
+
}
Added: maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/MavenExecutionPlanTest.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/MavenExecutionPlanTest.java?rev=931884&view=auto
==============================================================================
--- maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/MavenExecutionPlanTest.java (added)
+++ maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/MavenExecutionPlanTest.java Thu Apr 8 11:29:07 2010
@@ -0,0 +1,52 @@
+/*
+ * 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.
+ */
+
+
+package org.apache.maven.lifecycle;
+
+import junit.framework.TestCase;
+import org.apache.maven.lifecycle.internal.ExecutionPlanItem;
+import org.apache.maven.lifecycle.internal.stub.DefaultLifecyclesStub;
+import org.apache.maven.lifecycle.internal.stub.LifecycleExecutionPlanCalculatorStub;
+
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * @author Kristian Rosenvold
+ */
+public class MavenExecutionPlanTest
+ extends TestCase
+{
+ public void testFindFirstWithMatchingSchedule()
+ throws Exception
+ {
+ MavenExecutionPlan plan = LifecycleExecutionPlanCalculatorStub.getProjectAExceutionPlan();
+ final List<Scheduling> cycles = DefaultLifecyclesStub.getSchedulingList();
+ final Schedule schedule = cycles.get( 0 ).getSchedules().get( 0 );
+
+ }
+
+ public void testForceAllComplete()
+ throws Exception
+ {
+ MavenExecutionPlan plan = LifecycleExecutionPlanCalculatorStub.getProjectAExceutionPlan();
+ plan.forceAllComplete();
+ final Iterator<ExecutionPlanItem> planItemIterator = plan.iterator();
+ assertFalse( planItemIterator.next().ensureComplete() );
+ assertFalse( planItemIterator.next().ensureComplete() );
+ }
+
+}
Propchange: maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/MavenExecutionPlanTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/BuildListCalculatorTest.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/BuildListCalculatorTest.java?rev=931884&view=auto
==============================================================================
--- maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/BuildListCalculatorTest.java (added)
+++ maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/BuildListCalculatorTest.java Thu Apr 8 11:29:07 2010
@@ -0,0 +1,49 @@
+/*
+ * 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.
+ */
+
+package org.apache.maven.lifecycle.internal;
+
+import junit.framework.TestCase;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.lifecycle.internal.stub.LifecycleTaskSegmentCalculatorStub;
+import org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub;
+
+import java.util.List;
+
+public class BuildListCalculatorTest
+ extends TestCase
+{
+
+ public void testCalculateProjectBuilds()
+ throws Exception
+ {
+ BuildListCalculator buildListCalculator = createBuildListCalculator();
+ final MavenSession session = ProjectDependencyGraphStub.getMavenSession();
+ List<TaskSegment> taskSegments = buildListCalculator.calculateTaskSegments( session );
+ final ProjectBuildList buildList = buildListCalculator.calculateProjectBuilds( session, taskSegments );
+ final ProjectBuildList segments = buildList.getByTaskSegment( taskSegments.get( 0 ) );
+ assertEquals( "Stub data contains 3 segments", 3, taskSegments.size() );
+ assertEquals( "Stub data contains 6 items", 6, segments.size() );
+ final ProjectSegment build = segments.get( 0 );
+ assertNotNull( build );
+ }
+
+ public static BuildListCalculator createBuildListCalculator()
+ {
+ LifecycleTaskSegmentCalculator lifecycleTaskSegmentCalculator = new LifecycleTaskSegmentCalculatorStub();
+ return new BuildListCalculator( lifecycleTaskSegmentCalculator );
+ }
+
+}
Propchange: maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/BuildListCalculatorTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/BuilderCommonTest.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/BuilderCommonTest.java?rev=931884&view=auto
==============================================================================
--- maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/BuilderCommonTest.java (added)
+++ maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/BuilderCommonTest.java Thu Apr 8 11:29:07 2010
@@ -0,0 +1,72 @@
+/*
+ * 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.
+ */
+
+package org.apache.maven.lifecycle.internal;
+
+import junit.framework.TestCase;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.lifecycle.MavenExecutionPlan;
+import org.apache.maven.lifecycle.internal.stub.LifecycleExecutionPlanCalculatorStub;
+import org.apache.maven.lifecycle.internal.stub.LoggerStub;
+import org.apache.maven.lifecycle.internal.stub.ProjectDependenciesResolverStub;
+import org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub;
+
+/**
+ * @author Kristian Rosenvold
+ */
+public class BuilderCommonTest
+ extends TestCase
+{
+ public void testResolveBuildPlan()
+ throws Exception
+ {
+ MavenSession original = ProjectDependencyGraphStub.getMavenSession();
+
+ final TaskSegment taskSegment1 = new TaskSegment( false );
+ final MavenSession session1 = original.clone();
+ session1.setCurrentProject( ProjectDependencyGraphStub.A );
+
+ final BuilderCommon builderCommon = getBuilderCommon();
+ final MavenExecutionPlan plan =
+ builderCommon.resolveBuildPlan( session1, ProjectDependencyGraphStub.A, taskSegment1 );
+ assertEquals( LifecycleExecutionPlanCalculatorStub.getProjectAExceutionPlan().size(), plan.size() );
+
+ }
+
+
+ public void testHandleBuildError()
+ throws Exception
+ {
+ }
+
+ public void testAttachToThread()
+ throws Exception
+ {
+ }
+
+ public void testGetKey()
+ throws Exception
+ {
+ }
+
+ public static BuilderCommon getBuilderCommon()
+ {
+ final LifecycleDebugLogger logger = new LifecycleDebugLogger( new LoggerStub() );
+ final LifecycleDependencyResolver lifecycleDependencyResolver =
+ new LifecycleDependencyResolver( new ProjectDependenciesResolverStub(), new LoggerStub() );
+ return new BuilderCommon( logger, new LifecycleExecutionPlanCalculatorStub(), lifecycleDependencyResolver );
+ }
+
+}
Propchange: maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/BuilderCommonTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/ConcurrencyDependencyGraphTest.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/ConcurrencyDependencyGraphTest.java?rev=931884&view=auto
==============================================================================
--- maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/ConcurrencyDependencyGraphTest.java (added)
+++ maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/ConcurrencyDependencyGraphTest.java Thu Apr 8 11:29:07 2010
@@ -0,0 +1,92 @@
+/*
+ * 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.
+ */
+package org.apache.maven.lifecycle.internal;
+
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.execution.ProjectDependencyGraph;
+import org.apache.maven.lifecycle.LifecycleNotFoundException;
+import org.apache.maven.lifecycle.LifecyclePhaseNotFoundException;
+import org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub;
+import org.apache.maven.plugin.InvalidPluginDescriptorException;
+import org.apache.maven.plugin.MojoNotFoundException;
+import org.apache.maven.plugin.PluginDescriptorParsingException;
+import org.apache.maven.plugin.PluginNotFoundException;
+import org.apache.maven.plugin.PluginResolutionException;
+import org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException;
+import org.apache.maven.plugin.version.PluginVersionResolutionException;
+import org.apache.maven.project.MavenProject;
+
+import java.util.List;
+
+import static org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub.*;
+
+/**
+ * @author Kristian Rosenvold
+ */
+public class ConcurrencyDependencyGraphTest
+ extends junit.framework.TestCase
+{
+ public void testConcurrencyGraphPrimaryVersion()
+ throws InvalidPluginDescriptorException, PluginVersionResolutionException, PluginDescriptorParsingException,
+ NoPluginFoundForPrefixException, MojoNotFoundException, PluginNotFoundException, PluginResolutionException,
+ LifecyclePhaseNotFoundException, LifecycleNotFoundException
+ {
+ ProjectDependencyGraph dependencyGraph = new ProjectDependencyGraphStub();
+ final MavenSession session = ProjectDependencyGraphStub.getMavenSession();
+
+ ConcurrencyDependencyGraph graph =
+ new ConcurrencyDependencyGraph( getProjectBuildList( session ), dependencyGraph );
+
+ final List<MavenProject> projectBuilds = graph.getRootSchedulableBuilds();
+ assertEquals( 1, projectBuilds.size() );
+ assertEquals( A, projectBuilds.get( 0 ) );
+
+ final List<MavenProject> subsequent = graph.markAsFinished( A );
+ assertEquals( 2, subsequent.size() );
+ assertEquals( ProjectDependencyGraphStub.B, subsequent.get( 0 ) );
+ assertEquals( C, subsequent.get( 1 ) );
+
+ final List<MavenProject> bDescendants = graph.markAsFinished( B );
+ assertEquals( 1, bDescendants.size() );
+ assertEquals( Y, bDescendants.get( 0 ) );
+
+ final List<MavenProject> cDescendants = graph.markAsFinished( C );
+ assertEquals( 2, cDescendants.size() );
+ assertEquals( X, cDescendants.get( 0 ) );
+ assertEquals( Z, cDescendants.get( 1 ) );
+ }
+
+ public void testConcurrencyGraphDifferentCompletionOrder()
+ throws InvalidPluginDescriptorException, PluginVersionResolutionException, PluginDescriptorParsingException,
+ NoPluginFoundForPrefixException, MojoNotFoundException, PluginNotFoundException, PluginResolutionException,
+ LifecyclePhaseNotFoundException, LifecycleNotFoundException
+ {
+ ProjectDependencyGraph dependencyGraph = new ProjectDependencyGraphStub();
+ final MavenSession session = ProjectDependencyGraphStub.getMavenSession();
+ ConcurrencyDependencyGraph graph =
+ new ConcurrencyDependencyGraph( getProjectBuildList( session ), dependencyGraph );
+
+ graph.markAsFinished( A );
+ final List<MavenProject> cDescendants = graph.markAsFinished( C );
+ assertEquals( 1, cDescendants.size() );
+ assertEquals( Z, cDescendants.get( 0 ) );
+
+ final List<MavenProject> bDescendants = graph.markAsFinished( B );
+ assertEquals( 2, bDescendants.size() );
+ assertEquals( X, bDescendants.get( 0 ) );
+ assertEquals( Y, bDescendants.get( 1 ) );
+ }
+
+}
Propchange: maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/ConcurrencyDependencyGraphTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/ExecutionPlanItemTest.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/ExecutionPlanItemTest.java?rev=931884&view=auto
==============================================================================
--- maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/ExecutionPlanItemTest.java (added)
+++ maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/ExecutionPlanItemTest.java Thu Apr 8 11:29:07 2010
@@ -0,0 +1,67 @@
+/*
+ * 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.
+ */
+package org.apache.maven.lifecycle.internal;
+
+import junit.framework.TestCase;
+import org.apache.maven.lifecycle.Schedule;
+import org.apache.maven.lifecycle.internal.stub.MojoExecutorStub;
+import org.apache.maven.plugin.MojoExecution;
+
+/**
+ * @author Kristian Rosenvold
+ */
+public class ExecutionPlanItemTest
+ extends TestCase
+{
+
+ public void testSetComplete()
+ throws Exception
+ {
+ ExecutionPlanItem item = createExecutionPlanItem( "testMojo", null );
+ item.setComplete(); // This itself is a valid test
+ assertFalse( item.ensureComplete() );
+ }
+
+ public void testWaitUntilDone()
+ throws Exception
+ {
+
+ final ExecutionPlanItem item =
+ createExecutionPlanItem( "testMojo", createExecutionPlanItem( "testMojo2", null ) );
+ new Thread( new Runnable()
+ {
+ public void run()
+ {
+ item.setComplete();
+ }
+ } ).start();
+ item.waitUntilDone();
+ }
+
+
+ public static ExecutionPlanItem createExecutionPlanItem( String mojoDescription, ExecutionPlanItem downStream )
+ {
+ return createExecutionPlanItem( mojoDescription, downStream, null );
+ }
+
+ public static ExecutionPlanItem createExecutionPlanItem( String mojoDescription, ExecutionPlanItem downStream,
+ Schedule schedule )
+ {
+ return new ExecutionPlanItem( new MojoExecution( MojoExecutorStub.createMojoDescriptor( mojoDescription ) ),
+ schedule );
+ }
+
+
+}
Propchange: maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/ExecutionPlanItemTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/LifecycleExecutionPlanCalculatorTest.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/LifecycleExecutionPlanCalculatorTest.java?rev=931884&view=auto
==============================================================================
--- maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/LifecycleExecutionPlanCalculatorTest.java (added)
+++ maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/LifecycleExecutionPlanCalculatorTest.java Thu Apr 8 11:29:07 2010
@@ -0,0 +1,77 @@
+/*
+ * 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.
+ */
+
+package org.apache.maven.lifecycle.internal;
+
+import junit.framework.TestCase;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.lifecycle.MavenExecutionPlan;
+import org.apache.maven.lifecycle.internal.stub.BuildPluginManagerStub;
+import org.apache.maven.lifecycle.internal.stub.DefaultLifecyclesStub;
+import org.apache.maven.lifecycle.internal.stub.PluginPrefixResolverStub;
+import org.apache.maven.lifecycle.internal.stub.PluginVersionResolverStub;
+import org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub;
+
+/**
+ * @author Kristian Rosenvold>
+ */
+
+public class LifecycleExecutionPlanCalculatorTest
+ extends TestCase
+{
+
+ public void testCalculateExecutionPlanWithGoalTasks()
+ throws Exception
+ {
+ MojoDescriptorCreator mojoDescriptorCreator = createMojoDescriptorCreator();
+ LifecycleExecutionPlanCalculator lifecycleExecutionPlanCalculator =
+ createExecutionPlaceCalculator( mojoDescriptorCreator );
+
+ final GoalTask goalTask1 = new GoalTask( "compiler:compile" );
+ final GoalTask goalTask2 = new GoalTask( "surefire:test" );
+ final TaskSegment taskSegment1 = new TaskSegment( false, goalTask1, goalTask2 );
+ final MavenSession session1 = ProjectDependencyGraphStub.getMavenSession( ProjectDependencyGraphStub.A );
+
+ MavenExecutionPlan executionPlan =
+ lifecycleExecutionPlanCalculator.calculateExecutionPlan( session1, ProjectDependencyGraphStub.A,
+ taskSegment1.getTasks() );
+ assertEquals( 2, executionPlan.size() );
+
+ final GoalTask goalTask3 = new GoalTask( "surefire:test" );
+ final TaskSegment taskSegment2 = new TaskSegment( false, goalTask1, goalTask2, goalTask3 );
+ MavenExecutionPlan executionPlan2 =
+ lifecycleExecutionPlanCalculator.calculateExecutionPlan( session1, ProjectDependencyGraphStub.A,
+ taskSegment2.getTasks() );
+ assertEquals( 3, executionPlan2.size() );
+ }
+
+ // Maybe also make one with LifeCycleTasks
+
+ private LifecycleExecutionPlanCalculator createExecutionPlaceCalculator(
+ MojoDescriptorCreator mojoDescriptorCreator )
+ {
+ LifecyclePluginResolver lifecyclePluginResolver =
+ new LifecyclePluginResolver( new PluginVersionResolverStub() );
+ return new LifecycleExecutionPlanCalculatorImpl( new BuildPluginManagerStub(),
+ DefaultLifecyclesStub.createDefaultLifeCycles(),
+ mojoDescriptorCreator, lifecyclePluginResolver );
+ }
+
+ private MojoDescriptorCreator createMojoDescriptorCreator()
+ {
+ return new MojoDescriptorCreator( new PluginVersionResolverStub(), new BuildPluginManagerStub(),
+ new PluginPrefixResolverStub() );
+ }
+}
Propchange: maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/LifecycleExecutionPlanCalculatorTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/LifecycleWeaveBuilderTest.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/LifecycleWeaveBuilderTest.java?rev=931884&view=auto
==============================================================================
--- maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/LifecycleWeaveBuilderTest.java (added)
+++ maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/LifecycleWeaveBuilderTest.java Thu Apr 8 11:29:07 2010
@@ -0,0 +1,135 @@
+/*
+ * 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.
+ */
+package org.apache.maven.lifecycle.internal;
+
+import junit.framework.TestCase;
+import org.apache.maven.execution.DefaultMavenExecutionResult;
+import org.apache.maven.execution.MavenExecutionResult;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.lifecycle.LifecycleNotFoundException;
+import org.apache.maven.lifecycle.LifecyclePhaseNotFoundException;
+import org.apache.maven.lifecycle.internal.stub.CompletionServiceStub;
+import org.apache.maven.lifecycle.internal.stub.LifecycleExecutionPlanCalculatorStub;
+import org.apache.maven.lifecycle.internal.stub.LoggerStub;
+import org.apache.maven.lifecycle.internal.stub.MojoExecutorStub;
+import org.apache.maven.lifecycle.internal.stub.ProjectDependenciesResolverStub;
+import org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub;
+import org.apache.maven.plugin.InvalidPluginDescriptorException;
+import org.apache.maven.plugin.MojoNotFoundException;
+import org.apache.maven.plugin.PluginDescriptorParsingException;
+import org.apache.maven.plugin.PluginNotFoundException;
+import org.apache.maven.plugin.PluginResolutionException;
+import org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException;
+import org.apache.maven.plugin.version.PluginVersionResolutionException;
+
+import java.util.List;
+import java.util.concurrent.CompletionService;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorCompletionService;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+/**
+ * @author Kristian Rosenvold>
+ */
+public class LifecycleWeaveBuilderTest
+ extends TestCase
+{
+
+ public void testBuildProjectSynchronously()
+ throws Exception
+ {
+ final CompletionService<ProjectSegment> service = new CompletionServiceStub( true );
+ final ProjectBuildList projectBuildList = runWithCompletionService( service );
+ assertEquals( "Expect all tasks to be scheduled", projectBuildList.size(),
+ ( (CompletionServiceStub) service ).size() );
+ }
+
+ public void testBuildProjectThreaded()
+ throws Exception
+ {
+ ExecutorService executor = Executors.newFixedThreadPool( 10 );
+ ExecutorCompletionService<ProjectSegment> service = new ExecutorCompletionService<ProjectSegment>( executor );
+ runWithCompletionService( service );
+ executor.shutdown();
+ }
+
+ public void testBuildProjectThreadedAggressive()
+ throws Exception
+ {
+ ExecutorService executor = Executors.newFixedThreadPool( 10 );
+ ExecutorCompletionService<ProjectSegment> service = new ExecutorCompletionService<ProjectSegment>( executor );
+ runWithCompletionService( service );
+ executor.shutdown();
+ }
+
+ private ProjectBuildList runWithCompletionService( CompletionService<ProjectSegment> service )
+ throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
+ MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
+ PluginVersionResolutionException, LifecyclePhaseNotFoundException, LifecycleNotFoundException,
+ ExecutionException, InterruptedException
+ {
+ final ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ try
+ {
+ BuildListCalculator buildListCalculator = BuildListCalculatorTest.createBuildListCalculator();
+ final MavenSession session = ProjectDependencyGraphStub.getMavenSession();
+ List<TaskSegment> taskSegments = buildListCalculator.calculateTaskSegments( session );
+ ProjectBuildList projectBuildList = buildListCalculator.calculateProjectBuilds( session, taskSegments );
+
+ final MojoExecutorStub mojoExecutorStub = new MojoExecutorStub();
+ final LifecycleWeaveBuilder builder = getWeaveBuilder( mojoExecutorStub );
+ final ReactorContext buildContext = createBuildContext( session );
+ ReactorBuildStatus reactorBuildStatus = new ReactorBuildStatus( session.getProjectDependencyGraph() );
+ builder.build( projectBuildList, buildContext, taskSegments, session, service, reactorBuildStatus );
+
+ LifecycleExecutionPlanCalculatorStub lifecycleExecutionPlanCalculatorStub =
+ new LifecycleExecutionPlanCalculatorStub();
+ final int expected = lifecycleExecutionPlanCalculatorStub.getNumberOfExceutions( projectBuildList );
+ assertEquals( "All executions should be scheduled", expected, mojoExecutorStub.executions.size() );
+ return projectBuildList;
+ }
+ finally
+ {
+ Thread.currentThread().setContextClassLoader( loader );
+ }
+ }
+
+
+ private ReactorContext createBuildContext( MavenSession session )
+ {
+ MavenExecutionResult mavenExecutionResult = new DefaultMavenExecutionResult();
+ ReactorBuildStatus reactorBuildStatus = new ReactorBuildStatus( session.getProjectDependencyGraph() );
+ return new ReactorContext( mavenExecutionResult, null, null, reactorBuildStatus );
+ }
+
+ private LifecycleWeaveBuilder getWeaveBuilder( MojoExecutor mojoExecutor )
+ {
+ final BuilderCommon builderCommon = getBuilderCommon();
+ final LoggerStub loggerStub = new LoggerStub();
+ final LifecycleDependencyResolver lifecycleDependencyResolver =
+ new LifecycleDependencyResolver( new ProjectDependenciesResolverStub(), loggerStub );
+ return new LifecycleWeaveBuilder( mojoExecutor, builderCommon, loggerStub, lifecycleDependencyResolver );
+
+ }
+
+ private BuilderCommon getBuilderCommon()
+ {
+ final LifecycleDebugLogger logger = new LifecycleDebugLogger( new LoggerStub() );
+ final LifecycleDependencyResolver lifecycleDependencyResolver =
+ new LifecycleDependencyResolver( new ProjectDependenciesResolverStub(), new LoggerStub() );
+ return new BuilderCommon( logger, new LifecycleExecutionPlanCalculatorStub(), lifecycleDependencyResolver );
+ }
+}
Propchange: maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/LifecycleWeaveBuilderTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/ProjectBuildListTest.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/ProjectBuildListTest.java?rev=931884&view=auto
==============================================================================
--- maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/ProjectBuildListTest.java (added)
+++ maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/ProjectBuildListTest.java Thu Apr 8 11:29:07 2010
@@ -0,0 +1,41 @@
+/*
+ * 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.
+ */
+package org.apache.maven.lifecycle.internal;
+
+import junit.framework.TestCase;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub;
+
+/**
+ * @author Kristian Rosenvold
+ */
+public class ProjectBuildListTest
+ extends TestCase
+{
+
+ public void testGetByTaskSegment()
+ throws Exception
+ {
+ final MavenSession session = ProjectDependencyGraphStub.getMavenSession();
+ ProjectBuildList projectBuildList = ProjectDependencyGraphStub.getProjectBuildList( session );
+ TaskSegment taskSegment = projectBuildList.get( 0 ).getTaskSegment();
+ assertTrue( "This test assumes there are at least 6 elements in projectBuilds", projectBuildList.size() >= 6 );
+
+ final ProjectBuildList byTaskSegment = projectBuildList.getByTaskSegment( taskSegment );
+ assertEquals( projectBuildList.size(),
+ byTaskSegment.size() ); // Todo: Make multiple segments on projectBuildList
+ }
+
+}
Propchange: maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/ProjectBuildListTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/ThreadConfigurationServiceTest.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/ThreadConfigurationServiceTest.java?rev=931884&view=auto
==============================================================================
--- maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/ThreadConfigurationServiceTest.java (added)
+++ maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/ThreadConfigurationServiceTest.java Thu Apr 8 11:29:07 2010
@@ -0,0 +1,21 @@
+package org.apache.maven.lifecycle.internal;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+import org.apache.maven.lifecycle.internal.stub.LoggerStub;
+
+/**
+ * @author Kristian Rosenvold
+ */
+public class ThreadConfigurationServiceTest
+ extends TestCase
+{
+ public void testGetThreadCount()
+ throws Exception
+ {
+ ThreadConfigurationService threadConfigurationService = new ThreadConfigurationService( new LoggerStub(), 3 );
+
+ Assert.assertEquals( 5, threadConfigurationService.getThreadCount( "1.75", true, 6 ).intValue() );
+ Assert.assertEquals( 6, threadConfigurationService.getThreadCount( "1.84", true, 6 ).intValue() );
+ }
+}
Propchange: maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/ThreadConfigurationServiceTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/ThreadOutputMuxerTest.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/ThreadOutputMuxerTest.java?rev=931884&view=auto
==============================================================================
--- maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/ThreadOutputMuxerTest.java (added)
+++ maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/ThreadOutputMuxerTest.java Thu Apr 8 11:29:07 2010
@@ -0,0 +1,163 @@
+/*
+ * 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.
+ */
+package org.apache.maven.lifecycle.internal;
+
+import junit.framework.TestCase;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.lifecycle.LifecycleNotFoundException;
+import org.apache.maven.lifecycle.LifecyclePhaseNotFoundException;
+import org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub;
+import org.apache.maven.plugin.InvalidPluginDescriptorException;
+import org.apache.maven.plugin.MojoNotFoundException;
+import org.apache.maven.plugin.PluginDescriptorParsingException;
+import org.apache.maven.plugin.PluginNotFoundException;
+import org.apache.maven.plugin.PluginResolutionException;
+import org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException;
+import org.apache.maven.plugin.version.PluginVersionResolutionException;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import java.util.concurrent.Callable;
+import java.util.concurrent.CompletionService;
+import java.util.concurrent.ExecutorCompletionService;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+
+/**
+ * @author Kristian Rosenvold
+ */
+public class ThreadOutputMuxerTest
+ extends TestCase
+{
+
+ final String paid = "Paid";
+
+ final String in = "In";
+
+ final String full = "Full";
+
+ public void testSingleThreaded()
+ throws Exception
+ {
+ ProjectBuildList src = getProjectBuildList();
+ ProjectBuildList projectBuildList =
+ new ProjectBuildList( Arrays.asList( src.get( 0 ), src.get( 1 ), src.get( 2 ) ) );
+
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ PrintStream systemOut = new PrintStream( byteArrayOutputStream );
+ ThreadOutputMuxer threadOutputMuxer = new ThreadOutputMuxer( projectBuildList, systemOut );
+
+ threadOutputMuxer.associateThreadWithProjectSegment( projectBuildList.get( 0 ) );
+ System.out.print( paid ); // No, this does not print to system.out. It's part of the test
+ assertEquals( paid.length(), byteArrayOutputStream.size() );
+ threadOutputMuxer.associateThreadWithProjectSegment( projectBuildList.get( 1 ) );
+ System.out.print( in ); // No, this does not print to system.out. It's part of the test
+ assertEquals( paid.length(), byteArrayOutputStream.size() );
+ threadOutputMuxer.associateThreadWithProjectSegment( projectBuildList.get( 2 ) );
+ System.out.print( full ); // No, this does not print to system.out. It's part of the test
+ assertEquals( paid.length(), byteArrayOutputStream.size() );
+
+ threadOutputMuxer.setThisModuleComplete( projectBuildList.get( 0 ) );
+ threadOutputMuxer.setThisModuleComplete( projectBuildList.get( 1 ) );
+ threadOutputMuxer.setThisModuleComplete( projectBuildList.get( 2 ) );
+ threadOutputMuxer.close();
+ assertEquals( ( paid + in + full ).length(), byteArrayOutputStream.size() );
+ }
+
+ public void testMultiThreaded()
+ throws Exception
+ {
+ ProjectBuildList projectBuildList = getProjectBuildList();
+
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ PrintStream systemOut = new PrintStream( byteArrayOutputStream );
+ final ThreadOutputMuxer threadOutputMuxer = new ThreadOutputMuxer( projectBuildList, systemOut );
+
+ final List<String> stringList =
+ Arrays.asList( "Thinkin", "of", "a", "master", "plan", "Cuz", "ainât", "nuthin", "but", "sweat", "inside",
+ "my", "hand" );
+ Iterator<String> lyrics = stringList.iterator();
+ List<Outputter> outputters = new ArrayList<Outputter>();
+
+ ExecutorService executor = Executors.newFixedThreadPool( 10 );
+ CompletionService<ProjectSegment> service = new ExecutorCompletionService<ProjectSegment>( executor );
+
+ List<Future<ProjectSegment>> futures = new ArrayList<Future<ProjectSegment>>();
+ for ( ProjectSegment projectBuild : projectBuildList )
+ {
+ final Future<ProjectSegment> buildFuture =
+ service.submit( new Outputter( threadOutputMuxer, projectBuild, lyrics.next() ) );
+ futures.add( buildFuture );
+ }
+
+ for ( Future<ProjectSegment> future : futures )
+ {
+ future.get();
+ }
+ int expectedLength = 0;
+ for ( int i = 0; i < projectBuildList.size(); i++ )
+ {
+ expectedLength += stringList.get( i ).length();
+ }
+
+ threadOutputMuxer.close();
+ final byte[] bytes = byteArrayOutputStream.toByteArray();
+ String result = new String( bytes );
+ assertEquals( result, expectedLength, bytes.length );
+
+
+ }
+
+ class Outputter
+ implements Callable<ProjectSegment>
+ {
+ private final ThreadOutputMuxer threadOutputMuxer;
+
+ private final ProjectSegment item;
+
+ private final String response;
+
+ Outputter( ThreadOutputMuxer threadOutputMuxer, ProjectSegment item, String response )
+ {
+ this.threadOutputMuxer = threadOutputMuxer;
+ this.item = item;
+ this.response = response;
+ }
+
+ public ProjectSegment call()
+ throws Exception
+ {
+ threadOutputMuxer.associateThreadWithProjectSegment( item );
+ System.out.print( response );
+ threadOutputMuxer.setThisModuleComplete( item );
+ return item;
+ }
+ }
+
+
+ private ProjectBuildList getProjectBuildList()
+ throws InvalidPluginDescriptorException, PluginVersionResolutionException, PluginDescriptorParsingException,
+ NoPluginFoundForPrefixException, MojoNotFoundException, PluginNotFoundException, PluginResolutionException,
+ LifecyclePhaseNotFoundException, LifecycleNotFoundException
+ {
+ final MavenSession session = ProjectDependencyGraphStub.getMavenSession();
+ return ProjectDependencyGraphStub.getProjectBuildList( session );
+ }
+}
Propchange: maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/ThreadOutputMuxerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/AboutTheStubs.html
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/AboutTheStubs.html?rev=931884&view=auto
==============================================================================
--- maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/AboutTheStubs.html (added)
+++ maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/AboutTheStubs.html Thu Apr 8 11:29:07 2010
@@ -0,0 +1,36 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+ "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+ <title>About these stubs</title>
+</head>
+<body>
+<h2>Design</h2>
+These stubs can be thought of as hand-coded mock obects. They allow unit tests to test only specific
+aspects of a component while ignoring others.
+
+These stubs form an internally consistent data-set that is not expected to change. They are
+used to test the individual components in the lifecycle with data that has expected characteristics
+and can be asserted as desired.
+
+You can change/extend these stubs, and tests should not be breaking too much, since most tests
+assert using expected values from the stubs. Normally, when you try to use data from the stubs that
+have not been properly populated, you'll get a nullpointer in your test and you then have to
+identify which stub creates that specific piece of data.
+
+The most important stubs are:
+LifecycleExecutionPlanCalculatorStub
+ProjectDependencyGraphStub
+
+Since they define the primary structure of the project/build.
+
+The stubs define three top-level targets that are defined in LifecycleTaskSegmentCalculatorStub;
+clean, aggr and install. "aggr" is an aggregating task while clean and install are lifecyclephases.
+There will be three items in the task list for this dataset.
+
+The stubs also exist at different "levels", where one test might wire stubs into a specific live implementation.
+In the next test that same "live implementation" will be used in a stub version instead.
+
+Not all live services have stubs, but can be added as needed.
+</body>
+</html>
\ No newline at end of file
Propchange: maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/AboutTheStubs.html
------------------------------------------------------------------------------
svn:eol-style = native
Added: maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/BuildPluginManagerStub.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/BuildPluginManagerStub.java?rev=931884&view=auto
==============================================================================
--- maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/BuildPluginManagerStub.java (added)
+++ maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/BuildPluginManagerStub.java Thu Apr 8 11:29:07 2010
@@ -0,0 +1,67 @@
+/*
+ * 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.
+ */
+
+package org.apache.maven.lifecycle.internal.stub;
+
+import org.apache.maven.artifact.repository.RepositoryRequest;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.model.Plugin;
+import org.apache.maven.plugin.BuildPluginManager;
+import org.apache.maven.plugin.InvalidPluginDescriptorException;
+import org.apache.maven.plugin.MojoExecution;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugin.MojoNotFoundException;
+import org.apache.maven.plugin.PluginConfigurationException;
+import org.apache.maven.plugin.PluginDescriptorParsingException;
+import org.apache.maven.plugin.PluginManagerException;
+import org.apache.maven.plugin.PluginNotFoundException;
+import org.apache.maven.plugin.PluginResolutionException;
+import org.apache.maven.plugin.descriptor.MojoDescriptor;
+import org.apache.maven.plugin.descriptor.PluginDescriptor;
+import org.codehaus.plexus.classworlds.realm.ClassRealm;
+
+/**
+ * @author Kristian Rosenvold
+ */
+public class BuildPluginManagerStub
+ implements BuildPluginManager
+{
+
+ public PluginDescriptor loadPlugin( Plugin plugin, RepositoryRequest repositoryRequest )
+ throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
+ InvalidPluginDescriptorException
+ {
+ return null;
+ }
+
+ public MojoDescriptor getMojoDescriptor( Plugin plugin, String goal, RepositoryRequest repositoryRequest )
+ throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
+ MojoNotFoundException, InvalidPluginDescriptorException
+ {
+ return MojoExecutorStub.createMojoDescriptor( plugin.getKey() );
+ }
+
+ public ClassRealm getPluginRealm( MavenSession session, PluginDescriptor pluginDescriptor )
+ throws PluginResolutionException, PluginManagerException
+ {
+ return null;
+ }
+
+ public void executeMojo( MavenSession session, MojoExecution execution )
+ throws MojoFailureException, MojoExecutionException, PluginConfigurationException, PluginManagerException
+ {
+ }
+}
Propchange: maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/BuildPluginManagerStub.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/CompletionServiceStub.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/CompletionServiceStub.java?rev=931884&view=auto
==============================================================================
--- maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/CompletionServiceStub.java (added)
+++ maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/CompletionServiceStub.java Thu Apr 8 11:29:07 2010
@@ -0,0 +1,89 @@
+/*
+ * 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.
+ */
+
+package org.apache.maven.lifecycle.internal.stub;
+
+import org.apache.maven.lifecycle.internal.ProjectSegment;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.Callable;
+import java.util.concurrent.CompletionService;
+import java.util.concurrent.Future;
+import java.util.concurrent.FutureTask;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @author Kristian Rosenvold
+ */
+public class CompletionServiceStub
+ implements CompletionService<ProjectSegment>
+{
+ List<FutureTask<ProjectSegment>> projectBuildFutureTasks =
+ Collections.synchronizedList( new ArrayList<FutureTask<ProjectSegment>>() );
+
+ final boolean finishImmediately;
+
+
+ public int size()
+ {
+ return projectBuildFutureTasks.size();
+ }
+
+ public CompletionServiceStub( boolean finishImmediately )
+ {
+ this.finishImmediately = finishImmediately;
+ }
+
+ public Future<ProjectSegment> submit( Callable<ProjectSegment> task )
+ {
+ FutureTask<ProjectSegment> projectBuildFutureTask = new FutureTask<ProjectSegment>( task );
+ projectBuildFutureTasks.add( projectBuildFutureTask );
+ if ( finishImmediately )
+ {
+ projectBuildFutureTask.run();
+ }
+ return projectBuildFutureTask;
+ }
+
+ public Future<ProjectSegment> submit( Runnable task, ProjectSegment result )
+ {
+ FutureTask<ProjectSegment> projectBuildFutureTask = new FutureTask<ProjectSegment>( task, result );
+ projectBuildFutureTasks.add( projectBuildFutureTask );
+ if ( finishImmediately )
+ {
+ projectBuildFutureTask.run();
+ }
+ return projectBuildFutureTask;
+ }
+
+ public Future<ProjectSegment> take()
+ throws InterruptedException
+ {
+ return null;
+ }
+
+ public Future<ProjectSegment> poll()
+ {
+ return null;
+ }
+
+ public Future<ProjectSegment> poll( long timeout, TimeUnit unit )
+ throws InterruptedException
+ {
+ return null;
+ }
+}
Propchange: maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/CompletionServiceStub.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/DefaultLifecyclesStub.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/DefaultLifecyclesStub.java?rev=931884&view=auto
==============================================================================
--- maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/DefaultLifecyclesStub.java (added)
+++ maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/DefaultLifecyclesStub.java Thu Apr 8 11:29:07 2010
@@ -0,0 +1,56 @@
+/*
+ * 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.
+ */
+
+package org.apache.maven.lifecycle.internal.stub;
+
+import org.apache.maven.lifecycle.DefaultLifecycles;
+import org.apache.maven.lifecycle.Lifecycle;
+import org.apache.maven.lifecycle.Schedule;
+import org.apache.maven.lifecycle.Scheduling;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * @author Kristian Rosenvold
+ */
+
+public class DefaultLifecyclesStub
+{
+ public static DefaultLifecycles createDefaultLifeCycles()
+ {
+ final Lifecycle lifecycle1 = new Lifecycle( "abc", Arrays.asList( "compile" ), null );
+ final Lifecycle lifecycle2 = new Lifecycle( "abc", Arrays.asList( "test" ), null );
+ final List<Lifecycle> lifeCycles = Arrays.asList( lifecycle1, lifecycle2 );
+ final List<Scheduling> schedulingList = getSchedulingList();
+ final DefaultLifecycles defaultLifecycles = new DefaultLifecycles( lifeCycles, schedulingList );
+ try
+ {
+ defaultLifecycles.initialize();
+ }
+ catch ( InitializationException e )
+ {
+ throw new RuntimeException( e );
+ }
+ return defaultLifecycles;
+ }
+
+ public static List<Scheduling> getSchedulingList()
+ {
+ return Arrays.asList( new Scheduling( "default", Arrays.asList( new Schedule( "compile", false, false ),
+ new Schedule( "test", false, true ) ) ) );
+ }
+}
\ No newline at end of file
Propchange: maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/DefaultLifecyclesStub.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/LifeCyclePluginAnalyzerStub.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/LifeCyclePluginAnalyzerStub.java?rev=931884&view=auto
==============================================================================
--- maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/LifeCyclePluginAnalyzerStub.java (added)
+++ maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/LifeCyclePluginAnalyzerStub.java Thu Apr 8 11:29:07 2010
@@ -0,0 +1,74 @@
+/*
+ * 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.
+ */
+
+package org.apache.maven.lifecycle.internal.stub;
+
+import org.apache.maven.lifecycle.LifeCyclePluginAnalyzer;
+import org.apache.maven.model.Plugin;
+import org.apache.maven.model.PluginExecution;
+
+import java.util.Collections;
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+/**
+ * @author Kristian Rosenvold
+ */
+public class LifeCyclePluginAnalyzerStub
+ implements LifeCyclePluginAnalyzer
+{
+ public Set<Plugin> getPluginsBoundByDefaultToAllLifecycles( String packaging )
+ {
+ Set<Plugin> plugins;
+
+ // NOTE: The upper-case packaging name is intentional, that's a special hinting mode used for certain tests
+ if ( "JAR".equals( packaging ) )
+ {
+ plugins = new LinkedHashSet<Plugin>();
+
+ plugins.add( newPlugin( "maven-compiler-plugin", "compile", "testCompile" ) );
+ plugins.add( newPlugin( "maven-resources-plugin", "resources", "testResources" ) );
+ plugins.add( newPlugin( "maven-surefire-plugin", "test" ) );
+ plugins.add( newPlugin( "maven-jar-plugin", "jar" ) );
+ plugins.add( newPlugin( "maven-install-plugin", "install" ) );
+ plugins.add( newPlugin( "maven-deploy-plugin", "deploy" ) );
+ }
+ else
+ {
+ plugins = Collections.emptySet();
+ }
+
+ return plugins;
+ }
+
+ private Plugin newPlugin( String artifactId, String... goals )
+ {
+ Plugin plugin = new Plugin();
+
+ plugin.setGroupId( "org.apache.maven.plugins" );
+ plugin.setArtifactId( artifactId );
+
+ for ( String goal : goals )
+ {
+ PluginExecution pluginExecution = new PluginExecution();
+ pluginExecution.setId( "default-" + goal );
+ pluginExecution.addGoal( goal );
+ plugin.addExecution( pluginExecution );
+ }
+
+ return plugin;
+ }
+
+}
Propchange: maven/maven-3/trunk/maven-core/src/test/java/org/apache/maven/lifecycle/internal/stub/LifeCyclePluginAnalyzerStub.java
------------------------------------------------------------------------------
svn:eol-style = native