2828import java .io .UncheckedIOException ;
2929import java .nio .file .Path ;
3030import java .nio .file .Paths ;
31+ import java .util .ArrayList ;
3132import java .util .HashMap ;
33+ import java .util .List ;
3234import java .util .Map ;
3335import java .util .Optional ;
3436
@@ -73,8 +75,8 @@ private String getSpecForPath(Path path) {
7375 ProcessBuilder processBuilder = new ProcessBuilder (path .toString (), "-version" );
7476 processBuilder .redirectErrorStream (false );
7577 Process process = processBuilder .start ();
76- String stdout = readOutput (process .getInputStream ()). trim ( );
77- String stderr = readOutput (process .getErrorStream ()). trim ( );
78+ List < String > stdout = readOutput (process .getInputStream ());
79+ List < String > stderr = readOutput (process .getErrorStream ());
7880 process .waitFor ();
7981
8082 String version = tryParseVersion (stdout );
@@ -100,28 +102,30 @@ private String getSpecForPath(Path path) {
100102 return null ;
101103 }
102104
103- private String tryParseVersion (String version ) {
104- if (version .startsWith ("javac " )) {
105- version = version .substring (6 );
106- if (version .startsWith ("1." )) {
107- version = version .substring (0 , 3 );
108- } else {
109- version = version .substring (0 , 2 );
105+ private String tryParseVersion (List <String > versions ) {
106+ for (String version : versions ) {
107+ if (version .startsWith ("javac " )) {
108+ version = version .substring (6 );
109+ if (version .startsWith ("1." )) {
110+ version = version .substring (0 , 3 );
111+ } else {
112+ version = version .substring (0 , 2 );
113+ }
114+ return version ;
110115 }
111- return version ;
112116 }
113117 return null ;
114118 }
115119
116- private String readOutput (InputStream inputstream ) throws IOException {
120+ private List < String > readOutput (InputStream inputstream ) throws IOException {
117121 BufferedReader br = new BufferedReader (new InputStreamReader (inputstream ));
118122
119- StringBuilder output = new StringBuilder ();
123+ List < String > result = new ArrayList <> ();
120124 String line ;
121125 while ((line = br .readLine ()) != null ) {
122- output . append (line + System . lineSeparator () );
126+ result . add (line );
123127 }
124128
125- return output . toString () ;
129+ return result ;
126130 }
127131}
0 commit comments