Code Monkey home page Code Monkey logo

xml-doclet's Introduction

A doclet to output javadoc as XML

This library provides a doclet to output the javadoc comments from Java source code to a XML document.

The name, some ideas and most unit tests were shamelessly stolen from the xml-doclet library by Seth Call.

Usage

If you are using maven you can use this library by adding the following report to your pom.xml:

<project>
	...
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-javadoc-plugin</artifactId>
				<executions>
					<execution>
						<id>xml-doclet</id>
					<phase>prepare-package</phase>
						<goals>
							<goal>javadoc</goal>
						</goals>
						<configuration>
							<doclet>com.github.markusbernhardt.xmldoclet.XmlDoclet</doclet>
							<additionalparam>-d ${project.build.directory} -filename ${project.artifactId}-${project.version}-javadoc.xml</additionalparam>
							<useStandardDocletOptions>false</useStandardDocletOptions>
							<docletArtifact>
								<groupId>com.github.markusbernhardt</groupId>
								<artifactId>xml-doclet</artifactId>
								<version>1.0.5</version>
							</docletArtifact>
						</configuration>
					</execution>
				</executions>
			</plugin>
	...
</project>

Use 'mvn package' with maven. If you are not using maven, you can use the jar-with-dependencies, which contains all required libraries.

javadoc -doclet com.github.markusbernhardt.xmldoclet.XmlDoclet \
-docletpath xml-doclet-1.0.5-jar-with-dependencies.jar \
[Javadoc- and XmlDoclet-Options]

A Makefile target to generate xml from both the production and test code:

javadoc:
mkdir -p target/production target/test
CLASSPATH=$$(echo $$(find ~/.m2/repository/ -name '*.jar'|grep -v jdk14 )|sed 's/ /:/g')\
 javadoc -doclet com.github.markusbernhardt.xmldoclet.XmlDoclet -sourcepath src/main/java -d target/production org.rulez.demokracia.PDEngine
CLASSPATH=$$(echo $$(find ~/.m2/repository/ -name '*.jar'|grep -v jdk14 )|sed 's/ /:/g')\
 javadoc -doclet com.github.markusbernhardt.xmldoclet.XmlDoclet -sourcepath src/test/java -d target/test org.rulez.demokracia.PDEngine

If you want more control and feel adventurous you could you use this jar and provide all required libraries from this list on your own.

Options

-d <directory>            Destination directory for output file.
                          Default: .
                          
-docencoding <encoding>   Encoding of the output file.
                          Default: UTF8
                          
-dryrun                   Parse javadoc, but don't write output file.
                          Default: false
                          
-filename <filename>      Name of the output file.
                          Default: javadoc.xml

xml-doclet's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

xml-doclet's Issues

missing dependency

Running your doclet, and it's failing.

contents of dodoclet.sh:

CLASSPATH=../xml-doclet-1.0.6-jar-with-dependencies.jar;$CLASSPATH

javadoc -doclet com.github.markusbernhardt.xmldoclet.XmlDoclet -docletpath ../xml-doclet-1.0.6-jar-with-dependencies.jar -private -sourcepath %1 -d %2 Pengine

result:
2 warnings
~/kyndistuff/javalgt/scripts $./dodoclet.sh ../example/java ../example/docxml
invalid file (bad magic number): Exec format error
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Loading source files for package Pengine...
javadoc: warning - No source files for package Pengine
Constructing Javadoc information...
javadoc: warning - No source files for package Pengine
2 warnings
~/kyndistuff/javalgt/scripts $ls

I've tried this using the jar-with-dependencies from
http://search.maven.org/remotecontent?filepath=com/github/markusbernhardt/xml-doclet/1.0.5/xml-doclet-1.0.5-jar-with-dependencies.jar

(linked to in your readme)
And in a freshly made jar (1.0.6, changed relevant references) made from sources.

I'm no Maven maven, but it looks like the dependencies are OK in the pom file?

Any clue?

Fix README.md

The usage section is wrong and partially some things are missing.
Also show some demo output.

Add filters

Enable filtering of classes, methods, etc.

tools.jar is not available on OSX

The dependency for tools.jar fails on OSX, as Apple's jdk has these classes available instead on classes.jar.

The robot framework maven plugin solves this issue like this:

<profiles>
    <profile>
        <id>default</id>
        <activation>
            <property>
                <name>java.vendor</name>
                <value>!Apple Inc.</value>
            </property>
        </activation>
        <dependencies>
            <dependency>
                <groupId>com.sun</groupId>
                <artifactId>tools</artifactId>
                <version>6</version>
                <scope>system</scope>
                <systemPath>${java.home}/../lib/tools.jar</systemPath>
            </dependency>
        </dependencies>
    </profile>

    <profile>
        <id>OSX</id>
        <activation>
            <property>
                <name>java.vendor</name>
                <value>Apple Inc.</value>
            </property>
        </activation>
        <dependencies>
            <dependency>
                <groupId>com.sun</groupId>
                <artifactId>tools</artifactId>
                <version>6</version>
                <scope>system</scope>
                <systemPath>${java.home}/../Classes/classes.jar</systemPath>
            </dependency>
        </dependencies>
    </profile>
