Search in sources :

Example 31 with Task

use of org.gradle.api.Task in project gradle by gradle.

the class DefaultCacheScopeMapping method getBaseDirectory.

public File getBaseDirectory(Object scope, String key, VersionStrategy versionStrategy) {
    if (key.equalsIgnoreCase("projects") || key.equalsIgnoreCase("tasks") || !key.matches("\\p{Alpha}+[-//.\\w]*")) {
        throw new IllegalArgumentException(String.format("Unsupported cache key '%s'.", key));
    }
    File cacheRootDir = getRootDirectory(scope);
    String subDir = key;
    if (scope instanceof Project) {
        Project project = (Project) scope;
        subDir = "projects/" + project.getPath().replace(':', '_') + "/" + key;
    }
    if (scope instanceof Task) {
        Task task = (Task) scope;
        subDir = "tasks/" + task.getPath().replace(':', '_') + "/" + key;
    }
    return getCacheDir(cacheRootDir, versionStrategy, subDir);
}
Also used : Project(org.gradle.api.Project) Task(org.gradle.api.Task) File(java.io.File)

Example 32 with Task

use of org.gradle.api.Task in project gradle by gradle.

the class TaskFactory method createTask.

public TaskInternal createTask(Map<String, ?> args) {
    Map<String, Object> actualArgs = new HashMap<String, Object>(args);
    checkTaskArgsAndCreateDefaultValues(actualArgs);
    String name = actualArgs.get(Task.TASK_NAME).toString();
    if (!GUtil.isTrue(name)) {
        throw new InvalidUserDataException("The task name must be provided.");
    }
    Class<? extends TaskInternal> type = (Class) actualArgs.get(Task.TASK_TYPE);
    TaskInternal task = create(name, 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 = (Action<? super Task>) action;
        task.doFirst(taskAction);
    } else if (action != null) {
        Closure closure = (Closure) action;
        task.doFirst(closure);
    }
    return task;
}
Also used : Action(org.gradle.api.Action) AbstractTask(org.gradle.api.internal.AbstractTask) Task(org.gradle.api.Task) DefaultTask(org.gradle.api.DefaultTask) Closure(groovy.lang.Closure) HashMap(java.util.HashMap) InvalidUserDataException(org.gradle.api.InvalidUserDataException) TaskInternal(org.gradle.api.internal.TaskInternal)

Example 33 with Task

use of org.gradle.api.Task in project gradle by gradle.

the class BinarySourceTransformations method createTasksFor.

public void createTasksFor(BinarySpecInternal binary) {
    Set<LanguageSourceSetInternal> sourceSetsToCompile = getSourcesToCompile(binary);
    for (LanguageTransform<?, ?> languageTransform : prioritizedTransforms) {
        if (!languageTransform.applyToBinary(binary)) {
            continue;
        }
        LanguageSourceSetInternal sourceSetToCompile;
        while ((sourceSetToCompile = findSourceFor(languageTransform, sourceSetsToCompile)) != null) {
            sourceSetsToCompile.remove(sourceSetToCompile);
            final SourceTransformTaskConfig taskConfig = languageTransform.getTransformTask();
            String taskName = getTransformTaskName(languageTransform, taskConfig, binary, sourceSetToCompile);
            Task task = tasks.create(taskName, taskConfig.getTaskType());
            taskConfig.configureTask(task, binary, sourceSetToCompile, serviceRegistry);
            task.dependsOn(sourceSetToCompile);
            binary.getTasks().add(task);
            if (binary.hasCodependentSources() && taskConfig instanceof JointCompileTaskConfig) {
                JointCompileTaskConfig jointCompileTaskConfig = (JointCompileTaskConfig) taskConfig;
                Iterator<LanguageSourceSetInternal> candidateSourceSets = sourceSetsToCompile.iterator();
                while (candidateSourceSets.hasNext()) {
                    LanguageSourceSetInternal candidate = candidateSourceSets.next();
                    if (jointCompileTaskConfig.canTransform(candidate)) {
                        jointCompileTaskConfig.configureAdditionalTransform(task, candidate);
                        candidateSourceSets.remove();
                    }
                }
            }
        }
    }
// Should really fail here if sourcesToCompile is not empty: no transform for this source set in this binary
}
Also used : LanguageSourceSetInternal(org.gradle.language.base.internal.LanguageSourceSetInternal) Task(org.gradle.api.Task) SourceTransformTaskConfig(org.gradle.language.base.internal.SourceTransformTaskConfig) JointCompileTaskConfig(org.gradle.language.base.internal.JointCompileTaskConfig)

Example 34 with Task

use of org.gradle.api.Task in project gradle by gradle.

the class BuildInvocationsBuilder method findTasks.

private void findTasks(Project project, Map<String, LaunchableGradleTaskSelector> taskSelectors, Collection<String> visibleTasks) {
    for (Project child : project.getChildProjects().values()) {
        findTasks(child, taskSelectors, visibleTasks);
    }
    for (Task task : taskLister.listProjectTasks(project)) {
        // this way, for each task selector, its description will be the one from the selected task with the 'smallest' path
        if (!taskSelectors.containsKey(task.getName())) {
            LaunchableGradleTaskSelector taskSelector = new LaunchableGradleTaskSelector().setDescription(task.getDescription()).setPath(task.getPath());
            taskSelectors.put(task.getName(), taskSelector);
        } else {
            LaunchableGradleTaskSelector taskSelector = taskSelectors.get(task.getName());
            if (hasPathWithLowerOrdering(task, taskSelector)) {
                taskSelector.setDescription(task.getDescription()).setPath(task.getPath());
            }
        }
        // visible tasks are specified as those that have a non-empty group
        if (PublicTaskSpecification.INSTANCE.isSatisfiedBy(task)) {
            visibleTasks.add(task.getName());
        }
    }
}
Also used : Project(org.gradle.api.Project) ToolingModelBuilderSupport.buildFromTask(org.gradle.plugins.ide.internal.tooling.ToolingModelBuilderSupport.buildFromTask) LaunchableGradleTask(org.gradle.plugins.ide.internal.tooling.model.LaunchableGradleTask) Task(org.gradle.api.Task) LaunchableGradleTaskSelector(org.gradle.plugins.ide.internal.tooling.model.LaunchableGradleTaskSelector)

Example 35 with Task

use of org.gradle.api.Task in project gradle by gradle.

the class IdeaPlugin method createImlArtifact.

private static LocalComponentArtifactMetadata createImlArtifact(ProjectComponentIdentifier projectId, Project project) {
    String moduleName = project.getExtensions().getByType(IdeaModel.class).getModule().getName();
    File imlFile = new File(project.getProjectDir(), moduleName + ".iml");
    Task byName = project.getTasks().getByName("ideaModule");
    PublishArtifact publishArtifact = new DefaultPublishArtifact(moduleName, "iml", "iml", null, null, imlFile, byName);
    return new PublishArtifactLocalArtifactMetadata(projectId, publishArtifact);
}
Also used : Task(org.gradle.api.Task) DefaultPublishArtifact(org.gradle.api.internal.artifacts.publish.DefaultPublishArtifact) PublishArtifactLocalArtifactMetadata(org.gradle.internal.component.local.model.PublishArtifactLocalArtifactMetadata) DefaultPublishArtifact(org.gradle.api.internal.artifacts.publish.DefaultPublishArtifact) PublishArtifact(org.gradle.api.artifacts.PublishArtifact) File(java.io.File)

Aggregations

Task (org.gradle.api.Task)116 Test (org.junit.Test)21 File (java.io.File)18 DefaultTask (org.gradle.api.DefaultTask)16 Expectations (org.jmock.Expectations)14 Project (org.gradle.api.Project)12 ArrayList (java.util.ArrayList)10 IOException (java.io.IOException)6 Callable (java.util.concurrent.Callable)6 Action (org.gradle.api.Action)6 HashSet (java.util.HashSet)5 Map (java.util.Map)5 DefaultAndroidTask (com.android.build.gradle.internal.tasks.DefaultAndroidTask)4 List (java.util.List)4 Set (java.util.Set)4 InvalidUserDataException (org.gradle.api.InvalidUserDataException)4 TaskInternal (org.gradle.api.internal.TaskInternal)4 Spec (org.gradle.api.specs.Spec)4 TaskContainer (org.gradle.api.tasks.TaskContainer)4 TaskDependency (org.gradle.api.tasks.TaskDependency)4