2929import java .util .LinkedHashSet ;
3030import java .util .List ;
3131import java .util .Map ;
32+ import java .util .Objects ;
3233import java .util .Optional ;
3334import java .util .Set ;
3435import java .util .regex .Pattern ;
3536import java .util .stream .Collectors ;
37+ import java .util .stream .Stream ;
3638import java .util .stream .StreamSupport ;
3739import javax .annotation .Nullable ;
3840import org .gradle .api .Project ;
@@ -409,31 +411,17 @@ public static String constructPrefixedProjectName(String projectPath) {
409411 * Returns the collection of Java and Java FX runtime jars, if available.
410412 */
411413 public static Collection <File > getRuntimeJars () {
412- List <File > libraries = new ArrayList <>(2 );
413-
414- File runtimeJar = getRuntimeJar ();
415- if (runtimeJar != null ) {
416- libraries .add (runtimeJar );
417- }
418-
419- File fxRuntimeJar = getFxRuntimeJar ();
420- if (fxRuntimeJar != null ) {
421- libraries .add (fxRuntimeJar );
422- }
423-
424- return libraries ;
414+ return Stream .of (getRuntimeJar (), getFxRuntimeJar ()).filter (Objects ::nonNull ).collect (Collectors .toList ());
425415 }
426416
427417 @ Nullable
428418 private static File getRuntimeJar () {
429419 try {
430420 final File javaBase = new File (System .getProperty ("java.home" )).getCanonicalFile ();
431- File runtimeJar = new File (javaBase , "lib/rt.jar" );
432- if (runtimeJar .exists ()) {
433- return runtimeJar ;
434- }
435- runtimeJar = new File (javaBase , "jre/lib/rt.jar" );
436- return runtimeJar .exists () ? runtimeJar : null ;
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 );
437425 } catch (Exception e ) {
438426 throw new IllegalStateException (e );
439427 }
@@ -443,12 +431,10 @@ private static File getRuntimeJar() {
443431 private static File getFxRuntimeJar () {
444432 try {
445433 final File javaBase = new File (System .getProperty ("java.home" )).getCanonicalFile ();
446- File runtimeJar = new File (javaBase , "lib/ext/jfxrt.jar" );
447- if (runtimeJar .exists ()) {
448- return runtimeJar ;
449- }
450- runtimeJar = new File (javaBase , "jre/lib/ext/jfxrt.jar" );
451- return runtimeJar .exists () ? runtimeJar : null ;
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 );
452438 } catch (Exception e ) {
453439 throw new IllegalStateException (e );
454440 }
0 commit comments