Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ private Set<Path> getFileRepo() {
}
Resource resource = this.resourceLoader.getResource(repositoryUri);
if (resource instanceof FileSystemResource || resource instanceof FileUrlResource) {
paths.add(Paths.get(resource.getURI()));
paths.add(resolvePath(resource));
}
}
return paths;
Expand All @@ -217,7 +217,7 @@ private Set<Path> getFileRepo() {
Resource resource = this.resourceLoader.getResource(path);
if (resource.exists()) {
try {
paths.add(Paths.get(resource.getURI()));
paths.add(resolvePath(resource));
}
catch (Exception e) {
log.error("Cannot resolve URI for path: " + path);
Expand All @@ -229,6 +229,13 @@ private Set<Path> getFileRepo() {
return null;
}

private Path resolvePath(Resource resource) throws IOException {
if (resource instanceof FileSystemResource || resource instanceof FileUrlResource) {
return resource.getFile().toPath().toAbsolutePath().normalize();
}
return Paths.get(resource.getURI());
}

private Set<File> filesFromEvents() {
Set<File> files = new LinkedHashSet<File>();
if (this.watcher == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

package org.springframework.cloud.config.monitor;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand All @@ -26,6 +28,7 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import org.springframework.cloud.config.server.environment.AbstractScmEnvironmentRepository;
import org.springframework.cloud.config.server.environment.JGitEnvironmentProperties;
Expand Down Expand Up @@ -54,6 +57,9 @@ public class FileMonitorConfigurationTest {

private List<AbstractScmEnvironmentRepository> repositories = new ArrayList<>();

@TempDir
private Path tempDir;

@BeforeEach
public void setup() {
fileMonitorConfiguration.setResourceLoader(new FileSystemResourceLoader());
Expand Down Expand Up @@ -89,6 +95,22 @@ public void testStart_withNativeEnvironmentRepository() {
assertOnDirectory(1);
}

@Test
public void testStart_withNativeEnvironmentRepositoryAndRelativeFileUri() throws Exception {
// given
Path relativeLocation = Paths.get("target", "file-monitor", tempDir.getFileName().toString(), "config.d");
Files.createDirectories(relativeLocation);
NativeEnvironmentRepository repository = createNativeEnvironmentRepository("file:" + relativeLocation);
ReflectionTestUtils.setField(fileMonitorConfiguration, "nativeEnvironmentRepository", repository);

// when
fileMonitorConfiguration.start();

// then
Set<Path> directory = getDirectory();
assertThat(directory).containsExactly(relativeLocation.toAbsolutePath());
}

@Test
public void testStart_withOneScmRepository() {
// given
Expand Down Expand Up @@ -203,9 +225,13 @@ private void addScmRepository(AbstractScmEnvironmentRepository... repository) {
}

private NativeEnvironmentRepository createNativeEnvironmentRepository() {
return createNativeEnvironmentRepository("classpath:pathsamples");
}

private NativeEnvironmentRepository createNativeEnvironmentRepository(String... searchLocations) {
ConfigurableEnvironment environment = createConfigurableEnvironment();
NativeEnvironmentProperties properties = new NativeEnvironmentProperties();
properties.setSearchLocations(new String[] { "classpath:pathsamples" });
properties.setSearchLocations(searchLocations);
return new NativeEnvironmentRepository(environment, properties, ObservationRegistry.NOOP);
}

Expand Down