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 2024/01/01 12:59:02 UTC

(maven-invoker-plugin) branch MINVOKER-352 created (now 84b2692)

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

khmarbaise pushed a change to branch MINVOKER-352
in repository https://gitbox.apache.org/repos/asf/maven-invoker-plugin.git


      at 84b2692  [MINVOKER-352] - Remove usage commons-lang3

This branch includes the following new commits:

     new 84b2692  [MINVOKER-352] - Remove usage commons-lang3

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.



(maven-invoker-plugin) 01/01: [MINVOKER-352] - Remove usage commons-lang3

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

khmarbaise pushed a commit to branch MINVOKER-352
in repository https://gitbox.apache.org/repos/asf/maven-invoker-plugin.git

commit 84b2692f66cadfb467166a2650199746eb39f8bb
Author: Karl Heinz Marbaise <kh...@apache.org>
AuthorDate: Mon Jan 1 13:58:53 2024 +0100

    [MINVOKER-352] - Remove usage commons-lang3
---
 pom.xml                                            |  5 -----
 .../maven/plugins/invoker/AbstractInvokerMojo.java | 13 ++++++-----
 .../maven/plugins/invoker/InvokerProperties.java   |  9 ++++----
 .../maven/plugins/invoker/SelectorUtils.java       | 25 ++++++++++++++--------
 4 files changed, 28 insertions(+), 24 deletions(-)

diff --git a/pom.xml b/pom.xml
index 65120e4..c40407d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -206,11 +206,6 @@ under the License.
       <scope>runtime</scope>
     </dependency>
 
-    <dependency>
-      <groupId>org.apache.commons</groupId>
-      <artifactId>commons-lang3</artifactId>
-      <version>3.12.0</version>
-    </dependency>
     <dependency>
       <groupId>org.codehaus.plexus</groupId>
       <artifactId>plexus-utils</artifactId>
diff --git a/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java b/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java
index 2632020..14ddb73 100644
--- a/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java
+++ b/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java
@@ -43,12 +43,12 @@ import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Properties;
 import java.util.Set;
 import java.util.TreeSet;
 import java.util.stream.Collectors;
 
-import org.apache.commons.lang3.StringUtils;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.execution.MavenSession;
 import org.apache.maven.model.Model;
