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);
}
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;
}
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
}
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());
}
}
}
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);
}
Aggregations