org.gradle.execution.plan.LocalTaskNode Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gradle-api Show documentation
Show all versions of gradle-api Show documentation
Gradle 6.9.1 API redistribution.
/*
* Copyright 2018 the original author or authors.
*
* Licensed 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.gradle.execution.plan;
import org.gradle.api.Action;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.internal.TaskInternal;
import org.gradle.api.internal.tasks.TaskContainerInternal;
import org.gradle.internal.ImmutableActionSet;
import javax.annotation.Nullable;
import java.util.Set;
/**
* A {@link TaskNode} implementation for a task in the current build.
*/
public class LocalTaskNode extends TaskNode {
private final TaskInternal task;
private ImmutableActionSet postAction = ImmutableActionSet.empty();
public LocalTaskNode(TaskInternal task) {
this.task = task;
}
@Nullable
@Override
public Project getProject() {
// Running the task requires access to the task's owning project
return task.getProject();
}
@Override
public TaskInternal getTask() {
return task;
}
@Override
public Action super Task> getPostAction() {
return postAction;
}
@Override
public void appendPostAction(Action super Task> action) {
postAction = postAction.add(action);
}
@Override
public Throwable getNodeFailure() {
return task.getState().getFailure();
}
@Override
public void rethrowNodeFailure() {
task.getState().rethrowFailure();
}
@Override
public void prepareForExecution() {
((TaskContainerInternal) task.getProject().getTasks()).prepareForExecution(task);
}
@Override
public void resolveDependencies(TaskDependencyResolver dependencyResolver, Action processHardSuccessor) {
for (Node targetNode : getDependencies(dependencyResolver)) {
addDependencySuccessor(targetNode);
processHardSuccessor.execute(targetNode);
}
for (Node targetNode : getFinalizedBy(dependencyResolver)) {
if (!(targetNode instanceof TaskNode)) {
throw new IllegalStateException("Only tasks can be finalizers: " + targetNode);
}
addFinalizerNode((TaskNode) targetNode);
processHardSuccessor.execute(targetNode);
}
for (Node targetNode : getMustRunAfter(dependencyResolver)) {
addMustSuccessor(targetNode);
}
for (Node targetNode : getShouldRunAfter(dependencyResolver)) {
addShouldSuccessor(targetNode);
}
}
private void addFinalizerNode(TaskNode finalizerNode) {
addFinalizer(finalizerNode);
if (!finalizerNode.isInKnownState()) {
finalizerNode.mustNotRun();
}
}
private Set getDependencies(TaskDependencyResolver dependencyResolver) {
return dependencyResolver.resolveDependenciesFor(task, task.getTaskDependencies());
}
private Set getFinalizedBy(TaskDependencyResolver dependencyResolver) {
return dependencyResolver.resolveDependenciesFor(task, task.getFinalizedBy());
}
private Set getMustRunAfter(TaskDependencyResolver dependencyResolver) {
return dependencyResolver.resolveDependenciesFor(task, task.getMustRunAfter());
}
private Set getShouldRunAfter(TaskDependencyResolver dependencyResolver) {
return dependencyResolver.resolveDependenciesFor(task, task.getShouldRunAfter());
}
@Override
@SuppressWarnings("NullableProblems")
public int compareTo(Node other) {
if (getClass() != other.getClass()) {
return getClass().getName().compareTo(other.getClass().getName());
}
LocalTaskNode localTask = (LocalTaskNode) other;
return task.compareTo(localTask.task);
}
@Override
public String toString() {
return task.getIdentityPath().toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy