Skip to content

Commit de87c78

Browse files
committed
put all installed libraries on classpath
1 parent b6fd1fe commit de87c78

2 files changed

Lines changed: 51 additions & 5 deletions

File tree

resources/build.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,12 @@ source.repository=https://github.com/hkiel/JavaDoc.git
134134
# This is used to compare different versions of the same Tool, and check if an
135135
# update is available.
136136

137-
tool.version=2
137+
tool.version=3
138138

139139

140140
# The version as the user will see it.
141141

142-
tool.prettyVersion=1.0.1
142+
tool.prettyVersion=1.0.2
143143

144144

145145
# The min and max revision of Processing compatible with your Tool.
@@ -162,7 +162,7 @@ tested.processingVersion=4.1.1
162162

163163
# Additional information for the generated webpage.
164164

165-
tool.copyright=(c) 2022
165+
tool.copyright=(c) 2023
166166
tool.dependencies=?
167167
tool.keywords=javadoc
168168

src/javadoc/tool/JavaDoc.java

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import processing.app.Platform;
3030
import processing.app.Sketch;
3131
import processing.app.SketchCode;
32+
import processing.app.Preferences;
3233
import processing.app.tools.Tool;
3334
import processing.app.ui.Editor;
3435
import java.io.File;
@@ -39,6 +40,14 @@
3940
import java.io.FileWriter;
4041
import java.lang.StringBuilder;
4142

43+
import java.nio.file.Files;
44+
import java.nio.file.Path;
45+
import java.nio.file.Paths;
46+
import java.util.List;
47+
import java.util.stream.Collectors;
48+
import java.util.stream.Stream;
49+
50+
4251
// when creating a tool, the name of the main class which implements Tool must
4352
// be the same as the value defined for project.name in your build.properties
4453

@@ -56,7 +65,32 @@ public void init(Base base) {
5665
this.base = base;
5766
}
5867

68+
public static List<String> findFiles(Path path, String fileExtension)
69+
throws IOException {
70+
71+
if (!Files.isDirectory(path)) {
72+
throw new IllegalArgumentException("Path must be a directory!");
73+
}
74+
75+
List<String> result;
76+
77+
try (Stream<Path> walk = Files.walk(path)) {
78+
result = walk
79+
.filter(p -> !Files.isDirectory(p))
80+
// this is a path, not string,
81+
// convert path to string first
82+
.map(p -> p.toString().toLowerCase())
83+
// this only test if pathname ends with a certain extension
84+
.filter(f -> f.endsWith(fileExtension))
85+
.collect(Collectors.toList());
86+
}
87+
88+
return result;
89+
}
90+
5991
public void run() {
92+
boolean isWindows = System.getProperty("os.name").toLowerCase().startsWith("windows");
93+
6094
// Get the currently active Editor to run the Tool on it
6195
Editor editor = base.getActiveEditor();
6296

@@ -65,6 +99,19 @@ public void run() {
6599
//System.out.println("JavaDoc Tool. ##tool.name## ##tool.prettyVersion## by ##author##");
66100
Sketch sketch = editor.getSketch();
67101
System.out.println("Generating JavaDoc for Sketch \""+sketch.getName()+"\"");
102+
103+
String extraLibs = "";
104+
try {
105+
List<String> files = findFiles(Paths.get(Preferences.getSketchbookPath()+(isWindows?'\\':'/')+"libraries"), "jar");
106+
//files.forEach(x -> System.out.println(x));
107+
if (!files.isEmpty()) {
108+
extraLibs = isWindows?";":":" + String.join(isWindows?";":":", files);
109+
}
110+
111+
} catch (IOException e) {
112+
e.printStackTrace();
113+
}
114+
68115
File folder = sketch.getFolder();
69116
SketchCode codes[] = sketch.getCode();
70117
//System.out.println(folder.getAbsolutePath());
@@ -132,13 +179,12 @@ public void run() {
132179
myWriter.write("\n}\n\n");
133180
myWriter.close();
134181

135-
boolean isWindows = System.getProperty("os.name").toLowerCase().startsWith("windows");
136182
ProcessBuilder builder = new ProcessBuilder(
137183
System.getProperty("java.home") + (isWindows?"\\bin\\javadoc":"/bin/javadoc"),
138184
src.getAbsolutePath(),
139185
"-d", ref.getAbsolutePath(),
140186
"-package", "-quiet",
141-
"-cp", System.getProperty("java.class.path")
187+
"-cp", System.getProperty("java.class.path") + extraLibs
142188
);
143189
Process process = builder.start();
144190

0 commit comments

Comments
 (0)