[MNG-7263] introduce AbstractLifecycleProvider

This commit is contained in:
Hervé Boutemy 2022-01-06 00:07:56 +01:00 committed by Hervé Boutemy
parent e5b0831c10
commit 711d5fbbf2
5 changed files with 144 additions and 153 deletions

View File

@ -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<Lifecycle>
{
private final Lifecycle lifecycle;
protected AbstractLifecycleProvider( String id, String[] phases, String[] pluginBindings )
{
HashMap<String, LifecyclePhase> 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;
}
}

View File

@ -19,52 +19,33 @@
* 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<Lifecycle>
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<String, LifecyclePhase> 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 );
}
}

View File

@ -19,67 +19,51 @@
* 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<Lifecycle>
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
);
}
}

View File

@ -19,54 +19,35 @@
* 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<Lifecycle>
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<String, LifecyclePhase> 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 );
}
}

View File

@ -19,51 +19,32 @@
* 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<Lifecycle>
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<String, LifecyclePhase> 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 );
}
}