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 @@ -28,7 +28,6 @@
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -251,13 +250,11 @@ public Stream<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();
return lfPhases != null
? List.of(DefaultPackagingRegistry.parseLifecyclePhaseDefinitions(lfPhases)
.values()
.toArray(Plugin[]::new))
: List.of();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import javax.inject.Singleton;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
Expand Down Expand Up @@ -73,41 +73,35 @@ public DefaultPackagingRegistry(Lookup lookup, TypeRegistry typeRegistry, List<P

@Override
public Optional<Packaging> lookup(String id) {
id = id.toLowerCase(Locale.ROOT);
String lid = id.toLowerCase(Locale.ROOT);
// TODO: we should be able to inject a Map<String, LifecycleMapping> directly,
// however, SISU visibility filtering can only happen when an explicit
// lookup is performed. The whole problem here is caused by "project extensions"
// which are bound to a project's classloader, without any clear definition
// of a "project scope"
LifecycleMapping lifecycleMapping =
lookup.lookupOptional(LifecycleMapping.class, id).orElse(null);
if (lifecycleMapping == null) {
return Optional.empty();
}
Type type = typeRegistry.lookup(id).orElse(null);
if (type == null) {
return Optional.empty();
}
return Optional.of(new DefaultPackaging(id, type, getPlugins(lifecycleMapping)));
return lookup.lookupOptional(LifecycleMapping.class, lid).flatMap(lifecycleMapping -> typeRegistry
.lookup(lid)
.map(type -> new DefaultPackaging(lid, type, getPlugins(lifecycleMapping))));
}

private Map<String, PluginContainer> getPlugins(LifecycleMapping lifecycleMapping) {
Map<String, PluginContainer> lfs = new HashMap<>();
lifecycleMapping.getLifecycles().forEach((id, lifecycle) -> {
Map<String, Plugin> plugins = new HashMap<>();
lifecycle
.getLifecyclePhases()
.forEach((phase, lifecyclePhase) -> parseLifecyclePhaseDefinitions(plugins, phase, lifecyclePhase));
lfs.put(id, PluginContainer.newBuilder().plugins(plugins.values()).build());
});
return lfs;
return lifecycleMapping.getLifecycles().entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey, e -> PluginContainer.newBuilder()
.plugins(parseLifecyclePhaseDefinitions(e.getValue().getLifecyclePhases())
.values())
.build()));
}

static void parseLifecyclePhaseDefinitions(Map<String, Plugin> plugins, String phase, LifecyclePhase goals) {
static Map<String, Plugin> parseLifecyclePhaseDefinitions(Map<String, LifecyclePhase> phases) {
InputLocation location = DefaultLifecycleRegistry.DEFAULT_LIFECYCLE_INPUT_LOCATION;
Map<String, Plugin> plugins = new LinkedHashMap<>();

phases.forEach((phase, goals) -> {
List<LifecycleMojo> mojos = goals.getMojos();
if (mojos == null) {
return;
}

List<LifecycleMojo> mojos = goals.getMojos();
if (mojos != null) {
for (int i = 0; i < mojos.size(); i++) {
LifecycleMojo mojo = mojos.get(i);

Expand Down Expand Up @@ -181,7 +175,9 @@ static void parseLifecyclePhaseDefinitions(Map<String, Plugin> plugins, String p

plugins.put(key, plugin);
}
}
});

return plugins;
}

private static String getExecutionId(Plugin plugin, String goal) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ public Stream<BuildStep> allSteps() {
}

public Stream<BuildStep> steps(MavenProject project) {
return Optional.ofNullable(plan.get(project))
.map(m -> m.values().stream())
.orElse(Stream.empty());
return Optional.ofNullable(plan.get(project)).stream().flatMap(m -> m.values().stream());
}

public Optional<BuildStep> step(MavenProject project, String name) {
Expand All @@ -103,7 +101,7 @@ private Map<String, BuildStep> merge(Map<String, BuildStep> org, Map<String, Bui
add.values().stream().filter(b -> b.predecessors.isEmpty()).toList();
firsts.stream()
.filter(addNode -> !org.containsKey(addNode.name))
.forEach(addNode -> lasts.forEach(orgNode -> addNode.executeAfter(orgNode)));
.forEach(addNode -> lasts.forEach(addNode::executeAfter));
add.forEach((name, node) -> org.merge(name, node, this::merge));
return org;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public BuildPlan buildInitialPlan(List<TaskSegment> taskSegments) {
// Create plan, setup and teardown
for (MavenProject project : plan.getAllProjects().keySet()) {
BuildStep pplan = new BuildStep(PLAN, project, null);
pplan.status.set(PLANNING); // the plan step always need planning
pplan.status.set(PLANNING); // the plan step always needs planning
BuildStep setup = new BuildStep(SETUP, project, null);
BuildStep teardown = new BuildStep(TEARDOWN, project, null);
teardown.executeAfter(setup);
Expand Down Expand Up @@ -694,7 +694,7 @@ protected void handleBuildError(
} else if (MavenExecutionRequest.REACTOR_FAIL_FAST.equals(session.getReactorFailureBehavior())) {
buildContext.getReactorBuildStatus().halt();
} else {
logger.error("invalid reactor failure behavior " + session.getReactorFailureBehavior());
logger.error("invalid reactor failure behavior {}", session.getReactorFailureBehavior());
buildContext.getReactorBuildStatus().halt();
}
}
Expand Down Expand Up @@ -848,11 +848,11 @@ public BuildPlan calculateLifecycleMappings(
plan.addProject(project, steps);
}

// Create inter project dependencies
// Create inter-project dependencies
plan.allSteps().filter(step -> step.phase != null).forEach(step -> {
Lifecycle.Phase phase = step.phase;
MavenProject project = step.project;
phase.links().stream().forEach(link -> {
phase.links().forEach(link -> {
BuildStep before = plan.requiredStep(project, BEFORE + phase.name());
BuildStep after = plan.requiredStep(project, AFTER + phase.name());
Lifecycle.Pointer pointer = link.pointer();
Expand Down