This is an automated email from the ASF dual-hosted git repository. sjaranowski pushed a commit to branch rm-deprecated in repository https://gitbox.apache.org/repos/asf/maven-remote-resources-plugin.git
commit 05627f66427f71e617517840a7f1db8714bbedbb Author: Slawomir Jaranowski <s.jaranow...@gmail.com> AuthorDate: Thu Dec 19 00:12:51 2024 +0100 Avoid using deprecated API --- .../remote/AbstractProcessRemoteResourcesMojo.java | 46 +++++++--------------- .../remote/BundleRemoteResourcesMojo.java | 6 +-- 2 files changed, 18 insertions(+), 34 deletions(-) diff --git a/src/main/java/org/apache/maven/plugin/resources/remote/AbstractProcessRemoteResourcesMojo.java b/src/main/java/org/apache/maven/plugin/resources/remote/AbstractProcessRemoteResourcesMojo.java index 6767b0f..587d3f9 100644 --- a/src/main/java/org/apache/maven/plugin/resources/remote/AbstractProcessRemoteResourcesMojo.java +++ b/src/main/java/org/apache/maven/plugin/resources/remote/AbstractProcessRemoteResourcesMojo.java @@ -24,7 +24,6 @@ import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; -import java.io.InputStreamReader; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; @@ -33,6 +32,7 @@ import java.io.StringReader; import java.io.Writer; import java.net.MalformedURLException; import java.net.URL; +import java.nio.charset.Charset; import java.nio.file.Files; import java.time.Instant; import java.time.ZoneId; @@ -93,9 +93,7 @@ import org.codehaus.plexus.resource.ResourceManager; import org.codehaus.plexus.resource.loader.FileResourceLoader; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.IOUtil; -import org.codehaus.plexus.util.ReaderFactory; import org.codehaus.plexus.util.StringUtils; -import org.codehaus.plexus.util.WriterFactory; import org.codehaus.plexus.util.io.CachingOutputStream; import org.codehaus.plexus.util.xml.Xpp3Dom; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; @@ -395,8 +393,9 @@ public abstract class AbstractProcessRemoteResourcesMojo extends AbstractMojo { } if (encoding == null || encoding.isEmpty()) { - 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 = Charset.defaultCharset().name(); } if (resolveScopes == null) { @@ -510,8 +509,7 @@ public abstract class AbstractProcessRemoteResourcesMojo extends AbstractMojo { // add filters in well known order, least specific to most specific FilterArtifacts filter = new FilterArtifacts(); - Set<Artifact> artifacts = new LinkedHashSet<>(); - artifacts.addAll(getAllDependencies()); + Set<Artifact> artifacts = new LinkedHashSet<>(getAllDependencies()); if (this.excludeTransitive) { filter.addFilter(new ProjectTransitivityFilter(getDirectDependencies(), true)); } @@ -660,19 +658,11 @@ public abstract class AbstractProcessRemoteResourcesMojo extends AbstractMojo { } private Reader getReader(File source) throws IOException { - if (encoding != null) { - return new InputStreamReader(Files.newInputStream(source.toPath()), encoding); - } else { - return ReaderFactory.newPlatformReader(source); - } + return Files.newBufferedReader(source.toPath(), Charset.forName(encoding)); } private Writer getWriter(OutputStream os) throws IOException { - if (encoding != null) { - return new OutputStreamWriter(os, encoding); - } else { - return WriterFactory.newPlatformWriter(os); - } + return new OutputStreamWriter(os, encoding); } private MavenFileFilterRequest setupRequest(Resource resource, File source, File file) { @@ -685,9 +675,7 @@ public abstract class AbstractProcessRemoteResourcesMojo extends AbstractMojo { req.setMavenSession(mavenSession); req.setInjectProjectBuildFilters(true); - if (encoding != null) { - req.setEncoding(encoding); - } + req.setEncoding(encoding); if (filterDelimiters != null && !filterDelimiters.isEmpty()) { LinkedHashSet<String> delims = new LinkedHashSet<>(); @@ -918,16 +906,12 @@ public abstract class AbstractProcessRemoteResourcesMojo extends AbstractMojo { if (!copyResourceIfExists(f, projectResource, context)) { if (doVelocity) { try (CachingOutputStream os = new CachingOutputStream(f)) { - try (Writer writer = bundle.getSourceEncoding() == null - ? new OutputStreamWriter(os) - : new OutputStreamWriter(os, bundle.getSourceEncoding())) { - if (bundle.getSourceEncoding() == null) { - // TODO: Is this correct? Shouldn't we behave like the rest of maven and fail - // down to JVM default instead ISO-8859-1 ? - velocity.mergeTemplate(bundleResource, "ISO-8859-1", context, writer); - } else { - velocity.mergeTemplate(bundleResource, bundle.getSourceEncoding(), context, writer); - } + String bundleEncodeing = bundle.getSourceEncoding(); + if (bundleEncodeing == null) { + bundleEncodeing = encoding; + } + try (Writer writer = new OutputStreamWriter(os, bundleEncodeing)) { + velocity.mergeTemplate(bundleResource, bundleEncodeing, context, writer); } } } else { @@ -984,12 +968,12 @@ public abstract class AbstractProcessRemoteResourcesMojo extends AbstractMojo { String groupId = model.getGroupId(); String artifactId = model.getArtifactId(); - if (groupId == null || groupId.trim().equals("")) { + if (groupId == null || groupId.trim().isEmpty()) { throw new MojoExecutionException( "Supplemental project XML " + "requires that a <groupId> element be present."); } - if (artifactId == null || artifactId.trim().equals("")) { + if (artifactId == null || artifactId.trim().isEmpty()) { throw new MojoExecutionException( "Supplemental project XML " + "requires that a <artifactId> element be present."); } diff --git a/src/main/java/org/apache/maven/plugin/resources/remote/BundleRemoteResourcesMojo.java b/src/main/java/org/apache/maven/plugin/resources/remote/BundleRemoteResourcesMojo.java index 4007dca..d6af795 100644 --- a/src/main/java/org/apache/maven/plugin/resources/remote/BundleRemoteResourcesMojo.java +++ b/src/main/java/org/apache/maven/plugin/resources/remote/BundleRemoteResourcesMojo.java @@ -22,6 +22,7 @@ import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.Writer; +import java.nio.charset.Charset; import java.util.Arrays; import java.util.List; @@ -33,7 +34,6 @@ import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.codehaus.plexus.util.DirectoryScanner; import org.codehaus.plexus.util.FileUtils; -import org.codehaus.plexus.util.ReaderFactory; import org.codehaus.plexus.util.StringUtils; /** @@ -94,9 +94,9 @@ public class BundleRemoteResourcesMojo extends AbstractMojo { } if (sourceEncoding == null || sourceEncoding.isEmpty()) { - getLog().warn("sourceEncoding has not been set, using platform encoding " + ReaderFactory.FILE_ENCODING + getLog().warn("sourceEncoding has not been set, using platform encoding " + Charset.defaultCharset() + ", i.e. build is platform dependent!"); - sourceEncoding = ReaderFactory.FILE_ENCODING; + sourceEncoding = Charset.defaultCharset().name(); } // Look at the content of the resourcesDirectory and create a manifest of the files