Skip to content

Commit 4e5c89c

Browse files
authored
[MNG-8299] Fix ordering of phases from custom lifecycles (#1802)
--- https://issues.apache.org/jira/browse/MNG-8299
1 parent eafb2fb commit 4e5c89c

File tree

1 file changed

+61
-32
lines changed

1 file changed

+61
-32
lines changed

maven-core/src/main/java/org/apache/maven/internal/impl/DefaultLifecycleRegistry.java

Lines changed: 61 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -204,42 +204,71 @@ public String id() {
204204

205205
@Override
206206
public Collection<Phase> phases() {
207-
return lifecycle.getPhases().stream()
208-
.map(name -> (Phase) new Phase() {
209-
@Override
210-
public String name() {
211-
return name;
207+
List<String> names = lifecycle.getPhases();
208+
List<Phase> phases = new ArrayList<>();
209+
for (int i = 0; i < names.size(); i++) {
210+
String name = names.get(i);
211+
String prev = i > 0 ? names.get(i - 1) : null;
212+
phases.add(new Phase() {
213+
@Override
214+
public String name() {
215+
return name;
216+
}
217+
218+
@Override
219+
public List<Phase> phases() {
220+
return List.of();
221+
}
222+
223+
@Override
224+
public Stream<Phase> allPhases() {
225+
return Stream.concat(
226+
Stream.of(this), phases().stream().flatMap(Lifecycle.Phase::allPhases));
227+
}
228+
229+
@Override
230+
public List<Plugin> plugins() {
231+
Map<String, LifecyclePhase> lfPhases = lifecycle.getDefaultLifecyclePhases();
232+
LifecyclePhase phase = lfPhases != null ? lfPhases.get(name) : null;
233+
if (phase != null) {
234+
Map<String, Plugin> plugins = new LinkedHashMap<>();
235+
DefaultPackagingRegistry.parseLifecyclePhaseDefinitions(plugins, name, phase);
236+
return plugins.values().stream().toList();
212237
}
238+
return List.of();
239+
}
213240

214-
@Override
215-
public List<Phase> phases() {
241+
@Override
242+
public Collection<Link> links() {
243+
if (prev == null) {
216244
return List.of();
245+
} else {
246+
return List.of(new Link() {
247+
@Override
248+
public Kind kind() {
249+
return Kind.AFTER;
250+
}
251+
252+
@Override
253+
public Pointer pointer() {
254+
return new Pointer() {
255+
@Override
256+
public String phase() {
257+
return prev;
258+
}
259+
260+
@Override
261+
public Type type() {
262+
return Type.PROJECT;
263+
}
264+
};
265+
}
266+
});
217267
}
218-
219-
@Override
220-
public Stream<Phase> allPhases() {
221-
return Stream.concat(
222-
Stream.of(this), phases().stream().flatMap(Lifecycle.Phase::allPhases));
223-
}
224-
225-
@Override
226-
public List<Plugin> plugins() {
227-
Map<String, LifecyclePhase> lfPhases = lifecycle.getDefaultLifecyclePhases();
228-
LifecyclePhase phase = lfPhases != null ? lfPhases.get(name) : null;
229-
if (phase != null) {
230-
Map<String, Plugin> plugins = new LinkedHashMap<>();
231-
DefaultPackagingRegistry.parseLifecyclePhaseDefinitions(plugins, name, phase);
232-
return plugins.values().stream().toList();
233-
}
234-
return List.of();
235-
}
236-
237-
@Override
238-
public Collection<Link> links() {
239-
return List.of();
240-
}
241-
})
242-
.toList();
268+
}
269+
});
270+
}
271+
return phases;
243272
}
244273

245274
@Override

0 commit comments

Comments
 (0)