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:54 UTC
[maven] 01/01: Proposal to change abstract provider
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();