Skip to content

Commit

Permalink
remkop#2102 PropertiesDefaultProvider at first try to load properties…
Browse files Browse the repository at this point in the history
… from classpath
  • Loading branch information
Lumír Návrat committed Sep 5, 2023
1 parent 8e48885 commit 60f0bb8
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/main/java/picocli/CommandLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -18972,11 +18972,25 @@ private static Properties loadProperties(CommandSpec commandSpec) {
if (commandSpec == null) { return null; }
Properties p = System.getProperties();
for (String name : commandSpec.names()) {
String propertiesFileName = "." + name + ".properties";
String path = p.getProperty("picocli.defaults." + name + ".path");
File defaultPath = new File(p.getProperty("user.home"), "." + name + ".properties");
File defaultPath = new File(p.getProperty("user.home"), propertiesFileName);
File file = path == null ? defaultPath : new File(path);
if (file.canRead()) {
return createProperties(file, commandSpec);
} else {
URL resource = commandSpec.userObject().getClass().getClassLoader().getResource(propertiesFileName);
Tracer tracer = CommandLine.tracer();
if (resource != null) {
file = new File(resource.getFile());
if (file.canRead()) {
return createProperties(file, commandSpec);
} else {
tracer.warn("could not read defaults from %s", file.getAbsolutePath());
}
} else {
tracer.warn("defaults configuration file %s doesn not exists on classpath", propertiesFileName);
}
}
}
return loadProperties(commandSpec.parent());
Expand Down

0 comments on commit 60f0bb8

Please sign in to comment.