176 lines
4.2 KiB
Java
176 lines
4.2 KiB
Java
/*
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
* under the terms of the GNU Lesser General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or (at your
|
|
* option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
* more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along
|
|
* with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
package com.inteligr8.activiti.doclet;
|
|
|
|
import java.io.IOException;
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.HashSet;
|
|
import java.util.List;
|
|
import java.util.Locale;
|
|
import java.util.Set;
|
|
|
|
import javax.lang.model.SourceVersion;
|
|
import javax.lang.model.element.Element;
|
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import freemarker.template.TemplateException;
|
|
import jdk.javadoc.doclet.Doclet;
|
|
import jdk.javadoc.doclet.Doclet.Option.Kind;
|
|
import jdk.javadoc.doclet.DocletEnvironment;
|
|
import jdk.javadoc.doclet.Reporter;
|
|
|
|
/**
|
|
* This class is the entrypoint for Javadoc to load this Doclet.
|
|
*
|
|
* This is the entrypoint supported by JDK 9+.
|
|
*
|
|
* @author brian@inteligr8.com
|
|
*/
|
|
public class ActivitiDoclet implements Doclet {
|
|
|
|
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
|
|
private String title;
|
|
private String apiName;
|
|
|
|
@Override
|
|
public String getName() {
|
|
return "activiti";
|
|
}
|
|
|
|
@Override
|
|
public Set<? extends Option> getSupportedOptions() {
|
|
return new HashSet<>(Arrays.asList(
|
|
new ValueOption("--title", "Title for documentation", Kind.STANDARD) {
|
|
@Override
|
|
public boolean process(String name, List<String> valueAndClasses) {
|
|
title = valueAndClasses.get(0);
|
|
return true;
|
|
}
|
|
|
|
public String getParameters() {
|
|
return "'API Documentation'";
|
|
}
|
|
},
|
|
new ValueOption("--apiName", "Name of the API", Kind.STANDARD) {
|
|
@Override
|
|
public boolean process(String name, List<String> valueAndClasses) {
|
|
apiName = valueAndClasses.get(0);
|
|
return true;
|
|
}
|
|
|
|
public String getParameters() {
|
|
return "'My Project'";
|
|
}
|
|
}
|
|
));
|
|
}
|
|
|
|
@Override
|
|
public SourceVersion getSupportedSourceVersion() {
|
|
return SourceVersion.latest();
|
|
}
|
|
|
|
@Override
|
|
public void init(Locale locale, Reporter reporter) {
|
|
this.logger.trace("init()");
|
|
}
|
|
|
|
@Override
|
|
public boolean run(DocletEnvironment docenv) {
|
|
this.logger.trace("run()");
|
|
|
|
ActivitiDocFilter docfilter = new ActivitiDocFilter(docenv);
|
|
|
|
for (Element element : docenv.getSpecifiedElements())
|
|
docfilter.filter(element);
|
|
|
|
List<ActivitiApiBeanDoc> beandocs = docfilter.build();
|
|
|
|
try {
|
|
MarkdownWriter mdwriter = new MarkdownWriter(docenv);
|
|
if (this.title != null)
|
|
mdwriter.setTitle(this.title);
|
|
if (this.apiName != null)
|
|
mdwriter.setApiName(this.apiName);
|
|
mdwriter.write(beandocs);
|
|
return true;
|
|
} catch (TemplateException te) {
|
|
this.logger.error("A templating issue occurred", te);
|
|
return false;
|
|
} catch (IOException ie) {
|
|
this.logger.error("An I/O issue occurred", ie);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private abstract class NamedOption implements Option {
|
|
|
|
private final List<String> names;
|
|
private final String description;
|
|
|
|
public NamedOption(String name, String description, String... additionalNames) {
|
|
this.names = new ArrayList<>(additionalNames.length+1);
|
|
this.names.add(name);
|
|
for (String n : additionalNames)
|
|
this.names.add(n);
|
|
this.description = description;
|
|
}
|
|
|
|
@Override
|
|
public String getDescription() {
|
|
return this.description;
|
|
}
|
|
|
|
@Override
|
|
public List<String> getNames() {
|
|
return this.names;
|
|
}
|
|
|
|
}
|
|
|
|
private abstract class ValueOption extends NamedOption {
|
|
|
|
private final Kind kind;
|
|
|
|
public ValueOption(String name, String description, Kind kind, String... additionalNames) {
|
|
super(name, description, additionalNames);
|
|
this.kind = kind;
|
|
}
|
|
|
|
@Override
|
|
public int getArgumentCount() {
|
|
return 1;
|
|
}
|
|
|
|
@Override
|
|
public Kind getKind() {
|
|
return this.kind;
|
|
}
|
|
|
|
@Override
|
|
public String getParameters() {
|
|
return "<value>";
|
|
}
|
|
|
|
}
|
|
|
|
}
|