use of org.gradle.api.internal.TaskInternal in project gradle by gradle.
the class ExecuteActionsTaskExecuter method executeIfValid.
private TaskExecuterResult executeIfValid(TaskInternal task, TaskStateInternal state, TaskExecutionContext context, TaskExecution work) {
ExecutionEngine.Request request = executionEngine.createRequest(work);
context.getTaskExecutionMode().getRebuildReason().ifPresent(request::forceNonIncremental);
request.withValidationContext(context.getValidationContext());
Result result = request.execute();
result.getExecutionResult().ifSuccessfulOrElse(executionResult -> state.setOutcome(TaskExecutionOutcome.valueOf(executionResult.getOutcome())), failure -> state.setOutcome(new TaskExecutionException(task, failure)));
return new TaskExecuterResult() {
@Override
public Optional<OriginMetadata> getReusedOutputOriginMetadata() {
return result.getReusedOutputOriginMetadata();
}
@Override
public boolean executedIncrementally() {
return result.getExecutionResult().map(executionResult -> executionResult.getOutcome() == ExecutionOutcome.EXECUTED_INCREMENTALLY).getOrMapFailure(throwable -> false);
}
@Override
public List<String> getExecutionReasons() {
return result.getExecutionReasons();
}
@Override
public CachingState getCachingState() {
return result.getCachingState();
}
};
}
use of org.gradle.api.internal.TaskInternal in project gradle by gradle.
the class DefaultTaskContainer method doCreate.
private Task doCreate(Map<String, ?> options, final Action<? super Task> configureAction) {
Map<String, ?> factoryOptions = options;
final boolean replace;
if (options.containsKey(Task.TASK_OVERWRITE)) {
factoryOptions = new HashMap<String, Object>(options);
Object replaceStr = factoryOptions.remove(Task.TASK_OVERWRITE);
replace = "true".equals(replaceStr.toString());
} else {
replace = false;
}
final Map<String, ?> actualArgs = checkTaskArgsAndCreateDefaultValues(factoryOptions);
final String name = actualArgs.get(Task.TASK_NAME).toString();
if (!GUtil.isTrue(name)) {
throw new InvalidUserDataException("The task name must be provided.");
}
final Class<? extends TaskInternal> type = Cast.uncheckedCast(actualArgs.get(Task.TASK_TYPE));
final TaskIdentity<? extends TaskInternal> identity = TaskIdentity.create(name, type, project);
return buildOperationExecutor.call(new CallableBuildOperation<Task>() {
@Override
public BuildOperationDescriptor.Builder description() {
return realizeDescriptor(identity, replace, true);
}
@Override
public Task call(BuildOperationContext context) {
try {
Object[] constructorArgs = getConstructorArgs(actualArgs);
TaskInternal task = createTask(identity, constructorArgs);
statistics.eagerTask(type);
Object dependsOnTasks = actualArgs.get(Task.TASK_DEPENDS_ON);
if (dependsOnTasks != null) {
task.dependsOn(dependsOnTasks);
}
Object description = actualArgs.get(Task.TASK_DESCRIPTION);
if (description != null) {
task.setDescription(description.toString());
}
Object group = actualArgs.get(Task.TASK_GROUP);
if (group != null) {
task.setGroup(group.toString());
}
Object action = actualArgs.get(Task.TASK_ACTION);
if (action instanceof Action) {
Action<? super Task> taskAction = Cast.uncheckedCast(action);
task.doFirst(taskAction);
} else if (action != null) {
Closure closure = (Closure) action;
task.doFirst(closure);
}
addTask(task, replace);
configureAction.execute(task);
context.setResult(REALIZE_RESULT);
return task;
} catch (Throwable t) {
throw taskCreationException(name, t);
}
}
});
}
use of org.gradle.api.internal.TaskInternal in project gradle by gradle.
the class LocalTaskNodeExecutor method execute.
@Override
public boolean execute(Node node, NodeExecutionContext context) {
if (node instanceof LocalTaskNode) {
LocalTaskNode localTaskNode = (LocalTaskNode) node;
TaskInternal task = localTaskNode.getTask();
TaskStateInternal state = task.getState();
if (state.getExecuted()) {
// This should move earlier in task scheduling, so that a worker thread does not even bother trying to run this task
return true;
}
ExecutionNodeAccessHierarchies.InputNodeAccessHierarchy inputHierarchy = context.getService(ExecutionNodeAccessHierarchies.InputNodeAccessHierarchy.class);
TaskExecutionContext ctx = new DefaultTaskExecutionContext(localTaskNode, localTaskNode.getTaskProperties(), localTaskNode.getValidationContext(), (historyMaintained, typeValidationContext) -> detectMissingDependencies(localTaskNode, historyMaintained, inputHierarchy, typeValidationContext));
TaskExecuter taskExecuter = context.getService(TaskExecuter.class);
taskExecuter.execute(task, state, ctx);
localTaskNode.getPostAction().execute(task);
return true;
} else {
return false;
}
}
Aggregations