[MNG-7998] Minor cleanup regarding "tasks" (#1366)

Just a minor cleanup regarding internals of "tasks".

---

https://issues.apache.org/jira/browse/MNG-7998
This commit is contained in:
Tamas Cservenak 2024-01-09 21:57:17 +01:00 committed by GitHub
parent 33aec13b84
commit 076b346c0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 84 additions and 47 deletions

View File

@ -112,7 +112,7 @@ public class DefaultLifecycleExecutionPlanCalculator implements LifecycleExecuti
@Override
public MavenExecutionPlan calculateExecutionPlan(
MavenSession session, MavenProject project, List<Object> tasks, boolean setup)
MavenSession session, MavenProject project, List<Task> tasks, boolean setup)
throws PluginNotFoundException, PluginResolutionException, LifecyclePhaseNotFoundException,
PluginDescriptorParsingException, MojoNotFoundException, InvalidPluginDescriptorException,
NoPluginFoundForPrefixException, LifecycleNotFoundException, PluginVersionResolutionException {
@ -130,7 +130,7 @@ public class DefaultLifecycleExecutionPlanCalculator implements LifecycleExecuti
}
@Override
public MavenExecutionPlan calculateExecutionPlan(MavenSession session, MavenProject project, List<Object> tasks)
public MavenExecutionPlan calculateExecutionPlan(MavenSession session, MavenProject project, List<Task> tasks)
throws PluginNotFoundException, PluginResolutionException, LifecyclePhaseNotFoundException,
PluginDescriptorParsingException, MojoNotFoundException, InvalidPluginDescriptorException,
NoPluginFoundForPrefixException, LifecycleNotFoundException, PluginVersionResolutionException {
@ -199,15 +199,15 @@ public class DefaultLifecycleExecutionPlanCalculator implements LifecycleExecuti
calculateForkedExecutions(mojoExecution, session, project, alreadyPlannedExecutions);
}
public List<MojoExecution> calculateMojoExecutions(MavenSession session, MavenProject project, List<Object> tasks)
public List<MojoExecution> calculateMojoExecutions(MavenSession session, MavenProject project, List<Task> tasks)
throws PluginNotFoundException, PluginResolutionException, PluginDescriptorParsingException,
MojoNotFoundException, NoPluginFoundForPrefixException, InvalidPluginDescriptorException,
PluginVersionResolutionException, LifecyclePhaseNotFoundException {
final List<MojoExecution> mojoExecutions = new ArrayList<>();
for (Object task : tasks) {
for (Task task : tasks) {
if (task instanceof GoalTask) {
String pluginGoal = ((GoalTask) task).pluginGoal;
String pluginGoal = task.getValue();
String executionId = "default-cli";
int executionIdx = pluginGoal.indexOf('@');
@ -221,7 +221,7 @@ public class DefaultLifecycleExecutionPlanCalculator implements LifecycleExecuti
mojoExecutions.add(mojoExecution);
} else if (task instanceof LifecycleTask) {
String lifecyclePhase = ((LifecycleTask) task).getLifecyclePhase();
String lifecyclePhase = task.getValue();
Map<String, List<MojoExecution>> phaseToMojoMapping =
calculateLifecycleMappings(session, project, lifecyclePhase);

View File

@ -19,23 +19,14 @@
package org.apache.maven.lifecycle.internal;
/**
* A task that is a goal.
* <p>
* A task that is a goal
* </p>
* <strong>NOTE:</strong> This class is not part of any public api and can be changed or deleted without prior notice.
*
* @since 3.0
*/
public final class GoalTask {
final String pluginGoal;
public final class GoalTask extends Task {
public GoalTask(String pluginGoal) {
this.pluginGoal = pluginGoal;
}
@Override
public String toString() {
return pluginGoal;
super(pluginGoal);
}
}

View File

@ -40,13 +40,13 @@ import org.apache.maven.project.MavenProject;
* @since 3.0
*/
public interface LifecycleExecutionPlanCalculator {
MavenExecutionPlan calculateExecutionPlan(MavenSession session, MavenProject project, List<Object> tasks)
MavenExecutionPlan calculateExecutionPlan(MavenSession session, MavenProject project, List<Task> tasks)
throws PluginNotFoundException, PluginResolutionException, LifecyclePhaseNotFoundException,
PluginDescriptorParsingException, MojoNotFoundException, InvalidPluginDescriptorException,
NoPluginFoundForPrefixException, LifecycleNotFoundException, PluginVersionResolutionException;
MavenExecutionPlan calculateExecutionPlan(
MavenSession session, MavenProject project, List<Object> tasks, boolean setup)
MavenSession session, MavenProject project, List<Task> tasks, boolean setup)
throws PluginNotFoundException, PluginResolutionException, LifecyclePhaseNotFoundException,
PluginDescriptorParsingException, MojoNotFoundException, InvalidPluginDescriptorException,
NoPluginFoundForPrefixException, LifecycleNotFoundException, PluginVersionResolutionException;

View File

@ -19,27 +19,14 @@
package org.apache.maven.lifecycle.internal;
/**
* A task that is a lifecycle.
* <p>
* A task that is a lifecycle
* </p>
* <strong>NOTE:</strong> This class is not part of any public api and can be changed or deleted without prior notice.
*
* @since 3.0
*/
public final class LifecycleTask {
private final String lifecyclePhase;
public final class LifecycleTask extends Task {
public LifecycleTask(String lifecyclePhase) {
this.lifecyclePhase = lifecyclePhase;
}
@Override
public String toString() {
return getLifecyclePhase();
}
public String getLifecyclePhase() {
return lifecyclePhase;
super(lifecyclePhase);
}
}

View File

@ -0,0 +1,63 @@
/*
* 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.lifecycle.internal;
import java.util.Objects;
/**
* A Maven task, at this level is merely just an opaque string.
* <p>
* <strong>NOTE:</strong> This class is not part of any public api and can be changed or deleted without prior notice.
*
* @since 4.0.0
*/
public abstract class Task {
private final String value;
public Task(String value) {
this.value = Objects.requireNonNull(value, "value");
}
public String getValue() {
return value;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Task)) {
return false;
}
Task task = (Task) o;
return Objects.equals(getClass(), task.getClass()) && Objects.equals(value, task.value);
}
@Override
public int hashCode() {
return Objects.hash(getClass(), value);
}
@Override
public String toString() {
return value;
}
}

View File

@ -33,7 +33,7 @@ public final class TaskSegment {
// Can be both "LifeCycleTask" (clean/install) and "GoalTask" (org.mortbay.jetty:maven-jetty-plugin:6.1.19:run)
private final List<Object> tasks;
private final List<Task> tasks;
private final boolean aggregating;
@ -42,7 +42,7 @@ public final class TaskSegment {
tasks = new ArrayList<>();
}
public TaskSegment(boolean aggregating, Object... tasks) {
public TaskSegment(boolean aggregating, Task... tasks) {
this.aggregating = aggregating;
this.tasks = new ArrayList<>(Arrays.asList(tasks));
}
@ -52,7 +52,7 @@ public final class TaskSegment {
return getTasks().toString();
}
public List<Object> getTasks() {
public List<Task> getTasks() {
return tasks;
}

View File

@ -372,7 +372,7 @@ class LifecycleExecutorTest extends AbstractCoreMavenComponentTestCase {
LifecycleTask task = new LifecycleTask("generate-sources");
MavenExecutionPlan executionPlan = lifeCycleExecutionPlanCalculator.calculateExecutionPlan(
session, session.getCurrentProject(), Arrays.asList((Object) task), false);
session, session.getCurrentProject(), Arrays.asList(task), false);
MojoExecution execution = executionPlan.getMojoExecutions().get(0);
assertEquals("maven-it-plugin", execution.getArtifactId(), execution.toString());

View File

@ -30,11 +30,7 @@ import org.apache.maven.lifecycle.DefaultLifecycles;
import org.apache.maven.lifecycle.LifecycleNotFoundException;
import org.apache.maven.lifecycle.LifecyclePhaseNotFoundException;
import org.apache.maven.lifecycle.MavenExecutionPlan;
import org.apache.maven.lifecycle.internal.DefaultLifecyclePluginAnalyzer;
import org.apache.maven.lifecycle.internal.ExecutionPlanItem;
import org.apache.maven.lifecycle.internal.LifecycleExecutionPlanCalculator;
import org.apache.maven.lifecycle.internal.ProjectBuildList;
import org.apache.maven.lifecycle.internal.ProjectSegment;
import org.apache.maven.lifecycle.internal.*;
import org.apache.maven.model.InputLocation;
import org.apache.maven.model.InputSource;
import org.apache.maven.model.Plugin;
@ -130,7 +126,7 @@ public class LifecycleExecutionPlanCalculatorStub implements LifecycleExecutionP
}
public MavenExecutionPlan calculateExecutionPlan(
MavenSession session, MavenProject project, List<Object> tasks, boolean setup)
MavenSession session, MavenProject project, List<Task> tasks, boolean setup)
throws PluginNotFoundException, PluginResolutionException, LifecyclePhaseNotFoundException,
PluginDescriptorParsingException, MojoNotFoundException, InvalidPluginDescriptorException,
NoPluginFoundForPrefixException, LifecycleNotFoundException, PluginVersionResolutionException {
@ -147,7 +143,7 @@ public class LifecycleExecutionPlanCalculatorStub implements LifecycleExecutionP
return createExecutionPlan(project, me);
}
public MavenExecutionPlan calculateExecutionPlan(MavenSession session, MavenProject project, List<Object> tasks)
public MavenExecutionPlan calculateExecutionPlan(MavenSession session, MavenProject project, List<Task> tasks)
throws PluginNotFoundException, PluginResolutionException, LifecyclePhaseNotFoundException,
PluginDescriptorParsingException, MojoNotFoundException, InvalidPluginDescriptorException,
NoPluginFoundForPrefixException, LifecycleNotFoundException, PluginVersionResolutionException {