View Javadoc
1   package org.apache.maven.tools.plugin.javadoc;
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.Map;
23  
24  import org.apache.maven.tools.plugin.extractor.javadoc.JavadocMojoAnnotation;
25  
26  import com.sun.tools.doclets.Taglet;
27  
28  /**
29   * The <tt>@required</tt> tag is used to specify that this parameter is required for the Mojo
30   * and has no parameter.
31   * <br/>
32   * The following is a sample declaration:
33   * <pre>
34   * public class MyMojo extends AbstractMojo
35   * {
36   *   &#x2f;&#x2a;&#x2a;
37   *   &#x20;&#x2a; Dummy parameter.
38   *   &#x20;&#x2a;
39   *   &#x20;&#x2a; &#64;required
40   *   &#x20;&#x2a; ...
41   *   &#x20;&#x2a;&#x2f;
42   *   private Object parameterName;
43   * }
44   * </pre>
45   * To use it, calling the <code>Javadoc</code> tool with the following:
46   * <pre>
47   * javadoc ... -taglet 'org.apache.maven.tools.plugin.javadoc.MojoRequiredFieldTaglet'
48   * </pre>
49   * <b>Note</b>: This taglet is similar to call the <code>Javadoc</code> tool with the following:
50   * <pre>
51   * javadoc ... -tag 'required:f:Is required.'
52   * </pre>
53   *
54   * @see <a href="package-summary.html#package_description">package-summary.html</a>
55   *
56   * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
57   * @version $Id: MojoRequiredFieldTaglet.html 1024032 2018-01-19 18:16:30Z hboutemy $
58   */
59  public class MojoRequiredFieldTaglet
60      extends AbstractMojoFieldTaglet
61  {
62      /** The Javadoc annotation */
63      private static final String NAME = JavadocMojoAnnotation.REQUIRED;
64  
65      /** The Javadoc text which will be added to the generated page. */
66      protected static final String HEADER = "Is required.";
67  
68      /**
69       * @return By default, return the string defined in {@linkplain #HEADER}.
70       * @see org.apache.maven.tools.plugin.javadoc.AbstractMojoTaglet#getHeader()
71       * @see #HEADER
72       */
73      public String getHeader()
74      {
75          return HEADER;
76      }
77  
78      /**
79       * @return <code>null</code> since <code>@required</code> has no value.
80       * @see org.apache.maven.tools.plugin.javadoc.AbstractMojoTaglet#getAllowedValue()
81       */
82      public String getAllowedValue()
83      {
84          return null;
85      }
86  
87      /**
88       * @return <code>null</code> since <code>@required</code> has no parameter.
89       * @see org.apache.maven.tools.plugin.javadoc.AbstractMojoTaglet#getAllowedParameterNames()
90       */
91      public String[] getAllowedParameterNames()
92      {
93          return null;
94      }
95  
96      /**
97       * @return By default, return the name of this taglet.
98       * @see com.sun.tools.doclets.Taglet#getName()
99       * @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 }