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 03:09:47 UTC

[maven] 04/07: 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 66aeaf658f8328945ba20ae2eff662cf635d5d06
Author: Karl Heinz Marbaise <kh...@apache.org>
AuthorDate: Sat Dec 14 23:53:25 2019 +0100

    continued.
---
 .../org/apache/maven/artifact/ArtifactUtils.java   |  14 +-
 maven-embedder/pom.xml                             |   4 +
 .../org/apache/maven/cli/CLIReportingUtils.java    |   4 +-
 .../transfer/AbstractMavenTransferListener.java    | 146 +++++++++++----------
 maven-utils/pom.xml                                |  12 +-
 .../java/org/apache/maven/utils/Precondition.java  |  35 ++++-
 pom.xml                                            |   5 +
 7 files changed, 131 insertions(+), 89 deletions(-)

diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java b/maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java
index bd76edd..da17f7b 100644
--- a/maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java
+++ b/maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java
@@ -26,8 +26,8 @@ import java.util.List;
 import java.util.Map;
 import java.util.regex.Matcher;
 
-import org.apache.commons.lang3.Validate;
 import org.apache.maven.artifact.versioning.VersionRange;
+import org.apache.maven.utils.Precondition;
 
 /**
  * ArtifactUtils
@@ -40,7 +40,7 @@ public final class ArtifactUtils
         if ( version != null )
         {
             if ( version.regionMatches( true, version.length() - Artifact.SNAPSHOT_VERSION.length(),
-                                        Artifact.SNAPSHOT_VERSION, 0, Artifact.SNAPSHOT_VERSION.length() ) )
+                    Artifact.SNAPSHOT_VERSION, 0, Artifact.SNAPSHOT_VERSION.length() ) )
             {
                 return true;
             }
@@ -104,7 +104,7 @@ public final class ArtifactUtils
         int c = str != null && str.length() > 0 ? str.charAt( 0 ) : 0;
         if ( ( c < '0' || c > '9' ) && ( c < 'a' || c > 'z' ) )
         {
-            Validate.notBlank( str, message );
+            Precondition.notBlank( str, message );
         }
     }
 
@@ -153,8 +153,8 @@ public final class ArtifactUtils
         }
 
         DefaultArtifact clone = new DefaultArtifact( artifact.getGroupId(), artifact.getArtifactId(), range,
-            artifact.getScope(), artifact.getType(), artifact.getClassifier(),
-            artifact.getArtifactHandler(), artifact.isOptional() );
+                artifact.getScope(), artifact.getType(), artifact.getClassifier(), artifact.getArtifactHandler(),
+                artifact.isOptional() );
         clone.setRelease( artifact.isRelease() );
         clone.setResolvedVersion( artifact.getVersion() );
         clone.setResolved( artifact.isResolved() );
@@ -173,7 +173,9 @@ public final class ArtifactUtils
         return clone;
     }
 
-    /** Returns <code>to</code> collection */
+    /**
+     * Returns <code>to</code> collection
+     */
     public static <T extends Collection<Artifact>> T copyArtifacts( Collection<Artifact> from, T to )
     {
         for ( Artifact artifact : from )
diff --git a/maven-embedder/pom.xml b/maven-embedder/pom.xml
index 235ae62..ef53d2b 100644
--- a/maven-embedder/pom.xml
+++ b/maven-embedder/pom.xml
@@ -171,6 +171,10 @@ under the License.
       <artifactId>jansi</artifactId>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-utils</artifactId>
+    </dependency>
   </dependencies>
 
   <build>
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 d562c88..bd5ca56 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
@@ -19,8 +19,6 @@ package org.apache.maven.cli;
  * under the License.
  */
 
-import static org.apache.maven.shared.utils.logging.MessageUtils.buffer;
-
 import java.io.IOException;
 import java.io.InputStream;
 import java.text.SimpleDateFormat;
@@ -32,6 +30,8 @@ import org.apache.commons.lang3.StringUtils;
 import org.codehaus.plexus.util.Os;
 import org.slf4j.Logger;
 
+import static org.apache.maven.shared.utils.logging.MessageUtils.buffer;
+
 /**
  * Utility class used to report errors, statistics, application version info, etc.
  *
diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/transfer/AbstractMavenTransferListener.java b/maven-embedder/src/main/java/org/apache/maven/cli/transfer/AbstractMavenTransferListener.java
index 984902e..fa4ec3e 100644
--- a/maven-embedder/src/main/java/org/apache/maven/cli/transfer/AbstractMavenTransferListener.java
+++ b/maven-embedder/src/main/java/org/apache/maven/cli/transfer/AbstractMavenTransferListener.java
@@ -24,7 +24,7 @@ import java.text.DecimalFormat;
 import java.text.DecimalFormatSymbols;
 import java.util.Locale;
 
-import org.apache.commons.lang3.Validate;
+import org.apache.maven.utils.Precondition;
 import org.eclipse.aether.transfer.AbstractTransferListener;
 import org.eclipse.aether.transfer.TransferCancelledException;
 import org.eclipse.aether.transfer.TransferEvent;
@@ -33,20 +33,19 @@ import org.eclipse.aether.transfer.TransferResource;
 /**
  * AbstractMavenTransferListener
  */
-public abstract class AbstractMavenTransferListener
-    extends AbstractTransferListener
+public abstract class AbstractMavenTransferListener extends AbstractTransferListener
 {
 
     // CHECKSTYLE_OFF: LineLength
+
     /**
-     * Formats file size with the associated <a href="https://en.wikipedia.org/wiki/Metric_prefix">SI</a> prefix
-     * (GB, MB, kB) and using the patterns <code>#0.0</code> for numbers between 1 and 10
-     * and <code>###0</code> for numbers between 10 and 1000+ by default.
+     * Formats file size with the associated <a href="https://en.wikipedia.org/wiki/Metric_prefix">SI</a> prefix (GB,
+     * MB, kB) and using the patterns <code>#0.0</code> for numbers between 1 and 10 and <code>###0</code> for numbers
+     * between 10 and 1000+ by default.
      *
      * @see <a href="https://en.wikipedia.org/wiki/Metric_prefix">https://en.wikipedia.org/wiki/Metric_prefix</a>
      * @see <a href="https://en.wikipedia.org/wiki/Binary_prefix">https://en.wikipedia.org/wiki/Binary_prefix</a>
-     * @see <a
-     *      href="https://en.wikipedia.org/wiki/Octet_%28computing%29">https://en.wikipedia.org/wiki/Octet_(computing)</a>
+     * @see <a href="https://en.wikipedia.org/wiki/Octet_%28computing%29">https://en.wikipedia.org/wiki/Octet_(computing)</a>
      */
     // CHECKSTYLE_ON: LineLength
     // TODO Move me to Maven Shared Utils
@@ -55,68 +54,67 @@ public abstract class AbstractMavenTransferListener
         enum ScaleUnit
         {
             BYTE
-            {
-                @Override
-                public long bytes()
-                {
-                    return 1L;
-                }
-
-                @Override
-                public String symbol()
-                {
-                    return "B";
-                }
-            },
+                    {
+                        @Override
+                        public long bytes()
+                        {
+                            return 1L;
+                        }
+
+                        @Override
+                        public String symbol()
+                        {
+                            return "B";
+                        }
+                    },
             KILOBYTE
-            {
-                @Override
-                public long bytes()
-                {
-                    return 1000L;
-                }
-
-                @Override
-                public String symbol()
-                {
-                    return "kB";
-                }
-            },
+                    {
+                        @Override
+                        public long bytes()
+                        {
+                            return 1000L;
+                        }
+
+                        @Override
+                        public String symbol()
+                        {
+                            return "kB";
+                        }
+                    },
             MEGABYTE
-            {
-                @Override
-                public long bytes()
-                {
-                    return KILOBYTE.bytes() * KILOBYTE.bytes();
-                }
-
-                @Override
-                public String symbol()
-                {
-                    return "MB";
-                }
-            },
+                    {
+                        @Override
+                        public long bytes()
+                        {
+                            return KILOBYTE.bytes() * KILOBYTE.bytes();
+                        }
+
+                        @Override
+                        public String symbol()
+                        {
+                            return "MB";
+                        }
+                    },
             GIGABYTE
-            {
-                @Override
-                public long bytes()
-                {
-                    return MEGABYTE.bytes() * KILOBYTE.bytes();
-                };
-
-                @Override
-                public String symbol()
-                {
-                    return "GB";
-                }
-            };
-
-            public abstract long bytes();
-            public abstract String symbol();
+                    {
+                        @Override
+                        public long bytes()
+                        {
+                            return MEGABYTE.bytes() * KILOBYTE.bytes();
+                        }
+
+                        ;
+
+                        @Override
+                        public String symbol()
+                        {
+                            return "GB";
+                        }
+                    };
 
             public static ScaleUnit getScaleUnit( long size )
             {
-                Validate.isTrue( size >= 0L, "file size cannot be negative: %s", size );
+                Precondition.requireGreaterThanZero( size, "file size cannot be negative: %s", size );
 
                 if ( size >= GIGABYTE.bytes() )
                 {
@@ -135,6 +133,10 @@ public abstract class AbstractMavenTransferListener
                     return BYTE;
                 }
             }
+
+            public abstract long bytes();
+
+            public abstract String symbol();
         }
 
         private DecimalFormat smallFormat;
@@ -159,7 +161,7 @@ public abstract class AbstractMavenTransferListener
         @SuppressWarnings( "checkstyle:magicnumber" )
         public String format( long size, ScaleUnit unit, boolean omitSymbol )
         {
-            Validate.isTrue( size >= 0L, "file size cannot be negative: %s", size );
+            Precondition.requireGreaterThanZero( size, "file size cannot be negative: %s", size );
 
             if ( unit == null )
             {
@@ -191,9 +193,10 @@ public abstract class AbstractMavenTransferListener
 
         public String formatProgress( long progressedSize, long size )
         {
-            Validate.isTrue( progressedSize >= 0L, "progressed file size cannot be negative: %s", progressedSize );
-            Validate.isTrue( size >= 0L && progressedSize <= size || size < 0L,
-                "progressed file size cannot be greater than size: %s > %s", progressedSize, size );
+            Precondition.requireGreaterThanZero( progressedSize, "progressed file size cannot be negative: %s",
+                    progressedSize );
+            Precondition.isTrue( size >= 0L && progressedSize <= size || size < 0L,
+                    "progressed file size cannot be greater than size: %s > %s", progressedSize, size );
 
             if ( size >= 0L && progressedSize != size )
             {
@@ -233,13 +236,12 @@ public abstract class AbstractMavenTransferListener
     }
 
     @Override
-    public void transferCorrupted( TransferEvent event )
-        throws TransferCancelledException
+    public void transferCorrupted( TransferEvent event ) throws TransferCancelledException
     {
         TransferResource resource = event.getResource();
         // TODO This needs to be colorized
-        out.println( "[WARNING] " + event.getException().getMessage() + " from " + resource.getRepositoryId() + " for "
-            + resource.getRepositoryUrl() + resource.getResourceName() );
+        out.println( "[WARNING] " + event.getException().getMessage() + " from " + resource
+                .getRepositoryId() + " for " + resource.getRepositoryUrl() + resource.getResourceName() );
     }
 
     @Override
diff --git a/maven-utils/pom.xml b/maven-utils/pom.xml
index 3d3bd85..0472794 100644
--- a/maven-utils/pom.xml
+++ b/maven-utils/pom.xml
@@ -26,7 +26,7 @@ under the License.
   <parent>
     <groupId>org.apache.maven</groupId>
     <artifactId>maven</artifactId>
-    <version>3.6.3-SNAPSHOT</version>
+    <version>3.7.0-SNAPSHOT</version>
   </parent>
 
   <artifactId>maven-utils</artifactId>
@@ -34,6 +34,11 @@ under the License.
   <name>Maven Utils</name>
 
   <dependencies>
+    <dependency>
+      <groupId>org.apiguardian</groupId>
+      <artifactId>apiguardian-api</artifactId>
+      <version>1.1.0</version>
+    </dependency>
 
     <dependency>
       <groupId>org.junit.jupiter</groupId>
@@ -48,10 +53,5 @@ under the License.
       <scope>test</scope>
     </dependency>
 
-    <dependency>
-      <groupId>org.apiguardian</groupId>
-      <artifactId>apiguardian-api</artifactId>
-      <version>1.1.0</version>
-    </dependency>
   </dependencies>
 </project>
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 54f1399..838975c 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
@@ -19,10 +19,10 @@ package org.apache.maven.utils;
  * under the License.
  */
 
-import org.apiguardian.api.API;
-
 import java.util.List;
 
+import org.apiguardian.api.API;
+
 import static org.apiguardian.api.API.Status.INTERNAL;
 
 /**
@@ -30,7 +30,7 @@ import static org.apiguardian.api.API.Status.INTERNAL;
  *
  * @author Karl Heinz Marbaise
  */
-@API( status = INTERNAL, since = "3.6.4" )
+@API( status = INTERNAL, since = "3.7.0" )
 public final class Precondition
 {
     private Precondition()
@@ -116,6 +116,35 @@ public final class Precondition
         return longValue;
     }
 
+    public static void isTrue( boolean expression, String message, final long value )
+    {
+        if ( !expression )
+        {
+            throw new IllegalArgumentException( String.format( message, Long.valueOf( value ) ) );
+        }
+    }
+
+    public static void isTrue( boolean expression, String message, final Object... values )
+    {
+        if ( !expression )
+        {
+            throw new IllegalArgumentException( String.format( message, values ) );
+        }
+    }
+
+    public static Long requireGreaterThanZero(Long longValue, String message, final long value) {
+        if ( longValue == null )
+        {
+            throw new IllegalArgumentException( String.format( message, value ) );
+        }
+
+        if ( longValue <= 0 )
+        {
+            throw new IllegalArgumentException( String.format( message, value ) );
+        }
+        return longValue;
+    }
+
     /**
      * assert that the given {@code integerValue} is greater than {@code 0}.
      *
diff --git a/pom.xml b/pom.xml
index 05d36d6..eda1aaa 100644
--- a/pom.xml
+++ b/pom.xml
@@ -233,6 +233,11 @@ under the License.
         <artifactId>maven-slf4j-provider</artifactId>
         <version>${project.version}</version>
       </dependency>
+      <dependency>
+        <groupId>org.apache.maven</groupId>
+        <artifactId>maven-utils</artifactId>
+        <version>${project.version}</version>
+      </dependency>
       <!--bootstrap-end-comment-->
       <!--  Plexus -->
       <dependency>