Skip to content

Commit

Permalink
Add method to retrieve the list of compatible java versions
Browse files Browse the repository at this point in the history
  • Loading branch information
ia3andy committed Nov 21, 2023
1 parent 808fba7 commit 542e2b9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.TreeSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

public final class JavaVersion {

Expand Down Expand Up @@ -71,6 +72,15 @@ public static int determineBestJavaLtsVersion() {
return determineBestJavaLtsVersion(Runtime.version().feature());
}

public static SortedSet<Integer> getCompatibleLTSVersions(JavaVersion minimumJavaVersion) {
if (minimumJavaVersion.isEmpty()) {
return JAVA_VERSIONS_LTS;
}
return JAVA_VERSIONS_LTS.stream()
.filter(v -> v >= minimumJavaVersion.getAsInt())
.collect(Collectors.toCollection(TreeSet::new));
}

public static int determineBestJavaLtsVersion(int runtimeVersion) {
int bestLtsVersion = DEFAULT_JAVA_VERSION;
for (int ltsVersion : JAVA_VERSIONS_LTS) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package io.quarkus.devtools.project;

import static io.quarkus.devtools.project.JavaVersion.DETECT_JAVA_RUNTIME_VERSION;
import static io.quarkus.devtools.project.JavaVersion.JAVA_VERSIONS_LTS;
import static io.quarkus.devtools.project.JavaVersion.computeJavaVersion;
import static io.quarkus.devtools.project.JavaVersion.determineBestJavaLtsVersion;
import static io.quarkus.devtools.project.JavaVersion.getCompatibleLTSVersions;
import static io.quarkus.devtools.project.SourceType.JAVA;
import static io.quarkus.devtools.project.SourceType.KOTLIN;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;
Expand All @@ -31,6 +34,14 @@ public void givenJavaVersion18ShouldReturn17() {
assertEquals("17", computeJavaVersion(JAVA, "18"));
}

@Test
void shouldProperlyUseMinJavaVersion() {
assertThat(getCompatibleLTSVersions(new JavaVersion("11"))).isEqualTo(JAVA_VERSIONS_LTS);
assertThat(getCompatibleLTSVersions(new JavaVersion("17"))).containsExactly(17, 21);
assertThat(getCompatibleLTSVersions(new JavaVersion("100"))).isEmpty();
assertThat(getCompatibleLTSVersions(JavaVersion.NA)).isEqualTo(JAVA_VERSIONS_LTS);
}

@Test
public void givenAutoDetectShouldReturnAppropriateVersion() {
final String bestJavaLtsVersion = String.valueOf(determineBestJavaLtsVersion(Runtime.version().feature()));
Expand Down

0 comments on commit 542e2b9

Please sign in to comment.