From 39857ea3be42b8f9fde826b4456d49d2da91f2fc Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Mon, 18 Nov 2024 12:14:42 +0000 Subject: [PATCH] Remove usages of deprecated ReaderFactory class (#339) --- .../javadoc/AbstractFixJavadocMojo.java | 32 ++++--------------- .../plugins/javadoc/AbstractJavadocMojo.java | 9 +++--- 2 files changed, 12 insertions(+), 29 deletions(-) diff --git a/src/main/java/org/apache/maven/plugins/javadoc/AbstractFixJavadocMojo.java b/src/main/java/org/apache/maven/plugins/javadoc/AbstractFixJavadocMojo.java index 506aa4ad..06331fd9 100644 --- a/src/main/java/org/apache/maven/plugins/javadoc/AbstractFixJavadocMojo.java +++ b/src/main/java/org/apache/maven/plugins/javadoc/AbstractFixJavadocMojo.java @@ -29,6 +29,9 @@ import java.net.URISyntaxException; import java.net.URL; import java.net.URLClassLoader; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; @@ -82,7 +85,6 @@ import org.codehaus.plexus.components.interactivity.InputHandler; import org.codehaus.plexus.languages.java.version.JavaVersion; import org.codehaus.plexus.util.FileUtils; -import org.codehaus.plexus.util.ReaderFactory; import org.codehaus.plexus.util.StringUtils; /** @@ -532,10 +534,10 @@ private void init() { // encoding if (encoding == null || encoding.isEmpty()) { if (getLog().isWarnEnabled()) { - getLog().warn("File encoding has not been set, using platform encoding " + ReaderFactory.FILE_ENCODING + getLog().warn("File encoding has not been set, using platform encoding " + Charset.defaultCharset() + ", i.e. build is platform dependent!"); } - encoding = ReaderFactory.FILE_ENCODING; + encoding = Charset.defaultCharset().name(); } // level @@ -689,13 +691,13 @@ private void parseClirrTextOutputFile(File clirrTextOutputFile) throws IOExcepti clirrNewClasses = new LinkedList<>(); clirrNewMethods = new LinkedHashMap<>(); - try (BufferedReader reader = new BufferedReader(ReaderFactory.newReader(clirrTextOutputFile, "UTF-8"))) { + try (BufferedReader reader = Files.newBufferedReader(clirrTextOutputFile.toPath(), StandardCharsets.UTF_8)) { for (String line = reader.readLine(); line != null; line = reader.readLine()) { String[] split = StringUtils.split(line, ":"); if (split.length != 4) { if (getLog().isDebugEnabled()) { - getLog().debug("Unable to parse the clirr line: " + line); + getLog().debug("Unable to parse the Clirr line: " + line); } continue; } @@ -2098,26 +2100,6 @@ private void appendDefaultSinceTag(final StringBuilder sb, final String indent) sb.append(EOL); } - /** - * @param sb not null - * @param indent not null - * @param separatorAdded - * @return true if separator has been added. - */ - private boolean appendDefaultVersionTag(final StringBuilder sb, final String indent, boolean separatorAdded) { - if (!fixTag(VERSION_TAG) || StringUtils.isEmpty(defaultVersion)) { - return separatorAdded; - } - - if (!separatorAdded) { - appendSeparator(sb, indent); - separatorAdded = true; - } - - appendDefaultVersionTag(sb, indent); - return separatorAdded; - } - /** * @param sb not null * @param indent not null diff --git a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java index 99fc31ff..98e70a8c 100644 --- a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java +++ b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java @@ -122,7 +122,6 @@ import org.codehaus.plexus.util.DirectoryScanner; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.IOUtil; -import org.codehaus.plexus.util.ReaderFactory; import org.codehaus.plexus.util.WriterFactory; import org.codehaus.plexus.util.cli.CommandLineException; import org.codehaus.plexus.util.cli.CommandLineUtils; @@ -1836,14 +1835,16 @@ private String getCharset() { * @return the docencoding attribute or UTF-8 if null. */ private String getDocencoding() { - return (docencoding == null || docencoding.isEmpty()) ? ReaderFactory.UTF_8 : docencoding; + return (docencoding == null || docencoding.isEmpty()) ? StandardCharsets.UTF_8.name() : docencoding; } /** * @return the encoding attribute or the value of file.encoding system property if null. */ private String getEncoding() { - return (encoding == null || encoding.isEmpty()) ? ReaderFactory.FILE_ENCODING : encoding; + return (encoding == null || encoding.isEmpty()) + ? Charset.defaultCharset().name() + : encoding; } @Override @@ -4596,7 +4597,7 @@ private void addJavadocOptions( if (encoding == null || encoding.isEmpty()) { getLog().warn("Source files encoding has not been set, using platform encoding " - + ReaderFactory.FILE_ENCODING + ", i.e. build is platform dependent!"); + + Charset.defaultCharset().name() + ", i.e. build is platform dependent!"); } addArgIfNotEmpty(arguments, "-encoding", JavadocUtil.quotedArgument(getEncoding()));