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