Skip to content

Commit 0caae10

Browse files
Catch IO exception getRuntimeJars
To avoid code duplication
1 parent ec02054 commit 0caae10

File tree

1 file changed

+18
-21
lines changed

1 file changed

+18
-21
lines changed

src/main/java/org/sonarqube/gradle/SonarUtils.java

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.sonarqube.gradle;
2121

2222
import java.io.File;
23+
import java.io.IOException;
2324
import java.nio.file.Path;
2425
import java.nio.file.Paths;
2526
import java.util.ArrayList;
@@ -411,33 +412,29 @@ public static String constructPrefixedProjectName(String projectPath) {
411412
* Returns the collection of Java and Java FX runtime jars, if available.
412413
*/
413414
public static Collection<File> getRuntimeJars() {
414-
return Stream.of(getRuntimeJar(), getFxRuntimeJar()).filter(Objects::nonNull).collect(Collectors.toList());
415-
}
416-
417-
@Nullable
418-
private static File getRuntimeJar() {
419415
try {
420-
final File javaBase = new File(System.getProperty("java.home")).getCanonicalFile();
421-
return Stream.of(new File(javaBase, "lib/rt.jar"), new File(javaBase, "jre/lib/rt.jar"))
422-
.filter(File::exists)
423-
.findFirst()
424-
.orElse(null);
425-
} catch (Exception e) {
416+
return Stream.of(getRuntimeJar(), getFxRuntimeJar()).filter(Objects::nonNull).collect(Collectors.toList());
417+
} catch (IOException e) {
426418
throw new IllegalStateException(e);
427419
}
428420
}
429421

430422
@Nullable
431-
private static File getFxRuntimeJar() {
432-
try {
433-
final File javaBase = new File(System.getProperty("java.home")).getCanonicalFile();
434-
return Stream.of(new File(javaBase, "lib/ext/jfxrt.jar"), new File(javaBase, "jre/lib/ext/jfxrt.jar"))
435-
.filter(File::exists)
436-
.findFirst()
437-
.orElse(null);
438-
} catch (Exception e) {
439-
throw new IllegalStateException(e);
440-
}
423+
private static File getRuntimeJar() throws IOException {
424+
final File javaBase = new File(System.getProperty("java.home")).getCanonicalFile();
425+
return Stream.of(new File(javaBase, "lib/rt.jar"), new File(javaBase, "jre/lib/rt.jar"))
426+
.filter(File::exists)
427+
.findFirst()
428+
.orElse(null);
429+
}
430+
431+
@Nullable
432+
private static File getFxRuntimeJar() throws IOException {
433+
final File javaBase = new File(System.getProperty("java.home")).getCanonicalFile();
434+
return Stream.of(new File(javaBase, "lib/ext/jfxrt.jar"), new File(javaBase, "jre/lib/ext/jfxrt.jar"))
435+
.filter(File::exists)
436+
.findFirst()
437+
.orElse(null);
441438
}
442439

443440
}

0 commit comments

Comments
 (0)