chore: replace deprecated Version methods with updated API (#6678)

#### What type of PR is this?
/milestone 2.20.x
/area core

#### What this PR does / why we need it:
替换 Version 过时方法的引用为新 API

#### Does this PR introduce a user-facing change?
```release-note
None
```
pull/6686/head
guqing 2024-09-19 15:50:55 +08:00 committed by GitHub
parent dcadd38843
commit 1c31917778
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 10 additions and 10 deletions

View File

@ -476,7 +476,7 @@ public class PluginServiceImpl implements PluginService, InitializingBean, Dispo
Version version = systemVersion.get();
// validate the plugin version
// only use the nominal system version to compare, the format is like MAJOR.MINOR.PATCH
String systemVersion = version.getNormalVersion();
String systemVersion = version.toStableVersion().toString();
String requires = newPlugin.getSpec().getRequires();
if (!VersionUtils.satisfiesRequires(systemVersion, requires)) {
throw new UnsatisfiedAttributeValueException(String.format(

View File

@ -26,9 +26,9 @@ public class DefaultSystemVersionSupplier implements SystemVersionSupplier {
public Version get() {
var properties = buildProperties.getIfUnique();
if (properties == null) {
return Version.valueOf(DEFAULT_VERSION);
return Version.parse(DEFAULT_VERSION);
}
var projectVersion = Objects.toString(properties.getVersion(), DEFAULT_VERSION);
return Version.valueOf(projectVersion);
return Version.parse(projectVersion);
}
}

View File

@ -41,7 +41,7 @@ public class VersionUtils {
try {
return StringUtils.isBlank(constraint)
|| "*".equals(constraint)
|| Version.valueOf(version).satisfies(constraint);
|| Version.parse(version).satisfies(constraint);
} catch (Exception e) {
throw new ServerWebInputException("Illegal requires version expression.", null, e);
}

View File

@ -183,7 +183,7 @@ class PluginEndpointTest {
webClient = WebTestClient.bindToRouterFunction(endpoint.endpoint())
.build();
lenient().when(systemVersionSupplier.get()).thenReturn(Version.valueOf("0.0.0"));
lenient().when(systemVersionSupplier.get()).thenReturn(Version.parse("0.0.0"));
tempDirectory = Files.createTempDirectory("halo-test-plugin-upgrade-");
plugin002 = tempDirectory.resolve("plugin-0.0.2.jar");

View File

@ -74,7 +74,7 @@ class ThemeReconcilerTest {
@BeforeEach
void setUp() throws IOException {
defaultTheme = ResourceUtils.getFile("classpath:themes/default");
lenient().when(systemVersionSupplier.get()).thenReturn(Version.valueOf("0.0.0"));
lenient().when(systemVersionSupplier.get()).thenReturn(Version.parse("0.0.0"));
}
@Test
@ -190,7 +190,7 @@ class ThemeReconcilerTest {
@Test
void reconcileStatus() {
when(systemVersionSupplier.get()).thenReturn(Version.valueOf("2.3.0"));
when(systemVersionSupplier.get()).thenReturn(Version.parse("2.3.0"));
Path testWorkDir = tempDirectory.resolve("reconcile-delete");
when(themeRoot.get()).thenReturn(testWorkDir);

View File

@ -123,7 +123,7 @@ class PluginServiceImplTest {
getClass().getClassLoader().getResource("plugin/plugin-0.0.2")).toURI();
FileUtils.jar(Paths.get(fakePluingUri), tempDirectory.resolve("plugin-0.0.2.jar"));
lenient().when(systemVersionSupplier.get()).thenReturn(Version.valueOf("0.0.0"));
lenient().when(systemVersionSupplier.get()).thenReturn(Version.parse("0.0.0"));
}
@Test

View File

@ -78,7 +78,7 @@ class ThemeServiceImplTest {
// init the folder
Files.createDirectory(themeRoot.get());
lenient().when(systemVersionSupplier.get()).thenReturn(Version.valueOf("0.0.0"));
lenient().when(systemVersionSupplier.get()).thenReturn(Version.parse("0.0.0"));
}
@AfterEach

View File

@ -60,6 +60,6 @@ class DefaultSystemVersionSupplierTest {
when(buildPropertiesProvider.getIfUnique()).thenReturn(buildProperties);
version = systemVersionSupplier.get();
assertThat(version.toString()).isEqualTo("2.0.0-SNAPSHOT");
assertThat(version.getPreReleaseVersion()).isEqualTo("SNAPSHOT");
assertThat(version.preReleaseVersion().orElseThrow()).isEqualTo("SNAPSHOT");
}
}