29
29
import java .util .*;
30
30
31
31
public final class AggregateSnippets {
32
- public static void main (String [] args ) throws Throwable {
32
+
33
+ public static void main (String ... args ) throws Throwable {
33
34
final var repoRoot = Paths .get ("" ).toAbsolutePath ();
34
35
final var snippetsSrcRoot = repoRoot .resolve ("src/main/java/com/vonage/quickstart" );
35
36
final var aggregator = new AggregateSnippets (snippetsSrcRoot );
36
37
aggregator .computeContents ();
37
38
aggregator .saveContentsToFile (repoRoot .resolve ("SNIPPETS.md" ));
38
- aggregator .saveLineNumbersToCsv (repoRoot .resolve ("snippets_line_numbers.csv" ));
39
+ if (args .length > 0 ) {
40
+ aggregator .saveLineNumbersToCsv (Paths .get (args [0 ]));
41
+ }
39
42
}
40
43
41
44
42
- public record CodeSnippetFile (
45
+ public record CodeSnippetFileInfo (
43
46
Path file ,
44
47
int mainStartIndex , int mainEndIndex ,
45
48
int clientStartIndex , int clientEndIndex
46
49
) { }
47
50
48
51
private StringBuilder sb ;
49
52
private final Path snippetsSrcRoot ;
50
- private Collection <CodeSnippetFile > snippetFiles ;
53
+ private Collection <CodeSnippetFileInfo > snippetFiles ;
51
54
52
55
public AggregateSnippets (Path snippetsSrcRoot ) {
53
56
this .snippetsSrcRoot = Objects .requireNonNull (snippetsSrcRoot );
@@ -59,7 +62,7 @@ private void checkComputed() {
59
62
}
60
63
}
61
64
62
- public Collection <CodeSnippetFile > getLineNumbers () {
65
+ public Collection <CodeSnippetFileInfo > getLineNumbers () {
63
66
checkComputed ();
64
67
return snippetFiles ;
65
68
}
@@ -77,13 +80,13 @@ public void saveLineNumbersToCsv(Path destPath) throws IOException {
77
80
checkComputed ();
78
81
try (var writer = Files .newBufferedWriter (destPath , StandardOpenOption .CREATE )) {
79
82
writer .write ("File,MainStart,MainEnd,ClientStart,ClientEnd\n " );
80
- for (var file : snippetFiles ) {
83
+ for (var metadata : snippetFiles ) {
81
84
writer .write (
82
- file .file .getFileName () + "," +
83
- file .mainStartIndex + "," +
84
- file .mainEndIndex + "," +
85
- file .clientStartIndex + "," +
86
- file .clientEndIndex + "\n "
85
+ metadata .file .getFileName () + "," +
86
+ metadata .mainStartIndex + "," +
87
+ metadata .mainEndIndex + "," +
88
+ metadata .clientStartIndex + "," +
89
+ metadata .clientEndIndex + "\n "
87
90
);
88
91
}
89
92
}
@@ -163,7 +166,7 @@ else if (level > 2 && path.getName().endsWith(".java")) {
163
166
sb .append ("\n ```java\n " ).append (nugget ).append ("\n ```\n " );
164
167
165
168
boolean standalone = clientInitEndIndex < 12 ;
166
- snippetFiles .add (new CodeSnippetFile (path .toPath (),
169
+ snippetFiles .add (new CodeSnippetFileInfo (path .toPath (),
167
170
lineNumberFromIndex (fileContent , startIndex ) + 1 ,
168
171
lineNumberFromIndex (fileContent , endIndex ),
169
172
standalone ? -1 : lineNumberFromIndex (fileContent , clientInitStartIndex ) + 1 ,
0 commit comments