Skip to content

Commit

Permalink
- Removed negative logic (#212)
Browse files Browse the repository at this point in the history
- Removed unused code
- Improved code.
  • Loading branch information
khmarbaise authored Mar 21, 2024
1 parent 09a47e0 commit fcae667
Showing 1 changed file with 11 additions and 37 deletions.
48 changes: 11 additions & 37 deletions src/main/java/org/apache/maven/plugins/invoker/SelectorUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,10 @@ static boolean isOsFamily(String osSpec) {
}

static boolean isOsFamily(List<String> 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);
}

/**
Expand Down Expand Up @@ -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<String> includes = new ArrayList<>();
List<String> excludes = new ArrayList<>();
Expand All @@ -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<String> includes = new ArrayList<>();
List<String> excludes = new ArrayList<>();
Expand All @@ -176,33 +156,27 @@ static boolean isJreVersion(String jreSpec, String actualJreVersion) {
return isJreVersion(jreVersion, includes, true) && !isJreVersion(jreVersion, excludes, false);
}

static boolean isJreVersion(List<Integer> jreVersion, List<String> 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<Integer> jreVersions, List<String> versionPatterns, boolean defaultMatch) {
if (versionPatterns == null || versionPatterns.isEmpty()) {
return defaultMatch;
}

return versionPatterns.stream().anyMatch(versionPattern -> isJreVersion(jreVersions, versionPattern));
}

static boolean isJreVersion(List<Integer> jreVersion, String versionPattern) {
static boolean isJreVersion(List<Integer> jreVersions, String versionPattern) {
List<Integer> 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()));
}
}

Expand Down

0 comments on commit fcae667

Please sign in to comment.