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 2019/12/15 04:27:06 UTC

[maven] 05/08: WIP - Continued.

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

khmarbaise pushed a commit to branch MNG-6825
in repository https://gitbox.apache.org/repos/asf/maven.git

commit 564dfb5487342f8a6330c27b1f26156cc599ab7d
Author: Karl Heinz Marbaise <kh...@apache.org>
AuthorDate: Sun Dec 15 00:16:31 2019 +0100

    WIP - Continued.
---
 maven-core/pom.xml                                 |  4 ++
 .../DefaultBeanConfigurationRequest.java           |  9 ++--
 .../rtinfo/internal/DefaultRuntimeInformation.java | 15 +++---
 .../org/apache/maven/cli/CLIReportingUtils.java    |  4 +-
 .../cli/transfer/ConsoleMavenTransferListener.java |  2 +-
 .../java/org/apache/maven/utils/Precondition.java  | 59 ++++++++++++++++------
 .../java/org/apache/maven/utils/StringUtils.java   | 53 +++++++++++++++++++
 7 files changed, 115 insertions(+), 31 deletions(-)

diff --git a/maven-core/pom.xml b/maven-core/pom.xml
index 8b70b27..b40dcc8 100644
--- a/maven-core/pom.xml
+++ b/maven-core/pom.xml
@@ -62,6 +62,10 @@ under the License.
     </dependency>
     <dependency>
       <groupId>org.apache.maven</groupId>
+      <artifactId>maven-utils</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
       <artifactId>maven-plugin-api</artifactId>
     </dependency>
     <dependency>
diff --git a/maven-core/src/main/java/org/apache/maven/configuration/DefaultBeanConfigurationRequest.java b/maven-core/src/main/java/org/apache/maven/configuration/DefaultBeanConfigurationRequest.java
index 5ec69f5..2b478f0 100644
--- a/maven-core/src/main/java/org/apache/maven/configuration/DefaultBeanConfigurationRequest.java
+++ b/maven-core/src/main/java/org/apache/maven/configuration/DefaultBeanConfigurationRequest.java
@@ -19,13 +19,12 @@ package org.apache.maven.configuration;
  * under the License.
  */
 
-import org.apache.commons.lang3.Validate;
 import org.apache.maven.model.Build;
 import org.apache.maven.model.Model;
 import org.apache.maven.model.Plugin;
 import org.apache.maven.model.PluginExecution;
 import org.apache.maven.model.PluginManagement;
-import org.codehaus.plexus.util.StringUtils;
+import org.apache.maven.utils.Precondition;
 
 /**
  * A basic bean configuration request.
@@ -100,7 +99,7 @@ public class DefaultBeanConfigurationRequest
         Plugin plugin = findPlugin( model, pluginGroupId, pluginArtifactId );
         if ( plugin != null )
         {
-            if ( StringUtils.isNotEmpty( pluginExecutionId ) )
+            if ( Precondition.isNotEmpty( pluginExecutionId ) )
             {
                 for ( PluginExecution execution : plugin.getExecutions() )
                 {
@@ -121,8 +120,8 @@ public class DefaultBeanConfigurationRequest
 
     private Plugin findPlugin( Model model, String groupId, String artifactId )
     {
-        Validate.notBlank( groupId, "groupId can neither be null, empty nor blank" );
-        Validate.notBlank( artifactId, "artifactId can neither be null, empty nor blank" );
+        Precondition.notBlank( groupId, "groupId can neither be null, empty nor blank" );
+        Precondition.notBlank( artifactId, "artifactId can neither be null, empty nor blank" );
 
         if ( model != null )
         {
diff --git a/maven-core/src/main/java/org/apache/maven/rtinfo/internal/DefaultRuntimeInformation.java b/maven-core/src/main/java/org/apache/maven/rtinfo/internal/DefaultRuntimeInformation.java
index 12a6b6f..b9abef8 100644
--- a/maven-core/src/main/java/org/apache/maven/rtinfo/internal/DefaultRuntimeInformation.java
+++ b/maven-core/src/main/java/org/apache/maven/rtinfo/internal/DefaultRuntimeInformation.java
@@ -19,9 +19,12 @@ package org.apache.maven.rtinfo.internal;
  * under the License.
  */
 
-import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.lang3.Validate;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
 import org.apache.maven.rtinfo.RuntimeInformation;
+import org.apache.maven.utils.Precondition;
 import org.codehaus.plexus.component.annotations.Component;
 import org.codehaus.plexus.component.annotations.Requirement;
 import org.codehaus.plexus.logging.Logger;
@@ -31,10 +34,6 @@ import org.eclipse.aether.version.Version;
 import org.eclipse.aether.version.VersionConstraint;
 import org.eclipse.aether.version.VersionScheme;
 
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Properties;
-
 /**
  * Provides information about the current Maven runtime.
  */
