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
gnodet
wants to merge
4
commits into
apache:master
Choose a base branch
from
gnodet:lifecycle
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
157 changes: 157 additions & 0 deletions
157
api/maven-api-core/src/main/java/org/apache/maven/api/Lifecycle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"; | ||
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
api/maven-api-core/src/main/java/org/apache/maven/api/plugin/annotations/After.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ""; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 0 additions & 74 deletions
74
api/maven-api-core/src/main/java/org/apache/maven/api/plugin/annotations/LifecyclePhase.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this stage?
There was a problem hiding this comment.
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 thecompile
phase should not have to be executed after theresources
phase, as they both execute on different input and output and can be executed in parallel. Socompile
phase depends onsources
phase, andready
depends oncompile
andresources
, thenpackage
depends onready
.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, whileverify
would package and run unit/integration tests. This also cleanly solves problems coming from runningmvn compile
where some post processing can be mapped to thatready
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
anddeploy
do depend onpackage
, 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).