Initial support for reading from preferences
This commit is contained in:
@@ -20,6 +20,7 @@ import org.springframework.ide.vscode.boot.validation.generations.SpringIoProjec
|
||||
import org.springframework.ide.vscode.boot.validation.generations.SpringProjectDiagnostic;
|
||||
import org.springframework.ide.vscode.boot.validation.generations.SpringProjectsClient;
|
||||
import org.springframework.ide.vscode.boot.validation.generations.SpringProjectsProvider;
|
||||
import org.springframework.ide.vscode.boot.validation.generations.VersionValidationPreferences;
|
||||
import org.springframework.ide.vscode.boot.validation.generations.VersionValidators;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.ProjectObserver;
|
||||
@@ -42,11 +43,13 @@ public class BootVersionValidator {
|
||||
|
||||
@Override
|
||||
public void created(IJavaProject project) {
|
||||
|
||||
String url = getSpringProjectsUrl();
|
||||
VersionValidationPreferences preferences = new VersionValidationPreferences();
|
||||
|
||||
String url = getSpringProjectsUrl(preferences);
|
||||
SpringProjectsClient client = new SpringProjectsClient(url);
|
||||
SpringProjectsProvider provider = new SpringIoProjectsProvider(client);
|
||||
VersionValidators validators = new VersionValidators();
|
||||
VersionValidators validators = new VersionValidators(preferences);
|
||||
|
||||
ProjectVersionDiagnosticProvider diagnosticProvider = new ProjectVersionDiagnosticProvider(provider, validators);
|
||||
|
||||
try {
|
||||
@@ -69,10 +72,7 @@ public class BootVersionValidator {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private String getSpringProjectsUrl() {
|
||||
// TODO: Read from preferences
|
||||
return "https://spring.io/api/projects";
|
||||
private String getSpringProjectsUrl(VersionValidationPreferences preferences) {
|
||||
return preferences.getSpringProjectsUrl();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ public class ProjectVersionDiagnosticProvider {
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Non-null list of Diagnostics. Can be empty if no diagnostics are
|
||||
* @return Non-null list of Diagnostics for the given Java project. Can be empty if no diagnostics are
|
||||
* applicable.
|
||||
* @throws If error encountered while getting diagnostics
|
||||
*/
|
||||
@@ -64,19 +64,20 @@ public class ProjectVersionDiagnosticProvider {
|
||||
throw new Exception("Unable to resolve version for project: " + javaProject.getLocationUri().toString());
|
||||
}
|
||||
|
||||
// The generation of the current dependency
|
||||
Generation javaProjectGeneration = getGenerationForJavaProject(javaProject, springProject);
|
||||
|
||||
if (javaProjectGeneration == null) {
|
||||
throw new Exception("Unable to find Spring Generation for project: " + javaProjectVersion.toString());
|
||||
throw new Exception("Unable to find Spring Project Generation for project: " + javaProjectVersion.toString());
|
||||
}
|
||||
|
||||
VersionValidation validation = null;
|
||||
|
||||
for (VersionValidator validator : validators.getValidators()) {
|
||||
validation = validator.getValidation(springProject, javaProjectGeneration, javaProjectVersion);
|
||||
if (validation != null) {
|
||||
break;
|
||||
if (validator.isEnabled()) {
|
||||
validation = validator.getValidation(springProject, javaProjectGeneration, javaProjectVersion);
|
||||
if (validation != null) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2022 VMware, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* VMware, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.boot.validation.generations;
|
||||
|
||||
import org.eclipse.lsp4j.DiagnosticSeverity;
|
||||
|
||||
public class ValidationPreference {
|
||||
|
||||
private final boolean enabled;
|
||||
private final DiagnosticSeverity severity;
|
||||
|
||||
public ValidationPreference(boolean enabled, DiagnosticSeverity severity) {
|
||||
super();
|
||||
this.enabled = enabled;
|
||||
this.severity = severity;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public DiagnosticSeverity getSeverity() {
|
||||
return severity;
|
||||
}
|
||||
}
|
||||
@@ -16,21 +16,15 @@ import org.springframework.ide.vscode.commons.java.Version;
|
||||
public class VersionValidation {
|
||||
|
||||
private final Version versionToUpgrade;
|
||||
private final boolean enabled;
|
||||
private final DiagnosticSeverity severity;
|
||||
private final String message;
|
||||
|
||||
public VersionValidation(Version versionToUpgrade, boolean enabled, DiagnosticSeverity severity, String message) {
|
||||
public VersionValidation(Version versionToUpgrade, DiagnosticSeverity severity, String message) {
|
||||
this.versionToUpgrade = versionToUpgrade;
|
||||
this.enabled = enabled;
|
||||
this.severity = severity;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
public DiagnosticSeverity getSeverity() {
|
||||
return this.severity;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2022 VMware, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* VMware, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.boot.validation.generations;
|
||||
|
||||
import org.eclipse.lsp4j.DiagnosticSeverity;
|
||||
|
||||
// TODO: integrate with actual LS preferences
|
||||
public class VersionValidationPreferences {
|
||||
|
||||
private static final String DEFAULT_SPRING_PROJECT_URL = "https://spring.io/api/projects";
|
||||
|
||||
public ValidationPreference getSupportedPreference() {
|
||||
return new ValidationPreference(true, DiagnosticSeverity.Hint);
|
||||
}
|
||||
|
||||
public ValidationPreference getUnsupportedOssPreference() {
|
||||
return new ValidationPreference(true, DiagnosticSeverity.Warning);
|
||||
}
|
||||
|
||||
public ValidationPreference getUnsupportedCommercialPreference() {
|
||||
return new ValidationPreference(true, DiagnosticSeverity.Warning);
|
||||
}
|
||||
|
||||
public ValidationPreference getUnsupportedPreference() {
|
||||
return new ValidationPreference(true, DiagnosticSeverity.Error);
|
||||
}
|
||||
|
||||
public String getSpringProjectsUrl() {
|
||||
return DEFAULT_SPRING_PROJECT_URL;
|
||||
}
|
||||
}
|
||||
@@ -27,5 +27,7 @@ public interface VersionValidator {
|
||||
*/
|
||||
VersionValidation getValidation(ResolvedSpringProject springProject, Generation generation, Version version)
|
||||
throws Exception;
|
||||
|
||||
boolean isEnabled();
|
||||
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.boot.validation.generations;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.lsp4j.DiagnosticSeverity;
|
||||
@@ -17,24 +18,35 @@ import org.springframework.ide.vscode.boot.validation.generations.json.Generatio
|
||||
import org.springframework.ide.vscode.boot.validation.generations.json.ResolvedSpringProject;
|
||||
import org.springframework.ide.vscode.commons.java.Version;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
public class VersionValidators {
|
||||
|
||||
private final VersionValidator[] validators;
|
||||
|
||||
public VersionValidators(VersionValidationPreferences preferences) {
|
||||
this.validators = new VersionValidator[] {
|
||||
new SupportedValidator(preferences), new UnsupportedCommercialValidator(preferences),
|
||||
new UnsupportedOssValidator(preferences), new UnsupportedValidator(preferences)
|
||||
};
|
||||
}
|
||||
|
||||
public List<VersionValidator> getValidators() {
|
||||
return ImmutableList.of(new SupportedValidator(), new UnsupportedCommercialValidator(),
|
||||
new UnsupportedOssValidator(), new UnsupportedValidator());
|
||||
return Arrays.asList(this.validators);
|
||||
}
|
||||
|
||||
private static class SupportedValidator implements VersionValidator {
|
||||
|
||||
private final VersionValidationPreferences preferences;
|
||||
|
||||
public SupportedValidator(VersionValidationPreferences preferences) {
|
||||
this.preferences = preferences;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VersionValidation getValidation(ResolvedSpringProject springProject, Generation generation,
|
||||
Version version) throws Exception {
|
||||
|
||||
if (VersionValidationUtils.isCommercialValid(generation) && VersionValidationUtils.isOssValid(generation)) {
|
||||
DiagnosticSeverity severity = DiagnosticSeverity.Information;
|
||||
boolean enabled = true;
|
||||
DiagnosticSeverity severity = preferences.getSupportedPreference().getSeverity();
|
||||
|
||||
StringBuffer message = new StringBuffer();
|
||||
|
||||
@@ -43,23 +55,34 @@ public class VersionValidators {
|
||||
message.append('\n');
|
||||
message.append("Commercial supports ends on: ");
|
||||
message.append(generation.getCommercialSupportEndDate());
|
||||
|
||||
Version toUpdate = VersionValidationUtils.getLatestSupportedRelease(springProject, version);
|
||||
return new VersionValidation(toUpdate, enabled, severity, message.toString());
|
||||
return new VersionValidation(toUpdate, severity, message.toString());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return preferences.getSupportedPreference().isEnabled();
|
||||
}
|
||||
}
|
||||
|
||||
private static class UnsupportedValidator implements VersionValidator {
|
||||
|
||||
private final VersionValidationPreferences preferences;
|
||||
|
||||
public UnsupportedValidator(VersionValidationPreferences preferences) {
|
||||
this.preferences = preferences;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VersionValidation getValidation(ResolvedSpringProject springProject, Generation generation,
|
||||
Version version) throws Exception {
|
||||
|
||||
if (!VersionValidationUtils.isCommercialValid(generation)
|
||||
&& !VersionValidationUtils.isOssValid(generation)) {
|
||||
DiagnosticSeverity severity = DiagnosticSeverity.Error;
|
||||
boolean enabled = true;
|
||||
DiagnosticSeverity severity = preferences.getUnsupportedPreference().getSeverity();
|
||||
StringBuffer message = new StringBuffer();
|
||||
|
||||
message.append("Unsupported OSS. Support ended on: ");
|
||||
@@ -69,21 +92,32 @@ public class VersionValidators {
|
||||
message.append(generation.getCommercialSupportEndDate());
|
||||
|
||||
return new VersionValidation(
|
||||
toUpdateForUnsupported(springProject, version), enabled, severity, message.toString());
|
||||
toUpdateForUnsupported(springProject, version), severity, message.toString());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return preferences.getUnsupportedPreference().isEnabled();
|
||||
}
|
||||
}
|
||||
|
||||
private static class UnsupportedOssValidator implements VersionValidator {
|
||||
|
||||
private final VersionValidationPreferences preferences;
|
||||
|
||||
public UnsupportedOssValidator(VersionValidationPreferences preferences) {
|
||||
this.preferences = preferences;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VersionValidation getValidation(ResolvedSpringProject springProject, Generation generation,
|
||||
Version version) throws Exception {
|
||||
if (!VersionValidationUtils.isOssValid(generation)
|
||||
&& VersionValidationUtils.isCommercialValid(generation)) {
|
||||
DiagnosticSeverity severity = DiagnosticSeverity.Warning;
|
||||
boolean enabled = true;
|
||||
|
||||
DiagnosticSeverity severity = preferences.getUnsupportedOssPreference().getSeverity();
|
||||
|
||||
StringBuffer message = new StringBuffer();
|
||||
message.append("Unsupported OSS. Support ended on: ");
|
||||
@@ -91,14 +125,25 @@ public class VersionValidators {
|
||||
message.append('\n');
|
||||
message.append("Commercial supports ends on: ");
|
||||
message.append(generation.getCommercialSupportEndDate());
|
||||
return new VersionValidation(toUpdateForUnsupported(springProject, version), enabled, severity, message.toString());
|
||||
return new VersionValidation(toUpdateForUnsupported(springProject, version), severity, message.toString());
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return preferences.getUnsupportedOssPreference().isEnabled();
|
||||
}
|
||||
}
|
||||
|
||||
private static class UnsupportedCommercialValidator implements VersionValidator {
|
||||
|
||||
private final VersionValidationPreferences preferences;
|
||||
|
||||
public UnsupportedCommercialValidator(VersionValidationPreferences preferences) {
|
||||
this.preferences = preferences;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VersionValidation getValidation(ResolvedSpringProject springProject, Generation generation,
|
||||
@@ -106,8 +151,7 @@ public class VersionValidators {
|
||||
if (!VersionValidationUtils.isCommercialValid(generation)
|
||||
&& VersionValidationUtils.isOssValid(generation)) {
|
||||
|
||||
DiagnosticSeverity severity = DiagnosticSeverity.Warning;
|
||||
boolean enabled = true;
|
||||
DiagnosticSeverity severity = preferences.getUnsupportedCommercialPreference().getSeverity();
|
||||
|
||||
StringBuffer message = new StringBuffer();
|
||||
message.append("OSS support ends on: ");
|
||||
@@ -115,10 +159,16 @@ public class VersionValidators {
|
||||
message.append('\n');
|
||||
message.append("Unsupported Commercial. Support ended on: ");
|
||||
message.append(generation.getCommercialSupportEndDate());
|
||||
return new VersionValidation(toUpdateForUnsupported(springProject, version), enabled, severity, message.toString());
|
||||
|
||||
return new VersionValidation(toUpdateForUnsupported(springProject, version), severity, message.toString());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return preferences.getUnsupportedCommercialPreference().isEnabled();
|
||||
}
|
||||
}
|
||||
|
||||
private static Version toUpdateForUnsupported(ResolvedSpringProject springProject, Version version)
|
||||
@@ -129,4 +179,5 @@ public class VersionValidators {
|
||||
}
|
||||
return toUpdate;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user