Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/org/apache/maven/plugins/ear/EarMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,8 @@ private List<String> createUnpackList() throws MojoExecutionException {
List<String> unpackTypesList = new ArrayList<>();
if (unpackTypes != null) {
unpackTypesList = Arrays.asList(unpackTypes.split(","));
unpackTypesList = new ArrayList<>(unpackTypesList);
unpackTypesList.removeIf(String::isEmpty);
for (String type : unpackTypesList) {
if (!EarModuleFactory.isStandardArtifactType(type)) {
throw new MojoExecutionException("Invalid type [" + type + "] supported types are "
Expand Down
20 changes: 20 additions & 0 deletions src/test/java/org/apache/maven/plugins/ear/EarMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
package org.apache.maven.plugins.ear;

import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.List;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
Expand All @@ -37,6 +40,17 @@ private File invokeGetEarFile(String finalName, String classifier) throws Except
return (File) method.invoke(null, tempDir.getAbsolutePath(), finalName, classifier);
}

@SuppressWarnings("unchecked")
private List<String> invokeCreateUnpackList(String unpackTypes) throws Exception {
EarMojo mojo = new EarMojo(null, null, null, null, null, null);
Field field = EarMojo.class.getDeclaredField("unpackTypes");
field.setAccessible(true);
field.set(mojo, unpackTypes);
Method method = EarMojo.class.getDeclaredMethod("createUnpackList");
method.setAccessible(true);
return (List<String>) method.invoke(mojo);
}

@Test
void testGetEarFileWithNullClassifier() throws Exception {
File result = invokeGetEarFile("myapp", null);
Expand All @@ -54,4 +68,10 @@ void testGetEarFileWithDashPrefixedClassifier() throws Exception {
File result = invokeGetEarFile("myapp", "-sources");
assertEquals(new File(tempDir, "myapp-sources.ear"), result);
}

@Test
void testCreateUnpackListIgnoresEmptyTypes() throws Exception {
assertEquals(Arrays.asList("jar", "war"), invokeCreateUnpackList("jar,war,"));
assertEquals(Arrays.asList("jar", "war"), invokeCreateUnpackList("jar,,war"));
}
}