Skip to content

Commit

Permalink
Merge pull request #401 from cherylking/warnEmptyFeature
Browse files Browse the repository at this point in the history
Issue warning for empty feature and remove from collection
  • Loading branch information
cherylking committed Jun 5, 2023
2 parents b3dccb0 + e91a409 commit 59bb5d9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -320,16 +320,20 @@ 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<String> combineToSet(Collection<String>... collections) {
public Set<String> combineToSet(Collection<String>... collections) {
Set<String> result = new HashSet<String>();
Set<String> lowercaseSet = new HashSet<String>();
for (Collection<String> collection : collections) {
if (collection != null) {
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.trim().isEmpty()) {
warn("An empty feature was specified in a server configuration file. Ensure that the features are valid.");
} else {
result.add(value);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public void testInstallFeatures() throws Exception {

@Test
public void testCombineToSet() throws Exception {
InstallFeatureUtil util = getNewInstallFeatureUtil();
Set<String> a = new HashSet<String>();
a.add("1");
a.add("2");
Expand All @@ -106,12 +107,13 @@ public void testCombineToSet() throws Exception {
List<String> c = new ArrayList<String>();
c.add("4");
c.add("5");
Set<String> result = InstallFeatureUtil.combineToSet(a, b, c);
Set<String> result = util.combineToSet(a, b, c);
assertEquals(5, result.size());
}

@Test
public void testCombineToSetCaseInsensitive() throws Exception {
InstallFeatureUtil util = getNewInstallFeatureUtil();
Set<String> a = new HashSet<String>();
a.add("mpconfig-1.3");
a.add("mpOpenAPI-1.0");
Expand All @@ -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<String> result = InstallFeatureUtil.combineToSet(a, b, c);
Set<String> result = util.combineToSet(a, b, c);
assertEquals(5, result.size());
assertTrue(result.contains("mpconfig-1.3"));
assertTrue(result.contains("mpOpenAPI-1.0"));
Expand Down

0 comments on commit 59bb5d9

Please sign in to comment.