Browse Source

Make DataType and Reference generic

master
Gintas Grigelionis 6 years ago
parent
commit
57895fd064
57 changed files with 379 additions and 261 deletions
  1. +6
    -0
      src/etc/testcases/taskdefs/tar.xml
  2. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/Classloader.java
  3. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/Input.java
  4. +5
    -1
      src/main/org/apache/tools/ant/taskdefs/optional/extension/ExtensionAdapter.java
  5. +5
    -1
      src/main/org/apache/tools/ant/taskdefs/optional/extension/ExtensionSet.java
  6. +8
    -3
      src/main/org/apache/tools/ant/types/AbstractFileSet.java
  7. +7
    -3
      src/main/org/apache/tools/ant/types/AntFilterReader.java
  8. +18
    -22
      src/main/org/apache/tools/ant/types/ArchiveFileSet.java
  9. +25
    -6
      src/main/org/apache/tools/ant/types/DataType.java
  10. +16
    -6
      src/main/org/apache/tools/ant/types/DirSet.java
  11. +10
    -12
      src/main/org/apache/tools/ant/types/FileList.java
  12. +15
    -5
      src/main/org/apache/tools/ant/types/FileSet.java
  13. +5
    -1
      src/main/org/apache/tools/ant/types/FilterChain.java
  14. +1
    -1
      src/main/org/apache/tools/ant/types/FilterSet.java
  15. +1
    -1
      src/main/org/apache/tools/ant/types/Mapper.java
  16. +9
    -5
      src/main/org/apache/tools/ant/types/Path.java
  17. +1
    -1
      src/main/org/apache/tools/ant/types/PatternSet.java
  18. +1
    -1
      src/main/org/apache/tools/ant/types/PropertySet.java
  19. +1
    -1
      src/main/org/apache/tools/ant/types/RedirectorElement.java
  20. +3
    -3
      src/main/org/apache/tools/ant/types/Reference.java
  21. +1
    -1
      src/main/org/apache/tools/ant/types/RegularExpression.java
  22. +17
    -18
      src/main/org/apache/tools/ant/types/Resource.java
  23. +1
    -1
      src/main/org/apache/tools/ant/types/Substitution.java
  24. +15
    -5
      src/main/org/apache/tools/ant/types/TarFileSet.java
  25. +1
    -1
      src/main/org/apache/tools/ant/types/XMLCatalog.java
  26. +11
    -1
      src/main/org/apache/tools/ant/types/ZipFileSet.java
  27. +5
    -2
      src/main/org/apache/tools/ant/types/optional/depend/ClassfileSet.java
  28. +10
    -5
      src/main/org/apache/tools/ant/types/resources/AbstractClasspathResource.java
  29. +8
    -4
      src/main/org/apache/tools/ant/types/resources/AbstractResourceCollectionWrapper.java
  30. +10
    -10
      src/main/org/apache/tools/ant/types/resources/ArchiveResource.java
  31. +5
    -6
      src/main/org/apache/tools/ant/types/resources/Archives.java
  32. +6
    -2
      src/main/org/apache/tools/ant/types/resources/BCFileSet.java
  33. +6
    -8
      src/main/org/apache/tools/ant/types/resources/BaseResourceCollectionContainer.java
  34. +18
    -18
      src/main/org/apache/tools/ant/types/resources/FileResource.java
  35. +1
    -1
      src/main/org/apache/tools/ant/types/resources/Files.java
  36. +4
    -4
      src/main/org/apache/tools/ant/types/resources/JavaResource.java
  37. +1
    -1
      src/main/org/apache/tools/ant/types/resources/MappedResource.java
  38. +6
    -7
      src/main/org/apache/tools/ant/types/resources/MappedResourceCollection.java
  39. +10
    -6
      src/main/org/apache/tools/ant/types/resources/MultiRootFileSet.java
  40. +5
    -5
      src/main/org/apache/tools/ant/types/resources/PropertyResource.java
  41. +1
    -1
      src/main/org/apache/tools/ant/types/resources/ResourceDecorator.java
  42. +5
    -6
      src/main/org/apache/tools/ant/types/resources/ResourceList.java
  43. +2
    -2
      src/main/org/apache/tools/ant/types/resources/Resources.java
  44. +6
    -7
      src/main/org/apache/tools/ant/types/resources/Restrict.java
  45. +6
    -6
      src/main/org/apache/tools/ant/types/resources/StringResource.java
  46. +8
    -8
      src/main/org/apache/tools/ant/types/resources/TarResource.java
  47. +16
    -11
      src/main/org/apache/tools/ant/types/resources/URLResource.java
  48. +6
    -2
      src/main/org/apache/tools/ant/types/resources/Union.java
  49. +9
    -4
      src/main/org/apache/tools/ant/types/resources/ZipResource.java
  50. +3
    -3
      src/main/org/apache/tools/ant/types/resources/comparators/DelegatedResourceComparator.java
  51. +5
    -6
      src/main/org/apache/tools/ant/types/resources/comparators/ResourceComparator.java
  52. +5
    -1
      src/main/org/apache/tools/ant/types/resources/selectors/Compare.java
  53. +6
    -7
      src/main/org/apache/tools/ant/types/resources/selectors/ResourceSelectorContainer.java
  54. +13
    -10
      src/main/org/apache/tools/ant/types/selectors/AbstractSelectorContainer.java
  55. +3
    -4
      src/main/org/apache/tools/ant/types/selectors/BaseSelector.java
  56. +1
    -1
      src/main/org/apache/tools/ant/types/selectors/SelectSelector.java
  57. +4
    -1
      src/tests/junit/org/apache/tools/ant/taskdefs/TarTest.java

+ 6
- 0
src/etc/testcases/taskdefs/tar.xml View File

@@ -172,6 +172,12 @@
<untar src="${output}/test11.tar.bz2" dest="${output}/untar" compression="bzip2"/>
</target>

<target name="testTarFilesetWithReference">
<fileset id="xml.fileset" dir="." includes="*.xml"/>
<tar destfile="${output}/testtar.tar">
<tarfileset prefix="pre" refid="xml.fileset"/>
</tar>
</target>

<target name="feather">
<tar destfile="${output}/asf-logo.gif.tar"


+ 1
- 1
src/main/org/apache/tools/ant/taskdefs/Classloader.java View File

@@ -124,7 +124,7 @@ public class Classloader extends Task {
* @throws BuildException if there is a problem.
*/
public void setClasspathRef(Reference pathRef) throws BuildException {
classpath = (Path) pathRef.getReferencedObject(getProject());
classpath = pathRef.getReferencedObject(getProject());
}

/**


+ 1
- 1
src/main/org/apache/tools/ant/taskdefs/Input.java View File

@@ -105,7 +105,7 @@ public class Input extends Task {
}
if (refid != null) {
try {
return (InputHandler) (getProject().getReference(refid));
return getProject().getReference(refid);
} catch (final ClassCastException e) {
throw new BuildException(
refid + " does not denote an InputHandler", e);


+ 5
- 1
src/main/org/apache/tools/ant/taskdefs/optional/extension/ExtensionAdapter.java View File

@@ -180,7 +180,7 @@ public class ExtensionAdapter extends DataType {
Extension toExtension()
throws BuildException {
if (isReference()) {
return ((ExtensionAdapter) getCheckedRef()).toExtension();
return getRef().toExtension();
}
dieOnCircularReference();
if (null == extensionName) {
@@ -213,4 +213,8 @@ public class ExtensionAdapter extends DataType {
public String toString() {
return "{" + toExtension() + "}";
}

private ExtensionAdapter getRef() {
return getCheckedRef(ExtensionAdapter.class);
}
}

+ 5
- 1
src/main/org/apache/tools/ant/taskdefs/optional/extension/ExtensionSet.java View File

@@ -95,7 +95,7 @@ public class ExtensionSet
public Extension[] toExtensions(final Project proj)
throws BuildException {
if (isReference()) {
return ((ExtensionSet) getCheckedRef()).toExtensions(proj);
return getRef().toExtensions(proj);
}
dieOnCircularReference();
final List<Extension> extensionsList = ExtensionUtil.toExtensions(extensions);
@@ -141,6 +141,10 @@ public class ExtensionSet
}
}

private ExtensionSet getRef() {
return getCheckedRef(ExtensionSet.class);
}

/**
* @see java.lang.Object#toString()
* @return the extensions in a string.


+ 8
- 3
src/main/org/apache/tools/ant/types/AbstractFileSet.java View File

@@ -573,11 +573,17 @@ public abstract class AbstractFileSet extends DataType
/**
* Performs the check for circular references and returns the
* referenced FileSet.
* This method can overridden together with {@link ArchiveFileSet#getRef() getRef()}
* providing implementations containing the special support
* for FileSet references, which can be handled by all ArchiveFileSets.
* NB! This method must be overridden in subclasses such as FileSet and DirSet
* to distinguish between the data types.
* @return the dereferenced object.
* @param p the current project
* @return the referenced FileSet
*/
protected AbstractFileSet getRef(Project p) {
return (AbstractFileSet) getCheckedRef(p);
return getCheckedRef(AbstractFileSet.class, getDataTypeName(), p);
}

// SelectorContainer methods
@@ -901,8 +907,7 @@ public abstract class AbstractFileSet extends DataType
return getRef(getProject()).toString();
}
dieOnCircularReference();
DirectoryScanner ds = getDirectoryScanner(getProject());
return String.join(";", ds.getIncludedFiles());
return String.join(";", getDirectoryScanner().getIncludedFiles());
}

