View Javadoc
1   package org.apache.maven.plugins.plugin.descriptor_old;
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.net.URI;
23  
24  import org.apache.maven.plugin.descriptor.MojoDescriptor;
25  import org.apache.maven.plugin.descriptor.Parameter;
26  import org.apache.maven.plugin.descriptor.PluginDescriptor;
27  import org.apache.maven.plugin.descriptor.PluginDescriptorBuilder;
28  import org.apache.maven.plugin.plugin.report_old.PluginReport;
29  import org.apache.maven.rtinfo.RuntimeInformation;
30  import org.apache.maven.tools.plugin.EnhancedParameterWrapper;
31  import org.codehaus.plexus.configuration.PlexusConfiguration;
32  import org.codehaus.plexus.configuration.PlexusConfigurationException;
33  
34  /**
35   * Reads enhanced plugin.xml files as generated by
36   * {@link org.apache.maven.tools.plugin.generator.PluginDescriptorFilesGenerator} and
37   * used by {@link PluginReport}.
38   * Populates the slightly extended {@link Parameter} object {@link EnhancedParameterWrapper}.
39   */
40  @Deprecated
41  public class EnhancedPluginDescriptorBuilder extends PluginDescriptorBuilder
42  {
43      private final boolean requireAddingMissingParameterSinceField;
44      
45      public EnhancedPluginDescriptorBuilder( RuntimeInformation rtInfo )
46      {
47          this( rtInfo.isMavenVersion( "[,3.3.9]" ) );
48      }
49  
50      EnhancedPluginDescriptorBuilder( boolean requireAddingMissingParameterSinceField )
51      {
52          this.requireAddingMissingParameterSinceField = requireAddingMissingParameterSinceField;
53      }
54  
55      @Override
56      public MojoDescriptor buildComponentDescriptor( PlexusConfiguration c, PluginDescriptor pluginDescriptor )
57          throws PlexusConfigurationException
58      {
59          MojoDescriptor mojoDescriptor = super.buildComponentDescriptor( c, pluginDescriptor );
60          
61          // ----------------------------------------------------------------------
62          // Parameters
63          // ----------------------------------------------------------------------
64  
65          PlexusConfiguration[] parameterConfigurations = c.getChild( "parameters" ).getChildren( "parameter" );
66  
67          for ( PlexusConfiguration d : parameterConfigurations )
68          {
69              String parameterName = d.getChild( "name" ).getValue();
70              // don't call getParameterMap() to not populate 
71              Parameter pd = mojoDescriptor.getParameterMap().get( parameterName );
72              if ( requireAddingMissingParameterSinceField )
73              {
74                  addMissingParameterSinceField( pd, d );
75              }
76              PlexusConfiguration configTypeJavadocUrl = d.getChild( "typeJavadocUrl", false );
77              if ( configTypeJavadocUrl != null )
78              {
79                  String parameterTypeJavadocUrl = configTypeJavadocUrl.getValue();
80                  EnhancedParameterWrapper enhancedParameter = new EnhancedParameterWrapper( pd );
81                  enhancedParameter.setTypeJavadocUrl( URI.create( parameterTypeJavadocUrl ) );
82                  mojoDescriptor.getParameters().set( mojoDescriptor.getParameters().indexOf( pd ), enhancedParameter );
83                  mojoDescriptor.getParameterMap().put( parameterName, enhancedParameter );
84              }
85          }
86          return mojoDescriptor;
87      }
88  
89      /**
90       * Reads the plugin descriptor and adds the fix for <a href="https://issues.apache.org/jira/browse/MNG-6109">
91       * MNG-6109</a> when using Maven-3.3.9 and before.
92       * Method can be removed once Maven 3.5.0 is the prerequisite for this plugin.
93       * @throws PlexusConfigurationException 
94       * 
95       * @since 3.5.1
96       * @see <a href="https://issues.apache.org/jira/browse/MNG-6109">MNG-6109</a>
97       * @see <a href="https://issues.apache.org/jira/browse/MPLUGIN-319">MPLUGIN-319</a>
98       */
99       void addMissingParameterSinceField( Parameter pd, PlexusConfiguration d ) throws PlexusConfigurationException
100      {
101          String parameterSince = d.getChild( "since" ).getValue();
102          pd.setSince( parameterSince );
103      }
104 }