mirror of https://github.com/halo-dev/halo
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
parent
dcadd38843
commit
1c31917778
|
@ -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(
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue