You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by kh...@apache.org on 2023/11/05 17:34:11 UTC

(maven-dependency-plugin) branch code-improvements updated (213d2a44 -> d733b365)

This is an automated email from the ASF dual-hosted git repository.

khmarbaise pushed a change to branch code-improvements
in repository https://gitbox.apache.org/repos/asf/maven-dependency-plugin.git


    omit 213d2a44 Code Improvements  * using Files.newBufferedWriter(), Files.lines()  * using reader.lines().forEach()  * Removed inverse logic.  * Using StandardCharsets.UTF_8 instead of literal    texts.
     add 34348ece [MNG-6847] Use diamond operator
     add 4d18cfba [maven-release-plugin] prepare release maven-dependency-plugin-3.6.1
     add 4c898d78 [maven-release-plugin] prepare for next development iteration
     add fcdaf61c Bump org.jsoup:jsoup from 1.16.1 to 1.16.2 (#339)
     add 8a3ff132 Bump jettyVersion from 9.4.51.v20230217 to 9.4.53.v20231009 (#338)
     add 7ec0bda3 Bump resolverVersion from 1.0.0.v20140518 to 1.0.2.v20150114 (#329)
     add f45b26fb commons-io to 2.14.0 (#340)
     add 72488754 Assorted grammar nits on the home page (#345)
     add 9e920858 [MDEP-889] declare javax.inject explicitly (#343)
     add a56c4df2 [MDEP-888] Update used but undeclared commons-lang3 to 3.13.0 (#341)
     add 710a30f3 [MDEP-771] Remove broken 404 link (#344)
     add 3576dcb7 [MDEP-869] remove unused collections dependency (#342)
     add 69fdf929 remove executable flag
     add 416f7325 Bump org.codehaus.mojo:mrm-maven-plugin from 1.5.0 to 1.6.0 (#347)
     new d733b365 Code Improvements  * using Files.newBufferedWriter(), Files.lines()  * using reader.lines().forEach()  * Removed inverse logic.  * Using StandardCharsets.UTF_8 instead of literal    texts.

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (213d2a44)
            \
             N -- N -- N   refs/heads/code-improvements (d733b365)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 pom.xml                                            | 23 ++++++++-----
 .../tree/BuildingDependencyNodeVisitor.java        |  4 +--
 src/site/apt/index.apt.vm                          | 16 ++++-----
 .../fromDependencies/TestCopyDependenciesMojo.java | 30 ++++++++---------
 .../TestCopyDependenciesMojo2.java                 | 18 +++++-----
 .../TestUnpackDependenciesMojo.java                | 38 +++++++++++-----------
 .../resolvers/ResolveDependenciesMojoTest.java     |  2 +-
 .../unit/properties-test/plugin-config.xml         |  0
 8 files changed, 67 insertions(+), 64 deletions(-)
 mode change 100755 => 100644 src/test/resources/unit/properties-test/plugin-config.xml


(maven-dependency-plugin) 01/01: Code Improvements * using Files.newBufferedWriter(), Files.lines() * using reader.lines().forEach() * Removed inverse logic. * Using StandardCharsets.UTF_8 instead of literal texts.

Posted by kh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

khmarbaise pushed a commit to branch code-improvements
in repository https://gitbox.apache.org/repos/asf/maven-dependency-plugin.git

commit d733b365701ed4d1bae76dc1407904ee19b566cf
Author: Karl Heinz Marbaise <kh...@apache.org>
AuthorDate: Fri Aug 11 20:34:53 2023 +0200

    Code Improvements
     * using Files.newBufferedWriter(), Files.lines()
     * using reader.lines().forEach()
     * Removed inverse logic.
     * Using StandardCharsets.UTF_8 instead of literal
       texts.
---
 .../fromDependencies/BuildClasspathMojo.java       | 26 +++++++++-------------
 .../plugins/dependency/utils/DependencyUtil.java   | 24 +++++++-------------
 2 files changed, 18 insertions(+), 32 deletions(-)

diff --git a/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/BuildClasspathMojo.java b/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/BuildClasspathMojo.java
index 388c47c4..ab1c2689 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/BuildClasspathMojo.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/BuildClasspathMojo.java
@@ -18,15 +18,12 @@
  */
 package org.apache.maven.plugins.dependency.fromDependencies;
 
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
 import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
 import java.io.Writer;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
 import java.util.ArrayList;
 import java.util.Comparator;
 import java.util.Iterator;
@@ -35,6 +32,8 @@ import java.util.Objects;
 import java.util.Set;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 import org.apache.commons.lang3.StringUtils;
 import org.apache.maven.artifact.Artifact;
@@ -307,9 +306,8 @@ public class BuildClasspathMojo extends AbstractDependencyFilterMojo implements
         // make sure the parent path exists.
         out.getParentFile().mkdirs();
 
-        String encoding = Objects.toString(outputEncoding, "UTF-8");
-
-        try (Writer w = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(out), encoding))) {
+        String encoding = Objects.toString(outputEncoding, StandardCharsets.UTF_8.name());
+        try (Writer w = Files.newBufferedWriter(out.toPath(), Charset.forName(encoding))) {
             w.write(cpString);
             getLog().info("Wrote classpath file '" + out + "'.");
         } catch (IOException ex) {
@@ -333,15 +331,11 @@ public class BuildClasspathMojo extends AbstractDependencyFilterMojo implements
         if (!outputFile.isFile()) {
             return null;
         }
-        StringBuilder sb = new StringBuilder();
-        String encoding = Objects.toString(outputEncoding, "UTF-8");
 
-        try (BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(outputFile), encoding))) {
-            for (String line = r.readLine(); line != null; line = r.readLine()) {
-                sb.append(line);
-            }
+        String encoding = Objects.toString(outputEncoding, StandardCharsets.UTF_8.name());
 
-            return sb.toString();
+        try (Stream<String> lines = Files.lines(outputFile.toPath(), Charset.forName(encoding))) {
+            return lines.collect(Collectors.joining());
         }
     }
 
diff --git a/src/main/java/org/apache/maven/plugins/dependency/utils/DependencyUtil.java b/src/main/java/org/apache/maven/plugins/dependency/utils/DependencyUtil.java
index 0f58d1b2..dbb6a654 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/utils/DependencyUtil.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/utils/DependencyUtil.java
@@ -20,11 +20,11 @@ package org.apache.maven.plugins.dependency.utils;
 
 import java.io.BufferedReader;
 import java.io.File;
-import java.io.FileOutputStream;
 import java.io.IOException;
-import java.io.OutputStreamWriter;
 import java.io.StringReader;
 import java.io.Writer;
+import java.nio.charset.Charset;
+import java.nio.file.Files;
 import java.util.Objects;
 
 import org.apache.commons.lang3.StringUtils;
@@ -106,15 +106,13 @@ public final class DependencyUtil {
             destFileName.append(artifact.getGroupId()).append(".");
         }
 
-        String versionString;
+        String versionString = "";
         if (!removeVersion) {
             if (useBaseVersion) {
                 versionString = "-" + ArtifactUtils.toSnapshotVersion(artifact.getVersion());
             } else {
                 versionString = "-" + artifact.getVersion();
             }
-        } else {
-            versionString = "";
         }
 
         String classifierString = "";
@@ -227,9 +225,9 @@ public final class DependencyUtil {
      */
     public static synchronized void write(String string, File file, boolean append, String encoding)
             throws IOException {
-        file.getParentFile().mkdirs();
+        Files.createDirectories(file.getParentFile().toPath());
 
-        try (Writer writer = new OutputStreamWriter(new FileOutputStream(file, append), encoding)) {
+        try (Writer writer = Files.newBufferedWriter(file.toPath(), Charset.forName(encoding))) {
             writer.write(string);
         }
     }
@@ -242,15 +240,9 @@ public final class DependencyUtil {
      * @throws IOException if an I/O error occurs
      */
     public static synchronized void log(String string, Log log) throws IOException {
-        BufferedReader reader = new BufferedReader(new StringReader(string));
-
-        String line;
-
-        while ((line = reader.readLine()) != null) {
-            log.info(line);
+        try (BufferedReader reader = new BufferedReader(new StringReader(string))) {
+            reader.lines().forEach(log::info);
         }
-
-        reader.close();
     }
 
     /**
@@ -273,7 +265,7 @@ public final class DependencyUtil {
         String ret = "";
         if (!(str == null || str.isEmpty())) {
             // remove initial and ending spaces, plus all spaces next to commas
-            ret = str.trim().replaceAll("[\\s]*,[\\s]*", ",");
+            ret = str.trim().replaceAll("\\s*,\\s*", ",");
         }
 
         return ret;