Search in sources :

Example 21 with TaskInternal

use of org.gradle.api.internal.TaskInternal in project gradle by gradle.

the class TestExecutionResultEvaluator method started.

@Override
public void started(BuildOperationInternal buildOperation, OperationStartEvent startEvent) {
    if (!(buildOperation.getOperationDescriptor() instanceof TaskOperationDescriptor)) {
        return;
    }
    TaskInternal task = ((TaskOperationDescriptor) buildOperation.getOperationDescriptor()).getTask();
    runningTasks.put(buildOperation.getId(), task.getPath());
}
Also used : TaskInternal(org.gradle.api.internal.TaskInternal) TaskOperationDescriptor(org.gradle.api.execution.internal.TaskOperationDescriptor)

Example 22 with TaskInternal

use of org.gradle.api.internal.TaskInternal in project gradle by gradle.

the class DefaultTaskExecutionPlan method addToTaskGraph.

public void addToTaskGraph(Collection<? extends Task> tasks) {
    List<TaskInfo> queue = new ArrayList<TaskInfo>();
    List<Task> sortedTasks = new ArrayList<Task>(tasks);
    Collections.sort(sortedTasks);
    for (Task task : sortedTasks) {
        TaskInfo node = nodeFactory.createNode(task);
        if (node.isMustNotRun()) {
            requireWithDependencies(node);
        } else if (filter.isSatisfiedBy(task)) {
            node.require();
        }
        entryTasks.add(node);
        queue.add(node);
    }
    Set<TaskInfo> visiting = new HashSet<TaskInfo>();
    CachingTaskDependencyResolveContext context = new CachingTaskDependencyResolveContext();
    while (!queue.isEmpty()) {
        TaskInfo node = queue.get(0);
        if (node.getDependenciesProcessed()) {
            // Have already visited this task - skip it
            queue.remove(0);
            continue;
        }
        TaskInternal task = node.getTask();
        boolean filtered = !filter.isSatisfiedBy(task);
        if (filtered) {
            // Task is not required - skip it
            queue.remove(0);
            node.dependenciesProcessed();
            node.doNotRequire();
            filteredTasks.add(task);
            continue;
        }
        if (visiting.add(node)) {
            // Have not seen this task before - add its dependencies to the head of the queue and leave this
            // task in the queue
            // Make sure it has been configured
            ((TaskContainerInternal) task.getProject().getTasks()).prepareForExecution(task);
            Set<? extends Task> dependsOnTasks = context.getDependencies(task, task.getTaskDependencies());
            for (Task dependsOnTask : dependsOnTasks) {
                TaskInfo targetNode = nodeFactory.createNode(dependsOnTask);
                node.addDependencySuccessor(targetNode);
                if (!visiting.contains(targetNode)) {
                    queue.add(0, targetNode);
                }
            }
            for (Task finalizerTask : context.getDependencies(task, task.getFinalizedBy())) {
                TaskInfo targetNode = nodeFactory.createNode(finalizerTask);
                addFinalizerNode(node, targetNode);
                if (!visiting.contains(targetNode)) {
                    queue.add(0, targetNode);
                }
            }
            for (Task mustRunAfter : context.getDependencies(task, task.getMustRunAfter())) {
                TaskInfo targetNode = nodeFactory.createNode(mustRunAfter);
                node.addMustSuccessor(targetNode);
            }
            for (Task shouldRunAfter : context.getDependencies(task, task.getShouldRunAfter())) {
                TaskInfo targetNode = nodeFactory.createNode(shouldRunAfter);
                node.addShouldSuccessor(targetNode);
            }
            if (node.isRequired()) {
                for (TaskInfo successor : node.getDependencySuccessors()) {
                    if (filter.isSatisfiedBy(successor.getTask())) {
                        successor.require();
                    }
                }
            } else {
                tasksInUnknownState.add(node);
            }
        } else {
            // Have visited this task's dependencies - add it to the graph
            queue.remove(0);
            visiting.remove(node);
            node.dependenciesProcessed();
        }
    }
    resolveTasksInUnknownState();
}
Also used : CachingTaskDependencyResolveContext(org.gradle.api.internal.tasks.CachingTaskDependencyResolveContext) Task(org.gradle.api.Task) TaskInternal(org.gradle.api.internal.TaskInternal) ArrayList(java.util.ArrayList) TaskContainerInternal(org.gradle.api.internal.tasks.TaskContainerInternal) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 23 with TaskInternal

use of org.gradle.api.internal.TaskInternal in project gradle by gradle.

the class IvyPublishPlugin method disableGradleMetadataGenerationIfCustomLayout.

