summaryrefslogtreecommitdiffstats
path: root/auth/cli-editor
diff options
context:
space:
mode:
authorlapentafd <francesco.lapenta@est.tech>2021-05-27 10:18:49 +0100
committerlapentafd <francesco.lapenta@est.tech>2021-05-31 16:39:15 +0100
commitb6c674891e00f3bac43bd7b4fca06e7a87b8dd34 (patch)
tree35e0dfe7f60b01e651e1ad8741825419537855de /auth/cli-editor
parentc70c2179f1555e356794145956cbe32a3407e622 (diff)
Fix Sonar Issues on Apex-pdp
Changes made into cli-codegen, cli-editor, and core-engine Renamed one test class to match other test classes Issue-ID: POLICY-3093 Change-Id: Ib2d947782021590ffc08d426e7a1607a8c33f98a Signed-off-by: lapentafd <francesco.lapenta@est.tech>
Diffstat (limited to 'auth/cli-editor')
-rw-r--r--auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexCommandLineEditorMain.java12
-rw-r--r--auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexModelHandler.java15
-rw-r--r--auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexModelProperties.java9
-rw-r--r--auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineArgument.java6
-rw-r--r--auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineCommand.java8
-rw-r--r--auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorLoop.java29
-rw-r--r--auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineParameterParser.java6
-rw-r--r--auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineParameters.java4
-rw-r--r--auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineParser.java39
-rw-r--r--auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/KeywordNode.java8
-rw-r--r--auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaEditorMain.java8
-rw-r--r--auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaParameterParser.java7
-rw-r--r--auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/utils/CliUtils.java28
-rw-r--r--auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineCommandTest.java7
14 files changed, 93 insertions, 93 deletions
diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexCommandLineEditorMain.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexCommandLineEditorMain.java
index 9258b45b8..424f5853f 100644
--- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexCommandLineEditorMain.java
+++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexCommandLineEditorMain.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -61,7 +61,7 @@ public class ApexCommandLineEditorMain {
LOGGER.info(startMessage);
try {
- final CommandLineParameterParser parser = new CommandLineParameterParser();
+ final var parser = new CommandLineParameterParser();
parameters = parser.parse(args);
if (parameters.isHelpSet()) {
@@ -118,7 +118,7 @@ public class ApexCommandLineEditorMain {
return;
}
- String modelPropertiesString = "model properties are: " + apexModelProperties.toString();
+ var modelPropertiesString = "model properties are: " + apexModelProperties.toString();
LOGGER.debug(modelPropertiesString);
// Find the system commands
@@ -130,7 +130,7 @@ public class ApexCommandLineEditorMain {
}
// Read in the command hierarchy, this builds a tree of commands
- final KeywordNode rootKeywordNode = new KeywordNode("root");
+ final var rootKeywordNode = new KeywordNode("root");
for (final CommandLineCommand command : commands.getCommandSet()) {
rootKeywordNode.processKeywords(command.getKeywordlist(), command);
}
@@ -147,7 +147,7 @@ public class ApexCommandLineEditorMain {
return;
}
- final CommandLineEditorLoop cliEditorLoop = new CommandLineEditorLoop(apexModelProperties.getProperties(),
+ final var cliEditorLoop = new CommandLineEditorLoop(apexModelProperties.getProperties(),
modelHandler, rootKeywordNode);
try {
errorCount = cliEditorLoop.runLoop(parameters.getCommandInputStream(), parameters.getOutputStream(),
@@ -188,7 +188,7 @@ public class ApexCommandLineEditorMain {
* @param args the arguments
*/
public static void main(final String[] args) {
- final ApexCommandLineEditorMain cliEditor = new ApexCommandLineEditorMain(args);
+ final var cliEditor = new ApexCommandLineEditorMain(args);
// Only call system.exit on errors as it brings the JVM down
if (cliEditor.getErrorCount() > 0) {
diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexModelHandler.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexModelHandler.java
index 6814eab8c..896448b4f 100644
--- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexModelHandler.java
+++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexModelHandler.java
@@ -1,19 +1,20 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
@@ -79,13 +80,13 @@ public class ApexModelHandler {
public Result executeCommand(final CommandLineCommand command,
final SortedMap<String, CommandLineArgumentValue> argumentValues, final PrintWriter writer) {
// Get the method
- final Method apiMethod = getCommandMethod(command);
+ final var apiMethod = getCommandMethod(command);
// Get the method arguments
final Object[] parameterArray = getParameterArray(command, argumentValues, apiMethod);
try {
- final Object returnObject = apiMethod.invoke(apexModel, parameterArray);
+ final var returnObject = apiMethod.invoke(apexModel, parameterArray);
if (returnObject instanceof ApexApiResult) {
final ApexApiResult result = (ApexApiResult) returnObject;
@@ -146,9 +147,9 @@ public class ApexModelHandler {
*/
private Object[] getParameterArray(final CommandLineCommand command,
final SortedMap<String, CommandLineArgumentValue> argumentValues, final Method apiMethod) {
- final Object[] parameterArray = new Object[argumentValues.size()];
+ final var parameterArray = new Object[argumentValues.size()];
- int item = 0;
+ var item = 0;
try {
for (final Class<?> parametertype : apiMethod.getParameterTypes()) {
final String parameterValue = argumentValues.get(command.getArgumentList().get(item).getArgumentName())
diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexModelProperties.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexModelProperties.java
index 0e3cd0634..d618b159b 100644
--- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexModelProperties.java
+++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexModelProperties.java
@@ -1,19 +1,20 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
@@ -69,7 +70,7 @@ public class ApexModelProperties {
* @return the default properties
*/
public Properties getProperties() {
- final Properties properties = new Properties();
+ final var properties = new Properties();
// @formatter:off
properties.setProperty("DEFAULT_CONCEPT_VERSION", defaultConceptVersion);
properties.setProperty("DEFAULT_EVENT_NAMESPACE", defaultEventNamespace);
diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineArgument.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineArgument.java
index 48899baa6..772cd506e 100644
--- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineArgument.java
+++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineArgument.java
@@ -98,7 +98,7 @@ public class CommandLineArgument implements Comparable<CommandLineArgument> {
* @return the argument help
*/
public String getHelp() {
- final StringBuilder builder = new StringBuilder();
+ final var builder = new StringBuilder();
builder.append(argumentName);
builder.append(nullable ? ": (O) " : ": (M) ");
builder.append(description);
@@ -144,8 +144,8 @@ public class CommandLineArgument implements Comparable<CommandLineArgument> {
*/
@Override
public int hashCode() {
- final int prime = 31;
- int result = 1;
+ final var prime = 31;
+ var result = 1;
result = prime * result + ((argumentName == null) ? 0 : argumentName.hashCode());
result = prime * result + ((description == null) ? 0 : description.hashCode());
result = prime * result + (nullable ? 1231 : 1237);
diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineCommand.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineCommand.java
index beae65a06..37806af66 100644
--- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineCommand.java
+++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineCommand.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -166,7 +166,7 @@ public class CommandLineCommand implements Comparable<CommandLineCommand> {
* @return the help for this command
*/
public String getHelp() {
- final StringBuilder builder = new StringBuilder();
+ final var builder = new StringBuilder();
for (final String keyword : keywordlist) {
builder.append(keyword);
builder.append(' ');
@@ -255,8 +255,8 @@ public class CommandLineCommand implements Comparable<CommandLineCommand> {
*/
@Override
public int hashCode() {
- final int prime = 31;
- int result = 1;
+ final var prime = 31;
+ var result = 1;
result = prime * result + ((apiMethod == null) ? 0 : apiMethod.hashCode());
result = prime * result + argumentList.hashCode();
result = prime * result + ((description == null) ? 0 : description.hashCode());
diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorLoop.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorLoop.java
index 991257e6b..e198b663d 100644
--- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorLoop.java
+++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorLoop.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -105,11 +105,11 @@ public class CommandLineEditorLoop {
public int runLoop(final InputStream inputStream, final OutputStream outputStream,
final CommandLineParameters parameters) throws IOException {
// Readers and writers for input and output
- final BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
- final PrintWriter writer = new PrintWriter(new OutputStreamWriter(outputStream));
+ final var reader = new BufferedReader(new InputStreamReader(inputStream));
+ final var writer = new PrintWriter(new OutputStreamWriter(outputStream));
// The parser parses the input lines into commands and arguments
- final CommandLineParser parser = new CommandLineParser();
+ final var parser = new CommandLineParser();
// The execution status has the result of the latest command and a cumulative error count
MutablePair<Result, Integer> executionStatus = new MutablePair<>(Result.SUCCESS, 0);
@@ -122,7 +122,7 @@ public class CommandLineEditorLoop {
// Get the output model
if (!parameters.isSuppressModelOutput()) {
- final String modelString = modelHandler.writeModelToString(writer);
+ final var modelString = modelHandler.writeModelToString(writer);
if (parameters.checkSetOutputModelFileName()) {
TextFileUtils.putStringAsTextFile(modelString, parameters.getOutputModelFileName());
@@ -136,7 +136,6 @@ public class CommandLineEditorLoop {
if (!System.in.equals(inputStream)) {
reader.close();
}
-
if (!System.out.equals(outputStream) && !System.err.equals(outputStream)) {
writer.close();
}
@@ -236,7 +235,7 @@ public class CommandLineEditorLoop {
*/
private String readLogicBlock(final CommandLineParameters parameters, final BufferedReader reader,
final PrintWriter writer, MutablePair<Result, Integer> executionStatus) {
- StringBuilder logicBlock = new StringBuilder();
+ var logicBlock = new StringBuilder();
while (true) {
try {
@@ -277,7 +276,7 @@ public class CommandLineEditorLoop {
* @return A string with the prompt
*/
private String getPrompt() {
- final StringBuilder builder = new StringBuilder();
+ final var builder = new StringBuilder();
final Iterator<KeywordNode> keynodeDequeIter = keywordNodeDeque.descendingIterator();
while (keynodeDequeIter.hasNext()) {
@@ -300,11 +299,11 @@ public class CommandLineEditorLoop {
private CommandLineCommand findCommand(final List<String> commandWords) {
CommandLineCommand command = null;
- final KeywordNode startKeywordNode = keywordNodeDeque.peek();
+ final var startKeywordNode = keywordNodeDeque.peek();
// Go down through the keywords searching for the command
- for (int i = 0; i < commandWords.size(); i++) {
- final KeywordNode searchKeywordNode = keywordNodeDeque.peek();
+ for (var i = 0; i < commandWords.size(); i++) {
+ final var searchKeywordNode = keywordNodeDeque.peek();
// We have got to the arguments, time to stop looking
if (commandWords.get(i).indexOf('=') >= 0) {
@@ -330,7 +329,7 @@ public class CommandLineEditorLoop {
commandWords.set(i, foundNodeEntries.get(0).getKey());
// Check if there is a command
- final KeywordNode childKeywordNode = foundNodeEntries.get(0).getValue();
+ final var childKeywordNode = foundNodeEntries.get(0).getValue();
command = childKeywordNode.getCommand();
// If the command is null, we go into a sub mode, otherwise we unwind the stack of
@@ -538,8 +537,8 @@ public class CommandLineEditorLoop {
* @return the string
*/
private String stringAL2String(final List<String> stringArrayList) {
- final StringBuilder builder = new StringBuilder();
- boolean first = true;
+ final var builder = new StringBuilder();
+ var first = true;
for (final String word : stringArrayList) {
if (first) {
first = false;
@@ -564,7 +563,7 @@ public class CommandLineEditorLoop {
final int macroTagPos = line.indexOf(macroFileTag);
// Get the line before and after the macro tag
- final String lineBeforeMacroTag = line.substring(0, macroTagPos);
+ final var lineBeforeMacroTag = line.substring(0, macroTagPos);
final String lineAfterMacroTag = line.substring(macroTagPos + macroFileTag.length()).replaceAll("^\\s*", "");
// Get the file name that is the argument of the Macro tag
diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineParameterParser.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineParameterParser.java
index d630d89a5..912a2085e 100644
--- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineParameterParser.java
+++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineParameterParser.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -96,8 +96,8 @@ public class CommandLineParameterParser {
* @return the CLI parameters
*/
public CommandLineParameters parse(final String[] args) {
- CommandLine commandLine = parseDefault(args);
- final CommandLineParameters parameters = new CommandLineParameters();
+ var commandLine = parseDefault(args);
+ final var parameters = new CommandLineParameters();
parseSingleLetterOptions(commandLine, parameters);
parseDoubleLetterOptions(commandLine, parameters);
diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineParameters.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineParameters.java
index 9f0672bf1..111d56adb 100644
--- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineParameters.java
+++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineParameters.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -173,7 +173,7 @@ public class CommandLineParameters {
if (logFileName == null) {
return System.out;
} else {
- File logFile = new File(logFileName);
+ var logFile = new File(logFileName);
if (!logFile.getParentFile().exists()) {
logFile.getParentFile().mkdirs();
}
diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineParser.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineParser.java
index c9316cbd2..fcbf571ca 100644
--- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineParser.java
+++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineParser.java
@@ -79,9 +79,9 @@ public class CommandLineParser {
private ArrayList<String> mergeQuotes(final ArrayList<String> wordsSplitOnQuotes) {
final ArrayList<String> wordsWithQuotesMerged = new ArrayList<>();
- int loopWordIndex;
- for (int wordIndex = 0; wordIndex < wordsSplitOnQuotes.size(); wordIndex = loopWordIndex) {
- loopWordIndex = mergeQuote(wordsSplitOnQuotes, wordsWithQuotesMerged, wordIndex);
+ var wordIndex = 0;
+ while (wordIndex < wordsSplitOnQuotes.size()) {
+ wordIndex = mergeQuote(wordsSplitOnQuotes, wordsWithQuotesMerged, wordIndex);
}
return wordsWithQuotesMerged;
@@ -99,7 +99,7 @@ public class CommandLineParser {
int wordIndex) {
if ("\"".equals(wordsSplitOnQuotes.get(wordIndex))) {
- StringBuilder quotedWord = new StringBuilder(wordsSplitOnQuotes.get(wordIndex++));
+ var quotedWord = new StringBuilder(wordsSplitOnQuotes.get(wordIndex++));
for (; wordIndex < wordsSplitOnQuotes.size(); wordIndex++) {
quotedWord.append(wordsSplitOnQuotes.get(wordIndex));
@@ -108,7 +108,7 @@ public class CommandLineParser {
break;
}
}
- String quotedWordToString = quotedWord.toString();
+ var quotedWordToString = quotedWord.toString();
if (quotedWordToString.matches("^\".*\"$")) {
wordsWithQuotesMerged.add(quotedWordToString);
} else {
@@ -156,27 +156,26 @@ public class CommandLineParser {
private ArrayList<String> mergeEquals(final ArrayList<String> wordsSplitOnEquals) {
final ArrayList<String> wordsWithEqualsMerged = new ArrayList<>();
- int loopWordIndex;
- for (int wordIndex = 0; wordIndex < wordsSplitOnEquals.size(); wordIndex = loopWordIndex) {
- loopWordIndex = wordIndex;
+ var wordIndex = 0;
+ while (wordIndex < wordsSplitOnEquals.size()) {
// Is this a quoted word ?
- if (wordsSplitOnEquals.get(loopWordIndex).startsWith("\"")) {
- wordsWithEqualsMerged.add(wordsSplitOnEquals.get(loopWordIndex));
+ if (wordsSplitOnEquals.get(wordIndex).startsWith("\"")) {
+ wordsWithEqualsMerged.add(wordsSplitOnEquals.get(wordIndex));
continue;
}
- if ("=".equals(wordsSplitOnEquals.get(loopWordIndex))) {
- if (loopWordIndex < wordsSplitOnEquals.size() - 1
- && !wordsSplitOnEquals.get(loopWordIndex + 1).startsWith("=")) {
+ if ("=".equals(wordsSplitOnEquals.get(wordIndex))) {
+ if (wordIndex < wordsSplitOnEquals.size() - 1
+ && !wordsSplitOnEquals.get(wordIndex + 1).startsWith("=")) {
wordsWithEqualsMerged.add(
- wordsSplitOnEquals.get(loopWordIndex) + wordsSplitOnEquals.get(loopWordIndex + 1));
- loopWordIndex += 2;
+ wordsSplitOnEquals.get(wordIndex) + wordsSplitOnEquals.get(wordIndex + 1));
+ wordIndex += 2;
} else {
- wordsWithEqualsMerged.add(wordsSplitOnEquals.get(loopWordIndex++));
+ wordsWithEqualsMerged.add(wordsSplitOnEquals.get(wordIndex++));
}
} else {
- wordsWithEqualsMerged.add(wordsSplitOnEquals.get(loopWordIndex++));
+ wordsWithEqualsMerged.add(wordsSplitOnEquals.get(wordIndex++));
}
}
@@ -193,7 +192,7 @@ public class CommandLineParser {
private ArrayList<String> mergeArguments(final ArrayList<String> words) {
final ArrayList<String> mergedArguments = new ArrayList<>();
- for (int i = 0; i < words.size(); i++) {
+ for (var i = 0; i < words.size(); i++) {
// Is this a quoted word ?
if (words.get(i).startsWith("\"")) {
mergedArguments.add(words.get(i));
@@ -275,7 +274,7 @@ public class CommandLineParser {
private ArrayList<String> splitOnChar(final String line, final char splitChar) {
final ArrayList<String> wordsSplitOnQuotes = new ArrayList<>();
- int currentPos = 0;
+ var currentPos = 0;
while (currentPos != -1) {
final int quotePos = line.indexOf(splitChar, currentPos);
if (quotePos != -1) {
@@ -317,7 +316,7 @@ public class CommandLineParser {
}
// Now check that we have a sequence of commands at the beginning
- int currentWordPos = 0;
+ var currentWordPos = 0;
for (; currentWordPos < commandWords.size(); currentWordPos++) {
if (!commandWords.get(currentWordPos).matches("^[a-zA-Z0-9]*$")) {
break;
diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/KeywordNode.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/KeywordNode.java
index a2b15f50e..0a99eb067 100644
--- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/KeywordNode.java
+++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/KeywordNode.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -172,7 +172,7 @@ public class KeywordNode implements Comparable<KeywordNode> {
return this.hashCode() - otherKeywordNode.hashCode();
}
- final KeywordNode other = otherKeywordNode;
+ final var other = otherKeywordNode;
if (!keyword.equals(other.keyword)) {
return keyword.compareTo(other.keyword);
@@ -185,8 +185,8 @@ public class KeywordNode implements Comparable<KeywordNode> {
@Override
public int hashCode() {
- final int prime = 31;
- int result = 1;
+ final var prime = 31;
+ var result = 1;
result = prime * result + ((children == null) ? 0 : children.hashCode());
result = prime * result + ((command == null) ? 0 : command.hashCode());
result = prime * result + ((keyword == null) ? 0 : keyword.hashCode());
diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaEditorMain.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaEditorMain.java
index f5d6d31fd..1f2703daa 100644
--- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaEditorMain.java
+++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaEditorMain.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -52,10 +52,10 @@ public class ApexCliToscaEditorMain {
* @param args the command line arguments
*/
public ApexCliToscaEditorMain(final String[] args) {
- final String argumentString = Arrays.toString(args);
+ final var argumentString = Arrays.toString(args);
LOGGER.info("Starting Apex CLI Tosca editor with arguments - {}", argumentString);
- final ApexCliToscaParameterParser parser = new ApexCliToscaParameterParser();
+ final var parser = new ApexCliToscaParameterParser();
parameters = parser.parse(args);
if (parameters.isHelpSet()) {
CliUtils.help(ApexCliToscaEditorMain.class.getName(), parser.getOptions());
@@ -65,7 +65,7 @@ public class ApexCliToscaEditorMain {
String policyModelFilePath = null;
try {
- final File tempModelFile = File.createTempFile("policyModel", ".json");
+ final var tempModelFile = File.createTempFile("policyModel", ".json");
policyModelFilePath = tempModelFile.getAbsolutePath();
} catch (IOException e) {
LOGGER.error("Cannot create the policy model temp file.", e);
diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaParameterParser.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaParameterParser.java
index d5c66858f..5a35499c7 100644
--- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaParameterParser.java
+++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaParameterParser.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,7 +20,6 @@
package org.onap.policy.apex.auth.clieditor.tosca;
-import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Option;
import org.onap.policy.apex.auth.clieditor.CommandLineParameterParser;
@@ -54,8 +53,8 @@ public class ApexCliToscaParameterParser extends CommandLineParameterParser {
*/
@Override
public ApexCliToscaParameters parse(final String[] args) {
- CommandLine commandLine = parseDefault(args);
- final ApexCliToscaParameters parameters = new ApexCliToscaParameters();
+ var commandLine = parseDefault(args);
+ final var parameters = new ApexCliToscaParameters();
parseSingleLetterOptions(commandLine, parameters);
parseDoubleLetterOptions(commandLine, parameters);
diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/utils/CliUtils.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/utils/CliUtils.java
index a70439e10..22c541c3a 100644
--- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/utils/CliUtils.java
+++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/utils/CliUtils.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2020 Nordix Foundation.
+ * Copyright (C) 2019-2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -68,17 +68,17 @@ public class CliUtils {
*/
public static void createToscaServiceTemplate(ApexCliToscaParameters parameters, String policyModelFilePath)
throws IOException, CoderException {
- final StandardCoder standardCoder = new StandardCoder();
- String apexConfig = TextFileUtils.getTextFileAsString(parameters.getApexConfigFileName());
+ final var standardCoder = new StandardCoder();
+ var apexConfig = TextFileUtils.getTextFileAsString(parameters.getApexConfigFileName());
JsonObject apexConfigJson = standardCoder.decode(apexConfig, JsonObject.class);
- String policyModel = TextFileUtils.getTextFileAsString(policyModelFilePath);
+ var policyModel = TextFileUtils.getTextFileAsString(policyModelFilePath);
JsonObject policyModelJson = standardCoder.decode(policyModel, JsonObject.class);
- String toscaTemplate = TextFileUtils.getTextFileAsString(parameters.getInputToscaTemplateFileName());
+ var toscaTemplate = TextFileUtils.getTextFileAsString(parameters.getInputToscaTemplateFileName());
JsonObject toscaTemplateJson = standardCoder.decode(toscaTemplate, JsonObject.class);
- JsonObject toscaPolicyProperties = toscaTemplateJson.get("topology_template").getAsJsonObject();
- JsonObject toscaPolicy = toscaPolicyProperties.get("policies").getAsJsonArray().get(0).getAsJsonObject();
- JsonObject toscaProperties = toscaPolicy.get(toscaPolicy.keySet().toArray()[0].toString()).getAsJsonObject()
+ var toscaPolicyProperties = toscaTemplateJson.get("topology_template").getAsJsonObject();
+ var toscaPolicy = toscaPolicyProperties.get("policies").getAsJsonArray().get(0).getAsJsonObject();
+ var toscaProperties = toscaPolicy.get(toscaPolicy.keySet().toArray()[0].toString()).getAsJsonObject()
.get("properties").getAsJsonObject();
apexConfigJson.entrySet().forEach(entry -> {
@@ -87,7 +87,7 @@ public class CliUtils {
}
toscaProperties.add(entry.getKey(), entry.getValue());
});
- final String toscaPolicyString = standardCoder.encode(toscaTemplateJson);
+ final var toscaPolicyString = standardCoder.encode(toscaTemplateJson);
final String toscaPolicyFileName = parameters.getOutputToscaPolicyFileName();
if (StringUtils.isNotBlank(toscaPolicyFileName)) {
TextFileUtils.putStringAsTextFile(toscaPolicyString, toscaPolicyFileName);
@@ -106,7 +106,7 @@ public class CliUtils {
if (fileName == null) {
return;
}
- final File theFile = new File(fileName);
+ final var theFile = new File(fileName);
final String prefixExceptionMessage = "File " + fileName + OF_TYPE_TAG + fileTag;
if (!theFile.exists()) {
@@ -130,7 +130,7 @@ public class CliUtils {
if (fileName == null) {
return;
}
- final File theFile = new File(fileName);
+ final var theFile = new File(fileName);
final String prefixExceptionMessage = "File " + fileName + OF_TYPE_TAG + fileTag;
if (theFile.exists()) {
if (!theFile.isFile()) {
@@ -163,7 +163,7 @@ public class CliUtils {
if (directoryName == null) {
return;
}
- final File theDirectory = new File(directoryName);
+ final var theDirectory = new File(directoryName);
final String prefixExceptionMessage = "directory " + directoryName + OF_TYPE_TAG + directoryTag;
if (theDirectory.exists()) {
@@ -187,7 +187,7 @@ public class CliUtils {
* @param options the options for cli editor
*/
public static void help(final String mainClassName, Options options) {
- final HelpFormatter helpFormatter = new HelpFormatter();
+ final var helpFormatter = new HelpFormatter();
helpFormatter.printHelp(MAX_HELP_LINE_LENGTH, mainClassName + " [options...]", "options", options, "");
}
@@ -212,7 +212,7 @@ public class CliUtils {
pd = new PropertyDescriptor(entry.getValue().toString(), class1);
getter = pd.getReadMethod();
argValue = getter.invoke(parameters);
- String key = entry.getKey().toString();
+ var key = entry.getKey().toString();
if (argValue instanceof String && !key.equals("o")) {
cliArgsList.add("-" + key);
diff --git a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineCommandTest.java b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineCommandTest.java
index f05757fc8..15b2b98f3 100644
--- a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineCommandTest.java
+++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineCommandTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (c) 2020 Nordix Foundation.
+ * Copyright (c) 2020-2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@ package org.onap.policy.apex.auth.clieditor;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import java.util.List;
@@ -66,11 +67,11 @@ public class CommandLineCommandTest {
commandLineCommand.getApiMethodName();
}
- @Test(expected = CommandLineException.class)
+ @Test()
public void testInvalidApiMethod() {
commandLineCommand.setApiMethod("fail.");
assertEquals("fail.", commandLineCommand.getApiMethod());
- commandLineCommand.getApiMethodName();
+ assertThrows(CommandLineException.class, () -> commandLineCommand.getApiMethodName());
}
@Test