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.api.plugin.testing.stubs;
20  
21  import java.util.Collections;
22  import java.util.List;
23  import java.util.Map;
24  
25  import org.apache.maven.api.Artifact;
26  import org.apache.maven.api.Dependency;
27  import org.apache.maven.api.Plugin;
28  import org.apache.maven.api.plugin.descriptor.PluginDescriptor;
29  import org.apache.maven.api.plugin.descriptor.lifecycle.Lifecycle;
30  
31  /**
32   * A stub implementation of {@link Plugin} for testing Maven plugins.
33   * Provides a lightweight plugin context that can be configured with models,
34   * descriptors, lifecycles, and dependencies needed for testing.
35   *
36   * <p>This stub is commonly used in conjunction with {@link MojoExecutionStub}
37   * to create a complete testing environment for plugin executions.</p>
38   *
39   * <p>Example usage:</p>
40   * <pre>
41   * PluginStub plugin = new PluginStub();
42   * plugin.setDescriptor(pluginDescriptor);
43   * plugin.setModel(pluginModel);
44   * </pre>
45   *
46   * @see Plugin
47   * @see MojoExecutionStub
48   * @since 4.0.0
49   */
50  public class PluginStub implements Plugin {
51  
52      org.apache.maven.api.model.Plugin model;
53      PluginDescriptor descriptor;
54      List<Lifecycle> lifecycles = Collections.emptyList();
55      ClassLoader classLoader;
56      Artifact artifact;
57      List<Dependency> dependencies = Collections.emptyList();
58      Map<String, Dependency> dependenciesMap = Collections.emptyMap();
59  
60      @Override
61      public org.apache.maven.api.model.Plugin getModel() {
62          return model;
63      }
64  
65      public void setModel(org.apache.maven.api.model.Plugin model) {
66          this.model = model;
67      }
68  
69      @Override
70      public PluginDescriptor getDescriptor() {
71          return descriptor;
72      }
73  
74      public void setDescriptor(PluginDescriptor descriptor) {
75          this.descriptor = descriptor;
76      }
77  
78      @Override
79      public List<Lifecycle> getLifecycles() {
80          return lifecycles;
81      }
82  
83      public void setLifecycles(List<Lifecycle> lifecycles) {
84          this.lifecycles = lifecycles;
85      }
86  
87      @Override
88      public ClassLoader getClassLoader() {
89          return classLoader;
90      }
91  
92      public void setClassLoader(ClassLoader classLoader) {
93          this.classLoader = classLoader;
94      }
95  
96      @Override
97      public Artifact getArtifact() {
98          return artifact;
99      }
100 
101     public void setArtifact(Artifact artifact) {
102         this.artifact = artifact;
103     }
104 
105     @Override
106     public List<Dependency> getDependencies() {
107         return dependencies;
108     }
109 
110     public void setDependencies(List<Dependency> dependencies) {
111         this.dependencies = dependencies;
112     }
113 
114     @Override
115     public Map<String, Dependency> getDependenciesMap() {
116         return dependenciesMap;
117     }
118 
119     public void setDependenciesMap(Map<String, Dependency> dependenciesMap) {
120         this.dependenciesMap = dependenciesMap;
121     }
122 }