From 57dc9e8a528da30fea3735fefbf8fe776bee8e93 Mon Sep 17 00:00:00 2001 From: Martin Lippert Date: Thu, 17 Nov 2022 19:17:01 +0100 Subject: [PATCH] added boot version validations for patch, minor, and major versions as individual markers, but individual preferences not yet done --- .../generations/VersionValidationUtils.java | 48 ++++++++++-- .../generations/VersionValidators.java | 75 ++++++++++++++++++- 2 files changed, 114 insertions(+), 9 deletions(-) diff --git a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/validation/generations/VersionValidationUtils.java b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/validation/generations/VersionValidationUtils.java index e191fa3a0..32181af74 100644 --- a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/validation/generations/VersionValidationUtils.java +++ b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/validation/generations/VersionValidationUtils.java @@ -34,17 +34,55 @@ public class VersionValidationUtils { return currentDate.before(commercialEndDate); } - public static Version getLatestSupportedInSameMajor(ResolvedSpringProject springProject, Version version) - throws Exception { + public static Version getNewerPatchVersion(ResolvedSpringProject springProject, Version version) throws Exception { + Version result = version; + List rls = springProject.getReleases(); for (Release release : rls) { Version rlVersion = release.getVersion(); + if (GENERAL_AVAILABILITY_STATUS.equals(release.getStatus()) - && rlVersion.getMajor() == version.getMajor()) { - return rlVersion; + && rlVersion.getMajor() == result.getMajor() + && rlVersion.getMinor() == result.getMinor() + && rlVersion.getPatch() > result.getPatch()) { + result = rlVersion; } } - return null; + + return result.equals(version) ? null : result; + } + + public static Version getNewerMinorVersion(ResolvedSpringProject springProject, Version version) throws Exception { + Version result = version; + + List rls = springProject.getReleases(); + for (Release release : rls) { + Version rlVersion = release.getVersion(); + + if (GENERAL_AVAILABILITY_STATUS.equals(release.getStatus()) + && rlVersion.getMajor() == result.getMajor() + && rlVersion.getMinor() > result.getMinor()) { + result = rlVersion; + } + } + + return result.equals(version) ? null : result; + } + + public static Version getNewerMajorVersion(ResolvedSpringProject springProject, Version version) throws Exception { + Version result = version; + + List rls = springProject.getReleases(); + for (Release release : rls) { + Version rlVersion = release.getVersion(); + + if (GENERAL_AVAILABILITY_STATUS.equals(release.getStatus()) + && rlVersion.getMajor() > result.getMajor()) { + result = rlVersion; + } + } + + return result.equals(version) ? null : result; } public static Version getLatestSupportedRelease(ResolvedSpringProject springProject) diff --git a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/validation/generations/VersionValidators.java b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/validation/generations/VersionValidators.java index 54d180866..2a4344b6a 100644 --- a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/validation/generations/VersionValidators.java +++ b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/validation/generations/VersionValidators.java @@ -38,7 +38,9 @@ public class VersionValidators { new UnsupportedCommercialValidator(diagnosticSeverityProvider), new UnsupportedOssValidator(diagnosticSeverityProvider), new SupportedCommercialValidator(diagnosticSeverityProvider), - new UpdateLatestMajorVersion(diagnosticSeverityProvider) }; + new UpdateLatestMajorVersion(diagnosticSeverityProvider), + new UpdateLatestMinorVersion(diagnosticSeverityProvider), + new UpdateLatestPatchVersion(diagnosticSeverityProvider) }; } public List getValidators() { @@ -138,16 +140,16 @@ public class VersionValidators { } } - private static class UpdateLatestMajorVersion extends AbstractDiagnosticValidator { + private static class UpdateLatestMinorVersion extends AbstractDiagnosticValidator { - public UpdateLatestMajorVersion(DiagnosticSeverityProvider diagnosticSeverityProvider) { + public UpdateLatestMinorVersion(DiagnosticSeverityProvider diagnosticSeverityProvider) { super(diagnosticSeverityProvider); } @Override public Diagnostic validate(ResolvedSpringProject springProject, IJavaProject javaProject, Generation javaProjectGen, Version javaProjectVersion) throws Exception { - Version latest = VersionValidationUtils.getLatestSupportedInSameMajor(springProject, javaProjectVersion); + Version latest = VersionValidationUtils.getNewerMinorVersion(springProject, javaProjectVersion); if (latest != null) { VersionValidationProblemType problemType = VersionValidationProblemType.UPDATE_LATEST_MAJOR_VERSION; @@ -168,4 +170,69 @@ public class VersionValidators { return null; } } + + private static class UpdateLatestPatchVersion extends AbstractDiagnosticValidator { + + public UpdateLatestPatchVersion(DiagnosticSeverityProvider diagnosticSeverityProvider) { + super(diagnosticSeverityProvider); + } + + @Override + public Diagnostic validate(ResolvedSpringProject springProject, IJavaProject javaProject, + Generation javaProjectGen, Version javaProjectVersion) throws Exception { + Version latest = VersionValidationUtils.getNewerPatchVersion(springProject, javaProjectVersion); + if (latest != null) { + VersionValidationProblemType problemType = VersionValidationProblemType.UPDATE_LATEST_MAJOR_VERSION; + + StringBuffer message = new StringBuffer(); + message.append("Newer patch version of Spring Boot available: "); + message.append(latest.toString()); + + CodeAction ca = new CodeAction(); + ca.setKind(CodeActionKind.QuickFix); + ca.setTitle("Upgrade to Version " + latest.toString()); + String commandId = SpringBootUpgrade.CMD_UPGRADE_SPRING_BOOT; + ca.setCommand(new Command("Upgrade to Version " + latest.toString(), commandId, + ImmutableList.of(javaProject.getLocationUri().toString(), latest.toString()))); + + + return createDiagnostic(ca, problemType, message.toString()); + } + return null; + } + } + + private static class UpdateLatestMajorVersion extends AbstractDiagnosticValidator { + + public UpdateLatestMajorVersion(DiagnosticSeverityProvider diagnosticSeverityProvider) { + super(diagnosticSeverityProvider); + } + + @Override + public Diagnostic validate(ResolvedSpringProject springProject, IJavaProject javaProject, + Generation javaProjectGen, Version javaProjectVersion) throws Exception { + Version latest = VersionValidationUtils.getNewerMajorVersion(springProject, javaProjectVersion); + if (latest != null) { + VersionValidationProblemType problemType = VersionValidationProblemType.UPDATE_LATEST_MAJOR_VERSION; + + StringBuffer message = new StringBuffer(); + message.append("Newer major version of Spring Boot available: "); + message.append(latest.toString()); + + CodeAction ca = new CodeAction(); + ca.setKind(CodeActionKind.QuickFix); + ca.setTitle("Upgrade to Version " + latest.toString()); + String commandId = SpringBootUpgrade.CMD_UPGRADE_SPRING_BOOT; + ca.setCommand(new Command("Upgrade to Version " + latest.toString(), commandId, + ImmutableList.of(javaProject.getLocationUri().toString(), latest.toString()))); + + + return createDiagnostic(ca, problemType, message.toString()); + } + return null; + } + } + + + }