[MNG-8299] Fix ordering of phases from custom lifecycles (#1802)

---

https://issues.apache.org/jira/browse/MNG-8299
This commit is contained in:
Guillaume Nodet 2024-10-16 16:19:33 +02:00 committed by GitHub
parent eafb2fb8b1
commit 4e5c89c403
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 60 additions and 31 deletions

View File

@ -204,42 +204,71 @@ public class DefaultLifecycleRegistry implements LifecycleRegistry {
@Override @Override
public Collection<Phase> phases() { public Collection<Phase> phases() {
return lifecycle.getPhases().stream() List<String> names = lifecycle.getPhases();
.map(name -> (Phase) new Phase() { List<Phase> phases = new ArrayList<>();
@Override for (int i = 0; i < names.size(); i++) {
public String name() { String name = names.get(i);
return name; String prev = i > 0 ? names.get(i - 1) : null;
} phases.add(new Phase() {
@Override
public String name() {
return name;
}
@Override @Override
public List<Phase> phases() { public List<Phase> phases() {
return List.of();
}
@Override
public Stream<Phase> allPhases() {
return Stream.concat(
Stream.of(this), phases().stream().flatMap(Lifecycle.Phase::allPhases));
}
@Override
public List<Plugin> plugins() {
Map<String, LifecyclePhase> lfPhases = lifecycle.getDefaultLifecyclePhases();
LifecyclePhase phase = lfPhases != null ? lfPhases.get(name) : null;
if (phase != null) {
Map<String, Plugin> plugins = new LinkedHashMap<>();
DefaultPackagingRegistry.parseLifecyclePhaseDefinitions(plugins, name, phase);
return plugins.values().stream().toList();
}
return List.of();
}
@Override
public Collection<Link> links() {
if (prev == null) {
return List.of(); return List.of();
} } else {
return List.of(new Link() {
@Override
public Kind kind() {
return Kind.AFTER;
}
@Override @Override
public Stream<Phase> allPhases() { public Pointer pointer() {
return Stream.concat( return new Pointer() {
Stream.of(this), phases().stream().flatMap(Lifecycle.Phase::allPhases)); @Override
} public String phase() {
return prev;
}
@Override @Override
public List<Plugin> plugins() { public Type type() {
Map<String, LifecyclePhase> lfPhases = lifecycle.getDefaultLifecyclePhases(); return Type.PROJECT;
LifecyclePhase phase = lfPhases != null ? lfPhases.get(name) : null; }
if (phase != null) { };
Map<String, Plugin> plugins = new LinkedHashMap<>(); }
DefaultPackagingRegistry.parseLifecyclePhaseDefinitions(plugins, name, phase); });
return plugins.values().stream().toList();
}
return List.of();
} }
}
@Override });
public Collection<Link> links() { }
return List.of(); return phases;
}
})
.toList();
} }
@Override @Override