use of org.gradle.api.Task in project gradle by gradle.
the class DefaultTaskExecutionGraph method getDependencies.
@Override
public Set<Task> getDependencies(Task task) {
Node node = executionPlan.getNode(task);
ImmutableSet.Builder<Task> builder = ImmutableSet.builder();
for (Node dependencyNode : node.getDependencySuccessors()) {
if (dependencyNode instanceof TaskNode) {
builder.add(((TaskNode) dependencyNode).getTask());
}
}
return builder.build();
}
use of org.gradle.api.Task in project gradle by gradle.
the class TaskFactory method create.
@Override
@SuppressWarnings("deprecation")
public <S extends Task> S create(final TaskIdentity<S> identity, @Nullable final Object[] constructorArgs) {
if (!Task.class.isAssignableFrom(identity.type)) {
throw new InvalidUserDataException(String.format("Cannot create task '%s' of type '%s' as it does not implement the Task interface.", identity.identityPath.toString(), identity.type.getSimpleName()));
}
NameValidator.validate(identity.name, "task name", "");
final Class<? extends DefaultTask> implType;
if (identity.type == Task.class) {
implType = DefaultTask.class;
} else if (DefaultTask.class.isAssignableFrom(identity.type)) {
implType = identity.type.asSubclass(DefaultTask.class);
} else if (identity.type == org.gradle.api.internal.AbstractTask.class || identity.type == TaskInternal.class) {
throw new InvalidUserDataException(String.format("Cannot create task '%s' of type '%s' as this type is not supported for task registration.", identity.identityPath.toString(), identity.type.getSimpleName()));
} else {
throw new InvalidUserDataException(String.format("Cannot create task '%s' of type '%s' as directly extending AbstractTask is not supported.", identity.identityPath.toString(), identity.type.getSimpleName()));
}
Describable displayName = Describables.withTypeAndName("task", identity.getIdentityPath());
return org.gradle.api.internal.AbstractTask.injectIntoNewInstance(project, identity, new Callable<S>() {
@Override
public S call() {
try {
Task instance;
if (constructorArgs != null) {
instance = instantiationScheme.instantiator().newInstanceWithDisplayName(implType, displayName, constructorArgs);
} else {
instance = instantiationScheme.deserializationInstantiator().newInstance(implType, org.gradle.api.internal.AbstractTask.class);
}
return identity.type.cast(instance);
} catch (ObjectInstantiationException e) {
throw new TaskInstantiationException(String.format("Could not create task of type '%s'.", identity.type.getSimpleName()), e.getCause());
}
}
});
}
use of org.gradle.api.Task in project gradle by gradle.
the class DefaultProject method getTasksByName.
@Override
public Set<Task> getTasksByName(final String name, boolean recursive) {
if (isNullOrEmpty(name)) {
throw new InvalidUserDataException("Name is not specified!");
}
final Set<Task> foundTasks = new HashSet<Task>();
Action<Project> action = new Action<Project>() {
@Override
public void execute(Project project) {
// Don't force evaluation of rules here, let the task container do what it needs to
((ProjectInternal) project).getOwner().ensureTasksDiscovered();
Task task = project.getTasks().findByName(name);
if (task != null) {
foundTasks.add(task);
}
}
};
if (recursive) {
allprojects(action);
} else {
action.execute(this);
}
return foundTasks;
}
use of org.gradle.api.Task in project gradle by gradle.
the class LazyPublishArtifact method getDelegate.
private PublishArtifactInternal getDelegate() {
if (delegate == null) {
Object value = provider.get();
if (value instanceof FileSystemLocation) {
FileSystemLocation location = (FileSystemLocation) value;
delegate = fromFile(location.getAsFile());
} else if (value instanceof File) {
delegate = fromFile((File) value);
} else if (value instanceof AbstractArchiveTask) {
delegate = new ArchivePublishArtifact((AbstractArchiveTask) value);
} else if (value instanceof Task) {
delegate = fromFile(((Task) value).getOutputs().getFiles().getSingleFile());
} else if (fileResolver != null) {
delegate = fromFile(fileResolver.resolve(value));
} else {
throw new InvalidUserDataException(String.format("Cannot convert provided value (%s) to a file.", value));
}
}
return delegate;
}
use of org.gradle.api.Task in project gradle by gradle.
the class SkipTaskWithNoActionsExecuter method execute.
@Override
public TaskExecuterResult execute(TaskInternal task, TaskStateInternal state, TaskExecutionContext context) {
if (!task.hasTaskActions()) {
LOGGER.info("Skipping {} as it has no actions.", task);
boolean upToDate = true;
for (Task dependency : taskExecutionGraph.getDependencies(task)) {
if (!dependency.getState().getSkipped()) {
upToDate = false;
break;
}
}
state.setActionable(false);
state.setOutcome(upToDate ? TaskExecutionOutcome.UP_TO_DATE : TaskExecutionOutcome.EXECUTED);
return TaskExecuterResult.WITHOUT_OUTPUTS;
}
return executer.execute(task, state, context);
}
Aggregations