View Javadoc
1   package org.apache.maven.lifecycle.internal.builder;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
5    * agreements. See the NOTICE file distributed with this work for additional information regarding
6    * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance with the License. You may obtain a
8    * copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software distributed under the License
13   * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14   * or implied. See the License for the specific language governing permissions and limitations under
15   * the License.
16   */
17  
18  import java.util.HashSet;
19  
20  import org.apache.maven.execution.MavenSession;
21  import org.apache.maven.lifecycle.MavenExecutionPlan;
22  import org.apache.maven.lifecycle.internal.ExecutionEventCatapult;
23  import org.apache.maven.lifecycle.internal.LifecycleDebugLogger;
24  import org.apache.maven.lifecycle.internal.TaskSegment;
25  import org.apache.maven.lifecycle.internal.stub.LifecycleExecutionPlanCalculatorStub;
26  import org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub;
27  import org.junit.jupiter.api.Test;
28  import org.slf4j.Logger;
29  
30  import static org.junit.jupiter.api.Assertions.assertEquals;
31  import static org.mockito.Mockito.mock;
32  import static org.mockito.Mockito.verify;
33  
34  /**
35   * @author Kristian Rosenvold
36   */
37  public class BuilderCommonTest
38  {
39      private Logger logger = mock( Logger.class );
40  
41      @Test
42      public void testResolveBuildPlan()
43          throws Exception
44      {
45          MavenSession original = ProjectDependencyGraphStub.getMavenSession();
46  
47          final TaskSegment taskSegment1 = new TaskSegment( false );
48          final MavenSession session1 = original.clone();
49          session1.setCurrentProject( ProjectDependencyGraphStub.A );
50  
51          final BuilderCommon builderCommon = getBuilderCommon( logger );
52          final MavenExecutionPlan plan =
53              builderCommon.resolveBuildPlan( session1, ProjectDependencyGraphStub.A, taskSegment1,
54                      new HashSet<>() );
55          assertEquals( LifecycleExecutionPlanCalculatorStub.getProjectAExecutionPlan().size(), plan.size() );
56      }
57  
58      @Test
59      public void testDefaultBindingPluginsWarning()
60          throws Exception
61      {
62          MavenSession original = ProjectDependencyGraphStub.getMavenSession();
63  
64          final TaskSegment taskSegment1 = new TaskSegment( false );
65          final MavenSession session1 = original.clone();
66          session1.setCurrentProject( ProjectDependencyGraphStub.A );
67  
68          getBuilderCommon( logger ).resolveBuildPlan( session1, ProjectDependencyGraphStub.A, taskSegment1, new HashSet<>() );
69  
70          verify( logger ).warn("Version not locked for default bindings plugins ["
71              + "stub-plugin-initialize, "
72              + "stub-plugin-process-resources, "
73              + "stub-plugin-compile, "
74              + "stub-plugin-process-test-resources, "
75              + "stub-plugin-test-compile, "
76              + "stub-plugin-test, "
77              + "stub-plugin-package, "
78              + "stub-plugin-install], "
79              + "you should define versions in pluginManagement section of your pom.xml or parent");
80      }
81  
82      @Test
83      public void testHandleBuildError()
84          throws Exception
85      {
86      }
87  
88      @Test
89      public void testAttachToThread()
90          throws Exception
91      {
92      }
93  
94      @Test
95      public void testGetKey()
96          throws Exception
97      {
98      }
99  
100     public BuilderCommon getBuilderCommon( Logger logger )
101     {
102         final LifecycleDebugLogger debugLogger = new LifecycleDebugLogger();
103         return new BuilderCommon( debugLogger, new LifecycleExecutionPlanCalculatorStub(), mock(
104                 ExecutionEventCatapult.class ),  logger );
105     }
106 
107 }