Skip to content

Commit

Permalink
[MPH-193] Document charset for evaluate goal file output
Browse files Browse the repository at this point in the history
This closes #123
  • Loading branch information
michael-o committed Oct 18, 2024
1 parent eb870cc commit 31a2678
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
import java.io.StringReader;
import java.io.StringWriter;
import java.io.Writer;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Properties;
import java.util.Set;

import org.codehaus.plexus.util.WriterFactory;
import org.codehaus.plexus.util.xml.XMLWriter;
import org.codehaus.plexus.util.xml.XmlWriterUtil;
import org.jdom2.Document;
Expand All @@ -49,7 +49,7 @@
*/
public abstract class AbstractEffectiveMojo extends AbstractHelpMojo {
/**
* Utility method to write an XML content in a given file.
* Utility method to write an XML content to a given file.
*
* @param output is the wanted output file.
* @param content contains the XML content to be written to the file.
Expand All @@ -62,7 +62,7 @@ protected static void writeXmlFile(File output, String content) throws IOExcepti
}

output.getParentFile().mkdirs();
try (Writer out = WriterFactory.newXmlWriter(output)) {
try (Writer out = Files.newBufferedWriter(output.toPath())) {
out.write(content);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.File;
import java.io.IOException;
import java.io.Writer;
import java.nio.file.Files;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.execution.MavenSession;
Expand All @@ -33,7 +34,6 @@
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuilder;
import org.apache.maven.project.ProjectBuildingRequest;
import org.codehaus.plexus.util.WriterFactory;
import org.eclipse.aether.RepositoryException;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
Expand Down Expand Up @@ -81,15 +81,16 @@ public abstract class AbstractHelpMojo extends AbstractMojo {
protected MavenSession session;

/**
* Optional parameter to write the output of this help in a given file, instead of writing to the console.
* Optional parameter to write the output of this help to a given file using UTF-8 encoding,
* instead of writing to the console.
* <br>
* <b>Note</b>: Could be a relative path.
*/
@Parameter(property = "output")
protected File output;

/**
* Utility method to write a content in a given file.
* Utility method to write a content to a given file.
*
* @param output is the wanted output file.
* @param content contains the content to be written to the file.
Expand All @@ -101,7 +102,7 @@ protected static void writeFile(File output, StringBuilder content) throws IOExc
}

/**
* Utility method to write a content in a given file.
* Utility method to write a content to a given file.
*
* @param output is the wanted output file.
* @param content contains the content to be written to the file.
Expand All @@ -113,7 +114,7 @@ protected static void writeFile(File output, String content) throws IOException
}

output.getParentFile().mkdirs();
try (Writer out = WriterFactory.newPlatformWriter(output)) {
try (Writer out = Files.newBufferedWriter(output.toPath())) {
out.write(content);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
// ----------------------------------------------------------------------

/**
* Method to write the Mojo description into the output file
* Method to write the Mojo description to the output file
*
* @param descriptionBuffer contains the description to be written to the file
* @throws MojoExecutionException if any
Expand Down

0 comments on commit 31a2678

Please sign in to comment.