Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MNG-8052] New Lifecycle API #1411

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
157 changes: 157 additions & 0 deletions api/maven-api-core/src/main/java/org/apache/maven/api/Lifecycle.java
@@ -0,0 +1,157 @@
/*
* 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.
*/
package org.apache.maven.api;

import java.util.*;
import java.util.stream.Stream;

import org.apache.maven.api.annotations.Experimental;
import org.apache.maven.api.annotations.Immutable;
import org.apache.maven.api.model.Plugin;

/**
* Lifecycle definition
*
* @since 4.0.0
*/
@Experimental
@Immutable
public interface Lifecycle extends ExtensibleEnum {

String CLEAN = "clean";

String DEFAULT = "default";

String SITE = "site";

String WRAPPER = "wrapper";

String PRE = "pre:";
String POST = "post:";
String RUN = "run:";

String READY = "ready";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this stage?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not really used anymore in this PR, so I'll remove those new concepts and I'll defer their addition to #1429.

For the record, it's used for the new lifecycle definition supporting dynamic phases and a fully concurrent build, see https://github.com/apache/maven/pull/1429/files#diff-dbccda410d9433bca88c9821a2ebd7ecb3b759738a2599a85748766c34658547R224-R252
In this PR, the phases are more fine-grained with inter-phases dependencies and more fine-grained inter-project dependencies. The lifecycle is not a simple list anymore, but looks more like a tree.
So ready represents the state of a project which is ready to be used as a dependency. This usually means that resources have been processed and classes compiled. The main point is that the compile phase should not have to be executed after the resources phase, as they both execute on different input and output and can be executed in parallel. So compile phase depends on sources phase, and ready depends on compile and resources, then package depends on ready.
The benefits (in addition to supporting dynamic phases with pre/post steps) is that we can have a package phase which does not depend on running tests, while verify would package and run unit/integration tests. This also cleanly solves problems coming from running mvn compile where some post processing can be mapped to that ready phase. So the definition of the tree-lifecycle above is not well defined yet, especially, the problem is how to bring those new features and keep a good level of compatibility.

I'd rather have a clean set of inter-phase and inter-project dependencies (for example, install and deploy do depend on package, but should not depend on running unit-tests and integration-tests).

Anyway, this can be deferred and discussed in the context of #1429, so I'll trim the Lifecycle interface to what is currently in Maven 3 (keeping in mind it can be extended in the future).

String PACKAGE = "package";

/**
* Name or identifier of this lifecycle.
*
* @return the unique identifier for this lifecycle
*/
@Override
String id();

/**
* Collection of phases for this lifecycle
*/
Collection<Phase> phases();

/**
* Stream of phases containing all child phases recursively.
*/
default Stream<Phase> allPhases() {
return phases().stream().flatMap(Phase::allPhases);
}

/**
* Collection of aliases.
*/
Collection<Alias> aliases();

/**
* Pre-ordered list of phases.
* If not provided, a default order will be computed.
*/
default Optional<List<String>> orderedPhases() {
return Optional.empty();
}

/**
* A phase in the lifecycle.
*/
interface Phase {
String name();

List<Plugin> plugins();

Collection<Link> links();

List<Phase> phases();

Stream<Phase> allPhases();
}

/**
* A phase alias, mostly used to support the Maven 3 phases which are mapped
* to dynamic phases in Maven 4.
*/
interface Alias {
String v3Phase();

String v4Phase();
}

/**
* A link from a phase to another phase, consisting of a type which can be
* {@link Kind#BEFORE} or {@link Kind#AFTER}, and a {@link Pointer} to
* another phase.
*/
interface Link {
enum Kind {
BEFORE,
AFTER
}

Kind kind();

Pointer pointer();
}

interface Pointer {
enum Type {
PROJECT,
DEPENDENCIES,
CHILDREN
}

String phase();

Type type();
}

interface PhasePointer extends Pointer {
default Type type() {
return Type.PROJECT;
}
}

interface DependenciesPointer extends Pointer {
String scope(); // default: all

default Type type() {
return Type.DEPENDENCIES;
}
}

interface ChildrenPointer extends Pointer {
default Type type() {
return Type.CHILDREN;
}
}
}
Expand Up @@ -46,6 +46,7 @@
@Immutable
public interface PathScope extends ExtensibleEnum {

// TODO: what if I simply want all dependencies ?
@Nonnull
ProjectScope projectScope();

Expand Down
@@ -0,0 +1,66 @@
/*
* 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.
*/
package org.apache.maven.api.plugin.annotations;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.apache.maven.api.annotations.Experimental;

/**
* Specifies that the mojo should be run after the specific phase.
*
* @since 4.0.0
*/
@Experimental
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
@Inherited
public @interface After {

/**
* Type of pointer.
* @see org.apache.maven.api.Lifecycle.Pointer.Type
*/
enum Type {
PROJECT,
DEPENDENCIES,
CHILDREN
}

/**
* The phase name.
*/
String phase();

/**
* The type of this pointer.
*/
Type type();

/**
* The scope for dependencies, only if {@code type() == Type.Dependencies}.
*/
String scope() default "";
}
Expand Up @@ -41,21 +41,10 @@
public @interface Execute {
/**
* Lifecycle phase to fork. Note that specifying a phase overrides specifying a goal.
* For custom lifecycle phase ids use {@link #customPhase()} instead.
* Only one of {@link #customPhase()} and {@link #phase()} must be set.
* @return the phase
*/
@Nonnull
LifecyclePhase phase() default LifecyclePhase.NONE;

/**
* Custom lifecycle phase to fork. Note that specifying a phase overrides specifying a goal.
* This element should only be used for non-standard phases. For standard phases rather use {@link #phase()}.
* Only one of {@link #customPhase()} and {@link #phase()} must be set.
* @return the custom phase id
*/
@Nonnull
String customPhase() default "";
String phase() default "";

/**
* Goal to fork. Note that specifying a phase overrides specifying a goal. The specified <code>goal</code> must be
Expand Down

This file was deleted.

Expand Up @@ -54,7 +54,7 @@
* @return the default phase
*/
@Nonnull
LifecyclePhase defaultPhase() default LifecyclePhase.NONE;
String defaultPhase() default "";

/**
* does your mojo requires a project to be executed?
Expand Down
Expand Up @@ -16,32 +16,18 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.maven.lifecycle.providers;
package org.apache.maven.api.services;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import java.util.List;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

/**
* {@code wrapper} lifecycle provider.
*/
@Named(WrapperLifecycleProvider.LIFECYCLE_ID)
@Singleton
public final class WrapperLifecycleProvider extends AbstractLifecycleProvider {
static final String LIFECYCLE_ID = "wrapper";

// START SNIPPET: wrapper
private static final String[] PHASES = {"wrapper"};

private static final String MAVEN_WRAPPER_PLUGIN_VERSION = "3.2.0";
import org.apache.maven.api.Lifecycle;

private static final String[] BINDINGS = {
"wrapper", "org.apache.maven.plugins:maven-wrapper-plugin:" + MAVEN_WRAPPER_PLUGIN_VERSION + ":wrapper"
};
// END SNIPPET: wrapper

@Inject
public WrapperLifecycleProvider() {
super(LIFECYCLE_ID, PHASES, BINDINGS);
public interface LifecycleRegistry extends ExtensibleEnumRegistry<Lifecycle>, Iterable<Lifecycle> {
default Stream<Lifecycle> stream() {
return StreamSupport.stream(spliterator(), false);
}

List<String> computePhases(Lifecycle lifecycle);
}