Search in sources :

Example 1 with PropertyWalker

use of org.gradle.api.internal.tasks.properties.PropertyWalker in project gradle by gradle.

the class DefaultTaskExecutionPlan method getResolvedTaskMutationInfo.

private TaskMutationInfo getResolvedTaskMutationInfo(TaskInfo taskInfo) {
    TaskInternal task = taskInfo.getTask();
    TaskMutationInfo taskMutationInfo = taskMutations.get(taskInfo);
    if (!taskMutationInfo.resolved) {
        ProjectInternal project = (ProjectInternal) task.getProject();
        ServiceRegistry serviceRegistry = project.getServices();
        PathToFileResolver resolver = serviceRegistry.get(PathToFileResolver.class);
        PropertyWalker propertyWalker = serviceRegistry.get(PropertyWalker.class);
        TaskProperties taskProperties = DefaultTaskProperties.resolve(propertyWalker, resolver, task);
        taskMutationInfo.outputPaths.addAll(getOutputPaths(canonicalizedFileCache, taskInfo, taskProperties.getOutputFiles(), taskProperties.getLocalStateFiles()));
        taskMutationInfo.destroyablePaths.addAll(getDestroyablePaths(canonicalizedFileCache, taskInfo, taskProperties.getDestroyableFiles()));
        taskMutationInfo.hasFileInputs = !taskProperties.getInputFileProperties().isEmpty();
        taskMutationInfo.hasOutputs = taskProperties.hasDeclaredOutputs();
        taskMutationInfo.hasLocalState = !taskProperties.getLocalStateFiles().isEmpty();
        taskMutationInfo.resolved = true;
    }
    return taskMutationInfo;
}
Also used : PathToFileResolver(org.gradle.internal.file.PathToFileResolver) PropertyWalker(org.gradle.api.internal.tasks.properties.PropertyWalker) TaskInternal(org.gradle.api.internal.TaskInternal) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) TaskProperties(org.gradle.api.internal.tasks.execution.TaskProperties) DefaultTaskProperties(org.gradle.api.internal.tasks.execution.DefaultTaskProperties) ServiceRegistry(org.gradle.internal.service.ServiceRegistry)

Example 2 with PropertyWalker

use of org.gradle.api.internal.tasks.properties.PropertyWalker in project gradle by gradle.

the class LocalTaskNode method resolveMutations.

@Override
public void resolveMutations() {
    final LocalTaskNode taskNode = this;
    final TaskInternal task = getTask();
    final MutationInfo mutations = getMutationInfo();
    ProjectInternal project = (ProjectInternal) task.getProject();
    ServiceRegistry serviceRegistry = project.getServices();
    final FileCollectionFactory fileCollectionFactory = serviceRegistry.get(FileCollectionFactory.class);
    PropertyWalker propertyWalker = serviceRegistry.get(PropertyWalker.class);
    try {
        taskProperties = DefaultTaskProperties.resolve(propertyWalker, fileCollectionFactory, task);
        addOutputFilesToMutations(taskProperties.getOutputFileProperties());
        addLocalStateFilesToMutations(taskProperties.getLocalStateFiles());
        addDestroyablesToMutations(taskProperties.getDestroyableFiles());
        mutations.hasFileInputs = !taskProperties.getInputFileProperties().isEmpty();
    } catch (Exception e) {
        throw new TaskExecutionException(task, e);
    }
    mutations.resolved = true;
    if (!mutations.destroyablePaths.isEmpty()) {
        if (mutations.hasOutputs) {
            throw new IllegalStateException("Task " + taskNode + " has both outputs and destroyables defined.  A task can define either outputs or destroyables, but not both.");
        }
        if (mutations.hasFileInputs) {
            throw new IllegalStateException("Task " + taskNode + " has both inputs and destroyables defined.  A task can define either inputs or destroyables, but not both.");
        }
        if (mutations.hasLocalState) {
            throw new IllegalStateException("Task " + taskNode + " has both local state and destroyables defined.  A task can define either local state or destroyables, but not both.");
        }
    }
}
Also used : TaskExecutionException(org.gradle.api.tasks.TaskExecutionException) PropertyWalker(org.gradle.api.internal.tasks.properties.PropertyWalker) TaskInternal(org.gradle.api.internal.TaskInternal) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) ServiceRegistry(org.gradle.internal.service.ServiceRegistry) TaskExecutionException(org.gradle.api.tasks.TaskExecutionException) FileCollectionFactory(org.gradle.api.internal.file.FileCollectionFactory)

