001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 003 * agreements. See the NOTICE file distributed with this work for additional information regarding 004 * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the 005 * "License"); you may not use this file except in compliance with the License. You may obtain a 006 * copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software distributed under the License 011 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 012 * or implied. See the License for the specific language governing permissions and limitations under 013 * the License. 014 */ 015 016 package org.apache.maven.lifecycle.internal; 017 018 import java.io.File; 019 020 import org.apache.maven.AbstractCoreMavenComponentTestCase; 021 import org.apache.maven.execution.MavenSession; 022 import org.apache.maven.lifecycle.MavenExecutionPlan; 023 import org.apache.maven.lifecycle.internal.stub.BuildPluginManagerStub; 024 import org.apache.maven.lifecycle.internal.stub.DefaultLifecyclesStub; 025 import org.apache.maven.lifecycle.internal.stub.DefaultSchedulesStub; 026 import org.apache.maven.lifecycle.internal.stub.PluginPrefixResolverStub; 027 import org.apache.maven.lifecycle.internal.stub.PluginVersionResolverStub; 028 import org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub; 029 030 /** 031 * @author Kristian Rosenvold> 032 */ 033 public class LifecycleExecutionPlanCalculatorTest 034 extends AbstractCoreMavenComponentTestCase 035 { 036 037 public void testCalculateExecutionPlanWithGoalTasks() 038 throws Exception 039 { 040 MojoDescriptorCreator mojoDescriptorCreator = createMojoDescriptorCreator(); 041 LifecycleExecutionPlanCalculator lifecycleExecutionPlanCalculator = 042 createExecutionPlaceCalculator( mojoDescriptorCreator ); 043 044 final GoalTask goalTask1 = new GoalTask( "compiler:compile" ); 045 final GoalTask goalTask2 = new GoalTask( "surefire:test" ); 046 final TaskSegment taskSegment1 = new TaskSegment( false, goalTask1, goalTask2 ); 047 final MavenSession session1 = ProjectDependencyGraphStub.getMavenSession( ProjectDependencyGraphStub.A ); 048 049 MavenExecutionPlan executionPlan = 050 lifecycleExecutionPlanCalculator.calculateExecutionPlan( session1, ProjectDependencyGraphStub.A, 051 taskSegment1.getTasks() ); 052 assertEquals( 2, executionPlan.size() ); 053 054 final GoalTask goalTask3 = new GoalTask( "surefire:test" ); 055 final TaskSegment taskSegment2 = new TaskSegment( false, goalTask1, goalTask2, goalTask3 ); 056 MavenExecutionPlan executionPlan2 = 057 lifecycleExecutionPlanCalculator.calculateExecutionPlan( session1, ProjectDependencyGraphStub.A, 058 taskSegment2.getTasks() ); 059 assertEquals( 3, executionPlan2.size() ); 060 } 061 062 // Maybe also make one with LifeCycleTasks 063 064 public static LifecycleExecutionPlanCalculator createExecutionPlaceCalculator( MojoDescriptorCreator mojoDescriptorCreator ) 065 { 066 LifecyclePluginResolver lifecyclePluginResolver = new LifecyclePluginResolver( new PluginVersionResolverStub() ); 067 return new DefaultLifecycleExecutionPlanCalculator( new BuildPluginManagerStub(), 068 DefaultLifecyclesStub.createDefaultLifecycles(), 069 mojoDescriptorCreator, lifecyclePluginResolver, 070 DefaultSchedulesStub.createDefaultSchedules() ); 071 } 072 073 public static MojoDescriptorCreator createMojoDescriptorCreator() 074 { 075 return new MojoDescriptorCreator( new PluginVersionResolverStub(), new BuildPluginManagerStub(), 076 new PluginPrefixResolverStub(), 077 new LifecyclePluginResolver( new PluginVersionResolverStub() ) ); 078 } 079 080 @Override 081 protected String getProjectsDirectory() 082 { 083 return "src/test/projects/lifecycle-executor"; 084 } 085 086 }