Skip to content

Commit

Permalink
Merge pull request #35955 from ia3andy/fix-java-version-check
Browse files Browse the repository at this point in the history
Fix project Java version check and instructions
  • Loading branch information
ia3andy authored Sep 18, 2023
2 parents 6eb14c9 + fdc5b29 commit 5691380
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.quarkus.devtools.commands.data.QuarkusCommandOutcome;
import io.quarkus.devtools.messagewriter.MessageWriter;
import io.quarkus.devtools.project.BuildTool;
import io.quarkus.devtools.project.JavaVersion;
import io.quarkus.devtools.project.QuarkusProject;
import io.quarkus.devtools.project.QuarkusProjectHelper;
import io.quarkus.devtools.project.state.ProjectState;
Expand All @@ -44,7 +45,16 @@ public class UpdateProjectCommandHandler implements QuarkusCommandHandler {

@Override
public QuarkusCommandOutcome execute(QuarkusCommandInvocation invocation) throws QuarkusCommandException {
invocation.log().info("Detected project Java version: %s", invocation.getQuarkusProject().getJavaVersion());
final JavaVersion projectJavaVersion = invocation.getQuarkusProject().getJavaVersion();
invocation.log().info("Detected project Java version: %s", projectJavaVersion);
if (projectJavaVersion.isEmpty()) {
String instruction = invocation.getQuarkusProject().getBuildTool().isAnyGradle() ? "java>targetCompatibility"
: "maven.compiler.release property";
invocation.log().error(String.format("Project Java version not detected, set %s to fix the error.", instruction));
return QuarkusCommandOutcome.failure();
} else {
invocation.log().info("Detected project Java version: %s", projectJavaVersion);
}
final ApplicationModel appModel = invocation.getValue(UpdateProject.APP_MODEL);
final ExtensionCatalog targetCatalog = invocation.getValue(UpdateProject.TARGET_CATALOG);
final String targetPlatformVersion = invocation.getValue(UpdateProject.TARGET_PLATFORM_VERSION);
Expand Down Expand Up @@ -80,7 +90,8 @@ public QuarkusCommandOutcome execute(QuarkusCommandInvocation invocation) throws
final OptionalInt minJavaVersion = extensionsUpdateInfo.getMinJavaVersion();
final Optional<Integer> updateJavaVersion;
if (minJavaVersion.isPresent()
&& minJavaVersion.getAsInt() > invocation.getQuarkusProject().getJavaVersion().getAsInt()) {
&& projectJavaVersion.isPresent()
&& minJavaVersion.getAsInt() > projectJavaVersion.getAsInt()) {
updateJavaVersion = Optional.of(minJavaVersion.getAsInt());
} else {
updateJavaVersion = Optional.empty();
Expand Down Expand Up @@ -184,7 +195,7 @@ private static void logUpdates(QuarkusProject project, ProjectState currentState
return;
}

if (extensionsUpdateInfo.getMinJavaVersion().isPresent()) {
if (extensionsUpdateInfo.getMinJavaVersion().isPresent() && project.getJavaVersion().isPresent()) {
final Integer extensionsMinJavaVersion = extensionsUpdateInfo.getMinJavaVersion().getAsInt();
if (extensionsMinJavaVersion > project.getJavaVersion().getAsInt()) {
log.warn("We detected that some of the updated extensions require an update of the Java version to: %s",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ private BuildTool(String gitIgnoreEntries, String buildDirectory, String[] build
this.buildFiles = buildFiles;
}

public boolean isAnyGradle() {
return GRADLE.equals(this) || GRADLE_KOTLIN_DSL.equals(this);
}

/**
* @return {@code \n}-separated lines to add to a {@code .gitignore} file
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,18 @@ public boolean isEmpty() {
return version == null;
}

public boolean isPresent() {
return version != null;
}

public String getVersion() {
return version;
}

public int getAsInt() {
if (version == null) {
throw new IllegalStateException("Version is not available and can't be parsed as an integer.");
}
return Integer.parseInt(version);
}

Expand All @@ -50,7 +57,7 @@ public int hashCode() {

@Override
public String toString() {
return version;
return isEmpty() ? "NA" : version;
}

// ordering is important here, so let's keep them ordered
Expand Down

0 comments on commit 5691380

Please sign in to comment.