001    package org.apache.maven.project;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one
005     * or more contributor license agreements.  See the NOTICE file
006     * distributed with this work for additional information
007     * regarding copyright ownership.  The ASF licenses this file
008     * to you under the Apache License, Version 2.0 (the
009     * "License"); you may not use this file except in compliance
010     * with the License.  You may obtain a copy of the License at
011     *
012     *   http://www.apache.org/licenses/LICENSE-2.0
013     *
014     * Unless required by applicable law or agreed to in writing,
015     * software distributed under the License is distributed on an
016     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017     * KIND, either express or implied.  See the License for the
018     * specific language governing permissions and limitations
019     * under the License.
020     */
021    
022    import java.util.Collections;
023    import java.util.LinkedHashSet;
024    import java.util.List;
025    import java.util.Set;
026    
027    import org.apache.maven.execution.MavenSession;
028    import org.apache.maven.lifecycle.DefaultLifecycles;
029    import org.apache.maven.lifecycle.LifecycleExecutor;
030    import org.apache.maven.lifecycle.MavenExecutionPlan;
031    import org.apache.maven.model.Plugin;
032    import org.apache.maven.model.PluginExecution;
033    import org.apache.maven.plugin.MojoExecution;
034    
035    /**
036     * A stub implementation that assumes an empty lifecycle to bypass interaction with the plugin manager and to avoid
037     * plugin artifact resolution from repositories.
038     * 
039     * @author Benjamin Bentmann
040     */
041    public class EmptyLifecycleExecutor
042        implements LifecycleExecutor
043    {
044    
045        public MavenExecutionPlan calculateExecutionPlan( MavenSession session, String... tasks )
046        {
047            return new MavenExecutionPlan( null, new DefaultLifecycles() );
048        }
049    
050        public MavenExecutionPlan calculateExecutionPlan( MavenSession session, boolean setup, String... tasks )
051        {
052            return new MavenExecutionPlan( null, new DefaultLifecycles() );
053        }
054    
055        public void execute( MavenSession session )
056        {
057        }
058    
059        public Set<Plugin> getPluginsBoundByDefaultToAllLifecycles( String packaging )
060        {
061            Set<Plugin> plugins;
062    
063            // NOTE: The upper-case packaging name is intentional, that's a special hinting mode used for certain tests
064            if ( "JAR".equals( packaging ) )
065            {
066                plugins = new LinkedHashSet<Plugin>();
067    
068                plugins.add( newPlugin( "maven-compiler-plugin", "compile", "testCompile" ) );
069                plugins.add( newPlugin( "maven-resources-plugin", "resources", "testResources" ) );
070                plugins.add( newPlugin( "maven-surefire-plugin", "test" ) );
071                plugins.add( newPlugin( "maven-jar-plugin", "jar" ) );
072                plugins.add( newPlugin( "maven-install-plugin", "install" ) );
073                plugins.add( newPlugin( "maven-deploy-plugin", "deploy" ) );
074            }
075            else
076            {
077                plugins = Collections.emptySet();
078            }
079    
080            return plugins;
081        }
082    
083        private Plugin newPlugin( String artifactId, String... goals )
084        {
085            Plugin plugin = new Plugin();
086    
087            plugin.setGroupId( "org.apache.maven.plugins" );
088            plugin.setArtifactId( artifactId );
089    
090            for ( String goal : goals )
091            {
092                PluginExecution pluginExecution = new PluginExecution();
093                pluginExecution.setId( "default-" + goal );
094                pluginExecution.addGoal( goal );
095                plugin.addExecution( pluginExecution );
096            }
097    
098            return plugin;
099        }
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    }