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