You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by cs...@apache.org on 2022/01/06 07:48:53 UTC

[maven] branch MNG-7264-cstamas created (now edf4f20)

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

cstamas pushed a change to branch MNG-7264-cstamas
in repository https://gitbox.apache.org/repos/asf/maven.git.


      at edf4f20  Proposal to change abstract provider

This branch includes the following new commits:

     new edf4f20  Proposal to change abstract provider

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] 01/01: Proposal to change abstract provider

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

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

commit edf4f204e88db52059c67a229e9a2a7ef5e0a69d
Author: Tamas Cservenak <ta...@cservenak.net>
AuthorDate: Thu Jan 6 08:47:54 2022 +0100

    Proposal to change abstract provider
    
    Changes:
    * validate input
    * do not modify loop invariant within loop body
---
 .../packaging/AbstractLifecycleMappingProvider.java      | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/providers/packaging/AbstractLifecycleMappingProvider.java b/maven-core/src/main/java/org/apache/maven/lifecycle/providers/packaging/AbstractLifecycleMappingProvider.java
index f58f937..a1d8188 100644
--- a/maven-core/src/main/java/org/apache/maven/lifecycle/providers/packaging/AbstractLifecycleMappingProvider.java
+++ b/maven-core/src/main/java/org/apache/maven/lifecycle/providers/packaging/AbstractLifecycleMappingProvider.java
@@ -29,6 +29,8 @@ import org.apache.maven.lifecycle.mapping.Lifecycle;
 import org.apache.maven.lifecycle.mapping.LifecycleMapping;
 import org.apache.maven.lifecycle.mapping.LifecyclePhase;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * Base lifecycle mapping provider, ie per-packaging plugin bindings for {@code default} lifecycle.
  */
@@ -39,11 +41,17 @@ public abstract class AbstractLifecycleMappingProvider
 
     protected AbstractLifecycleMappingProvider( String[] pluginBindings )
     {
-        HashMap<String, LifecyclePhase> lifecyclePhases = new HashMap<>();
-        int len = pluginBindings.length;
-        for ( int i = 0; i < len; i++ )
+        requireNonNull( pluginBindings );
+        final int len = pluginBindings.length;
+        if ( len < 1 || len % 2 != 0 )
+        {
+            throw new IllegalArgumentException( "Plugin bindings must have more than 0, even count of elements" );
+        }
+
+        HashMap<String, LifecyclePhase> lifecyclePhases = new HashMap<>( len / 2 );
+        for ( int i = 0; i < len; i = i + 2 )
         {
-            lifecyclePhases.put( pluginBindings[i++], new LifecyclePhase( pluginBindings[i] ) );
+            lifecyclePhases.put( pluginBindings[i], new LifecyclePhase( pluginBindings[i + 1] ) );
         }
 
         Lifecycle lifecycle = new Lifecycle();