@@ -100,7 +99,7 @@ public class DefaultRuntimeInformation
     {
         VersionScheme versionScheme = new GenericVersionScheme();
 
-        Validate.notBlank( versionRange, "versionRange can neither be null, empty nor blank" );
+        Precondition.notBlank( versionRange, "versionRange can neither be null, empty nor blank" );
 
         VersionConstraint constraint;
         try
@@ -116,7 +115,7 @@ public class DefaultRuntimeInformation
         try
         {
             String mavenVersion = getMavenVersion();
-            Validate.validState( StringUtils.isNotEmpty( mavenVersion ), "Could not determine current Maven version" );
+            Precondition.isTrue(  Precondition.isNotEmpty( mavenVersion ), "Could not determine current Maven version" );
 
             current = versionScheme.parseVersion( mavenVersion );
         }
diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java b/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java
index bd5ca56..d322e88 100644
--- a/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java
+++ b/maven-embedder/src/main/java/org/apache/maven/cli/CLIReportingUtils.java
@@ -26,7 +26,7 @@ import java.util.Date;
 import java.util.Locale;
 import java.util.Properties;
 
-import org.apache.commons.lang3.StringUtils;
+import org.apache.maven.utils.Precondition;
 import org.codehaus.plexus.util.Os;
 import org.slf4j.Logger;
 
@@ -94,7 +94,7 @@ public final class CLIReportingUtils
         {
             msg += " (";
             msg += ( rev != null ? rev : "" );
-            if ( StringUtils.isNotBlank( timestamp ) )
+            if ( Precondition.isNotBlank( timestamp ) )
             {
                 String ts = formatTimestamp( Long.valueOf( timestamp ) );
                 msg += ( rev != null ? "; " : "" ) + ts;
diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/transfer/ConsoleMavenTransferListener.java b/maven-embedder/src/main/java/org/apache/maven/cli/transfer/ConsoleMavenTransferListener.java
index 1ad943b..e9195fb 100644
--- a/maven-embedder/src/main/java/org/apache/maven/cli/transfer/ConsoleMavenTransferListener.java
+++ b/maven-embedder/src/main/java/org/apache/maven/cli/transfer/ConsoleMavenTransferListener.java
@@ -26,7 +26,7 @@ import java.util.LinkedHashMap;
 import java.util.Locale;
 import java.util.Map;
 
-import org.apache.commons.lang3.StringUtils;
+import org.apache.maven.utils.StringUtils;
 import org.eclipse.aether.transfer.TransferCancelledException;
 import org.eclipse.aether.transfer.TransferEvent;
 import org.eclipse.aether.transfer.TransferResource;
diff --git a/maven-utils/src/main/java/org/apache/maven/utils/Precondition.java b/maven-utils/src/main/java/org/apache/maven/utils/Precondition.java
index 838975c..677d3fb 100644
--- a/maven-utils/src/main/java/org/apache/maven/utils/Precondition.java
+++ b/maven-utils/src/main/java/org/apache/maven/utils/Precondition.java
@@ -56,14 +56,6 @@ public final class Precondition
         throw new IllegalArgumentException( message );
     }
 
-    public static boolean isBlank(String str, String message)
-    {
-        if ( str == null || str.trim().isEmpty() )
-        {
-            return true;
-        }
-        return true;
-    }
     /**
      * assert that the given {@code obj} is not {@code null}.
      *
@@ -167,13 +159,13 @@ public final class Precondition
         return integerValue;
     }
 
-    /**
-     * assert that the given {@code str} is not {@code null} and not {@code empty}.
-     *
-     * @param str     The str which should not be {@code null} and not be empty.
-     * @param message The message for the exception in case of {@code null}.
-     * @return The supplied object as convenient.
-     */
+//    /**
+//     * assert that the given {@code str} is not {@code null} and not {@code empty}.
+//     *
+//     * @param str     The str which should not be {@code null} and not be empty.
+//     * @param message The message for the exception in case of {@code null}.
+//     * @return The supplied object as convenient.
+//     */
 //    public static String requireNotEmpty(String str, String message)
 //    {
 //        requireNotNull( str, message );
@@ -184,5 +176,42 @@ public final class Precondition
 //        return str;
 //    }
 
+
+    public static boolean isNotEmpty( String str )
+    {
+        return ( ( str != null ) && ( !str.isEmpty() ) );
+    }
+
+    public static boolean isNotBlank(final CharSequence cs) {
+        return !isBlank(cs);
+    }
+
+    public static boolean isBlank(final CharSequence cs) {
+        int strLen;
+        if (cs == null || (strLen = cs.length()) == 0) {
+            return true;
+        }
+        for (int i = 0; i < strLen; i++) {
+            if (!Character.isWhitespace(cs.charAt(i))) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    public static boolean isBlank(String str, String message)
+    {
+        if ( str == null || str.trim().isEmpty() )
+        {
+            return true;
+        }
+        return true;
+    }
+
+    public static boolean isEmpty(final CharSequence cs) {
+        return cs == null || cs.length() == 0;
+    }
+
+
 }
 
diff --git a/maven-utils/src/main/java/org/apache/maven/utils/StringUtils.java b/maven-utils/src/main/java/org/apache/maven/utils/StringUtils.java
new file mode 100644
index 0000000..ff3c6ae
--- /dev/null
+++ b/maven-utils/src/main/java/org/apache/maven/utils/StringUtils.java
@@ -0,0 +1,53 @@
+package org.apache.maven.utils;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apiguardian.api.API;
+
+import static org.apache.maven.utils.Precondition.isEmpty;
+import static org.apiguardian.api.API.Status.INTERNAL;
+
+@API( status = INTERNAL, since = "3.7.0" )
+public final class StringUtils
+{
+    private StringUtils()
+    {
+        // intentionally empty.
+    }
+
+    public static final String EMPTY = "";
+    public static final int INDEX_NOT_FOUND = -1;
+
+    public static String substringAfterLast(final String str, final String separator) {
+        if ( isEmpty(str)) {
+            return str;
+        }
+        if (isEmpty(separator)) {
+            return EMPTY;
+        }
+        final int pos = str.lastIndexOf(separator);
+        if (pos == INDEX_NOT_FOUND || pos == str.length() - separator.length()) {
+            return EMPTY;
+        }
+        return str.substring(pos + separator.length());
+    }
+
+
+}