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   * @author Benjamin Bentmann
38   */
39  public class EmptyLifecycleExecutor implements LifecycleExecutor {
40  
41      public MavenExecutionPlan calculateExecutionPlan(MavenSession session, String... tasks) {
42          return new MavenExecutionPlan(null, null);
43      }
44  
45      public MavenExecutionPlan calculateExecutionPlan(MavenSession session, boolean setup, String... tasks) {
46          return new MavenExecutionPlan(null, null);
47      }
48  
49      public void execute(MavenSession session) {}
50  
51      public Set<Plugin> getPluginsBoundByDefaultToAllLifecycles(String packaging) {
52          Set<Plugin> plugins;
53  
54          // NOTE: The upper-case packaging name is intentional, that's a special hinting mode used for certain tests
55          if ("JAR".equals(packaging)) {
56              plugins = new LinkedHashSet<>();
57  
58              plugins.add(newPlugin("maven-compiler-plugin", "compile", "testCompile"));
59              plugins.add(newPlugin("maven-resources-plugin", "resources", "testResources"));
60              plugins.add(newPlugin("maven-surefire-plugin", "test"));
61              plugins.add(newPlugin("maven-jar-plugin", "jar"));
62              plugins.add(newPlugin("maven-install-plugin", "install"));
63              plugins.add(newPlugin("maven-deploy-plugin", "deploy"));
64          } else {
65              plugins = Collections.emptySet();
66          }
67  
68          return plugins;
69      }
70  
71      private Plugin newPlugin(String artifactId, String... goals) {
72          Plugin plugin = new Plugin();
73  
74          plugin.setGroupId("org.apache.maven.plugins");
75          plugin.setArtifactId(artifactId);
76  
77          for (String goal : goals) {
78              PluginExecution pluginExecution = new PluginExecution();
79              pluginExecution.setId("default-" + goal);
80              pluginExecution.addGoal(goal);
81              plugin.addExecution(pluginExecution);
82          }
83  
84          return plugin;
85      }
86  
87      public void calculateForkedExecutions(MojoExecution mojoExecution, MavenSession session) {}
88  
89      public List<MavenProject> executeForkedExecutions(MojoExecution mojoExecution, MavenSession session) {
90          return Collections.emptyList();
91      }
92  }