Skip to content

Commit 956ee16

Browse files
committed
Lifecycle API
1 parent a3e8da8 commit 956ee16

File tree

22 files changed

+1042
-306
lines changed

22 files changed

+1042
-306
lines changed
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.maven.api;
20+
21+
import java.util.*;
22+
import java.util.stream.Stream;
23+
24+
import org.apache.maven.api.annotations.Experimental;
25+
import org.apache.maven.api.annotations.Immutable;
26+
import org.apache.maven.api.model.Plugin;
27+
28+
/**
29+
* Lifecycle definition
30+
*
31+
* @since 4.0.0
32+
*/
33+
@Experimental
34+
@Immutable
35+
public interface Lifecycle extends ExtensibleEnum {
36+
37+
String CLEAN = "clean";
38+
39+
String DEFAULT = "default";
40+
41+
String SITE = "site";
42+
43+
String WRAPPER = "wrapper";
44+
45+
String PRE = "pre:";
46+
String POST = "post:";
47+
String RUN = "run:";
48+
49+
String READY = "ready";
50+
String PACKAGE = "package";
51+
52+
/**
53+
* Name or identifier of this lifecycle.
54+
*
55+
* @return the unique identifier for this lifecycle
56+
*/
57+
@Override
58+
String id();
59+
60+
/**
61+
* Collection of phases for this lifecycle
62+
*/
63+
Collection<Phase> phases();
64+
65+
/**
66+
* Stream of phases containing all child phases recursively.
67+
*/
68+
default Stream<Phase> allPhases() {
69+
return phases().stream().flatMap(Phase::allPhases);
70+
}
71+
72+
/**
73+
* Collection of aliases.
74+
*/
75+
Collection<Alias> aliases();
76+
77+
/**
78+
* Pre-ordered list of phases.
79+
* If not provided, a default order will be computed.
80+
*/
81+
default Optional<List<String>> orderedPhases() {
82+
return Optional.empty();
83+
}
84+
85+
/**
86+
* A phase in the lifecycle.
87+
*/
88+
interface Phase {
89+
String name();
90+
91+
List<Plugin> plugins();
92+
93+
Collection<Link> links();
94+
95+
List<Phase> phases();
96+
97+
Stream<Phase> allPhases();
98+
}
99+
100+
/**
101+
* A phase alias, mostly used to support the Maven 3 phases which are mapped
102+
* to dynamic phases in Maven 4.
103+
*/
104+
interface Alias {
105+
String v3Phase();
106+
107+
String v4Phase();
108+
}
109+
110+
/**
111+
* A link from a phase to another phase, consisting of a type which can be
112+
* {@link Kind#Before} or {@link Kind#After}, and a {@link Pointer} to
113+
* another phase.
114+
*/
115+
interface Link {
116+
enum Kind {
117+
Before,
118+
After
119+
}
120+
121+
Kind kind();
122+
123+
Pointer pointer();
124+
}
125+
126+
interface Pointer {
127+
enum Type {
128+
Project,
129+
Dependencies,
130+
Children
131+
}
132+
133+
String phase();
134+
135+
Type type();
136+
}
137+
138+
interface PhasePointer extends Pointer {
139+
default Type type() {
140+
return Type.Project;
141+
}
142+
}
143+
144+
interface DependenciesPointer extends Pointer {
145+
String scope(); // default: all
146+
147+
default Type type() {
148+
return Type.Dependencies;
149+
}
150+
}
151+
152+
interface ChildrenPointer extends Pointer {
153+
default Type type() {
154+
return Type.Children;
155+
}
156+
}
157+
}

api/maven-api-core/src/main/java/org/apache/maven/api/Packaging.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@
1818
*/
1919
package org.apache.maven.api;
2020

21+
import java.util.Optional;
22+
2123
import org.apache.maven.api.annotations.Experimental;
2224
import org.apache.maven.api.annotations.Immutable;
2325
import org.apache.maven.api.annotations.Nonnull;
26+
import org.apache.maven.api.model.PluginContainer;
2427

2528
/**
2629
* Interface representing a Maven project packaging.
@@ -52,4 +55,11 @@ default Language language() {
5255
*/
5356
@Nonnull
5457
Type getType();
58+
59+
/**
60+
* Returns the binding to use specifically for this packaging.
61+
* This will be merged to the default packaging definition.
62+
*/
63+
@Nonnull
64+
Optional<PluginContainer> getPlugins();
5565
}

api/maven-api-core/src/main/java/org/apache/maven/api/PathScope.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
@Immutable
4747
public interface PathScope extends ExtensibleEnum {
4848

49+
// TODO: what if I simply want all dependencies ?
4950
@Nonnull
5051
ProjectScope projectScope();
5152

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.maven.api.plugin.annotations;
20+
21+
import java.lang.annotation.Documented;
22+
import java.lang.annotation.ElementType;
23+
import java.lang.annotation.Inherited;
24+
import java.lang.annotation.Retention;
25+
import java.lang.annotation.RetentionPolicy;
26+
import java.lang.annotation.Target;
27+
28+
import org.apache.maven.api.annotations.Experimental;
29+
30+
/**
31+
* Specifies that the mojo should be run after the specific phase.
32+
*
33+
* @since 4.0.0
34+
*/
35+
@Experimental
36+
@Documented
37+
@Retention(RetentionPolicy.RUNTIME)
38+
@Target(ElementType.TYPE)
39+
@Inherited
40+
public @interface After {
41+
42+
/**
43+
* Type of pointer.
44+
* @see org.apache.maven.api.Lifecycle.Pointer.Type
45+
*/
46+
enum Type {
47+
Project,
48+
Dependencies,
49+
Children
50+
}
51+
52+
/**
53+
* The phase name.
54+
*/
55+
String phase();
56+
57+
/**
58+
* The type of this pointer.
59+
*/
60+
Type type();
61+
62+
/**
63+
* The scope for dependencies, only if {@code type() == Type.Dependencies}.
64+
*/
65+
String scope() default "";
66+
}

api/maven-api-core/src/main/java/org/apache/maven/api/plugin/annotations/Execute.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,10 @@
4141
public @interface Execute {
4242
/**
4343
* Lifecycle phase to fork. Note that specifying a phase overrides specifying a goal.
44-
* For custom lifecycle phase ids use {@link #customPhase()} instead.
45-
* Only one of {@link #customPhase()} and {@link #phase()} must be set.
4644
* @return the phase
4745
*/
4846
@Nonnull
49-
LifecyclePhase phase() default LifecyclePhase.NONE;
50-
51-
/**
52-
* Custom lifecycle phase to fork. Note that specifying a phase overrides specifying a goal.
53-
* This element should only be used for non-standard phases. For standard phases rather use {@link #phase()}.
54-
* Only one of {@link #customPhase()} and {@link #phase()} must be set.
55-
* @return the custom phase id
56-
*/
57-
@Nonnull
58-
String customPhase() default "";
47+
String phase() default "";
5948

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

api/maven-api-core/src/main/java/org/apache/maven/api/plugin/annotations/LifecyclePhase.java

Lines changed: 0 additions & 74 deletions
This file was deleted.

api/maven-api-core/src/main/java/org/apache/maven/api/plugin/annotations/Mojo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
* @return the default phase
5555
*/
5656
@Nonnull
57-
LifecyclePhase defaultPhase() default LifecyclePhase.NONE;
57+
String defaultPhase() default "";
5858

5959
/**
6060
* does your mojo requires a project to be executed?

0 commit comments

Comments
 (0)