001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
003 * agreements. See the NOTICE file distributed with this work for additional information regarding
004 * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
005 * "License"); you may not use this file except in compliance with the License. You may obtain a
006 * copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software distributed under the License
011 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
012 * or implied. See the License for the specific language governing permissions and limitations under
013 * the License.
014 */
015
016 package org.apache.maven.lifecycle.internal.stub;
017
018 import org.apache.maven.execution.MavenSession;
019 import org.apache.maven.lifecycle.LifecycleExecutionException;
020 import org.apache.maven.lifecycle.internal.DependencyContext;
021 import org.apache.maven.lifecycle.internal.MojoExecutor;
022 import org.apache.maven.lifecycle.internal.PhaseRecorder;
023 import org.apache.maven.lifecycle.internal.ProjectIndex;
024 import org.apache.maven.plugin.MojoExecution;
025 import org.apache.maven.plugin.descriptor.MojoDescriptor;
026 import org.apache.maven.plugin.descriptor.PluginDescriptor;
027
028 import java.util.ArrayList;
029 import java.util.Collections;
030 import java.util.List;
031
032 /**
033 * @author Kristian Rosenvold
034 */
035 public class MojoExecutorStub
036 extends MojoExecutor
037 { // This is being lazy instead of making interface
038
039 public List<MojoExecution> executions = Collections.synchronizedList( new ArrayList<MojoExecution>() );
040
041 @Override
042 public void execute( MavenSession session, MojoExecution mojoExecution, ProjectIndex projectIndex,
043 DependencyContext dependencyContext, PhaseRecorder phaseRecorder )
044 throws LifecycleExecutionException
045 {
046 executions.add( mojoExecution );
047 }
048
049 @Override
050 public void execute( MavenSession session, List<MojoExecution> mojoExecutions, ProjectIndex projectIndex )
051 throws LifecycleExecutionException
052 {
053 for ( MojoExecution mojoExecution : mojoExecutions )
054 {
055 executions.add( mojoExecution );
056 }
057 }
058
059
060 public static MojoDescriptor createMojoDescriptor( String mojoDescription )
061 {
062 final PluginDescriptor descriptor = new PluginDescriptor();
063 descriptor.setArtifactId( mojoDescription );
064 final MojoDescriptor mojoDescriptor = new MojoDescriptor();
065 mojoDescriptor.setDescription( mojoDescription );
066 mojoDescriptor.setPluginDescriptor( descriptor );
067 return mojoDescriptor;
068 }
069
070 }