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.plugins.plugin.descriptor_old; 020 021import java.net.URI; 022 023import org.apache.maven.plugin.descriptor.MojoDescriptor; 024import org.apache.maven.plugin.descriptor.Parameter; 025import org.apache.maven.plugin.descriptor.PluginDescriptor; 026import org.apache.maven.plugin.descriptor.PluginDescriptorBuilder; 027import org.apache.maven.plugin.plugin.report_old.PluginReport; 028import org.apache.maven.rtinfo.RuntimeInformation; 029import org.apache.maven.tools.plugin.EnhancedParameterWrapper; 030import org.codehaus.plexus.configuration.PlexusConfiguration; 031import org.codehaus.plexus.configuration.PlexusConfigurationException; 032 033/** 034 * Reads enhanced plugin.xml files as generated by 035 * {@link org.apache.maven.tools.plugin.generator.PluginDescriptorFilesGenerator} and 036 * used by {@link PluginReport}. 037 * Populates the slightly extended {@link Parameter} object {@link EnhancedParameterWrapper}. 038 */ 039@Deprecated 040public class EnhancedPluginDescriptorBuilder extends PluginDescriptorBuilder { 041 private final boolean requireAddingMissingParameterSinceField; 042 043 public EnhancedPluginDescriptorBuilder(RuntimeInformation rtInfo) { 044 this(rtInfo.isMavenVersion("[,3.3.9]")); 045 } 046 047 EnhancedPluginDescriptorBuilder(boolean requireAddingMissingParameterSinceField) { 048 this.requireAddingMissingParameterSinceField = requireAddingMissingParameterSinceField; 049 } 050 051 @Override 052 public MojoDescriptor buildComponentDescriptor(PlexusConfiguration c, PluginDescriptor pluginDescriptor) 053 throws PlexusConfigurationException { 054 MojoDescriptor mojoDescriptor = super.buildComponentDescriptor(c, pluginDescriptor); 055 056 // ---------------------------------------------------------------------- 057 // Parameters 058 // ---------------------------------------------------------------------- 059 060 PlexusConfiguration[] parameterConfigurations = c.getChild("parameters").getChildren("parameter"); 061 062 for (PlexusConfiguration d : parameterConfigurations) { 063 String parameterName = d.getChild("name").getValue(); 064 // don't call getParameterMap() to not populate 065 Parameter pd = mojoDescriptor.getParameterMap().get(parameterName); 066 if (requireAddingMissingParameterSinceField) { 067 addMissingParameterSinceField(pd, d); 068 } 069 PlexusConfiguration configTypeJavadocUrl = d.getChild("typeJavadocUrl", false); 070 if (configTypeJavadocUrl != null) { 071 String parameterTypeJavadocUrl = configTypeJavadocUrl.getValue(); 072 EnhancedParameterWrapper enhancedParameter = new EnhancedParameterWrapper(pd); 073 enhancedParameter.setTypeJavadocUrl(URI.create(parameterTypeJavadocUrl)); 074 mojoDescriptor 075 .getParameters() 076 .set(mojoDescriptor.getParameters().indexOf(pd), enhancedParameter); 077 mojoDescriptor.getParameterMap().put(parameterName, enhancedParameter); 078 } 079 } 080 return mojoDescriptor; 081 } 082 083 /** 084 * Reads the plugin descriptor and adds the fix for <a href="https://issues.apache.org/jira/browse/MNG-6109"> 085 * MNG-6109</a> when using Maven-3.3.9 and before. 086 * Method can be removed once Maven 3.5.0 is the prerequisite for this plugin. 087 * @throws PlexusConfigurationException 088 * 089 * @since 3.5.1 090 * @see <a href="https://issues.apache.org/jira/browse/MNG-6109">MNG-6109</a> 091 * @see <a href="https://issues.apache.org/jira/browse/MPLUGIN-319">MPLUGIN-319</a> 092 */ 093 void addMissingParameterSinceField(Parameter pd, PlexusConfiguration d) throws PlexusConfigurationException { 094 String parameterSince = d.getChild("since").getValue(); 095 pd.setSince(parameterSince); 096 } 097}