diff options
Diffstat (limited to 'main/src/main/java/org/onap/policy/pap/main/startstop/PapCommandLineArguments.java')
-rw-r--r-- | main/src/main/java/org/onap/policy/pap/main/startstop/PapCommandLineArguments.java | 57 |
1 files changed, 44 insertions, 13 deletions
diff --git a/main/src/main/java/org/onap/policy/pap/main/startstop/PapCommandLineArguments.java b/main/src/main/java/org/onap/policy/pap/main/startstop/PapCommandLineArguments.java index 78c2cc70..6d9c2f03 100644 --- a/main/src/main/java/org/onap/policy/pap/main/startstop/PapCommandLineArguments.java +++ b/main/src/main/java/org/onap/policy/pap/main/startstop/PapCommandLineArguments.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. - * Modifications Copyright (C) 2019 AT&T Intellectual Property. + * Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,7 +24,6 @@ package org.onap.policy.pap.main.startstop; import java.io.File; import java.io.PrintWriter; import java.io.StringWriter; -import java.net.URL; import java.util.Arrays; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.DefaultParser; @@ -49,6 +48,7 @@ public class PapCommandLineArguments { private final Options options; private String configurationFilePath = null; private String propertyFilePath = null; + private String groupFilePath = null; /** * Construct the options for the CLI editor. @@ -86,6 +86,15 @@ public class PapCommandLineArguments { .required(false) .type(String.class) .build()); + options.addOption(Option.builder("g") + .longOpt("groups-file") + .desc("the full path to the groups file to use, " + + "the groups file contains the group configuration") + .hasArg() + .argName("GROUP_FILE") + .required(false) + .type(String.class) + .build()); //@formatter:on } @@ -117,8 +126,9 @@ public class PapCommandLineArguments { // Clear all our arguments setConfigurationFilePath(null); setPropertyFilePath(null); + setGroupFilePath(null); - CommandLine commandLine = null; + CommandLine commandLine; try { commandLine = new DefaultParser().parse(options, args); } catch (final ParseException e) { @@ -132,10 +142,6 @@ public class PapCommandLineArguments { throw new PolicyPapException("too many command line arguments specified : " + Arrays.toString(args)); } - if (remainingArgs.length == 1) { - configurationFilePath = remainingArgs[0]; - } - if (commandLine.hasOption('h')) { return help(Main.class.getName()); } @@ -152,6 +158,10 @@ public class PapCommandLineArguments { setPropertyFilePath(commandLine.getOptionValue('p')); } + if (commandLine.hasOption('g')) { + setGroupFilePath(commandLine.getOptionValue('g')); + } + return null; } @@ -162,6 +172,9 @@ public class PapCommandLineArguments { */ public void validate() throws PolicyPapException { validateReadableFile("policy pap configuration", configurationFilePath); + if (groupFilePath != null) { + validateReadableFile("policy pap groups", groupFilePath); + } } /** @@ -180,9 +193,9 @@ public class PapCommandLineArguments { * @return the help string */ public String help(final String mainClassName) { - final HelpFormatter helpFormatter = new HelpFormatter(); - final StringWriter stringWriter = new StringWriter(); - final PrintWriter printWriter = new PrintWriter(stringWriter); + final var helpFormatter = new HelpFormatter(); + final var stringWriter = new StringWriter(); + final var printWriter = new PrintWriter(stringWriter); helpFormatter.printHelp(printWriter, HELP_LINE_LENGTH, mainClassName + " [options...]", "options", options, 0, 0, ""); @@ -265,6 +278,24 @@ public class PapCommandLineArguments { } /** + * Gets the group file path or the default file group resource if not present. + * + * @return the group file path + */ + public String getGroupFilePath() { + return groupFilePath; + } + + /** + * Sets the group file path. + * + * @param groupFilePath the property file path + */ + public void setGroupFilePath(final String groupFilePath) { + this.groupFilePath = groupFilePath; + } + + /** * Validate readable file. * * @param fileTag the file tag @@ -277,12 +308,12 @@ public class PapCommandLineArguments { } // The file name refers to a resource on the local file system - final URL fileUrl = ResourceUtils.getUrl4Resource(fileName); + final var fileUrl = ResourceUtils.getUrl4Resource(fileName); if (fileUrl == null) { throw new PolicyPapException(fileTag + FILE_MESSAGE_PREAMBLE + fileName + "\" does not exist"); } - final File theFile = new File(fileUrl.getPath()); + final var theFile = new File(fileUrl.getPath()); if (!theFile.exists()) { throw new PolicyPapException(fileTag + FILE_MESSAGE_PREAMBLE + fileName + "\" does not exist"); } @@ -290,7 +321,7 @@ public class PapCommandLineArguments { throw new PolicyPapException(fileTag + FILE_MESSAGE_PREAMBLE + fileName + "\" is not a normal file"); } if (!theFile.canRead()) { - throw new PolicyPapException(fileTag + FILE_MESSAGE_PREAMBLE + fileName + "\" is ureadable"); + throw new PolicyPapException(fileTag + FILE_MESSAGE_PREAMBLE + fileName + "\" is unreadable"); } } } |