View Javadoc
1   package org.apache.maven.shared.release.transform.jdom2;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.ArrayList;
23  import java.util.Collections;
24  import java.util.List;
25  import java.util.Map;
26  
27  import org.apache.maven.model.Dependency;
28  import org.apache.maven.model.Plugin;
29  import org.apache.maven.model.PluginExecution;
30  import org.apache.maven.shared.release.transform.MavenCoordinate;
31  import org.jdom2.Element;
32  
33  /**
34   * JDOM2 implementation of poms PLUGIN element
35   *
36   * @author Robert Scholte
37   * @since 3.0
38   */
39  public class JDomPlugin extends Plugin implements MavenCoordinate
40  {
41      private Element plugin;
42      private final MavenCoordinate coordinate;
43  
44      /**
45       * <p>Constructor for JDomPlugin.</p>
46       *
47       * @param plugin a {@link org.jdom2.Element} object
48       */
49      public JDomPlugin( Element plugin )
50      {
51          this.plugin = plugin;
52          this.coordinate = new JDomMavenCoordinate( plugin );
53      }
54  
55      @Override
56      public void addDependency( Dependency dependency )
57      {
58          throw new UnsupportedOperationException();
59      }
60  
61      @Override
62      public void addExecution( PluginExecution pluginExecution )
63      {
64          throw new UnsupportedOperationException();
65      }
66  
67      @Override
68      public String getArtifactId()
69      {
70          return coordinate.getArtifactId();
71      }
72  
73      @Override
74      public List<Dependency> getDependencies()
75      {
76          Element dependenciesElm = plugin.getChild( "dependencies", plugin.getNamespace() );
77          if ( dependenciesElm == null )
78          {
79              return Collections.emptyList();
80          }
81          else
82          {
83              List<Element> dependencyElms =
84                  dependenciesElm.getChildren( "dependency", plugin.getNamespace() );
85  
86              List<Dependency> dependencies = new ArrayList<>( dependencyElms.size() );
87  
88              for ( Element dependencyElm : dependencyElms )
89              {
90                  dependencies.add( new JDomDependency( dependencyElm ) );
91              }
92  
93              return dependencies;
94          }
95      }
96  
97      @Override
98      public List<PluginExecution> getExecutions()
99      {
100         throw new UnsupportedOperationException();
101     }
102 
103     @Override
104     public Object getGoals()
105     {
106         throw new UnsupportedOperationException();
107     }
108 
109     @Override
110     public String getGroupId()
111     {
112         return coordinate.getGroupId();
113     }
114 
115     @Override
116     public String getVersion()
117     {
118         return coordinate.getVersion();
119     }
120 
121     @Override
122     public boolean isExtensions()
123     {
124         throw new UnsupportedOperationException();
125     }
126 
127     @Override
128     public void removeDependency( Dependency dependency )
129     {
130         throw new UnsupportedOperationException();
131     }
132 
133     @Override
134     public void removeExecution( PluginExecution pluginExecution )
135     {
136         throw new UnsupportedOperationException();
137     }
138 
139     @Override
140     public void setArtifactId( String artifactId )
141     {
142         throw new UnsupportedOperationException();
143     }
144 
145     @Override
146     public void setDependencies( List<Dependency> dependencies )
147     {
148         throw new UnsupportedOperationException();
149     }
150 
151     @Override
152     public void setExecutions( List<PluginExecution> executions )
153     {
154         throw new UnsupportedOperationException();
155     }
156 
157     @Override
158     public void setExtensions( boolean extensions )
159     {
160         throw new UnsupportedOperationException();
161     }
162 
163     @Override
164     public void setGoals( Object goals )
165     {
166         throw new UnsupportedOperationException();
167     }
168 
169     @Override
170     public void setGroupId( String groupId )
171     {
172         throw new UnsupportedOperationException();
173     }
174 
175     @Override
176     public void setVersion( String version )
177     {
178         coordinate.setVersion( version );
179     }
180 
181     @Override
182     public void flushExecutionMap()
183     {
184         throw new UnsupportedOperationException();
185     }
186 
187     @Override
188     public Map<String, PluginExecution>  getExecutionsAsMap()
189     {
190         throw new UnsupportedOperationException();
191     }
192 
193     @Override
194     public String getName()
195     {
196         return "plugin";
197     }
198 }