简体   繁体   中英

Running DocumentationTool on sources from OpenJDK 11

I am trying to run DocumentationTool on sources from OpenJDK 11.

The output looks like this:

Constructing Javadoc information...
/Users/Borkdude/git/openjdk-jdk11/src/java.base/share/classes/java/lang/IllegalStateException.java:26: error: package exists in another module: java.base
package java.lang;

and this repeats about a 100 times.

The code I have looks like this in Clojure:

(import '[javax.tools ToolProvider])
(let [dt (ToolProvider/getSystemDocumentationTool)
        fm (.getStandardFileManager dt nil nil nil)
        files (.getJavaFileObjectsFromFiles
               fm
               (filter #(str/ends-with? (.getPath %) ".java")
                       (file-seq (io/file "/Users/Borkdude/git/openjdk-jdk11/src/java.base/share/classes/java/lang"))))
        task (.getTask dt nil fm nil nil nil files)]
    (.call task))

How do I get rid of the error:

error: package exists in another module: java.base
package java.lang;

?

You can either compile the entire module, or you need to "patch" the module. Here's an example of each, assuming you unzip src.zip to /tmp .

To compile the entire module:

(import '[javax.tools ToolProvider])
(require '[clojure.string :as str])

(let [dt (ToolProvider/getSystemDocumentationTool)
      fm (.getStandardFileManager dt nil nil nil)
      files (.getJavaFileObjectsFromFiles
             fm
             (filter #(str/ends-with? (.getPath %) ".java")
                     (file-seq (io/file "/tmp/src/java.base/"))))
      task (.getTask dt nil fm nil nil nil files)]
  (.call task))  

To patch the module (ie compile only certain sources):

(let [dt (ToolProvider/getSystemDocumentationTool)
      fm (.getStandardFileManager dt nil nil nil)
      files (.getJavaFileObjectsFromFiles
             fm
             (filter #(str/ends-with? (.getPath %) ".java")
                     (file-seq (io/file "/tmp/src/java.base/java/lang"))))
      opts ["--patch-module" "java.base=/tmp/src"]
      task (.getTask dt nil fm nil nil opts files)]
  (.call task))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM