001package ball.tools.javadoc;
002/*-
003 * ##########################################################################
004 * Utilities
005 * $Id: MavenBootstrapDoclet.java 5285 2020-02-05 04:23:21Z ball $
006 * $HeadURL: svn+ssh://svn.hcf.dev/var/spool/scm/repository.svn/ball-util/trunk/src/main/java/ball/tools/javadoc/MavenBootstrapDoclet.java $
007 * %%
008 * Copyright (C) 2008 - 2020 Allen D. Ball
009 * %%
010 * Licensed under the Apache License, Version 2.0 (the "License");
011 * you may not use this file except in compliance with the License.
012 * You may obtain a copy of the License at
013 *
014 *      http://www.apache.org/licenses/LICENSE-2.0
015 *
016 * Unless required by applicable law or agreed to in writing, software
017 * distributed under the License is distributed on an "AS IS" BASIS,
018 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
019 * See the License for the specific language governing permissions and
020 * limitations under the License.
021 * ##########################################################################
022 */
023import com.sun.javadoc.DocErrorReporter;
024import com.sun.javadoc.LanguageVersion;
025import com.sun.javadoc.RootDoc;
026import com.sun.tools.doclets.Taglet;
027import com.sun.tools.doclets.standard.Standard;
028import java.util.ArrayList;
029import java.util.Arrays;
030import java.util.ServiceLoader;
031import lombok.NoArgsConstructor;
032import lombok.ToString;
033
034/**
035 * WORK IN PROGRESS: {@link Doclet} implementation to intercept calls to the
036 * {@link Standard} {@link Doclet}.
037 *
038 * @author {@link.uri mailto:ball@hcf.dev Allen D. Ball}
039 * @version $Revision: 5285 $
040 */
041@NoArgsConstructor @ToString
042public class MavenBootstrapDoclet extends Standard {
043
044    /**
045     * See {@link Doclet#validOptions(String[][],DocErrorReporter)}.
046     */
047    public static final ThreadLocal<String[][]> OPTIONS = new ThreadLocal<>();
048
049    /**
050     * See {@link Doclet#validOptions(String[][],DocErrorReporter)}.
051     */
052    public static final ThreadLocal<DocErrorReporter> REPORTER =
053        new ThreadLocal<>();
054
055    /**
056     * See {@link Doclet#start(RootDoc)}.
057     */
058    public static final ThreadLocal<RootDoc> ROOT = new ThreadLocal<>();
059
060    /**
061     * See {@link Doclet#validOptions(String[][],DocErrorReporter)}.
062     *
063     * @param   options         The {@code options} and their arguments.
064     * @param   reporter        The {@link DocErrorReporter}.
065     *
066     * @return  {@code true} if the {@code options} are valid; {@code false}
067     *          otherwise.
068     */
069    public static boolean validOptions(String[][] options,
070                                       DocErrorReporter reporter) {
071        Boolean result = null;
072
073        ArrayList<String[]> list = new ArrayList<>(Arrays.asList(options));
074/*
075        for (Taglet taglet :
076                 ServiceLoader.load(Taglet.class,
077                                    MavenBootstrapDoclet.class
078                                    .getClassLoader())) {
079            list.add(new String[] { "-taglet", taglet.getClass().getName() });
080        }
081*/
082        list.add(new String[] {
083                     "-taglet", MavenBootstrapTaglet.class.getName()
084                 });
085
086        options = list.toArray(new String[][] { });
087
088        OPTIONS.set(options);
089        REPORTER.set(reporter);
090
091        result = Standard.validOptions(options, reporter);
092
093        return (result != null) ? result : false;
094    }
095
096    /**
097     * See {@link Doclet#start(RootDoc)}.
098     *
099     * @param   root            The {@link RootDoc}.
100     *
101     * @return  {@code true} on success; {@code false} otherwise.
102     */
103    public static boolean start(RootDoc root) {
104        Boolean result = null;
105
106        ROOT.set(root);
107
108        result = Standard.start(root);
109
110        return (result != null) ? result : false;
111    }
112}