Cache dependency versions
This commit is contained in:
@@ -19,6 +19,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.ide.vscode.commons.Version;
|
||||
import org.springframework.ide.vscode.commons.protocol.java.Classpath;
|
||||
import org.springframework.ide.vscode.commons.protocol.java.Classpath.CPE;
|
||||
|
||||
@@ -26,8 +27,6 @@ public class SpringProjectUtil {
|
||||
|
||||
public static final String SPRING_BOOT = "spring-boot";
|
||||
|
||||
// Pattern copied from https://semver.org/
|
||||
private static final String VERSION_PATTERN_STR = "(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:(-|\\.)((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?";
|
||||
private static final String GENERATION_VERSION_STR = "([0-9]+)";
|
||||
|
||||
public static final Logger log = LoggerFactory.getLogger(SpringProjectUtil.class);
|
||||
@@ -114,10 +113,9 @@ public class SpringProjectUtil {
|
||||
|
||||
public static Version getDependencyVersion(IJavaProject jp, String dependency) {
|
||||
try {
|
||||
for (File f : IClasspathUtil.getBinaryRoots(jp.getClasspath(), (cpe) -> !cpe.isSystem())) {
|
||||
Version version = getDependencyVersion(f.getName(), dependency);
|
||||
if (version != null) {
|
||||
return version;
|
||||
for (CPE cpe : jp.getClasspath().getClasspathEntries()) {
|
||||
if (Classpath.isBinary(cpe) && !cpe.isSystem() && new File(cpe.getPath()).getName().startsWith(dependency)) {
|
||||
return cpe.getVersion();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@@ -156,10 +154,9 @@ public class SpringProjectUtil {
|
||||
|
||||
public static Version getSpringBootVersion(IJavaProject jp) {
|
||||
try {
|
||||
for (File f : IClasspathUtil.getBinaryRoots(jp.getClasspath(), (cpe) -> !cpe.isSystem())) {
|
||||
Version version = getDependencyVersion(f.getName(), SPRING_BOOT);
|
||||
if (version != null) {
|
||||
return version;
|
||||
for (CPE cpe : jp.getClasspath().getClasspathEntries()) {
|
||||
if (Classpath.isBinary(cpe) && !cpe.isSystem() && new File(cpe.getPath()).getName().startsWith(SPRING_BOOT)) {
|
||||
return cpe.getVersion();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@@ -168,33 +165,6 @@ public class SpringProjectUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Version getDependencyVersion(String fileName, String dependency) {
|
||||
if (fileName.startsWith(dependency)) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append('^');
|
||||
sb.append(dependency);
|
||||
sb.append('-');
|
||||
sb.append(VERSION_PATTERN_STR);
|
||||
sb.append("\\.jar$");
|
||||
Pattern pattern = Pattern.compile(sb.toString());
|
||||
|
||||
Matcher matcher = pattern.matcher(fileName);
|
||||
if (matcher.find() && matcher.groupCount() > 5) {
|
||||
String major = matcher.group(1);
|
||||
String minor = matcher.group(2);
|
||||
String patch = matcher.group(3);
|
||||
String qualifier = matcher.group(5);
|
||||
return new Version(
|
||||
Integer.parseInt(major),
|
||||
Integer.parseInt(minor),
|
||||
Integer.parseInt(patch),
|
||||
qualifier
|
||||
);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Predicate<IJavaProject> springBootVersionGreaterOrEqual(int major, int minor, int patch) {
|
||||
return project -> {
|
||||
Version version = getDependencyVersion(project, SPRING_BOOT);
|
||||
@@ -216,39 +186,4 @@ public class SpringProjectUtil {
|
||||
};
|
||||
}
|
||||
|
||||
public static Version getVersion(String version) {
|
||||
Pattern pattern = Pattern.compile(VERSION_PATTERN_STR);
|
||||
Matcher matcher = pattern.matcher(version);
|
||||
if (matcher.find() && matcher.groupCount() > 4) {
|
||||
String major = matcher.group(1);
|
||||
String minor = matcher.group(2);
|
||||
String patch = matcher.group(3);
|
||||
String qualifier = matcher.group(5);
|
||||
return new Version(
|
||||
Integer.parseInt(major),
|
||||
Integer.parseInt(minor),
|
||||
Integer.parseInt(patch),
|
||||
qualifier
|
||||
);
|
||||
} else {
|
||||
String[] tokens = version.split("\\.");
|
||||
if (tokens.length <= 3) {
|
||||
if (tokens.length >= 1) {
|
||||
int major = Integer.parseInt(tokens[0]);
|
||||
if (tokens.length >= 2) {
|
||||
int minor = Integer.parseInt(tokens[1]);
|
||||
if (tokens.length == 3) {
|
||||
int patch = Integer.parseInt(tokens[2]);
|
||||
return new Version(major, minor, patch, null);
|
||||
} else {
|
||||
return new Version(major, minor, 0, null);
|
||||
}
|
||||
} else {
|
||||
return new Version(major, 0, 0, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,12 +8,16 @@
|
||||
* Contributors:
|
||||
* VMware, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.commons.java;
|
||||
package org.springframework.ide.vscode.commons;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public final class Version implements Comparable<Version> {
|
||||
|
||||
private static final Pattern VERSION_PATTERN = Pattern.compile("(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:(-|\\.)((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?");
|
||||
|
||||
private int major;
|
||||
private int minor;
|
||||
private int patch;
|
||||
@@ -95,5 +99,41 @@ public final class Version implements Comparable<Version> {
|
||||
return major == other.major && minor == other.minor && patch == other.patch
|
||||
&& Objects.equals(qualifier, other.qualifier);
|
||||
}
|
||||
|
||||
public static Version parse(String version) {
|
||||
Matcher matcher = VERSION_PATTERN.matcher(version);
|
||||
if (matcher.find() && matcher.groupCount() > 4) {
|
||||
String major = matcher.group(1);
|
||||
String minor = matcher.group(2);
|
||||
String patch = matcher.group(3);
|
||||
String qualifier = matcher.group(5);
|
||||
return new Version(
|
||||
Integer.parseInt(major),
|
||||
Integer.parseInt(minor),
|
||||
Integer.parseInt(patch),
|
||||
qualifier
|
||||
);
|
||||
} else {
|
||||
String[] tokens = version.split("\\.");
|
||||
if (tokens.length <= 3) {
|
||||
if (tokens.length >= 1) {
|
||||
int major = Integer.parseInt(tokens[0]);
|
||||
if (tokens.length >= 2) {
|
||||
int minor = Integer.parseInt(tokens[1]);
|
||||
if (tokens.length == 3) {
|
||||
int patch = Integer.parseInt(tokens[2]);
|
||||
return new Version(major, minor, patch, null);
|
||||
} else {
|
||||
return new Version(major, minor, 0, null);
|
||||
}
|
||||
} else {
|
||||
return new Version(major, 0, 0, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -16,8 +16,15 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.springframework.ide.vscode.commons.Version;
|
||||
|
||||
public class Classpath {
|
||||
|
||||
// Pattern copied from https://semver.org/
|
||||
private static final Pattern VERSION_PATTERN = Pattern.compile("^.+-(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:(-|\\.)((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?\\.jar$");
|
||||
|
||||
public static final String ENTRY_KIND_SOURCE = "source";
|
||||
public static final String ENTRY_KIND_BINARY = "binary";
|
||||
@@ -64,6 +71,8 @@ public class Classpath {
|
||||
private boolean isJavaContent = false;
|
||||
|
||||
private Map<String, String> extra;
|
||||
|
||||
transient private Version version;
|
||||
|
||||
public CPE() {}
|
||||
|
||||
@@ -205,6 +214,15 @@ public class Classpath {
|
||||
&& Objects.equals(kind, other.kind) && Objects.equals(outputFolder, other.outputFolder)
|
||||
&& Objects.equals(path, other.path) && Objects.equals(sourceContainerUrl, other.sourceContainerUrl);
|
||||
}
|
||||
|
||||
public Version getVersion() {
|
||||
if (version == null) {
|
||||
if (getKind() == ENTRY_KIND_BINARY) {
|
||||
version = getDependencyVersion(new File(getPath()).getName());
|
||||
}
|
||||
}
|
||||
return version;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -232,5 +250,16 @@ public class Classpath {
|
||||
return isProjectJavaSource(cpe) && cpe.isTest();
|
||||
}
|
||||
|
||||
static Version getDependencyVersion(String fileName) {
|
||||
Matcher matcher = VERSION_PATTERN.matcher(fileName);
|
||||
if (matcher.find() && matcher.groupCount() > 5) {
|
||||
String major = matcher.group(1);
|
||||
String minor = matcher.group(2);
|
||||
String patch = matcher.group(3);
|
||||
String qualifier = matcher.group(5);
|
||||
return new Version(Integer.parseInt(major), Integer.parseInt(minor), Integer.parseInt(patch), qualifier);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2023 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.commons;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class VersionTests {
|
||||
|
||||
@Test
|
||||
void testVersionCalculation1() throws Exception {
|
||||
Version version = Version.parse("2.7.5");
|
||||
assertEquals(2, version.getMajor());
|
||||
assertEquals(7, version.getMinor());
|
||||
assertEquals(5, version.getPatch());
|
||||
assertNull(version.getQualifier());
|
||||
|
||||
version = Version.parse("3.0.0-SNAPSHOT");
|
||||
assertEquals(3, version.getMajor());
|
||||
assertEquals(0, version.getMinor());
|
||||
assertEquals(0, version.getPatch());
|
||||
assertEquals(version.getQualifier(), "SNAPSHOT");
|
||||
|
||||
|
||||
version = Version.parse("2.6.14-RC2");
|
||||
assertEquals(2, version.getMajor());
|
||||
assertEquals(6, version.getMinor());
|
||||
assertEquals(14, version.getPatch());
|
||||
assertEquals(version.getQualifier(), "RC2");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testVersionCalculation2() throws Exception {
|
||||
Version version = Version.parse("2.7");
|
||||
assertEquals(2, version.getMajor());
|
||||
assertEquals(7, version.getMinor());
|
||||
assertEquals(0, version.getPatch());
|
||||
assertNull(version.getQualifier());
|
||||
|
||||
version = Version.parse("2");
|
||||
assertEquals(2, version.getMajor());
|
||||
assertEquals(0, version.getMinor());
|
||||
assertEquals(0, version.getPatch());
|
||||
assertNull(version.getQualifier());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2023 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.commons.protocol.java;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.ide.vscode.commons.Version;
|
||||
|
||||
public class ClasspathTests {
|
||||
|
||||
@Test
|
||||
void testDependencyVersionCalculation2() throws Exception {
|
||||
Version version = Classpath.getDependencyVersion("spring-boot-1.2.3.jar");
|
||||
assertEquals(1, version.getMajor(), 1);
|
||||
assertEquals(2, version.getMinor(), 2);
|
||||
assertEquals(3, version.getPatch());
|
||||
assertNull(version.getQualifier());
|
||||
|
||||
version = Classpath.getDependencyVersion("spring-boot-1.2.3-RELEASE.jar");
|
||||
assertEquals(version.getMajor(), 1);
|
||||
assertEquals(version.getMinor(), 2);
|
||||
assertEquals(version.getPatch(), 3);
|
||||
assertEquals(version.getQualifier(), "RELEASE");
|
||||
|
||||
version = Classpath.getDependencyVersion("spring-boot-1.2.3.RELEASE.jar");
|
||||
assertEquals(1, version.getMajor(), 1);
|
||||
assertEquals(2, version.getMinor(), 2);
|
||||
assertEquals(3, version.getPatch());
|
||||
assertEquals("RELEASE", version.getQualifier());
|
||||
|
||||
version = Classpath.getDependencyVersion("spring-boot-1.2.3.BUILD-SNAPSHOT.jar");
|
||||
assertEquals(1, version.getMajor(), 1);
|
||||
assertEquals(2, version.getMinor(), 2);
|
||||
assertEquals(3, version.getPatch());
|
||||
assertEquals("BUILD-SNAPSHOT", version.getQualifier());
|
||||
|
||||
version = Classpath.getDependencyVersion("spring-boot-actuator-1.2.3.BUILD-SNAPSHOT.jar");
|
||||
assertEquals(1, version.getMajor(), 1);
|
||||
assertEquals(2, version.getMinor(), 2);
|
||||
assertEquals(3, version.getPatch());
|
||||
assertEquals("BUILD-SNAPSHOT", version.getQualifier());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -35,9 +35,9 @@ import org.springframework.ide.vscode.boot.java.beans.BeansSymbolAddOnInformatio
|
||||
import org.springframework.ide.vscode.boot.java.beans.FeignClientBeanSymbolAddOnInformation;
|
||||
import org.springframework.ide.vscode.boot.java.handlers.EnhancedSymbolInformation;
|
||||
import org.springframework.ide.vscode.boot.java.handlers.SymbolAddOnInformation;
|
||||
import org.springframework.ide.vscode.commons.Version;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.java.SpringProjectUtil;
|
||||
import org.springframework.ide.vscode.commons.java.Version;
|
||||
import org.springframework.ide.vscode.commons.languageserver.quickfix.QuickfixRegistry;
|
||||
import org.springframework.ide.vscode.commons.languageserver.reconcile.IProblemCollector;
|
||||
import org.springframework.ide.vscode.commons.languageserver.reconcile.ProblemType;
|
||||
|
||||
@@ -20,9 +20,9 @@ import org.eclipse.jdt.core.dom.MethodInvocation;
|
||||
import org.eclipse.jdt.core.dom.SimpleType;
|
||||
import org.openrewrite.java.spring.security5.AuthorizeHttpRequests;
|
||||
import org.springframework.ide.vscode.boot.java.Boot2JavaProblemType;
|
||||
import org.springframework.ide.vscode.commons.Version;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.java.SpringProjectUtil;
|
||||
import org.springframework.ide.vscode.commons.java.Version;
|
||||
import org.springframework.ide.vscode.commons.languageserver.quickfix.QuickfixRegistry;
|
||||
import org.springframework.ide.vscode.commons.languageserver.reconcile.IProblemCollector;
|
||||
import org.springframework.ide.vscode.commons.languageserver.reconcile.ProblemType;
|
||||
|
||||
@@ -31,9 +31,9 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.ide.vscode.boot.java.Annotations;
|
||||
import org.springframework.ide.vscode.boot.java.Boot2JavaProblemType;
|
||||
import org.springframework.ide.vscode.boot.java.rewrite.RewriteRefactorings;
|
||||
import org.springframework.ide.vscode.commons.Version;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.java.SpringProjectUtil;
|
||||
import org.springframework.ide.vscode.commons.java.Version;
|
||||
import org.springframework.ide.vscode.commons.languageserver.quickfix.Quickfix.QuickfixData;
|
||||
import org.springframework.ide.vscode.commons.languageserver.quickfix.QuickfixRegistry;
|
||||
import org.springframework.ide.vscode.commons.languageserver.quickfix.QuickfixType;
|
||||
|
||||
@@ -15,9 +15,9 @@ import java.util.Collection;
|
||||
|
||||
import org.openrewrite.java.spring.boot2.HttpSecurityLambdaDsl;
|
||||
import org.springframework.ide.vscode.boot.java.Boot2JavaProblemType;
|
||||
import org.springframework.ide.vscode.commons.Version;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.java.SpringProjectUtil;
|
||||
import org.springframework.ide.vscode.commons.java.Version;
|
||||
import org.springframework.ide.vscode.commons.languageserver.quickfix.QuickfixRegistry;
|
||||
import org.springframework.ide.vscode.commons.languageserver.reconcile.ProblemType;
|
||||
|
||||
|
||||
@@ -15,9 +15,9 @@ import java.util.Collection;
|
||||
|
||||
import org.openrewrite.java.spring.boot2.ServerHttpSecurityLambdaDsl;
|
||||
import org.springframework.ide.vscode.boot.java.Boot2JavaProblemType;
|
||||
import org.springframework.ide.vscode.commons.Version;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.java.SpringProjectUtil;
|
||||
import org.springframework.ide.vscode.commons.java.Version;
|
||||
import org.springframework.ide.vscode.commons.languageserver.quickfix.QuickfixRegistry;
|
||||
import org.springframework.ide.vscode.commons.languageserver.reconcile.ProblemType;
|
||||
|
||||
|
||||
@@ -23,9 +23,9 @@ import org.eclipse.jdt.core.dom.TypeDeclaration;
|
||||
import org.openrewrite.java.spring.security5.WebSecurityConfigurerAdapter;
|
||||
import org.springframework.ide.vscode.boot.java.Annotations;
|
||||
import org.springframework.ide.vscode.boot.java.Boot2JavaProblemType;
|
||||
import org.springframework.ide.vscode.commons.Version;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.java.SpringProjectUtil;
|
||||
import org.springframework.ide.vscode.commons.java.Version;
|
||||
import org.springframework.ide.vscode.commons.languageserver.quickfix.QuickfixRegistry;
|
||||
import org.springframework.ide.vscode.commons.languageserver.reconcile.IProblemCollector;
|
||||
import org.springframework.ide.vscode.commons.languageserver.reconcile.ProblemType;
|
||||
|
||||
@@ -23,9 +23,9 @@ import org.openrewrite.Recipe;
|
||||
import org.openrewrite.config.DeclarativeRecipe;
|
||||
import org.openrewrite.maven.UpgradeDependencyVersion;
|
||||
import org.openrewrite.maven.UpgradeParentVersion;
|
||||
import org.springframework.ide.vscode.commons.Version;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.java.SpringProjectUtil;
|
||||
import org.springframework.ide.vscode.commons.java.Version;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
|
||||
import org.springframework.ide.vscode.commons.util.Assert;
|
||||
@@ -53,7 +53,7 @@ public class SpringBootUpgrade {
|
||||
server.onCommand(CMD_UPGRADE_SPRING_BOOT, params -> {
|
||||
String uri = ((JsonElement) params.getArguments().get(0)).getAsString();
|
||||
Assert.isLegal(uri != null, "Project URI parameter must not be 'null'");
|
||||
Version targetVersion = SpringProjectUtil.getVersion(((JsonElement) params.getArguments().get(1)).getAsString());
|
||||
Version targetVersion = Version.parse(((JsonElement) params.getArguments().get(1)).getAsString());
|
||||
Assert.isLegal(targetVersion != null, "Target Spring Boot version must not be 'null'");
|
||||
|
||||
IJavaProject project = projectFinder.find(new TextDocumentIdentifier(uri)).orElse(null);
|
||||
|
||||
@@ -17,9 +17,9 @@ import org.eclipse.lsp4j.Diagnostic;
|
||||
import org.springframework.ide.vscode.boot.validation.generations.json.Generation;
|
||||
import org.springframework.ide.vscode.boot.validation.generations.json.ResolvedSpringProject;
|
||||
import org.springframework.ide.vscode.boot.validation.generations.preferences.VersionValidationProblemType;
|
||||
import org.springframework.ide.vscode.commons.Version;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.java.SpringProjectUtil;
|
||||
import org.springframework.ide.vscode.commons.java.Version;
|
||||
import org.springframework.ide.vscode.commons.languageserver.reconcile.DiagnosticSeverityProvider;
|
||||
import org.springframework.ide.vscode.commons.util.Assert;
|
||||
|
||||
|
||||
@@ -20,9 +20,9 @@ import java.util.List;
|
||||
import org.eclipse.lsp4j.Diagnostic;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.ide.vscode.commons.Version;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.java.SpringProjectUtil;
|
||||
import org.springframework.ide.vscode.commons.java.Version;
|
||||
|
||||
public class ProjectVersionDiagnosticProvider {
|
||||
|
||||
|
||||
@@ -23,9 +23,9 @@ import org.eclipse.lsp4j.Range;
|
||||
import org.eclipse.lsp4j.ShowDocumentParams;
|
||||
import org.springframework.ide.vscode.boot.java.rewrite.SpringBootUpgrade;
|
||||
import org.springframework.ide.vscode.boot.validation.generations.preferences.VersionValidationProblemType;
|
||||
import org.springframework.ide.vscode.commons.Version;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.java.SpringProjectUtil;
|
||||
import org.springframework.ide.vscode.commons.java.Version;
|
||||
import org.springframework.ide.vscode.commons.languageserver.reconcile.DiagnosticSeverityProvider;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
@@ -67,7 +67,7 @@ public class UpdateBootVersion extends AbstractDiagnosticValidator {
|
||||
List<CodeAction> actions = new ArrayList<>(2);
|
||||
|
||||
bootUpgradeOpt.flatMap(bu -> bu.getNearestAvailableMinorVersion(latest)).map(targetVersion -> {
|
||||
Version upgradeVersion = SpringProjectUtil.getVersion(targetVersion);
|
||||
Version upgradeVersion = Version.parse(targetVersion);
|
||||
if (javaProjectVersion.compareTo(upgradeVersion) >= 0) {
|
||||
return null;
|
||||
}
|
||||
@@ -100,7 +100,7 @@ public class UpdateBootVersion extends AbstractDiagnosticValidator {
|
||||
List<CodeAction> actions = new ArrayList<>(2);
|
||||
|
||||
bootUpgradeOpt.flatMap(bu -> bu.getNearestAvailableMinorVersion(latest)).map(targetVersion -> {
|
||||
Version upgradeVersion = SpringProjectUtil.getVersion(targetVersion);
|
||||
Version upgradeVersion = Version.parse(targetVersion);
|
||||
if (javaProjectVersion.compareTo(upgradeVersion) >= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ import java.util.List;
|
||||
|
||||
import org.springframework.ide.vscode.boot.validation.generations.json.Generation;
|
||||
import org.springframework.ide.vscode.boot.validation.generations.json.ResolvedSpringProject;
|
||||
import org.springframework.ide.vscode.commons.java.Version;
|
||||
import org.springframework.ide.vscode.commons.Version;
|
||||
|
||||
public class VersionValidationUtils {
|
||||
|
||||
|
||||
@@ -13,8 +13,8 @@ package org.springframework.ide.vscode.boot.validation.generations;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.eclipse.lsp4j.Diagnostic;
|
||||
import org.springframework.ide.vscode.commons.Version;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.java.Version;
|
||||
|
||||
public interface VersionValidator {
|
||||
|
||||
|
||||
@@ -10,8 +10,7 @@
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.boot.validation.generations.json;
|
||||
|
||||
import org.springframework.ide.vscode.commons.java.SpringProjectUtil;
|
||||
import org.springframework.ide.vscode.commons.java.Version;
|
||||
import org.springframework.ide.vscode.commons.Version;
|
||||
|
||||
public class Release extends JsonHalLinks {
|
||||
|
||||
@@ -29,7 +28,7 @@ public class Release extends JsonHalLinks {
|
||||
|
||||
|
||||
public Version getVersion() {
|
||||
return SpringProjectUtil.getVersion(version);
|
||||
return Version.parse(version);
|
||||
}
|
||||
|
||||
public Status getStatus() {
|
||||
|
||||
@@ -14,7 +14,7 @@ import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.ide.vscode.boot.validation.generations.SpringProjectsClient;
|
||||
import org.springframework.ide.vscode.commons.java.Version;
|
||||
import org.springframework.ide.vscode.commons.Version;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.ide.vscode.commons.java.Version;
|
||||
import org.springframework.ide.vscode.commons.Version;
|
||||
|
||||
public class SpringBootUpgradeTest {
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ package org.springframework.ide.vscode.boot.validation.test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.util.List;
|
||||
@@ -32,8 +31,6 @@ import org.springframework.ide.vscode.boot.validation.generations.json.Generatio
|
||||
import org.springframework.ide.vscode.boot.validation.generations.json.Link;
|
||||
import org.springframework.ide.vscode.boot.validation.generations.json.ResolvedSpringProject;
|
||||
import org.springframework.ide.vscode.boot.validation.generations.json.SpringProject;
|
||||
import org.springframework.ide.vscode.commons.java.SpringProjectUtil;
|
||||
import org.springframework.ide.vscode.commons.java.Version;
|
||||
import org.springframework.ide.vscode.project.harness.BootLanguageServerHarness;
|
||||
import org.springframework.ide.vscode.project.harness.ProjectsHarness;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
@@ -104,71 +101,5 @@ public class ProjectGenerationsValidationTest {
|
||||
assertEquals("2020-01-01", generation.getOssSupportEndDate());
|
||||
assertEquals("2021-01-01", generation.getCommercialSupportEndDate());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDependencyVersionCalculation() throws Exception {
|
||||
Version version = SpringProjectUtil.getDependencyVersion("spring-boot-1.2.3.jar", "spring-boot");
|
||||
assertEquals(1, version.getMajor(), 1);
|
||||
assertEquals(2, version.getMinor(), 2);
|
||||
assertEquals(3, version.getPatch());
|
||||
assertNull(version.getQualifier());
|
||||
|
||||
version = SpringProjectUtil.getDependencyVersion("spring-boot-1.2.3-RELEASE.jar", "spring-boot");
|
||||
assertEquals(version.getMajor(), 1);
|
||||
assertEquals(version.getMinor(), 2);
|
||||
assertEquals(version.getPatch(), 3);
|
||||
assertEquals(version.getQualifier(), "RELEASE");
|
||||
|
||||
version = SpringProjectUtil.getDependencyVersion("spring-boot-1.2.3.RELEASE.jar", "spring-boot");
|
||||
assertEquals(1, version.getMajor(), 1);
|
||||
assertEquals(2, version.getMinor(), 2);
|
||||
assertEquals(3, version.getPatch());
|
||||
assertEquals("RELEASE", version.getQualifier());
|
||||
|
||||
version = SpringProjectUtil.getDependencyVersion("spring-boot-1.2.3.BUILD-SNAPSHOT.jar", "spring-boot");
|
||||
assertEquals(1, version.getMajor(), 1);
|
||||
assertEquals(2, version.getMinor(), 2);
|
||||
assertEquals(3, version.getPatch());
|
||||
assertEquals("BUILD-SNAPSHOT", version.getQualifier());
|
||||
|
||||
version = SpringProjectUtil.getDependencyVersion("spring-boot-actuator-1.2.3.BUILD-SNAPSHOT.jar", "spring-boot");
|
||||
assertNull(version);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testVersionCalculation1() throws Exception {
|
||||
Version version = SpringProjectUtil.getVersion("2.7.5");
|
||||
assertEquals(2, version.getMajor());
|
||||
assertEquals(7, version.getMinor());
|
||||
assertEquals(5, version.getPatch());
|
||||
assertNull(version.getQualifier());
|
||||
|
||||
version = SpringProjectUtil.getVersion("3.0.0-SNAPSHOT");
|
||||
assertEquals(3, version.getMajor());
|
||||
assertEquals(0, version.getMinor());
|
||||
assertEquals(0, version.getPatch());
|
||||
assertEquals(version.getQualifier(), "SNAPSHOT");
|
||||
|
||||
|
||||
version = SpringProjectUtil.getVersion("2.6.14-RC2");
|
||||
assertEquals(2, version.getMajor());
|
||||
assertEquals(6, version.getMinor());
|
||||
assertEquals(14, version.getPatch());
|
||||
assertEquals(version.getQualifier(), "RC2");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testVersionCalculation2() throws Exception {
|
||||
Version version = SpringProjectUtil.getVersion("2.7");
|
||||
assertEquals(2, version.getMajor());
|
||||
assertEquals(7, version.getMinor());
|
||||
assertEquals(0, version.getPatch());
|
||||
assertNull(version.getQualifier());
|
||||
|
||||
version = SpringProjectUtil.getVersion("2");
|
||||
assertEquals(2, version.getMajor());
|
||||
assertEquals(0, version.getMinor());
|
||||
assertEquals(0, version.getPatch());
|
||||
assertNull(version.getQualifier());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ 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.boot.validation.generations.json.SpringProject;
|
||||
import org.springframework.ide.vscode.boot.validation.generations.json.SpringProjects;
|
||||
import org.springframework.ide.vscode.commons.java.Version;
|
||||
import org.springframework.ide.vscode.commons.Version;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.ide.vscode.boot.validation.generations.VersionValidationUtils;
|
||||
import org.springframework.ide.vscode.commons.java.Version;
|
||||
import org.springframework.ide.vscode.commons.Version;
|
||||
|
||||
public class VersionValidationUtilsTest {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user