2929import java .util .*;
3030
3131public final class AggregateSnippets {
32- public static void main (String [] args ) throws Throwable {
32+
33+ public static void main (String ... args ) throws Throwable {
3334 final var repoRoot = Paths .get ("" ).toAbsolutePath ();
3435 final var snippetsSrcRoot = repoRoot .resolve ("src/main/java/com/vonage/quickstart" );
3536 final var aggregator = new AggregateSnippets (snippetsSrcRoot );
3637 aggregator .computeContents ();
3738 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+ }
3942 }
4043
4144
42- public record CodeSnippetFile (
45+ public record CodeSnippetFileInfo (
4346 Path file ,
4447 int mainStartIndex , int mainEndIndex ,
4548 int clientStartIndex , int clientEndIndex
4649 ) { }
4750
4851 private StringBuilder sb ;
4952 private final Path snippetsSrcRoot ;
50- private Collection <CodeSnippetFile > snippetFiles ;
53+ private Collection <CodeSnippetFileInfo > snippetFiles ;
5154
5255 public AggregateSnippets (Path snippetsSrcRoot ) {
5356 this .snippetsSrcRoot = Objects .requireNonNull (snippetsSrcRoot );
@@ -59,7 +62,7 @@ private void checkComputed() {
5962 }
6063 }
6164
62- public Collection <CodeSnippetFile > getLineNumbers () {
65+ public Collection <CodeSnippetFileInfo > getLineNumbers () {
6366 checkComputed ();
6467 return snippetFiles ;
6568 }
@@ -77,13 +80,13 @@ public void saveLineNumbersToCsv(Path destPath) throws IOException {
7780 checkComputed ();
7881 try (var writer = Files .newBufferedWriter (destPath , StandardOpenOption .CREATE )) {
7982 writer .write ("File,MainStart,MainEnd,ClientStart,ClientEnd\n " );
80- for (var file : snippetFiles ) {
83+ for (var metadata : snippetFiles ) {
8184 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 "
8790 );
8891 }
8992 }
@@ -163,7 +166,7 @@ else if (level > 2 && path.getName().endsWith(".java")) {
163166 sb .append ("\n ```java\n " ).append (nugget ).append ("\n ```\n " );
164167
165168 boolean standalone = clientInitEndIndex < 12 ;
166- snippetFiles .add (new CodeSnippetFile (path .toPath (),
169+ snippetFiles .add (new CodeSnippetFileInfo (path .toPath (),
167170 lineNumberFromIndex (fileContent , startIndex ) + 1 ,
168171 lineNumberFromIndex (fileContent , endIndex ),
169172 standalone ? -1 : lineNumberFromIndex (fileContent , clientInitStartIndex ) + 1 ,
0 commit comments