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