Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
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;
Expand All @@ -41,6 +42,13 @@ public interface Lifecycle extends ExtensibleEnum {

String WRAPPER = "wrapper";

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

String READY = "ready";
Copy link
Copy Markdown
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
Copy Markdown
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.
*
Expand All @@ -54,6 +62,18 @@ public interface Lifecycle extends ExtensibleEnum {
*/
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.
Expand All @@ -69,5 +89,69 @@ 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;
}
}
}
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 "";
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.maven.api.services;

import java.util.List;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

Expand All @@ -28,4 +29,6 @@ public interface LifecycleRegistry extends ExtensibleEnumRegistry<Lifecycle>, It
default Stream<Lifecycle> stream() {
return StreamSupport.stream(spliterator(), false);
}

List<String> computePhases(Lifecycle lifecycle);
}
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,11 @@ public Iterator<Lifecycle> iterator() {
public Optional<Lifecycle> lookup(String id) {
return Optional.empty();
}

@Override
public List<String> computePhases(Lifecycle lifecycle) {
return List.of();
}
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ public Iterator<Lifecycle> iterator() {
public Optional<Lifecycle> lookup(String id) {
return Optional.empty();
}

@Override
public List<String> computePhases(Lifecycle lifecycle) {
return List.of();
}
};

private static final PackagingRegistry emptyPackagingRegistry = new PackagingRegistry() {
Expand Down Expand Up @@ -140,6 +145,11 @@ public Iterator<Lifecycle> iterator() {
protected LifecycleRegistry getDelegate() {
return lifecycleRegistry;
}

@Override
public List<String> computePhases(Lifecycle lifecycle) {
return List.of();
}
}

static class WrapperPackagingRegistry implements PackagingRegistry {
Expand Down
Loading