</profiles>

This issue prevents the archetype type annotation library from working on OSX.

Support nested annotations

Problem

Currently the value node for annotations contains a simple string representation of the values. This makes it hard to parse where annotations are nested. It would be nice to handle annotations recursive to be able to extract the desired information more easy.

Example usage of nested annotations

@Entity
@Table(name="VCUST")
@DiscriminatorValue("VCUST")
@PrimaryKeyJoinColumns({
    @PrimaryKeyJoinColumn(name="CUST_ID",referencedColumnName="ID"),
    @PrimaryKeyJoinColumn(name="CUST_TYPE",referencedColumnName="TYPE")
})
public class ValuedCustomer extends Customer { 
    // body
}

Expected Output

In respect to XSD i would not change the value type to mixed content and prefer a more typed way with a new node.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root>
    <package name="com.github.markusbernhardt.xmldoclet.simpledata">
        <class name="ClassJPA" qualified="com.github.markusbernhardt.xmldoclet.simpledata.ClassJPA" scope="public" abstract="false" error="false" exception="false" externalizable="false" included="true" serializable="false">
            <class qualified="java.lang.Object"/>
            <constructor name="ClassJPA" signature="()" qualified="com.github.markusbernhardt.xmldoclet.simpledata.ClassJPA" scope="public" final="false" included="true" native="false" synchronized="false" static="false" varArgs="false"/>
            <annotation name="Entity" qualified="javax.persistence.Entity"/>
            <annotation name="Table" qualified="javax.persistence.Table">
                <argument name="name" primitive="false" array="false">
                    <type qualified="java.lang.String"/>
                    <value>VCUST</value>
                </argument>
            </annotation>
            <annotation name="DiscriminatorValue" qualified="javax.persistence.DiscriminatorValue">
                <argument name="value" primitive="false" array="false">
                    <type qualified="java.lang.String"/>
                    <value>VCUST</value>
                </argument>
            </annotation>
            <annotation name="PrimaryKeyJoinColumns" qualified="javax.persistence.PrimaryKeyJoinColumns">
                <argument name="value" primitive="false" array="true">
                    <type qualified="javax.persistence.PrimaryKeyJoinColumn" dimension="[]"/>
                    <annotation name="PrimaryKeyJoinColumn" qualified="javax.persistence.PrimaryKeyJoinColumn">
                        <argument name="name" primitive="false" array="false">
                            <type qualified="java.lang.String"/>
                            <value>CUST_ID</value>
                        </argument>
                        <argument name="referencedColumnName" primitive="false" array="false">
                            <type qualified="java.lang.String"/>
                            <value>ID</value>
                        </argument>
                    </annotation>
                    <annotation name="PrimaryKeyJoinColumn" qualified="javax.persistence.PrimaryKeyJoinColumn">
                        <argument name="name" primitive="false" array="false">
                            <type qualified="java.lang.String"/>
                            <value>CUST_TYPE</value>
                        </argument>
                        <argument name="referencedColumnName" primitive="false" array="false">
                            <type qualified="java.lang.String"/>
                            <value>TYPE</value>
                        </argument>
                    </annotation>
                </argument>
            </annotation>
        </class>
    </package>
</root>

Doclet is not compatible with Java 11

If I try to run Doclet in JDK 11, it fails:
Exit code: 1 - javadoc: warning - The old Doclet and Taglet APIs in the packages
com.sun.javadoc, com.sun.tools.doclets and their implementations
are planned to be removed in a future JDK release. These
components have been superseded by the new APIs in jdk.javadoc.doclet.
Users are strongly recommended to migrate to the new APIs.
java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
at java.base/java.lang.Class.getDeclaredMethods0(Native Method)
at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3167)
at java.base/java.lang.Class.getMethodsRecursive(Class.java:3308)
at java.base/java.lang.Class.getMethod0(Class.java:3294)
at java.base/java.lang.Class.getMethod(Class.java:2107)
at jdk.javadoc/com.sun.tools.javadoc.main.DocletInvoker.invoke(DocletInvoker.java:309)
at jdk.javadoc/com.sun.tools.javadoc.main.DocletInvoker.optionLength(DocletInvoker.java:236)
at jdk.javadoc/com.sun.tools.javadoc.main.Start.parseAndExecute(Start.java:341)
at jdk.javadoc/com.sun.tools.javadoc.main.Start.begin(Start.java:238)
at jdk.javadoc/com.sun.tools.javadoc.main.Start.begin(Start.java:224)
at jdk.javadoc/com.sun.tools.javadoc.Main.execute(Main.java:174)
at jdk.javadoc/jdk.javadoc.internal.tool.Start.begin(Start.java:419)
at jdk.javadoc/jdk.javadoc.internal.tool.Start.begin(Start.java:344)
at jdk.javadoc/jdk.javadoc.internal.tool.Main.execute(Main.java:63)
at jdk.javadoc/jdk.javadoc.internal.tool.Main.main(Main.java:52)
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.JAXBException
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:471)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 15 more

According to the release-notes, Java 11 removed the Java EE modules:
java.xml.bind (JAXB) - REMOVED
See JEP 320 for more info.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.