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.tools.plugin;
20  
21  import java.io.IOException;
22  import java.util.List;
23  import java.util.Map;
24  import java.util.Objects;
25  import java.util.Set;
26  
27  import org.apache.maven.artifact.Artifact;
28  import org.apache.maven.model.Plugin;
29  import org.apache.maven.plugin.descriptor.DuplicateMojoDescriptorException;
30  import org.apache.maven.plugin.descriptor.MojoDescriptor;
31  import org.apache.maven.plugin.descriptor.PluginDescriptor;
32  import org.apache.maven.plugin.lifecycle.Lifecycle;
33  import org.codehaus.plexus.classworlds.realm.ClassRealm;
34  import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
35  
36  /**
37   * Extensions to {@link PluginDescriptor} not supported by Maven 3.2.5.
38   * This is a wrapper around an existing PluginDescriptor.
39   */
40  public class ExtendedPluginDescriptor extends PluginDescriptor {
41      private final PluginDescriptor delegate;
42      private String requiredJavaVersion;
43  
44      public ExtendedPluginDescriptor(PluginDescriptor delegate) {
45          this.delegate = delegate;
46          // populate the fields feeding the final methods of ComponentSetDescriptor
47          // which can't be overridden by this wrapper
48          this.setIsolatedRealm(delegate.isIsolatedRealm());
49          this.setDependencies(delegate.getDependencies());
50          this.setComponents(delegate.getComponents());
51      }
52  
53      public void setRequiredJavaVersion(String requiredJavaVersion) {
54          this.requiredJavaVersion = requiredJavaVersion;
55      }
56  
57      public String getRequiredJavaVersion() {
58          return requiredJavaVersion;
59      }
60  
61      @Override
62      public boolean equals(Object obj) {
63          if (this == obj) {
64              return true;
65          }
66          if (!super.equals(obj)) {
67              return false;
68          }
69          if (getClass() != obj.getClass()) {
70              return false;
71          }
72          ExtendedPluginDescriptor other = (ExtendedPluginDescriptor) obj;
73          return Objects.equals(delegate, other.delegate)
74                  && Objects.equals(requiredJavaVersion, other.requiredJavaVersion);
75      }
76  
77      @Override
78      public int hashCode() {
79          final int prime = 31;
80          int result = super.hashCode();
81          result = prime * result + Objects.hash(delegate, requiredJavaVersion);
82          return result;
83      }
84  
85      /* -- START delegate methods --*/
86      public List<MojoDescriptor> getMojos() {
87          return delegate.getMojos();
88      }
89  
90      public void addMojo(MojoDescriptor mojoDescriptor) throws DuplicateMojoDescriptorException {
91          delegate.addMojo(mojoDescriptor);
92      }
93  
94      public String getGroupId() {
95          return delegate.getGroupId();
96      }
97  
98      public void setGroupId(String groupId) {
99          delegate.setGroupId(groupId);
100     }
101 
102     public String getArtifactId() {
103         return delegate.getArtifactId();
104     }
105 
106     public void setArtifactId(String artifactId) {
107         delegate.setArtifactId(artifactId);
108     }
109 
110     public String getPluginLookupKey() {
111         return delegate.getPluginLookupKey();
112     }
113 
114     public String getId() {
115         return delegate.getId();
116     }
117 
118     public String getGoalPrefix() {
119         return delegate.getGoalPrefix();
120     }
121 
122     public void setGoalPrefix(String goalPrefix) {
123         delegate.setGoalPrefix(goalPrefix);
124     }
125 
126     public void setVersion(String version) {
127         delegate.setVersion(version);
128     }
129 
130     public String getVersion() {
131         return delegate.getVersion();
132     }
133 
134     public void setSource(String source) {
135         delegate.setSource(source);
136     }
137 
138     public String getSource() {
139         return delegate.getSource();
140     }
141 
142     public boolean isInheritedByDefault() {
143         return delegate.isInheritedByDefault();
144     }
145 
146     public void setInheritedByDefault(boolean inheritedByDefault) {
147         delegate.setInheritedByDefault(inheritedByDefault);
148     }
149 
150     public List<Artifact> getArtifacts() {
151         return delegate.getArtifacts();
152     }
153 
154     public void setArtifacts(List<Artifact> artifacts) {
155         delegate.setArtifacts(artifacts);
156     }
157 
158     public Map<String, Artifact> getArtifactMap() {
159         return delegate.getArtifactMap();
160     }
161 
162     public MojoDescriptor getMojo(String goal) {
163         return delegate.getMojo(goal);
164     }
165 
166     public void setClassRealm(ClassRealm classRealm) {
167         delegate.setClassRealm(classRealm);
168     }
169 
170     public ClassRealm getClassRealm() {
171         return delegate.getClassRealm();
172     }
173 
174     public void setIntroducedDependencyArtifacts(Set<Artifact> introducedDependencyArtifacts) {
175         delegate.setIntroducedDependencyArtifacts(introducedDependencyArtifacts);
176     }
177 
178     public Set<Artifact> getIntroducedDependencyArtifacts() {
179         return delegate.getIntroducedDependencyArtifacts();
180     }
181 
182     public void setName(String name) {
183         delegate.setName(name);
184     }
185 
186     public String getName() {
187         return delegate.getName();
188     }
189 
190     public void setDescription(String description) {
191         delegate.setDescription(description);
192     }
193 
194     public String getDescription() {
195         return delegate.getDescription();
196     }
197 
198     public void setRequiredMavenVersion(String requiredMavenVersion) {
199         delegate.setRequiredMavenVersion(requiredMavenVersion);
200     }
201 
202     public String getRequiredMavenVersion() {
203         return delegate.getRequiredMavenVersion();
204     }
205 
206     public void setPlugin(Plugin plugin) {
207         delegate.setPlugin(plugin);
208     }
209 
210     @Override
211     public Plugin getPlugin() {
212         return delegate.getPlugin();
213     }
214 
215     @Override
216     public Artifact getPluginArtifact() {
217         return delegate.getPluginArtifact();
218     }
219 
220     @Override
221     public void setPluginArtifact(Artifact pluginArtifact) {
222         delegate.setPluginArtifact(pluginArtifact);
223     }
224 
225     @Override
226     public Lifecycle getLifecycleMapping(String lifecycleId) throws IOException, XmlPullParserException {
227         return delegate.getLifecycleMapping(lifecycleId);
228     }
229 
230     public PluginDescriptor clone() {
231         return delegate.clone();
232     }
233 }