diff --git a/resources/build.properties b/resources/build.properties index 6c159f2..e69c7ca 100644 --- a/resources/build.properties +++ b/resources/build.properties @@ -134,12 +134,12 @@ source.repository=https://github.com/hkiel/JavaDoc.git # This is used to compare different versions of the same Tool, and check if an # update is available. -tool.version=2 +tool.version=3 # The version as the user will see it. -tool.prettyVersion=1.0.1 +tool.prettyVersion=1.0.2 # The min and max revision of Processing compatible with your Tool. @@ -162,7 +162,7 @@ tested.processingVersion=4.1.1 # Additional information for the generated webpage. -tool.copyright=(c) 2022 +tool.copyright=(c) 2023 tool.dependencies=? tool.keywords=javadoc diff --git a/src/javadoc/tool/JavaDoc.java b/src/javadoc/tool/JavaDoc.java index d7a5b8f..a66df9b 100644 --- a/src/javadoc/tool/JavaDoc.java +++ b/src/javadoc/tool/JavaDoc.java @@ -29,6 +29,7 @@ import processing.app.Platform; import processing.app.Sketch; import processing.app.SketchCode; +import processing.app.Preferences; import processing.app.tools.Tool; import processing.app.ui.Editor; import java.io.File; @@ -39,6 +40,14 @@ import java.io.FileWriter; import java.lang.StringBuilder; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + + // when creating a tool, the name of the main class which implements Tool must // be the same as the value defined for project.name in your build.properties @@ -56,7 +65,32 @@ public void init(Base base) { this.base = base; } + public static List findFiles(Path path, String fileExtension) + throws IOException { + + if (!Files.isDirectory(path)) { + throw new IllegalArgumentException("Path must be a directory!"); + } + + List result; + + try (Stream walk = Files.walk(path)) { + result = walk + .filter(p -> !Files.isDirectory(p)) + // this is a path, not string, + // convert path to string first + .map(p -> p.toString().toLowerCase()) + // this only test if pathname ends with a certain extension + .filter(f -> f.endsWith(fileExtension)) + .collect(Collectors.toList()); + } + + return result; + } + public void run() { + boolean isWindows = System.getProperty("os.name").toLowerCase().startsWith("windows"); + // Get the currently active Editor to run the Tool on it Editor editor = base.getActiveEditor(); @@ -65,6 +99,19 @@ public void run() { //System.out.println("JavaDoc Tool. ##tool.name## ##tool.prettyVersion## by ##author##"); Sketch sketch = editor.getSketch(); System.out.println("Generating JavaDoc for Sketch \""+sketch.getName()+"\""); + + String extraLibs = ""; + try { + List files = findFiles(Paths.get(Preferences.getSketchbookPath()+(isWindows?'\\':'/')+"libraries"), "jar"); + //files.forEach(x -> System.out.println(x)); + if (!files.isEmpty()) { + extraLibs = isWindows?";":":" + String.join(isWindows?";":":", files); + } + + } catch (IOException e) { + e.printStackTrace(); + } + File folder = sketch.getFolder(); SketchCode codes[] = sketch.getCode(); //System.out.println(folder.getAbsolutePath()); @@ -132,13 +179,12 @@ public void run() { myWriter.write("\n}\n\n"); myWriter.close(); - boolean isWindows = System.getProperty("os.name").toLowerCase().startsWith("windows"); ProcessBuilder builder = new ProcessBuilder( System.getProperty("java.home") + (isWindows?"\\bin\\javadoc":"/bin/javadoc"), src.getAbsolutePath(), "-d", ref.getAbsolutePath(), "-package", "-quiet", - "-cp", System.getProperty("java.class.path") + "-cp", System.getProperty("java.class.path") + extraLibs ); Process process = builder.start();