mirror of https://github.com/halo-dev/halo
Fix the problem that bundle files are not changed in development mode (#6073)
#### What type of PR is this? /kind regression /area plugin /milestone 2.17.x #### What this PR does / why we need it: This PR reverts changes of generating bundle resource version in <https://github.com/halo-dev/halo/pull/6028>. Because the changes were adapted realtime change of bundle files for plugin developers in plugin development runtime mode, but I ignored it. #### Special notes for your reviewer: 1. Try to start Halo in plugin development mode 2. Change and rebuild ui resources 3. Refresh console and check the result #### Does this PR introduce a user-facing change? ```release-note None ```pull/6064/head^2
parent
b692db1f57
commit
ebf1a1fe1b
|
@ -14,6 +14,7 @@ import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.time.Clock;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
@ -90,6 +91,8 @@ public class PluginServiceImpl implements PluginService, InitializingBean, Dispo
|
||||||
|
|
||||||
private final Scheduler scheduler = Schedulers.boundedElastic();
|
private final Scheduler scheduler = Schedulers.boundedElastic();
|
||||||
|
|
||||||
|
private Clock clock = Clock.systemUTC();
|
||||||
|
|
||||||
public PluginServiceImpl(ReactiveExtensionClient client, SystemVersionSupplier systemVersion,
|
public PluginServiceImpl(ReactiveExtensionClient client, SystemVersionSupplier systemVersion,
|
||||||
PluginProperties pluginProperties, SpringPluginManager pluginManager) {
|
PluginProperties pluginProperties, SpringPluginManager pluginManager) {
|
||||||
this.client = client;
|
this.client = client;
|
||||||
|
@ -101,6 +104,16 @@ public class PluginServiceImpl implements PluginService, InitializingBean, Dispo
|
||||||
this.cssBundleCache = new BundleCache(".css");
|
this.cssBundleCache = new BundleCache(".css");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The method is only for testing.
|
||||||
|
*
|
||||||
|
* @param clock new clock
|
||||||
|
*/
|
||||||
|
void setClock(Clock clock) {
|
||||||
|
Assert.notNull(clock, "Clock must not be null");
|
||||||
|
this.clock = clock;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Flux<Plugin> getPresets() {
|
public Flux<Plugin> getPresets() {
|
||||||
// list presets from classpath
|
// list presets from classpath
|
||||||
|
@ -269,6 +282,9 @@ public class PluginServiceImpl implements PluginService, InitializingBean, Dispo
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mono<String> generateBundleVersion() {
|
public Mono<String> generateBundleVersion() {
|
||||||
|
if (pluginManager.isDevelopment()) {
|
||||||
|
return Mono.just(String.valueOf(clock.instant().toEpochMilli()));
|
||||||
|
}
|
||||||
return Flux.fromIterable(new ArrayList<>(pluginManager.getStartedPlugins()))
|
return Flux.fromIterable(new ArrayList<>(pluginManager.getStartedPlugins()))
|
||||||
.sort(Comparator.comparing(PluginWrapper::getPluginId))
|
.sort(Comparator.comparing(PluginWrapper::getPluginId))
|
||||||
.map(pw -> pw.getPluginId() + ':' + pw.getDescriptor().getVersion())
|
.map(pw -> pw.getPluginId() + ':' + pw.getDescriptor().getVersion())
|
||||||
|
|
|
@ -23,6 +23,9 @@ import java.net.URISyntaxException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.time.Clock;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.ZoneId;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
@ -249,7 +252,6 @@ class PluginServiceImplTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void generateBundleVersionTest() {
|
void generateBundleVersionTest() {
|
||||||
var plugin1 = mock(PluginWrapper.class);
|
var plugin1 = mock(PluginWrapper.class);
|
||||||
|
@ -297,6 +299,19 @@ class PluginServiceImplTest {
|
||||||
assertThat(result).isNotEqualTo(result2);
|
assertThat(result).isNotEqualTo(result2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void shouldGenerateRandomBundleVersionInDevelopment() {
|
||||||
|
var clock = Clock.fixed(Instant.now(), ZoneId.systemDefault());
|
||||||
|
pluginService.setClock(clock);
|
||||||
|
when(pluginManager.isDevelopment()).thenReturn(true);
|
||||||
|
pluginService.generateBundleVersion()
|
||||||
|
.as(StepVerifier::create)
|
||||||
|
.expectNext(String.valueOf(clock.instant().toEpochMilli()))
|
||||||
|
.verifyComplete();
|
||||||
|
|
||||||
|
verify(pluginManager, never()).getStartedPlugins();
|
||||||
|
}
|
||||||
|
|
||||||
@Nested
|
@Nested
|
||||||
class PluginStateChangeTest {
|
class PluginStateChangeTest {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue