Skip to content

Commit fcae667

Browse files
authored
- Removed negative logic (#212)
- Removed unused code - Improved code.
1 parent 09a47e0 commit fcae667

File tree

1 file changed

+11
-37
lines changed

1 file changed

+11
-37
lines changed

src/main/java/org/apache/maven/plugins/invoker/SelectorUtils.java

+11-37
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,10 @@ static boolean isOsFamily(String osSpec) {
7373
}
7474

7575
static boolean isOsFamily(List<String> families, boolean defaultMatch) {
76-
if (families != null && !families.isEmpty()) {
77-
for (String family : families) {
78-
if (Os.isFamily(family)) {
79-
return true;
80-
}
81-
}
82-
83-
return false;
84-
} else {
76+
if (families == null || families.isEmpty()) {
8577
return defaultMatch;
8678
}
79+
return families.stream().anyMatch(Os::isFamily);
8780
}
8881

8982
/**
@@ -139,10 +132,6 @@ static String getMavenVersion(File mavenHome) throws IOException {
139132
return null;
140133
}
141134

142-
static boolean isMavenVersion(String mavenSpec) {
143-
return isMavenVersion(mavenSpec, getMavenVersion());
144-
}
145-
146135
static boolean isMavenVersion(String mavenSpec, String actualVersion) {
147136
List<String> includes = new ArrayList<>();
148137
List<String> excludes = new ArrayList<>();
@@ -157,15 +146,6 @@ static String getJreVersion() {
157146
return System.getProperty("java.version", "");
158147
}
159148

160-
static String getJreVersion(File javaHome) {
161-
// @todo detect actual version
162-
return null;
163-
}
164-
165-
static boolean isJreVersion(String jreSpec) {
166-
return isJreVersion(jreSpec, getJreVersion());
167-
}
168-
169149
static boolean isJreVersion(String jreSpec, String actualJreVersion) {
170150
List<String> includes = new ArrayList<>();
171151
List<String> excludes = new ArrayList<>();
@@ -176,33 +156,27 @@ static boolean isJreVersion(String jreSpec, String actualJreVersion) {
176156
return isJreVersion(jreVersion, includes, true) && !isJreVersion(jreVersion, excludes, false);
177157
}
178158

179-
static boolean isJreVersion(List<Integer> jreVersion, List<String> versionPatterns, boolean defaultMatch) {
180-
if (versionPatterns != null && !versionPatterns.isEmpty()) {
181-
for (String versionPattern : versionPatterns) {
182-
if (isJreVersion(jreVersion, versionPattern)) {
183-
return true;
184-
}
185-
}
186-
187-
return false;
188-
} else {
159+
static boolean isJreVersion(List<Integer> jreVersions, List<String> versionPatterns, boolean defaultMatch) {
160+
if (versionPatterns == null || versionPatterns.isEmpty()) {
189161
return defaultMatch;
190162
}
163+
164+
return versionPatterns.stream().anyMatch(versionPattern -> isJreVersion(jreVersions, versionPattern));
191165
}
192166

193-
static boolean isJreVersion(List<Integer> jreVersion, String versionPattern) {
167+
static boolean isJreVersion(List<Integer> jreVersions, String versionPattern) {
194168
List<Integer> checkVersion = parseVersion(versionPattern);
195169

196170
if (versionPattern.endsWith("+")) {
197171
// 1.5+ <=> [1.5,)
198-
return compareVersions(jreVersion, checkVersion) >= 0;
172+
return compareVersions(jreVersions, checkVersion) >= 0;
199173
} else if (versionPattern.endsWith("-")) {
200174
// 1.5- <=> (,1.5)
201-
return compareVersions(jreVersion, checkVersion) < 0;
175+
return compareVersions(jreVersions, checkVersion) < 0;
202176
} else {
203177
// 1.5 <=> [1.5,1.6)
204-
return checkVersion.size() <= jreVersion.size()
205-
&& checkVersion.equals(jreVersion.subList(0, checkVersion.size()));
178+
return checkVersion.size() <= jreVersions.size()
179+
&& checkVersion.equals(jreVersions.subList(0, checkVersion.size()));
206180
}
207181
}
208182

0 commit comments

Comments
 (0)