Skip to content

Commit 87f6b61

Browse files
committed
Added kotlin support
1 parent e13e70f commit 87f6b61

File tree

2 files changed

+116
-112
lines changed

2 files changed

+116
-112
lines changed

β€Žpom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
<archive>
2727
<manifestEntries>
2828
<Main-Class>generatejavadoc.Main</Main-Class>
29-
<Built-By></Built-By>
30-
<Created-By></Created-By>
31-
<Build-Jdk></Build-Jdk>
29+
<Built-By/>
30+
<Created-By/>
31+
<Build-Jdk/>
3232
</manifestEntries>
3333
</archive>
3434
</configuration>

β€Žsrc/main/java/generatejavadoc/Main.java

Lines changed: 113 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44

55
import java.io.File;
66
import java.io.IOException;
7-
import java.nio.file.DirectoryStream;
8-
import java.nio.file.Files;
9-
import java.nio.file.Path;
10-
import java.nio.file.Paths;
7+
import java.nio.file.*;
118
import java.util.ArrayList;
129
import java.util.List;
1310
import java.util.regex.Pattern;
@@ -44,114 +41,121 @@ public static void main(String[] args) throws IOException {
4441
ind++;
4542
final byte[] readmeMd = Files.readAllBytes(Paths.get(file.getAbsolutePath()));
4643
String readmeMdText = new String(readmeMd, UTF_8);
44+
PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:*.{java,kt}");
4745
try (DirectoryStream<Path> dirStream =
4846
Files.newDirectoryStream(
49-
Paths.get(file.getAbsolutePath().replace("readme.md", "")), "*.java")) {
47+
Paths.get(file.getAbsolutePath().replace("readme.md", "")))) {
5048
for (Path entry : dirStream) {
51-
File javaFile = entry.toFile();
52-
Path path = Paths.get(javaFile.getAbsolutePath());
53-
final byte[] solutionJava = Files.readAllBytes(path);
54-
String solutionJavaText = new String(solutionJava, UTF_8);
55-
int[] index = {0};
56-
String[] fromStr = {
57-
"(\"{{",
58-
"= \"{{",
59-
"\n- [",
60-
" board = [[",
61-
" grid = [[",
62-
" = [[",
63-
"**,",
64-
"**]",
65-
"(**",
66-
"**)",
67-
"[[]",
68-
"<code>",
69-
"</code>",
70-
"<sub>",
71-
"</sub>",
72-
"<sup>",
73-
"</sup>",
74-
"<ins>",
75-
"</ins>",
76-
"<",
77-
">",
78-
"&"
79-
};
80-
String[] fromStr2 = {
81-
"[code]", "[/code]", "[sub]", "[/sub]", "[sup]", "[/sup]", "[ins]",
82-
"[/ins]",
83-
};
84-
String[] toStr = {
85-
"(\"{ {",
86-
"= \"{ {",
87-
"\n- \\[",
88-
" board = [ [",
89-
" grid = [ [",
90-
" = \\[\\[",
91-
"** ,",
92-
"** ]",
93-
"( **",
94-
"** )",
95-
"[ []",
96-
"[code]",
97-
"[/code]",
98-
"[sub]",
99-
"[/sub]",
100-
"[sup]",
101-
"[/sup]",
102-
"[ins]",
103-
"[/ins]",
104-
"&lt;",
105-
"&gt;",
106-
"&amp;"
107-
};
108-
String[] toStr2 = {
109-
"<code>", "</code>", "<sub>", "</sub>", "<sup>", "</sup>", "<ins>",
110-
"</ins>",
111-
};
112-
String readmeMdJavadoc =
113-
"/**\n"
114-
+ StringUtils.replaceEach(
115-
StringUtils.replaceEach(
116-
PATTERN.splitAsStream(readmeMdText)
117-
.map(
118-
line -> {
119-
String firstLine =
120-
line
121-
.replace(
122-
"\\.",
123-
" -")
124-
+ "\\.";
125-
String str =
126-
index[0]++
127-
== 0
128-
? firstLine
129-
: line;
130-
return line
131-
.isEmpty()
132-
? " *"
133-
: " * "
134-
+ str;
135-
})
136-
.collect(
137-
Collectors.joining(
138-
"\n")),
139-
fromStr,
140-
toStr),
141-
fromStr2,
142-
toStr2)
143-
.replace("`**", "` **")
144-
.replace(",**", ", **")
145-
.replace("<ins>**", "<ins> **")
146-
.replace("**</ins>", "** </ins>")
147-
.replace("/*", "{@literal /}*")
148-
.replace("*/", "*{@literal /}")
149-
+ "\n**/";
150-
String publicClass =
151-
solutionJavaText.contains("@SuppressWarnings")
152-
? "@SuppressWarnings"
153-
: "public class ";
154-
Files.write(path, getBytes(solutionJavaText, readmeMdJavadoc, publicClass));
49+
if (matcher.matches(entry.getFileName())) {
50+
File javaFile = entry.toFile();
51+
Path path = Paths.get(javaFile.getAbsolutePath());
52+
final byte[] solutionJava = Files.readAllBytes(path);
53+
String solutionJavaText = new String(solutionJava, UTF_8);
54+
int[] index = {0};
55+
String[] fromStr = {
56+
"(\"{{",
57+
"= \"{{",
58+
"\n- [",
59+
" board = [[",
60+
" grid = [[",
61+
" = [[",
62+
"**,",
63+
"**]",
64+
"(**",
65+
"**)",
66+
"[[]",
67+
"<code>",
68+
"</code>",
69+
"<sub>",
70+
"</sub>",
71+
"<sup>",
72+
"</sup>",
73+
"<ins>",
74+
"</ins>",
75+
"<",
76+
">",
77+
"&"
78+
};
79+
String[] fromStr2 = {
80+
"[code]", "[/code]", "[sub]", "[/sub]", "[sup]", "[/sup]", "[ins]",
81+
"[/ins]",
82+
};
83+
String[] toStr = {
84+
"(\"{ {",
85+
"= \"{ {",
86+
"\n- \\[",
87+
" board = [ [",
88+
" grid = [ [",
89+
" = \\[\\[",
90+
"** ,",
91+
"** ]",
92+
"( **",
93+
"** )",
94+
"[ []",
95+
"[code]",
96+
"[/code]",
97+
"[sub]",
98+
"[/sub]",
99+
"[sup]",
100+
"[/sup]",
101+
"[ins]",
102+
"[/ins]",
103+
"&lt;",
104+
"&gt;",
105+
"&amp;"
106+
};
107+
String[] toStr2 = {
108+
"<code>", "</code>", "<sub>", "</sub>", "<sup>", "</sup>", "<ins>",
109+
"</ins>",
110+
};
111+
String readmeMdJavadoc =
112+
"/**\n"
113+
+ StringUtils.replaceEach(
114+
StringUtils.replaceEach(
115+
PATTERN.splitAsStream(readmeMdText)
116+
.map(
117+
line -> {
118+
String
119+
firstLine =
120+
line
121+
.replace(
122+
"\\.",
123+
" -")
124+
+ "\\.";
125+
String str =
126+
index[
127+
0]++
128+
== 0
129+
? firstLine
130+
: line;
131+
return line
132+
.isEmpty()
133+
? " *"
134+
: " * "
135+
+ str;
136+
})
137+
.collect(
138+
Collectors.joining(
139+
"\n")),
140+
fromStr,
141+
toStr),
142+
fromStr2,
143+
toStr2)
144+
.replace("`**", "` **")
145+
.replace(",**", ", **")
146+
.replace("<ins>**", "<ins> **")
147+
.replace("**</ins>", "** </ins>")
148+
.replace("/*", "{@literal /}*")
149+
.replace("*/", "*{@literal /}")
150+
+ "\n**/";
151+
String publicClass =
152+
solutionJavaText.contains("@SuppressWarnings")
153+
? "@SuppressWarnings"
154+
: solutionJavaText.contains("public class ")
155+
? "public class "
156+
: "class ";
157+
Files.write(path, getBytes(solutionJavaText, readmeMdJavadoc, publicClass));
158+
}
155159
}
156160
}
157161
}

0 commit comments

Comments
 (0)