Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly monitor config for changes loaded from quarkus.config.locations #31556

Merged
merged 1 commit into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.io.IOException;
import java.lang.reflect.Modifier;
import java.net.URI;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -439,11 +440,20 @@ public void watchConfigFiles(BuildProducer<HotDeploymentWatchedFileBuildItem> wa
Optional<List<URI>> optionalLocations = config.getOptionalValues(SMALLRYE_CONFIG_LOCATIONS, URI.class);
optionalLocations.ifPresent(locations -> {
for (URI location : locations) {
Path path = location.getScheme() != null ? Paths.get(location) : Paths.get(location.getPath());
if (!Files.isDirectory(path)) {
configWatchedFiles.add(path.toString());
Path path = location.getScheme() != null && location.getScheme().equals("file") ? Paths.get(location)
: Paths.get(location.getPath());
if (Files.isRegularFile(path)) {
configWatchedFiles.add(path.toAbsolutePath().toString());
for (String profile : config.getProfiles()) {
configWatchedFiles.add(appendProfileToFilename(path, profile));
configWatchedFiles.add(appendProfileToFilename(path.toAbsolutePath(), profile));
}
} else if (Files.isDirectory(path)) {
try (DirectoryStream<Path> files = Files.newDirectoryStream(path, Files::isRegularFile)) {
for (Path file : files) {
configWatchedFiles.add(file.toAbsolutePath().toString());
}
} catch (IOException e) {
// Ignore
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import static org.hamcrest.core.Is.is;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.event.Observes;
Expand All @@ -26,6 +28,18 @@
import io.vertx.ext.web.Router;

public class AdditionalLocationsTest {
static final File additionalProperties;

static {
try {
additionalProperties = File.createTempFile("additional", "properties");
Files.write(additionalProperties.toPath(), "additional.property=1234".getBytes(StandardCharsets.UTF_8));
additionalProperties.deleteOnExit();
} catch (IOException e) {
throw new RuntimeException("Failed to create temporary file for " + AdditionalLocationsTest.class);
}
}

@RegisterExtension
static final QuarkusDevModeTest TEST = new QuarkusDevModeTest()
.setArchiveProducer(() -> {
Expand All @@ -36,9 +50,9 @@ public class AdditionalLocationsTest {

return ShrinkWrap.create(JavaArchive.class)
.addClasses(DevBean.class)
.addAsResource(new StringAsset(props + "\nquarkus.config.locations=additional.properties\n"),
"application.properties")
.addAsResource(new StringAsset("additional.property=1234\n"), "additional.properties");
.addAsResource(new StringAsset(
props + "\nquarkus.config.locations=" + additionalProperties.toURI() + "\n"),
"application.properties");
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand All @@ -50,7 +64,7 @@ static void beforeAll() {
}

@Test
void additionalLocations() {
void additionalLocations() throws Exception {
// A combination of QuarkusUnitTest and QuarkusProdModeTest tests ordering may mess with the port leaving it in
// 8081 and QuarkusDevModeTest does not changes to the right port.
RestAssured.port = -1;
Expand All @@ -59,7 +73,7 @@ void additionalLocations() {
.statusCode(200)
.body(is("1234"));

TEST.modifyResourceFile("additional.properties", s -> "additional.property=5678\n");
Files.write(additionalProperties.toPath(), "additional.property=5678".getBytes(StandardCharsets.UTF_8));

RestAssured.when().get("/config").then()
.statusCode(200)
Expand Down