org.gradle.execution.plan.TaskNode 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 2012 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 com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
import org.gradle.api.Action;
import org.gradle.api.Task;
import org.gradle.api.internal.TaskInternal;
import org.gradle.internal.deprecation.DeprecationLogger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.NavigableSet;
import java.util.Set;
public abstract class TaskNode extends Node {
private static final Logger LOGGER = LoggerFactory.getLogger(TaskNode.class);
private final NavigableSet mustSuccessors = Sets.newTreeSet();
private final Set mustPredecessors = Sets.newHashSet();
private final NavigableSet shouldSuccessors = Sets.newTreeSet();
private final NavigableSet finalizers = Sets.newTreeSet();
private final NavigableSet finalizingSuccessors = Sets.newTreeSet();
@Override
public boolean doCheckDependenciesComplete() {
if (!super.doCheckDependenciesComplete()) {
return false;
}
LOGGER.debug("Checking if all must successors are complete for {}", this);
for (Node dependency : mustSuccessors) {
if (!dependency.isComplete()) {
return false;
}
}
LOGGER.debug("Checking if all finalizing successors are complete for {}", this);
for (Node dependency : finalizingSuccessors) {
if (!dependency.isComplete()) {
return false;
}
}
LOGGER.debug("All task dependencies are complete for {}", this);
return true;
}
public Set getMustSuccessors() {
return mustSuccessors;
}
@Override
public Set getFinalizers() {
return finalizers;
}
public Set getFinalizingSuccessors() {
return finalizingSuccessors;
}
public Set getShouldSuccessors() {
return shouldSuccessors;
}
public void addMustSuccessor(TaskNode toNode) {
deprecateLifecycleHookReferencingNonLocalTask("mustRunAfter", toNode);
mustSuccessors.add(toNode);
toNode.mustPredecessors.add(this);
}
public void addFinalizingSuccessor(TaskNode finalized) {
finalizingSuccessors.add(finalized);
finalized.finalizers.add(this);
}
public void addFinalizer(TaskNode finalizerNode) {
deprecateLifecycleHookReferencingNonLocalTask("finalizedBy", finalizerNode);
finalizerNode.addFinalizingSuccessor(this);
}
public void addShouldSuccessor(Node toNode) {
deprecateLifecycleHookReferencingNonLocalTask("shouldRunAfter", toNode);
shouldSuccessors.add(toNode);
}
public void removeShouldSuccessor(TaskNode toNode) {
shouldSuccessors.remove(toNode);
}
@Override
public Iterable getAllSuccessors() {
return Iterables.concat(
shouldSuccessors,
finalizingSuccessors,
mustSuccessors,
super.getAllSuccessors()
);
}
@Override
public Iterable getAllSuccessorsInReverseOrder() {
return Iterables.concat(
super.getAllSuccessorsInReverseOrder(),
mustSuccessors.descendingSet(),
finalizingSuccessors.descendingSet(),
shouldSuccessors.descendingSet()
);
}
@Override
public Iterable getAllPredecessors() {
return Iterables.concat(mustPredecessors, finalizers, super.getAllPredecessors());
}
@Override
public boolean hasHardSuccessor(Node successor) {
if (super.hasHardSuccessor(successor)) {
return true;
}
if (!(successor instanceof TaskNode)) {
return false;
}
return getMustSuccessors().contains(successor)
|| getFinalizingSuccessors().contains(successor);
}
/**
* Attach an action to execute immediately after the successful completion of this task.
*
* This is used to ensure that dependency resolution metadata for a particular artifact is calculated immediately after that artifact is produced and cached, to avoid consuming tasks having to lock the producing project in order to calculate this metadata.
*
* This action should really be modelled as a real node in the graph. This 'post action' concept is intended to be a step in this direction.
*/
public abstract void appendPostAction(Action super Task> action);
public abstract Action super Task> getPostAction();
public abstract TaskInternal getTask();
@Override
public boolean isPublicNode() {
return true;
}
private void deprecateLifecycleHookReferencingNonLocalTask(String hookName, Node taskNode) {
if (taskNode instanceof TaskInAnotherBuild) {
DeprecationLogger.deprecateAction("Using " + hookName + " to reference tasks from another build")
.willBecomeAnErrorInGradle7()
.withUpgradeGuideSection(6, "referencing_tasks_from_included_builds")
.nagUser();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy