Search in sources :

Example 1 with Describable

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());
    }
}
Also used : Describable(org.gradle.api.Describable)

Example 2 with Describable

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());
            }
        }
    });
}
Also used : Task(org.gradle.api.Task) DefaultTask(org.gradle.api.DefaultTask) ObjectInstantiationException(org.gradle.api.reflect.ObjectInstantiationException) Describable(org.gradle.api.Describable) TaskInternal(org.gradle.api.internal.TaskInternal) TaskInstantiationException(org.gradle.api.tasks.TaskInstantiationException) InvalidUserDataException(org.gradle.api.InvalidUserDataException) DefaultTask(org.gradle.api.DefaultTask)

Example 3 with Describable

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)));
    }
}
Also used : Describable(org.gradle.api.Describable)

Aggregations

Describable (org.gradle.api.Describable)3 DefaultTask (org.gradle.api.DefaultTask)1 InvalidUserDataException (org.gradle.api.InvalidUserDataException)1 Task (org.gradle.api.Task)1 TaskInternal (org.gradle.api.internal.TaskInternal)1 ObjectInstantiationException (org.gradle.api.reflect.ObjectInstantiationException)1 TaskInstantiationException (org.gradle.api.tasks.TaskInstantiationException)1