Search in sources :

Example 1 with TaskContainerInternal

use of org.gradle.api.internal.tasks.TaskContainerInternal in project gradle by gradle.

the class DefaultProjectTaskLister method listProjectTasks.

@Override
public Collection<Task> listProjectTasks(Project project) {
    ProjectInternal projectInternal = (ProjectInternal) project;
    TaskContainerInternal tasks = projectInternal.getTasks();
    tasks.realize();
    return tasks;
}
Also used : TaskContainerInternal(org.gradle.api.internal.tasks.TaskContainerInternal)

Example 2 with TaskContainerInternal

use of org.gradle.api.internal.tasks.TaskContainerInternal in project gradle by gradle.

the class HelpTasksPlugin method apply.

@Override
public void apply(final ProjectInternal project) {
    final TaskContainerInternal tasks = project.getTasks();
    // static classes are used for the actions to avoid implicitly dragging project/tasks into the model registry
    String projectName = project.toString();
    tasks.addPlaceholderAction(ProjectInternal.HELP_TASK, Help.class, new HelpAction());
    tasks.addPlaceholderAction(ProjectInternal.PROJECTS_TASK, ProjectReportTask.class, new ProjectReportTaskAction(projectName));
    tasks.addPlaceholderAction(ProjectInternal.TASKS_TASK, TaskReportTask.class, new TaskReportTaskAction(projectName, project.getChildProjects().isEmpty()));
    tasks.addPlaceholderAction(PROPERTIES_TASK, PropertyReportTask.class, new PropertyReportTaskAction(projectName));
    tasks.addPlaceholderAction(DEPENDENCY_INSIGHT_TASK, DependencyInsightReportTask.class, new DependencyInsightReportTaskAction(projectName));
    tasks.addPlaceholderAction(DEPENDENCIES_TASK, DependencyReportTask.class, new DependencyReportTaskAction(projectName));
    tasks.addPlaceholderAction(BuildEnvironmentReportTask.TASK_NAME, BuildEnvironmentReportTask.class, new BuildEnvironmentReportTaskAction(projectName));
    tasks.addPlaceholderAction(COMPONENTS_TASK, ComponentReport.class, new ComponentReportAction(projectName));
    tasks.addPlaceholderAction(MODEL_TASK, ModelReport.class, new ModelReportAction(projectName));
    tasks.addPlaceholderAction(DEPENDENT_COMPONENTS_TASK, DependentComponentsReport.class, new DependentComponentsReportAction(projectName));
}
Also used : TaskContainerInternal(org.gradle.api.internal.tasks.TaskContainerInternal)

Example 3 with TaskContainerInternal

use of org.gradle.api.internal.tasks.TaskContainerInternal in project gradle by gradle.

the class TestUtility method attachTasks.

/**
     * This makes the tasks children of the root project. If you call this repeatedly on the same parentProject, any previous tasks will be replaced with the new ones.
     *
     * @param context the mock context
     * @param parentProject where to attach the sub projects. This must be a mock object.
     * @param taskArray the tasks to attach to the root. these must be mock objects. Pass in null or an empty array to set no tasks.
     */
public static void attachTasks(JUnit4Mockery context, final Project parentProject, Task... taskArray) {
    //first, make our project return our task container
    final TaskContainerInternal taskContainer = context.mock(TaskContainerInternal.class, "[taskcontainer]_" + parentProject.getName() + '_' + uniqueNameCounter++);
    context.checking(new Expectations() {

        {
            allowing(parentProject).getTasks();
            will(returnValue(taskContainer));
            allowing(taskContainer).realize();
        }
    });
    final Set<Task> set = //using a LinkedHashSet rather than TreeSet (which is what gradle uses) so I don't have to deal with compareTo() being called on mock objects.
    new LinkedHashSet<Task>();
    if (taskArray != null && taskArray.length != 0) {
        set.addAll(Arrays.asList(taskArray));
        //set the root project of the tasks
        for (int index = 0; index < taskArray.length; index++) {
            final Task task = taskArray[index];
            context.checking(new Expectations() {

                {
                    allowing(task).getProject();
                    will(returnValue(parentProject));
                }
            });
        }
    }
    //populate the task container (this may be an empty set)
    context.checking(new Expectations() {

        {
            allowing(taskContainer).iterator();
            will(returnIterator(set));
        }
    });
}
Also used : Expectations(org.jmock.Expectations) Task(org.gradle.api.Task) TaskContainerInternal(org.gradle.api.internal.tasks.TaskContainerInternal)

Example 4 with TaskContainerInternal

use of org.gradle.api.internal.tasks.TaskContainerInternal 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 5 with TaskContainerInternal

use of org.gradle.api.internal.tasks.TaskContainerInternal in project gradle by gradle.

the class CppBasePlugin method apply.

