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.stub;
20  
21  import static org.apache.maven.lifecycle.internal.stub.LifecycleExecutionPlanCalculatorStub.*;
22  import static org.mockito.Mockito.mock;
23  import static org.mockito.Mockito.when;
24  
25  import java.util.Arrays;
26  import java.util.HashMap;
27  import java.util.Iterator;
28  import java.util.List;
29  import java.util.Map;
30  import org.apache.maven.lifecycle.DefaultLifecycles;
31  import org.apache.maven.lifecycle.Lifecycle;
32  import org.codehaus.plexus.PlexusContainer;
33  import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
34  
35  /**
36   * @author Kristian Rosenvold
37   */
38  public class DefaultLifecyclesStub {
39      public static DefaultLifecycles createDefaultLifecycles() throws ComponentLookupException {
40  
41          List<String> stubDefaultCycle = Arrays.asList(
42                  VALIDATE.getPhase(),
43                  INITIALIZE.getPhase(),
44                  PROCESS_RESOURCES.getPhase(),
45                  COMPILE.getPhase(),
46                  TEST.getPhase(),
47                  PROCESS_TEST_RESOURCES.getPhase(),
48                  PACKAGE.getPhase(),
49                  "BEER",
50                  INSTALL.getPhase());
51  
52          // The two phases below are really for future expansion, some would say they lack a drink
53          // The point being that they do not really have to match the "real" stuff,
54          List<String> stubCleanCycle = Arrays.asList(PRE_CLEAN.getPhase(), CLEAN.getPhase(), POST_CLEAN.getPhase());
55  
56          List<String> stubSiteCycle =
57                  Arrays.asList(PRE_SITE.getPhase(), SITE.getPhase(), POST_SITE.getPhase(), SITE_DEPLOY.getPhase());
58  
59          List<String> stubWrapperCycle = Arrays.asList(WRAPPER.getPhase());
60  
61          Iterator<List<String>> lcs = Arrays.asList(stubDefaultCycle, stubCleanCycle, stubSiteCycle, stubWrapperCycle)
62                  .iterator();
63  
64          Map<String, Lifecycle> lifeCycles = new HashMap<>();
65          for (String s : DefaultLifecycles.STANDARD_LIFECYCLES) {
66              final Lifecycle lifecycle = new Lifecycle(s, lcs.next(), null);
67              lifeCycles.put(s, lifecycle);
68          }
69  
70          PlexusContainer mockedContainer = mock(PlexusContainer.class);
71          when(mockedContainer.lookupMap(Lifecycle.class)).thenReturn(lifeCycles);
72  
73          return new DefaultLifecycles(mockedContainer);
74      }
75  }