From 711d5fbbf2eaf0ef76ce5a62e3593654b512fae9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Boutemy?= Date: Thu, 6 Jan 2022 00:07:56 +0100 Subject: [PATCH] [MNG-7263] introduce AbstractLifecycleProvider --- .../providers/AbstractLifecycleProvider.java | 64 ++++++++++++++ .../providers/CleanLifecycleProvider.java | 49 ++++------- .../providers/DefaultLifecycleProvider.java | 84 ++++++++----------- .../providers/SiteLifecycleProvider.java | 53 ++++-------- .../providers/WrapperLifecycleProvider.java | 47 ++++------- 5 files changed, 144 insertions(+), 153 deletions(-) create mode 100644 maven-core/src/main/java/org/apache/maven/lifecycle/providers/AbstractLifecycleProvider.java diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/providers/AbstractLifecycleProvider.java b/maven-core/src/main/java/org/apache/maven/lifecycle/providers/AbstractLifecycleProvider.java new file mode 100644 index 0000000000..eb80a58971 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/providers/AbstractLifecycleProvider.java @@ -0,0 +1,64 @@ +package org.apache.maven.lifecycle.providers; + +/* + * 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 java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; + +import javax.inject.Provider; + +import org.apache.maven.lifecycle.Lifecycle; +import org.apache.maven.lifecycle.mapping.LifecyclePhase; + +/** + * Base lifecycle provider. + */ +public abstract class AbstractLifecycleProvider + implements Provider +{ + private final Lifecycle lifecycle; + + protected AbstractLifecycleProvider( String id, String[] phases, String[] pluginBindings ) + { + HashMap defaultBindings = null; + if ( pluginBindings != null ) + { + int len = pluginBindings.length; + defaultBindings = new HashMap<>(); + for ( int i = 0; i < len; i++ ) + { + defaultBindings.put( pluginBindings[i++], new LifecyclePhase( pluginBindings[i] ) ); + } + } + + this.lifecycle = new Lifecycle( + id, + Collections.unmodifiableList( Arrays.asList( phases ) ), + defaultBindings == null ? null : Collections.unmodifiableMap( defaultBindings ) + ); + } + + @Override + public Lifecycle get() + { + return lifecycle; + } +} diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/providers/CleanLifecycleProvider.java b/maven-core/src/main/java/org/apache/maven/lifecycle/providers/CleanLifecycleProvider.java index 4b72b5ee26..62924cd5ed 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/providers/CleanLifecycleProvider.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/providers/CleanLifecycleProvider.java @@ -19,52 +19,33 @@ package org.apache.maven.lifecycle.providers; * under the License. */ -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; - import javax.inject.Inject; import javax.inject.Named; -import javax.inject.Provider; import javax.inject.Singleton; -import org.apache.maven.lifecycle.Lifecycle; -import org.apache.maven.lifecycle.mapping.LifecyclePhase; - /** * {@code clean} lifecycle provider. */ @Named( "clean" ) @Singleton public final class CleanLifecycleProvider - implements Provider + extends AbstractLifecycleProvider { - private static final String LIFECYCLE_ID = "clean"; + private static final String LIFECYCLE_ID = "clean"; - private static final String[] PHASES = { - "pre-clean", - "clean", - "post-clean" - }; + private static final String[] PHASES = { + "pre-clean", + "clean", + "post-clean" + }; - private final Lifecycle lifecycle; + private static final String[] BINDINGS = { + "clean", "org.apache.maven.plugins:maven-clean-plugin:3.1.0:clean" + }; - @Inject - public CleanLifecycleProvider() - { - HashMap defaultBindings = new HashMap<>(); - defaultBindings.put( "clean", new LifecyclePhase( "org.apache.maven.plugins:maven-clean-plugin:3.1.0:clean" ) ); - - this.lifecycle = new Lifecycle( - LIFECYCLE_ID, - Collections.unmodifiableList( Arrays.asList( PHASES ) ), - Collections.unmodifiableMap( defaultBindings ) - ); - } - - @Override - public Lifecycle get() - { - return lifecycle; - } + @Inject + public CleanLifecycleProvider() + { + super( LIFECYCLE_ID, PHASES, BINDINGS ); + } } diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/providers/DefaultLifecycleProvider.java b/maven-core/src/main/java/org/apache/maven/lifecycle/providers/DefaultLifecycleProvider.java index 29d54836a7..aa6f75c516 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/providers/DefaultLifecycleProvider.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/providers/DefaultLifecycleProvider.java @@ -19,67 +19,51 @@ package org.apache.maven.lifecycle.providers; * under the License. */ -import java.util.Arrays; -import java.util.Collections; - import javax.inject.Inject; import javax.inject.Named; -import javax.inject.Provider; import javax.inject.Singleton; -import org.apache.maven.lifecycle.Lifecycle; - /** * {@code default} lifecycle provider. */ @Named( "default" ) @Singleton public final class DefaultLifecycleProvider - implements Provider + extends AbstractLifecycleProvider { - private static final String LIFECYCLE_ID = "default"; + private static final String LIFECYCLE_ID = "default"; - private static final String[] PHASES = { - "validate", - "initialize", - "generate-sources", - "process-sources", - "generate-resources", - "process-resources", - "compile", - "process-classes", - "generate-test-sources", - "process-test-sources", - "generate-test-resources", - "process-test-resources", - "test-compile", - "process-test-classes", - "test", - "prepare-package", - "package", - "pre-integration-test", - "integration-test", - "post-integration-test", - "verify", - "install", - "deploy" - }; + private static final String[] PHASES = { + "validate", + "initialize", + "generate-sources", + "process-sources", + "generate-resources", + "process-resources", + "compile", + "process-classes", + "generate-test-sources", + "process-test-sources", + "generate-test-resources", + "process-test-resources", + "test-compile", + "process-test-classes", + "test", + "prepare-package", + "package", + "pre-integration-test", + "integration-test", + "post-integration-test", + "verify", + "install", + "deploy" + }; - private final Lifecycle lifecycle; - - @Inject - public DefaultLifecycleProvider() - { - this.lifecycle = new Lifecycle( - LIFECYCLE_ID, - Collections.unmodifiableList( Arrays.asList( PHASES ) ), - null // no global plugin bindings for default lifecycle: they are defined per-packaging in separate providers - ); - } - - @Override - public Lifecycle get() - { - return lifecycle; - } + @Inject + public DefaultLifecycleProvider() + { + super( LIFECYCLE_ID, PHASES, + null // no global plugin bindings for default lifecycle: they are defined per-packaging in separate providers + ); + } } diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/providers/SiteLifecycleProvider.java b/maven-core/src/main/java/org/apache/maven/lifecycle/providers/SiteLifecycleProvider.java index d7ff5631d7..142ac1c131 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/providers/SiteLifecycleProvider.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/providers/SiteLifecycleProvider.java @@ -19,54 +19,35 @@ package org.apache.maven.lifecycle.providers; * under the License. */ -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; - import javax.inject.Inject; import javax.inject.Named; -import javax.inject.Provider; import javax.inject.Singleton; -import org.apache.maven.lifecycle.Lifecycle; -import org.apache.maven.lifecycle.mapping.LifecyclePhase; - /** * {@code site} lifecycle provider. */ @Named( "site" ) @Singleton public final class SiteLifecycleProvider - implements Provider + extends AbstractLifecycleProvider { - private static final String LIFECYCLE_ID = "site"; + private static final String LIFECYCLE_ID = "site"; - private static final String[] PHASES = { - "pre-site", - "site", - "post-site", - "site-deploy" - }; + private static final String[] PHASES = { + "pre-site", + "site", + "post-site", + "site-deploy" + }; - private final Lifecycle lifecycle; + private static final String[] BINDINGS = { + "site", "org.apache.maven.plugins:maven-site-plugin:3.9.1:site", + "site-deploy", "org.apache.maven.plugins:maven-site-plugin:3.9.1:deploy" + }; - @Inject - public SiteLifecycleProvider() - { - HashMap defaultBindings = new HashMap<>(); - defaultBindings.put( "site", new LifecyclePhase( "org.apache.maven.plugins:maven-site-plugin:3.9.1:site" ) ); - defaultBindings.put( "site-deploy", new LifecyclePhase( "org.apache.maven.plugins:maven-site-plugin:3.9.1:deploy" ) ); - - this.lifecycle = new Lifecycle( - LIFECYCLE_ID, - Collections.unmodifiableList( Arrays.asList( PHASES ) ), - Collections.unmodifiableMap( defaultBindings ) - ); - } - - @Override - public Lifecycle get() - { - return lifecycle; - } + @Inject + public SiteLifecycleProvider() + { + super( LIFECYCLE_ID, PHASES, BINDINGS ); + } } diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/providers/WrapperLifecycleProvider.java b/maven-core/src/main/java/org/apache/maven/lifecycle/providers/WrapperLifecycleProvider.java index b88dcc1b84..aa383abfbc 100644 --- a/maven-core/src/main/java/org/apache/maven/lifecycle/providers/WrapperLifecycleProvider.java +++ b/maven-core/src/main/java/org/apache/maven/lifecycle/providers/WrapperLifecycleProvider.java @@ -19,51 +19,32 @@ package org.apache.maven.lifecycle.providers; * under the License. */ -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; - import javax.inject.Inject; import javax.inject.Named; -import javax.inject.Provider; import javax.inject.Singleton; -import org.apache.maven.lifecycle.Lifecycle; -import org.apache.maven.lifecycle.mapping.LifecyclePhase; - /** * {@code wrapper} lifecycle provider. */ @Named( "wrapper" ) @Singleton public final class WrapperLifecycleProvider - implements Provider + extends AbstractLifecycleProvider { - private static final String LIFECYCLE_ID = "wrapper"; + private static final String LIFECYCLE_ID = "wrapper"; - private static final String[] PHASES = - { - "wrapper" - }; + private static final String[] PHASES = + { + "wrapper" + }; - private final Lifecycle lifecycle; + private static final String[] BINDINGS = { + "wrapper", "org.apache.maven.plugins:maven-wrapper-plugin:3.1.0:wrapper" + }; - @Inject - public WrapperLifecycleProvider() - { - HashMap defaultBindings = new HashMap<>(); - defaultBindings.put( "wrapper", new LifecyclePhase( "org.apache.maven.plugins:maven-wrapper-plugin:3.1.0:wrapper" ) ); - - this.lifecycle = new Lifecycle( - LIFECYCLE_ID, - Collections.unmodifiableList( Arrays.asList( PHASES ) ), - Collections.unmodifiableMap( defaultBindings ) - ); - } - - @Override - public Lifecycle get() - { - return lifecycle; - } + @Inject + public WrapperLifecycleProvider() + { + super( LIFECYCLE_ID, PHASES, BINDINGS ); + } }