private void disableGradleMetadataGenerationIfCustomLayout(NamedDomainObjectList<IvyArtifactRepository> repositories, GenerateModuleMetadata generateTask) {
    AtomicBoolean didWarn = new AtomicBoolean();
    Spec<? super Task> checkStandardLayout = task -> {
        boolean standard = repositories.stream().allMatch(this::hasStandardPattern);
        if (!standard && !didWarn.getAndSet(true)) {
            LOGGER.warn("Publication of Gradle Module Metadata is disabled because you have configured an Ivy repository with a non-standard layout");
        }
        return standard;
    };
    Spec<TaskInternal> spec = new AndSpec<TaskInternal>(generateTask.getOnlyIf(), checkStandardLayout);
    generateTask.setOnlyIf(Cast.<Spec<? super Task>>uncheckedCast(spec));
}
Also used : NamedDomainObjectFactory(org.gradle.api.NamedDomainObjectFactory) VersionMappingStrategyInternal(org.gradle.api.publish.internal.versionmapping.VersionMappingStrategyInternal) Path(org.gradle.model.Path) PluginManager(org.gradle.api.plugins.PluginManager) IvyArtifactNotationParserFactory(org.gradle.api.publish.ivy.internal.artifact.IvyArtifactNotationParserFactory) GenerateModuleMetadata(org.gradle.api.publish.tasks.GenerateModuleMetadata) NamedDomainObjectList(org.gradle.api.NamedDomainObjectList) Task(org.gradle.api.Task) PublishingExtension(org.gradle.api.publish.PublishingExtension) PublishingPlugin(org.gradle.api.publish.plugins.PublishingPlugin) IvyPublicationIdentity(org.gradle.api.publish.ivy.internal.publisher.IvyPublicationIdentity) TaskProvider(org.gradle.api.tasks.TaskProvider) ExtensionContainer(org.gradle.api.plugins.ExtensionContainer) IvyArtifact(org.gradle.api.publish.ivy.IvyArtifact) Project(org.gradle.api.Project) Set(java.util.Set) NamedDomainObjectSet(org.gradle.api.NamedDomainObjectSet) GenerateIvyDescriptor(org.gradle.api.publish.ivy.tasks.GenerateIvyDescriptor) IvyPublication(org.gradle.api.publish.ivy.IvyPublication) List(java.util.List) Spec(org.gradle.api.specs.Spec) TaskContainer(org.gradle.api.tasks.TaskContainer) AndSpec(org.gradle.api.specs.AndSpec) IvyRepositoryDescriptor(org.gradle.api.internal.artifacts.repositories.descriptor.IvyRepositoryDescriptor) NotationParser(org.gradle.internal.typeconversion.NotationParser) PublishToIvyRepository(org.gradle.api.publish.ivy.tasks.PublishToIvyRepository) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DefaultIvyPublicationIdentity(org.gradle.api.publish.ivy.internal.publication.DefaultIvyPublicationIdentity) Logger(org.gradle.api.logging.Logger) Module(org.gradle.api.internal.artifacts.Module) SourceSet(org.gradle.api.tasks.SourceSet) Inject(javax.inject.Inject) DefaultVersionMappingStrategy(org.gradle.api.publish.ivy.internal.versionmapping.DefaultVersionMappingStrategy) DirectoryProperty(org.gradle.api.file.DirectoryProperty) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer) DefaultIvyPublication(org.gradle.api.publish.ivy.internal.publication.DefaultIvyPublication) StringUtils.capitalize(org.apache.commons.lang.StringUtils.capitalize) Usage(org.gradle.api.attributes.Usage) TaskInternal(org.gradle.api.internal.TaskInternal) JavaPlatformPlugin(org.gradle.api.plugins.JavaPlatformPlugin) Cast(org.gradle.internal.Cast) RepositoryDescriptor(org.gradle.api.internal.artifacts.repositories.descriptor.RepositoryDescriptor) Instantiator(org.gradle.internal.reflect.Instantiator) IvyPublicationInternal(org.gradle.api.publish.ivy.internal.publication.IvyPublicationInternal) FileResolver(org.gradle.api.internal.file.FileResolver) ObjectFactory(org.gradle.api.model.ObjectFactory) Logging(org.gradle.api.logging.Logging) DefaultIvyArtifactRepository(org.gradle.api.internal.artifacts.repositories.DefaultIvyArtifactRepository) DependencyMetaDataProvider(org.gradle.api.internal.artifacts.configurations.DependencyMetaDataProvider) Plugin(org.gradle.api.Plugin) IvyArtifactRepository(org.gradle.api.artifacts.repositories.IvyArtifactRepository) AndSpec(org.gradle.api.specs.AndSpec) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TaskInternal(org.gradle.api.internal.TaskInternal)

Example 24 with TaskInternal

use of org.gradle.api.internal.TaskInternal in project gradle by gradle.

the class TaskOperationMapper method createFinishedEvent.

@Override
public InternalOperationFinishedProgressEvent createFinishedEvent(DefaultTaskDescriptor descriptor, ExecuteTaskBuildOperationDetails details, OperationFinishEvent finishEvent) {
    TaskInternal task = details.getTask();
    AbstractTaskResult taskResult = operationResultPostProcessor.process(toTaskResult(task, finishEvent), descriptor.getId());
    return new DefaultTaskFinishedProgressEvent(finishEvent.getEndTime(), descriptor, taskResult);
}
Also used : DefaultTaskFinishedProgressEvent(org.gradle.internal.build.event.types.DefaultTaskFinishedProgressEvent) TaskInternal(org.gradle.api.internal.TaskInternal) AbstractTaskResult(org.gradle.internal.build.event.types.AbstractTaskResult)

