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