/**


+ 7
- 3
src/main/org/apache/tools/ant/types/AntFilterReader.java View File

@@ -55,7 +55,7 @@ public final class AntFilterReader extends DataType {
*/
public String getClassName() {
if (isReference()) {
return ((AntFilterReader) getCheckedRef()).getClassName();
return getRef().getClassName();
}
dieOnCircularReference();
return className;
@@ -110,7 +110,7 @@ public final class AntFilterReader extends DataType {
*/
public Path getClasspath() {
if (isReference()) {
((AntFilterReader) getCheckedRef()).getClasspath();
getRef().getClasspath();
}
dieOnCircularReference();
return classpath;
@@ -135,7 +135,7 @@ public final class AntFilterReader extends DataType {
*/
public Parameter[] getParams() {
if (isReference()) {
((AntFilterReader) getCheckedRef()).getParams();
getRef().getParams();
}
dieOnCircularReference();
return parameters.toArray(new Parameter[parameters.size()]);
@@ -173,4 +173,8 @@ public final class AntFilterReader extends DataType {
setChecked(true);
}
}

private AntFilterReader getRef() {
return getCheckedRef(AntFilterReader.class);
}
}

+ 18
- 22
src/main/org/apache/tools/ant/types/ArchiveFileSet.java View File

@@ -189,7 +189,7 @@ public abstract class ArchiveFileSet extends FileSet {
*/
public File getSrc() {
if (isReference()) {
return ((ArchiveFileSet) getCheckedRef()).getSrc();
return getCheckedRef(ArchiveFileSet.class).getSrc();
}
dieOnCircularReference();
if (src == null) {
@@ -201,18 +201,17 @@ public abstract class ArchiveFileSet extends FileSet {
/**
* Performs the check for circular references and returns the
* referenced object.
* This is an override which does not delegate to the superclass; instead it invokes
* {@link #getRef(Project)}, because that contains the special support for fileset
* references, which can be handled by all ArchiveFileSets.
* @param p the Ant Project instance against which to resolve references.
* This method must be overridden together with
* {@link AbstractFileSet#getRef(Project) getRef(Project)}
* providing implementations containing the special support
* for FileSet references, which can be handled by all ArchiveFileSets.
* NB! This method cannot be implemented in AbstractFileSet in order to allow
* FileSet and DirSet to implement it as a private method.
* @return the dereferenced object.
* @throws BuildException if the reference is invalid (circular ref, wrong class, etc).
* @since Ant 1.8
*/
// TODO is the above true? AFAICT the calls look circular :/
@Override
protected Object getCheckedRef(Project p) {
return getRef(p);
protected AbstractFileSet getRef() {
return getCheckedRef(AbstractFileSet.class);
}

/**
@@ -286,7 +285,7 @@ public abstract class ArchiveFileSet extends FileSet {
*/
public String getEncoding() {
if (isReference()) {
AbstractFileSet ref = getRef(getProject());
AbstractFileSet ref = getRef();
return ref instanceof ArchiveFileSet ? ((ArchiveFileSet) ref).getEncoding() : null;
}
return encoding;
@@ -339,13 +338,12 @@ public abstract class ArchiveFileSet extends FileSet {
@Override
public Iterator<Resource> iterator() {
if (isReference()) {
return ((ResourceCollection) (getRef(getProject()))).iterator();
return ((ResourceCollection) getRef()).iterator();
}
if (src == null) {
return super.iterator();
}
ArchiveScanner as = (ArchiveScanner) getDirectoryScanner(getProject());
return as.getResourceFiles(getProject());
return ((ArchiveScanner) getDirectoryScanner()).getResourceFiles(getProject());
}

/**
@@ -356,13 +354,12 @@ public abstract class ArchiveFileSet extends FileSet {
@Override
public int size() {
if (isReference()) {
return ((ResourceCollection) (getRef(getProject()))).size();
return ((ResourceCollection) getRef()).size();
}
if (src == null) {
return super.size();
}
ArchiveScanner as = (ArchiveScanner) getDirectoryScanner(getProject());
return as.getIncludedFilesCount();
return getDirectoryScanner().getIncludedFilesCount();
}

/**
@@ -376,7 +373,7 @@ public abstract class ArchiveFileSet extends FileSet {
@Override
public boolean isFilesystemOnly() {
if (isReference()) {
return ((ArchiveFileSet) getCheckedRef()).isFilesystemOnly();
return ((ArchiveFileSet) getRef()).isFilesystemOnly();
}
dieOnCircularReference();
return src == null;
@@ -427,7 +424,7 @@ public abstract class ArchiveFileSet extends FileSet {
*/
public boolean hasFileModeBeenSet() {
if (isReference()) {
return ((ArchiveFileSet) getRef(getProject())).hasFileModeBeenSet();
return ((ArchiveFileSet) getRef()).hasFileModeBeenSet();
}
dieOnCircularReference();
return fileModeHasBeenSet;
@@ -478,7 +475,7 @@ public abstract class ArchiveFileSet extends FileSet {
*/
public boolean hasDirModeBeenSet() {
if (isReference()) {
return ((ArchiveFileSet) getRef(getProject())).hasDirModeBeenSet();
return ((ArchiveFileSet) getRef()).hasDirModeBeenSet();
}
dieOnCircularReference();
return dirModeHasBeenSet;
@@ -507,8 +504,7 @@ public abstract class ArchiveFileSet extends FileSet {
@Override
public Object clone() {
if (isReference()) {
return getCheckedRef(ArchiveFileSet.class, getDataTypeName(),
getProject()).clone();
return getCheckedRef(ArchiveFileSet.class).clone();
}
return super.clone();
}


+ 25
- 6
src/main/org/apache/tools/ant/types/DataType.java View File

@@ -196,24 +196,44 @@ public abstract class DataType extends ProjectComponent implements Cloneable {
/**
* Performs the check for circular references and returns the
* referenced object.
* @param <T> required reference type
* @return the dereferenced object.
* @throws BuildException if the reference is invalid (circular ref, wrong class, etc).
* @since Ant 1.7
* @deprecated use getCheckedRef(Class)
*/
protected Object getCheckedRef() {
@Deprecated
protected <T> T getCheckedRef() {
return getCheckedRef(getProject());
}

/**
* Performs the check for circular references and returns the
* referenced object.
* @param <T> required reference type
* @param requiredClass the class that this reference should be a subclass of.
* @return the dereferenced object.
* @throws BuildException if the reference is invalid (circular ref, wrong class, etc).
* @since Ant 1.10.6
*/
protected <T> T getCheckedRef(final Class<T> requiredClass) {
return getCheckedRef(requiredClass, getDataTypeName(), getProject());
}

/**
* Performs the check for circular references and returns the
* referenced object.
* @param <T> required reference type
* @param p the Ant Project instance against which to resolve references.
* @return the dereferenced object.
* @throws BuildException if the reference is invalid (circular ref, wrong class, etc).
* @since Ant 1.7
* @deprecated use getCheckedRef(Class)
*/
protected Object getCheckedRef(Project p) {
return getCheckedRef(getClass(), getDataTypeName(), p);
@Deprecated
@SuppressWarnings("unchecked")
protected <T> T getCheckedRef(Project p) {
return getCheckedRef((Class<T>) getClass(), getDataTypeName(), p);
}

/**
@@ -244,16 +264,15 @@ public abstract class DataType extends ProjectComponent implements Cloneable {
* or if <code>project</code> is <code>null</code>.
* @since Ant 1.7
*/
@SuppressWarnings("unchecked")
protected <T> T getCheckedRef(final Class<T> requiredClass,
final String dataTypeName, final Project project) {
if (project == null) {
throw new BuildException("No Project specified");
}
dieOnCircularReference(project);
Object o = ref.getReferencedObject(project);
T o = ref.getReferencedObject(project);
if (requiredClass.isAssignableFrom(o.getClass())) {
return (T) o;
return o;
}
log("Class " + displayName(o.getClass())
+ " is not a subclass of "


+ 16
- 6
src/main/org/apache/tools/ant/types/DirSet.java View File

@@ -20,6 +20,7 @@ package org.apache.tools.ant.types;

import java.util.Iterator;

import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.resources.FileResourceIterator;

/**
@@ -53,7 +54,7 @@ public class DirSet extends AbstractFileSet implements ResourceCollection {
@Override
public Object clone() {
if (isReference()) {
return getRef(getProject()).clone();
return getRef().clone();
}
return super.clone();
}
@@ -66,10 +67,10 @@ public class DirSet extends AbstractFileSet implements ResourceCollection {
@Override
public Iterator<Resource> iterator() {
if (isReference()) {
return ((DirSet) getRef(getProject())).iterator();
return getRef().iterator();
}
return new FileResourceIterator(getProject(), getDir(getProject()),
getDirectoryScanner(getProject()).getIncludedDirectories());
getDirectoryScanner().getIncludedDirectories());
}

/**
@@ -80,9 +81,9 @@ public class DirSet extends AbstractFileSet implements ResourceCollection {
@Override
public int size() {
if (isReference()) {
return ((DirSet) getRef(getProject())).size();
return getRef().size();
}
return getDirectoryScanner(getProject()).getIncludedDirsCount();
return getDirectoryScanner().getIncludedDirsCount();
}

/**
@@ -102,7 +103,16 @@ public class DirSet extends AbstractFileSet implements ResourceCollection {
*/
@Override
public String toString() {
return String.join(";", getDirectoryScanner(getProject()).getIncludedDirectories());
return String.join(";", getDirectoryScanner().getIncludedDirectories());
}

@Override
protected AbstractFileSet getRef(Project p) {
return getCheckedRef(DirSet.class, getDataTypeName(), p);
}

private DirSet getRef() {
return getCheckedRef(DirSet.class);
}

}

+ 10
- 12
src/main/org/apache/tools/ant/types/FileList.java View File

@@ -136,16 +136,6 @@ public class FileList extends DataType implements ResourceCollection {
return filenames.toArray(new String[filenames.size()]);
}

/**
* Performs the check for circular references and returns the
* referenced FileList.
* @param p the current project
* @return the FileList represented by a referenced filelist.
*/
protected FileList getRef(Project p) {
return (FileList) getCheckedRef(p);
}

/**
* Inner class corresponding to the &lt;file&gt; nested element.
*/
@@ -191,7 +181,7 @@ public class FileList extends DataType implements ResourceCollection {
@Override
public Iterator<Resource> iterator() {
if (isReference()) {
return getRef(getProject()).iterator();
return getRef().iterator();
}
return new FileResourceIterator(getProject(), dir,
filenames.toArray(new String[filenames.size()]));
@@ -205,7 +195,7 @@ public class FileList extends DataType implements ResourceCollection {
@Override
public int size() {
if (isReference()) {
return getRef(getProject()).size();
return getRef().size();
}
return filenames.size();
}
@@ -220,4 +210,12 @@ public class FileList extends DataType implements ResourceCollection {
return true;
}

private FileList getRef() {
return getCheckedRef(FileList.class);
}

private FileList getRef(Project p) {
return getCheckedRef(FileList.class, getDataTypeName(), p);
}

}

+ 15
- 5
src/main/org/apache/tools/ant/types/FileSet.java View File

@@ -20,6 +20,7 @@ package org.apache.tools.ant.types;

import java.util.Iterator;

import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.resources.FileResourceIterator;

/**
@@ -52,7 +53,7 @@ public class FileSet extends AbstractFileSet implements ResourceCollection {
@Override
public Object clone() {
if (isReference()) {
return getRef(getProject()).clone();
return getRef().clone();
}
return super.clone();
}
@@ -65,10 +66,10 @@ public class FileSet extends AbstractFileSet implements ResourceCollection {
@Override
public Iterator<Resource> iterator() {
if (isReference()) {
return ((FileSet) getRef(getProject())).iterator();
return getRef().iterator();
}
return new FileResourceIterator(getProject(), getDir(getProject()),
getDirectoryScanner(getProject()).getIncludedFiles());
getDirectoryScanner().getIncludedFiles());
}

/**
@@ -79,9 +80,9 @@ public class FileSet extends AbstractFileSet implements ResourceCollection {
@Override
public int size() {
if (isReference()) {
return ((FileSet) getRef(getProject())).size();
return getRef().size();
}
return getDirectoryScanner(getProject()).getIncludedFilesCount();
return getDirectoryScanner().getIncludedFilesCount();
}

/**
@@ -94,4 +95,13 @@ public class FileSet extends AbstractFileSet implements ResourceCollection {
return true;
}

@Override
protected AbstractFileSet getRef(Project p) {
return getCheckedRef(FileSet.class, getDataTypeName(), p);
}

private FileSet getRef() {
return getCheckedRef(FileSet.class);
}

}

+ 5
- 1
src/main/org/apache/tools/ant/types/FilterChain.java View File

@@ -68,7 +68,7 @@ public class FilterChain extends DataType {
*/
public Vector<Object> getFilterReaders() {
if (isReference()) {
return ((FilterChain) getCheckedRef()).getFilterReaders();
return getRef().getFilterReaders();
}
dieOnCircularReference();
return filterReaders;
@@ -412,4 +412,8 @@ public class FilterChain extends DataType {
setChecked(true);
}
}

private FilterChain getRef() {
return getCheckedRef(FilterChain.class);
}
}

+ 1
- 1
src/main/org/apache/tools/ant/types/FilterSet.java View File

@@ -236,7 +236,7 @@ public class FilterSet extends DataType implements Cloneable {
* @return the filterset from the reference.
*/
protected FilterSet getRef() {
return getCheckedRef(FilterSet.class, "filterset");
return getCheckedRef(FilterSet.class);
}

/**


+ 1
- 1
src/main/org/apache/tools/ant/types/Mapper.java View File

@@ -276,7 +276,7 @@ public class Mapper extends DataType {
*/
@Deprecated
protected Mapper getRef() {
return getCheckedRef(Mapper.class, getDataTypeName());
return getCheckedRef(Mapper.class);
}

/**


+ 9
- 5
src/main/org/apache/tools/ant/types/Path.java View File

@@ -376,7 +376,7 @@ public class Path extends DataType implements Cloneable, ResourceCollection {
*/
public String[] list() {
if (isReference()) {
return ((Path) getCheckedRef()).list();
return getRef().list();
}
return assertFilesystemOnly(union) == null
? new String[0] : union.list();
@@ -389,7 +389,7 @@ public class Path extends DataType implements Cloneable, ResourceCollection {
*/
@Override
public String toString() {
return isReference() ? getCheckedRef().toString()
return isReference() ? getRef().toString()
: union == null ? "" : union.toString();
}

@@ -463,7 +463,7 @@ public class Path extends DataType implements Cloneable, ResourceCollection {
@Override
public synchronized int size() {
if (isReference()) {
return ((Path) getCheckedRef()).size();
return getRef().size();
}
dieOnCircularReference();
return union == null ? 0 : assertFilesystemOnly(union).size();
@@ -690,7 +690,7 @@ public class Path extends DataType implements Cloneable, ResourceCollection {
@Override
public final synchronized Iterator<Resource> iterator() {
if (isReference()) {
return ((Path) getCheckedRef()).iterator();
return getRef().iterator();
}
dieOnCircularReference();
if (getPreserveBC()) {
@@ -707,7 +707,7 @@ public class Path extends DataType implements Cloneable, ResourceCollection {
@Override
public synchronized boolean isFilesystemOnly() {
if (isReference()) {
return ((Path) getCheckedRef()).isFilesystemOnly();
return getRef().isFilesystemOnly();
}
dieOnCircularReference();
assertFilesystemOnly(union);
@@ -764,4 +764,8 @@ public class Path extends DataType implements Cloneable, ResourceCollection {
return path != null && (path.contains("*") || path.contains("?"));
}

private Path getRef() {
return getCheckedRef(Path.class);
}

}

+ 1
- 1
src/main/org/apache/tools/ant/types/PatternSet.java View File

@@ -505,7 +505,7 @@ public class PatternSet extends DataType implements Cloneable {
* referenced PatternSet.
*/
private PatternSet getRef(Project p) {
return (PatternSet) getCheckedRef(p);
return getCheckedRef(PatternSet.class, getDataTypeName(), p);
}

/**


+ 1
- 1
src/main/org/apache/tools/ant/types/PropertySet.java View File

@@ -425,7 +425,7 @@ public class PropertySet extends DataType implements ResourceCollection {
* @return the referenced PropertySet.
*/
protected PropertySet getRef() {
return getCheckedRef(PropertySet.class, "propertyset");
return getCheckedRef(PropertySet.class);
}

/**


+ 1
- 1
src/main/org/apache/tools/ant/types/RedirectorElement.java View File

@@ -624,7 +624,7 @@ public class RedirectorElement extends DataType {
* @return the referenced RedirectorElement.
*/
private RedirectorElement getRef() {
return (RedirectorElement) getCheckedRef();
return getCheckedRef(RedirectorElement.class);
}

}

+ 3
- 3
src/main/org/apache/tools/ant/types/Reference.java View File

@@ -107,12 +107,12 @@ public class Reference {
* @return the dereferenced object.
* @throws BuildException if the reference cannot be dereferenced.
*/
public Object getReferencedObject(Project fallback) throws BuildException {
public <T> T getReferencedObject(Project fallback) throws BuildException {
if (refid == null) {
throw new BuildException("No reference specified");
}

Object o = project == null ? fallback.getReference(refid) : project.getReference(refid);
T o = project == null ? fallback.getReference(refid) : project.getReference(refid);
if (o == null) {
throw new BuildException("Reference " + refid + " not found.");
}
@@ -126,7 +126,7 @@ public class Reference {
* @throws BuildException if the project is null or the reference cannot be dereferenced
* @since Ant 1.6.3
*/
public Object getReferencedObject() throws BuildException {
public <T> T getReferencedObject() throws BuildException {
if (project == null) {
throw new BuildException("No project set on reference to " + refid);
}


+ 1
- 1
src/main/org/apache/tools/ant/types/RegularExpression.java View File

@@ -130,6 +130,6 @@ public class RegularExpression extends DataType {
* @return resolved RegularExpression instance
*/
public RegularExpression getRef(Project p) {
return (RegularExpression) getCheckedRef(p);
return getCheckedRef(RegularExpression.class, getDataTypeName(), p);
}
}

+ 17
- 18
src/main/org/apache/tools/ant/types/Resource.java View File

@@ -141,7 +141,7 @@ public class Resource extends DataType implements Comparable<Resource>, Resource
* @return the name of this resource.
*/
public String getName() {
return isReference() ? getCheckedRef().getName() : name;
return isReference() ? getRef().getName() : name;
}

/**
@@ -160,7 +160,7 @@ public class Resource extends DataType implements Comparable<Resource>, Resource
*/
public boolean isExists() {
if (isReference()) {
return getCheckedRef().isExists();
return getRef().isExists();
}
//default true:
return exists == null || exists;
@@ -187,7 +187,7 @@ public class Resource extends DataType implements Comparable<Resource>, Resource
*/
public long getLastModified() {
if (isReference()) {
return getCheckedRef().getLastModified();
return getRef().getLastModified();
}
if (!isExists() || lastmodified == null) {
return UNKNOWN_DATETIME;
@@ -211,7 +211,7 @@ public class Resource extends DataType implements Comparable<Resource>, Resource
*/
public boolean isDirectory() {
if (isReference()) {
return getCheckedRef().isDirectory();
return getRef().isDirectory();
}
//default false:
return directory != null && directory;
@@ -244,7 +244,7 @@ public class Resource extends DataType implements Comparable<Resource>, Resource
*/
public long getSize() {
if (isReference()) {
return getCheckedRef().getSize();
return getRef().getSize();
}
return isExists()
? (size != null ? size : UNKNOWN_SIZE)
@@ -275,7 +275,7 @@ public class Resource extends DataType implements Comparable<Resource>, Resource
@Override
public int compareTo(Resource other) {
if (isReference()) {
return getCheckedRef().compareTo(other);
return getRef().compareTo(other);
}
return toString().compareTo(other.toString());
}
@@ -292,7 +292,7 @@ public class Resource extends DataType implements Comparable<Resource>, Resource
return true;
}
if (isReference()) {
return getCheckedRef().equals(other);
return getRef().equals(other);
}
return other != null && other.getClass().equals(getClass())
&& compareTo((Resource) other) == 0;
@@ -306,7 +306,7 @@ public class Resource extends DataType implements Comparable<Resource>, Resource
@Override
public int hashCode() {
if (isReference()) {
return getCheckedRef().hashCode();
return getRef().hashCode();
}
String name = getName();
return MAGIC * (name == null ? NULL_NAME : name.hashCode());
@@ -323,7 +323,7 @@ public class Resource extends DataType implements Comparable<Resource>, Resource
*/
public InputStream getInputStream() throws IOException {
if (isReference()) {
return getCheckedRef().getInputStream();
return getRef().getInputStream();
}
throw new UnsupportedOperationException();
}
@@ -339,7 +339,7 @@ public class Resource extends DataType implements Comparable<Resource>, Resource
*/
public OutputStream getOutputStream() throws IOException {
if (isReference()) {
return getCheckedRef().getOutputStream();
return getRef().getOutputStream();
}
throw new UnsupportedOperationException();
}
@@ -351,7 +351,7 @@ public class Resource extends DataType implements Comparable<Resource>, Resource
*/
@Override
public Iterator<Resource> iterator() {
return isReference() ? getCheckedRef().iterator()
return isReference() ? getRef().iterator()
: Collections.singleton(this).iterator();
}

@@ -362,7 +362,7 @@ public class Resource extends DataType implements Comparable<Resource>, Resource
*/
@Override
public int size() {
return isReference() ? getCheckedRef().size() : 1;
return isReference() ? getRef().size() : 1;
}

/**
@@ -372,7 +372,7 @@ public class Resource extends DataType implements Comparable<Resource>, Resource
*/
@Override
public boolean isFilesystemOnly() {
return (isReference() && getCheckedRef().isFilesystemOnly())
return (isReference() && getRef().isFilesystemOnly())
|| this.as(FileProvider.class) != null;
}

@@ -384,7 +384,7 @@ public class Resource extends DataType implements Comparable<Resource>, Resource
@Override
public String toString() {
if (isReference()) {
return getCheckedRef().toString();
return getRef().toString();
}
String n = getName();
return n == null ? "(anonymous)" : n;
@@ -398,7 +398,7 @@ public class Resource extends DataType implements Comparable<Resource>, Resource
* @since Ant 1.7
*/
public final String toLongString() {
return isReference() ? getCheckedRef().toLongString()
return isReference() ? getRef().toLongString()
: getDataTypeName() + " \"" + toString() + '"';
}

@@ -449,8 +449,7 @@ public class Resource extends DataType implements Comparable<Resource>, Resource
return Optional.ofNullable(as(clazz));
}

@Override
protected Resource getCheckedRef() {
return (Resource) super.getCheckedRef();
protected Resource getRef() {
return getCheckedRef(Resource.class);
}
}

+ 1
- 1
src/main/org/apache/tools/ant/types/Substitution.java View File

@@ -71,6 +71,6 @@ public class Substitution extends DataType {
* @return the resolved reference
*/
public Substitution getRef(Project p) {
return (Substitution) getCheckedRef(p);
return getCheckedRef(Substitution.class, getDataTypeName(), p);
}
}

+ 15
- 5
src/main/org/apache/tools/ant/types/TarFileSet.java View File

@@ -78,7 +78,7 @@ public class TarFileSet extends ArchiveFileSet {
*/
public String getUserName() {
if (isReference()) {
return ((TarFileSet) getCheckedRef()).getUserName();
return ((TarFileSet) getRef()).getUserName();
}
return userName;
}
@@ -106,7 +106,7 @@ public class TarFileSet extends ArchiveFileSet {
*/
public int getUid() {
if (isReference()) {
return ((TarFileSet) getCheckedRef()).getUid();
return ((TarFileSet) getRef()).getUid();
}
return uid;
}
@@ -134,7 +134,7 @@ public class TarFileSet extends ArchiveFileSet {
*/
public String getGroup() {
if (isReference()) {
return ((TarFileSet) getCheckedRef()).getGroup();
return ((TarFileSet) getRef()).getGroup();
}
return groupName;
}
@@ -162,7 +162,7 @@ public class TarFileSet extends ArchiveFileSet {
*/
public int getGid() {
if (isReference()) {
return ((TarFileSet) getCheckedRef()).getGid();
return ((TarFileSet) getRef()).getGid();
}
return gid;
}
@@ -223,6 +223,16 @@ public class TarFileSet extends ArchiveFileSet {
throw new BuildException(msg);
}

/**
* A TarFileset accepts another TarFileSet or a FileSet as reference
* FileSets are often used by the war task for the lib attribute
* @return the abstract fileset instance
*/
@Override
protected AbstractFileSet getRef() {
return getRef(getProject());
}

/**
* Configure a fileset based on this fileset.
* If the fileset is a TarFileSet copy in the tarfileset
@@ -249,7 +259,7 @@ public class TarFileSet extends ArchiveFileSet {
@Override
public Object clone() {
if (isReference()) {
return getRef(getProject()).clone();
return getRef().clone();
}
return super.clone();
}


+ 1
- 1
src/main/org/apache/tools/ant/types/XMLCatalog.java View File

@@ -474,7 +474,7 @@ public class XMLCatalog extends DataType
if (!isReference()) {
return this;
}
return getCheckedRef(XMLCatalog.class, "xmlcatalog");
return getCheckedRef(XMLCatalog.class);
}

/**


+ 11
- 1
src/main/org/apache/tools/ant/types/ZipFileSet.java View File

@@ -87,6 +87,16 @@ public class ZipFileSet extends ArchiveFileSet {
throw new BuildException(msg);
}

/**
* A ZipFileset accepts another ZipFileSet or a FileSet as reference
* FileSets are often used by the war task for the lib attribute
* @return the abstract fileset instance
*/
@Override
protected AbstractFileSet getRef() {
return getRef(getProject());
}

/**
* Return a ZipFileSet that has the same properties
* as this one.
@@ -95,7 +105,7 @@ public class ZipFileSet extends ArchiveFileSet {
@Override
public Object clone() {
if (isReference()) {
return getRef(getProject()).clone();
return getRef().clone();
}
return super.clone();
}


+ 5
- 2
src/main/org/apache/tools/ant/types/optional/depend/ClassfileSet.java View File

@@ -162,8 +162,7 @@ public class ClassfileSet extends FileSet {
*/
@Override
public Object clone() {
return new ClassfileSet(isReference()
? (ClassfileSet) (getRef(getProject())) : this);
return new ClassfileSet(isReference() ? getRef() : this);
}

@Override
@@ -182,4 +181,8 @@ public class ClassfileSet extends FileSet {
setChecked(true);
}
}

private ClassfileSet getRef() {
return getCheckedRef(ClassfileSet.class);
}
}

+ 10
- 5
src/main/org/apache/tools/ant/types/resources/AbstractClasspathResource.java View File

@@ -84,7 +84,7 @@ public abstract class AbstractClasspathResource extends Resource {
*/
public Path getClasspath() {
if (isReference()) {
return ((AbstractClasspathResource) getCheckedRef()).getClasspath();
return getRef().getClasspath();
}
dieOnCircularReference();
return classpath;
@@ -96,7 +96,7 @@ public abstract class AbstractClasspathResource extends Resource {
*/
public Reference getLoader() {
if (isReference()) {
return ((AbstractClasspathResource) getCheckedRef()).getLoader();
return getRef().getLoader();
}
dieOnCircularReference();
return loader;
@@ -151,7 +151,7 @@ public abstract class AbstractClasspathResource extends Resource {
*/
public boolean isExists() {
if (isReference()) {
return getCheckedRef().isExists();
return getRef().isExists();
}
dieOnCircularReference();
try (InputStream is = getInputStream()) {
@@ -169,7 +169,7 @@ public abstract class AbstractClasspathResource extends Resource {
*/
public InputStream getInputStream() throws IOException {
if (isReference()) {
return getCheckedRef().getInputStream();
return getRef().getInputStream();
}
dieOnCircularReference();

@@ -204,7 +204,7 @@ public abstract class AbstractClasspathResource extends Resource {
protected ClassLoaderWithFlag getClassLoader() {
ClassLoader cl = null;
if (loader != null) {
cl = (ClassLoader) loader.getReferencedObject();
cl = loader.getReferencedObject();
}
boolean clNeedsCleanup = false;
if (cl == null) {
@@ -252,6 +252,11 @@ public abstract class AbstractClasspathResource extends Resource {
}
}

@Override
protected AbstractClasspathResource getRef() {
return getCheckedRef(AbstractClasspathResource.class);
}

public static class ClassLoaderWithFlag {
private final ClassLoader loader;
private final boolean cleanup;


+ 8
- 4
src/main/org/apache/tools/ant/types/resources/AbstractResourceCollectionWrapper.java View File

@@ -89,7 +89,7 @@ public abstract class AbstractResourceCollectionWrapper
@Override
public final synchronized Iterator<Resource> iterator() {
if (isReference()) {
return ((AbstractResourceCollectionWrapper) getCheckedRef()).iterator();
return getRef().iterator();
}
dieOnCircularReference();
return new FailFast(this, createIterator());
@@ -112,7 +112,7 @@ public abstract class AbstractResourceCollectionWrapper
@Override
public synchronized int size() {
if (isReference()) {
return ((AbstractResourceCollectionWrapper) getCheckedRef()).size();
return getRef().size();
}
dieOnCircularReference();
return getSize();
@@ -132,7 +132,7 @@ public abstract class AbstractResourceCollectionWrapper
*/
public synchronized boolean isFilesystemOnly() {
if (isReference()) {
return ((BaseResourceCollectionContainer) getCheckedRef()).isFilesystemOnly();
return getRef().isFilesystemOnly();
}
dieOnCircularReference();

@@ -191,7 +191,7 @@ public abstract class AbstractResourceCollectionWrapper
@Override
public synchronized String toString() {
if (isReference()) {
return getCheckedRef().toString();
return getRef().toString();
}
if (isEmpty()) {
return "";
@@ -200,6 +200,10 @@ public abstract class AbstractResourceCollectionWrapper
.collect(Collectors.joining(File.pathSeparator));
}

private AbstractResourceCollectionWrapper getRef() {
return getCheckedRef(AbstractResourceCollectionWrapper.class);
}

private BuildException oneNested() {
return new BuildException(super.toString() + ONE_NESTED_MESSAGE);
}


+ 10
- 10
src/main/org/apache/tools/ant/types/resources/ArchiveResource.java View File

@@ -118,7 +118,7 @@ public abstract class ArchiveResource extends Resource {
* @return the archive as a Resource.
*/
public Resource getArchive() {
return isReference() ? getCheckedRef().getArchive() : archive;
return isReference() ? getRef().getArchive() : archive;
}

/**
@@ -128,7 +128,7 @@ public abstract class ArchiveResource extends Resource {
@Override
public long getLastModified() {
if (isReference()) {
return getCheckedRef().getLastModified();
return getRef().getLastModified();
}
checkEntry();
return super.getLastModified();
@@ -141,7 +141,7 @@ public abstract class ArchiveResource extends Resource {
@Override
public long getSize() {
if (isReference()) {
return getCheckedRef().getSize();
return getRef().getSize();
}
checkEntry();
return super.getSize();
@@ -154,7 +154,7 @@ public abstract class ArchiveResource extends Resource {
@Override
public boolean isDirectory() {
if (isReference()) {
return getCheckedRef().isDirectory();
return getRef().isDirectory();
}
checkEntry();
return super.isDirectory();
@@ -167,7 +167,7 @@ public abstract class ArchiveResource extends Resource {
@Override
public boolean isExists() {
if (isReference()) {
return getCheckedRef().isExists();
return getRef().isExists();
}
checkEntry();
return super.isExists();
@@ -179,7 +179,7 @@ public abstract class ArchiveResource extends Resource {
*/
public int getMode() {
if (isReference()) {
return getCheckedRef().getMode();
return getRef().getMode();
}
checkEntry();
return mode;
@@ -220,7 +220,7 @@ public abstract class ArchiveResource extends Resource {
return true;
}
if (isReference()) {
return getCheckedRef().equals(another);
return getRef().equals(another);
}
if (another == null || !another.getClass().equals(getClass())) {
return false;
@@ -246,7 +246,7 @@ public abstract class ArchiveResource extends Resource {
*/
@Override
public String toString() {
return isReference() ? getCheckedRef().toString()
return isReference() ? getRef().toString()
: getArchive().toString() + ':' + getName();
}

@@ -301,7 +301,7 @@ public abstract class ArchiveResource extends Resource {
}

@Override
protected ArchiveResource getCheckedRef() {
return (ArchiveResource) super.getCheckedRef();
protected ArchiveResource getRef() {
return getCheckedRef(ArchiveResource.class);
}
}

+ 5
- 6
src/main/org/apache/tools/ant/types/resources/Archives.java View File

@@ -81,7 +81,7 @@ public class Archives extends DataType
@Override
public int size() {
if (isReference()) {
return getCheckedRef().size();
return getRef().size();
}
dieOnCircularReference();
return streamArchives().mapToInt(ArchiveFileSet::size).sum();
@@ -94,7 +94,7 @@ public class Archives extends DataType
*/
public Iterator<Resource> iterator() {
if (isReference()) {
return getCheckedRef().iterator();
return getRef().iterator();
}
dieOnCircularReference();
return streamArchives().flatMap(ResourceCollection::stream)
@@ -106,7 +106,7 @@ public class Archives extends DataType
*/
public boolean isFilesystemOnly() {
if (isReference()) {
return getCheckedRef().isFilesystemOnly();
return getRef().isFilesystemOnly();
}
dieOnCircularReference();
// TODO check each archive in turn?
@@ -207,9 +207,8 @@ public class Archives extends DataType
}
}

@Override
protected Archives getCheckedRef() {
return (Archives) super.getCheckedRef();
private Archives getRef() {
return getCheckedRef(Archives.class);
}

}

+ 6
- 2
src/main/org/apache/tools/ant/types/resources/BCFileSet.java View File

@@ -50,7 +50,7 @@ public class BCFileSet extends FileSet {
@Override
public Iterator<Resource> iterator() {
if (isReference()) {
return ((FileSet) getRef(getProject())).iterator();
return getRef().iterator();
}
FileResourceIterator result = new FileResourceIterator(getProject(), getDir());
result.addFiles(getDirectoryScanner().getIncludedFiles());
@@ -66,10 +66,14 @@ public class BCFileSet extends FileSet {
@Override
public int size() {
if (isReference()) {
return ((FileSet) getRef(getProject())).size();
return getRef().size();
}
return getDirectoryScanner().getIncludedFilesCount()
+ getDirectoryScanner().getIncludedDirsCount();
}

private FileSet getRef() {
return getCheckedRef(FileSet.class);
}

}

+ 6
- 8
src/main/org/apache/tools/ant/types/resources/BaseResourceCollectionContainer.java View File

@@ -136,7 +136,7 @@ public abstract class BaseResourceCollectionContainer
@Override
public final synchronized Iterator<Resource> iterator() {
if (isReference()) {
return getCheckedRef().iterator();
return getRef().iterator();
}
dieOnCircularReference();
return new FailFast(this, cacheCollection().iterator());
@@ -149,8 +149,7 @@ public abstract class BaseResourceCollectionContainer
@Override
public synchronized int size() {
if (isReference()) {
return getCheckedRef(BaseResourceCollectionContainer.class,
getDataTypeName()).size();
return getRef().size();
}
dieOnCircularReference();
return cacheCollection().size();
@@ -163,7 +162,7 @@ public abstract class BaseResourceCollectionContainer
@Override
public synchronized boolean isFilesystemOnly() {
if (isReference()) {
return getCheckedRef().isFilesystemOnly();
return getRef().isFilesystemOnly();
}
dieOnCircularReference();
//first the easy way, if all children are filesystem-only, return true:
@@ -240,7 +239,7 @@ public abstract class BaseResourceCollectionContainer
@Override
public synchronized String toString() {
if (isReference()) {
return getCheckedRef().toString();
return getRef().toString();
}
if (cacheCollection().isEmpty()) {
return "";
@@ -249,9 +248,8 @@ public abstract class BaseResourceCollectionContainer
.collect(Collectors.joining(File.pathSeparator));
}

@Override
protected BaseResourceCollectionContainer getCheckedRef() {
return (BaseResourceCollectionContainer) super.getCheckedRef();
private BaseResourceCollectionContainer getRef() {
return getCheckedRef(BaseResourceCollectionContainer.class);
}

private synchronized Collection<Resource> cacheCollection() {


+ 18
- 18
src/main/org/apache/tools/ant/types/resources/FileResource.java View File

@@ -108,7 +108,7 @@ public class FileResource extends Resource implements Touchable, FileProvider,
@Override
public File getFile() {
if (isReference()) {
return getCheckedRef().getFile();
return getRef().getFile();
}
dieOnCircularReference();
synchronized (this) {
@@ -139,7 +139,7 @@ public class FileResource extends Resource implements Touchable, FileProvider,
*/
public File getBaseDir() {
if (isReference()) {
return getCheckedRef().getBaseDir();
return getRef().getBaseDir();
}
dieOnCircularReference();
return baseDir;
@@ -166,7 +166,7 @@ public class FileResource extends Resource implements Touchable, FileProvider,
@Override
public String getName() {
if (isReference()) {
return getCheckedRef().getName();
return getRef().getName();
}
File b = getBaseDir();
return b == null ? getNotNullFile().getName()
@@ -179,7 +179,7 @@ public class FileResource extends Resource implements Touchable, FileProvider,
*/
@Override
public boolean isExists() {
return isReference() ? getCheckedRef().isExists()
return isReference() ? getRef().isExists()
: getNotNullFile().exists();
}

@@ -190,7 +190,7 @@ public class FileResource extends Resource implements Touchable, FileProvider,
@Override
public long getLastModified() {
return isReference()
? getCheckedRef().getLastModified()
? getRef().getLastModified()
: getNotNullFile().lastModified();
}

@@ -200,7 +200,7 @@ public class FileResource extends Resource implements Touchable, FileProvider,
*/
@Override
public boolean isDirectory() {
return isReference() ? getCheckedRef().isDirectory()
return isReference() ? getRef().isDirectory()
: getNotNullFile().isDirectory();
}

@@ -210,7 +210,7 @@ public class FileResource extends Resource implements Touchable, FileProvider,
*/
@Override
public long getSize() {
return isReference() ? getCheckedRef().getSize()
return isReference() ? getRef().getSize()
: getNotNullFile().length();
}

@@ -221,7 +221,7 @@ public class FileResource extends Resource implements Touchable, FileProvider,
*/
@Override
public InputStream getInputStream() throws IOException {
return isReference() ? getCheckedRef().getInputStream()
return isReference() ? getRef().getInputStream()
: Files.newInputStream(getNotNullFile().toPath());
}

@@ -236,7 +236,7 @@ public class FileResource extends Resource implements Touchable, FileProvider,
@Override
public OutputStream getOutputStream() throws IOException {
if (isReference()) {
return getCheckedRef().getOutputStream();
return getRef().getOutputStream();
}
return getOutputStream(false);
}
@@ -247,7 +247,7 @@ public class FileResource extends Resource implements Touchable, FileProvider,
@Override
public OutputStream getAppendOutputStream() throws IOException {
if (isReference()) {
return getCheckedRef().getAppendOutputStream();
return getRef().getAppendOutputStream();
}
return getOutputStream(true);
}
@@ -276,7 +276,7 @@ public class FileResource extends Resource implements Touchable, FileProvider,
@Override
public int compareTo(Resource another) {
if (isReference()) {
return getCheckedRef().compareTo(another);
return getRef().compareTo(another);
}
if (this.equals(another)) {
return 0;
@@ -309,7 +309,7 @@ public class FileResource extends Resource implements Touchable, FileProvider,
return true;
}
if (isReference()) {
return getCheckedRef().equals(another);
return getRef().equals(another);
}
if (another == null || !(another.getClass().equals(getClass()))) {
return false;
@@ -327,7 +327,7 @@ public class FileResource extends Resource implements Touchable, FileProvider,
@Override
public int hashCode() {
if (isReference()) {
return getCheckedRef().hashCode();
return getRef().hashCode();
}
return MAGIC * (getFile() == null ? NULL_FILE : getFile().hashCode());
}
@@ -339,7 +339,7 @@ public class FileResource extends Resource implements Touchable, FileProvider,
@Override
public String toString() {
if (isReference()) {
return getCheckedRef().toString();
return getRef().toString();
}
if (file == null) {
return "(unbound file resource)";
@@ -355,7 +355,7 @@ public class FileResource extends Resource implements Touchable, FileProvider,
@Override
public boolean isFilesystemOnly() {
if (isReference()) {
return getCheckedRef().isFilesystemOnly();
return getRef().isFilesystemOnly();
}
dieOnCircularReference();
return true;
@@ -368,7 +368,7 @@ public class FileResource extends Resource implements Touchable, FileProvider,
@Override
public void touch(long modTime) {
if (isReference()) {
getCheckedRef().touch(modTime);
getRef().touch(modTime);
return;
}
if (!getNotNullFile().setLastModified(modTime)) {
@@ -408,7 +408,7 @@ public class FileResource extends Resource implements Touchable, FileProvider,
}

@Override
protected FileResource getCheckedRef() {
return (FileResource) super.getCheckedRef();
protected FileResource getRef() {
return getCheckedRef(FileResource.class);
}
}

+ 1
- 1
src/main/org/apache/tools/ant/types/resources/Files.java View File

@@ -458,7 +458,7 @@ public class Files extends AbstractSelectorContainer
* @return <code>FileCollection</code>.
*/
protected Files getRef() {
return (Files) getCheckedRef();
return getCheckedRef(Files.class);
}

private synchronized void ensureDirectoryScannerSetup() {


+ 4
- 4
src/main/org/apache/tools/ant/types/resources/JavaResource.java View File

@@ -82,7 +82,7 @@ public class JavaResource extends AbstractClasspathResource
@Override
public URL getURL() {
if (isReference()) {
return getCheckedRef().getURL();
return getRef().getURL();
}
AbstractClasspathResource.ClassLoaderWithFlag classLoader =
getClassLoader();
@@ -106,7 +106,7 @@ public class JavaResource extends AbstractClasspathResource
@Override
public int compareTo(Resource another) {
if (isReference()) {
return getCheckedRef().compareTo(another);
return getRef().compareTo(another);
}
if (another.getClass().equals(getClass())) {
JavaResource otherjr = (JavaResource) another;
@@ -140,7 +140,7 @@ public class JavaResource extends AbstractClasspathResource
}

@Override
protected JavaResource getCheckedRef() {
return (JavaResource) super.getCheckedRef();
protected JavaResource getRef() {
return getCheckedRef(JavaResource.class);
}
}

+ 1
- 1
src/main/org/apache/tools/ant/types/resources/MappedResource.java View File

@@ -108,7 +108,7 @@ public class MappedResource extends ResourceDecorator {
@Override
public String toString() {
if (isReference()) {
return getCheckedRef().toString();
return getRef().toString();
}
return getName();
}


+ 6
- 7
src/main/org/apache/tools/ant/types/resources/MappedResourceCollection.java View File

@@ -127,7 +127,7 @@ public class MappedResourceCollection
@Override
public boolean isFilesystemOnly() {
if (isReference()) {
return getCheckedRef().isFilesystemOnly();
return getRef().isFilesystemOnly();
}
checkInitialized();
return false;
@@ -139,7 +139,7 @@ public class MappedResourceCollection
@Override
public int size() {
if (isReference()) {
return getCheckedRef().size();
return getRef().size();
}
checkInitialized();
return cacheCollection().size();
@@ -151,7 +151,7 @@ public class MappedResourceCollection
@Override
public Iterator<Resource> iterator() {
if (isReference()) {
return getCheckedRef().iterator();
return getRef().iterator();
}
checkInitialized();
return cacheCollection().iterator();
@@ -254,14 +254,13 @@ public class MappedResourceCollection
@Override
public String toString() {
if (isReference()) {
return getCheckedRef().toString();
return getRef().toString();
}
return isEmpty() ? "" : stream().map(Object::toString)
.collect(Collectors.joining(File.pathSeparator));
}

@Override
protected MappedResourceCollection getCheckedRef() {
return (MappedResourceCollection) super.getCheckedRef();
private MappedResourceCollection getRef() {
return getCheckedRef(MappedResourceCollection.class);
}
}

+ 10
- 6
src/main/org/apache/tools/ant/types/resources/MultiRootFileSet.java View File

@@ -113,7 +113,7 @@ public class MultiRootFileSet extends AbstractFileSet
@Override
public Object clone() {
if (isReference()) {
return getRef(getProject()).clone();
return getRef().clone();
}
final MultiRootFileSet fs = (MultiRootFileSet) super.clone();
fs.baseDirs = new ArrayList<>(baseDirs);
@@ -128,7 +128,7 @@ public class MultiRootFileSet extends AbstractFileSet
@Override
public Iterator<Resource> iterator() {
if (isReference()) {
return ((MultiRootFileSet) getRef(getProject())).iterator();
return getRef().iterator();
}
return merge().iterator();
}
@@ -140,7 +140,7 @@ public class MultiRootFileSet extends AbstractFileSet
@Override
public int size() {
if (isReference()) {
return ((MultiRootFileSet) getRef(getProject())).size();
return getRef().size();
}
return merge().size();
}
@@ -162,11 +162,15 @@ public class MultiRootFileSet extends AbstractFileSet
@Override
public String toString() {
if (isReference()) {
return getRef(getProject()).toString();
return getRef().toString();
}
return merge().toString();
}

private MultiRootFileSet getRef() {
return getCheckedRef(MultiRootFileSet.class);
}

private synchronized Union merge() {
if (cache && union != null) {
return union;
@@ -210,7 +214,7 @@ public class MultiRootFileSet extends AbstractFileSet

@Override
public Iterator<Resource> iterator() {
final DirectoryScanner ds = getDirectoryScanner(getProject());
final DirectoryScanner ds = getDirectoryScanner();
String[] names = type == SetType.file
? ds.getIncludedFiles()
: ds.getIncludedDirectories();
@@ -227,7 +231,7 @@ public class MultiRootFileSet extends AbstractFileSet

@Override
public int size() {
final DirectoryScanner ds = getDirectoryScanner(getProject());
final DirectoryScanner ds = getDirectoryScanner();
int count = type == SetType.file
? ds.getIncludedFilesCount()
: ds.getIncludedDirsCount();


+ 5
- 5
src/main/org/apache/tools/ant/types/resources/PropertyResource.java View File

@@ -67,7 +67,7 @@ public class PropertyResource extends Resource {
*/
public String getValue() {
if (isReference()) {
return getCheckedRef().getValue();
return getRef().getValue();
}
Project p = getProject();
return p == null ? null : p.getProperty(getName());
@@ -80,7 +80,7 @@ public class PropertyResource extends Resource {
*/
public Object getObjectValue() {
if (isReference()) {
return getCheckedRef().getObjectValue();
return getRef().getObjectValue();
}
Project p = getProject();
return p == null ? null : PropertyHelper.getProperty(p, getName());
@@ -199,7 +199,7 @@ public class PropertyResource extends Resource {
*/
protected Resource getReferencedOrProxied() {
if (isReference()) {
return getCheckedRef(Resource.class, "resource");
return super.getRef();
}
Object o = getObjectValue();
if (o instanceof Resource) {
@@ -210,7 +210,7 @@ public class PropertyResource extends Resource {
}

@Override
protected PropertyResource getCheckedRef() {
return (PropertyResource) super.getCheckedRef();
protected PropertyResource getRef() {
return getCheckedRef(PropertyResource.class);
}
}

+ 1
- 1
src/main/org/apache/tools/ant/types/resources/ResourceDecorator.java View File

@@ -205,7 +205,7 @@ public abstract class ResourceDecorator extends Resource {
*/
protected final Resource getResource() {
if (isReference()) {
return getCheckedRef();
return getCheckedRef(Resource.class);
}
if (resource == null) {
throw new BuildException("no resource specified");


+ 5
- 6
src/main/org/apache/tools/ant/types/resources/ResourceList.java View File

@@ -143,7 +143,7 @@ public class ResourceList extends DataType implements ResourceCollection {
@Override
public final synchronized Iterator<Resource> iterator() {
if (isReference()) {
return getCheckedRef().iterator();
return getRef().iterator();
}
return cache().iterator();
}
@@ -156,7 +156,7 @@ public class ResourceList extends DataType implements ResourceCollection {
@Override
public synchronized int size() {
if (isReference()) {
return getCheckedRef().size();
return getRef().size();
}
return cache().size();
}
@@ -169,7 +169,7 @@ public class ResourceList extends DataType implements ResourceCollection {
@Override
public synchronized boolean isFilesystemOnly() {
if (isReference()) {
return getCheckedRef().isFilesystemOnly();
return getRef().isFilesystemOnly();
}
return cache().isFilesystemOnly();
}
@@ -203,9 +203,8 @@ public class ResourceList extends DataType implements ResourceCollection {
}
}

@Override
protected ResourceList getCheckedRef() {
return (ResourceList) super.getCheckedRef();
private ResourceList getRef() {
return getCheckedRef(ResourceList.class);
}

private synchronized ResourceCollection cache() {


+ 2
- 2
src/main/org/apache/tools/ant/types/resources/Resources.java View File

@@ -219,7 +219,7 @@ public class Resources extends DataType implements ResourceCollection {
@Override
public synchronized String toString() {
if (isReference()) {
return getCheckedRef().toString();
return getRef().toString();
}
validate();
if (coll == null || coll.isEmpty()) {
@@ -266,7 +266,7 @@ public class Resources extends DataType implements ResourceCollection {
* @return the referenced ResourceCollection.
*/
private ResourceCollection getRef() {
return getCheckedRef(ResourceCollection.class, "ResourceCollection");
return getCheckedRef(ResourceCollection.class);
}

private synchronized void validate() {


+ 6
- 7
src/main/org/apache/tools/ant/types/resources/Restrict.java View File

@@ -96,7 +96,7 @@ public class Restrict
@Override
public final synchronized Iterator<Resource> iterator() {
if (isReference()) {
return getCheckedRef().iterator();
return getRef().iterator();
}
dieOnCircularReference();
return w.iterator();
@@ -109,7 +109,7 @@ public class Restrict
@Override
public synchronized int size() {
if (isReference()) {
return getCheckedRef().size();
return getRef().size();
}
dieOnCircularReference();
return w.size();
@@ -122,7 +122,7 @@ public class Restrict
@Override
public synchronized boolean isFilesystemOnly() {
if (isReference()) {
return getCheckedRef().isFilesystemOnly();
return getRef().isFilesystemOnly();
}
dieOnCircularReference();
return w.isFilesystemOnly();
@@ -135,7 +135,7 @@ public class Restrict
@Override
public synchronized String toString() {
if (isReference()) {
return getCheckedRef().toString();
return getRef().toString();
}
dieOnCircularReference();
return w.toString();
@@ -156,8 +156,7 @@ public class Restrict
}
}

@Override
protected Restrict getCheckedRef() {
return (Restrict) super.getCheckedRef();
private Restrict getRef() {
return getCheckedRef(Restrict.class);
}
}

+ 6
- 6
src/main/org/apache/tools/ant/types/resources/StringResource.java View File

@@ -149,7 +149,7 @@ public class StringResource extends Resource {
*/
@Override
public synchronized long getSize() {
return isReference() ? getCheckedRef().getSize()
return isReference() ? getRef().getSize()
: getContent().length();
}

@@ -161,7 +161,7 @@ public class StringResource extends Resource {
public synchronized int hashCode() { //NOSONAR
// super.equals + super.compareTo are consistent with this implementation
if (isReference()) {
return getCheckedRef().hashCode();
return getRef().hashCode();
}
return super.hashCode() * STRING_MAGIC;
}
@@ -188,7 +188,7 @@ public class StringResource extends Resource {
@Override
public synchronized InputStream getInputStream() throws IOException {
if (isReference()) {
return getCheckedRef().getInputStream();
return getRef().getInputStream();
}
String content = getContent();
if (content == null) {
@@ -209,7 +209,7 @@ public class StringResource extends Resource {
@Override
public synchronized OutputStream getOutputStream() throws IOException {
if (isReference()) {
return getCheckedRef().getOutputStream();
return getRef().getOutputStream();
}
if (getValue() != null) {
throw new ImmutableResourceException();
@@ -238,8 +238,8 @@ public class StringResource extends Resource {
}

@Override
protected StringResource getCheckedRef() {
return (StringResource) super.getCheckedRef();
protected StringResource getRef() {
return getCheckedRef(StringResource.class);
}

private class StringResourceFilterOutputStream extends FilterOutputStream {


+ 8
- 8
src/main/org/apache/tools/ant/types/resources/TarResource.java View File

@@ -77,7 +77,7 @@ public class TarResource extends ArchiveResource {
@Override
public InputStream getInputStream() throws IOException {
if (isReference()) {
return getCheckedRef().getInputStream();
return getRef().getInputStream();
}
Resource archive = getArchive();
final TarInputStream i = new TarInputStream(archive.getInputStream());
@@ -104,7 +104,7 @@ public class TarResource extends ArchiveResource {
@Override
public OutputStream getOutputStream() throws IOException {
if (isReference()) {
return getCheckedRef().getOutputStream();
return getRef().getOutputStream();
}
throw new UnsupportedOperationException(
"Use the tar task for tar output.");
@@ -115,7 +115,7 @@ public class TarResource extends ArchiveResource {
*/
public String getUserName() {
if (isReference()) {
return getCheckedRef().getUserName();
return getRef().getUserName();
}
checkEntry();
return userName;
@@ -126,7 +126,7 @@ public class TarResource extends ArchiveResource {
*/
public String getGroup() {
if (isReference()) {
return getCheckedRef().getGroup();
return getRef().getGroup();
}
checkEntry();
return groupName;
@@ -138,7 +138,7 @@ public class TarResource extends ArchiveResource {
*/
public long getLongUid() {
if (isReference()) {
return getCheckedRef().getLongUid();
return getRef().getLongUid();
}
checkEntry();
return uid;
@@ -158,7 +158,7 @@ public class TarResource extends ArchiveResource {
*/
public long getLongGid() {
if (isReference()) {
return getCheckedRef().getLongGid();
return getRef().getLongGid();
}
checkEntry();
return gid;
@@ -194,8 +194,8 @@ public class TarResource extends ArchiveResource {
}

@Override
protected TarResource getCheckedRef() {
return (TarResource) super.getCheckedRef();
protected TarResource getRef() {
return getCheckedRef(TarResource.class);
}

private void setEntry(TarEntry e) {


+ 16
- 11
src/main/org/apache/tools/ant/types/resources/URLResource.java View File

@@ -143,7 +143,7 @@ public class URLResource extends Resource implements URLProvider {
*/
public synchronized URL getURL() {
if (isReference()) {
return ((URLResource) getCheckedRef()).getURL();
return getRef().getURL();
}
if (url == null) {
if (baseURL != null) {
@@ -180,7 +180,7 @@ public class URLResource extends Resource implements URLProvider {
*/
public synchronized String getName() {
if (isReference()) {
return getCheckedRef().getName();
return getRef().getName();
}
String name = getURL().getFile();
return name.isEmpty() ? name : name.substring(1);
@@ -192,7 +192,7 @@ public class URLResource extends Resource implements URLProvider {
*/
public synchronized String toString() {
return isReference()
? getCheckedRef().toString() : String.valueOf(getURL());
? getRef().toString() : String.valueOf(getURL());
}

/**
@@ -201,7 +201,7 @@ public class URLResource extends Resource implements URLProvider {
*/
public synchronized boolean isExists() {
if (isReference()) {
return getCheckedRef().isExists();
return getRef().isExists();
}
return isExists(false);
}
@@ -262,7 +262,7 @@ public class URLResource extends Resource implements URLProvider {
*/
public synchronized long getLastModified() {
if (isReference()) {
return getCheckedRef().getLastModified();
return getRef().getLastModified();
}
if (!isExists(false)) {
return UNKNOWN_DATETIME;
@@ -276,7 +276,7 @@ public class URLResource extends Resource implements URLProvider {
*/
public synchronized boolean isDirectory() {
return isReference()
? getCheckedRef().isDirectory()
? getRef().isDirectory()
: getName().endsWith("/");
}

@@ -287,7 +287,7 @@ public class URLResource extends Resource implements URLProvider {
*/
public synchronized long getSize() {
if (isReference()) {
return getCheckedRef().getSize();
return getRef().getSize();
}
if (!isExists(false)) {
return 0L;
@@ -305,7 +305,7 @@ public class URLResource extends Resource implements URLProvider {
return true;
}
if (isReference()) {
return getCheckedRef().equals(another);
return getRef().equals(another);
}
if (another == null || another.getClass() != getClass()) {
return false;
@@ -322,7 +322,7 @@ public class URLResource extends Resource implements URLProvider {
*/
public synchronized int hashCode() {
if (isReference()) {
return getCheckedRef().hashCode();
return getRef().hashCode();
}
return MAGIC * ((getURL() == null) ? NULL_URL : getURL().hashCode());
}
@@ -337,7 +337,7 @@ public class URLResource extends Resource implements URLProvider {
*/
public synchronized InputStream getInputStream() throws IOException {
if (isReference()) {
return getCheckedRef().getInputStream();
return getRef().getInputStream();
}
connect();
try {
@@ -358,7 +358,7 @@ public class URLResource extends Resource implements URLProvider {
*/
public synchronized OutputStream getOutputStream() throws IOException {
if (isReference()) {
return getCheckedRef().getOutputStream();
return getRef().getOutputStream();
}
connect();
try {
@@ -401,6 +401,11 @@ public class URLResource extends Resource implements URLProvider {
}
}

@Override
protected URLResource getRef() {
return getCheckedRef(URLResource.class);
}

/**
* Closes the URL connection if:
* - it is opened (i.e. the field conn is not null)


+ 6
- 2
src/main/org/apache/tools/ant/types/resources/Union.java View File

@@ -82,7 +82,7 @@ public class Union extends BaseResourceCollectionContainer {
*/
public String[] list() {
if (isReference()) {
return getCheckedRef(Union.class, getDataTypeName()).list();
return getRef().list();
}
return streamResources().map(Object::toString).toArray(String[]::new);
}
@@ -93,7 +93,7 @@ public class Union extends BaseResourceCollectionContainer {
*/
public Resource[] listResources() {
if (isReference()) {
return getCheckedRef(Union.class, getDataTypeName()).listResources();
return getRef().listResources();
}
return streamResources().toArray(Resource[]::new);
}
@@ -139,6 +139,10 @@ public class Union extends BaseResourceCollectionContainer {
.collect(Collectors.toCollection(LinkedHashSet::new));
}

private Union getRef() {
return getCheckedRef(Union.class);
}

private Stream<? extends Resource> streamResources() {
return streamResources(Function.identity());
}


+ 9
- 4
src/main/org/apache/tools/ant/types/resources/ZipResource.java View File

@@ -105,7 +105,7 @@ public class ZipResource extends ArchiveResource {
*/
public String getEncoding() {
return isReference()
? ((ZipResource) getCheckedRef()).getEncoding() : encoding;
? getRef().getEncoding() : encoding;
}

/**
@@ -127,7 +127,7 @@ public class ZipResource extends ArchiveResource {
*/
public InputStream getInputStream() throws IOException {
if (isReference()) {
return getCheckedRef().getInputStream();
return getRef().getInputStream();
}
return getZipEntryStream(new ZipFile(getZipfile(), getEncoding()), getName());
}
@@ -142,7 +142,7 @@ public class ZipResource extends ArchiveResource {
*/
public OutputStream getOutputStream() throws IOException {
if (isReference()) {
return getCheckedRef().getOutputStream();
return getRef().getOutputStream();
}
throw new UnsupportedOperationException(
"Use the zip task for zip output.");
@@ -155,7 +155,7 @@ public class ZipResource extends ArchiveResource {
*/
public ZipExtraField[] getExtraFields() {
if (isReference()) {
return ((ZipResource) getCheckedRef()).getExtraFields();
return getRef().getExtraFields();
}
checkEntry();
if (extras == null) {
@@ -219,6 +219,11 @@ public class ZipResource extends ArchiveResource {
}
}

@Override
protected ZipResource getRef() {
return getCheckedRef(ZipResource.class);
}

private void setEntry(ZipEntry e) {
if (e == null) {
setExists(false);


+ 3
- 3
src/main/org/apache/tools/ant/types/resources/comparators/DelegatedResourceComparator.java View File

@@ -54,7 +54,7 @@ public class DelegatedResourceComparator extends ResourceComparator {

/**
* Equality method based on the vector of resources,
* or if a reference, the referredto object.
* or if a reference, the referred to object.
* @param o the object to check against.
* @return true if there is equality.
*/
@@ -64,7 +64,7 @@ public class DelegatedResourceComparator extends ResourceComparator {
return true;
}
if (isReference()) {
return getCheckedRef().equals(o);
return getCheckedRef(DelegatedResourceComparator.class).equals(o);
}
if (o instanceof DelegatedResourceComparator) {
List<ResourceComparator> ov = ((DelegatedResourceComparator) o).resourceComparators;
@@ -80,7 +80,7 @@ public class DelegatedResourceComparator extends ResourceComparator {
@Override
public synchronized int hashCode() {
if (isReference()) {
return getCheckedRef().hashCode();
return getCheckedRef(DelegatedResourceComparator.class).hashCode();
}
return resourceComparators == null ? 0 : resourceComparators.hashCode();
}


+ 5
- 6
src/main/org/apache/tools/ant/types/resources/comparators/ResourceComparator.java View File

@@ -39,7 +39,7 @@ public abstract class ResourceComparator extends DataType implements Comparator<
@Override
public final int compare(Resource foo, Resource bar) {
dieOnCircularReference();
ResourceComparator c = isReference() ? getCheckedRef() : this;
ResourceComparator c = isReference() ? getRef() : this;
return c.resourceCompare(foo, bar);
}

@@ -51,7 +51,7 @@ public abstract class ResourceComparator extends DataType implements Comparator<
@Override
public boolean equals(Object o) {
if (isReference()) {
return getCheckedRef().equals(o);
return getRef().equals(o);
}
return o != null && (o == this || o.getClass().equals(getClass()));
}
@@ -63,7 +63,7 @@ public abstract class ResourceComparator extends DataType implements Comparator<
@Override
public synchronized int hashCode() {
if (isReference()) {
return getCheckedRef().hashCode();
return getRef().hashCode();
}
return getClass().hashCode();
}
@@ -77,8 +77,7 @@ public abstract class ResourceComparator extends DataType implements Comparator<
*/
protected abstract int resourceCompare(Resource foo, Resource bar);

@Override
protected ResourceComparator getCheckedRef() {
return (ResourceComparator) super.getCheckedRef();
private ResourceComparator getRef() {
return getCheckedRef(ResourceComparator.class);
}
}

+ 5
- 1
src/main/org/apache/tools/ant/types/resources/selectors/Compare.java View File

@@ -100,7 +100,7 @@ public class Compare extends DataType implements ResourceSelector {
/** {@inheritDoc} */
public synchronized boolean isSelected(Resource r) {
if (isReference()) {
return ((ResourceSelector) getCheckedRef()).isSelected(r);
return getRef().isSelected(r);
}
if (control == null) {
throw oneControl();
@@ -140,6 +140,10 @@ public class Compare extends DataType implements ResourceSelector {
}
}

private ResourceSelector getRef() {
return getCheckedRef(ResourceSelector.class);
}

private BuildException oneControl() {
return new BuildException("%s the <control> element should be specified exactly once.",
super.toString());


+ 6
- 7
src/main/org/apache/tools/ant/types/resources/selectors/ResourceSelectorContainer.java View File

@@ -72,7 +72,7 @@ public class ResourceSelectorContainer extends DataType {
*/
public boolean hasSelectors() {
if (isReference()) {
return getCheckedRef().hasSelectors();
return getRef().hasSelectors();
}
dieOnCircularReference();
return !resourceSelectors.isEmpty();
@@ -84,7 +84,7 @@ public class ResourceSelectorContainer extends DataType {
*/
public int selectorCount() {
if (isReference()) {
return getCheckedRef().selectorCount();
return getRef().selectorCount();
}
dieOnCircularReference();
return resourceSelectors.size();
@@ -96,7 +96,7 @@ public class ResourceSelectorContainer extends DataType {
*/
public Iterator<ResourceSelector> getSelectors() {
if (isReference()) {
return getCheckedRef().getSelectors();
return getRef().getSelectors();
}
return getResourceSelectors().iterator();
}
@@ -107,7 +107,7 @@ public class ResourceSelectorContainer extends DataType {
*/
public List<ResourceSelector> getResourceSelectors() {
if (isReference()) {
return getCheckedRef().getResourceSelectors();
return getRef().getResourceSelectors();
}
dieOnCircularReference();
return Collections.unmodifiableList(resourceSelectors);
@@ -136,8 +136,7 @@ public class ResourceSelectorContainer extends DataType {
}
}

@Override
protected ResourceSelectorContainer getCheckedRef() {
return (ResourceSelectorContainer) super.getCheckedRef();
private ResourceSelectorContainer getRef() {
return getCheckedRef(ResourceSelectorContainer.class);
}
}

+ 13
- 10
src/main/org/apache/tools/ant/types/selectors/AbstractSelectorContainer.java View File

@@ -50,7 +50,7 @@ public abstract class AbstractSelectorContainer extends DataType
@Override
public boolean hasSelectors() {
if (isReference()) {
return getCheckedRef().hasSelectors();
return getRef().hasSelectors();
}
dieOnCircularReference();
return !selectorsList.isEmpty();
@@ -62,7 +62,7 @@ public abstract class AbstractSelectorContainer extends DataType
*/
public int selectorCount() {
if (isReference()) {
return getCheckedRef().selectorCount();
return getRef().selectorCount();
}
dieOnCircularReference();
return selectorsList.size();
@@ -75,8 +75,7 @@ public abstract class AbstractSelectorContainer extends DataType
*/
public FileSelector[] getSelectors(Project p) {
if (isReference()) {
return getCheckedRef(AbstractSelectorContainer.class,
getDataTypeName(), p).getSelectors(p);
return getRef(p).getSelectors(p);
}
dieOnCircularReference(p);
return selectorsList.toArray(new FileSelector[selectorsList.size()]);
@@ -88,7 +87,7 @@ public abstract class AbstractSelectorContainer extends DataType
*/
public Enumeration<FileSelector> selectorElements() {
if (isReference()) {
return getCheckedRef().selectorElements();
return getRef().selectorElements();
}
dieOnCircularReference();
return Collections.enumeration(selectorsList);
@@ -137,7 +136,7 @@ public abstract class AbstractSelectorContainer extends DataType
*/
public void validate() {
if (isReference()) {
getCheckedRef().validate();
getRef().validate();
}
dieOnCircularReference();
selectorsList.stream().filter(BaseSelector.class::isInstance)
@@ -367,7 +366,7 @@ public abstract class AbstractSelectorContainer extends DataType

public synchronized Object clone() {
if (isReference()) {
return getCheckedRef().clone();
return getRef().clone();
}
try {
AbstractSelectorContainer sc =
@@ -379,9 +378,13 @@ public abstract class AbstractSelectorContainer extends DataType
}
}

@Override
protected AbstractSelectorContainer getCheckedRef() {
return (AbstractSelectorContainer) super.getCheckedRef();

private AbstractSelectorContainer getRef(Project p) {
return getCheckedRef(AbstractSelectorContainer.class, getDataTypeName(), p);
}

private AbstractSelectorContainer getRef() {
return getCheckedRef(AbstractSelectorContainer.class);
}

}

+ 3
- 4
src/main/org/apache/tools/ant/types/selectors/BaseSelector.java View File

@@ -80,7 +80,7 @@ public abstract class BaseSelector extends DataType implements FileSelector {
*/
public void verifySettings() {
if (isReference()) {
getCheckedRef().verifySettings();
getRef().verifySettings();
}
}

@@ -114,9 +114,8 @@ public abstract class BaseSelector extends DataType implements FileSelector {
public abstract boolean isSelected(File basedir, String filename,
File file);

@Override
protected BaseSelector getCheckedRef() {
return (BaseSelector) super.getCheckedRef();
private BaseSelector getRef() {
return getCheckedRef(BaseSelector.class);
}
}



+ 1
- 1
src/main/org/apache/tools/ant/types/selectors/SelectSelector.java View File

@@ -66,7 +66,7 @@ public class SelectSelector extends BaseSelectorContainer {
* referenced Selector.
*/
private SelectSelector getRef() {
return getCheckedRef(this.getClass(), "SelectSelector");
return getCheckedRef(SelectSelector.class);
}

/**


+ 4
- 1
src/tests/junit/org/apache/tools/ant/taskdefs/TarTest.java View File

@@ -182,5 +182,8 @@ public class TarTest {
FileUtilities.getFileContents(new File(buildRule.getProject().getProperty("output"), "untar/asf-logo.gif.gz")));
}


@Test
public void testtestTarFilesetWithReference() {
buildRule.executeTarget("testTarFilesetWithReference");
}
}

Loading…
Cancel
Save