use of org.gradle.api.internal.provider.ProviderInternal in project gradle by gradle.
the class DefaultTaskDependency method visitDependencies.
@Override
public void visitDependencies(TaskDependencyResolveContext context) {
Set<Object> mutableValues = getMutableValues();
if (mutableValues.isEmpty() && immutableValues.isEmpty()) {
return;
}
Deque<Object> queue = new ArrayDeque<Object>(mutableValues.size() + immutableValues.size());
queue.addAll(immutableValues);
queue.addAll(mutableValues);
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 if (dependency instanceof TaskDependencyContainer) {
((TaskDependencyContainer) dependency).visitDependencies(context);
} else if (dependency instanceof ProviderInternal) {
ProviderInternal providerInternal = (ProviderInternal) dependency;
if (providerInternal.getType() == null || providerInternal.getType().equals(Provider.class)) {
queue.addFirst(providerInternal.get());
continue;
}
List<String> formats = new ArrayList<String>();
formats.add("A RegularFileProperty");
formats.add("A DirectoryProperty");
throw new UnsupportedNotationException(dependency, String.format("Cannot convert Provider %s to a task.", dependency), null, formats);
} 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 RegularFileProperty or DirectoryProperty instance");
formats.add("A Provider instance that returns any of these types");
formats.add("A Closure instance that returns any of these types");
formats.add("A Callable instance that returns any of these types");
formats.add("An Iterable, Collection, Map or array instance that contains any of these types");
throw new UnsupportedNotationException(dependency, String.format("Cannot convert %s to a task.", dependency), null, formats);
}
}
}
Aggregations