public void getNodeValues(Object node, Collection<? super Task> values, Collection<? super Object> connectedNodes) { if (node instanceof TaskDependencyContainer) { TaskDependencyContainer taskDependency = (TaskDependencyContainer) node; queue.clear(); taskDependency.visitDependencies(CachingTaskDependencyResolveContext.this); connectedNodes.addAll(queue); } else if (node instanceof Buildable) { Buildable buildable = (Buildable) node; connectedNodes.add(buildable.getBuildDependencies()); } else if (node instanceof TaskDependency) { TaskDependency dependency = (TaskDependency) node; values.addAll(dependency.getDependencies(task)); } else if (node instanceof Task) { values.add((Task) node); } else { throw new IllegalArgumentException(String.format("Cannot resolve object of unknown type %s to a Task.", node.getClass().getSimpleName())); } }
public void getNodeValues(Object node, Collection<? super Task> values, Collection<? super Object> connectedNodes) { if (node instanceof TaskDependencyInternal) { TaskDependencyInternal taskDependency = (TaskDependencyInternal) node; queue.clear(); taskDependency.resolve(CachingTaskDependencyResolveContext.this); connectedNodes.addAll(queue); } else if (node instanceof Buildable) { Buildable buildable = (Buildable) node; connectedNodes.add(buildable.getBuildDependencies()); } else if (node instanceof TaskDependency) { TaskDependency dependency = (TaskDependency) node; values.addAll(dependency.getDependencies(task)); } else if (node instanceof Task) { values.add((Task) node); } else { throw new IllegalArgumentException(String.format("Cannot resolve object of unknown type %s to a Task.", node.getClass().getSimpleName())); } }
@Override public TaskDependency getBuildDependencies() { if (tree instanceof Buildable) { Buildable buildable = (Buildable) tree; return buildable.getBuildDependencies(); } return super.getBuildDependencies(); }
@Override public TaskDependency getBuildDependencies() { if (fileCollection instanceof Buildable) { Buildable buildable = (Buildable) fileCollection; return buildable.getBuildDependencies(); } return super.getBuildDependencies(); }
@Override public FileCollection create(final TaskDependency builtBy, MinimalFileSet contents) { if (contents instanceof Buildable) { throw new UnsupportedOperationException("Not implemented yet."); } return new FileCollectionAdapter(contents) { @Override public TaskDependency getBuildDependencies() { return builtBy; } }; }
/** * Allows subclasses to add additional dependencies * @param context The context to add dependencies to. */ protected void addDependencies(TaskDependencyResolveContext context) { BuildDependenciesOnlyFileCollectionResolveContext fileContext = new BuildDependenciesOnlyFileCollectionResolveContext(); resolve(fileContext); for (Buildable buildable : fileContext.resolveAsBuildables()) { context.add(buildable); } }
public void convertInto(Object element, Collection<? super FileTree> result, FileResolver resolver) { if (element instanceof DefaultFileCollectionResolveContext) { DefaultFileCollectionResolveContext nestedContext = (DefaultFileCollectionResolveContext) element; result.addAll(nestedContext.resolveAsFileTrees()); } else if (element instanceof Buildable) { Buildable buildable = (Buildable) element; result.add(new FileTreeAdapter(new EmptyFileTree(buildable.getBuildDependencies()))); } else if (element instanceof TaskDependency) { TaskDependency dependency = (TaskDependency) element; result.add(new FileTreeAdapter(new EmptyFileTree(dependency))); } }
@Override public TaskDependency getBuildDependencies() { if (delegate instanceof Buildable) return ((Buildable) delegate).getBuildDependencies(); return new TaskDependency() { @Override public Set<? extends Task> getDependencies(Task task) { return Collections.emptySet(); } }; }
@Override public void collectBuildDependencies(Collection<? super TaskDependency> dest) { for (ResolvedArtifact artifact : artifacts) { dest.add(((Buildable) artifact).getBuildDependencies()); } }
@Override public void collectBuildDependencies(Collection<? super TaskDependency> dest) { dest.add(((Buildable) artifact).getBuildDependencies()); }
@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); } } }
/** * Searches the specified class path for Groovy Jars ({@code groovy(-indy)}, {@code groovy-all(-indy)}) and returns a corresponding class path for executing Groovy tools such as the Groovy * compiler and Groovydoc tool. The tool versions will match those of the Groovy Jars found. If no Groovy Jars are found on the specified class path, a class path with the contents of the {@code * groovy} configuration will be returned. * * <p>The returned class path may be empty, or may fail to resolve when asked for its contents. * * @param classpath a class path containing Groovy Jars * @return a corresponding class path for executing Groovy tools such as the Groovy compiler and Groovydoc tool */ public FileCollection inferGroovyClasspath(final Iterable<File> classpath) { // alternatively, we could return project.files(Runnable) // would differ in at least the following ways: 1. live 2. no autowiring return new LazilyInitializedFileCollection() { @Override public String getDisplayName() { return "Groovy runtime classpath"; } @Override public FileCollection createDelegate() { GroovyJarFile groovyJar = findGroovyJarFile(classpath); if (groovyJar == null) { throw new GradleException(String.format("Cannot infer Groovy class path because no Groovy Jar was found on class path: %s", classpath)); } if (groovyJar.isGroovyAll()) { return Cast.cast(FileCollectionInternal.class, project.files(groovyJar.getFile())); } if (project.getRepositories().isEmpty()) { throw new GradleException("Cannot infer Groovy class path because no repository is declared for the project."); } String notation = groovyJar.getDependencyNotation(); List<Dependency> dependencies = Lists.newArrayList(); // project.getDependencies().create(String) seems to be the only feasible way to create a Dependency with a classifier dependencies.add(project.getDependencies().create(notation)); if (groovyJar.getVersion().getMajor() >= 2) { // add groovy-ant to bring in Groovydoc dependencies.add(project.getDependencies().create(notation.replace(":groovy:", ":groovy-ant:"))); } return project.getConfigurations().detachedConfiguration(dependencies.toArray(new Dependency[0])); } // let's override this so that delegate isn't created at autowiring time (which would mean on every build) @Override public void visitDependencies(TaskDependencyResolveContext context) { if (classpath instanceof Buildable) { context.add(classpath); } } }; }
public void resolve(TaskDependencyResolveContext context) { LinkedList<Object> queue = new LinkedList<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.add(0, closureResult); } } else if (dependency instanceof Iterable) { Iterable<?> iterable = (Iterable) dependency; queue.addAll(0, GUtil.addToCollection(new ArrayList<Object>(), iterable)); } else if (dependency instanceof Map) { Map<?, ?> map = (Map) dependency; queue.addAll(0, map.values()); } else if (dependency instanceof Object[]) { Object[] array = (Object[]) dependency; queue.addAll(0, Arrays.asList(array)); } else if (dependency instanceof Callable) { Callable callable = (Callable) dependency; Object callableResult; try { callableResult = callable.call(); } catch (Exception e) { throw UncheckedException.throwAsUncheckedException(e); } if (callableResult != null) { queue.add(0, callableResult); } } 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 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); } } }
/** * Resolves the contents of this context as a list of atomic {@link Buildable} instances. */ public List<? extends Buildable> resolveAsBuildables() { return resolveAsFileCollections(); }
public void resolve(TaskDependencyResolveContext context) { LinkedList<Object> queue = new LinkedList<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.add(0, closureResult); } } else if (dependency instanceof Iterable) { Iterable<?> iterable = (Iterable) dependency; queue.addAll(0, GUtil.addToCollection(new ArrayList<Object>(), iterable)); } else if (dependency instanceof Map) { Map<?, ?> map = (Map) dependency; queue.addAll(0, map.values()); } else if (dependency instanceof Object[]) { Object[] array = (Object[]) dependency; queue.addAll(0, Arrays.asList(array)); } else if (dependency instanceof Callable) { Callable callable = (Callable) dependency; Object callableResult; try { callableResult = callable.call(); } catch (Exception e) { throw UncheckedException.throwAsUncheckedException(e); } if (callableResult != null) { queue.add(0, callableResult); } } else { context.add(resolver.resolveTask(dependency)); } } }