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