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.execution.MavenSession;
19  import org.apache.maven.lifecycle.LifecycleExecutionException;
20  import org.apache.maven.lifecycle.internal.DependencyContext;
21  import org.apache.maven.lifecycle.internal.MojoExecutor;
22  import org.apache.maven.lifecycle.internal.PhaseRecorder;
23  import org.apache.maven.lifecycle.internal.ProjectIndex;
24  import org.apache.maven.plugin.MojoExecution;
25  import org.apache.maven.plugin.descriptor.MojoDescriptor;
26  import org.apache.maven.plugin.descriptor.PluginDescriptor;
27  
28  import java.util.ArrayList;
29  import java.util.Collections;
30  import java.util.List;
31  
32  /**
33   * @author Kristian Rosenvold
34   */
35  public class MojoExecutorStub
36      extends MojoExecutor
37  { // This is being lazy instead of making interface
38  
39      public List<MojoExecution> executions = Collections.synchronizedList( new ArrayList<MojoExecution>() );
40  
41      @Override
42      public void execute( MavenSession session, MojoExecution mojoExecution, ProjectIndex projectIndex,
43                           DependencyContext dependencyContext, PhaseRecorder phaseRecorder )
44          throws LifecycleExecutionException
45      {
46          executions.add( mojoExecution );
47      }
48  
49      @Override
50      public void execute( MavenSession session, List<MojoExecution> mojoExecutions, ProjectIndex projectIndex )
51          throws LifecycleExecutionException
52      {
53          for ( MojoExecution mojoExecution : mojoExecutions )
54          {
55              executions.add( mojoExecution );
56          }
57      }
58  
59  
60      public static MojoDescriptor createMojoDescriptor( String mojoDescription )
61      {
62          final PluginDescriptor descriptor = new PluginDescriptor();
63          descriptor.setArtifactId( mojoDescription );
64          final MojoDescriptor mojoDescriptor = new MojoDescriptor();
65          mojoDescriptor.setDescription( mojoDescription );
66          mojoDescriptor.setPluginDescriptor( descriptor );
67          return mojoDescriptor;
68      }
69  
70  }