PT 173730396 - Further support for version validation
Added further support to generate warning messages for a java project from spring project metadata.
This commit is contained in:
@@ -12,7 +12,6 @@ package org.springframework.ide.vscode.commons.java;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -23,9 +22,14 @@ import org.slf4j.LoggerFactory;
|
||||
public class SpringProjectUtil {
|
||||
|
||||
public static final Logger log = LoggerFactory.getLogger(SpringProjectUtil.class);
|
||||
|
||||
private static final Pattern MAJOR_MINOR_VERSION = Pattern.compile("(\\d+\\.)(\\d+)");
|
||||
|
||||
private static final Pattern MAJOR_MINOR_VERSION = Pattern.compile("(0|[1-9]\\d*)\\.(0|[1-9]\\d*)");
|
||||
|
||||
// Pattern copied from https://semver.org/
|
||||
private static final Pattern VERSION = 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 static final Pattern SPRING_NAME = Pattern.compile("([a-z]+)(-[a-z]+)*");
|
||||
|
||||
public static boolean isSpringProject(IJavaProject jp) {
|
||||
return hasSpecificLibraryOnClasspath(jp, "spring-core", true);
|
||||
}
|
||||
@@ -37,45 +41,6 @@ public class SpringProjectUtil {
|
||||
public static boolean hasBootActuators(IJavaProject jp) {
|
||||
return hasSpecificLibraryOnClasspath(jp, "spring-boot-actuator-", true);
|
||||
}
|
||||
|
||||
public static boolean hasSpecificLibraryOnClasspath(IJavaProject jp, String libraryNamePrefix, boolean onlyLibs) {
|
||||
try {
|
||||
IClasspath cp = jp.getClasspath();
|
||||
if (cp!=null) {
|
||||
return IClasspathUtil.getBinaryRoots(cp, (cpe) -> !cpe.isSystem()).stream().anyMatch(cpe -> isEntry(cpe, libraryNamePrefix, onlyLibs));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to determine whether '" + jp.getElementName() + "' is Spring Boot project", e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static File getLibraryOnClasspath(IJavaProject jp, String libraryNamePrefix) {
|
||||
try {
|
||||
IClasspath cp = jp.getClasspath();
|
||||
if (cp!=null) {
|
||||
boolean onlyLibs = true;
|
||||
Optional<File> found = IClasspathUtil.getBinaryRoots(cp, (cpe) -> !cpe.isSystem()).stream().filter(cpe -> isEntry(cpe, libraryNamePrefix, onlyLibs)).findFirst();
|
||||
if (found.isPresent()) {
|
||||
return found.get();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to get library for project '" + jp.getElementName() + "' that start with prefix: " + libraryNamePrefix, e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getMajMinVersion(IJavaProject jp, String libraryNamePrefix) {
|
||||
if (jp != null) {
|
||||
File libraryOnClasspath = getLibraryOnClasspath(jp, libraryNamePrefix);
|
||||
if (libraryOnClasspath != null) {
|
||||
String name = libraryOnClasspath.getName();
|
||||
return getMajMinVersion(name);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getMajMinVersion(String name) {
|
||||
Matcher matcher = MAJOR_MINOR_VERSION.matcher(name);
|
||||
@@ -86,6 +51,31 @@ public class SpringProjectUtil {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getVersion(String name) {
|
||||
Matcher matcher = VERSION.matcher(name);
|
||||
if (matcher.find()) {
|
||||
int start = matcher.start();
|
||||
int end = matcher.end();
|
||||
return name.substring(start, end);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param libName e.g. spring-boot-3.0.0.RELEASE.jar
|
||||
* @return "slug" portion: "spring-boot"
|
||||
*/
|
||||
public static String getProjectSlug(String libName) {
|
||||
Matcher matcher = SPRING_NAME.matcher(libName);
|
||||
if (matcher.find()) {
|
||||
int start = matcher.start();
|
||||
int end = matcher.end();
|
||||
return libName.substring(start, end);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static List<File> getLibrariesOnClasspath(IJavaProject jp, String libraryNamePrefix) {
|
||||
try {
|
||||
@@ -100,6 +90,18 @@ public class SpringProjectUtil {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean hasSpecificLibraryOnClasspath(IJavaProject jp, String libraryNamePrefix, boolean onlyLibs) {
|
||||
try {
|
||||
IClasspath cp = jp.getClasspath();
|
||||
if (cp!=null) {
|
||||
return IClasspathUtil.getBinaryRoots(cp, (cpe) -> !cpe.isSystem()).stream().anyMatch(cpe -> isEntry(cpe, libraryNamePrefix, onlyLibs));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to determine whether '" + jp.getElementName() + "' is Spring Boot project", e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isEntry(File cpe, String libNamePrefix, boolean onlyLibs) {
|
||||
String name = cpe.getName();
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2020 Pivotal, 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:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.boot.validation.generations;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.ide.vscode.boot.validation.generations.json.Generations;
|
||||
import org.springframework.ide.vscode.boot.validation.generations.json.Link;
|
||||
import org.springframework.ide.vscode.boot.validation.generations.json.Links;
|
||||
import org.springframework.ide.vscode.boot.validation.generations.json.SpringProject;
|
||||
import org.springframework.ide.vscode.boot.validation.generations.json.SpringProjects;
|
||||
|
||||
public class SpringProjectIndex {
|
||||
|
||||
private final SpringProjectsClient client;
|
||||
|
||||
public SpringProjectIndex(SpringProjectsClient client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
public SpringProjects getProjects() throws Exception {
|
||||
return client.getSpringProjects();
|
||||
}
|
||||
|
||||
public Generations getGenerations(SpringProject project) throws Exception {
|
||||
if (project != null) {
|
||||
Links _links = project.get_links();
|
||||
if (_links != null) {
|
||||
Link genLink = _links.getGenerations();
|
||||
if (genLink != null) {
|
||||
return client.getGenerations(genLink.getHref());
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param projectSlug slug used by Spring projects metadata, for example
|
||||
* "spring-boot" for Spring Boot projects
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public SpringProject getProject(String projectSlug) throws Exception {
|
||||
SpringProjects springProjects = getProjects();
|
||||
List<SpringProject> projects = springProjects.getProjects();
|
||||
SpringProject prj = null;
|
||||
for (SpringProject project : projects) {
|
||||
if (project.getSlug().equals(projectSlug)) {
|
||||
prj = project;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return prj;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2020 Pivotal, 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:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.boot.validation.generations;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.ide.vscode.boot.validation.generations.json.Generations;
|
||||
import org.springframework.ide.vscode.boot.validation.generations.json.Link;
|
||||
import org.springframework.ide.vscode.boot.validation.generations.json.Links;
|
||||
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.languageserver.util.SimpleLanguageServer;
|
||||
import org.springframework.ide.vscode.commons.util.AsyncRunner;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableMap.Builder;
|
||||
|
||||
public class SpringProjectsCache {
|
||||
|
||||
private static final long TIMEOUT_SECS = 30;
|
||||
private final SpringProjectsClient client;
|
||||
private final SimpleLanguageServer server;
|
||||
private Map<String, SpringProject> cache;
|
||||
|
||||
public SpringProjectsCache(SpringProjectsClient client, SimpleLanguageServer server) {
|
||||
this.client = client;
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Project slug. E.g. "spring-boot"
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public SpringProject getProject(String slug) throws Exception {
|
||||
return cache().get(slug);
|
||||
}
|
||||
|
||||
public Generations getGenerations(SpringProject project) throws Exception {
|
||||
if (project != null) {
|
||||
Links _links = project.get_links();
|
||||
if (_links != null) {
|
||||
Link genLink = _links.getGenerations();
|
||||
if (genLink != null) {
|
||||
return client.getGenerations(genLink.getHref());
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Map<String, SpringProject> cache() throws Exception {
|
||||
if (cache == null) {
|
||||
loadCache();
|
||||
}
|
||||
return cache != null ? cache : ImmutableMap.of();
|
||||
}
|
||||
|
||||
private void loadCache() throws Exception {
|
||||
AsyncRunner async = this.server.getAsync();
|
||||
if (async != null) {
|
||||
async.invoke(Duration.ofSeconds(TIMEOUT_SECS), () -> {
|
||||
SpringProjects springProjects = client.getSpringProjects();
|
||||
return asMap(springProjects);
|
||||
}).thenAccept((map) -> cache = map).get();
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, SpringProject> asMap(SpringProjects springProjects) {
|
||||
Builder<String, SpringProject> builder = ImmutableMap.builder();
|
||||
|
||||
if (springProjects != null) {
|
||||
List<SpringProject> projects = springProjects.getProjects();
|
||||
if (projects != null) {
|
||||
for (SpringProject project : projects) {
|
||||
builder.put(project.getSlug(), project);
|
||||
}
|
||||
}
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2020 Pivotal, 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:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.boot.validation.generations;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.ide.vscode.boot.validation.generations.json.Generation;
|
||||
import org.springframework.ide.vscode.boot.validation.generations.json.Generations;
|
||||
import org.springframework.ide.vscode.boot.validation.generations.json.SpringProject;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.java.SpringProjectUtil;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
public class SpringProjectsValidations {
|
||||
|
||||
private final SpringProjectsCache cache;
|
||||
|
||||
public SpringProjectsValidations(SpringProjectsCache cache) {
|
||||
this.cache = cache;
|
||||
}
|
||||
|
||||
public List<String> getVersionWarnings(IJavaProject jp) throws Exception {
|
||||
ImmutableList.Builder<String> messages = ImmutableList.builder();
|
||||
|
||||
if (jp != null) {
|
||||
List<File> librariesOnClasspath = SpringProjectUtil.getLibrariesOnClasspath(jp, "spring");
|
||||
if (librariesOnClasspath != null) {
|
||||
for (File file : librariesOnClasspath) {
|
||||
String fileName = file.getName();
|
||||
String slug = SpringProjectUtil.getProjectSlug(fileName);
|
||||
String majMin = SpringProjectUtil.getMajMinVersion(fileName);
|
||||
String fullVersion = SpringProjectUtil.getVersion(fileName);
|
||||
SpringProject springProject = cache.getProject(slug);
|
||||
if (springProject != null && majMin != null) {
|
||||
Generations generations = cache.getGenerations(springProject);
|
||||
if (generations != null) {
|
||||
List<Generation> gens = generations.getGenerations();
|
||||
if (gens != null) {
|
||||
Generation gen = null;
|
||||
for (Generation g : gens) {
|
||||
if (isInGeneration(majMin, g)) {
|
||||
gen = g;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (gen != null) {
|
||||
messages.add(getWarning(slug, fullVersion, gen));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return messages.build();
|
||||
}
|
||||
|
||||
private String getWarning(String slug, String version, Generation gen) {
|
||||
StringBuilder msg = new StringBuilder();
|
||||
msg.append("Using ");
|
||||
msg.append(slug);
|
||||
msg.append(" version: ");
|
||||
msg.append(version);
|
||||
msg.append(" - OSS support end date: ");
|
||||
msg.append(gen.getOssSupportEndDate());
|
||||
return msg.toString();
|
||||
}
|
||||
|
||||
private boolean isInGeneration(String version, Generation g) {
|
||||
return g.getName().contains(version);
|
||||
}
|
||||
}
|
||||
@@ -20,8 +20,13 @@ import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ide.vscode.boot.validation.generations.SpringProjectIndex;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.ide.vscode.boot.bootiful.BootLanguageServerTest;
|
||||
import org.springframework.ide.vscode.boot.bootiful.HoverTestConf;
|
||||
import org.springframework.ide.vscode.boot.validation.generations.SpringProjectsCache;
|
||||
import org.springframework.ide.vscode.boot.validation.generations.SpringProjectsValidations;
|
||||
import org.springframework.ide.vscode.boot.validation.generations.SpringProjectsClient;
|
||||
import org.springframework.ide.vscode.boot.validation.generations.json.Generation;
|
||||
import org.springframework.ide.vscode.boot.validation.generations.json.Generations;
|
||||
@@ -35,7 +40,11 @@ import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.java.SpringProjectUtil;
|
||||
import org.springframework.ide.vscode.project.harness.BootLanguageServerHarness;
|
||||
import org.springframework.ide.vscode.project.harness.ProjectsHarness;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@BootLanguageServerTest
|
||||
@Import(HoverTestConf.class)
|
||||
public class ProjectGenerationsValidationTest {
|
||||
|
||||
@Autowired private BootLanguageServerHarness harness;
|
||||
@@ -45,12 +54,12 @@ public class ProjectGenerationsValidationTest {
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
// harness.useProject(projects.mavenProject("empty-boot-15-web-app"));
|
||||
|
||||
harness.useProject(projects.mavenProject("empty-boot-1.3.0-app"));
|
||||
harness.intialize(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVersionParsing() throws Exception {
|
||||
public void testMajMinVersionParsing() throws Exception {
|
||||
String version = SpringProjectUtil.getMajMinVersion("spring-boot-starter-batch-2.3.4.RELEASE");
|
||||
assertEquals("2.3", version);
|
||||
|
||||
@@ -60,8 +69,8 @@ public class ProjectGenerationsValidationTest {
|
||||
version = SpringProjectUtil.getMajMinVersion("spring-boot-4.4.0-RC2");
|
||||
assertEquals("4.4", version);
|
||||
|
||||
version = SpringProjectUtil.getMajMinVersion("spring-integration-70.411.RELEASE");
|
||||
assertEquals("70.411", version);
|
||||
version = SpringProjectUtil.getMajMinVersion("spring-integration-70.811.0.RELEASE");
|
||||
assertEquals("70.811", version);
|
||||
|
||||
version = SpringProjectUtil.getMajMinVersion("another-java-");
|
||||
assertNull(version);
|
||||
@@ -73,73 +82,95 @@ public class ProjectGenerationsValidationTest {
|
||||
assertNull(version);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVersionParsing() throws Exception {
|
||||
String version = SpringProjectUtil.getVersion("spring-boot-starter-batch-2.3.0.RELEASE");
|
||||
assertEquals("2.3.0", version);
|
||||
|
||||
version = SpringProjectUtil.getVersion("spring-boot-starter-batch-2.4.0-M4");
|
||||
assertEquals("2.4.0-M4", version);
|
||||
|
||||
version = SpringProjectUtil.getVersion("spring-boot-4.4.0-RC2");
|
||||
assertEquals("4.4.0-RC2", version);
|
||||
|
||||
version = SpringProjectUtil.getVersion("spring-integration-70.811.0.RELEASE");
|
||||
assertEquals("70.811.0", version);
|
||||
|
||||
version = SpringProjectUtil.getVersion("another-java-");
|
||||
assertNull(version);
|
||||
|
||||
version = SpringProjectUtil.getVersion("spring-core-5.f.2");
|
||||
assertNull(version);
|
||||
|
||||
version = SpringProjectUtil.getVersion("springcore.f.b");
|
||||
assertNull(version);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProjectSlugParsing() throws Exception {
|
||||
String slug = SpringProjectUtil.getProjectSlug("spring-boot-starter-batch-2.3.4.RELEASE");
|
||||
assertEquals("spring-boot-starter-batch", slug);
|
||||
|
||||
slug = SpringProjectUtil.getProjectSlug("spring-2.4.0-M4");
|
||||
assertEquals("spring", slug);
|
||||
|
||||
slug = SpringProjectUtil.getProjectSlug("-4.4.0-RC2");
|
||||
assertNull(slug);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVersionAndLibsFromActualProject() throws Exception {
|
||||
IJavaProject jp = projects.mavenProject("empty-boot-1.3.0-app");
|
||||
assertTrue(SpringProjectUtil.isBootProject(jp));
|
||||
|
||||
File file = SpringProjectUtil.getLibraryOnClasspath(jp, "spring-boot");
|
||||
assertNotNull(file);
|
||||
assertTrue(file.exists());
|
||||
|
||||
String version = SpringProjectUtil.getMajMinVersion(jp, "spring-boot");
|
||||
assertEquals("1.3", version);
|
||||
|
||||
List<File> springLibs = SpringProjectUtil.getLibrariesOnClasspath(jp, "spring");
|
||||
assertNotNull(springLibs);
|
||||
assertTrue(springLibs.size() > 1);
|
||||
|
||||
File file = getLib(springLibs, "spring-boot");
|
||||
assertNotNull(file);
|
||||
assertTrue(file.exists());
|
||||
|
||||
String version = SpringProjectUtil.getMajMinVersion(file.getName());
|
||||
assertEquals("1.3", version);
|
||||
|
||||
String slug = SpringProjectUtil.getProjectSlug(file.getName());
|
||||
assertEquals("spring-boot", slug);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProjectsInfoFromSpringIo() throws Exception {
|
||||
String url = "https://spring.io/api/projects";
|
||||
SpringProjectsClient client = new SpringProjectsClient(url);
|
||||
SpringProjectIndex projectIndex = new SpringProjectIndex(client);
|
||||
SpringProjectsCache cache = new SpringProjectsCache(client, harness.getServer());
|
||||
|
||||
SpringProjects springProjects = projectIndex.getProjects();
|
||||
assertNotNull(springProjects);
|
||||
assertTrue(!springProjects.getProjects().isEmpty());
|
||||
|
||||
SpringProject project = projectIndex.getProject("spring-boot");
|
||||
SpringProject project = cache.getProject("spring-boot");
|
||||
assertNotNull(project);
|
||||
assertEquals("Spring Boot", project.getName());
|
||||
assertEquals("spring-boot", project.getSlug());
|
||||
|
||||
project = projectIndex.getProject("spring-integration");
|
||||
assertNotNull(project);
|
||||
assertEquals("Spring Integration", project.getName());
|
||||
assertEquals("spring-integration", project.getSlug());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerationsFromSpringIo() throws Exception {
|
||||
String url = "https://spring.io/api/projects";
|
||||
SpringProjectsClient client = new SpringProjectsClient(url);
|
||||
SpringProjectIndex projectIndex = new SpringProjectIndex(client);
|
||||
|
||||
SpringProject project = projectIndex.getProject("spring-boot");
|
||||
assertNotNull(project);
|
||||
Link generationsUrl = project.get_links().getGenerations();
|
||||
assertNotNull(generationsUrl);
|
||||
assertEquals("https://spring.io/api/projects/spring-boot/generations", generationsUrl.getHref());
|
||||
|
||||
Generations generations = projectIndex.getGenerations(project);
|
||||
|
||||
// NOTE: at the moment Generations are not available from spring.io API. Enable
|
||||
// when they are
|
||||
// assertNotNull(generations);
|
||||
project = cache.getProject("spring-integration");
|
||||
assertNotNull(project);
|
||||
assertEquals("Spring Integration", project.getName());
|
||||
assertEquals("spring-integration", project.getSlug());
|
||||
generationsUrl = project.get_links().getGenerations();
|
||||
assertNotNull(generationsUrl);
|
||||
assertEquals("https://spring.io/api/projects/spring-integration/generations", generationsUrl.getHref());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerationsFromSample() throws Exception {
|
||||
SpringProjectsClient client = getMockClient();
|
||||
|
||||
SpringProjectIndex projectIndex = new SpringProjectIndex(client);
|
||||
SpringProjectsCache cache = new SpringProjectsCache(client, harness.getServer());
|
||||
|
||||
SpringProject project = projectIndex.getProject("spring-boot");
|
||||
SpringProject project = cache.getProject("spring-boot");
|
||||
assertNotNull(project);
|
||||
|
||||
Generations generations = projectIndex.getGenerations(project);
|
||||
Generations generations = cache.getGenerations(project);
|
||||
assertNotNull(generations);
|
||||
|
||||
List<Generation> genList = generations.getGenerations();
|
||||
@@ -148,11 +179,26 @@ public class ProjectGenerationsValidationTest {
|
||||
assertTrue(genList.size() > 0);
|
||||
|
||||
Generation generation = genList.get(0);
|
||||
assertEquals("2.1.x", generation.getName());
|
||||
assertEquals("1.3.x", generation.getName());
|
||||
assertEquals("2019-01-01", generation.getInitialReleaseDate());
|
||||
assertEquals("2020-01-01", generation.getOssSupportEndDate());
|
||||
assertEquals("2021-01-01", generation.getCommercialSupportEndDate());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWarningsFromSample() throws Exception {
|
||||
|
||||
SpringProjectsClient client = getMockClient();
|
||||
IJavaProject jp = projects.mavenProject("empty-boot-1.3.0-app");
|
||||
|
||||
SpringProjectsCache cache = new SpringProjectsCache(client, harness.getServer());
|
||||
SpringProjectsValidations validation = new SpringProjectsValidations(cache);
|
||||
List<String> messages = validation.getVersionWarnings(jp);
|
||||
assertTrue(messages != null && messages.size() > 0);
|
||||
String msg = messages.get(0);
|
||||
// Check that the message mentions the boot version of the project and the OSS support end date
|
||||
assertTrue(msg.contains("1.3.2") && msg.contains("OSS") && msg.contains("2020-01-01"));
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
@@ -195,4 +241,15 @@ public class ProjectGenerationsValidationTest {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private File getLib(List<File> springLibs, String slug) {
|
||||
for (File file : springLibs) {
|
||||
String name = file.getName();
|
||||
String libSlug = SpringProjectUtil.getProjectSlug(name);
|
||||
if (slug.equals(libSlug)) {
|
||||
return file;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,11 +3,11 @@ package org.springframework.ide.vscode.boot.validation.test;
|
||||
public class SpringProjectsTestSamples {
|
||||
|
||||
public static final String SPRING_BOOT_PROJECT_GENERATIONS = "{\n" + " \"_embedded\" : {\n"
|
||||
+ " \"generations\" : [ {\n" + " \"name\" : \"2.1.x\",\n"
|
||||
+ " \"generations\" : [ {\n" + " \"name\" : \"1.3.x\",\n"
|
||||
+ " \"initialReleaseDate\" : \"2019-01-01\",\n" + " \"ossSupportEndDate\" : \"2020-01-01\",\n"
|
||||
+ " \"commercialSupportEndDate\" : \"2021-01-01\",\n" + " \"_links\" : {\n"
|
||||
+ " \"self\" : {\n"
|
||||
+ " \"href\" : \"https://spring.io/api/projects/spring-boot/generations/2.1.x\"\n" + " },\n"
|
||||
+ " \"href\" : \"https://spring.io/api/projects/spring-boot/generations/1.3.x\"\n" + " },\n"
|
||||
+ " \"project\" : {\n" + " \"href\" : \"https://spring.io/api/projects/spring-boot\"\n"
|
||||
+ " }\n" + " }\n" + " }, {\n" + " \"name\" : \"2.2.x\",\n"
|
||||
+ " \"initialReleaseDate\" : \"2020-01-01\",\n" + " \"ossSupportEndDate\" : \"2021-01-01\",\n"
|
||||
|
||||
Reference in New Issue
Block a user