Skip to content

Commit

Permalink
put all installed libraries on classpath
Browse files Browse the repository at this point in the history
  • Loading branch information
hkiel committed Jan 5, 2023
1 parent b6fd1fe commit de87c78
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 5 deletions.
6 changes: 3 additions & 3 deletions resources/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

Expand Down
50 changes: 48 additions & 2 deletions src/javadoc/tool/JavaDoc.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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

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

public static List<String> findFiles(Path path, String fileExtension)
throws IOException {

if (!Files.isDirectory(path)) {
throw new IllegalArgumentException("Path must be a directory!");
}

List<String> result;

try (Stream<Path> 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();

Expand All @@ -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<String> 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());
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit de87c78

Please sign in to comment.