001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.apache.maven.tools.plugin;
020
021import java.io.IOException;
022import java.util.List;
023import java.util.Map;
024import java.util.Objects;
025import java.util.Set;
026
027import org.apache.maven.artifact.Artifact;
028import org.apache.maven.model.Plugin;
029import org.apache.maven.plugin.descriptor.DuplicateMojoDescriptorException;
030import org.apache.maven.plugin.descriptor.MojoDescriptor;
031import org.apache.maven.plugin.descriptor.PluginDescriptor;
032import org.apache.maven.plugin.lifecycle.Lifecycle;
033import org.codehaus.plexus.classworlds.realm.ClassRealm;
034import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
035
036/**
037 * Extensions to {@link PluginDescriptor} not supported by Maven 3.2.5.
038 * This is a wrapper around an existing PluginDescriptor.
039 */
040public class ExtendedPluginDescriptor extends PluginDescriptor {
041    private final PluginDescriptor delegate;
042    private String requiredJavaVersion;
043
044    public ExtendedPluginDescriptor(PluginDescriptor delegate) {
045        this.delegate = delegate;
046        // populate the fields feeding the final methods of ComponentSetDescriptor
047        // which can't be overridden by this wrapper
048        this.setIsolatedRealm(delegate.isIsolatedRealm());
049        this.setDependencies(delegate.getDependencies());
050        this.setComponents(delegate.getComponents());
051    }
052
053    public void setRequiredJavaVersion(String requiredJavaVersion) {
054        this.requiredJavaVersion = requiredJavaVersion;
055    }
056
057    public String getRequiredJavaVersion() {
058        return requiredJavaVersion;
059    }
060
061    @Override
062    public boolean equals(Object obj) {
063        if (this == obj) {
064            return true;
065        }
066        if (!super.equals(obj)) {
067            return false;
068        }
069        if (getClass() != obj.getClass()) {
070            return false;
071        }
072        ExtendedPluginDescriptor other = (ExtendedPluginDescriptor) obj;
073        return Objects.equals(delegate, other.delegate)
074                && Objects.equals(requiredJavaVersion, other.requiredJavaVersion);
075    }
076
077    @Override
078    public int hashCode() {
079        final int prime = 31;
080        int result = super.hashCode();
081        result = prime * result + Objects.hash(delegate, requiredJavaVersion);
082        return result;
083    }
084
085    /* -- START delegate methods --*/
086    public List<MojoDescriptor> getMojos() {
087        return delegate.getMojos();
088    }
089
090    public void addMojo(MojoDescriptor mojoDescriptor) throws DuplicateMojoDescriptorException {
091        delegate.addMojo(mojoDescriptor);
092    }
093
094    public String getGroupId() {
095        return delegate.getGroupId();
096    }
097
098    public void setGroupId(String groupId) {
099        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}