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 @@ -38,7 +38,7 @@
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuilder;
import org.apache.maven.shared.utils.logging.MessageUtils;

Check warning on line 41 in src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-26.04 jdk-17-zulu 3.10.0

org.apache.maven.shared.utils.logging.MessageUtils in org.apache.maven.shared.utils.logging has been deprecated

Check warning on line 41 in src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java

View workflow job for this annotation

GitHub Actions / Verify / macos-latest jdk-25-zulu 4.0.0-rc-7

org.apache.maven.shared.utils.logging.MessageUtils in org.apache.maven.shared.utils.logging has been deprecated

Check warning on line 41 in src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java

View workflow job for this annotation

GitHub Actions / Verify / macos-latest jdk-25-zulu 3.10.0

org.apache.maven.shared.utils.logging.MessageUtils in org.apache.maven.shared.utils.logging has been deprecated

Check warning on line 41 in src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-26.04 jdk-8-zulu 3.10.0

org.apache.maven.shared.utils.logging.MessageUtils in org.apache.maven.shared.utils.logging has been deprecated

Check warning on line 41 in src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-26.04 jdk-21-zulu 3.10.0

org.apache.maven.shared.utils.logging.MessageUtils in org.apache.maven.shared.utils.logging has been deprecated

Check warning on line 41 in src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-26.04 jdk-21-zulu 4.0.0-rc-7

org.apache.maven.shared.utils.logging.MessageUtils in org.apache.maven.shared.utils.logging has been deprecated

Check warning on line 41 in src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-26.04 jdk-25-zulu 3.10.0

org.apache.maven.shared.utils.logging.MessageUtils in org.apache.maven.shared.utils.logging has been deprecated

Check warning on line 41 in src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-26.04 jdk-25-zulu 4.0.0-rc-7

org.apache.maven.shared.utils.logging.MessageUtils in org.apache.maven.shared.utils.logging has been deprecated
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
import org.codehaus.plexus.util.xml.XMLWriter;
Expand Down Expand Up @@ -107,7 +107,7 @@
}

StringWriter w = new StringWriter();
String encoding = output != null ? project.getModel().getModelEncoding() : System.getProperty("file.encoding");
String encoding = encodingOrDefault(project.getModel().getModelEncoding());
XMLWriter writer = new PrettyPrintXMLWriter(
w, StringUtils.repeat(" ", XmlWriterUtil.DEFAULT_INDENTATION_SIZE), encoding, null);

Expand Down Expand Up @@ -139,7 +139,7 @@

getLog().info("Effective-POM written to: " + output);
} else {
if (MessageUtils.isColorEnabled()) {

Check warning on line 142 in src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-26.04 jdk-17-zulu 3.10.0

org.apache.maven.shared.utils.logging.MessageUtils in org.apache.maven.shared.utils.logging has been deprecated

Check warning on line 142 in src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java

View workflow job for this annotation

GitHub Actions / Verify / macos-latest jdk-25-zulu 4.0.0-rc-7

org.apache.maven.shared.utils.logging.MessageUtils in org.apache.maven.shared.utils.logging has been deprecated

Check warning on line 142 in src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java

View workflow job for this annotation

GitHub Actions / Verify / macos-latest jdk-25-zulu 3.10.0

org.apache.maven.shared.utils.logging.MessageUtils in org.apache.maven.shared.utils.logging has been deprecated

Check warning on line 142 in src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-26.04 jdk-8-zulu 3.10.0

org.apache.maven.shared.utils.logging.MessageUtils in org.apache.maven.shared.utils.logging has been deprecated

Check warning on line 142 in src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-26.04 jdk-21-zulu 3.10.0

org.apache.maven.shared.utils.logging.MessageUtils in org.apache.maven.shared.utils.logging has been deprecated

Check warning on line 142 in src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-26.04 jdk-21-zulu 4.0.0-rc-7

org.apache.maven.shared.utils.logging.MessageUtils in org.apache.maven.shared.utils.logging has been deprecated

Check warning on line 142 in src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-26.04 jdk-25-zulu 3.10.0

org.apache.maven.shared.utils.logging.MessageUtils in org.apache.maven.shared.utils.logging has been deprecated

Check warning on line 142 in src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-26.04 jdk-25-zulu 4.0.0-rc-7

org.apache.maven.shared.utils.logging.MessageUtils in org.apache.maven.shared.utils.logging has been deprecated
// add color to comments
String comment = MessageUtils.buffer().project("<!--.-->").build();
int dotIndex = comment.indexOf(".");
Expand Down Expand Up @@ -213,6 +213,13 @@
pom.setProperties(properties);
}

static String encodingOrDefault(String encoding) {
if (encoding == null || encoding.isEmpty()) {
return "UTF-8";
}
return encoding;
}

private static class InputLocationStringFormatter extends InputLocation.StringFormatter {
@Override
public String toString(InputLocation location) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ void setup() throws IOException {

model.setProperties(originalProperties);

when(project.getModel()).thenReturn(model);

Path outputPath = Files.createTempFile(tempDir, "maven-help-plugin-test-", ".xml");
mavenSession.getUserProperties().setProperty("outputPath", outputPath.toString());
}
Expand All @@ -89,6 +87,7 @@ void testExecuteDoesNotModifyProjectModel(EffectivePomMojo mojo) throws Exceptio
Properties expectedProperties = new Properties();
expectedProperties.putAll(originalProperties);

when(project.getModel()).thenReturn(model);
setVariableValueToObject(mojo, "projects", Collections.singletonList(project));
setVariableValueToObject(mojo, "mojoExecution", mojoExecution);

Expand All @@ -104,4 +103,16 @@ void testExecuteDoesNotModifyProjectModel(EffectivePomMojo mojo) throws Exceptio
model.getProperties(),
"effective-pom must not modify the properties of the project model");
}

@Test
void encodingOrDefaultFallsBackToUtf8() {
assertEquals("UTF-8", EffectivePomMojo.encodingOrDefault(null));
assertEquals("UTF-8", EffectivePomMojo.encodingOrDefault(""));
}

@Test
void encodingOrDefaultKeepsExplicitValue() {
assertEquals("UTF-8", EffectivePomMojo.encodingOrDefault("UTF-8"));
assertEquals("ISO-8859-1", EffectivePomMojo.encodingOrDefault("ISO-8859-1"));
}
}
Loading