Partial implementation of Spring Boot Releases

This commit is contained in:
Nieraj Singh
2022-11-12 03:56:54 -08:00
parent 1a262f2a3f
commit db472bf04e
9 changed files with 94 additions and 30 deletions

View File

@@ -186,4 +186,22 @@ public class SpringProjectUtil {
}
return null;
}
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
);
}
return null;
}
}

View File

@@ -18,8 +18,4 @@ public class GenerationsEmbedded extends JsonHalLinks implements JsonHalEmbedded
public Generations get_embedded() {
return _embedded;
}
public void set_embedded(Generations _embedded) {
this._embedded = _embedded;
}
}

View File

@@ -13,6 +13,4 @@ package org.springframework.ide.vscode.boot.validation.generations.json;
public interface JsonHalEmbedded<T> {
T get_embedded();
void set_embedded(T _embedded);
}

View File

@@ -22,39 +22,19 @@ public class Links {
return self;
}
public void setSelf(Link self) {
this.self = self;
}
public Link getReleases() {
return releases;
}
public void setReleases(Link releases) {
this.releases = releases;
}
public Link getGenerations() {
return generations;
}
public void setGenerations(Link generations) {
this.generations = generations;
}
public Link getParent() {
return parent;
}
public void setParent(Link parent) {
this.parent = parent;
}
public Link getProject() {
return project;
}
public void setProject(Link project) {
this.project = project;
}
}

View File

@@ -0,0 +1,23 @@
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;
public class Release {
private String version;
private String status;
private boolean current;
public Version getVersion() {
return SpringProjectUtil.getVersion(version);
}
public String getStatus() {
return status;
}
public boolean isCurrent() {
return current;
}
}

View File

@@ -0,0 +1,16 @@
package org.springframework.ide.vscode.boot.validation.generations.json;
import java.util.Arrays;
import java.util.List;
import com.google.common.collect.ImmutableList;
public class Releases {
private Release[] releases;
public List<Release> getReleases() {
return releases != null ? Arrays.asList(releases) : ImmutableList.of();
}
}

View File

@@ -15,6 +15,7 @@ import org.springframework.ide.vscode.boot.validation.generations.SpringProjects
public class SpringProject extends JsonHalLinks {
private Generations generations;
private Releases releases;
private String name;
@@ -52,4 +53,18 @@ public class SpringProject extends JsonHalLinks {
}
return this.generations;
}
public Releases getReleases(SpringProjectsClient client) throws Exception {
// cache the releases to prevent frequent calls to the client
if (this.releases == null) {
Links _links = get_links();
if (_links != null) {
Link genLink = _links.getReleases();
if (genLink != null) {
// this.releases = client.getGenerations(genLink.getHref());
}
}
}
return this.releases;
}
}

View File

@@ -17,8 +17,4 @@ public class SpringProjectsEmbedded extends JsonHalLinks implements JsonHalEmbed
public SpringProjects get_embedded() {
return _embedded;
}
public void set_embedded(SpringProjects _embedded) {
this._embedded = _embedded;
}
}

View File

@@ -134,4 +134,26 @@ public class ProjectGenerationsValidationTest {
version = SpringProjectUtil.getDependencyVersion("spring-boot-actuator-1.2.3.BUILD-SNAPSHOT.jar", "spring-boot");
assertNull(version);
}
@Test
public void testVersionCalculation() 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");
}
}