Skip to content

Commit

Permalink
[release-2.16] Fix the problem that bundle files are not changed in d…
Browse files Browse the repository at this point in the history
…evelopment mode (#6077)

This is an automated cherry-pick of #6073

/assign guqing

```release-note
None
```
  • Loading branch information
halo-dev-bot authored Jun 13, 2024
1 parent 7b2c8e4 commit 6e1f0f3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Clock;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Comparator;
Expand Down Expand Up @@ -90,6 +91,8 @@ public class PluginServiceImpl implements PluginService, InitializingBean, Dispo

private final Scheduler scheduler = Schedulers.boundedElastic();

private Clock clock = Clock.systemUTC();

public PluginServiceImpl(ReactiveExtensionClient client, SystemVersionSupplier systemVersion,
PluginProperties pluginProperties, SpringPluginManager pluginManager) {
this.client = client;
Expand All @@ -101,6 +104,16 @@ public PluginServiceImpl(ReactiveExtensionClient client, SystemVersionSupplier s
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
public Flux<Plugin> getPresets() {
// list presets from classpath
Expand Down Expand Up @@ -269,6 +282,9 @@ public Flux<DataBuffer> uglifyCssBundle() {

@Override
public Mono<String> generateBundleVersion() {
if (pluginManager.isDevelopment()) {
return Mono.just(String.valueOf(clock.instant().toEpochMilli()));
}
return Flux.fromIterable(new ArrayList<>(pluginManager.getStartedPlugins()))
.sort(Comparator.comparing(PluginWrapper::getPluginId))
.map(pw -> pw.getPluginId() + ':' + pw.getDescriptor().getVersion())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Clock;
import java.time.Instant;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
Expand Down Expand Up @@ -249,7 +252,6 @@ void shouldReloadIfLoadLocationReady() {

}


@Test
void generateBundleVersionTest() {
var plugin1 = mock(PluginWrapper.class);
Expand Down Expand Up @@ -297,6 +299,19 @@ void generateBundleVersionTest() {
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
class PluginStateChangeTest {

Expand Down

0 comments on commit 6e1f0f3

Please sign in to comment.