Adjust tests for project version validation
This commit is contained in:
@@ -24,14 +24,14 @@ public class SpringProjectUtil {
|
||||
|
||||
public static final String SPRING_BOOT = "spring-boot";
|
||||
|
||||
private static final String VERION_PATTERN_STR = "(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)((\\.|-).+)?";
|
||||
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-]+)*))?";
|
||||
|
||||
public static final Logger log = LoggerFactory.getLogger(SpringProjectUtil.class);
|
||||
|
||||
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(VERION_PATTERN_STR);
|
||||
private static final Pattern VERSION = Pattern.compile(VERSION_PATTERN_STR);
|
||||
|
||||
private static final Pattern SPRING_NAME = Pattern.compile("([a-z]+)(-[a-z]+)*");
|
||||
|
||||
@@ -122,7 +122,7 @@ public class SpringProjectUtil {
|
||||
sb.append('^');
|
||||
sb.append(dependency);
|
||||
sb.append('-');
|
||||
sb.append(VERION_PATTERN_STR);
|
||||
sb.append(VERSION_PATTERN_STR);
|
||||
sb.append(".jar$");
|
||||
Pattern pattern = Pattern.compile(sb.toString());
|
||||
|
||||
@@ -132,9 +132,9 @@ public class SpringProjectUtil {
|
||||
String minor = matcher.group(2);
|
||||
String patch = matcher.group(3);
|
||||
String qualifier = null;
|
||||
if (matcher.group(4) != null && matcher.group(4).length() > 1) {
|
||||
qualifier = matcher.group(4).substring(1);
|
||||
}
|
||||
// if (matcher.group(4) != null && matcher.group(4).length() > 1) {
|
||||
qualifier = matcher.group(4);
|
||||
// }
|
||||
return new Version(
|
||||
Integer.parseInt(major),
|
||||
Integer.parseInt(minor),
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2021 Pivotal, Inc.
|
||||
* Copyright (c) 2021, 2022 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
|
||||
@@ -12,6 +12,7 @@ package org.springframework.ide.vscode.boot.validation.generations;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.springframework.ide.vscode.commons.java.SpringProjectUtil;
|
||||
|
||||
/**
|
||||
@@ -32,7 +33,7 @@ public class SpringVersionInfo {
|
||||
* @param file spring for dependency, e.g. spring-boot-2.4.0-M4.jar
|
||||
*/
|
||||
public SpringVersionInfo(File file) {
|
||||
String fileName = file.getName();
|
||||
String fileName = FilenameUtils.getBaseName(file.getName());
|
||||
this.slug = SpringProjectUtil.getProjectSlug(fileName);
|
||||
this.majMin = SpringProjectUtil.getMajMinVersion(fileName);
|
||||
this.fullVersion = SpringProjectUtil.getVersion(fileName);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2020 Pivotal, Inc.
|
||||
* Copyright (c) 2020, 2022 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
|
||||
@@ -16,7 +16,6 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.lsp4j.MessageType;
|
||||
@@ -88,7 +87,7 @@ public class ProjectGenerationsValidationTest {
|
||||
@Test
|
||||
public void testVersionParsing() throws Exception {
|
||||
String version = SpringProjectUtil.getVersion("spring-boot-starter-batch-2.3.0.RELEASE");
|
||||
assertEquals("2.3.0", version);
|
||||
assertEquals("2.3.0.RELEASE", version);
|
||||
|
||||
version = SpringProjectUtil.getVersion("spring-batch-core-2.4.0-M4");
|
||||
assertEquals("2.4.0-M4", version);
|
||||
@@ -97,7 +96,7 @@ public class ProjectGenerationsValidationTest {
|
||||
assertEquals("4.4.0-RC2", version);
|
||||
|
||||
version = SpringProjectUtil.getVersion("spring-integration-70.811.0.RELEASE");
|
||||
assertEquals("70.811.0", version);
|
||||
assertEquals("70.811.0.RELEASE", version);
|
||||
|
||||
version = SpringProjectUtil.getVersion("another-java-");
|
||||
assertNull(version);
|
||||
@@ -204,7 +203,7 @@ public class ProjectGenerationsValidationTest {
|
||||
assertNotNull(versionValidation != null);
|
||||
assertEquals(versionValidation.getMessageType(), MessageType.Warning);
|
||||
// Check that the message mentions the boot version of the project and the OSS support end date
|
||||
assertEquals("Using spring-boot version: 1.3.2 - OSS has ended on: 2020-01-01 - Commercial support has ended on: 2021-01-01", versionValidation.getMessage());
|
||||
assertEquals("Using spring-boot version: 1.3.2.RELEASE - OSS has ended on: 2020-01-01 - Commercial support has ended on: 2021-01-01", versionValidation.getMessage());
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user