Example 25 with TaskInternal

use of org.gradle.api.internal.TaskInternal in project gradle by gradle.

the class DefaultBuildController method checkForCyclesFor.

private void checkForCyclesFor(TaskInternal task, Set<TaskInternal> visited, Set<TaskInternal> visiting) {
    if (visited.contains(task)) {
        // Already checked
        return;
    }
    if (!visiting.add(task)) {
        // Visiting dependencies -> have found a cycle
        CachingDirectedGraphWalker<TaskInternal, Void> graphWalker = new CachingDirectedGraphWalker<>((node, values, connectedNodes) -> visitDependenciesOf(node, connectedNodes::add));
        graphWalker.add(task);
        List<Set<TaskInternal>> cycles = graphWalker.findCycles();
        Set<TaskInternal> cycle = cycles.get(0);
        DirectedGraphRenderer<TaskInternal> graphRenderer = new DirectedGraphRenderer<>((node, output) -> output.withStyle(StyledTextOutput.Style.Identifier).text(node.getIdentityPath()), (node, values, connectedNodes) -> visitDependenciesOf(node, dep -> {
            if (cycle.contains(dep)) {
                connectedNodes.add(dep);
            }
        }));
        StringWriter writer = new StringWriter();
        graphRenderer.renderTo(task, writer);
        throw new CircularReferenceException(String.format("Circular dependency between the following tasks:%n%s", writer));
    }
    visitDependenciesOf(task, dep -> checkForCyclesFor(dep, visited, visiting));
    visiting.remove(task);
    visited.add(task);
}
Also used : TaskNodeFactory(org.gradle.execution.plan.TaskNodeFactory) BuildLifecycleController(org.gradle.internal.build.BuildLifecycleController) BuildState(org.gradle.internal.build.BuildState) BuildOperationRef(org.gradle.internal.operations.BuildOperationRef) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) TaskNode(org.gradle.execution.plan.TaskNode) UncheckedException(org.gradle.internal.UncheckedException) LinkedHashSet(java.util.LinkedHashSet) ExecutorService(java.util.concurrent.ExecutorService) CircularReferenceException(org.gradle.api.CircularReferenceException) TaskInternal(org.gradle.api.internal.TaskInternal) Node(org.gradle.execution.plan.Node) GradleInternal(org.gradle.api.internal.GradleInternal) DirectedGraphRenderer(org.gradle.internal.graph.DirectedGraphRenderer) ReentrantLock(java.util.concurrent.locks.ReentrantLock) StringWriter(java.io.StringWriter) BuildWorkGraph(org.gradle.internal.build.BuildWorkGraph) Set(java.util.Set) ExecutionResult(org.gradle.internal.build.ExecutionResult) StyledTextOutput(org.gradle.internal.logging.text.StyledTextOutput) ExportedTaskNode(org.gradle.internal.build.ExportedTaskNode) Consumer(java.util.function.Consumer) List(java.util.List) Condition(java.util.concurrent.locks.Condition) Lock(java.util.concurrent.locks.Lock) CurrentBuildOperationRef(org.gradle.internal.operations.CurrentBuildOperationRef) CachingDirectedGraphWalker(org.gradle.internal.graph.CachingDirectedGraphWalker) WorkerLeaseService(org.gradle.internal.work.WorkerLeaseService) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) StringWriter(java.io.StringWriter) TaskInternal(org.gradle.api.internal.TaskInternal) DirectedGraphRenderer(org.gradle.internal.graph.DirectedGraphRenderer) CircularReferenceException(org.gradle.api.CircularReferenceException) CachingDirectedGraphWalker(org.gradle.internal.graph.CachingDirectedGraphWalker)

Aggregations

TaskInternal (org.gradle.api.internal.TaskInternal)28 Task (org.gradle.api.Task)7 TaskStateInternal (org.gradle.api.internal.tasks.TaskStateInternal)5 TaskOperationDescriptor (org.gradle.api.execution.internal.TaskOperationDescriptor)4 TaskExecutionContext (org.gradle.api.internal.tasks.TaskExecutionContext)4 Closure (groovy.lang.Closure)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 LinkedHashSet (java.util.LinkedHashSet)3 List (java.util.List)3 Action (org.gradle.api.Action)3 InvalidUserDataException (org.gradle.api.InvalidUserDataException)3 Set (java.util.Set)2 DefaultTask (org.gradle.api.DefaultTask)2 ProjectInternal (org.gradle.api.internal.project.ProjectInternal)2 DefaultTaskOutputs (org.gradle.api.internal.tasks.DefaultTaskOutputs)2 TaskExecuter (org.gradle.api.internal.tasks.TaskExecuter)2 PropertyWalker (org.gradle.api.internal.tasks.properties.PropertyWalker)2 TaskOutputs (org.gradle.api.tasks.TaskOutputs)2 ServiceRegistry (org.gradle.internal.service.ServiceRegistry)2