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