001package org.apache.maven.plugins.plugin.descriptor_old; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import java.net.URI; 023 024import org.apache.maven.plugin.descriptor.MojoDescriptor; 025import org.apache.maven.plugin.descriptor.Parameter; 026import org.apache.maven.plugin.descriptor.PluginDescriptor; 027import org.apache.maven.plugin.descriptor.PluginDescriptorBuilder; 028import org.apache.maven.plugin.plugin.report_old.PluginReport; 029import org.apache.maven.rtinfo.RuntimeInformation; 030import org.apache.maven.tools.plugin.EnhancedParameterWrapper; 031import org.codehaus.plexus.configuration.PlexusConfiguration; 032import org.codehaus.plexus.configuration.PlexusConfigurationException; 033 034/** 035 * Reads enhanced plugin.xml files as generated by 036 * {@link org.apache.maven.tools.plugin.generator.PluginDescriptorFilesGenerator} and 037 * used by {@link PluginReport}. 038 * Populates the slightly extended {@link Parameter} object {@link EnhancedParameterWrapper}. 039 */ 040@Deprecated 041public class EnhancedPluginDescriptorBuilder extends PluginDescriptorBuilder 042{ 043 private final boolean requireAddingMissingParameterSinceField; 044 045 public EnhancedPluginDescriptorBuilder( RuntimeInformation rtInfo ) 046 { 047 this( rtInfo.isMavenVersion( "[,3.3.9]" ) ); 048 } 049 050 EnhancedPluginDescriptorBuilder( boolean requireAddingMissingParameterSinceField ) 051 { 052 this.requireAddingMissingParameterSinceField = requireAddingMissingParameterSinceField; 053 } 054 055 @Override 056 public MojoDescriptor buildComponentDescriptor( PlexusConfiguration c, PluginDescriptor pluginDescriptor ) 057 throws PlexusConfigurationException 058 { 059 MojoDescriptor mojoDescriptor = super.buildComponentDescriptor( c, pluginDescriptor ); 060 061 // ---------------------------------------------------------------------- 062 // Parameters 063 // ---------------------------------------------------------------------- 064 065 PlexusConfiguration[] parameterConfigurations = c.getChild( "parameters" ).getChildren( "parameter" ); 066 067 for ( PlexusConfiguration d : parameterConfigurations ) 068 { 069 String parameterName = d.getChild( "name" ).getValue(); 070 // don't call getParameterMap() to not populate 071 Parameter pd = mojoDescriptor.getParameterMap().get( parameterName ); 072 if ( requireAddingMissingParameterSinceField ) 073 { 074 addMissingParameterSinceField( pd, d ); 075 } 076 PlexusConfiguration configTypeJavadocUrl = d.getChild( "typeJavadocUrl", false ); 077 if ( configTypeJavadocUrl != null ) 078 { 079 String parameterTypeJavadocUrl = configTypeJavadocUrl.getValue(); 080 EnhancedParameterWrapper enhancedParameter = new EnhancedParameterWrapper( pd ); 081 enhancedParameter.setTypeJavadocUrl( URI.create( parameterTypeJavadocUrl ) ); 082 mojoDescriptor.getParameters().set( mojoDescriptor.getParameters().indexOf( pd ), enhancedParameter ); 083 mojoDescriptor.getParameterMap().put( parameterName, enhancedParameter ); 084 } 085 } 086 return mojoDescriptor; 087 } 088 089 /** 090 * Reads the plugin descriptor and adds the fix for <a href="https://issues.apache.org/jira/browse/MNG-6109"> 091 * MNG-6109</a> when using Maven-3.3.9 and before. 092 * Method can be removed once Maven 3.5.0 is the prerequisite for this plugin. 093 * @throws PlexusConfigurationException 094 * 095 * @since 3.5.1 096 * @see <a href="https://issues.apache.org/jira/browse/MNG-6109">MNG-6109</a> 097 * @see <a href="https://issues.apache.org/jira/browse/MPLUGIN-319">MPLUGIN-319</a> 098 */ 099 void addMissingParameterSinceField( Parameter pd, PlexusConfiguration d ) throws PlexusConfigurationException 100 { 101 String parameterSince = d.getChild( "since" ).getValue(); 102 pd.setSince( parameterSince ); 103 } 104}