Skip to content

Commit

Permalink
Add ability to specify the output file name on the command line.
Browse files Browse the repository at this point in the history
This is required, in a maven multi-module setup, where relative path could point
to different files, when started as a parent or a sub-module build.
With this change, in the pom.xml you can specify --outputFile ${basedir}/validation.json
  • Loading branch information
gzsombor committed Apr 21, 2015
1 parent f944d20 commit 341aca7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ Example of Maven integration:
<arguments>
<argument>-cf</argument>
<argument>my-config.json</argument>
<argument>--outputFile</argument>
<argument>${basedir}/src/main/webapp/validation/validation.json</argument>
</configuration>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public static void main(String[] args) {
private static Options loadOptions(CommandLine cli) {
InputStream inputStream = null;
String configFile = cli.getOptionValue("cf");
String outputFile = cli.getOptionValue("outputFile");

try {
if (StringUtils.isEmpty(configFile)) {
Expand All @@ -72,7 +73,11 @@ private static Options loadOptions(CommandLine cli) {
System.out.println("Building parser configuration from configured file path '" + configFile + "'.");
inputStream = new FileInputStream(new File(configFile));
}
return new ObjectMapper().readValue(inputStream, Options.class);
Options opt = new ObjectMapper().readValue(inputStream, Options.class);
if (StringUtils.isEmpty(opt.getOutputFile())) {
opt.setOutputFile(outputFile);
}
return opt;
} catch (IOException e) {
throw new IllegalArgumentException("Cannot read config file.", e);
} finally {
Expand Down Expand Up @@ -110,6 +115,8 @@ private static org.apache.commons.cli.Options createCliOptions() {
org.apache.commons.cli.Options options = new org.apache.commons.cli.Options();
options.addOption(new Option("cf", true,
"path to JSON config file, if omitted valdr-bean-validation.json is " + "expected at root of class path"));
options.addOption(new Option("outputFile", true,
"path to output file, which will be used, if no outputFile is specified in the JSON config"));
return options;
}

Expand Down

0 comments on commit 341aca7

Please sign in to comment.