Support system-dependent path separators

Update `StandardConfigDataLocationResolver` so that it recognizes
both `/` and `File.separator` suffixes as directories.

Prior to this commit, working with directories on Windows was awkward
since the path separator is `\`. If a directory were specified in the
form `c:\config\`, an exception was raised complaining it did not end
with '/'.

See gh-24490
pull/25947/head
mederel 4 years ago committed by Phillip Webb
parent 6ad100eae6
commit f918a46ea2

@ -26,6 +26,7 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.io.File;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@ -212,7 +213,7 @@ public class StandardConfigDataLocationResolver
} }
} }
throw new IllegalStateException("File extension is not known to any PropertySourceLoader. " throw new IllegalStateException("File extension is not known to any PropertySourceLoader. "
+ "If the location is meant to reference a directory, it must end in '/'"); + "If the location is meant to reference a directory, it must end in '/' or File.separator");
} }
private String getLoadableFileExtension(PropertySourceLoader loader, String file) { private String getLoadableFileExtension(PropertySourceLoader loader, String file) {
@ -225,7 +226,7 @@ public class StandardConfigDataLocationResolver
} }
private boolean isDirectory(String resourceLocation) { private boolean isDirectory(String resourceLocation) {
return resourceLocation.endsWith("/"); return resourceLocation.endsWith("/") || resourceLocation.endsWith(File.separator);
} }
private List<StandardConfigDataResource> resolve(Set<StandardConfigDataReference> references) { private List<StandardConfigDataResource> resolve(Set<StandardConfigDataReference> references) {

Loading…
Cancel
Save