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.project;
20  
21  import java.util.Collections;
22  import java.util.LinkedHashSet;
23  import java.util.List;
24  import java.util.Set;
25  
26  import org.apache.maven.execution.MavenSession;
27  import org.apache.maven.lifecycle.LifecycleExecutor;
28  import org.apache.maven.lifecycle.MavenExecutionPlan;
29  import org.apache.maven.model.Plugin;
30  import org.apache.maven.model.PluginExecution;
31  import org.apache.maven.plugin.MojoExecution;
32  
33  /**
34   * A stub implementation that assumes an empty lifecycle to bypass interaction with the plugin manager and to avoid
35   * plugin artifact resolution from repositories.
36   *
37   */
38  public class EmptyLifecycleExecutor implements LifecycleExecutor {
39  
40      public MavenExecutionPlan calculateExecutionPlan(MavenSession session, String... tasks) {
41          return new MavenExecutionPlan(null, null);
42      }
43  
44      public MavenExecutionPlan calculateExecutionPlan(MavenSession session, boolean setup, String... tasks) {
45          return new MavenExecutionPlan(null, null);
46      }
47  
48      public void execute(MavenSession session) {}
49  
50      public Set<Plugin> getPluginsBoundByDefaultToAllLifecycles(String packaging) {
51          Set<Plugin> plugins;
52  
53          // NOTE: The upper-case packaging name is intentional, that's a special hinting mode used for certain tests
54          if ("JAR".equals(packaging)) {
55              plugins = new LinkedHashSet<>();
56  
57              plugins.add(newPlugin("maven-compiler-plugin", "compile", "testCompile"));
58              plugins.add(newPlugin("maven-resources-plugin", "resources", "testResources"));
59              plugins.add(newPlugin("maven-surefire-plugin", "test"));
60              plugins.add(newPlugin("maven-jar-plugin", "jar"));
61              plugins.add(newPlugin("maven-install-plugin", "install"));
62              plugins.add(newPlugin("maven-deploy-plugin", "deploy"));
63          } else {
64              plugins = Collections.emptySet();
65          }
66  
67          return plugins;
68      }
69  
70      private Plugin newPlugin(String artifactId, String... goals) {
71          Plugin plugin = new Plugin();
72  
73          plugin.setGroupId("org.apache.maven.plugins");
74          plugin.setArtifactId(artifactId);
75  
76          for (String goal : goals) {
77              PluginExecution pluginExecution = new PluginExecution();
78              pluginExecution.setId("default-" + goal);
79              pluginExecution.setGoals(Collections.singletonList(goal));
80              plugin.addExecution(pluginExecution);
81          }
82  
83          return plugin;
84      }
85  
86      public void calculateForkedExecutions(MojoExecution mojoExecution, MavenSession session) {}
87  
88      public List<MavenProject> executeForkedExecutions(MojoExecution mojoExecution, MavenSession session) {
89          return Collections.emptyList();
90      }
91  }