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