@Override
public void apply(final ProjectInternal project) {
    project.getPluginManager().apply(NativeBasePlugin.class);
    project.getPluginManager().apply(StandardToolChainsPlugin.class);
    final TaskContainerInternal tasks = project.getTasks();
    final DirectoryProperty buildDirectory = project.getLayout().getBuildDirectory();
    // Enable the use of Gradle metadata. This is a temporary opt-in switch until available by default
    project.getGradle().getServices().get(FeaturePreviews.class).enableFeature(GRADLE_METADATA);
    // Create the tasks for each C++ binary that is registered
    project.getComponents().withType(DefaultCppBinary.class, new Action<DefaultCppBinary>() {

        @Override
        public void execute(final DefaultCppBinary binary) {
            final Names names = binary.getNames();
            String language = "cpp";
            final NativePlatform currentPlatform = binary.getTargetPlatform();
            // TODO - make this lazy
            final NativeToolChainInternal toolChain = binary.getToolChain();
            Callable<List<File>> systemIncludes = new Callable<List<File>>() {

                @Override
                public List<File> call() {
                    PlatformToolProvider platformToolProvider = binary.getPlatformToolProvider();
                    return platformToolProvider.getSystemLibraries(ToolType.CPP_COMPILER).getIncludeDirs();
                }
            };
            CppCompile compile = tasks.create(names.getCompileTaskName(language), CppCompile.class);
            compile.includes(binary.getCompileIncludePath());
            compile.includes(systemIncludes);
            compile.source(binary.getCppSource());
            if (binary.isDebuggable()) {
                compile.setDebuggable(true);
            }
            if (binary.isOptimized()) {
                compile.setOptimized(true);
            }
            compile.getTargetPlatform().set(currentPlatform);
            compile.getToolChain().set(toolChain);
            compile.getObjectFileDir().set(buildDirectory.dir("obj/" + names.getDirName()));
            binary.getObjectsDir().set(compile.getObjectFileDir());
            binary.getCompileTask().set(compile);
        }
    });
    project.getComponents().withType(CppSharedLibrary.class, new Action<CppSharedLibrary>() {

        @Override
        public void execute(CppSharedLibrary library) {
            library.getCompileTask().get().setPositionIndependentCode(true);
        }
    });
    project.getComponents().withType(ProductionCppComponent.class, new Action<ProductionCppComponent>() {

        @Override
        public void execute(final ProductionCppComponent component) {
            project.afterEvaluate(new Action<Project>() {

                @Override
                public void execute(Project project) {
                    DefaultCppComponent componentInternal = (DefaultCppComponent) component;
                    publicationRegistry.registerPublication(project.getPath(), new DefaultProjectPublication(componentInternal.getDisplayName(), new SwiftPmTarget(component.getBaseName().get()), false));
                }
            });
        }
    });
}
Also used : Action(org.gradle.api.Action) Callable(java.util.concurrent.Callable) Names(org.gradle.language.nativeplatform.internal.Names) NativeToolChainInternal(org.gradle.nativeplatform.toolchain.internal.NativeToolChainInternal) List(java.util.List) CppSharedLibrary(org.gradle.language.cpp.CppSharedLibrary) FeaturePreviews(org.gradle.api.internal.FeaturePreviews) DefaultCppBinary(org.gradle.language.cpp.internal.DefaultCppBinary) SwiftPmTarget(org.gradle.swiftpm.internal.SwiftPmTarget) TaskContainerInternal(org.gradle.api.internal.tasks.TaskContainerInternal) ProductionCppComponent(org.gradle.language.cpp.ProductionCppComponent) Project(org.gradle.api.Project) DefaultCppComponent(org.gradle.language.cpp.internal.DefaultCppComponent) DirectoryProperty(org.gradle.api.file.DirectoryProperty) PlatformToolProvider(org.gradle.nativeplatform.toolchain.internal.PlatformToolProvider) NativePlatform(org.gradle.nativeplatform.platform.NativePlatform) CppCompile(org.gradle.language.cpp.tasks.CppCompile) DefaultProjectPublication(org.gradle.api.internal.artifacts.ivyservice.projectmodule.DefaultProjectPublication) File(java.io.File)

Aggregations

TaskContainerInternal (org.gradle.api.internal.tasks.TaskContainerInternal)6 Callable (java.util.concurrent.Callable)2 Action (org.gradle.api.Action)2 Project (org.gradle.api.Project)2 Task (org.gradle.api.Task)2 DirectoryProperty (org.gradle.api.file.DirectoryProperty)2 DefaultProjectPublication (org.gradle.api.internal.artifacts.ivyservice.projectmodule.DefaultProjectPublication)2 Names (org.gradle.language.nativeplatform.internal.Names)2 SwiftPmTarget (org.gradle.swiftpm.internal.SwiftPmTarget)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 FeaturePreviews (org.gradle.api.internal.FeaturePreviews)1 TaskInternal (org.gradle.api.internal.TaskInternal)1 CachingTaskDependencyResolveContext (org.gradle.api.internal.tasks.CachingTaskDependencyResolveContext)1 ProviderFactory (org.gradle.api.provider.ProviderFactory)1 CppSharedLibrary (org.gradle.language.cpp.CppSharedLibrary)1 ProductionCppComponent (org.gradle.language.cpp.ProductionCppComponent)1