Search in sources :

Example 1 with UnsupportedNotationException

use of org.gradle.internal.typeconversion.UnsupportedNotationException in project gradle by gradle.

the class DefaultTaskDependency method visitDependencies.

@Override
public void visitDependencies(TaskDependencyResolveContext context) {
    if (values.isEmpty()) {
        return;
    }
    Deque<Object> queue = new ArrayDeque<Object>(values);
    while (!queue.isEmpty()) {
        Object dependency = queue.removeFirst();
        if (dependency instanceof Buildable) {
            context.add(dependency);
        } else if (dependency instanceof Task) {
            context.add(dependency);
        } else if (dependency instanceof TaskDependency) {
            context.add(dependency);
        } else if (dependency instanceof Closure) {
            Closure closure = (Closure) dependency;
            Object closureResult = closure.call(context.getTask());
            if (closureResult != null) {
                queue.addFirst(closureResult);
            }
        } else if (dependency instanceof RealizableTaskCollection) {
            RealizableTaskCollection realizableTaskCollection = (RealizableTaskCollection) dependency;
            realizableTaskCollection.realizeRuleTaskTypes();
            addAllFirst(queue, realizableTaskCollection.toArray());
        } else if (dependency instanceof List) {
            List<?> list = (List) dependency;
            if (list instanceof RandomAccess) {
                for (int i = list.size() - 1; i >= 0; i--) {
                    queue.addFirst(list.get(i));
                }
            } else {
                ListIterator<?> iterator = list.listIterator(list.size());
                while (iterator.hasPrevious()) {
                    Object item = iterator.previous();
                    queue.addFirst(item);
                }
            }
        } else if (dependency instanceof Iterable) {
            Iterable<?> iterable = (Iterable) dependency;
            addAllFirst(queue, toArray(iterable, Object.class));
        } else if (dependency instanceof Map) {
            Map<?, ?> map = (Map) dependency;
            addAllFirst(queue, map.values().toArray());
        } else if (dependency instanceof Object[]) {
            Object[] array = (Object[]) dependency;
            addAllFirst(queue, array);
        } else if (dependency instanceof Callable) {
            Callable callable = (Callable) dependency;
            Object callableResult = uncheckedCall(callable);
            if (callableResult != null) {
                queue.addFirst(callableResult);
            }
        } else if (resolver != null && dependency instanceof TaskReference) {
            context.add(resolver.resolveTask((TaskReference) dependency));
        } else if (resolver != null && dependency instanceof CharSequence) {
            context.add(resolver.resolveTask(dependency.toString()));
        } else {
            List<String> formats = new ArrayList<String>();
            if (resolver != null) {
                formats.add("A String or CharSequence task name or path");
                formats.add("A TaskReference instance");
            }
            formats.add("A Task instance");
            formats.add("A Buildable instance");
            formats.add("A TaskDependency instance");
            formats.add("A Closure instance that returns any of the above types");
            formats.add("A Callable instance that returns any of the above types");
            formats.add("An Iterable, Collection, Map or array instance that contains any of the above types");
            throw new UnsupportedNotationException(dependency, String.format("Cannot convert %s to a task.", dependency), null, formats);
        }
    }
}
Also used : TaskDependency(org.gradle.api.tasks.TaskDependency) Task(org.gradle.api.Task) Closure(groovy.lang.Closure) RandomAccess(java.util.RandomAccess) ListIterator(java.util.ListIterator) ArrayDeque(java.util.ArrayDeque) Callable(java.util.concurrent.Callable) TaskReference(org.gradle.api.tasks.TaskReference) UnsupportedNotationException(org.gradle.internal.typeconversion.UnsupportedNotationException) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) Buildable(org.gradle.api.Buildable)

Example 2 with UnsupportedNotationException

use of org.gradle.internal.typeconversion.UnsupportedNotationException in project gradle by gradle.

the class DefaultComponentSelectionRules method createSpecRuleActionFromId.

private SpecRuleAction<? super ComponentSelection> createSpecRuleActionFromId(Object id, RuleAction<? super ComponentSelection> ruleAction) {
    final ModuleIdentifier moduleIdentifier;
    try {
        moduleIdentifier = moduleIdentifierNotationParser.parseNotation(id);
    } catch (UnsupportedNotationException e) {
        throw new InvalidUserCodeException(String.format(INVALID_SPEC_ERROR, id == null ? "null" : id.toString()), e);
    }
    Spec<ComponentSelection> spec = new ComponentSelectionMatchingSpec(moduleIdentifier);
    return new SpecRuleAction<ComponentSelection>(ruleAction, spec);
}
Also used : InvalidUserCodeException(org.gradle.api.InvalidUserCodeException) SpecRuleAction(org.gradle.internal.rules.SpecRuleAction) UnsupportedNotationException(org.gradle.internal.typeconversion.UnsupportedNotationException) ModuleIdentifier(org.gradle.api.artifacts.ModuleIdentifier) ComponentSelection(org.gradle.api.artifacts.ComponentSelection)

Example 3 with UnsupportedNotationException

use of org.gradle.internal.typeconversion.UnsupportedNotationException in project gradle by gradle.

the class DefaultComponentMetadataHandler method createSpecRuleActionForModule.

private SpecRuleAction<? super ComponentMetadataDetails> createSpecRuleActionForModule(Object id, RuleAction<? super ComponentMetadataDetails> ruleAction) {
    ModuleIdentifier moduleIdentifier;
    try {
        moduleIdentifier = moduleIdentifierNotationParser.parseNotation(id);
    } catch (UnsupportedNotationException e) {
        throw new InvalidUserCodeException(String.format(INVALID_SPEC_ERROR, id == null ? "null" : id.toString()), e);
    }
    Spec<ComponentMetadataDetails> spec = new ComponentMetadataDetailsMatchingSpec(moduleIdentifier);
    return new SpecRuleAction<ComponentMetadataDetails>(ruleAction, spec);
}
Also used : InvalidUserCodeException(org.gradle.api.InvalidUserCodeException) SpecRuleAction(org.gradle.internal.rules.SpecRuleAction) UnsupportedNotationException(org.gradle.internal.typeconversion.UnsupportedNotationException) ModuleIdentifier(org.gradle.api.artifacts.ModuleIdentifier) ComponentMetadataDetails(org.gradle.api.artifacts.ComponentMetadataDetails)

Aggregations

UnsupportedNotationException (org.gradle.internal.typeconversion.UnsupportedNotationException)3 InvalidUserCodeException (org.gradle.api.InvalidUserCodeException)2 ModuleIdentifier (org.gradle.api.artifacts.ModuleIdentifier)2 SpecRuleAction (org.gradle.internal.rules.SpecRuleAction)2 Closure (groovy.lang.Closure)1 ArrayDeque (java.util.ArrayDeque)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ListIterator (java.util.ListIterator)1 Map (java.util.Map)1 RandomAccess (java.util.RandomAccess)1 Callable (java.util.concurrent.Callable)1 Buildable (org.gradle.api.Buildable)1 Task (org.gradle.api.Task)1 ComponentMetadataDetails (org.gradle.api.artifacts.ComponentMetadataDetails)1 ComponentSelection (org.gradle.api.artifacts.ComponentSelection)1 TaskDependency (org.gradle.api.tasks.TaskDependency)1 TaskReference (org.gradle.api.tasks.TaskReference)1