Example 3 with PropertyWalker

use of org.gradle.api.internal.tasks.properties.PropertyWalker in project gradle by gradle.

the class DefaultExecutionPlan method createOrdinalRelationships.

private void createOrdinalRelationships(Node node) {
    if (node instanceof TaskNode && ((TaskNode) node).getOrdinal() != TaskNode.UNKNOWN_ORDINAL) {
        TaskNode taskNode = (TaskNode) node;
        TaskClassifier taskClassifier = new TaskClassifier();
        ProjectInternal project = (ProjectInternal) taskNode.getTask().getProject();
        ServiceRegistry serviceRegistry = project.getServices();
        PropertyWalker propertyWalker = serviceRegistry.get(PropertyWalker.class);
        // Walk the properties of the task to determine if it is a destroyer or a producer (or neither)
        propertyWalker.visitProperties(taskNode.getTask(), TypeValidationContext.NOOP, taskClassifier);
        taskNode.getTask().getOutputs().visitRegisteredProperties(taskClassifier);
        ((TaskDestroyablesInternal) taskNode.getTask().getDestroyables()).visitRegisteredProperties(taskClassifier);
        ((TaskLocalStateInternal) taskNode.getTask().getLocalState()).visitRegisteredProperties(taskClassifier);
        if (taskClassifier.isDestroyer()) {
            // Create (or get) a destroyer ordinal node that depends on the dependencies of this task node
            Node ordinalNode = ordinalNodeAccess.getOrCreateDestroyableLocationNode(taskNode.getOrdinal());
            taskNode.getHardSuccessors().forEach(ordinalNode::addDependencySuccessor);
            if (taskNode.getOrdinal() > 0) {
                // Depend on any previous producer ordinal nodes (i.e. any producer ordinal nodes with a lower
                // ordinal)
                ordinalNodeAccess.getPrecedingProducerLocationNodes(taskNode.getOrdinal()).forEach(taskNode::addDependencySuccessor);
            }
        } else if (taskClassifier.isProducer()) {
            // Create (or get) a producer ordinal node that depends on the dependencies of this task node
            Node ordinalNode = ordinalNodeAccess.getOrCreateOutputLocationNode(taskNode.getOrdinal());
            taskNode.getHardSuccessors().forEach(ordinalNode::addDependencySuccessor);
            if (taskNode.getOrdinal() > 0) {
                // Depend on any previous destroyer ordinal nodes (i.e. any destroyer ordinal nodes with a lower
                // ordinal)
                ordinalNodeAccess.getPrecedingDestroyerLocationNodes(taskNode.getOrdinal()).forEach(taskNode::addDependencySuccessor);
            }
        }
    }
}
Also used : PropertyWalker(org.gradle.api.internal.tasks.properties.PropertyWalker) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) TaskDestroyablesInternal(org.gradle.api.internal.tasks.TaskDestroyablesInternal) ServiceRegistry(org.gradle.internal.service.ServiceRegistry) TaskLocalStateInternal(org.gradle.api.internal.tasks.TaskLocalStateInternal)

Aggregations

ProjectInternal (org.gradle.api.internal.project.ProjectInternal)3 PropertyWalker (org.gradle.api.internal.tasks.properties.PropertyWalker)3 ServiceRegistry (org.gradle.internal.service.ServiceRegistry)3 TaskInternal (org.gradle.api.internal.TaskInternal)2 FileCollectionFactory (org.gradle.api.internal.file.FileCollectionFactory)1 TaskDestroyablesInternal (org.gradle.api.internal.tasks.TaskDestroyablesInternal)1 TaskLocalStateInternal (org.gradle.api.internal.tasks.TaskLocalStateInternal)1 DefaultTaskProperties (org.gradle.api.internal.tasks.execution.DefaultTaskProperties)1 TaskProperties (org.gradle.api.internal.tasks.execution.TaskProperties)1 TaskExecutionException (org.gradle.api.tasks.TaskExecutionException)1 PathToFileResolver (org.gradle.internal.file.PathToFileResolver)1