微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何为 Java 9+ 自定义 Javadoc 输出

如何解决如何为 Java 9+ 自定义 Javadoc 输出

我想修改 Javadoc 输出,为此我创建了一个自定义 Doclet,它重用认的 Doclet,并将 DocletEnvironment 包装在包含我的自定义过滤逻辑的代理类中。

注意:使用了 java 11 javadoc API

我的 Doclet 类:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
    <dict>
        <key>childItems</key>
        <array>
            <dict>
                <key>childItems</key>
                <array/>
                <key>choiceDescription</key>
                <string>Standalone App</string>
                <key>choiceIdentifier</key>
                <string>installer_choice_1</string>
                <key>choiceIsEnabled</key>
                <true/>
                <key>choiceIsSelected</key>
                <integer>1</integer>
                <key>choiceIsVisible</key>
                <true/>
                <key>choiceSizeInKilobytes</key>
                <integer>457609</integer>
                <key>choiceTitle</key>
                <string>Orpheus</string>
                <key>pathsOfActivePackagesInChoice</key>
                <array>
                    <string>file://localhost/Users/username/path/myinstaller.pkg#mystandalone.pkg</string>
                </array>
            </dict>
            <dict>
                <key>childItems</key>
                <array/>
                <key>choiceDescription</key>
                <string>Pluto AU plugin</string>
                <key>choiceIdentifier</key>
                <string>installer_choice_2</string>
                <key>choiceIsEnabled</key>
                <true/>
                <key>choiceIsSelected</key>
                <integer>1</integer>
                <key>choiceIsVisible</key>
                <true/>
                <key>choiceSizeInKilobytes</key>
                <integer>8831</integer>
                <key>choiceTitle</key>
                <string>AU</string>
                <key>pathsOfActivePackagesInChoice</key>
                <array>
                    <string>file://localhost/Users/username/path/myinstaller.pkg#AU.pkg</string>
                </array>
            </dict>
            <dict>
                <key>childItems</key>
                <array/>
                <key>choiceDescription</key>
                <string>Pluto VST3 plugin</string>
                <key>choiceIdentifier</key>
                <string>installer_choice_3</string>
                <key>choiceIsEnabled</key>
                <true/>
                <key>choiceIsSelected</key>
                <integer>1</integer>
                <key>choiceIsVisible</key>
                <true/>
                <key>choiceSizeInKilobytes</key>
                <integer>9002</integer>
                <key>choiceTitle</key>
                <string>VST3</string>
                <key>pathsOfActivePackagesInChoice</key>
                <array>
                    <string>file://localhost/Users/username/path/myinstaller.pkg#VST3.pkg</string>
                </array>
            </dict>
        </array>
        <key>choiceIdentifier</key>
        <string>__ROOT_CHOICE_IDENT_disTRIBUTION_TITLE</string>
        <key>choiceIsEnabled</key>
        <true/>
        <key>choiceIsSelected</key>
        <integer>1</integer>
        <key>choiceIsVisible</key>
        <true/>
        <key>choiceSizeInKilobytes</key>
        <integer>0</integer>
        <key>choiceTitle</key>
        <string>myapp</string>
        <key>pathsOfActivePackagesInChoice</key>
        <array/>
    </dict>
</array>
</plist>

我的 DocletEnvironment 代理类:

public class MyDoclet implements Doclet {
    private final HtmlDoclet htmlDoclet;

    public MyDoclet() {
        htmlDoclet = new HtmlDoclet(this);
    }

    @Override
    public boolean run(DocletEnvironment docEnv) {
        var proxy = new DocletEnvironmentProxy(docEnv);
        return htmlDoclet.run(proxy);
    }

//other code...
}

但是当我尝试运行它时,我得到: java.lang.classCastException:类 mypackage.DocletEnvironmentProxy 不能转换为类 jdk.javadoc.internal.tool。 DocEnvImpl(mypackage.DocletEnvironmentProxy 位于加载器 java.net.urlclassloader @3dfc5fb8 的未命名模块中;jdk.javadoc.internal.tool.DocEnvImpl 位于加载器“app”的模块 jdk.javadoc 中)

我发现了与它相关的 bug 和有趣的 comment,上面写着“这不是一种公认​​的执行自定义的方式”

我花了很多时间寻找自定义方法的“正确”描述,但没有找到与之相关的任何内容。仅来自 Oracle 的一些关于基本 Doclet API 用法的指南。

也许有人知道我在哪里可以找到“正确”的方法或者已经解决了 Doclet 自定义问题?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。