Skip to content

Commit

Permalink
Avoid using deprecated API
Browse files Browse the repository at this point in the history
  • Loading branch information
slawekjaranowski committed Dec 18, 2024
1 parent 93a1e11 commit 05627f6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
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;
Expand All @@ -33,6 +32,7 @@
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;
Expand Down Expand Up @@ -93,9 +93,7 @@
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;
Expand Down Expand Up @@ -395,8 +393,9 @@ public void execute() throws MojoExecutionException {
}

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) {
Expand Down Expand Up @@ -510,8 +509,7 @@ protected List<MavenProject> getProjects() {
// 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));
}
Expand Down Expand Up @@ -660,19 +658,11 @@ protected boolean copyResourceIfExists(File file, String relFileName, VelocityCo
}

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) {
Expand All @@ -685,9 +675,7 @@ private MavenFileFilterRequest setupRequest(Resource resource, File source, File
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<>();
Expand Down Expand Up @@ -918,16 +906,12 @@ protected void processResourceBundles(ClassLoader classLoader, VelocityContext c
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 {
Expand Down Expand Up @@ -984,12 +968,12 @@ protected Model getSupplement(Xpp3Dom supplementModelXml) throws MojoExecutionEx
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.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
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;

Expand All @@ -33,7 +34,6 @@
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;

/**
Expand Down Expand Up @@ -94,9 +94,9 @@ public void execute() throws MojoExecutionException {
}

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
Expand Down

0 comments on commit 05627f6

Please sign in to comment.