use of org.gradle.api.tasks.TaskInstantiationException in project gradle by gradle.
the class TaskFactory method create.
@Override
public <S extends Task> S create(String name, final Class<S> type, final Object... args) {
if (!Task.class.isAssignableFrom(type)) {
throw new InvalidUserDataException(String.format("Cannot create task of type '%s' as it does not implement the Task interface.", type.getSimpleName()));
}
NameValidator.validate(name, "task name", "");
final Class<? extends Task> generatedType;
if (type.isAssignableFrom(DefaultTask.class)) {
generatedType = generator.generate(DefaultTask.class);
} else {
generatedType = generator.generate(type);
}
return type.cast(AbstractTask.injectIntoNewInstance(project, name, type, new Callable<Task>() {
public Task call() throws Exception {
try {
if (args != null) {
return instantiator.newInstance(generatedType, args);
}
return instantiator.newInstance(generatedType);
} catch (ObjectInstantiationException e) {
throw new TaskInstantiationException(String.format("Could not create task of type '%s'.", type.getSimpleName()), e.getCause());
}
}
}));
}
use of org.gradle.api.tasks.TaskInstantiationException in project gradle by gradle.
the class IncludedBuildTaskReferenceResolver method constructTask.
@Override
public Task constructTask(final TaskReference reference, TaskContainer tasks) {
if (!(reference instanceof IncludedBuildTaskReference)) {
return null;
}
final IncludedBuildTaskReference ref = (IncludedBuildTaskReference) reference;
final BuildIdentifier sourceBuild = buildIdentity.getCurrentBuild();
final BuildIdentifier targetBuild = new DefaultBuildIdentifier(ref.getBuildName());
includedBuilds.addTask(sourceBuild, targetBuild, ref.getTaskPath());
String delegateTaskName = ref.getName();
Task task = tasks.findByName(delegateTaskName);
if (task == null) {
return tasks.create(delegateTaskName, CompositeBuildTaskDelegate.class, new Action<CompositeBuildTaskDelegate>() {
@Override
public void execute(CompositeBuildTaskDelegate compositeBuildTaskDelegate) {
compositeBuildTaskDelegate.setBuild(targetBuild);
compositeBuildTaskDelegate.setTaskPath(ref.getTaskPath());
}
});
}
if (task instanceof CompositeBuildTaskDelegate) {
return task;
}
throw new TaskInstantiationException("Cannot create delegating task '" + delegateTaskName + "' as task with same name already exists.");
}
Aggregations