Skip to content

Commit 7fa5b09

Browse files
committed
Refactored code with Groovy additions
1 parent 7ab9f2c commit 7fa5b09

File tree

1 file changed

+26
-34
lines changed

1 file changed

+26
-34
lines changed

buildSrc/src/main/groovy/JavaDocUtils.groovy

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,23 @@ class JavaDocUtils {
3030
createModulesPage(name, version, outputDir)
3131
}
3232

33+
private static def aggregateJavaDocRec(File current, File output, String... ignoreDirs) {
34+
if (!current.isDirectory()) return
35+
36+
def files = current.listFiles()
37+
if (files == null) return
38+
39+
files.findAll { f -> f.isDirectory() }
40+
.findAll { f -> !IGNORE_DIRS.any { d -> d == f.getName() } }
41+
.findAll { f -> !ignoreDirs.any { d -> d == f.getName() } }
42+
.each { f -> {
43+
if (f.getName() == DOCS_DIR) {
44+
def dest = getDestinationFromModule(output, f)
45+
copyDirectory(f, new File(output, dest))
46+
} else aggregateJavaDocRec(f, output)
47+
} }
48+
}
49+
3350
private static def createModulesPage(String name, String version, File file) {
3451
if (!file.isDirectory()) return
3552
def files = file.listFiles()
@@ -42,12 +59,11 @@ class JavaDocUtils {
4259
}
4360

4461
private static def parseResource(File parentFile, String resource, String name, String version, File[] files) {
45-
JavaDocUtils.class.getResourceAsStream("/${resource}").withReader { reader ->
62+
getResource("/${resource}").withReader { reader ->
4663
new File(parentFile, resource).withWriter { writer ->
4764
String line
4865
while ((line = reader.readLine()) != null) {
49-
line = line
50-
.replace("%module_name%", name)
66+
line = line.replace("%module_name%", name)
5167
.replace("%module_version%", version)
5268
if (line.contains(MODULE_PLACEHOLDER))
5369
line = parseModulesPlaceholder(line, files)
@@ -60,38 +76,15 @@ class JavaDocUtils {
6076

6177
private static def parseModulesPlaceholder(String line, File[] files) {
6278
String output = ""
63-
for (f in files)
64-
JavaDocUtils.class.getResourceAsStream("/${MODULE_FORMAT_FILE}").withReader { r -> {
65-
String l
66-
while ((l = r.readLine()) != null)
67-
output += l.replace("%submodule_name%", f.getName())
68-
.replace("%submodule_path%", "${f.getName()}${File.separator}index.html")
69-
}}
79+
files.collect { it.getName() } .each { n -> getResource("/${MODULE_FORMAT_FILE}").withReader { r ->
80+
String l
81+
while ((l = r.readLine()) != null)
82+
output += l.replace("%submodule_name%", n)
83+
.replace("%submodule_path%", "${n}${File.separator}index.html")
84+
} }
7085
return line.replace(MODULE_PLACEHOLDER, output)
7186
}
7287

73-
private static def aggregateJavaDocRec(File current, File output, String... ignoreDirs) {
74-
if (!current.isDirectory()) return
75-
76-
def files = current.listFiles()
77-
if (files == null) return
78-
79-
main_loop:
80-
for (file in files) {
81-
def fileName = file.getName()
82-
for (dir in IGNORE_DIRS)
83-
if (fileName == dir) continue main_loop
84-
for (dir in ignoreDirs)
85-
if (fileName == dir) continue main_loop
86-
87-
if (file.isDirectory())
88-
if (file.getName() == DOCS_DIR) {
89-
def dest = getDestinationFromModule(output, file)
90-
copyDirectory(file, new File(output, dest))
91-
} else aggregateJavaDocRec(file, output)
92-
}
93-
}
94-
9588
/**
9689
* Copies the given file.
9790
*
@@ -103,8 +96,7 @@ class JavaDocUtils {
10396
def files = src.listFiles()
10497
dst.mkdirs()
10598
if (files != null)
106-
for (file in files)
107-
copyDirectory(new File(src, file.getName()), new File(dst, file.getName()))
99+
files.collect { it.getName() } .each { copyDirectory(new File(src, it), new File(dst, it)) }
108100
} else Files.copy(src.toPath(), dst.toPath(), StandardCopyOption.REPLACE_EXISTING)
109101
}
110102

0 commit comments

Comments
 (0)