View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.lifecycle.internal.stub;
20  
21  import java.util.ArrayList;
22  import java.util.Collections;
23  import java.util.List;
24  import javax.inject.Provider;
25  import org.apache.maven.execution.MavenSession;
26  import org.apache.maven.lifecycle.LifecycleExecutionException;
27  import org.apache.maven.lifecycle.internal.ExecutionEventCatapult;
28  import org.apache.maven.lifecycle.internal.LifecycleDependencyResolver;
29  import org.apache.maven.lifecycle.internal.MojoExecutor;
30  import org.apache.maven.lifecycle.internal.ProjectIndex;
31  import org.apache.maven.model.Plugin;
32  import org.apache.maven.plugin.BuildPluginManager;
33  import org.apache.maven.plugin.MavenPluginManager;
34  import org.apache.maven.plugin.MojoExecution;
35  import org.apache.maven.plugin.MojosExecutionStrategy;
36  import org.apache.maven.plugin.descriptor.MojoDescriptor;
37  import org.apache.maven.plugin.descriptor.PluginDescriptor;
38  import org.apache.maven.project.MavenProject;
39  
40  /**
41   * @author Kristian Rosenvold
42   */
43  public class MojoExecutorStub extends MojoExecutor { // This is being lazy instead of making interface
44  
45      public final List<MojoExecution> executions = Collections.synchronizedList(new ArrayList<>());
46  
47      public MojoExecutorStub() {
48          super(null, null, null, null, null);
49      }
50  
51      public MojoExecutorStub(
52              BuildPluginManager pluginManager,
53              MavenPluginManager mavenPluginManager,
54              LifecycleDependencyResolver lifeCycleDependencyResolver,
55              ExecutionEventCatapult eventCatapult,
56              Provider<MojosExecutionStrategy> mojosExecutionStrategy) {
57          super(pluginManager, mavenPluginManager, lifeCycleDependencyResolver, eventCatapult, mojosExecutionStrategy);
58      }
59  
60      @Override
61      public void execute(MavenSession session, List<MojoExecution> mojoExecutions, ProjectIndex projectIndex)
62              throws LifecycleExecutionException {
63          executions.addAll(mojoExecutions);
64      }
65  
66      @Override
67      public List<MavenProject> executeForkedExecutions(
68              MojoExecution mojoExecution, MavenSession session, ProjectIndex projectIndex)
69              throws LifecycleExecutionException {
70          return null;
71      }
72  
73      public static MojoDescriptor createMojoDescriptor(Plugin plugin) {
74          final PluginDescriptor descriptor = new PluginDescriptor();
75          descriptor.setGroupId(plugin.getGroupId());
76          descriptor.setArtifactId(plugin.getArtifactId());
77          descriptor.setPlugin(plugin);
78          descriptor.setVersion(plugin.getVersion());
79          final MojoDescriptor mojoDescriptor = new MojoDescriptor();
80          mojoDescriptor.setPluginDescriptor(descriptor);
81          return mojoDescriptor;
82      }
83  }