use of org.gradle.api.Describable in project gradle by gradle.
the class Describables method appendDisplayName.
private static void appendDisplayName(Object src, StringBuilder stringBuilder) {
if (src instanceof Describable) {
Describable describable = (Describable) src;
stringBuilder.append(describable.getDisplayName());
} else {
stringBuilder.append(src.toString());
}
}
use of org.gradle.api.Describable 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.Describable in project gradle by gradle.
the class Describables method appendCapDisplayName.
private static void appendCapDisplayName(Object src, StringBuilder stringBuilder) {
if (src instanceof DisplayName) {
DisplayName displayName = (DisplayName) src;
stringBuilder.append(displayName.getCapitalizedDisplayName());
} else {
int pos = stringBuilder.length();
if (src instanceof Describable) {
Describable describable = (Describable) src;
stringBuilder.append(describable.getDisplayName());
} else {
stringBuilder.append(src.toString());
}
stringBuilder.setCharAt(pos, Character.toUpperCase(stringBuilder.charAt(pos)));
}
}
Aggregations