@@ -1020,8 +1020,7 @@ public abstract class AbstractInvokerMojo extends AbstractMojo {
             String projectDir = pomFile.getParent();
 
             String parentPath = "../pom.xml";
-            if (model.getParent() != null
-                    && StringUtils.isNotEmpty(model.getParent().getRelativePath())) {
+            if (model.getParent() != null && isNotEmpty(model.getParent().getRelativePath())) {
                 parentPath = model.getParent().getRelativePath();
             }
             String parent = relativizePath(new File(projectDir, parentPath), projectsRoot);
@@ -1044,6 +1043,10 @@ public abstract class AbstractInvokerMojo extends AbstractMojo {
         }
     }
 
+    private boolean isNotEmpty(String s) {
+        return Objects.nonNull(s) && !s.isEmpty();
+    }
+
     /**
      * Copies the specified projects to the directory given by {@link #cloneProjectsTo}. A project may either be denoted
      * by a path to a POM file or merely by a path to a base directory. During cloning, the POM files will be filtered.
@@ -2031,7 +2034,7 @@ public abstract class AbstractInvokerMojo extends AbstractMojo {
 
     private List<String> calculateIncludes() {
         if (invokerTest != null) {
-            String[] testRegexes = StringUtils.split(invokerTest, ",");
+            String[] testRegexes = invokerTest.split(",+");
             return Arrays.stream(testRegexes)
                     .map(String::trim)
                     .filter(s -> !s.isEmpty())
@@ -2049,7 +2052,7 @@ public abstract class AbstractInvokerMojo extends AbstractMojo {
         List<String> excludes;
 
         if (invokerTest != null) {
-            String[] testRegexes = StringUtils.split(invokerTest, ",");
+            String[] testRegexes = invokerTest.split(",+");
             excludes = Arrays.stream(testRegexes)
                     .map(String::trim)
                     .filter(s -> !s.isEmpty())
diff --git a/src/main/java/org/apache/maven/plugins/invoker/InvokerProperties.java b/src/main/java/org/apache/maven/plugins/invoker/InvokerProperties.java
index a315c55..15e246d 100644
--- a/src/main/java/org/apache/maven/plugins/invoker/InvokerProperties.java
+++ b/src/main/java/org/apache/maven/plugins/invoker/InvokerProperties.java
@@ -31,7 +31,6 @@ import java.util.function.Consumer;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import org.apache.commons.lang3.StringUtils;
 import org.apache.maven.shared.invoker.InvocationRequest;
 
 /**
@@ -43,7 +42,7 @@ class InvokerProperties {
     private static final String SELECTOR_PREFIX = "selector.";
 
     private static final Pattern ENVIRONMENT_VARIABLES_PATTERN =
-            Pattern.compile("invoker\\.environmentVariables\\.([A-Za-z][^.]+)(\\.([0-9]+))?");
+            Pattern.compile("invoker\\.environmentVariables\\.([A-Za-z][^.]+)(\\.(\\d+))?");
 
     // default values from Mojo configuration
     private Boolean defaultDebug;
@@ -154,7 +153,7 @@ class InvokerProperties {
      * @param defaultMavenExecutable a default value
      */
     public void setDefaultMavenExecutable(String defaultMavenExecutable) {
-        if (StringUtils.isNotBlank(defaultMavenExecutable)) {
+        if (Objects.nonNull(defaultMavenExecutable) && !defaultMavenExecutable.isEmpty()) {
             this.defaultMavenExecutable = new File(defaultMavenExecutable);
         }
     }
@@ -397,7 +396,7 @@ class InvokerProperties {
         setIfNotNull(
                 request::setGoals,
                 get(InvocationProperty.GOALS, index)
-                        .map(s -> StringUtils.split(s, ", \t\n\r\f"))
+                        .map(s -> s.trim().split("\\s*[ ,]+\\s*"))
                         .map(Arrays::asList)
                         .filter(l -> !l.isEmpty())
                         .orElse(defaultGoals));
@@ -405,7 +404,7 @@ class InvokerProperties {
         setIfNotNull(
                 request::setProfiles,
                 get(InvocationProperty.PROFILES, index)
-                        .map(s -> StringUtils.split(s, ", \t\n\r\f"))
+                        .map(s -> s.trim().split("\\s*[ ,]+\\s*"))
                         .map(Arrays::asList)
                         .filter(l -> !l.isEmpty())
                         .orElse(defaultProfiles));
diff --git a/src/main/java/org/apache/maven/plugins/invoker/SelectorUtils.java b/src/main/java/org/apache/maven/plugins/invoker/SelectorUtils.java
index 5cba3f4..00b5400 100644
--- a/src/main/java/org/apache/maven/plugins/invoker/SelectorUtils.java
+++ b/src/main/java/org/apache/maven/plugins/invoker/SelectorUtils.java
@@ -29,10 +29,10 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Objects;
 import java.util.Properties;
 import java.util.stream.Collectors;
 
-import org.apache.commons.lang3.StringUtils;
 import org.apache.maven.plugins.invoker.AbstractInvokerMojo.ToolchainPrivateManager;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.toolchain.MisconfiguredToolchainException;
@@ -47,7 +47,11 @@ import org.codehaus.plexus.util.Os;
 class SelectorUtils {
 
     static void parseList(String list, Collection<String> includes, Collection<String> excludes) {
-        String[] tokens = (list != null) ? StringUtils.split(list, ",") : new String[0];
+        if (Objects.isNull(list)) {
+            return;
+        }
+
+        String[] tokens = list.split(",+");
 
         for (String token1 : tokens) {
             String token = token1.trim();
@@ -99,7 +103,8 @@ class SelectorUtils {
                     .getClassLoader()
                     .getResourceAsStream("META-INF/maven/org.apache.maven/maven-core/pom.properties"));
             // CHECKSTYLE_ON: LineLength
-            return StringUtils.trim(properties.getProperty("version"));
+            String str = properties.getProperty("version");
+            return str == null ? null : str.trim();
         } catch (Exception e) {
             return null;
         }
@@ -121,7 +126,8 @@ class SelectorUtils {
                 try (InputStream in = url.openStream()) {
                     Properties properties = new Properties();
                     properties.load(in);
-                    String version = StringUtils.trim(properties.getProperty("version"));
+                    String str = properties.getProperty("version");
+                    String version = str == null ? null : str.trim();
                     if (version != null) {
                         return version;
                     }
@@ -201,13 +207,14 @@ class SelectorUtils {
     }
 
     static List<Integer> parseVersion(String version) {
-        version = version.replaceAll("[^0-9]", ".");
-
-        String[] tokens = StringUtils.split(version, ".");
+        version = version.replaceAll("\\D", ".");
 
-        List<Integer> numbers = Arrays.stream(tokens).map(Integer::valueOf).collect(Collectors.toList());
+        String[] tokens = version.split("\\s*\\.+\\s*");
 
-        return numbers;
+        return Arrays.stream(tokens)
+                .filter(s -> !s.isEmpty())
+                .map(Integer::valueOf)
+                .collect(Collectors.toList());
     }
 
     static int compareVersions(List<Integer> version1, List<Integer> version2) {