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
Original file line number Diff line number Diff line change
Expand Up @@ -334,13 +334,15 @@ protected void startModuleElement(XMLWriter writer, Boolean generateId) {
// FIXME: Should we use the mapping using outputFileNameMapping instead
// of doing this on our own?
Artifact theArtifact = getArtifact();
String generatedId = theArtifact.getType().toUpperCase() + "_" + theArtifact.getGroupId() + "."
+ theArtifact.getArtifactId();
if (null != theArtifact.getClassifier()
&& !theArtifact.getClassifier().trim().isEmpty()) {
generatedId += "-" + theArtifact.getClassifier().trim();
if (theArtifact != null) {
String generatedId = theArtifact.getType().toUpperCase() + "_" + theArtifact.getGroupId() + "."
+ theArtifact.getArtifactId();
if (null != theArtifact.getClassifier()
&& !theArtifact.getClassifier().trim().isEmpty()) {
generatedId += "-" + theArtifact.getClassifier().trim();
}
writer.addAttribute("id", generatedId);
}
writer.addAttribute("id", generatedId);
}
}

Expand Down
24 changes: 24 additions & 0 deletions src/test/java/org/apache/maven/plugins/ear/EarModuleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@
*/
package org.apache.maven.plugins.ear;

import java.io.StringWriter;

import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
import org.codehaus.plexus.util.xml.XMLWriter;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;

/**
Expand All @@ -40,4 +46,22 @@ void testCleanArchivePath() {
assertEquals("", AbstractEarModule.cleanArchivePath(""));
assertNull(AbstractEarModule.cleanArchivePath(null));
}

@Test
void testStartModuleElementWithoutResolvedArtifact() {
StringWriter output = new StringWriter();
XMLWriter writer = new PrettyPrintXMLWriter(output);
TestableWebModule module = new TestableWebModule();

assertDoesNotThrow(() -> module.start(writer));
writer.endElement();

assertFalse(output.toString().contains("id="));
}

private static final class TestableWebModule extends WebModule {
void start(XMLWriter writer) {
startModuleElement(writer, true);
}
}
}