View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
3    * agreements. See the NOTICE file distributed with this work for additional information regarding
4    * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
5    * "License"); you may not use this file except in compliance with the License. You may obtain a
6    * copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software distributed under the License
11   * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing permissions and limitations under
13   * the License.
14   */
15  
16  package org.apache.maven.lifecycle.internal.stub;
17  
18  import org.apache.maven.lifecycle.LifeCyclePluginAnalyzer;
19  import org.apache.maven.model.Plugin;
20  import org.apache.maven.model.PluginExecution;
21  
22  import java.util.Collections;
23  import java.util.LinkedHashSet;
24  import java.util.Set;
25  
26  /**
27   * @author Kristian Rosenvold
28   */
29  public class LifeCyclePluginAnalyzerStub
30      implements LifeCyclePluginAnalyzer
31  {
32      public Set<Plugin> getPluginsBoundByDefaultToAllLifecycles( String packaging )
33      {
34          Set<Plugin> plugins;
35  
36          // NOTE: The upper-case packaging name is intentional, that's a special hinting mode used for certain tests
37          if ( "JAR".equals( packaging ) )
38          {
39              plugins = new LinkedHashSet<>();
40  
41              plugins.add( newPlugin( "maven-compiler-plugin", "compile", "testCompile" ) );
42              plugins.add( newPlugin( "maven-resources-plugin", "resources", "testResources" ) );
43              plugins.add( newPlugin( "maven-surefire-plugin", "test" ) );
44              plugins.add( newPlugin( "maven-jar-plugin", "jar" ) );
45              plugins.add( newPlugin( "maven-install-plugin", "install" ) );
46              plugins.add( newPlugin( "maven-deploy-plugin", "deploy" ) );
47          }
48          else
49          {
50              plugins = Collections.emptySet();
51          }
52  
53          return plugins;
54      }
55  
56      private Plugin newPlugin( String artifactId, String... goals )
57      {
58          Plugin plugin = new Plugin();
59  
60          plugin.setGroupId( "org.apache.maven.plugins" );
61          plugin.setArtifactId( artifactId );
62  
63          for ( String goal : goals )
64          {
65              PluginExecution pluginExecution = new PluginExecution();
66              pluginExecution.setId( "default-" + goal );
67              pluginExecution.addGoal( goal );
68              plugin.addExecution( pluginExecution );
69          }
70  
71          return plugin;
72      }
73  
74  }