From fcae667b070815fae176b06fb2393a940a3a9670 Mon Sep 17 00:00:00 2001 From: Karl Heinz Marbaise Date: Thu, 21 Mar 2024 21:57:20 +0100 Subject: [PATCH] - Removed negative logic (#212) - Removed unused code - Improved code. --- .../maven/plugins/invoker/SelectorUtils.java | 48 +++++-------------- 1 file changed, 11 insertions(+), 37 deletions(-) diff --git a/src/main/java/org/apache/maven/plugins/invoker/SelectorUtils.java b/src/main/java/org/apache/maven/plugins/invoker/SelectorUtils.java index 00b54005..ded4fad3 100644 --- a/src/main/java/org/apache/maven/plugins/invoker/SelectorUtils.java +++ b/src/main/java/org/apache/maven/plugins/invoker/SelectorUtils.java @@ -73,17 +73,10 @@ static boolean isOsFamily(String osSpec) { } static boolean isOsFamily(List families, boolean defaultMatch) { - if (families != null && !families.isEmpty()) { - for (String family : families) { - if (Os.isFamily(family)) { - return true; - } - } - - return false; - } else { + if (families == null || families.isEmpty()) { return defaultMatch; } + return families.stream().anyMatch(Os::isFamily); } /** @@ -139,10 +132,6 @@ static String getMavenVersion(File mavenHome) throws IOException { return null; } - static boolean isMavenVersion(String mavenSpec) { - return isMavenVersion(mavenSpec, getMavenVersion()); - } - static boolean isMavenVersion(String mavenSpec, String actualVersion) { List includes = new ArrayList<>(); List excludes = new ArrayList<>(); @@ -157,15 +146,6 @@ static String getJreVersion() { return System.getProperty("java.version", ""); } - static String getJreVersion(File javaHome) { - // @todo detect actual version - return null; - } - - static boolean isJreVersion(String jreSpec) { - return isJreVersion(jreSpec, getJreVersion()); - } - static boolean isJreVersion(String jreSpec, String actualJreVersion) { List includes = new ArrayList<>(); List excludes = new ArrayList<>(); @@ -176,33 +156,27 @@ static boolean isJreVersion(String jreSpec, String actualJreVersion) { return isJreVersion(jreVersion, includes, true) && !isJreVersion(jreVersion, excludes, false); } - static boolean isJreVersion(List jreVersion, List versionPatterns, boolean defaultMatch) { - if (versionPatterns != null && !versionPatterns.isEmpty()) { - for (String versionPattern : versionPatterns) { - if (isJreVersion(jreVersion, versionPattern)) { - return true; - } - } - - return false; - } else { + static boolean isJreVersion(List jreVersions, List versionPatterns, boolean defaultMatch) { + if (versionPatterns == null || versionPatterns.isEmpty()) { return defaultMatch; } + + return versionPatterns.stream().anyMatch(versionPattern -> isJreVersion(jreVersions, versionPattern)); } - static boolean isJreVersion(List jreVersion, String versionPattern) { + static boolean isJreVersion(List jreVersions, String versionPattern) { List checkVersion = parseVersion(versionPattern); if (versionPattern.endsWith("+")) { // 1.5+ <=> [1.5,) - return compareVersions(jreVersion, checkVersion) >= 0; + return compareVersions(jreVersions, checkVersion) >= 0; } else if (versionPattern.endsWith("-")) { // 1.5- <=> (,1.5) - return compareVersions(jreVersion, checkVersion) < 0; + return compareVersions(jreVersions, checkVersion) < 0; } else { // 1.5 <=> [1.5,1.6) - return checkVersion.size() <= jreVersion.size() - && checkVersion.equals(jreVersion.subList(0, checkVersion.size())); + return checkVersion.size() <= jreVersions.size() + && checkVersion.equals(jreVersions.subList(0, checkVersion.size())); } }