001 package org.apache.maven.tools.plugin.javadoc; 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 022 import java.util.Map; 023 024 import org.apache.maven.tools.plugin.extractor.java.JavaMojoAnnotation; 025 026 import com.sun.tools.doclets.Taglet; 027 028 /** 029 * The <tt>@required</tt> tag is used to specify that this parameter is required for the Mojo 030 * and has no parameter. 031 * <br/> 032 * The following is a sample declaration: 033 * <pre> 034 * public class MyMojo extends AbstractMojo 035 * { 036 * /** 037 *  * Dummy parameter. 038 *  * 039 *  * @required 040 *  * ... 041 *  */ 042 * private Object parameterName; 043 * } 044 * </pre> 045 * To use it, calling the <code>Javadoc</code> tool with the following: 046 * <pre> 047 * javadoc ... -taglet 'org.apache.maven.tools.plugin.javadoc.MojoRequiredFieldTaglet' 048 * </pre> 049 * <b>Note</b>: This taglet is similar to call the <code>Javadoc</code> tool with the following: 050 * <pre> 051 * javadoc ... -tag 'required:f:Is required.' 052 * </pre> 053 * 054 * @see <a href="package-summary.html#package_description">package-summary.html</a> 055 * 056 * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a> 057 * @version $Id: MojoRequiredFieldTaglet.java 1133707 2011-06-09 08:28:59Z stephenc $ 058 */ 059 public class MojoRequiredFieldTaglet 060 extends AbstractMojoFieldTaglet 061 { 062 /** The Javadoc annotation */ 063 private static final String NAME = JavaMojoAnnotation.REQUIRED; 064 065 /** The Javadoc text which will be added to the generated page. */ 066 protected static final String HEADER = "Is required."; 067 068 /** 069 * @return By default, return the string defined in {@linkplain #HEADER}. 070 * @see org.apache.maven.tools.plugin.javadoc.AbstractMojoTaglet#getHeader() 071 * @see #HEADER 072 */ 073 public String getHeader() 074 { 075 return HEADER; 076 } 077 078 /** 079 * @return <code>null</code> since <code>@required</code> has no value. 080 * @see org.apache.maven.tools.plugin.javadoc.AbstractMojoTaglet#getAllowedValue() 081 */ 082 public String getAllowedValue() 083 { 084 return null; 085 } 086 087 /** 088 * @return <code>null</code> since <code>@required</code> has no parameter. 089 * @see org.apache.maven.tools.plugin.javadoc.AbstractMojoTaglet#getAllowedParameterNames() 090 */ 091 public String[] getAllowedParameterNames() 092 { 093 return null; 094 } 095 096 /** 097 * @return By default, return the name of this taglet. 098 * @see com.sun.tools.doclets.Taglet#getName() 099 * @see MojoRequiredFieldTaglet#NAME 100 */ 101 public String getName() 102 { 103 return NAME; 104 } 105 106 /** 107 * Register this Taglet. 108 * 109 * @param tagletMap the map to register this tag to. 110 */ 111 public static void register( Map<String, Taglet> tagletMap ) 112 { 113 MojoRequiredFieldTaglet tag = new MojoRequiredFieldTaglet(); 114 Taglet t = tagletMap.get( tag.getName() ); 115 if ( t != null ) 116 { 117 tagletMap.remove( tag.getName() ); 118 } 119 tagletMap.put( tag.getName(), tag ); 120 } 121 }