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.shared.release.transform.jdom2;
20  
21  import java.util.ArrayList;
22  import java.util.Collections;
23  import java.util.List;
24  import java.util.Map;
25  
26  import org.apache.maven.model.Dependency;
27  import org.apache.maven.model.Plugin;
28  import org.apache.maven.model.PluginExecution;
29  import org.apache.maven.shared.release.transform.MavenCoordinate;
30  import org.jdom2.Element;
31  
32  /**
33   * JDOM2 implementation of poms PLUGIN element
34   *
35   * @author Robert Scholte
36   * @since 3.0
37   */
38  public class JDomPlugin extends Plugin implements MavenCoordinate {
39      private Element plugin;
40      private final MavenCoordinate coordinate;
41  
42      /**
43       * <p>Constructor for JDomPlugin.</p>
44       *
45       * @param plugin a {@link org.jdom2.Element} object
46       */
47      public JDomPlugin(Element plugin) {
48          this.plugin = plugin;
49          this.coordinate = new JDomMavenCoordinate(plugin);
50      }
51  
52      @Override
53      public void addDependency(Dependency dependency) {
54          throw new UnsupportedOperationException();
55      }
56  
57      @Override
58      public void addExecution(PluginExecution pluginExecution) {
59          throw new UnsupportedOperationException();
60      }
61  
62      @Override
63      public String getArtifactId() {
64          return coordinate.getArtifactId();
65      }
66  
67      @Override
68      public List<Dependency> getDependencies() {
69          Element dependenciesElm = plugin.getChild("dependencies", plugin.getNamespace());
70          if (dependenciesElm == null) {
71              return Collections.emptyList();
72          } else {
73              List<Element> dependencyElms = dependenciesElm.getChildren("dependency", plugin.getNamespace());
74  
75              List<Dependency> dependencies = new ArrayList<>(dependencyElms.size());
76  
77              for (Element dependencyElm : dependencyElms) {
78                  dependencies.add(new JDomDependency(dependencyElm));
79              }
80  
81              return dependencies;
82          }
83      }
84  
85      @Override
86      public List<PluginExecution> getExecutions() {
87          throw new UnsupportedOperationException();
88      }
89  
90      @Override
91      public Object getGoals() {
92          throw new UnsupportedOperationException();
93      }
94  
95      @Override
96      public String getGroupId() {
97          return coordinate.getGroupId();
98      }
99  
100     @Override
101     public String getVersion() {
102         return coordinate.getVersion();
103     }
104 
105     @Override
106     public boolean isExtensions() {
107         throw new UnsupportedOperationException();
108     }
109 
110     @Override
111     public void removeDependency(Dependency dependency) {
112         throw new UnsupportedOperationException();
113     }
114 
115     @Override
116     public void removeExecution(PluginExecution pluginExecution) {
117         throw new UnsupportedOperationException();
118     }
119 
120     @Override
121     public void setArtifactId(String artifactId) {
122         throw new UnsupportedOperationException();
123     }
124 
125     @Override
126     public void setDependencies(List<Dependency> dependencies) {
127         throw new UnsupportedOperationException();
128     }
129 
130     @Override
131     public void setExecutions(List<PluginExecution> executions) {
132         throw new UnsupportedOperationException();
133     }
134 
135     @Override
136     public void setExtensions(boolean extensions) {
137         throw new UnsupportedOperationException();
138     }
139 
140     @Override
141     public void setGoals(Object goals) {
142         throw new UnsupportedOperationException();
143     }
144 
145     @Override
146     public void setGroupId(String groupId) {
147         throw new UnsupportedOperationException();
148     }
149 
150     @Override
151     public void setVersion(String version) {
152         coordinate.setVersion(version);
153     }
154 
155     @Override
156     public void flushExecutionMap() {
157         throw new UnsupportedOperationException();
158     }
159 
160     @Override
161     public Map<String, PluginExecution> getExecutionsAsMap() {
162         throw new UnsupportedOperationException();
163     }
164 
165     @Override
166     public String getName() {
167         return "plugin";
168     }
169 }