Skip to content

Commit

Permalink
Issue #81. Handle implicit layers config file
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmiray authored and gunnarmorling committed Feb 2, 2021
1 parent 1b96781 commit 1951f74
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,17 @@ public static void launch(String... args) throws Exception {
URL propertiesFileUrl = toUrl(propertiesFile);

String layersConfig = arguments.getLayersConfig();
if (null == layersConfig || layersConfig.isEmpty()) {
layersConfig = resolveLayersConfigFile(basedir);
}
if (null == layersConfig) {
jCommander.getConsole()
.println("Missing --layers-config parameter or local file named layers" + getSupportedConfigFormats());
jCommander.getConsole().println("");
printUsage(jCommander);
return;
}

URL layersConfigUrl = toUrl(layersConfig);

if (null != layersConfigUrl) {
Expand Down Expand Up @@ -139,4 +150,22 @@ private static Set<String> getSupportedConfigFormats() {

return extensions;
}

private static String resolveLayersConfigFile(File basedir) {
if (basedir == null) {
basedir = new File(System.getProperty("user.dir"));
}

ServiceLoader<LayersConfigParser> parsers = ServiceLoader.load(LayersConfigParser.class,
LayrryLauncher.class.getClassLoader());

for (LayersConfigParser parser : parsers) {
File layersConfigFile = new File(basedir, "layers."+parser.getPreferredFileExtension());
if(layersConfigFile.exists()) {
return layersConfigFile.getAbsolutePath();
}
}

return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class Args {
@Parameter(description = "[arguments]")
private List<String> mainArgs = new ArrayList<>();

@Parameter(names = "--layers-config", required = true, description = "Layers configuration file. May be a local file or remote URL.")
@Parameter(names = "--layers-config", description = "Layers configuration file. May be a local file or remote URL.")
private String layersConfig;

@Parameter(names = "--properties", description = "Additional configuration properties. May be a local file or remote URL. Must use the Java properties format.")
Expand Down

0 comments on commit 1951f74

Please sign in to comment.