Skip to content

Commit

Permalink
#2102 PropertiesDefaultProvider at first try to load properties from …
Browse files Browse the repository at this point in the history
…classpath
  • Loading branch information
Lumír Návrat authored and remkop committed Sep 18, 2023
1 parent d87528a commit a6c207f
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 a6c207f

Please sign in to comment.