Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use AsciiDoclet to generate asciidoc file from javadoc comments in .java file

I'm newbie with asciidoc. I want to generate HTML Documentation from commented javadoc (in asciidoc format) in java file.

for example java file

/**
 * = Asciidoclet
 *
 * Sample comments that include `source code`.
 *
 * [source,java]
 * --
 * public class Asciidoclet extends Doclet {
 *     private final Asciidoctor asciidoctor = Asciidoctor.Factory.create();
 *
 *     @SuppressWarnings("UnusedDeclaration")
 *     public static boolean start(RootDoc rootDoc) {
 *         new Asciidoclet().render(rootDoc);
 *         return Standard.start(rootDoc);
 *     }
 * }
 * --
 *
 * @author https://github.com/johncarl81[John Ericksen]
 */
public class Asciidoclet extends Doclet {
}

I can generate html file from .ad file but I don't know how to generate .ad(or any asciidoc format file) from javadoc.
So I want to generate .ad (asciidoc file) which i'm using for generate html documentation using asciidoctor-maven-plugin. asciidoctor-maven-plugin will check for .ad files in sourceDirectory and generate html file in outputDirectory.

</plugin>
<plugin>
    <groupId>org.asciidoctor</groupId>
    <artifactId>asciidoctor-maven-plugin</artifactId>
    <version>${asciidoctor.version}</version>
    <executions>
        <execution>
            <id>output-html</id>
            <phase>generate-resources</phase>
            <goals>
                <goal>process-asciidoc</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <sourceDirectory>asciidocs</sourceDirectory>
        <outputDirectory>asciidocs-output</outputDirectory>
        <backend>html</backend>
        <doctype>book</doctype>
    </configuration>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-javadoc-plugin</artifactId>
    <version>2.9</version>
    <configuration>
        <source>1.7</source>
        <doclet>org.asciidoctor.Asciidoclet</doclet>
        <docletArtifact>
            <groupId>org.asciidoctor</groupId>
            <artifactId>asciidoclet</artifactId>
            <version>${asciidoclet.version}</version>
        </docletArtifact>
        <overview>src/main/java/overview.adoc</overview>
        <additionalparam>
            --base-dir ${project.basedir}
            --attribute "name=${project.name}"
            --attribute "version=${project.version}"
            --attribute "title-link=http://example.com[${project.name} ${project.version}]"
        </additionalparam>
    </configuration>
</plugin>

Dependency

<asciidoclet.version>1.5.0</asciidoclet.version>
<asciidoctor.version>1.5.0</asciidoctor.version>

<dependency>
    <groupId>org.asciidoctor</groupId>
    <artifactId>asciidoctorj</artifactId>
    <version>1.5.2</version>
</dependency>

I reffered asciidoclet but i can't get any useful information. also all sample projects are for generating html,pdf,epub,etc.
Thanks...

Update
I changed my maven-javadoc-plugin configuration as following and executed mvn org.apache.maven.plugins:maven-javadoc-plugin:2.9:jar but its generating normal html java documents it should generate .adoc file. Can anyone help me what i'm doing wrong?
Thanks...

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-javadoc-plugin</artifactId>
    <version>2.9</version>
    <executions>
        <execution>
            <id>javadoc-jar</id>
            <phase>package</phase>
            <goals>
                <goal>jar</goal>
            </goals>
            <configuration>
                <includeDependencySources>true</includeDependencySources>
                <dependencySourceExcludes>
                    <dependencySourceExclude>commons-cli:*</dependencySourceExclude>
                </dependencySourceExcludes>
                <source>1.7</source>
                <doclet>org.asciidoctor.Asciidoclet</doclet>
                <docletArtifact>
                    <groupId>org.asciidoctor</groupId>
                    <artifactId>asciidoclet</artifactId>
                    <version>${asciidoclet.version}</version>
                </docletArtifact>
                <overview>src/main/java/overview.adoc</overview>
                <additionalparam>
                    --base-dir ${project.basedir}
                    --attribute "name=${project.name}"
                    --attribute "version=${project.version}"
                    --attribute "title-link=http://example.com[${project.name} ${project.version}]"
                </additionalparam>
            </configuration>
        </execution>
    </executions>
</plugin>

I'm using following dependencies.

  • asciidoctor-maven-plugin
  • asciidoctorj
  • asciidoclet
like image 325
Piyush Avatar asked Nov 01 '22 10:11

Piyush


1 Answers

It seems like your idea on what Asciidoclet is doing is a bit off. It wasn't designed to create Asciidoc, but was designed to be able to write the javadoc in Asciidoc which is then translated into the html output of the javadoc command.

Something you may want to look into is building a custom include module for asciidoctor that will take your asciidoc javadoc source, strip out the java comments and include that into your other outputs you're creating.

like image 152
LightGuard Avatar answered Nov 15 '22 06:11

LightGuard