From 3f58c01124c286c8b78407013d2b6dc2f3041a75 Mon Sep 17 00:00:00 2001 From: Cheryl King Date: Mon, 5 Jun 2023 11:03:05 -0500 Subject: [PATCH 1/2] Issue warning for empty feature and remove from collection --- .../tools/common/plugins/util/InstallFeatureUtil.java | 10 +++++++--- .../common/plugins/util/InstallFeatureUtilTest.java | 6 ++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/java/io/openliberty/tools/common/plugins/util/InstallFeatureUtil.java b/src/main/java/io/openliberty/tools/common/plugins/util/InstallFeatureUtil.java index c5867143..7813c547 100644 --- a/src/main/java/io/openliberty/tools/common/plugins/util/InstallFeatureUtil.java +++ b/src/main/java/io/openliberty/tools/common/plugins/util/InstallFeatureUtil.java @@ -320,8 +320,7 @@ public abstract File downloadArtifact(String groupId, String artifactId, String * @param collections a collection of strings * @return the combined set of strings, ignoring case */ - @SafeVarargs - public static Set combineToSet(Collection... collections) { + public Set combineToSet(Collection... collections) { Set result = new HashSet(); Set lowercaseSet = new HashSet(); for (Collection collection : collections) { @@ -329,7 +328,12 @@ public static Set combineToSet(Collection... collections) { for (String value : collection) { if (!lowercaseSet.contains(value.toLowerCase())) { lowercaseSet.add(value.toLowerCase()); - result.add(value); + // if the value is empty or blank, issue a warning and do not add it to the list of features to install + if (value.isEmpty() || value.isBlank()) { + warn("An empty feature was specified in a server configuration file. Ensure that the features are valid."); + } else { + result.add(value); + } } } } diff --git a/src/test/java/io/openliberty/tools/common/plugins/util/InstallFeatureUtilTest.java b/src/test/java/io/openliberty/tools/common/plugins/util/InstallFeatureUtilTest.java index 21ecb2b0..24602c52 100644 --- a/src/test/java/io/openliberty/tools/common/plugins/util/InstallFeatureUtilTest.java +++ b/src/test/java/io/openliberty/tools/common/plugins/util/InstallFeatureUtilTest.java @@ -97,6 +97,7 @@ public void testInstallFeatures() throws Exception { @Test public void testCombineToSet() throws Exception { + InstallFeatureUtil util = getNewInstallFeatureUtil(); Set a = new HashSet(); a.add("1"); a.add("2"); @@ -106,12 +107,13 @@ public void testCombineToSet() throws Exception { List c = new ArrayList(); c.add("4"); c.add("5"); - Set result = InstallFeatureUtil.combineToSet(a, b, c); + Set result = util.combineToSet(a, b, c); assertEquals(5, result.size()); } @Test public void testCombineToSetCaseInsensitive() throws Exception { + InstallFeatureUtil util = getNewInstallFeatureUtil(); Set a = new HashSet(); a.add("mpconfig-1.3"); a.add("mpOpenAPI-1.0"); @@ -125,7 +127,7 @@ public void testCombineToSetCaseInsensitive() throws Exception { c.add("mpHealth-1.0"); c.add("ejblite-3.2"); c.add("EJBLITE-3.2"); - Set result = InstallFeatureUtil.combineToSet(a, b, c); + Set result = util.combineToSet(a, b, c); assertEquals(5, result.size()); assertTrue(result.contains("mpconfig-1.3")); assertTrue(result.contains("mpOpenAPI-1.0")); From e91a409999dca6c08ced95516ac4e7a42ae55290 Mon Sep 17 00:00:00 2001 From: Cheryl King Date: Mon, 5 Jun 2023 11:19:46 -0500 Subject: [PATCH 2/2] Remove Java 11 specific isBlank() method --- .../tools/common/plugins/util/InstallFeatureUtil.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/io/openliberty/tools/common/plugins/util/InstallFeatureUtil.java b/src/main/java/io/openliberty/tools/common/plugins/util/InstallFeatureUtil.java index 7813c547..d88ff826 100644 --- a/src/main/java/io/openliberty/tools/common/plugins/util/InstallFeatureUtil.java +++ b/src/main/java/io/openliberty/tools/common/plugins/util/InstallFeatureUtil.java @@ -329,7 +329,7 @@ public Set combineToSet(Collection... collections) { if (!lowercaseSet.contains(value.toLowerCase())) { lowercaseSet.add(value.toLowerCase()); // if the value is empty or blank, issue a warning and do not add it to the list of features to install - if (value.isEmpty() || value.isBlank()) { + if (value.isEmpty() || value.trim().isEmpty()) { warn("An empty feature was specified in a server configuration file. Ensure that the features are valid."); } else { result.add(value);