2929import processing .app .Platform ;
3030import processing .app .Sketch ;
3131import processing .app .SketchCode ;
32+ import processing .app .Preferences ;
3233import processing .app .tools .Tool ;
3334import processing .app .ui .Editor ;
3435import java .io .File ;
3940import java .io .FileWriter ;
4041import 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