public void addToAntBuilder(Object builder, String nodeName, AntType type) { if (type == AntType.ResourceCollection) { addAsResourceCollection(builder, nodeName); } else if (type == AntType.FileSet) { addAsFileSet(builder, nodeName); } else { addAsMatchingTask(builder, nodeName); } }
public Object addToAntBuilder(Object node, String childNodeName) { addToAntBuilder(node, childNodeName, AntType.ResourceCollection); return this; }
@Override public TaskDependency getBuildDependencies() { return AbstractFileCollection.this.getBuildDependencies(); }
public Object asType(Class<?> type) throws UnsupportedOperationException { if (type.isAssignableFrom(Set.class)) { return getFiles(); } if (type.isAssignableFrom(List.class)) { return new ArrayList<File>(getFiles()); } if (type.isAssignableFrom(File[].class)) { Set<File> files = getFiles(); return files.toArray(new File[0]); } if (type.isAssignableFrom(File.class)) { return getSingleFile(); } if (type.isAssignableFrom(FileCollection.class)) { return this; } if (type.isAssignableFrom(FileTree.class)) { return getAsFileTree(); } throw new UnsupportedOperationException(String.format("Cannot convert %s to type %s, as this type is not supported.", getDisplayName(), type.getSimpleName())); }
public FileCollection stopExecutionIfEmpty() { if (isEmpty()) { throw new StopExecutionException(String.format("%s does not contain any files.", getCapDisplayName())); } return this; }
public FileCollection add(FileCollection collection) throws UnsupportedOperationException { throw new UnsupportedOperationException(String.format("%s does not allow modification.", getCapDisplayName())); }
public FileCollection filter(Closure filterClosure) { return filter(Specs.convertClosureToSpec(filterClosure)); }
public File getSingleFile() throws IllegalStateException { Collection<File> files = getFiles(); if (files.isEmpty()) { throw new IllegalStateException(String.format("Expected %s to contain exactly one file, however, it contains no files.", getDisplayName())); } if (files.size() != 1) { throw new IllegalStateException(String.format("Expected %s to contain exactly one file, however, it contains %d files.", getDisplayName(), files.size())); } return files.iterator().next(); }
@Override public String getDisplayName() { return AbstractFileCollection.this.getDisplayName(); } };
@Override protected Collection<DirectoryFileTree> getAsFileTrees() { List<DirectoryFileTree> fileTree = new ArrayList<DirectoryFileTree>(); for (FileCollection source : getSourceCollections()) { AbstractFileCollection collection = (AbstractFileCollection) source; fileTree.addAll(collection.getAsFileTrees()); } return fileTree; }
@Override public String toString() { return getDisplayName(); }
protected void addAsFileSet(Object builder, String nodeName) { new AntFileSetBuilder(getAsFileTrees()).addToAntBuilder(builder, nodeName); }
@Override public String getDisplayName() { return AbstractFileCollection.this.getDisplayName(); }
protected void addAsMatchingTask(Object builder, String nodeName) { new AntFileCollectionMatchingTaskBuilder(getAsFileTrees()).addToAntBuilder(builder, nodeName); }
@Override public TaskDependency getBuildDependencies() { return AbstractFileCollection.this.getBuildDependencies(); }
@Override public String getDisplayName() { return AbstractFileCollection.this.getDisplayName(); }
@Override public TaskDependency getBuildDependencies() { if (fileCollection instanceof Buildable) { Buildable buildable = (Buildable) fileCollection; return buildable.getBuildDependencies(); } return super.getBuildDependencies(); } }
protected String getCapDisplayName() { return StringUtils.capitalize(getDisplayName()); }