View Javadoc
1   package org.apache.maven.project;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.Collections;
23  import java.util.LinkedHashSet;
24  import java.util.List;
25  import java.util.Set;
26  
27  import org.apache.maven.execution.MavenSession;
28  import org.apache.maven.lifecycle.DefaultLifecycles;
29  import org.apache.maven.lifecycle.LifecycleExecutor;
30  import org.apache.maven.lifecycle.MavenExecutionPlan;
31  import org.apache.maven.model.Plugin;
32  import org.apache.maven.model.PluginExecution;
33  import org.apache.maven.plugin.MojoExecution;
34  
35  /**
36   * A stub implementation that assumes an empty lifecycle to bypass interaction with the plugin manager and to avoid
37   * plugin artifact resolution from repositories.
38   *
39   * @author Benjamin Bentmann
40   */
41  public class EmptyLifecycleExecutor
42      implements LifecycleExecutor
43  {
44  
45      public MavenExecutionPlan calculateExecutionPlan( MavenSession session, String... tasks )
46      {
47          return new MavenExecutionPlan( null, new DefaultLifecycles() );
48      }
49  
50      public MavenExecutionPlan calculateExecutionPlan( MavenSession session, boolean setup, String... tasks )
51      {
52          return new MavenExecutionPlan( null, new DefaultLifecycles() );
53      }
54  
55      public void execute( MavenSession session )
56      {
57      }
58  
59      public Set<Plugin> getPluginsBoundByDefaultToAllLifecycles( String packaging )
60      {
61          Set<Plugin> plugins;
62  
63          // NOTE: The upper-case packaging name is intentional, that's a special hinting mode used for certain tests
64          if ( "JAR".equals( packaging ) )
65          {
66              plugins = new LinkedHashSet<>();
67  
68              plugins.add( newPlugin( "maven-compiler-plugin", "compile", "testCompile" ) );
69              plugins.add( newPlugin( "maven-resources-plugin", "resources", "testResources" ) );
70              plugins.add( newPlugin( "maven-surefire-plugin", "test" ) );
71              plugins.add( newPlugin( "maven-jar-plugin", "jar" ) );
72              plugins.add( newPlugin( "maven-install-plugin", "install" ) );
73              plugins.add( newPlugin( "maven-deploy-plugin", "deploy" ) );
74          }
75          else
76          {
77              plugins = Collections.emptySet();
78          }
79  
80          return plugins;
81      }
82  
83      private Plugin newPlugin( String artifactId, String... goals )
84      {
85          Plugin plugin = new Plugin();
86  
87          plugin.setGroupId( "org.apache.maven.plugins" );
88          plugin.setArtifactId( artifactId );
89  
90          for ( String goal : goals )
91          {
92              PluginExecution pluginExecution = new PluginExecution();
93              pluginExecution.setId( "default-" + goal );
94              pluginExecution.addGoal( goal );
95              plugin.addExecution( pluginExecution );
96          }
97  
98          return plugin;
99      }
100 
101     public void calculateForkedExecutions( MojoExecution mojoExecution, MavenSession session )
102     {
103     }
104 
105     public List<MavenProject> executeForkedExecutions( MojoExecution mojoExecution, MavenSession session )
106     {
107         return Collections.emptyList();
108     }
109 
110 }