17
17
18
18
package dev .selenium .tools .javadoc ;
19
19
20
- import com .github .bazelbuild .rules_jvm_external .zip .StableZipEntry ;
21
- import org .openqa .selenium .io .TemporaryFilesystem ;
20
+ import static java .nio .charset .StandardCharsets .UTF_8 ;
22
21
23
- import javax .tools .DocumentationTool ;
24
- import javax .tools .JavaFileObject ;
25
- import javax .tools .StandardJavaFileManager ;
26
- import javax .tools .StandardLocation ;
27
- import javax .tools .ToolProvider ;
22
+ import com .github .bazelbuild .rules_jvm_external .zip .StableZipEntry ;
28
23
import java .io .File ;
29
24
import java .io .IOException ;
30
25
import java .io .InputStream ;
46
41
import java .util .zip .ZipEntry ;
47
42
import java .util .zip .ZipInputStream ;
48
43
import java .util .zip .ZipOutputStream ;
49
-
50
- import static java .nio .charset .StandardCharsets .UTF_8 ;
44
+ import javax .tools .DocumentationTool ;
45
+ import javax .tools .JavaFileObject ;
46
+ import javax .tools .StandardJavaFileManager ;
47
+ import javax .tools .StandardLocation ;
48
+ import javax .tools .ToolProvider ;
49
+ import org .openqa .selenium .io .TemporaryFilesystem ;
51
50
52
51
public class JavadocJarMaker {
53
52
@@ -76,11 +75,13 @@ public static void main(String[] args) throws IOException {
76
75
}
77
76
78
77
if (sourceJars .isEmpty ()) {
79
- throw new IllegalArgumentException ("At least one input just must be specified via the --in flag" );
78
+ throw new IllegalArgumentException (
79
+ "At least one input just must be specified via the --in flag" );
80
80
}
81
81
82
82
if (out == null ) {
83
- throw new IllegalArgumentException ("The output jar location must be specified via the --out flag" );
83
+ throw new IllegalArgumentException (
84
+ "The output jar location must be specified via the --out flag" );
84
85
}
85
86
86
87
TemporaryFilesystem tmpFS = TemporaryFilesystem .getDefaultTmpFS ();
@@ -89,22 +90,26 @@ public static void main(String[] args) throws IOException {
89
90
tempDirs .add (dir );
90
91
91
92
DocumentationTool tool = ToolProvider .getSystemDocumentationTool ();
92
- try (StandardJavaFileManager fileManager = tool .getStandardFileManager (null , Locale .getDefault (), UTF_8 )) {
93
+ try (StandardJavaFileManager fileManager =
94
+ tool .getStandardFileManager (null , Locale .getDefault (), UTF_8 )) {
93
95
fileManager .setLocation (DocumentationTool .Location .DOCUMENTATION_OUTPUT , List .of (dir ));
94
- fileManager .setLocation (StandardLocation .CLASS_PATH , classpath .stream ().map (Path ::toFile ).collect (Collectors .toSet ()));
96
+ fileManager .setLocation (
97
+ StandardLocation .CLASS_PATH ,
98
+ classpath .stream ().map (Path ::toFile ).collect (Collectors .toSet ()));
95
99
96
100
Set <JavaFileObject > sources = new HashSet <>();
97
101
Set <String > topLevelPackages = new HashSet <>();
98
102
99
103
File unpackTo = tmpFS .createTempDir ("unpacked-sources" , "" );
100
104
tempDirs .add (unpackTo );
101
105
Set <String > fileNames = new HashSet <>();
102
- readSourceFiles (unpackTo .toPath (), fileManager , sourceJars , sources , topLevelPackages , fileNames );
106
+ readSourceFiles (
107
+ unpackTo .toPath (), fileManager , sourceJars , sources , topLevelPackages , fileNames );
103
108
104
109
// True if we're just exporting a set of modules
105
110
if (sources .isEmpty ()) {
106
111
try (OutputStream os = Files .newOutputStream (out );
107
- ZipOutputStream zos = new ZipOutputStream (os )) {
112
+ ZipOutputStream zos = new ZipOutputStream (os )) {
108
113
// It's enough to just create the thing
109
114
}
110
115
return ;
@@ -113,10 +118,21 @@ public static void main(String[] args) throws IOException {
113
118
List <String > options = new ArrayList <>();
114
119
if (!classpath .isEmpty ()) {
115
120
options .add ("-cp" );
116
- options .add (classpath .stream ().map (String ::valueOf ).collect (Collectors .joining (File .pathSeparator )));
121
+ options .add (
122
+ classpath .stream ()
123
+ .map (String ::valueOf )
124
+ .collect (Collectors .joining (File .pathSeparator )));
117
125
}
118
- options .addAll (List .of ("-html5" , "--frames" , "-notimestamp" , "-use" , "-quiet" , "-Xdoclint:-missing" , "-encoding" , "UTF8" ));
119
-
126
+ options .addAll (
127
+ List .of (
128
+ "-html5" ,
129
+ "--frames" ,
130
+ "-notimestamp" ,
131
+ "-use" ,
132
+ "-quiet" ,
133
+ "-Xdoclint:-missing" ,
134
+ "-encoding" ,
135
+ "UTF8" ));
120
136
121
137
File outputTo = tmpFS .createTempDir ("output-dir" , "" );
122
138
tempDirs .add (outputTo );
@@ -127,7 +143,8 @@ public static void main(String[] args) throws IOException {
127
143
sources .forEach (obj -> options .add (obj .getName ()));
128
144
129
145
Writer writer = new StringWriter ();
130
- DocumentationTool .DocumentationTask task = tool .getTask (writer , fileManager , null , null , options , sources );
146
+ DocumentationTool .DocumentationTask task =
147
+ tool .getTask (writer , fileManager , null , null , options , sources );
131
148
Boolean result = task .call ();
132
149
if (result == null || !result ) {
133
150
System .err .println ("javadoc " + String .join (" " , options ));
@@ -136,46 +153,48 @@ public static void main(String[] args) throws IOException {
136
153
}
137
154
138
155
try (OutputStream os = Files .newOutputStream (out );
139
- ZipOutputStream zos = new ZipOutputStream (os );
140
- Stream <Path > walk = Files .walk (outputToPath )) {
156
+ ZipOutputStream zos = new ZipOutputStream (os );
157
+ Stream <Path > walk = Files .walk (outputToPath )) {
141
158
walk .sorted (Comparator .naturalOrder ())
142
- .forEachOrdered (path -> {
143
- if (path .equals (outputToPath )) {
144
- return ;
145
- }
146
-
147
- try {
148
- if (Files .isDirectory (path )) {
149
- String name = outputToPath .relativize (path ) + "/" ;
150
- ZipEntry entry = new StableZipEntry (name );
151
- zos .putNextEntry (entry );
152
- zos .closeEntry ();
153
- } else {
154
- String name = outputToPath .relativize (path ).toString ();
155
- ZipEntry entry = new StableZipEntry (name );
156
- zos .putNextEntry (entry );
157
- try (InputStream is = Files .newInputStream (path )) {
158
- is .transferTo (zos );
159
- }
160
- zos .closeEntry ();
161
- }
162
- } catch (IOException e ) {
163
- throw new UncheckedIOException (e );
164
- }
165
- });
159
+ .forEachOrdered (
160
+ path -> {
161
+ if (path .equals (outputToPath )) {
162
+ return ;
163
+ }
164
+
165
+ try {
166
+ if (Files .isDirectory (path )) {
167
+ String name = outputToPath .relativize (path ) + "/" ;
168
+ ZipEntry entry = new StableZipEntry (name );
169
+ zos .putNextEntry (entry );
170
+ zos .closeEntry ();
171
+ } else {
172
+ String name = outputToPath .relativize (path ).toString ();
173
+ ZipEntry entry = new StableZipEntry (name );
174
+ zos .putNextEntry (entry );
175
+ try (InputStream is = Files .newInputStream (path )) {
176
+ is .transferTo (zos );
177
+ }
178
+ zos .closeEntry ();
179
+ }
180
+ } catch (IOException e ) {
181
+ throw new UncheckedIOException (e );
182
+ }
183
+ });
166
184
}
167
185
}
168
186
169
187
tempDirs .forEach (tmpFS ::deleteTempDir );
170
188
}
171
189
172
190
private static void readSourceFiles (
173
- Path unpackTo ,
174
- StandardJavaFileManager fileManager ,
175
- Set <Path > sourceJars ,
176
- Set <JavaFileObject > sources ,
177
- Set <String > topLevelPackages ,
178
- Set <String > fileNames ) throws IOException {
191
+ Path unpackTo ,
192
+ StandardJavaFileManager fileManager ,
193
+ Set <Path > sourceJars ,
194
+ Set <JavaFileObject > sources ,
195
+ Set <String > topLevelPackages ,
196
+ Set <String > fileNames )
197
+ throws IOException {
179
198
180
199
for (Path jar : sourceJars ) {
181
200
if (!Files .exists (jar )) {
0 commit comments