Browse Source

make it compile under Java5 (1.5.0_22-b03)

master
Jan Matèrne 11 years ago
parent
commit
13f6d98c9d
37 changed files with 1284 additions and 1423 deletions
  1. +0
    -11
      src/main/org/apache/tools/ant/AntClassLoader.java
  2. +112
    -130
      src/main/org/apache/tools/ant/DirectoryScanner.java
  3. +0
    -2
      src/main/org/apache/tools/ant/Main.java
  4. +0
    -1
      src/main/org/apache/tools/ant/Project.java
  5. +2
    -3
      src/main/org/apache/tools/ant/filters/ConcatFilter.java
  6. +0
    -4
      src/main/org/apache/tools/ant/taskdefs/AntStructure.java
  7. +9
    -9
      src/main/org/apache/tools/ant/taskdefs/Copy.java
  8. +62
    -70
      src/main/org/apache/tools/ant/taskdefs/Get.java
  9. +249
    -248
      src/main/org/apache/tools/ant/taskdefs/Javadoc.java
  10. +112
    -92
      src/main/org/apache/tools/ant/taskdefs/Tar.java
  11. +103
    -109
      src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java
  12. +173
    -178
      src/main/org/apache/tools/ant/taskdefs/Zip.java
  13. +15
    -16
      src/main/org/apache/tools/ant/taskdefs/compilers/AptCompilerAdapter.java
  14. +0
    -2
      src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java
  15. +12
    -13
      src/main/org/apache/tools/ant/taskdefs/condition/IsReachable.java
  16. +55
    -65
      src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java
  17. +0
    -2
      src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnit4TestMethodAdapter.java
  18. +184
    -186
      src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
  19. +0
    -22
      src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java
  20. +0
    -9
      src/main/org/apache/tools/ant/taskdefs/optional/junit/TearDownOnVmCrash.java
  21. +0
    -11
      src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLJUnitResultFormatter.java
  22. +0
    -3
      src/main/org/apache/tools/ant/types/mappers/CutDirsMapper.java
  23. +12
    -15
      src/main/org/apache/tools/ant/types/resources/Archives.java
  24. +4
    -5
      src/main/org/apache/tools/ant/types/resources/ContentTransformingResource.java
  25. +6
    -12
      src/main/org/apache/tools/ant/types/resources/LazyResourceCollectionWrapper.java
  26. +17
    -23
      src/main/org/apache/tools/ant/types/resources/MultiRootFileSet.java
  27. +0
    -1
      src/main/org/apache/tools/ant/types/resources/selectors/Type.java
  28. +0
    -2
      src/main/org/apache/tools/ant/util/ResourceUtils.java
  29. +15
    -16
      src/main/org/apache/tools/ant/util/SymbolicLinkUtils.java
  30. +28
    -31
      src/main/org/apache/tools/tar/TarUtils.java
  31. +9
    -14
      src/main/org/apache/tools/zip/AbstractUnicodeExtraField.java
  32. +4
    -7
      src/main/org/apache/tools/zip/FallbackZipEncoding.java
  33. +8
    -11
      src/main/org/apache/tools/zip/NioZipEncoding.java
  34. +21
    -25
      src/main/org/apache/tools/zip/Simple8BitZipEncoding.java
  35. +3
    -4
      src/main/org/apache/tools/zip/UnicodeCommentExtraField.java
  36. +2
    -3
      src/main/org/apache/tools/zip/UnicodePathExtraField.java
  37. +67
    -68
      src/main/org/apache/tools/zip/ZipFile.java

+ 0
- 11
src/main/org/apache/tools/ant/AntClassLoader.java View File

@@ -119,7 +119,6 @@ public class AntClassLoader extends ClassLoader implements SubBuildListener {
* @return <code>true</code> if there are more elements in the
* enumeration; <code>false</code> otherwise.
*/
@Override
public boolean hasMoreElements() {
return (this.nextResource != null);
}
@@ -129,7 +128,6 @@ public class AntClassLoader extends ClassLoader implements SubBuildListener {
*
* @return the next resource in the enumeration
*/
@Override
public URL nextElement() {
final URL ret = this.nextResource;
if (ret == null) {
@@ -1445,7 +1443,6 @@ public class AntClassLoader extends ClassLoader implements SubBuildListener {
*
* @param event the buildStarted event
*/
@Override
public void buildStarted(final BuildEvent event) {
// Not significant for the class loader.
}
@@ -1456,7 +1453,6 @@ public class AntClassLoader extends ClassLoader implements SubBuildListener {
*
* @param event the buildFinished event
*/
@Override
public void buildFinished(final BuildEvent event) {
cleanup();
}
@@ -1470,7 +1466,6 @@ public class AntClassLoader extends ClassLoader implements SubBuildListener {
*
* @since Ant 1.6.2
*/
@Override
public void subBuildFinished(final BuildEvent event) {
if (event.getProject() == project) {
cleanup();
@@ -1484,7 +1479,6 @@ public class AntClassLoader extends ClassLoader implements SubBuildListener {
*
* @since Ant 1.6.2
*/
@Override
public void subBuildStarted(final BuildEvent event) {
// Not significant for the class loader.
}
@@ -1494,7 +1488,6 @@ public class AntClassLoader extends ClassLoader implements SubBuildListener {
*
* @param event the targetStarted event
*/
@Override
public void targetStarted(final BuildEvent event) {
// Not significant for the class loader.
}
@@ -1504,7 +1497,6 @@ public class AntClassLoader extends ClassLoader implements SubBuildListener {
*
* @param event the targetFinished event
*/
@Override
public void targetFinished(final BuildEvent event) {
// Not significant for the class loader.
}
@@ -1514,7 +1506,6 @@ public class AntClassLoader extends ClassLoader implements SubBuildListener {
*
* @param event the taskStarted event
*/
@Override
public void taskStarted(final BuildEvent event) {
// Not significant for the class loader.
}
@@ -1524,7 +1515,6 @@ public class AntClassLoader extends ClassLoader implements SubBuildListener {
*
* @param event the taskFinished event
*/
@Override
public void taskFinished(final BuildEvent event) {
// Not significant for the class loader.
}
@@ -1534,7 +1524,6 @@ public class AntClassLoader extends ClassLoader implements SubBuildListener {
*
* @param event the messageLogged event
*/
@Override
public void messageLogged(final BuildEvent event) {
// Not significant for the class loader.
}


+ 112
- 130
src/main/org/apache/tools/ant/DirectoryScanner.java View File

@@ -310,7 +310,7 @@ public class DirectoryScanner
*
* @since Ant 1.6
*/
private Set<String> scannedDirs = new HashSet<String>();
private final Set<String> scannedDirs = new HashSet<String>();

/**
* Map of all include patterns that are full file names and don't
@@ -327,7 +327,7 @@ public class DirectoryScanner
*
* @since Ant 1.8.0
*/
private Map<String, TokenizedPath> includeNonPatterns = new HashMap<String, TokenizedPath>();
private final Map<String, TokenizedPath> includeNonPatterns = new HashMap<String, TokenizedPath>();

/**
* Map of all exclude patterns that are full file names and don't
@@ -344,7 +344,7 @@ public class DirectoryScanner
*
* @since Ant 1.8.0
*/
private Map<String, TokenizedPath> excludeNonPatterns = new HashMap<String, TokenizedPath>();
private final Map<String, TokenizedPath> excludeNonPatterns = new HashMap<String, TokenizedPath>();

/**
* Array of all include patterns that contain wildcards.
@@ -384,7 +384,7 @@ public class DirectoryScanner
*
* @since Ant 1.6.3
*/
private Object scanLock = new Object();
private final Object scanLock = new Object();

/**
* Slow scanning flag.
@@ -398,7 +398,7 @@ public class DirectoryScanner
*
* @since Ant 1.6.3
*/
private Object slowScanLock = new Object();
private final Object slowScanLock = new Object();

/**
* Exception thrown during scan.
@@ -423,7 +423,7 @@ public class DirectoryScanner
*
* @since Ant 1.8.0
*/
private Set<String> notFollowedSymlinks = new HashSet<String>();
private final Set<String> notFollowedSymlinks = new HashSet<String>();

/**
* Sole constructor.
@@ -447,7 +447,7 @@ public class DirectoryScanner
* @return whether or not a given path matches the start of a given
* pattern up to the first "**".
*/
protected static boolean matchPatternStart(String pattern, String str) {
protected static boolean matchPatternStart(final String pattern, final String str) {
return SelectorUtils.matchPatternStart(pattern, str);
}

@@ -469,8 +469,8 @@ public class DirectoryScanner
* @return whether or not a given path matches the start of a given
* pattern up to the first "**".
*/
protected static boolean matchPatternStart(String pattern, String str,
boolean isCaseSensitive) {
protected static boolean matchPatternStart(final String pattern, final String str,
final boolean isCaseSensitive) {
return SelectorUtils.matchPatternStart(pattern, str, isCaseSensitive);
}

@@ -485,7 +485,7 @@ public class DirectoryScanner
* @return <code>true</code> if the pattern matches against the string,
* or <code>false</code> otherwise.
*/
protected static boolean matchPath(String pattern, String str) {
protected static boolean matchPath(final String pattern, final String str) {
return SelectorUtils.matchPath(pattern, str);
}

@@ -502,8 +502,8 @@ public class DirectoryScanner
* @return <code>true</code> if the pattern matches against the string,
* or <code>false</code> otherwise.
*/
protected static boolean matchPath(String pattern, String str,
boolean isCaseSensitive) {
protected static boolean matchPath(final String pattern, final String str,
final boolean isCaseSensitive) {
return SelectorUtils.matchPath(pattern, str, isCaseSensitive);
}

@@ -521,7 +521,7 @@ public class DirectoryScanner
* @return <code>true</code> if the string matches against the pattern,
* or <code>false</code> otherwise.
*/
public static boolean match(String pattern, String str) {
public static boolean match(final String pattern, final String str) {
return SelectorUtils.match(pattern, str);
}

@@ -542,8 +542,8 @@ public class DirectoryScanner
* @return <code>true</code> if the string matches against the pattern,
* or <code>false</code> otherwise.
*/
protected static boolean match(String pattern, String str,
boolean isCaseSensitive) {
protected static boolean match(final String pattern, final String str,
final boolean isCaseSensitive) {
return SelectorUtils.match(pattern, str, isCaseSensitive);
}

@@ -574,7 +574,7 @@ public class DirectoryScanner
*
* @since Ant 1.6
*/
public static boolean addDefaultExclude(String s) {
public static boolean addDefaultExclude(final String s) {
synchronized (defaultExcludes) {
return defaultExcludes.add(s);
}
@@ -591,7 +591,7 @@ public class DirectoryScanner
*
* @since Ant 1.6
*/
public static boolean removeDefaultExclude(String s) {
public static boolean removeDefaultExclude(final String s) {
synchronized (defaultExcludes) {
return defaultExcludes.remove(s);
}
@@ -619,8 +619,7 @@ public class DirectoryScanner
*
* @param basedir The base directory to scan.
*/
@Override
public void setBasedir(String basedir) {
public void setBasedir(final String basedir) {
setBasedir(basedir == null ? (File) null
: new File(basedir.replace('/', File.separatorChar).replace(
'\\', File.separatorChar)));
@@ -632,8 +631,7 @@ public class DirectoryScanner
*
* @param basedir The base directory for scanning.
*/
@Override
public synchronized void setBasedir(File basedir) {
public synchronized void setBasedir(final File basedir) {
this.basedir = basedir;
}

@@ -643,7 +641,6 @@ public class DirectoryScanner
*
* @return the base directory to be scanned.
*/
@Override
public synchronized File getBasedir() {
return basedir;
}
@@ -665,8 +662,7 @@ public class DirectoryScanner
* @param isCaseSensitive whether or not the file system should be
* regarded as a case sensitive one.
*/
@Override
public synchronized void setCaseSensitive(boolean isCaseSensitive) {
public synchronized void setCaseSensitive(final boolean isCaseSensitive) {
this.isCaseSensitive = isCaseSensitive;
}

@@ -677,7 +673,7 @@ public class DirectoryScanner
* is an error
* @since Ant 1.7.1
*/
public void setErrorOnMissingDir(boolean errorOnMissingDir) {
public void setErrorOnMissingDir(final boolean errorOnMissingDir) {
this.errorOnMissingDir = errorOnMissingDir;
}

@@ -697,7 +693,7 @@ public class DirectoryScanner
*
* @param followSymlinks whether or not symbolic links should be followed.
*/
public synchronized void setFollowSymlinks(boolean followSymlinks) {
public synchronized void setFollowSymlinks(final boolean followSymlinks) {
this.followSymlinks = followSymlinks;
}

@@ -707,7 +703,7 @@ public class DirectoryScanner
*
* @since Ant 1.8.0
*/
public void setMaxLevelsOfSymlinks(int max) {
public void setMaxLevelsOfSymlinks(final int max) {
maxLevelsOfSymlinks = max;
}

@@ -724,8 +720,7 @@ public class DirectoryScanner
* list is given, all elements must be
* non-<code>null</code>.
*/
@Override
public synchronized void setIncludes(String[] includes) {
public synchronized void setIncludes(final String[] includes) {
if (includes == null) {
this.includes = null;
} else {
@@ -748,8 +743,7 @@ public class DirectoryScanner
* should be excluded. If a non-<code>null</code> list is
* given, all elements must be non-<code>null</code>.
*/
@Override
public synchronized void setExcludes(String[] excludes) {
public synchronized void setExcludes(final String[] excludes) {
if (excludes == null) {
this.excludes = null;
} else {
@@ -773,10 +767,10 @@ public class DirectoryScanner
*
* @since Ant 1.6.3
*/
public synchronized void addExcludes(String[] excludes) {
public synchronized void addExcludes(final String[] excludes) {
if (excludes != null && excludes.length > 0) {
if (this.excludes != null && this.excludes.length > 0) {
String[] tmp = new String[excludes.length
final String[] tmp = new String[excludes.length
+ this.excludes.length];
System.arraycopy(this.excludes, 0, tmp, 0,
this.excludes.length);
@@ -800,7 +794,7 @@ public class DirectoryScanner
*
* @since Ant 1.6.3
*/
private static String normalizePattern(String p) {
private static String normalizePattern(final String p) {
String pattern = p.replace('/', File.separatorChar)
.replace('\\', File.separatorChar);
if (pattern.endsWith(File.separator)) {
@@ -814,8 +808,7 @@ public class DirectoryScanner
*
* @param selectors specifies the selectors to be invoked on a scan.
*/
@Override
public synchronized void setSelectors(FileSelector[] selectors) {
public synchronized void setSelectors(final FileSelector[] selectors) {
this.selectors = selectors;
}

@@ -840,14 +833,13 @@ public class DirectoryScanner
* @exception IllegalStateException if the base directory was set
* incorrectly (i.e. if it doesn't exist or isn't a directory).
*/
@Override
public void scan() throws IllegalStateException {
synchronized (scanLock) {
if (scanning) {
while (scanning) {
try {
scanLock.wait();
} catch (InterruptedException e) {
} catch (final InterruptedException e) {
continue;
}
}
@@ -858,17 +850,17 @@ public class DirectoryScanner
}
scanning = true;
}
File savedBase = basedir;
final File savedBase = basedir;
try {
synchronized (this) {
illegal = null;
clearResults();

// set in/excludes to reasonable defaults if needed:
boolean nullIncludes = (includes == null);
final boolean nullIncludes = (includes == null);
includes = nullIncludes
? new String[] {SelectorUtils.DEEP_TREE_MATCH} : includes;
boolean nullExcludes = (excludes == null);
final boolean nullExcludes = (excludes == null);
excludes = nullExcludes ? new String[0] : excludes;

if (basedir != null && !followSymlinks
@@ -920,7 +912,7 @@ public class DirectoryScanner
includes = nullIncludes ? null : includes;
excludes = nullExcludes ? null : excludes;
}
} catch (IOException ex) {
} catch (final IOException ex) {
throw new BuildException(ex);
} finally {
basedir = savedBase;
@@ -938,19 +930,19 @@ public class DirectoryScanner
*/
private void checkIncludePatterns() {
ensureNonPatternSetsReady();
Map<TokenizedPath, String> newroots = new HashMap<TokenizedPath, String>();
final Map<TokenizedPath, String> newroots = new HashMap<TokenizedPath, String>();

// put in the newroots map the include patterns without
// wildcard tokens
for (int i = 0; i < includePatterns.length; i++) {
String pattern = includePatterns[i].toString();
final String pattern = includePatterns[i].toString();
if (!shouldSkipPattern(pattern)) {
newroots.put(includePatterns[i].rtrimWildcardTokens(),
pattern);
}
}
for (Map.Entry<String, TokenizedPath> entry : includeNonPatterns.entrySet()) {
String pattern = entry.getKey();
for (final Map.Entry<String, TokenizedPath> entry : includeNonPatterns.entrySet()) {
final String pattern = entry.getKey();
if (!shouldSkipPattern(pattern)) {
newroots.put(entry.getValue(), pattern);
}
@@ -965,13 +957,13 @@ public class DirectoryScanner
if (basedir != null) {
try {
canonBase = basedir.getCanonicalFile();
} catch (IOException ex) {
} catch (final IOException ex) {
throw new BuildException(ex);
}
}
// only scan directories that can include matched files or
// directories
for (Map.Entry<TokenizedPath, String> entry : newroots.entrySet()) {
for (final Map.Entry<TokenizedPath, String> entry : newroots.entrySet()) {
TokenizedPath currentPath = entry.getKey();
String currentelement = currentPath.toString();
if (basedir == null
@@ -985,7 +977,7 @@ public class DirectoryScanner
// the results to show what's really on the disk, so
// we need to double check.
try {
String path = (basedir == null)
final String path = (basedir == null)
? myfile.getCanonicalPath()
: FILE_UTILS.removeLeadingPath(canonBase,
myfile.getCanonicalFile());
@@ -1001,13 +993,13 @@ public class DirectoryScanner
}
}
}
} catch (IOException ex) {
} catch (final IOException ex) {
throw new BuildException(ex);
}
}

if ((myfile == null || !myfile.exists()) && !isCaseSensitive()) {
File f = currentPath.findFile(basedir, false);
final File f = currentPath.findFile(basedir, false);
if (f != null && f.exists()) {
// adapt currentelement to the case we've
// actually found
@@ -1032,8 +1024,8 @@ public class DirectoryScanner
scandir(myfile, currentPath, true);
}
} else if (myfile.isFile()) {
String originalpattern = entry.getValue();
boolean included = isCaseSensitive()
final String originalpattern = entry.getValue();
final boolean included = isCaseSensitive()
? originalpattern.equals(currentelement)
: originalpattern.equalsIgnoreCase(currentelement);
if (included) {
@@ -1051,7 +1043,7 @@ public class DirectoryScanner
*
* @since Ant 1.8.0
*/
private boolean shouldSkipPattern(String pattern) {
private boolean shouldSkipPattern(final String pattern) {
if (FileUtils.isAbsolutePath(pattern)) {
//skip abs. paths not under basedir, if set:
if (basedir != null
@@ -1101,7 +1093,7 @@ public class DirectoryScanner
while (slowScanning) {
try {
slowScanLock.wait();
} catch (InterruptedException e) {
} catch (final InterruptedException e) {
// Empty
}
}
@@ -1113,16 +1105,16 @@ public class DirectoryScanner
synchronized (this) {

// set in/excludes to reasonable defaults if needed:
boolean nullIncludes = (includes == null);
final boolean nullIncludes = (includes == null);
includes = nullIncludes
? new String[] {SelectorUtils.DEEP_TREE_MATCH} : includes;
boolean nullExcludes = (excludes == null);
final boolean nullExcludes = (excludes == null);
excludes = nullExcludes ? new String[0] : excludes;

String[] excl = new String[dirsExcluded.size()];
final String[] excl = new String[dirsExcluded.size()];
dirsExcluded.copyInto(excl);

String[] notIncl = new String[dirsNotIncluded.size()];
final String[] notIncl = new String[dirsNotIncluded.size()];
dirsNotIncluded.copyInto(notIncl);

ensureNonPatternSetsReady();
@@ -1142,9 +1134,9 @@ public class DirectoryScanner
}
}

private void processSlowScan(String[] arr) {
private void processSlowScan(final String[] arr) {
for (int i = 0; i < arr.length; i++) {
TokenizedPath path = new TokenizedPath(arr[i]);
final TokenizedPath path = new TokenizedPath(arr[i]);
if (!couldHoldIncluded(path) || contentsExcluded(path)) {
scandir(new File(basedir, arr[i]), path, false);
}
@@ -1171,7 +1163,7 @@ public class DirectoryScanner
* @see #dirsExcluded
* @see #slowScan
*/
protected void scandir(File dir, String vpath, boolean fast) {
protected void scandir(final File dir, final String vpath, final boolean fast) {
scandir(dir, new TokenizedPath(vpath), fast);
}

@@ -1195,11 +1187,11 @@ public class DirectoryScanner
* @see #dirsExcluded
* @see #slowScan
*/
private void scandir(File dir, TokenizedPath path, boolean fast) {
private void scandir(final File dir, final TokenizedPath path, final boolean fast) {
if (dir == null) {
throw new BuildException("dir must not be null.");
}
String[] newfiles = dir.list();
final String[] newfiles = dir.list();
if (newfiles == null) {
if (!dir.exists()) {
throw new BuildException(dir + DOES_NOT_EXIST_POSTFIX);
@@ -1213,8 +1205,8 @@ public class DirectoryScanner
scandir(dir, path, fast, newfiles, new LinkedList<String>());
}

private void scandir(File dir, TokenizedPath path, boolean fast,
String[] newfiles, LinkedList<String> directoryNamesFollowed) {
private void scandir(final File dir, final TokenizedPath path, final boolean fast,
String[] newfiles, final LinkedList<String> directoryNamesFollowed) {
String vpath = path.toString();
if (vpath.length() > 0 && !vpath.endsWith(File.separator)) {
vpath += File.separator;
@@ -1225,12 +1217,12 @@ public class DirectoryScanner
return;
}
if (!followSymlinks) {
ArrayList<String> noLinks = new ArrayList<String>();
final ArrayList<String> noLinks = new ArrayList<String>();
for (int i = 0; i < newfiles.length; i++) {
try {
if (SYMLINK_UTILS.isSymbolicLink(dir, newfiles[i])) {
String name = vpath + newfiles[i];
File file = new File(dir, newfiles[i]);
final String name = vpath + newfiles[i];
final File file = new File(dir, newfiles[i]);
if (file.isDirectory()) {
dirsExcluded.addElement(name);
} else if (file.isFile()) {
@@ -1240,8 +1232,8 @@ public class DirectoryScanner
} else {
noLinks.add(newfiles[i]);
}
} catch (IOException ioe) {
String msg = "IOException caught while checking "
} catch (final IOException ioe) {
final String msg = "IOException caught while checking "
+ "for links, couldn't get canonical path!";
// will be caught and redirected to Ant's logging system
System.err.println(msg);
@@ -1254,10 +1246,10 @@ public class DirectoryScanner
}

for (int i = 0; i < newfiles.length; i++) {
String name = vpath + newfiles[i];
TokenizedPath newPath = new TokenizedPath(path, newfiles[i]);
File file = new File(dir, newfiles[i]);
String[] children = file.list();
final String name = vpath + newfiles[i];
final TokenizedPath newPath = new TokenizedPath(path, newfiles[i]);
final File file = new File(dir, newfiles[i]);
final String[] children = file.list();
if (children == null || (children.length == 0 && file.isFile())) {
if (isIncluded(newPath)) {
accountForIncludedFile(newPath, file);
@@ -1307,7 +1299,7 @@ public class DirectoryScanner
* @param name path of the file relative to the directory of the FileSet.
* @param file included File.
*/
private void accountForIncludedFile(TokenizedPath name, File file) {
private void accountForIncludedFile(final TokenizedPath name, final File file) {
processIncluded(name, file, filesIncluded, filesExcluded,
filesDeselected);
}
@@ -1319,29 +1311,29 @@ public class DirectoryScanner
* @param file directory as File.
* @param fast whether to perform fast scans.
*/
private void accountForIncludedDir(TokenizedPath name, File file,
boolean fast) {
private void accountForIncludedDir(final TokenizedPath name, final File file,
final boolean fast) {
processIncluded(name, file, dirsIncluded, dirsExcluded, dirsDeselected);
if (fast && couldHoldIncluded(name) && !contentsExcluded(name)) {
scandir(file, name, fast);
}
}

private void accountForIncludedDir(TokenizedPath name,
File file, boolean fast,
String[] children,
LinkedList<String> directoryNamesFollowed) {
private void accountForIncludedDir(final TokenizedPath name,
final File file, final boolean fast,
final String[] children,
final LinkedList<String> directoryNamesFollowed) {
processIncluded(name, file, dirsIncluded, dirsExcluded, dirsDeselected);
if (fast && couldHoldIncluded(name) && !contentsExcluded(name)) {
scandir(file, name, fast, children, directoryNamesFollowed);
}
}

private void accountForNotFollowedSymlink(String name, File file) {
private void accountForNotFollowedSymlink(final String name, final File file) {
accountForNotFollowedSymlink(new TokenizedPath(name), file);
}

private void accountForNotFollowedSymlink(TokenizedPath name, File file) {
private void accountForNotFollowedSymlink(final TokenizedPath name, final File file) {
if (!isExcluded(name) &&
(isIncluded(name)
|| (file.isDirectory() && couldHoldIncluded(name)
@@ -1350,10 +1342,10 @@ public class DirectoryScanner
}
}

private void processIncluded(TokenizedPath path,
File file, Vector<String> inc, Vector<String> exc,
Vector<String> des) {
String name = path.toString();
private void processIncluded(final TokenizedPath path,
final File file, final Vector<String> inc, final Vector<String> exc,
final Vector<String> des) {
final String name = path.toString();
if (inc.contains(name) || exc.contains(name) || des.contains(name)) {
return;
}
@@ -1378,7 +1370,7 @@ public class DirectoryScanner
* @return <code>true</code> when the name matches against at least one
* include pattern, or <code>false</code> otherwise.
*/
protected boolean isIncluded(String name) {
protected boolean isIncluded(final String name) {
return isIncluded(new TokenizedPath(name));
}

@@ -1390,7 +1382,7 @@ public class DirectoryScanner
* @return <code>true</code> when the name matches against at least one
* include pattern, or <code>false</code> otherwise.
*/
private boolean isIncluded(TokenizedPath path) {
private boolean isIncluded(final TokenizedPath path) {
ensureNonPatternSetsReady();

if (isCaseSensitive()
@@ -1414,7 +1406,7 @@ public class DirectoryScanner
* @return <code>true</code> when the name matches against the start of at
* least one include pattern, or <code>false</code> otherwise.
*/
protected boolean couldHoldIncluded(String name) {
protected boolean couldHoldIncluded(final String name) {
return couldHoldIncluded(new TokenizedPath(name));
}

@@ -1426,13 +1418,13 @@ public class DirectoryScanner
* @return <code>true</code> when the name matches against the start of at
* least one include pattern, or <code>false</code> otherwise.
*/
private boolean couldHoldIncluded(TokenizedPath tokenizedName) {
private boolean couldHoldIncluded(final TokenizedPath tokenizedName) {
for (int i = 0; i < includePatterns.length; i++) {
if (couldHoldIncluded(tokenizedName, includePatterns[i])) {
return true;
}
}
for (Iterator<TokenizedPath> iter = includeNonPatterns.values().iterator();
for (final Iterator<TokenizedPath> iter = includeNonPatterns.values().iterator();
iter.hasNext();) {
if (couldHoldIncluded(tokenizedName,
iter.next().toPattern())) {
@@ -1450,8 +1442,8 @@ public class DirectoryScanner
* @return <code>true</code> when the name matches against the start of the
* include pattern, or <code>false</code> otherwise.
*/
private boolean couldHoldIncluded(TokenizedPath tokenizedName,
TokenizedPattern tokenizedInclude) {
private boolean couldHoldIncluded(final TokenizedPath tokenizedName,
final TokenizedPattern tokenizedInclude) {
return tokenizedInclude.matchStartOf(tokenizedName, isCaseSensitive())
&& isMorePowerfulThanExcludes(tokenizedName.toString())
&& isDeeper(tokenizedInclude, tokenizedName);
@@ -1465,7 +1457,7 @@ public class DirectoryScanner
* @return whether the pattern is deeper than the name.
* @since Ant 1.6.3
*/
private boolean isDeeper(TokenizedPattern pattern, TokenizedPath name) {
private boolean isDeeper(final TokenizedPattern pattern, final TokenizedPath name) {
return pattern.containsPattern(SelectorUtils.DEEP_TREE_MATCH)
|| pattern.depth() > name.depth();
}
@@ -1486,7 +1478,7 @@ public class DirectoryScanner
* this include pattern.
* @since Ant 1.6
*/
private boolean isMorePowerfulThanExcludes(String name) {
private boolean isMorePowerfulThanExcludes(final String name) {
final String soughtexclude =
name + File.separatorChar + SelectorUtils.DEEP_TREE_MATCH;
for (int counter = 0; counter < excludePatterns.length; counter++) {
@@ -1502,7 +1494,7 @@ public class DirectoryScanner
* @param path the path to check.
* @return whether all the specified directory's contents are excluded.
*/
/* package */ boolean contentsExcluded(TokenizedPath path) {
/* package */ boolean contentsExcluded(final TokenizedPath path) {
for (int i = 0; i < excludePatterns.length; i++) {
if (excludePatterns[i].endsWith(SelectorUtils.DEEP_TREE_MATCH)
&& excludePatterns[i].withoutLastToken()
@@ -1521,7 +1513,7 @@ public class DirectoryScanner
* @return <code>true</code> when the name matches against at least one
* exclude pattern, or <code>false</code> otherwise.
*/
protected boolean isExcluded(String name) {
protected boolean isExcluded(final String name) {
return isExcluded(new TokenizedPath(name));
}

@@ -1533,7 +1525,7 @@ public class DirectoryScanner
* @return <code>true</code> when the name matches against at least one
* exclude pattern, or <code>false</code> otherwise.
*/
private boolean isExcluded(TokenizedPath name) {
private boolean isExcluded(final TokenizedPath name) {
ensureNonPatternSetsReady();

if (isCaseSensitive()
@@ -1557,7 +1549,7 @@ public class DirectoryScanner
* @return <code>false</code> when the selectors says that the file
* should not be selected, <code>true</code> otherwise.
*/
protected boolean isSelected(String name, File file) {
protected boolean isSelected(final String name, final File file) {
if (selectors != null) {
for (int i = 0; i < selectors.length; i++) {
if (!selectors[i].isSelected(basedir, name, file)) {
@@ -1576,7 +1568,6 @@ public class DirectoryScanner
* @return the names of the files which matched at least one of the
* include patterns and none of the exclude patterns.
*/
@Override
public String[] getIncludedFiles() {
String[] files;
synchronized (this) {
@@ -1612,10 +1603,9 @@ public class DirectoryScanner
*
* @see #slowScan
*/
@Override
public synchronized String[] getNotIncludedFiles() {
slowScan();
String[] files = new String[filesNotIncluded.size()];
final String[] files = new String[filesNotIncluded.size()];
filesNotIncluded.copyInto(files);
return files;
}
@@ -1631,10 +1621,9 @@ public class DirectoryScanner
*
* @see #slowScan
*/
@Override
public synchronized String[] getExcludedFiles() {
slowScan();
String[] files = new String[filesExcluded.size()];
final String[] files = new String[filesExcluded.size()];
filesExcluded.copyInto(files);
return files;
}
@@ -1650,10 +1639,9 @@ public class DirectoryScanner
*
* @see #slowScan
*/
@Override
public synchronized String[] getDeselectedFiles() {
slowScan();
String[] files = new String[filesDeselected.size()];
final String[] files = new String[filesDeselected.size()];
filesDeselected.copyInto(files);
return files;
}
@@ -1666,7 +1654,6 @@ public class DirectoryScanner
* @return the names of the directories which matched at least one of the
* include patterns and none of the exclude patterns.
*/
@Override
public String[] getIncludedDirectories() {
String[] directories;
synchronized (this) {
@@ -1702,10 +1689,9 @@ public class DirectoryScanner
*
* @see #slowScan
*/
@Override
public synchronized String[] getNotIncludedDirectories() {
slowScan();
String[] directories = new String[dirsNotIncluded.size()];
final String[] directories = new String[dirsNotIncluded.size()];
dirsNotIncluded.copyInto(directories);
return directories;
}
@@ -1721,10 +1707,9 @@ public class DirectoryScanner
*
* @see #slowScan
*/
@Override
public synchronized String[] getExcludedDirectories() {
slowScan();
String[] directories = new String[dirsExcluded.size()];
final String[] directories = new String[dirsExcluded.size()];
dirsExcluded.copyInto(directories);
return directories;
}
@@ -1740,10 +1725,9 @@ public class DirectoryScanner
*
* @see #slowScan
*/
@Override
public synchronized String[] getDeselectedDirectories() {
slowScan();
String[] directories = new String[dirsDeselected.size()];
final String[] directories = new String[dirsDeselected.size()];
dirsDeselected.copyInto(directories);
return directories;
}
@@ -1770,11 +1754,10 @@ public class DirectoryScanner
/**
* Add default exclusions to the current exclusions set.
*/
@Override
public synchronized void addDefaultExcludes() {
int excludesLength = excludes == null ? 0 : excludes.length;
final int excludesLength = excludes == null ? 0 : excludes.length;
String[] newExcludes;
String[] defaultExcludesTemp = getDefaultExcludes();
final String[] defaultExcludesTemp = getDefaultExcludes();
newExcludes = new String[excludesLength + defaultExcludesTemp.length];
if (excludesLength > 0) {
System.arraycopy(excludes, 0, newExcludes, 0, excludesLength);
@@ -1794,8 +1777,7 @@ public class DirectoryScanner
* @return the resource with the given name.
* @since Ant 1.5.2
*/
@Override
public synchronized Resource getResource(String name) {
public synchronized Resource getResource(final String name) {
return new FileResource(basedir, name);
}

@@ -1807,7 +1789,7 @@ public class DirectoryScanner
*
* @since Ant 1.6
*/
private boolean hasBeenScanned(String vpath) {
private boolean hasBeenScanned(final String vpath) {
return !scannedDirs.add(vpath);
}

@@ -1855,11 +1837,11 @@ public class DirectoryScanner
* @param patterns String[] of patterns.
* @since Ant 1.8.0
*/
private TokenizedPattern[] fillNonPatternSet(Map<String, TokenizedPath> map, String[] patterns) {
ArrayList<TokenizedPattern> al = new ArrayList<TokenizedPattern>(patterns.length);
private TokenizedPattern[] fillNonPatternSet(final Map<String, TokenizedPath> map, final String[] patterns) {
final ArrayList<TokenizedPattern> al = new ArrayList<TokenizedPattern>(patterns.length);
for (int i = 0; i < patterns.length; i++) {
if (!SelectorUtils.hasWildcards(patterns[i])) {
String s = isCaseSensitive()
final String s = isCaseSensitive()
? patterns[i] : patterns[i].toUpperCase();
map.put(s, new TokenizedPath(s));
} else {
@@ -1880,21 +1862,21 @@ public class DirectoryScanner
*
* @since Ant 1.8.0
*/
private boolean causesIllegalSymlinkLoop(String dirName, File parent,
LinkedList<String> directoryNamesFollowed) {
private boolean causesIllegalSymlinkLoop(final String dirName, final File parent,
final LinkedList<String> directoryNamesFollowed) {
try {
if (directoryNamesFollowed.size() >= maxLevelsOfSymlinks
&& CollectionUtils.frequency(directoryNamesFollowed, dirName)
>= maxLevelsOfSymlinks
&& SYMLINK_UTILS.isSymbolicLink(parent, dirName)) {

ArrayList<String> files = new ArrayList<String>();
final ArrayList<String> files = new ArrayList<String>();
File f = FILE_UTILS.resolveFile(parent, dirName);
String target = f.getCanonicalPath();
final String target = f.getCanonicalPath();
files.add(target);

String relPath = "";
for (String dir : directoryNamesFollowed) {
for (final String dir : directoryNamesFollowed) {
relPath += "../";
if (dirName.equals(dir)) {
f = FILE_UTILS.resolveFile(parent, relPath + dir);
@@ -1909,7 +1891,7 @@ public class DirectoryScanner

}
return false;
} catch (IOException ex) {
} catch (final IOException ex) {
throw new BuildException("Caught error while checking for"
+ " symbolic links", ex);
}


+ 0
- 2
src/main/org/apache/tools/ant/Main.java View File

@@ -157,7 +157,6 @@ public class Main implements AntMain {
private final Map<Class<?>, List<String>> extraArguments = new HashMap<Class<?>, List<String>>();

private static final GetProperty NOPROPERTIES = new GetProperty() {
@Override
public Object getProperty(final String aName) {
// No existing property takes precedence
return null;
@@ -208,7 +207,6 @@ public class Main implements AntMain {
*
* @since Ant 1.6
*/
@Override
public void startAnt(final String[] args, final Properties additionalUserProperties,
final ClassLoader coreLoader) {



+ 0
- 1
src/main/org/apache/tools/ant/Project.java View File

@@ -2487,7 +2487,6 @@ public class Project implements ResourceFactory {
* @return the file resource.
* @since Ant 1.7
*/
@Override
public Resource getResource(final String name) {
return new FileResource(getBaseDir(), name);
}


+ 2
- 3
src/main/org/apache/tools/ant/filters/ConcatFilter.java View File

@@ -171,9 +171,8 @@ public final class ConcatFilter extends BaseParamFilterReader
* @return a new filter based on this configuration, but filtering
* the specified reader
*/
@Override
public Reader chain(final Reader rdr) {
ConcatFilter newFilter = new ConcatFilter(rdr);
final ConcatFilter newFilter = new ConcatFilter(rdr);
newFilter.setPrepend(getPrepend());
newFilter.setAppend(getAppend());
// Usually the initialized is set to true. But here it must not.
@@ -190,7 +189,7 @@ public final class ConcatFilter extends BaseParamFilterReader
*/
private void initialize() throws IOException {
// get parameters
Parameter[] params = getParameters();
final Parameter[] params = getParameters();
if (params != null) {
for (int i = 0; i < params.length; i++) {
if ("prepend".equals(params[i].getName())) {


+ 0
- 4
src/main/org/apache/tools/ant/taskdefs/AntStructure.java View File

@@ -182,12 +182,10 @@ public class AntStructure extends Task {

private final Hashtable<String, String> visited = new Hashtable<String, String>();

@Override
public void printTail(final PrintWriter out) {
visited.clear();
}

@Override
public void printHead(final PrintWriter out, final Project p, final Hashtable<String, Class<?>> tasks,
final Hashtable<String, Class<?>> types) {
printHead(out, tasks.keys(), types.keys());
@@ -246,7 +244,6 @@ public class AntStructure extends Task {
/**
* Prints the definition for the target element.
*/
@Override
public void printTargetDecl(final PrintWriter out) {
out.print("<!ELEMENT target (");
out.print(TASKS);
@@ -280,7 +277,6 @@ public class AntStructure extends Task {
/**
* Print the definition for a given element.
*/
@Override
public void printElementDecl(final PrintWriter out, final Project p,
final String name, final Class<?> element) {



+ 9
- 9
src/main/org/apache/tools/ant/taskdefs/Copy.java View File

@@ -823,16 +823,16 @@ public class Copy extends Task {
toCopy = new Resource[v.size()];
v.copyInto(toCopy);
} else {
toCopy =
ResourceUtils.selectOutOfDateSources(this, fromResources,
mapper,
new ResourceFactory() {
@Override
toCopy = ResourceUtils.selectOutOfDateSources(
this,
fromResources,
mapper,
new ResourceFactory() {
public Resource getResource(final String name) {
return new FileResource(toDir, name);
}
},
granularity);
return new FileResource(toDir, name);
}
},
granularity);
}
for (int i = 0; i < toCopy.length; i++) {
final String[] mappedFiles = mapper.mapFileName(toCopy[i].getName());


+ 62
- 70
src/main/org/apache/tools/ant/taskdefs/Get.java View File

@@ -71,7 +71,7 @@ public class Get extends Task {
private static final String DEFAULT_AGENT_PREFIX = "Apache Ant";
private static final String GZIP_CONTENT_ENCODING = "gzip";

private Resources sources = new Resources();
private final Resources sources = new Resources();
private File destination; // required
private boolean verbose = false;
private boolean quiet = false;
@@ -98,9 +98,9 @@ public class Get extends Task {
public void execute() throws BuildException {
checkAttributes();

for (Resource r : sources) {
URLProvider up = r.as(URLProvider.class);
URL source = up.getURL();
for (final Resource r : sources) {
final URLProvider up = r.as(URLProvider.class);
final URL source = up.getURL();

File dest = destination;
if (destination.isDirectory()) {
@@ -109,14 +109,14 @@ public class Get extends Task {
if (path.endsWith("/")) {
path = path.substring(0, path.length() - 1);
}
int slash = path.lastIndexOf("/");
final int slash = path.lastIndexOf("/");
if (slash > -1) {
path = path.substring(slash + 1);
}
dest = new File(destination, path);
} else {
FileNameMapper mapper = mapperElement.getImplementation();
String[] d = mapper.mapFileName(source.toString());
final FileNameMapper mapper = mapperElement.getImplementation();
final String[] d = mapper.mapFileName(source.toString());
if (d == null) {
log("skipping " + r + " - mapper can't handle it",
Project.MSG_WARN);
@@ -135,7 +135,7 @@ public class Get extends Task {
}

//set up logging
int logLevel = Project.MSG_INFO;
final int logLevel = Project.MSG_INFO;
DownloadProgress progress = null;
if (verbose) {
progress = new VerboseProgress(System.out);
@@ -144,7 +144,7 @@ public class Get extends Task {
//execute the get
try {
doGet(source, dest, logLevel, progress);
} catch (IOException ioe) {
} catch (final IOException ioe) {
log("Error getting " + source + " to " + dest);
if (!ignoreErrors) {
throw new BuildException(ioe, getLocation());
@@ -168,12 +168,12 @@ public class Get extends Task {
* @deprecated only gets the first configured resource
*/
@Deprecated
public boolean doGet(int logLevel, DownloadProgress progress)
public boolean doGet(final int logLevel, final DownloadProgress progress)
throws IOException {
checkAttributes();
for (Resource r : sources) {
URLProvider up = r.as(URLProvider.class);
URL source = up.getURL();
for (final Resource r : sources) {
final URLProvider up = r.as(URLProvider.class);
final URL source = up.getURL();
return doGet(source, destination, logLevel, progress);
}
/*NOTREACHED*/
@@ -197,7 +197,7 @@ public class Get extends Task {
* is false.
* @since Ant 1.8.0
*/
public boolean doGet(URL source, File dest, int logLevel,
public boolean doGet(final URL source, final File dest, final int logLevel,
DownloadProgress progress)
throws IOException {

@@ -221,13 +221,13 @@ public class Get extends Task {
if (useTimestamp && dest.exists()) {
timestamp = dest.lastModified();
if (verbose) {
Date t = new Date(timestamp);
final Date t = new Date(timestamp);
log("local file date : " + t.toString(), logLevel);
}
hasTimestamp = true;
}

GetThread getThread = new GetThread(source, dest,
final GetThread getThread = new GetThread(source, dest,
hasTimestamp, timestamp, progress,
logLevel, userAgent);
getThread.setDaemon(true);
@@ -235,13 +235,13 @@ public class Get extends Task {
getThread.start();
try {
getThread.join(maxTime * 1000);
} catch (InterruptedException ie) {
} catch (final InterruptedException ie) {
log("interrupted waiting for GET to finish",
Project.MSG_VERBOSE);
}

if (getThread.isAlive()) {
String msg = "The GET operation took longer than " + maxTime
final String msg = "The GET operation took longer than " + maxTime
+ " seconds, stopping it.";
if (ignoreErrors) {
log(msg);
@@ -257,7 +257,7 @@ public class Get extends Task {
}

@Override
public void log(String msg, int msgLevel) {
public void log(final String msg, final int msgLevel) {
if (!quiet || msgLevel >= Project.MSG_ERR) {
super.log(msg, msgLevel);
}
@@ -276,8 +276,8 @@ public class Get extends Task {
throw new BuildException("at least one source is required",
getLocation());
}
for (Resource r : sources) {
URLProvider up = r.as(URLProvider.class);
for (final Resource r : sources) {
final URLProvider up = r.as(URLProvider.class);
if (up == null) {
throw new BuildException("Only URLProvider resources are"
+ " supported", getLocation());
@@ -311,7 +311,7 @@ public class Get extends Task {
*
* @param u URL for the file.
*/
public void setSrc(URL u) {
public void setSrc(final URL u) {
add(new URLResource(u));
}

@@ -319,7 +319,7 @@ public class Get extends Task {
* Adds URLs to get.
* @since Ant 1.8.0
*/
public void add(ResourceCollection rc) {
public void add(final ResourceCollection rc) {
sources.add(rc);
}

@@ -328,7 +328,7 @@ public class Get extends Task {
*
* @param dest Path to file.
*/
public void setDest(File dest) {
public void setDest(final File dest) {
this.destination = dest;
}

@@ -337,7 +337,7 @@ public class Get extends Task {
*
* @param v if "true" then be verbose
*/
public void setVerbose(boolean v) {
public void setVerbose(final boolean v) {
verbose = v;
}

@@ -347,7 +347,7 @@ public class Get extends Task {
* @param v if "true" then be quiet
* @since Ant 1.9.4
*/
public void setQuiet(boolean v){
public void setQuiet(final boolean v){
this.quiet = v;
}

@@ -356,7 +356,7 @@ public class Get extends Task {
*
* @param v if "true" then don't report download errors up to ant
*/
public void setIgnoreErrors(boolean v) {
public void setIgnoreErrors(final boolean v) {
ignoreErrors = v;
}

@@ -378,7 +378,7 @@ public class Get extends Task {
* cause no end of grief.</p>
* @param v "true" to enable file time fetching
*/
public void setUseTimestamp(boolean v) {
public void setUseTimestamp(final boolean v) {
useTimestamp = v;
}

@@ -388,7 +388,7 @@ public class Get extends Task {
*
* @param u username for authentication
*/
public void setUsername(String u) {
public void setUsername(final String u) {
this.uname = u;
}

@@ -397,7 +397,7 @@ public class Get extends Task {
*
* @param p password for authentication
*/
public void setPassword(String p) {
public void setPassword(final String p) {
this.pword = p;
}

@@ -407,7 +407,7 @@ public class Get extends Task {
*
* @since Ant 1.8.0
*/
public void setMaxTime(long maxTime) {
public void setMaxTime(final long maxTime) {
this.maxTime = maxTime;
}

@@ -418,7 +418,7 @@ public class Get extends Task {
*
* @since Ant 1.8.0
*/
public void setRetries(int r) {
public void setRetries(final int r) {
this.numberRetries = r;
}

@@ -429,7 +429,7 @@ public class Get extends Task {
*
* @since Ant 1.8.0
*/
public void setSkipExisting(boolean s) {
public void setSkipExisting(final boolean s) {
this.skipExisting = s;
}

@@ -441,7 +441,7 @@ public class Get extends Task {
*
* @since Ant 1.9.3
*/
public void setUserAgent(String userAgent) {
public void setUserAgent(final String userAgent) {
this.userAgent = userAgent;
}

@@ -455,7 +455,7 @@ public class Get extends Task {
*
* @since Ant 1.8.0
*/
public void setHttpUseCaches(boolean httpUseCache) {
public void setHttpUseCaches(final boolean httpUseCache) {
this.httpUseCaches = httpUseCache;
}

@@ -479,7 +479,7 @@ public class Get extends Task {
* @param fileNameMapper the mapper to add.
* @since Ant 1.8.0
*/
public void add(FileNameMapper fileNameMapper) {
public void add(final FileNameMapper fileNameMapper) {
createMapper().add(fileNameMapper);
}

@@ -520,25 +520,20 @@ public class Get extends Task {
/**
* begin a download
*/
@Override
public void beginDownload() {

}

/**
* tick handler
*
*/
@Override
public void onTick() {
}

/**
* end a download
*/
@Override
public void endDownload() {

}
}

@@ -555,14 +550,13 @@ public class Get extends Task {
* Construct a verbose progress reporter.
* @param out the output stream.
*/
public VerboseProgress(PrintStream out) {
public VerboseProgress(final PrintStream out) {
this.out = out;
}

/**
* begin a download
*/
@Override
public void beginDownload() {
dots = 0;
}
@@ -571,7 +565,6 @@ public class Get extends Task {
* tick handler
*
*/
@Override
public void onTick() {
out.print(".");
if (dots++ > DOTS_PER_LINE) {
@@ -583,7 +576,6 @@ public class Get extends Task {
/**
* end a download
*/
@Override
public void endDownload() {
out.println();
out.flush();
@@ -608,8 +600,8 @@ public class Get extends Task {
private int redirections = 0;
private String userAgent = null;

GetThread(URL source, File dest,
boolean h, long t, DownloadProgress p, int l, String userAgent) {
GetThread(final URL source, final File dest,
final boolean h, final long t, final DownloadProgress p, final int l, final String userAgent) {
this.source = source;
this.dest = dest;
hasTimestamp = h;
@@ -623,9 +615,9 @@ public class Get extends Task {
public void run() {
try {
success = get();
} catch (IOException ioex) {
} catch (final IOException ioex) {
ioexception = ioex;
} catch (BuildException bex) {
} catch (final BuildException bex) {
exception = bex;
}
}
@@ -638,7 +630,7 @@ public class Get extends Task {
return false;
}

boolean downloadSucceeded = downloadFile();
final boolean downloadSucceeded = downloadFile();

//if (and only if) the use file time option is set, then
//the saved file now has its timestamp set to that of the
@@ -651,11 +643,11 @@ public class Get extends Task {
}


private boolean redirectionAllowed(URL aSource, URL aDest) {
private boolean redirectionAllowed(final URL aSource, final URL aDest) {
if (!(aSource.getProtocol().equals(aDest.getProtocol()) || (HTTP
.equals(aSource.getProtocol()) && HTTPS.equals(aDest
.getProtocol())))) {
String message = "Redirection detected from "
final String message = "Redirection detected from "
+ aSource.getProtocol() + " to " + aDest.getProtocol()
+ ". Protocol switch unsafe, not allowed.";
if (ignoreErrors) {
@@ -668,7 +660,7 @@ public class Get extends Task {

redirections++;
if (redirections > REDIRECT_LIMIT) {
String message = "More than " + REDIRECT_LIMIT
final String message = "More than " + REDIRECT_LIMIT
+ " times redirected, giving up";
if (ignoreErrors) {
log(message, logLevel);
@@ -682,10 +674,10 @@ public class Get extends Task {
return true;
}

private URLConnection openConnection(URL aSource) throws IOException {
private URLConnection openConnection(final URL aSource) throws IOException {

// set up the URL connection
URLConnection connection = aSource.openConnection();
final URLConnection connection = aSource.openConnection();
// modify the headers
// NB: things like user authentication could go in here too.
if (hasTimestamp) {
@@ -696,12 +688,12 @@ public class Get extends Task {

// prepare Java 1.1 style credentials
if (uname != null || pword != null) {
String up = uname + ":" + pword;
final String up = uname + ":" + pword;
String encoding;
// we do not use the sun impl for portability,
// and always use our own implementation for consistent
// testing
Base64Converter encoder = new Base64Converter();
final Base64Converter encoder = new Base64Converter();
encoding = encoder.encode(up.getBytes());
connection.setRequestProperty("Authorization", "Basic "
+ encoding);
@@ -718,29 +710,29 @@ public class Get extends Task {
// connect to the remote site (may take some time)
try {
connection.connect();
} catch (NullPointerException e) {
} catch (final NullPointerException e) {
//bad URLs can trigger NPEs in some JVMs
throw new BuildException("Failed to parse " + source.toString(), e);
}

// First check on a 301 / 302 (moved) response (HTTP only)
if (connection instanceof HttpURLConnection) {
HttpURLConnection httpConnection = (HttpURLConnection) connection;
int responseCode = httpConnection.getResponseCode();
final HttpURLConnection httpConnection = (HttpURLConnection) connection;
final int responseCode = httpConnection.getResponseCode();
if (isMoved(responseCode)) {
String newLocation = httpConnection.getHeaderField("Location");
String message = aSource
final String newLocation = httpConnection.getHeaderField("Location");
final String message = aSource
+ (responseCode == HttpURLConnection.HTTP_MOVED_PERM ? " permanently"
: "") + " moved to " + newLocation;
log(message, logLevel);
URL newURL = new URL(aSource, newLocation);
final URL newURL = new URL(aSource, newLocation);
if (!redirectionAllowed(aSource, newURL)) {
return null;
}
return openConnection(newURL);
}
// next test for a 304 result (HTTP only)
long lastModified = httpConnection.getLastModified();
final long lastModified = httpConnection.getLastModified();
if (responseCode == HttpURLConnection.HTTP_NOT_MODIFIED
|| (lastModified != 0 && hasTimestamp && timestamp >= lastModified)) {
// not modified so no file download. just return
@@ -752,7 +744,7 @@ public class Get extends Task {
}
// test for 401 result (HTTP only)
if (responseCode == HttpURLConnection.HTTP_UNAUTHORIZED) {
String message = "HTTP Authorization failure";
final String message = "HTTP Authorization failure";
if (ignoreErrors) {
log(message, logLevel);
return null;
@@ -770,7 +762,7 @@ public class Get extends Task {
return connection;
}

private boolean isMoved(int responseCode) {
private boolean isMoved(final int responseCode) {
return responseCode == HttpURLConnection.HTTP_MOVED_PERM ||
responseCode == HttpURLConnection.HTTP_MOVED_TEMP ||
responseCode == HttpURLConnection.HTTP_SEE_OTHER ||
@@ -786,7 +778,7 @@ public class Get extends Task {
try {
is = connection.getInputStream();
break;
} catch (IOException ex) {
} catch (final IOException ex) {
log("Error opening connection " + ex, logLevel);
}
}
@@ -807,7 +799,7 @@ public class Get extends Task {
progress.beginDownload();
boolean finished = false;
try {
byte[] buffer = new byte[BIG_BUFFER_SIZE];
final byte[] buffer = new byte[BIG_BUFFER_SIZE];
int length;
while (!isInterrupted() && (length = is.read(buffer)) >= 0) {
os.write(buffer, 0, length);
@@ -830,9 +822,9 @@ public class Get extends Task {
}

private void updateTimeStamp() {
long remoteTimestamp = connection.getLastModified();
final long remoteTimestamp = connection.getLastModified();
if (verbose) {
Date t = new Date(remoteTimestamp);
final Date t = new Date(remoteTimestamp);
log("last modified = " + t.toString()
+ ((remoteTimestamp == 0)
? " - using current time instead"


+ 249
- 248
src/main/org/apache/tools/ant/taskdefs/Javadoc.java
File diff suppressed because it is too large
View File


+ 112
- 92
src/main/org/apache/tools/ant/taskdefs/Tar.java View File

@@ -24,10 +24,13 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Enumeration;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Vector;
import java.util.zip.GZIPOutputStream;

@@ -68,31 +71,36 @@ public class Tar extends MatchingTask {
* Tar.WARN is deprecated and is replaced with
* Tar.TarLongFileMode.WARN
*/
public static final String WARN = "warn";
@Deprecated
public static final String WARN = "warn";
/**
* @deprecated since 1.5.x.
* Tar.FAIL is deprecated and is replaced with
* Tar.TarLongFileMode.FAIL
*/
public static final String FAIL = "fail";
@Deprecated
public static final String FAIL = "fail";
/**
* @deprecated since 1.5.x.
* Tar.TRUNCATE is deprecated and is replaced with
* Tar.TarLongFileMode.TRUNCATE
*/
public static final String TRUNCATE = "truncate";
@Deprecated
public static final String TRUNCATE = "truncate";
/**
* @deprecated since 1.5.x.
* Tar.GNU is deprecated and is replaced with
* Tar.TarLongFileMode.GNU
*/
public static final String GNU = "gnu";
@Deprecated
public static final String GNU = "gnu";
/**
* @deprecated since 1.5.x.
* Tar.OMIT is deprecated and is replaced with
* Tar.TarLongFileMode.OMIT
*/
public static final String OMIT = "omit";
@Deprecated
public static final String OMIT = "omit";

// CheckStyle:VisibilityModifier OFF - bc
File tarFile;
@@ -101,12 +109,10 @@ public class Tar extends MatchingTask {
private TarLongFileMode longFileMode = new TarLongFileMode();

// need to keep the package private version for backwards compatibility
Vector filesets = new Vector();
Vector<TarFileSet> filesets = new Vector<TarFileSet>();
// we must keep two lists since other classes may modify the
// filesets Vector (it is package private) without us noticing
private Vector resourceCollections = new Vector();

Vector fileSetFiles = new Vector();
private final Vector<ResourceCollection> resourceCollections = new Vector<ResourceCollection>();

// CheckStyle:VisibilityModifier ON

@@ -122,7 +128,7 @@ public class Tar extends MatchingTask {
* @return the tar fileset to be used as the nested element.
*/
public TarFileSet createTarFileSet() {
TarFileSet fs = new TarFileSet();
final TarFileSet fs = new TarFileSet();
fs.setProject(getProject());
filesets.addElement(fs);
return fs;
@@ -133,7 +139,7 @@ public class Tar extends MatchingTask {
* @param res a resource collection to archive.
* @since Ant 1.7
*/
public void add(ResourceCollection res) {
public void add(final ResourceCollection res) {
resourceCollections.add(res);
}

@@ -143,7 +149,8 @@ public class Tar extends MatchingTask {
* @deprecated since 1.5.x.
* For consistency with other tasks, please use setDestFile().
*/
public void setTarfile(File tarFile) {
@Deprecated
public void setTarfile(final File tarFile) {
this.tarFile = tarFile;
}

@@ -152,7 +159,7 @@ public class Tar extends MatchingTask {
* @since Ant 1.5
* @param destFile The output of the tar
*/
public void setDestFile(File destFile) {
public void setDestFile(final File destFile) {
this.tarFile = destFile;
}

@@ -160,7 +167,7 @@ public class Tar extends MatchingTask {
* This is the base directory to look in for things to tar.
* @param baseDir the base directory.
*/
public void setBasedir(File baseDir) {
public void setBasedir(final File baseDir) {
this.baseDir = baseDir;
}

@@ -183,7 +190,8 @@ public class Tar extends MatchingTask {
* mechanism do the work and also to encapsulate operations on
* the mode in its own class.
*/
public void setLongfile(String mode) {
@Deprecated
public void setLongfile(final String mode) {
log("DEPRECATED - The setLongfile(String) method has been deprecated."
+ " Use setLongfile(Tar.TarLongFileMode) instead.");
this.longFileMode = new TarLongFileMode();
@@ -205,7 +213,7 @@ public class Tar extends MatchingTask {
* </ul>
* @param mode the mode to handle long file names.
*/
public void setLongfile(TarLongFileMode mode) {
public void setLongfile(final TarLongFileMode mode) {
this.longFileMode = mode;
}

@@ -219,7 +227,7 @@ public class Tar extends MatchingTask {
* </ul>
* @param mode the compression method.
*/
public void setCompression(TarCompressionMethod mode) {
public void setCompression(final TarCompressionMethod mode) {
this.compression = mode;
}

@@ -227,7 +235,8 @@ public class Tar extends MatchingTask {
* do the business
* @throws BuildException on error
*/
public void execute() throws BuildException {
@Override
public void execute() throws BuildException {
if (tarFile == null) {
throw new BuildException("tarfile attribute must be set!",
getLocation());
@@ -243,7 +252,8 @@ public class Tar extends MatchingTask {
getLocation());
}

Vector savedFileSets = (Vector) filesets.clone();
@SuppressWarnings("unchecked")
final Vector<TarFileSet> savedFileSets = (Vector<TarFileSet>) filesets.clone();
try {
if (baseDir != null) {
if (!baseDir.exists()) {
@@ -252,7 +262,7 @@ public class Tar extends MatchingTask {
}

// add the main fileset to the list of filesets to process.
TarFileSet mainFileSet = new TarFileSet(fileset);
final TarFileSet mainFileSet = new TarFileSet(fileset);
mainFileSet.setDir(baseDir);
filesets.addElement(mainFileSet);
}
@@ -267,12 +277,11 @@ public class Tar extends MatchingTask {
// check if tar is out of date with respect to each
// fileset
boolean upToDate = true;
for (Enumeration e = filesets.elements(); e.hasMoreElements();) {
upToDate &= check((TarFileSet) e.nextElement());
for(final TarFileSet tfs : filesets) {
upToDate &= check(tfs);
}
for (Enumeration e = resourceCollections.elements();
e.hasMoreElements();) {
upToDate &= check((ResourceCollection) e.nextElement());
for(final ResourceCollection rcol : resourceCollections) {
upToDate &= check(rcol);
}

if (upToDate) {
@@ -281,7 +290,7 @@ public class Tar extends MatchingTask {
return;
}

File parent = tarFile.getParentFile();
final File parent = tarFile.getParentFile();
if (parent != null && !parent.isDirectory()
&& !(parent.mkdirs() || parent.isDirectory())) {
throw new BuildException("Failed to create missing parent"
@@ -310,16 +319,14 @@ public class Tar extends MatchingTask {
}

longWarningGiven = false;
for (Enumeration e = filesets.elements();
e.hasMoreElements();) {
tar((TarFileSet) e.nextElement(), tOut);
for(final TarFileSet tfs : filesets) {
tar(tfs, tOut);
}
for (Enumeration e = resourceCollections.elements();
e.hasMoreElements();) {
tar((ResourceCollection) e.nextElement(), tOut);
for(final ResourceCollection rcol : resourceCollections) {
tar(rcol, tOut);
}
} catch (IOException ioe) {
String msg = "Problem creating TAR: " + ioe.getMessage();
} catch (final IOException ioe) {
final String msg = "Problem creating TAR: " + ioe.getMessage();
throw new BuildException(msg, ioe, getLocation());
} finally {
FileUtils.close(tOut);
@@ -337,8 +344,8 @@ public class Tar extends MatchingTask {
* @param tarFileSet the fileset that the file came from.
* @throws IOException on error
*/
protected void tarFile(File file, TarOutputStream tOut, String vPath,
TarFileSet tarFileSet)
protected void tarFile(final File file, final TarOutputStream tOut, final String vPath,
final TarFileSet tarFileSet)
throws IOException {
if (file.equals(tarFile)) {
// If the archive is built for the first time and it is
@@ -364,8 +371,8 @@ public class Tar extends MatchingTask {
* @throws IOException on error
* @since Ant 1.7
*/
protected void tarResource(Resource r, TarOutputStream tOut, String vPath,
TarFileSet tarFileSet)
protected void tarResource(final Resource r, final TarOutputStream tOut, String vPath,
final TarFileSet tarFileSet)
throws IOException {

if (!r.isExists()) {
@@ -375,7 +382,7 @@ public class Tar extends MatchingTask {
boolean preserveLeadingSlashes = false;

if (tarFileSet != null) {
String fullpath = tarFileSet.getFullpath(this.getProject());
final String fullpath = tarFileSet.getFullpath(this.getProject());
if (fullpath.length() > 0) {
vPath = fullpath;
} else {
@@ -395,7 +402,7 @@ public class Tar extends MatchingTask {
preserveLeadingSlashes = tarFileSet.getPreserveLeadingSlashes();

if (vPath.startsWith("/") && !preserveLeadingSlashes) {
int l = vPath.length();
final int l = vPath.length();
if (l <= 1) {
// we would end up adding "" to the archive
return;
@@ -429,14 +436,14 @@ public class Tar extends MatchingTask {
}
}

TarEntry te = new TarEntry(vPath, preserveLeadingSlashes);
final TarEntry te = new TarEntry(vPath, preserveLeadingSlashes);
te.setModTime(r.getLastModified());
// preserve permissions
if (r instanceof ArchiveResource) {
ArchiveResource ar = (ArchiveResource) r;
final ArchiveResource ar = (ArchiveResource) r;
te.setMode(ar.getMode());
if (r instanceof TarResource) {
TarResource tr = (TarResource) r;
final TarResource tr = (TarResource) r;
te.setUserName(tr.getUserName());
te.setUserId(tr.getUid());
te.setGroupName(tr.getGroup());
@@ -483,7 +490,7 @@ public class Tar extends MatchingTask {
if (!r.isDirectory()) {
in = r.getInputStream();

byte[] buffer = new byte[BUFFER_SIZE];
final byte[] buffer = new byte[BUFFER_SIZE];
int count = 0;
do {
tOut.write(buffer, 0, count);
@@ -504,7 +511,8 @@ public class Tar extends MatchingTask {
* @deprecated since 1.5.x.
* use the two-arg version instead.
*/
protected boolean archiveIsUpToDate(String[] files) {
@Deprecated
protected boolean archiveIsUpToDate(final String[] files) {
return archiveIsUpToDate(files, baseDir);
}

@@ -515,9 +523,9 @@ public class Tar extends MatchingTask {
* @return true if the archive is up to date.
* @since Ant 1.5.2
*/
protected boolean archiveIsUpToDate(String[] files, File dir) {
SourceFileScanner sfs = new SourceFileScanner(this);
MergingMapper mm = new MergingMapper();
protected boolean archiveIsUpToDate(final String[] files, final File dir) {
final SourceFileScanner sfs = new SourceFileScanner(this);
final MergingMapper mm = new MergingMapper();
mm.setTo(tarFile.getAbsolutePath());
return sfs.restrict(files, dir, null, mm).length == 0;
}
@@ -528,7 +536,7 @@ public class Tar extends MatchingTask {
* @return true if the archive is up to date.
* @since Ant 1.7
*/
protected boolean archiveIsUpToDate(Resource r) {
protected boolean archiveIsUpToDate(final Resource r) {
return SelectorUtils.isOutOfDate(new FileResource(tarFile), r,
FileUtils.getFileUtils()
.getFileTimestampGranularity());
@@ -563,27 +571,27 @@ public class Tar extends MatchingTask {
* @return whether the archive is up-to-date
* @since Ant 1.7
*/
protected boolean check(ResourceCollection rc) {
protected boolean check(final ResourceCollection rc) {
boolean upToDate = true;
if (isFileFileSet(rc)) {
FileSet fs = (FileSet) rc;
final FileSet fs = (FileSet) rc;
upToDate = check(fs.getDir(getProject()), getFileNames(fs));
} else if (!rc.isFilesystemOnly() && !supportsNonFileResources()) {
throw new BuildException("only filesystem resources are supported");
} else if (rc.isFilesystemOnly()) {
HashSet basedirs = new HashSet();
HashMap basedirToFilesMap = new HashMap();
for (Resource res : rc) {
FileResource r = ResourceUtils
final Set<File> basedirs = new HashSet<File>();
final Map<File, List<String>> basedirToFilesMap = new HashMap<File, List<String>>();
for (final Resource res : rc) {
final FileResource r = ResourceUtils
.asFileResource(res.as(FileProvider.class));
File base = r.getBaseDir();
if (base == null) {
base = Copy.NULL_FILE_PLACEHOLDER;
}
basedirs.add(base);
Vector files = (Vector) basedirToFilesMap.get(base);
List<String> files = basedirToFilesMap.get(base);
if (files == null) {
files = new Vector();
files = new Vector<String>();
basedirToFilesMap.put(base, files);
}
if (base == Copy.NULL_FILE_PLACEHOLDER) {
@@ -592,19 +600,15 @@ public class Tar extends MatchingTask {
files.add(r.getName());
}
}
Iterator iter = basedirs.iterator();
while (iter.hasNext()) {
File base = (File) iter.next();
Vector f = (Vector) basedirToFilesMap.get(base);
String[] files = (String[]) f.toArray(new String[f.size()]);
upToDate &=
check(base == Copy.NULL_FILE_PLACEHOLDER ? null : base,
files);
for(final File base : basedirs) {
final File tmpBase = base == Copy.NULL_FILE_PLACEHOLDER ? null : base;
final List<String> files = basedirToFilesMap.get(base);
check(tmpBase, files);
}
} else { // non-file resources
Iterator<Resource> iter = rc.iterator();
final Iterator<Resource> iter = rc.iterator();
while (upToDate && iter.hasNext()) {
Resource r = iter.next();
final Resource r = iter.next();
upToDate = archiveIsUpToDate(r);
}
}
@@ -620,7 +624,7 @@ public class Tar extends MatchingTask {
* @return whether the archive is up-to-date
* @since Ant 1.7
*/
protected boolean check(File basedir, String[] files) {
protected boolean check(final File basedir, final String[] files) {
boolean upToDate = true;
if (!archiveIsUpToDate(files, basedir)) {
upToDate = false;
@@ -635,6 +639,20 @@ public class Tar extends MatchingTask {
return upToDate;
}

/**
* <p>Checks whether the archive is out-of-date with respect to the
* given files, ensures that the archive won't contain itself.</p>
*
* @param basedir base directory for file names
* @param files array of relative file names
* @return whether the archive is up-to-date
* @see #check(File, String[])
* @since Ant 1.9.5
*/
protected boolean check(final File basedir, final Collection<String> files) {
return check(basedir, files.toArray(new String[files.size()]));
}

/**
* Adds the resources contained in this collection to the archive.
*
@@ -646,7 +664,7 @@ public class Tar extends MatchingTask {
* @throws IOException on error.
* @since Ant 1.7
*/
protected void tar(ResourceCollection rc, TarOutputStream tOut)
protected void tar(final ResourceCollection rc, final TarOutputStream tOut)
throws IOException {
ArchiveFileSet afs = null;
if (rc instanceof ArchiveFileSet) {
@@ -659,23 +677,23 @@ public class Tar extends MatchingTask {
+ "filesets that specify a "
+ "single file.");
}
TarFileSet tfs = asTarFileSet(afs);
final TarFileSet tfs = asTarFileSet(afs);

if (isFileFileSet(rc)) {
FileSet fs = (FileSet) rc;
String[] files = getFileNames(fs);
final FileSet fs = (FileSet) rc;
final String[] files = getFileNames(fs);
for (int i = 0; i < files.length; i++) {
File f = new File(fs.getDir(getProject()), files[i]);
String name = files[i].replace(File.separatorChar, '/');
final File f = new File(fs.getDir(getProject()), files[i]);
final String name = files[i].replace(File.separatorChar, '/');
tarFile(f, tOut, name, tfs);
}
} else if (rc.isFilesystemOnly()) {
for (Resource r : rc) {
File f = r.as(FileProvider.class).getFile();
for (final Resource r : rc) {
final File f = r.as(FileProvider.class).getFile();
tarFile(f, tOut, f.getName(), tfs);
}
} else { // non-file resources
for (Resource r : rc) {
for (final Resource r : rc) {
tarResource(r, tOut, r.getName(), tfs);
}
}
@@ -688,7 +706,7 @@ public class Tar extends MatchingTask {
* @return true if the collection is a fileset.
* @since Ant 1.7
*/
protected static boolean isFileFileSet(ResourceCollection rc) {
protected static boolean isFileFileSet(final ResourceCollection rc) {
return rc instanceof FileSet && rc.isFilesystemOnly();
}

@@ -699,11 +717,11 @@ public class Tar extends MatchingTask {
* @return a list of the filenames.
* @since Ant 1.7
*/
protected static String[] getFileNames(FileSet fs) {
DirectoryScanner ds = fs.getDirectoryScanner(fs.getProject());
String[] directories = ds.getIncludedDirectories();
String[] filesPerSe = ds.getIncludedFiles();
String[] files = new String [directories.length + filesPerSe.length];
protected static String[] getFileNames(final FileSet fs) {
final DirectoryScanner ds = fs.getDirectoryScanner(fs.getProject());
final String[] directories = ds.getIncludedDirectories();
final String[] filesPerSe = ds.getIncludedFiles();
final String[] files = new String [directories.length + filesPerSe.length];
System.arraycopy(directories, 0, files, 0, directories.length);
System.arraycopy(filesPerSe, 0, files, directories.length,
filesPerSe.length);
@@ -719,7 +737,7 @@ public class Tar extends MatchingTask {
* @return a new TarFileSet.
* @since Ant 1.7
*/
protected TarFileSet asTarFileSet(ArchiveFileSet archiveFileSet) {
protected TarFileSet asTarFileSet(final ArchiveFileSet archiveFileSet) {
TarFileSet tfs = null;
if (archiveFileSet != null && archiveFileSet instanceof TarFileSet) {
tfs = (TarFileSet) archiveFileSet;
@@ -740,7 +758,7 @@ public class Tar extends MatchingTask {

if (archiveFileSet
instanceof org.apache.tools.ant.types.TarFileSet) {
org.apache.tools.ant.types.TarFileSet t =
final org.apache.tools.ant.types.TarFileSet t =
(org.apache.tools.ant.types.TarFileSet) archiveFileSet;
if (t.hasUserNameBeenSet()) {
tfs.setUserName(t.getUserName());
@@ -776,7 +794,7 @@ public class Tar extends MatchingTask {
*
* @param fileset a <code>FileSet</code> value
*/
public TarFileSet(FileSet fileset) {
public TarFileSet(final FileSet fileset) {
super(fileset);
}

@@ -794,7 +812,7 @@ public class Tar extends MatchingTask {
* @return a list of file and directory names, relative to
* the baseDir for the project.
*/
public String[] getFiles(Project p) {
public String[] getFiles(final Project p) {
if (files == null) {
files = getFileNames(this);
}
@@ -808,7 +826,7 @@ public class Tar extends MatchingTask {
* optional, default=0644
* @param octalString a 3 digit octal string.
*/
public void setMode(String octalString) {
public void setMode(final String octalString) {
setFileMode(octalString);
}

@@ -825,7 +843,7 @@ public class Tar extends MatchingTask {
* Optional, default is <code>false</code>.
* @param b the leading slashes flag.
*/
public void setPreserveLeadingSlashes(boolean b) {
public void setPreserveLeadingSlashes(final boolean b) {
this.preserveLeadingSlashes = b;
}

@@ -865,7 +883,8 @@ public class Tar extends MatchingTask {
/**
* @return the possible values for this enumerated type.
*/
public String[] getValues() {
@Override
public String[] getValues() {
return validModes;
}

@@ -945,7 +964,8 @@ public class Tar extends MatchingTask {
* Get valid enumeration values.
* @return valid enumeration values
*/
public String[] getValues() {
@Override
public String[] getValues() {
return new String[] {NONE, GZIP, BZIP2 };
}



+ 103
- 109
src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java View File

@@ -90,7 +90,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
private String fileDirParameter = null;

/** additional parameters to be passed to the stylesheets */
private List<Param> params = new ArrayList<Param>();
private final List<Param> params = new ArrayList<Param>();

/** Input XML document to be used */
private File inFile = null;
@@ -116,10 +116,10 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
private boolean force = false;

/** XSL output properties to be used */
private Vector outputProperties = new Vector();
private final Vector outputProperties = new Vector();

/** for resolving entities such as dtds */
private XMLCatalog xmlCatalog = new XMLCatalog();
private final XMLCatalog xmlCatalog = new XMLCatalog();

/** Utilities used for file operations */
private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
@@ -167,7 +167,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
*
* @since Ant 1.7
*/
private Union resources = new Union();
private final Union resources = new Union();

/**
* Whether to use the implicit fileset.
@@ -229,7 +229,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
*
* @since Ant 1.8.0
*/
private CommandlineJava.SysProperties sysProperties =
private final CommandlineJava.SysProperties sysProperties =
new CommandlineJava.SysProperties();

/**
@@ -252,7 +252,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
* @param b true if files in included directories are processed.
* @since Ant 1.5
*/
public void setScanIncludedDirectories(boolean b) {
public void setScanIncludedDirectories(final boolean b) {
performDirectoryScan = b;
}

@@ -264,7 +264,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
* @param b a <code>boolean</code> value
* @since Ant 1.5.2
*/
public void setReloadStylesheet(boolean b) {
public void setReloadStylesheet(final boolean b) {
reuseLoadedStylesheet = !b;
}

@@ -274,7 +274,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
* @exception BuildException if more than one mapper is defined
* @since Ant 1.6.2
*/
public void addMapper(Mapper mapper) {
public void addMapper(final Mapper mapper) {
if (mapperElement != null) {
handleError("Cannot define more than one mapper");
} else {
@@ -289,7 +289,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
* @param rc the collection of resources to style
* @since Ant 1.7
*/
public void add(ResourceCollection rc) {
public void add(final ResourceCollection rc) {
resources.add(rc);
}

@@ -298,7 +298,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
* @param rc the configured Resources object represented as &lt;style&gt;.
* @since Ant 1.7
*/
public void addConfiguredStyle(Resources rc) {
public void addConfiguredStyle(final Resources rc) {
if (rc.size() != 1) {
handleError("The style element must be specified with exactly one"
+ " nested resource.");
@@ -312,7 +312,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
* @param xslResource Resource to set as the stylesheet.
* @since Ant 1.7
*/
public void setXslResource(Resource xslResource) {
public void setXslResource(final Resource xslResource) {
this.xslResource = xslResource;
}

@@ -322,8 +322,8 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
* @exception BuildException if more than one mapper is defined
* @since Ant 1.7.0
*/
public void add(FileNameMapper fileNameMapper) throws BuildException {
Mapper mapper = new Mapper(getProject());
public void add(final FileNameMapper fileNameMapper) throws BuildException {
final Mapper mapper = new Mapper(getProject());
mapper.add(fileNameMapper);
addMapper(mapper);
}
@@ -340,13 +340,13 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
log("Warning: the task name <style> is deprecated. Use <xslt> instead.",
Project.MSG_WARN);
}
File savedBaseDir = baseDir;
final File savedBaseDir = baseDir;

DirectoryScanner scanner;
String[] list;
String[] dirs;

String baseMessage =
final String baseMessage =
"specify the stylesheet either as a filename in style attribute "
+ "or as a nested resource";

@@ -386,7 +386,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
// via style attribute
File stylesheet = getProject().resolveFile(xslFile);
if (!stylesheet.exists()) {
File alternative = FILE_UTILS.resolveFile(baseDir, xslFile);
final File alternative = FILE_UTILS.resolveFile(baseDir, xslFile);
/*
* shouldn't throw out deprecation warnings before we know,
* the wrong version has been used.
@@ -398,7 +398,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
stylesheet = alternative;
}
}
FileResource fr = new FileResource();
final FileResource fr = new FileResource();
fr.setProject(getProject());
fr.setFile(stylesheet);
styleResource = fr;
@@ -474,7 +474,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
*
* @param force true if always generate.
*/
public void setForce(boolean force) {
public void setForce(final boolean force) {
this.force = force;
}

@@ -484,7 +484,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
*
* @param dir the base directory
**/
public void setBasedir(File dir) {
public void setBasedir(final File dir) {
baseDir = dir;
}

@@ -495,7 +495,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
* specified.
* @param dir the name of the destination directory
**/
public void setDestdir(File dir) {
public void setDestdir(final File dir) {
destDir = dir;
}

@@ -504,7 +504,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
* optional, default is html.
* @param name the extension to use
**/
public void setExtension(String name) {
public void setExtension(final String name) {
targetExtension = name;
}

@@ -514,7 +514,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
*
* @param xslFile the stylesheet to use
*/
public void setStyle(String xslFile) {
public void setStyle(final String xslFile) {
this.xslFile = xslFile;
}

@@ -523,7 +523,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
*
* @param classpath the classpath to use when loading the XSL processor
*/
public void setClasspath(Path classpath) {
public void setClasspath(final Path classpath) {
createClasspath().append(classpath);
}

@@ -545,7 +545,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
* @param r the id of the Ant path instance to act as the classpath
* for loading the XSL processor
*/
public void setClasspathRef(Reference r) {
public void setClasspathRef(final Reference r) {
createClasspath().setRefid(r);
}

@@ -554,7 +554,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
*
* @param processor the name of the XSL processor
*/
public void setProcessor(String processor) {
public void setProcessor(final String processor) {
this.processor = processor;
}

@@ -566,7 +566,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
* @param useimplicitfileset set to true if you want to use implicit fileset
* @since Ant 1.7
*/
public void setUseImplicitFileset(boolean useimplicitfileset) {
public void setUseImplicitFileset(final boolean useimplicitfileset) {
useImplicitFileset = useimplicitfileset;
}

@@ -575,7 +575,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
*
* @param xmlCatalog the XMLCatalog instance to use to look up DTDs
*/
public void addConfiguredXMLCatalog(XMLCatalog xmlCatalog) {
public void addConfiguredXMLCatalog(final XMLCatalog xmlCatalog) {
this.xmlCatalog.addConfiguredXMLCatalog(xmlCatalog);
}

@@ -586,7 +586,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
* @param fileNameParameter name of the xsl parameter retrieving the
* current file name
*/
public void setFileNameParameter(String fileNameParameter) {
public void setFileNameParameter(final String fileNameParameter) {
this.fileNameParameter = fileNameParameter;
}

@@ -597,7 +597,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
* @param fileDirParameter name of the xsl parameter retrieving the
* current file directory
*/
public void setFileDirParameter(String fileDirParameter) {
public void setFileDirParameter(final String fileDirParameter) {
this.fileDirParameter = fileDirParameter;
}

@@ -606,7 +606,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
*
* @since Ant 1.8.0
*/
public void setSuppressWarnings(boolean b) {
public void setSuppressWarnings(final boolean b) {
suppressWarnings = b;
}

@@ -624,7 +624,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
*
* @since Ant 1.8.0
*/
public void setFailOnTransformationError(boolean b) {
public void setFailOnTransformationError(final boolean b) {
failOnTransformationError = b;
}

@@ -633,7 +633,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
*
* @since Ant 1.8.0
*/
public void setFailOnError(boolean b) {
public void setFailOnError(final boolean b) {
failOnError = b;
}

@@ -642,7 +642,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
*
* @since Ant 1.8.0
*/
public void setFailOnNoResources(boolean b) {
public void setFailOnNoResources(final boolean b) {
failOnNoResources = b;
}

@@ -651,7 +651,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
*
* @since Ant 1.8.0
*/
public void addSysproperty(Environment.Variable sysp) {
public void addSysproperty(final Environment.Variable sysp) {
sysProperties.addVariable(sysp);
}

@@ -660,7 +660,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
*
* @since Ant 1.8.0
*/
public void addSyspropertyset(PropertySet sysp) {
public void addSyspropertyset(final PropertySet sysp) {
sysProperties.addSyspropertyset(sysp);
}

@@ -699,12 +699,12 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
* @param proc the name of the processor to load.
* @exception Exception if the processor cannot be loaded.
*/
private void resolveProcessor(String proc) throws Exception {
private void resolveProcessor(final String proc) throws Exception {
if (proc.equals(PROCESSOR_TRAX)) {
liaison = new org.apache.tools.ant.taskdefs.optional.TraXLiaison();
} else {
//anything else is a classname
Class clazz = loadClass(proc);
final Class clazz = loadClass(proc);
liaison = (XSLTLiaison) clazz.newInstance();
}
}
@@ -718,7 +718,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
* @return the requested class.
* @exception Exception if the class could not be loaded.
*/
private Class loadClass(String classname) throws Exception {
private Class loadClass(final String classname) throws Exception {
setupLoader();
if (loader == null) {
return Class.forName(classname);
@@ -744,7 +744,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
*
* @param outFile the output File instance.
*/
public void setOut(File outFile) {
public void setOut(final File outFile) {
this.outFile = outFile;
}

@@ -754,7 +754,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
*
* @param inFile the input file
*/
public void setIn(File inFile) {
public void setIn(final File inFile) {
this.inFile = inFile;
}

@@ -775,16 +775,16 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
* @param stylesheet style sheet to use
* @since Ant 1.7
*/
private void processResources(Resource stylesheet) {
for (Resource r : resources) {
private void processResources(final Resource stylesheet) {
for (final Resource r : resources) {
if (!r.isExists()) {
continue;
}
File base = baseDir;
String name = r.getName();
FileProvider fp = r.as(FileProvider.class);
final FileProvider fp = r.as(FileProvider.class);
if (fp != null) {
FileResource f = ResourceUtils.asFileResource(fp);
final FileResource f = ResourceUtils.asFileResource(fp);
base = f.getBaseDir();
if (base == null) {
name = f.getFile().getAbsolutePath();
@@ -804,14 +804,14 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
* @param stylesheet the stylesheet to use.
* @exception BuildException if the processing fails.
*/
private void process(File baseDir, String xmlFile, File destDir, Resource stylesheet)
private void process(final File baseDir, final String xmlFile, final File destDir, final Resource stylesheet)
throws BuildException {

File outF = null;
File inF = null;

try {
long styleSheetLastModified = stylesheet.getLastModified();
final long styleSheetLastModified = stylesheet.getLastModified();
inF = new File(baseDir, xmlFile);

if (inF.isDirectory()) {
@@ -825,7 +825,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
mapper = new StyleMapper();
}

String[] outFileName = mapper.mapFileName(xmlFile);
final String[] outFileName = mapper.mapFileName(xmlFile);
if (outFileName == null || outFileName.length == 0) {
log("Skipping " + inFile + " it cannot get mapped to output.", Project.MSG_VERBOSE);
return;
@@ -843,7 +843,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
setLiaisonDynamicFileParameters(liaison, inF);
liaison.transform(inF, outF);
}
} catch (Exception ex) {
} catch (final Exception ex) {
// If failed to process document, must delete target document,
// or it will not attempt to process it the second time
log("Failed to process " + inFile, Project.MSG_INFO);
@@ -863,9 +863,9 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
* @param stylesheet the stylesheet to use.
* @exception BuildException if the processing fails.
*/
private void process(File inFile, File outFile, Resource stylesheet) throws BuildException {
private void process(final File inFile, final File outFile, final Resource stylesheet) throws BuildException {
try {
long styleSheetLastModified = stylesheet.getLastModified();
final long styleSheetLastModified = stylesheet.getLastModified();
log("In file " + inFile + " time: " + inFile.lastModified(), Project.MSG_DEBUG);
log("Out file " + outFile + " time: " + outFile.lastModified(), Project.MSG_DEBUG);
log("Style file " + xslFile + " time: " + styleSheetLastModified, Project.MSG_DEBUG);
@@ -880,7 +880,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
log("Skipping input file " + inFile + " because it is older than output file "
+ outFile + " and so is the stylesheet " + stylesheet, Project.MSG_DEBUG);
}
} catch (Exception ex) {
} catch (final Exception ex) {
log("Failed to process " + inFile, Project.MSG_INFO);
if (outFile != null) {
outFile.delete();
@@ -895,8 +895,8 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
* @param targetFile the file for which the directories are required.
* @exception BuildException if the directories cannot be created.
*/
private void ensureDirectoryFor(File targetFile) throws BuildException {
File directory = targetFile.getParentFile();
private void ensureDirectoryFor(final File targetFile) throws BuildException {
final File directory = targetFile.getParentFile();
if (!directory.exists()) {
if (!(directory.mkdirs() || directory.isDirectory())) {
handleError("Unable to create directory: "
@@ -943,13 +943,13 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
if (processor != null) {
try {
resolveProcessor(processor);
} catch (Exception e) {
} catch (final Exception e) {
handleError(e);
}
} else {
try {
resolveProcessor(PROCESSOR_TRAX);
} catch (Throwable e1) {
} catch (final Throwable e1) {
e1.printStackTrace();
handleError(e1);
}
@@ -964,7 +964,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
* @return an instance of the Param class to be configured.
*/
public Param createParam() {
Param p = new Param();
final Param p = new Param();
params.add(p);
return p;
}
@@ -994,7 +994,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
*
* @param project the current project
*/
public void setProject(Project project) {
public void setProject(final Project project) {
this.project = project;
}

@@ -1003,7 +1003,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
*
* @param name the name of the parameter.
*/
public void setName(String name) {
public void setName(final String name) {
this.name = name;
}

@@ -1013,7 +1013,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
* @param expression the parameter's value/expression.
* @see #setType(java.lang.String)
*/
public void setExpression(String expression) {
public void setExpression(final String expression) {
this.expression = expression;
}

@@ -1021,7 +1021,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
* @see ParamType
* @since Ant 1.9.3
*/
public void setType(String type) {
public void setType(final String type) {
this.type = type;
}

@@ -1067,7 +1067,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
* @param ifCond evaluated expression
* @since Ant 1.8.0
*/
public void setIf(Object ifCond) {
public void setIf(final Object ifCond) {
this.ifCond = ifCond;
}

@@ -1077,7 +1077,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
* which has been set, otherwise it won't.
* @param ifProperty evaluated expression
*/
public void setIf(String ifProperty) {
public void setIf(final String ifProperty) {
setIf((Object) ifProperty);
}

@@ -1088,7 +1088,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
* @param unlessCond evaluated expression
* @since Ant 1.8.0
*/
public void setUnless(Object unlessCond) {
public void setUnless(final Object unlessCond) {
this.unlessCond = unlessCond;
}

@@ -1098,7 +1098,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
* property which has been set, otherwise it will be used.
* @param unlessProperty evaluated expression
*/
public void setUnless(String unlessProperty) {
public void setUnless(final String unlessProperty) {
setUnless((Object) unlessProperty);
}

@@ -1108,7 +1108,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
* @return true if the task passes the "if" and "unless" parameters
*/
public boolean shouldUse() {
PropertyHelper ph = PropertyHelper.getPropertyHelper(project);
final PropertyHelper ph = PropertyHelper.getPropertyHelper(project);
return ph.testIfCondition(ifCond)
&& ph.testUnlessCondition(unlessCond);
}
@@ -1155,7 +1155,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
public static final Map<ParamType, QName> XPATH_TYPES;

static {
Map<ParamType, QName> m = new EnumMap<ParamType, QName>(ParamType.class);
final Map<ParamType, QName> m = new EnumMap<ParamType, QName>(ParamType.class);
m.put(XPATH_STRING, XPathConstants.STRING);
m.put(XPATH_BOOLEAN, XPathConstants.BOOLEAN);
m.put(XPATH_NUMBER, XPathConstants.NUMBER);
@@ -1171,7 +1171,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
* @since Ant 1.5
*/
public OutputProperty createOutputProperty() {
OutputProperty p = new OutputProperty();
final OutputProperty p = new OutputProperty();
outputProperties.addElement(p);
return p;
}
@@ -1201,7 +1201,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
* @param name A non-null String that specifies an
* output property name, which may be namespace qualified.
*/
public void setName(String name) {
public void setName(final String name) {
this.name = name;
}

@@ -1216,7 +1216,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
* set the value for this property
* @param value The non-null string value of the output property.
*/
public void setValue(String value) {
public void setValue(final String value) {
this.value = value;
}
}
@@ -1234,8 +1234,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
xpathFactory = XPathFactory.newInstance();
xpath = xpathFactory.newXPath();
xpath.setXPathVariableResolver(new XPathVariableResolver() {
@Override
public Object resolveVariable(QName variableName) {
public Object resolveVariable(final QName variableName) {
return getProject().getProperty(variableName.toString());
}
});
@@ -1249,8 +1248,8 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
* @deprecated since Ant 1.7
*/
@Deprecated
protected void configureLiaison(File stylesheet) throws BuildException {
FileResource fr = new FileResource();
protected void configureLiaison(final File stylesheet) throws BuildException {
final FileResource fr = new FileResource();
fr.setProject(getProject());
fr.setFile(stylesheet);
configureLiaison(fr);
@@ -1263,7 +1262,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
* @exception BuildException if the stylesheet cannot be loaded.
* @since Ant 1.7
*/
protected void configureLiaison(Resource stylesheet) throws BuildException {
protected void configureLiaison(final Resource stylesheet) throws BuildException {
if (stylesheetLoaded && reuseLoadedStylesheet) {
return;
}
@@ -1284,7 +1283,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
// If we are here we cannot set the stylesheet as
// a resource, but we can set it as a file. So,
// we make an attempt to get it as a file
FileProvider fp =
final FileProvider fp =
stylesheet.as(FileProvider.class);
if (fp != null) {
liaison.setStylesheet(fp.getFile());
@@ -1294,9 +1293,9 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
return;
}
}
for (Param p : params) {
for (final Param p : params) {
if (p.shouldUse()) {
Object evaluatedParam = evaluateParam(p);
final Object evaluatedParam = evaluateParam(p);
if (liaison instanceof XSLTLiaison4) {
((XSLTLiaison4)liaison).addParam(p.getName(), evaluatedParam);
} else {
@@ -1311,7 +1310,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
}
}
}
} catch (Exception ex) {
} catch (final Exception ex) {
log("Failed to transform using stylesheet " + stylesheet, Project.MSG_INFO);
handleTransformationError(ex);
}
@@ -1328,9 +1327,9 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
* @throws XPathExpressionException if XPath expression can not be compiled
* @since Ant 1.9.3
*/
private Object evaluateParam(Param param) throws XPathExpressionException {
String typeName = param.getType();
String expression = param.getExpression();
private Object evaluateParam(final Param param) throws XPathExpressionException {
final String typeName = param.getType();
final String expression = param.getExpression();

ParamType type;

@@ -1339,7 +1338,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
} else {
try {
type = ParamType.valueOf(typeName);
} catch (IllegalArgumentException e) {
} catch (final IllegalArgumentException e) {
throw new IllegalArgumentException("Invalid XSLT parameter type: " + typeName, e);
}
}
@@ -1356,11 +1355,11 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
case LONG:
return Long.parseLong(expression);
default: // XPath expression
QName xpathType = ParamType.XPATH_TYPES.get(type);
final QName xpathType = ParamType.XPATH_TYPES.get(type);
if (xpathType == null) {
throw new IllegalArgumentException("Invalid XSLT parameter type: " + typeName);
} else {
XPathExpression xpe = xpath.compile(expression);
final XPathExpression xpe = xpath.compile(expression);
// null = evaluate XPath on empty XML document
return xpe.evaluate((Object) null, xpathType);
}
@@ -1378,13 +1377,13 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
* @since Ant 1.7
*/
private void setLiaisonDynamicFileParameters(
XSLTLiaison liaison, File inFile) throws Exception {
final XSLTLiaison liaison, final File inFile) throws Exception {
if (fileNameParameter != null) {
liaison.addParam(fileNameParameter, inFile.getName());
}
if (fileDirParameter != null) {
String fileName = FileUtils.getRelativePath(baseDir, inFile);
File file = new File(fileName);
final String fileName = FileUtils.getRelativePath(baseDir, inFile);
final File file = new File(fileName);
// Give always a slash as file separator, so the stylesheet could be sure about that
// Use '.' so a dir+"/"+name would not result in an absolute path
liaison.addParam(fileDirParameter, file.getParent() != null ? file.getParent().replace(
@@ -1412,7 +1411,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
*
* @since Ant 1.8.0
*/
protected void handleError(String msg) {
protected void handleError(final String msg) {
if (failOnError) {
throw new BuildException(msg, getLocation());
}
@@ -1427,7 +1426,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
*
* @since Ant 1.8.0
*/
protected void handleError(Throwable ex) {
protected void handleError(final Throwable ex) {
if (failOnError) {
throw new BuildException(ex);
} else {
@@ -1442,7 +1441,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
*
* @since Ant 1.8.0
*/
protected void handleTransformationError(Exception ex) {
protected void handleTransformationError(final Exception ex) {
if (failOnError && failOnTransformationError) {
throw new BuildException(ex);
} else {
@@ -1463,7 +1462,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
/**
* the list of factory attributes to use for TraXLiaison
*/
private Vector attributes = new Vector();
private final Vector attributes = new Vector();

/**
* @return the name of the factory.
@@ -1476,7 +1475,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
* Set the name of the factory
* @param name the name of the factory.
*/
public void setName(String name) {
public void setName(final String name) {
this.name = name;
}

@@ -1484,7 +1483,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
* Create an instance of a factory attribute.
* @param attr the newly created factory attribute
*/
public void addAttribute(Attribute attr) {
public void addAttribute(final Attribute attr) {
attributes.addElement(attr);
}

@@ -1532,8 +1531,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
* @return null
* @throws BuildException never
*/
@Override
public Object createDynamicElement(String name) throws BuildException {
public Object createDynamicElement(final String name) throws BuildException {
return null;
}

@@ -1544,8 +1542,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
* @param value the value of the attribute
* @throws BuildException on error
*/
@Override
public void setDynamicAttribute(String name, String value) throws BuildException {
public void setDynamicAttribute(final String name, final String value) throws BuildException {
// only 'name' and 'value' exist.
if ("name".equalsIgnoreCase(name)) {
this.name = value;
@@ -1559,7 +1556,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
} else {
try {
this.value = new Integer(value);
} catch (NumberFormatException e) {
} catch (final NumberFormatException e) {
this.value = value;
}
}
@@ -1580,15 +1577,12 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
* @since Ant 1.6.2
*/
private class StyleMapper implements FileNameMapper {
@Override
public void setFrom(String from) {
public void setFrom(final String from) {
}
@Override
public void setTo(String to) {
public void setTo(final String to) {
}
@Override
public String[] mapFileName(String xmlFile) {
int dotPos = xmlFile.lastIndexOf('.');
final int dotPos = xmlFile.lastIndexOf('.');
if (dotPos > 0) {
xmlFile = xmlFile.substring(0, dotPos);
}
@@ -1608,7 +1602,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
* Set to true if the listener is to print events that occur
* as each node is 'executed' in the stylesheet.
*/
public void setElements(boolean b) {
public void setElements(final boolean b) {
elements = b;
}

@@ -1624,7 +1618,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
* Set to true if the listener is to print information after
* each extension event.
*/
public void setExtension(boolean b) {
public void setExtension(final boolean b) {
extension = b;
}

@@ -1640,7 +1634,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
* Set to true if the listener is to print information after
* each result-tree generation event.
*/
public void setGeneration(boolean b) {
public void setGeneration(final boolean b) {
generation = b;
}

@@ -1656,7 +1650,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
* Set to true if the listener is to print information after
* each selection event.
*/
public void setSelection(boolean b) {
public void setSelection(final boolean b) {
selection = b;
}

@@ -1672,7 +1666,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
* Set to true if the listener is to print an event whenever a
* template is invoked.
*/
public void setTemplates(boolean b) {
public void setTemplates(final boolean b) {
templates = b;
}



+ 173
- 178
src/main/org/apache/tools/ant/taskdefs/Zip.java
File diff suppressed because it is too large
View File


+ 15
- 16
src/main/org/apache/tools/ant/taskdefs/compilers/AptCompilerAdapter.java View File

@@ -100,35 +100,35 @@ public class AptCompilerAdapter extends DefaultCompilerAdapter {
* @param cmd command that is set up with the various switches from the task
* options
*/
static void setAptCommandlineSwitches(Apt apt, Commandline cmd) {
static void setAptCommandlineSwitches(final Apt apt, final Commandline cmd) {

if (!apt.isCompile()) {
cmd.createArgument().setValue("-nocompile");
}

// Process the factory class
String factory = apt.getFactory();
final String factory = apt.getFactory();
if (factory != null) {
cmd.createArgument().setValue("-factory");
cmd.createArgument().setValue(factory);
}

// Process the factory path
Path factoryPath = apt.getFactoryPath();
final Path factoryPath = apt.getFactoryPath();
if (factoryPath != null) {
cmd.createArgument().setValue("-factorypath");
cmd.createArgument().setPath(factoryPath);
}

File preprocessDir = apt.getPreprocessDir();
final File preprocessDir = apt.getPreprocessDir();
if (preprocessDir != null) {
cmd.createArgument().setValue("-s");
cmd.createArgument().setFile(preprocessDir);
}

// Process the processor options
Vector options = apt.getOptions();
Enumeration elements = options.elements();
final Vector options = apt.getOptions();
final Enumeration elements = options.elements();
Apt.Option opt;
StringBuffer arg = null;
while (elements.hasMoreElements()) {
@@ -147,8 +147,8 @@ public class AptCompilerAdapter extends DefaultCompilerAdapter {
*
* @param cmd command line to set up
*/
protected void setAptCommandlineSwitches(Commandline cmd) {
Apt apt = getApt();
protected void setAptCommandlineSwitches(final Commandline cmd) {
final Apt apt = getApt();
setAptCommandlineSwitches(apt, cmd);
}

@@ -157,29 +157,28 @@ public class AptCompilerAdapter extends DefaultCompilerAdapter {
* @return true on success.
* @throws BuildException if the compilation has problems.
*/
@Override
public boolean execute() throws BuildException {
attributes.log("Using apt compiler", Project.MSG_VERBOSE);
//set up the javac options
Commandline cmd = setupModernJavacCommand();
final Commandline cmd = setupModernJavacCommand();
//then add the Apt options
setAptCommandlineSwitches(cmd);

//finally invoke APT
// Use reflection to be able to build on all JDKs:
try {
Class c = Class.forName(APT_ENTRY_POINT);
Object compiler = c.newInstance();
Method compile = c.getMethod(APT_METHOD_NAME,
final Class c = Class.forName(APT_ENTRY_POINT);
final Object compiler = c.newInstance();
final Method compile = c.getMethod(APT_METHOD_NAME,
new Class[]{(new String[]{}).getClass()});
int result = ((Integer) compile.invoke
final int result = ((Integer) compile.invoke
(compiler, new Object[]{cmd.getArguments()}))
.intValue();
return (result == APT_COMPILER_SUCCESS);
} catch (BuildException be) {
} catch (final BuildException be) {
//rethrow build exceptions
throw be;
} catch (Exception ex) {
} catch (final Exception ex) {
//cast everything else to a build exception
throw new BuildException("Error starting apt compiler",
ex, location);


+ 0
- 2
src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java View File

@@ -97,7 +97,6 @@ public abstract class DefaultCompilerAdapter
*
* @param attributes a configured Javac task.
*/
@Override
public void setJavac(final Javac attributes) {
this.attributes = attributes;
src = attributes.getSrcdir();
@@ -136,7 +135,6 @@ public abstract class DefaultCompilerAdapter
* but specialized compilers can recognize multiple kinds
* of files.
*/
@Override
public String[] getSupportedFileExtensions() {
return new String[] {"java"};
}


+ 12
- 13
src/main/org/apache/tools/ant/taskdefs/condition/IsReachable.java View File

@@ -96,7 +96,7 @@ public class IsReachable extends ProjectComponent implements Condition {
*
* @param host the host to ping.
*/
public void setHost(String host) {
public void setHost(final String host) {
this.host = host;
}

@@ -105,7 +105,7 @@ public class IsReachable extends ProjectComponent implements Condition {
*
* @param url a URL object.
*/
public void setUrl(String url) {
public void setUrl(final String url) {
this.url = url;
}

@@ -114,7 +114,7 @@ public class IsReachable extends ProjectComponent implements Condition {
*
* @param timeout the timeout in seconds.
*/
public void setTimeout(int timeout) {
public void setTimeout(final int timeout) {
this.timeout = timeout;
}

@@ -125,7 +125,7 @@ public class IsReachable extends ProjectComponent implements Condition {
*
* @return true if it is empty
*/
private boolean empty(String string) {
private boolean empty(final String string) {
return string == null || string.length() == 0;
}

@@ -139,7 +139,6 @@ public class IsReachable extends ProjectComponent implements Condition {
* @throws org.apache.tools.ant.BuildException
* if an error occurs
*/
@Override
public boolean eval() throws BuildException {
if (empty(host) && empty(url)) {
throw new BuildException(ERROR_NO_HOSTNAME);
@@ -154,12 +153,12 @@ public class IsReachable extends ProjectComponent implements Condition {
}
try {
//get the host of a url
URL realURL = new URL(url);
final URL realURL = new URL(url);
target = realURL.getHost();
if (empty(target)) {
throw new BuildException(ERROR_NO_HOST_IN_URL + url);
}
} catch (MalformedURLException e) {
} catch (final MalformedURLException e) {
throw new BuildException(ERROR_BAD_URL + url, e);
}
}
@@ -167,7 +166,7 @@ public class IsReachable extends ProjectComponent implements Condition {
InetAddress address;
try {
address = InetAddress.getByName(target);
} catch (UnknownHostException e1) {
} catch (final UnknownHostException e1) {
log(WARN_UNKNOWN_HOST + target);
return false;
}
@@ -179,22 +178,22 @@ public class IsReachable extends ProjectComponent implements Condition {
try {
reachableMethod = InetAddress.class.getMethod(METHOD_NAME,
parameterTypes);
Object[] params = new Object[1];
final Object[] params = new Object[1];
params[0] = new Integer(timeout * SECOND);
try {
reachable = ((Boolean) reachableMethod.invoke(address, params))
.booleanValue();
} catch (IllegalAccessException e) {
} catch (final IllegalAccessException e) {
//utterly implausible, but catered for anyway
throw new BuildException("When calling " + reachableMethod);
} catch (InvocationTargetException e) {
} catch (final InvocationTargetException e) {
//assume this is an IOexception about un readability
Throwable nested = e.getTargetException();
final Throwable nested = e.getTargetException();
log(ERROR_ON_NETWORK + target + ": " + nested.toString());
//any kind of fault: not reachable.
reachable = false;
}
} catch (NoSuchMethodException e) {
} catch (final NoSuchMethodException e) {
//java1.4
log("Not found: InetAddress." + METHOD_NAME, Project.MSG_VERBOSE);
log(MSG_NO_REACHABLE_TEST);


+ 55
- 65
src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java View File

@@ -117,13 +117,13 @@ public class TraXLiaison implements XSLTLiaison4, ErrorListener, XSLTLoggerAware
private URIResolver uriResolver;

/** transformer output properties */
private Vector outputProperties = new Vector();
private final Vector outputProperties = new Vector();

/** stylesheet parameters */
private Hashtable<String, Object> params = new Hashtable<String, Object>();
private final Hashtable<String, Object> params = new Hashtable<String, Object>();

/** factory attributes */
private Vector attributes = new Vector();
private final Vector attributes = new Vector();

/** whether to suppress warnings */
private boolean suppressWarnings = false;
@@ -143,9 +143,8 @@ public class TraXLiaison implements XSLTLiaison4, ErrorListener, XSLTLoggerAware
* @param stylesheet a <code>File</code> value
* @throws Exception on error
*/
@Override
public void setStylesheet(File stylesheet) throws Exception {
FileResource fr = new FileResource();
public void setStylesheet(final File stylesheet) throws Exception {
final FileResource fr = new FileResource();
fr.setProject(project);
fr.setFile(stylesheet);
setStylesheet(fr);
@@ -156,8 +155,7 @@ public class TraXLiaison implements XSLTLiaison4, ErrorListener, XSLTLoggerAware
* @param stylesheet a {@link org.apache.tools.ant.types.Resource} value
* @throws Exception on error
*/
@Override
public void setStylesheet(Resource stylesheet) throws Exception {
public void setStylesheet(final Resource stylesheet) throws Exception {
if (this.stylesheet != null) {
// resetting the stylesheet - reset transformer
transformer = null;
@@ -177,8 +175,7 @@ public class TraXLiaison implements XSLTLiaison4, ErrorListener, XSLTLoggerAware
* @param outfile the result file
* @throws Exception on error
*/
@Override
public void transform(File infile, File outfile) throws Exception {
public void transform(final File infile, final File outfile) throws Exception {
if (transformer == null) {
createTransformer();
}
@@ -188,10 +185,10 @@ public class TraXLiaison implements XSLTLiaison4, ErrorListener, XSLTLoggerAware
try {
fis = new BufferedInputStream(new FileInputStream(infile));
fos = new BufferedOutputStream(new FileOutputStream(outfile));
StreamResult res = new StreamResult(fos);
final StreamResult res = new StreamResult(fos);
// not sure what could be the need of this...
res.setSystemId(JAXPUtils.getSystemId(outfile));
Source src = getSource(fis, infile);
final Source src = getSource(fis, infile);

// set parameters on each transformation, maybe something has changed
//(e.g. value of file name parameter)
@@ -216,7 +213,7 @@ public class TraXLiaison implements XSLTLiaison4, ErrorListener, XSLTLoggerAware
* satisfies the requested configuration.
* @throws SAXException in case of problem detected by the SAX parser.
*/
private Source getSource(InputStream is, File infile)
private Source getSource(final InputStream is, final File infile)
throws ParserConfigurationException, SAXException {
// todo: is this comment still relevant ??
// FIXME: need to use a SAXSource as the source for the transform
@@ -224,9 +221,9 @@ public class TraXLiaison implements XSLTLiaison4, ErrorListener, XSLTLoggerAware
Source src = null;
if (entityResolver != null) {
if (getFactory().getFeature(SAXSource.FEATURE)) {
SAXParserFactory spFactory = SAXParserFactory.newInstance();
final SAXParserFactory spFactory = SAXParserFactory.newInstance();
spFactory.setNamespaceAware(true);
XMLReader reader = spFactory.newSAXParser().getXMLReader();
final XMLReader reader = spFactory.newSAXParser().getXMLReader();
reader.setEntityResolver(entityResolver);
src = new SAXSource(reader, new InputSource(is));
} else {
@@ -242,7 +239,7 @@ public class TraXLiaison implements XSLTLiaison4, ErrorListener, XSLTLoggerAware
return src;
}

private Source getSource(InputStream is, Resource resource)
private Source getSource(final InputStream is, final Resource resource)
throws ParserConfigurationException, SAXException {
// todo: is this comment still relevant ??
// FIXME: need to use a SAXSource as the source for the transform
@@ -250,9 +247,9 @@ public class TraXLiaison implements XSLTLiaison4, ErrorListener, XSLTLoggerAware
Source src = null;
if (entityResolver != null) {
if (getFactory().getFeature(SAXSource.FEATURE)) {
SAXParserFactory spFactory = SAXParserFactory.newInstance();
final SAXParserFactory spFactory = SAXParserFactory.newInstance();
spFactory.setNamespaceAware(true);
XMLReader reader = spFactory.newSAXParser().getXMLReader();
final XMLReader reader = spFactory.newSAXParser().getXMLReader();
reader.setEntityResolver(entityResolver);
src = new SAXSource(reader, new InputSource(is));
} else {
@@ -271,14 +268,14 @@ public class TraXLiaison implements XSLTLiaison4, ErrorListener, XSLTLoggerAware
return src;
}

private String resourceToURI(Resource resource) {
FileProvider fp = resource.as(FileProvider.class);
private String resourceToURI(final Resource resource) {
final FileProvider fp = resource.as(FileProvider.class);
if (fp != null) {
return FILE_UTILS.toURI(fp.getFile().getAbsolutePath());
}
URLProvider up = resource.as(URLProvider.class);
final URLProvider up = resource.as(URLProvider.class);
if (up != null) {
URL u = up.getURL();
final URL u = up.getURL();
return String.valueOf(u);
} else {
return resource.getName();
@@ -301,7 +298,7 @@ public class TraXLiaison implements XSLTLiaison4, ErrorListener, XSLTLoggerAware
xslStream
= new BufferedInputStream(stylesheet.getInputStream());
templatesModTime = stylesheet.getLastModified();
Source src = getSource(xslStream, stylesheet);
final Source src = getSource(xslStream, stylesheet);
templates = getFactory().newTemplates(src);
} finally {
if (xslStream != null) {
@@ -339,16 +336,16 @@ public class TraXLiaison implements XSLTLiaison4, ErrorListener, XSLTLoggerAware
if ("org.apache.xalan.transformer.TransformerImpl"
.equals(transformer.getClass().getName())) {
try {
Class traceSupport =
final Class traceSupport =
Class.forName("org.apache.tools.ant.taskdefs.optional."
+ "Xalan2TraceSupport", true,
Thread.currentThread()
.getContextClassLoader());
XSLTTraceSupport ts =
final XSLTTraceSupport ts =
(XSLTTraceSupport) traceSupport.newInstance();
ts.configureTrace(transformer, traceConfiguration);
} catch (Exception e) {
String msg = "Failed to enable tracing because of " + e;
} catch (final Exception e) {
final String msg = "Failed to enable tracing because of " + e;
if (project != null) {
project.log(msg, Project.MSG_WARN);
} else {
@@ -356,7 +353,7 @@ public class TraXLiaison implements XSLTLiaison4, ErrorListener, XSLTLoggerAware
}
}
} else {
String msg = "Not enabling trace support for transformer"
final String msg = "Not enabling trace support for transformer"
+ " implementation" + transformer.getClass().getName();
if (project != null) {
project.log(msg, Project.MSG_WARN);
@@ -402,8 +399,8 @@ public class TraXLiaison implements XSLTLiaison4, ErrorListener, XSLTLoggerAware
Class.forName(factoryName, true,
Thread.currentThread()
.getContextClassLoader());
} catch (ClassNotFoundException cnfe) {
String msg = "Failed to load " + factoryName
} catch (final ClassNotFoundException cnfe) {
final String msg = "Failed to load " + factoryName
+ " via the configured classpath, will try"
+ " Ant's classpath instead.";
if (logger != null) {
@@ -419,16 +416,16 @@ public class TraXLiaison implements XSLTLiaison4, ErrorListener, XSLTLoggerAware
clazz = Class.forName(factoryName);
}
tfactory = (TransformerFactory) clazz.newInstance();
} catch (Exception e) {
} catch (final Exception e) {
throw new BuildException(e);
}
}

try { // #51668, #52382
Field _isNotSecureProcessing = tfactory.getClass().getDeclaredField("_isNotSecureProcessing");
final Field _isNotSecureProcessing = tfactory.getClass().getDeclaredField("_isNotSecureProcessing");
_isNotSecureProcessing.setAccessible(true);
_isNotSecureProcessing.set(tfactory, Boolean.TRUE);
} catch (Exception x) {
} catch (final Exception x) {
if (project != null) {
project.log(x.toString(), Project.MSG_DEBUG);
}
@@ -456,7 +453,7 @@ public class TraXLiaison implements XSLTLiaison4, ErrorListener, XSLTLoggerAware
* or null for the default JAXP look up mechanism.
* @since Ant 1.6
*/
public void setFactory(String name) {
public void setFactory(final String name) {
factoryName = name;
}

@@ -467,7 +464,7 @@ public class TraXLiaison implements XSLTLiaison4, ErrorListener, XSLTLoggerAware
* string or object.
* @since Ant 1.6
*/
public void setAttribute(String name, Object value) {
public void setAttribute(final String name, final Object value) {
final Object[] pair = new Object[]{name, value};
attributes.addElement(pair);
}
@@ -481,7 +478,7 @@ public class TraXLiaison implements XSLTLiaison4, ErrorListener, XSLTLoggerAware
* @since Ant 1.5
* @since Ant 1.5
*/
public void setOutputProperty(String name, String value) {
public void setOutputProperty(final String name, final String value) {
final String[] pair = new String[]{name, value};
outputProperties.addElement(pair);
}
@@ -490,7 +487,7 @@ public class TraXLiaison implements XSLTLiaison4, ErrorListener, XSLTLoggerAware
* Set the class to resolve entities during the transformation.
* @param aResolver the resolver class.
*/
public void setEntityResolver(EntityResolver aResolver) {
public void setEntityResolver(final EntityResolver aResolver) {
entityResolver = aResolver;
}

@@ -498,7 +495,7 @@ public class TraXLiaison implements XSLTLiaison4, ErrorListener, XSLTLoggerAware
* Set the class to resolve URIs during the transformation
* @param aResolver a <code>EntityResolver</code> value
*/
public void setURIResolver(URIResolver aResolver) {
public void setURIResolver(final URIResolver aResolver) {
uriResolver = aResolver;
}

@@ -507,8 +504,7 @@ public class TraXLiaison implements XSLTLiaison4, ErrorListener, XSLTLoggerAware
* @param name the name of the parameter
* @param value the value of the parameter
*/
@Override
public void addParam(String name, String value) {
public void addParam(final String name, final String value) {
params.put(name, value);
}

@@ -518,8 +514,7 @@ public class TraXLiaison implements XSLTLiaison4, ErrorListener, XSLTLoggerAware
* @param value the value of the parameter
* @since Ant 1.9.3
*/
@Override
public void addParam(String name, Object value) {
public void addParam(final String name, final Object value) {
params.put(name, value);
}

@@ -527,8 +522,7 @@ public class TraXLiaison implements XSLTLiaison4, ErrorListener, XSLTLoggerAware
* Set a logger.
* @param l a logger.
*/
@Override
public void setLogger(XSLTLogger l) {
public void setLogger(final XSLTLogger l) {
logger = l;
}

@@ -536,8 +530,7 @@ public class TraXLiaison implements XSLTLiaison4, ErrorListener, XSLTLoggerAware
* Log an error.
* @param e the exception to log.
*/
@Override
public void error(TransformerException e) {
public void error(final TransformerException e) {
logError(e, "Error");
}

@@ -545,8 +538,7 @@ public class TraXLiaison implements XSLTLiaison4, ErrorListener, XSLTLoggerAware
* Log a fatal error.
* @param e the exception to log.
*/
@Override
public void fatalError(TransformerException e) {
public void fatalError(final TransformerException e) {
logError(e, "Fatal Error");
throw new BuildException("Fatal error during transformation using " + stylesheet + ": " + e.getMessageAndLocation(), e);
}
@@ -555,22 +547,21 @@ public class TraXLiaison implements XSLTLiaison4, ErrorListener, XSLTLoggerAware
* Log a warning.
* @param e the exception to log.
*/
@Override
public void warning(TransformerException e) {
public void warning(final TransformerException e) {
if (!suppressWarnings) {
logError(e, "Warning");
}
}

private void logError(TransformerException e, String type) {
private void logError(final TransformerException e, final String type) {
if (logger == null) {
return;
}

StringBuffer msg = new StringBuffer();
SourceLocator locator = e.getLocator();
final StringBuffer msg = new StringBuffer();
final SourceLocator locator = e.getLocator();
if (locator != null) {
String systemid = locator.getSystemId();
final String systemid = locator.getSystemId();
if (systemid != null) {
String url = systemid;
if (url.startsWith("file:")) {
@@ -580,11 +571,11 @@ public class TraXLiaison implements XSLTLiaison4, ErrorListener, XSLTLoggerAware
} else {
msg.append("Unknown file");
}
int line = locator.getLineNumber();
final int line = locator.getLineNumber();
if (line != -1) {
msg.append(":");
msg.append(line);
int column = locator.getColumnNumber();
final int column = locator.getColumnNumber();
if (column != -1) {
msg.append(":");
msg.append(column);
@@ -611,7 +602,7 @@ public class TraXLiaison implements XSLTLiaison4, ErrorListener, XSLTLoggerAware
* Use org.apache.tools.ant.util.JAXPUtils#getSystemId instead.
*/
@Deprecated
protected String getSystemId(File file) {
protected String getSystemId(final File file) {
return JAXPUtils.getSystemId(file);
}

@@ -621,23 +612,22 @@ public class TraXLiaison implements XSLTLiaison4, ErrorListener, XSLTLoggerAware
* @param xsltTask the XSLTProcess task instance from which this liasion
* is to be configured.
*/
@Override
public void configure(XSLTProcess xsltTask) {
public void configure(final XSLTProcess xsltTask) {
project = xsltTask.getProject();
XSLTProcess.Factory factory = xsltTask.getFactory();
final XSLTProcess.Factory factory = xsltTask.getFactory();
if (factory != null) {
setFactory(factory.getName());

// configure factory attributes
for (Enumeration attrs = factory.getAttributes();
for (final Enumeration attrs = factory.getAttributes();
attrs.hasMoreElements();) {
XSLTProcess.Factory.Attribute attr =
final XSLTProcess.Factory.Attribute attr =
(XSLTProcess.Factory.Attribute) attrs.nextElement();
setAttribute(attr.getName(), attr.getValue());
}
}

XMLCatalog xmlCatalog = xsltTask.getXMLCatalog();
final XMLCatalog xmlCatalog = xsltTask.getXMLCatalog();
// use XMLCatalog as the entity resolver and URI resolver
if (xmlCatalog != null) {
setEntityResolver(xmlCatalog);
@@ -646,9 +636,9 @@ public class TraXLiaison implements XSLTLiaison4, ErrorListener, XSLTLoggerAware


// configure output properties
for (Enumeration props = xsltTask.getOutputProperties();
for (final Enumeration props = xsltTask.getOutputProperties();
props.hasMoreElements();) {
XSLTProcess.OutputProperty prop
final XSLTProcess.OutputProperty prop
= (XSLTProcess.OutputProperty) props.nextElement();
setOutputProperty(prop.getName(), prop.getValue());
}


+ 0
- 2
src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnit4TestMethodAdapter.java View File

@@ -87,7 +87,6 @@ public class JUnit4TestMethodAdapter implements Test {
runner = request.getRunner();
}

@Override
public int countTestCases() {
return runner.testCount();
}
@@ -104,7 +103,6 @@ public class JUnit4TestMethodAdapter implements Test {
return testClass;
}

@Override
public void run(final TestResult result) {
runner.run(cache.getNotifier(result));
}


+ 184
- 186
src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
File diff suppressed because it is too large
View File


+ 0
- 22
src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java View File

@@ -355,7 +355,6 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR
/**
* Run the test.
*/
@Override
public void run() {
res = new IgnoredTestResult();
res.addListener(wrapListener(this));
@@ -678,7 +677,6 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR
*
* @return 2 if errors occurred, 1 if tests failed else 0.
*/
@Override
public int getRetCode() {
return retCode;
}
@@ -689,7 +687,6 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR
* <p>A new Test is started.
* @param t the test.
*/
@Override
public void startTest(final Test t) {
final String testName = JUnitVersionHelper.getTestCaseName(t);
logTestListenerEvent("startTest(" + testName + ")");
@@ -701,7 +698,6 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR
* <p>A Test is finished.
* @param test the test.
*/
@Override
public void endTest(final Test test) {
final String testName = JUnitVersionHelper.getTestCaseName(test);
logTestListenerEvent("endTest(" + testName + ")");
@@ -745,7 +741,6 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR
* @param test the test.
* @param t the assertion thrown by the test.
*/
@Override
public void addFailure(final Test test, final AssertionFailedError t) {
addFailure(test, (Throwable) t);
}
@@ -757,7 +752,6 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR
* @param test the test.
* @param t the error thrown by the test.
*/
@Override
public void addError(final Test test, final Throwable t) {
final String testName = JUnitVersionHelper.getTestCaseName(test);
logTestListenerEvent("addError(" + testName + ", " + t.getMessage() + ")");
@@ -771,7 +765,6 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR
* @since Ant 1.6
* @param permissions the permissions to use.
*/
@Override
public void setPermissions(final Permissions permissions) {
perm = permissions;
}
@@ -780,7 +773,6 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR
* Handle a string destined for standard output.
* @param output the string to output
*/
@Override
public void handleOutput(final String output) {
if (!logTestListenerEvents && output.startsWith(JUnitTask.TESTLISTENER_PREFIX)) {
// ignore
@@ -800,14 +792,12 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR
*
* @since Ant 1.6
*/
@Override
public int handleInput(final byte[] buffer, final int offset, final int length)
throws IOException {
return -1;
}

/** {@inheritDoc}. */
@Override
public void handleErrorOutput(final String output) {
if (systemError != null) {
systemError.print(output);
@@ -815,7 +805,6 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR
}

/** {@inheritDoc}. */
@Override
public void handleFlush(final String output) {
if (systemOut != null) {
systemOut.print(output);
@@ -823,7 +812,6 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR
}

/** {@inheritDoc}. */
@Override
public void handleErrorFlush(final String output) {
if (systemError != null) {
systemError.print(output);
@@ -866,7 +854,6 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR
}

/** {@inheritDoc}. */
@Override
public void addFormatter(final JUnitTaskMirror.JUnitResultFormatterMirror f) {
formatters.addElement(f);
}
@@ -1058,39 +1045,30 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR
final JUnitTest test) {
runner.addFormatter(new JUnitResultFormatter() {

@Override
public void startTestSuite(final JUnitTest suite) throws BuildException {
}

@Override
public void endTestSuite(final JUnitTest suite) throws BuildException {
}

@Override
public void setOutput(final OutputStream out) {
}

@Override
public void setSystemOutput(final String out) {
}

@Override
public void setSystemError(final String err) {
}

@Override
public void addError(final Test arg0, final Throwable arg1) {
}

@Override
public void addFailure(final Test arg0, final AssertionFailedError arg1) {
}

@Override
public void endTest(final Test arg0) {
}

@Override
public void startTest(final Test arg0) {
registerTestCase(JUnitVersionHelper.getTestCaseName(arg0));
}


+ 0
- 9
src/main/org/apache/tools/ant/taskdefs/optional/junit/TearDownOnVmCrash.java View File

@@ -43,7 +43,6 @@ public class TearDownOnVmCrash implements JUnitResultFormatter {
* Records the suite's name to later determine the class to invoke
* tearDown on.
*/
@Override
public void startTestSuite(final JUnitTest suite) {
suiteName = suite.getName();
if (suiteName != null &&
@@ -58,7 +57,6 @@ public class TearDownOnVmCrash implements JUnitResultFormatter {
* test we get when a Batch fails and the error is an actual
* error generated by Ant.
*/
@Override
public void addError(final Test fakeTest, final Throwable t) {
if (suiteName != null
&& fakeTest instanceof JUnitTaskMirrorImpl.VmExitErrorTest) {
@@ -69,25 +67,18 @@ public class TearDownOnVmCrash implements JUnitResultFormatter {
// no need to implement the rest
public void addFailure(Test test, Throwable t) {}

@Override
public void addFailure(Test test, AssertionFailedError t) {}

@Override
public void startTest(Test test) {}

@Override
public void endTest(Test test) {}

@Override
public void endTestSuite(JUnitTest suite) {}

@Override
public void setOutput(OutputStream out) {}

@Override
public void setSystemOutput(String out) {}

@Override
public void setSystemError(String err) {}

private void tearDown() {


+ 0
- 11
src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLJUnitResultFormatter.java View File

@@ -109,19 +109,16 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan
}

/** {@inheritDoc}. */
@Override
public void setOutput(OutputStream out) {
this.out = out;
}

/** {@inheritDoc}. */
@Override
public void setSystemOutput(String out) {
formatOutput(SYSTEM_OUT, out);
}

/** {@inheritDoc}. */
@Override
public void setSystemError(String out) {
formatOutput(SYSTEM_ERR, out);
}
@@ -130,7 +127,6 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan
* The whole testsuite started.
* @param suite the testsuite.
*/
@Override
public void startTestSuite(JUnitTest suite) {
doc = getDocumentBuilder().newDocument();
rootElement = doc.createElement(TESTSUITE);
@@ -182,7 +178,6 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan
* @param suite the testsuite.
* @throws BuildException on error.
*/
@Override
public void endTestSuite(JUnitTest suite) throws BuildException {
rootElement.setAttribute(ATTR_TESTS, "" + suite.runCount());
rootElement.setAttribute(ATTR_FAILURES, "" + suite.failureCount());
@@ -219,7 +214,6 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan
* <p>A new Test is started.
* @param t the test.
*/
@Override
public void startTest(Test t) {
testStarts.put(createDescription(t), System.currentTimeMillis());
}
@@ -234,7 +228,6 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan
* <p>A Test is finished.
* @param test the test.
*/
@Override
public void endTest(Test test) {
String testDescription = createDescription(test);

@@ -283,7 +276,6 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan
* @param test the test.
* @param t the assertion.
*/
@Override
public void addFailure(Test test, AssertionFailedError t) {
addFailure(test, (Throwable) t);
}
@@ -295,7 +287,6 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan
* @param test the test.
* @param t the error.
*/
@Override
public void addError(Test test, Throwable t) {
formatError(ERROR, test, t);
}
@@ -333,7 +324,6 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan
nested.appendChild(doc.createCDATASection(output));
}

@Override
public void testIgnored(Test test) {
formatSkip(test, JUnitVersionHelper.getIgnoreMessage(test));
if (test != null) {
@@ -364,7 +354,6 @@ public class XMLJUnitResultFormatter implements JUnitResultFormatter, XMLConstan

}

@Override
public void testAssumptionFailure(Test test, Throwable failure) {
formatSkip(test, failure.getMessage());
skippedTests.put(createDescription(test), test);


+ 0
- 3
src/main/org/apache/tools/ant/types/mappers/CutDirsMapper.java View File

@@ -46,7 +46,6 @@ public class CutDirsMapper implements FileNameMapper {
* Empty implementation.
* @param ignore ignored.
*/
@Override
public void setFrom(final String ignore) {
}

@@ -54,12 +53,10 @@ public class CutDirsMapper implements FileNameMapper {
* Empty implementation.
* @param ignore ignored.
*/
@Override
public void setTo(final String ignore) {
}

/** {@inheritDoc}. */
@Override
public String[] mapFileName(final String sourceFileName) {
if (dirs <= 0) {
throw new BuildException("dirs must be set to a positive number");


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

@@ -72,14 +72,13 @@ public class Archives extends DataType
/**
* Sums the sizes of nested archives.
*/
@Override
public int size() {
if (isReference()) {
return ((Archives) getCheckedRef()).size();
}
dieOnCircularReference();
int total = 0;
for (Iterator<ArchiveFileSet> i = grabArchives(); i.hasNext();) {
for (final Iterator<ArchiveFileSet> i = grabArchives(); i.hasNext();) {
total += i.next().size();
}
return total;
@@ -88,14 +87,13 @@ public class Archives extends DataType
/**
* Merges the nested collections.
*/
@Override
public Iterator<Resource> iterator() {
if (isReference()) {
return ((Archives) getCheckedRef()).iterator();
}
dieOnCircularReference();
List<Resource> l = new LinkedList<Resource>();
for (Iterator<ArchiveFileSet> i = grabArchives(); i.hasNext();) {
final List<Resource> l = new LinkedList<Resource>();
for (final Iterator<ArchiveFileSet> i = grabArchives(); i.hasNext();) {
l.addAll(CollectionUtils
.asCollection(i.next().iterator()));
}
@@ -105,7 +103,6 @@ public class Archives extends DataType
/**
* @return false
*/
@Override
public boolean isFilesystemOnly() {
if (isReference()) {
return ((Archives) getCheckedRef()).isFilesystemOnly();
@@ -119,7 +116,7 @@ public class Archives extends DataType
* @param r the Reference to set.
*/
@Override
public void setRefid(Reference r) {
public void setRefid(final Reference r) {
if (zips.getResourceCollections().size() > 0
|| tars.getResourceCollections().size() > 0) {
throw tooManyAttributes();
@@ -135,11 +132,11 @@ public class Archives extends DataType
@Override
public Object clone() {
try {
Archives a = (Archives) super.clone();
final Archives a = (Archives) super.clone();
a.zips = (Union) zips.clone();
a.tars = (Union) tars.clone();
return a;
} catch (CloneNotSupportedException e) {
} catch (final CloneNotSupportedException e) {
throw new BuildException(e);
}
}
@@ -151,11 +148,11 @@ public class Archives extends DataType
* and returns an iterator over the collected archives.
*/
protected Iterator<ArchiveFileSet> grabArchives() {
List<ArchiveFileSet> l = new LinkedList<ArchiveFileSet>();
for (Resource r : zips) {
final List<ArchiveFileSet> l = new LinkedList<ArchiveFileSet>();
for (final Resource r : zips) {
l.add(configureArchive(new ZipFileSet(), r));
}
for (Resource r : tars) {
for (final Resource r : tars) {
l.add(configureArchive(new TarFileSet(), r));
}
return l.iterator();
@@ -165,8 +162,8 @@ public class Archives extends DataType
* Configures the archivefileset based on this type's settings,
* set the source.
*/
protected ArchiveFileSet configureArchive(ArchiveFileSet afs,
Resource src) {
protected ArchiveFileSet configureArchive(final ArchiveFileSet afs,
final Resource src) {
afs.setProject(getProject());
afs.setSrcResource(src);
return afs;
@@ -180,7 +177,7 @@ public class Archives extends DataType
* @throws BuildException on error.
*/
@Override
protected synchronized void dieOnCircularReference(Stack<Object> stk, Project p)
protected synchronized void dieOnCircularReference(final Stack<Object> stk, final Project p)
throws BuildException {
if (isChecked()) {
return;


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

@@ -46,7 +46,7 @@ public abstract class ContentTransformingResource extends ResourceDecorator {
* Constructor with another resource to wrap.
* @param other the resource to wrap.
*/
protected ContentTransformingResource(ResourceCollection other) {
protected ContentTransformingResource(final ResourceCollection other) {
super(other);
}

@@ -61,14 +61,14 @@ public abstract class ContentTransformingResource extends ResourceDecorator {
InputStream in = null;
try {
in = getInputStream();
byte[] buf = new byte[BUFFER_SIZE];
final byte[] buf = new byte[BUFFER_SIZE];
int size = 0;
int readNow;
while ((readNow = in.read(buf, 0, buf.length)) > 0) {
size += readNow;
}
return size;
} catch (IOException ex) {
} catch (final IOException ex) {
throw new BuildException("caught exception while reading "
+ getName(), ex);
} finally {
@@ -117,14 +117,13 @@ public abstract class ContentTransformingResource extends ResourceDecorator {
* Suppress FileProvider, re-implement Appendable
*/
@Override
public <T> T as(Class<T> clazz) {
public <T> T as(final Class<T> clazz) {
if (Appendable.class.isAssignableFrom(clazz)) {
if (isAppendSupported()) {
final Appendable a =
getResource().as(Appendable.class);
if (a != null) {
return clazz.cast(new Appendable() {
@Override
public OutputStream getAppendOutputStream()
throws IOException {
OutputStream out = a.getAppendOutputStream();


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

@@ -56,7 +56,7 @@ public class LazyResourceCollectionWrapper extends
protected int getSize() {
// to compute the size, just iterate: the iterator will take care of
// caching
Iterator<Resource> it = createIterator();
final Iterator<Resource> it = createIterator();
int size = 0;
while (it.hasNext()) {
it.next();
@@ -72,7 +72,7 @@ public class LazyResourceCollectionWrapper extends
* @param r resource considered for filtration
* @return whether the resource should be filtered or not
*/
protected boolean filterResource(Resource r) {
protected boolean filterResource(final Resource r) {
return false;
}

@@ -84,11 +84,10 @@ public class LazyResourceCollectionWrapper extends

protected final Iterator<Resource> it;

public FilteringIterator(Iterator<Resource> it) {
public FilteringIterator(final Iterator<Resource> it) {
this.it = it;
}

@Override
public boolean hasNext() {
if (ended) {
return false;
@@ -106,17 +105,15 @@ public class LazyResourceCollectionWrapper extends
return true;
}

@Override
public Resource next() {
if (!hasNext()) {
throw new UnsupportedOperationException();
}
Resource r = next;
final Resource r = next;
next = null;
return r;
}

@Override
public void remove() {
throw new UnsupportedOperationException();
}
@@ -139,11 +136,10 @@ public class LazyResourceCollectionWrapper extends
* the iterator which will provide the resources to put in
* cache
*/
public CachedIterator(Iterator<Resource> it) {
public CachedIterator(final Iterator<Resource> it) {
this.it = it;
}

@Override
public boolean hasNext() {
synchronized (cachedResources) {
// have we already cached the next entry ?
@@ -155,13 +151,12 @@ public class LazyResourceCollectionWrapper extends
return false;
}
// put in cache the next resource
Resource r = it.next();
final Resource r = it.next();
cachedResources.add(r);
}
return true;
}

@Override
public Resource next() {
// first check that we have some to deliver
if (!hasNext()) {
@@ -174,7 +169,6 @@ public class LazyResourceCollectionWrapper extends
}
}

@Override
public void remove() {
throw new UnsupportedOperationException();
}


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

@@ -44,7 +44,7 @@ public class MultiRootFileSet extends AbstractFileSet
private Union union;

@Override
public void setDir(File dir) {
public void setDir(final File dir) {
throw new BuildException(getDataTypeName()
+ " doesn't support the dir attribute");
}
@@ -53,7 +53,7 @@ public class MultiRootFileSet extends AbstractFileSet
* Determines the types of resources to return.
* @param type the types of resources to return
*/
public void setType(SetType type) {
public void setType(final SetType type) {
if (isReference()) {
throw tooManyAttributes();
}
@@ -64,7 +64,7 @@ public class MultiRootFileSet extends AbstractFileSet
* Set whether to cache collections.
* @param b boolean cache flag.
*/
public synchronized void setCache(boolean b) {
public synchronized void setCache(final boolean b) {
if (isReference()) {
throw tooManyAttributes();
}
@@ -75,13 +75,13 @@ public class MultiRootFileSet extends AbstractFileSet
* Adds basedirs as a comman separated list.
* @param b boolean cache flag.
*/
public void setBaseDirs(String dirs) {
public void setBaseDirs(final String dirs) {
if (isReference()) {
throw tooManyAttributes();
}
if (dirs != null && dirs.length() > 0) {
String[] ds = dirs.split(",");
for (String d : ds) {
final String[] ds = dirs.split(",");
for (final String d : ds) {
baseDirs.add(getProject().resolveFile(d));
}
}
@@ -90,7 +90,7 @@ public class MultiRootFileSet extends AbstractFileSet
/**
* Adds a basedir as nested element.
*/
public void addConfiguredBaseDir(FileResource r) {
public void addConfiguredBaseDir(final FileResource r) {
if (isReference()) {
throw noChildrenAllowed();
}
@@ -98,7 +98,7 @@ public class MultiRootFileSet extends AbstractFileSet
}

@Override
public void setRefid(Reference r) {
public void setRefid(final Reference r) {
if (!baseDirs.isEmpty()) {
throw tooManyAttributes();
}
@@ -115,7 +115,7 @@ public class MultiRootFileSet extends AbstractFileSet
if (isReference()) {
return ((MultiRootFileSet) getRef(getProject())).clone();
} else {
MultiRootFileSet fs = (MultiRootFileSet) super.clone();
final MultiRootFileSet fs = (MultiRootFileSet) super.clone();
fs.baseDirs = new ArrayList<File>(baseDirs);
fs.union = null;
return fs;
@@ -126,7 +126,6 @@ public class MultiRootFileSet extends AbstractFileSet
* Fulfill the ResourceCollection contract.
* @return an Iterator of Resources.
*/
@Override
public Iterator<Resource> iterator() {
if (isReference()) {
return ((MultiRootFileSet) getRef(getProject())).iterator();
@@ -138,7 +137,6 @@ public class MultiRootFileSet extends AbstractFileSet
* Fulfill the ResourceCollection contract.
* @return number of elements as int.
*/
@Override
public int size() {
if (isReference()) {
return ((MultiRootFileSet) getRef(getProject())).size();
@@ -150,7 +148,6 @@ public class MultiRootFileSet extends AbstractFileSet
* Always returns true.
* @return true indicating that all elements will be FileResources.
*/
@Override
public boolean isFilesystemOnly() {
return true;
}
@@ -172,7 +169,7 @@ public class MultiRootFileSet extends AbstractFileSet
if (cache && union != null) {
return union;
}
Union u = new Union();
final Union u = new Union();
setup(u);
if (cache) {
union = u;
@@ -180,8 +177,8 @@ public class MultiRootFileSet extends AbstractFileSet
return u;
}

private void setup(Union u) {
for (File d : baseDirs) {
private void setup(final Union u) {
for (final File d : baseDirs) {
u.add(new Worker(this, type, d));
}
}
@@ -198,26 +195,24 @@ public class MultiRootFileSet extends AbstractFileSet

private final SetType type;

private Worker(MultiRootFileSet fs, SetType type, File dir) {
private Worker(final MultiRootFileSet fs, final SetType type, final File dir) {
super(fs);
this.type = type;
setDir(dir);
}

@Override
public boolean isFilesystemOnly() {
return true;
}

@Override
public Iterator<Resource> iterator() {
DirectoryScanner ds = getDirectoryScanner(getProject());
final DirectoryScanner ds = getDirectoryScanner(getProject());
String[] names = type == SetType.file
? ds.getIncludedFiles()
: ds.getIncludedDirectories();
if (type == SetType.both) {
String[] files = ds.getIncludedFiles();
String[] merged = new String[names.length + files.length];
final String[] files = ds.getIncludedFiles();
final String[] merged = new String[names.length + files.length];
System.arraycopy(names, 0, merged, 0, names.length);
System.arraycopy(files, 0, merged, names.length, files.length);
names = merged;
@@ -226,9 +221,8 @@ public class MultiRootFileSet extends AbstractFileSet
names);
}

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


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

@@ -99,7 +99,6 @@ public class Type implements ResourceSelector {
* @param r the Resource to check.
* @return whether the Resource was selected.
*/
@Override
public boolean isSelected(final Resource r) {
if (type == null) {
throw new BuildException("The type attribute is required.");


+ 0
- 2
src/main/org/apache/tools/ant/util/ResourceUtils.java View File

@@ -145,11 +145,9 @@ public class ResourceUtils {
logFuture(logTo, source, granularity);
final ResourceSelectorProvider p =
new ResourceSelectorProvider() {
@Override
public ResourceSelector
getTargetSelectorForSource(final Resource sr) {
return new ResourceSelector() {
@Override
public boolean isSelected(final Resource target) {
/* Extra I/O, probably wasted:
if (target.isDirectory()) {


+ 15
- 16
src/main/org/apache/tools/ant/util/SymbolicLinkUtils.java View File

@@ -70,7 +70,7 @@ public class SymbolicLinkUtils {
* @return true if the file is a symbolic link.
* @throws IOException on error.
*/
public boolean isSymbolicLink(File file) throws IOException {
public boolean isSymbolicLink(final File file) throws IOException {
return isSymbolicLink(file.getParentFile(), file.getName());
}

@@ -86,7 +86,7 @@ public class SymbolicLinkUtils {
* @return true if the file is a symbolic link.
* @throws IOException on error.
*/
public boolean isSymbolicLink(String name) throws IOException {
public boolean isSymbolicLink(final String name) throws IOException {
return isSymbolicLink(new File(name));
}

@@ -103,9 +103,9 @@ public class SymbolicLinkUtils {
* @return true if the file is a symbolic link.
* @throws IOException on error.
*/
public boolean isSymbolicLink(File parent, String name)
public boolean isSymbolicLink(final File parent, final String name)
throws IOException {
File toTest = parent != null
final File toTest = parent != null
? new File(parent.getCanonicalPath(), name)
: new File(name);
return !toTest.getAbsolutePath().equals(toTest.getCanonicalPath());
@@ -128,7 +128,7 @@ public class SymbolicLinkUtils {
* @return true if the file is a broken symbolic link.
* @throws IOException on error.
*/
public boolean isDanglingSymbolicLink(String name) throws IOException {
public boolean isDanglingSymbolicLink(final String name) throws IOException {
return isDanglingSymbolicLink(new File(name));
}

@@ -149,7 +149,7 @@ public class SymbolicLinkUtils {
* @return true if the file is a broken symbolic link.
* @throws IOException on error.
*/
public boolean isDanglingSymbolicLink(File file) throws IOException {
public boolean isDanglingSymbolicLink(final File file) throws IOException {
return isDanglingSymbolicLink(file.getParentFile(), file.getName());
}

@@ -171,14 +171,13 @@ public class SymbolicLinkUtils {
* @return true if the file is a broken symbolic link.
* @throws IOException on error.
*/
public boolean isDanglingSymbolicLink(File parent, String name)
public boolean isDanglingSymbolicLink(final File parent, final String name)
throws IOException {
File f = new File(parent, name);
final File f = new File(parent, name);
if (!f.exists()) {
final String localName = f.getName();
String[] c = parent.list(new FilenameFilter() {
@Override
public boolean accept(File d, String n) {
final String[] c = parent.list(new FilenameFilter() {
public boolean accept(final File d, final String n) {
return localName.equals(n);
}
});
@@ -214,7 +213,7 @@ public class SymbolicLinkUtils {
* fail.
* @throws BuildException if the execution of "rm" failed.
*/
public void deleteSymbolicLink(File link, Task task)
public void deleteSymbolicLink(File link, final Task task)
throws IOException {
if (isDanglingSymbolicLink(link)) {
if (!link.delete()) {
@@ -234,7 +233,7 @@ public class SymbolicLinkUtils {
}

// find the resource of the existing link:
File target = link.getCanonicalFile();
final File target = link.getCanonicalFile();

// no reason to try the renaming algorithm if we aren't allowed to
// write to the target's parent directory. Let's hope that
@@ -243,7 +242,7 @@ public class SymbolicLinkUtils {
if (task == null || target.getParentFile().canWrite()) {

// rename the resource, thus breaking the link:
File temp = FILE_UTILS.createTempFile("symlink", ".tmp",
final File temp = FILE_UTILS.createTempFile("symlink", ".tmp",
target.getParentFile(), false,
false);

@@ -259,7 +258,7 @@ public class SymbolicLinkUtils {
try {
FILE_UTILS.rename(target, temp);
renamedTarget = true;
} catch (IOException e) {
} catch (final IOException e) {
throw new IOException("Couldn't rename resource when "
+ "attempting to delete '" + link
+ "'. Reason: " + e.getMessage());
@@ -276,7 +275,7 @@ public class SymbolicLinkUtils {
// return the resource to its original name:
try {
FILE_UTILS.rename(temp, target);
} catch (IOException e) {
} catch (final IOException e) {
throw new IOException("Couldn't return resource "
+ temp
+ " to its original name: "


+ 28
- 31
src/main/org/apache/tools/tar/TarUtils.java View File

@@ -46,13 +46,11 @@ public class TarUtils {
* Encapsulates the algorithms used up to Ant 1.8 as ZipEncoding.
*/
static final ZipEncoding FALLBACK_ENCODING = new ZipEncoding() {
@Override
public boolean canEncode(String name) { return true; }
public boolean canEncode(final String name) { return true; }

@Override
public ByteBuffer encode(String name) {
public ByteBuffer encode(final String name) {
final int length = name.length();
byte[] buf = new byte[length];
final byte[] buf = new byte[length];

// copy until end of input or output is reached.
for (int i = 0; i < length; ++i) {
@@ -61,13 +59,12 @@ public class TarUtils {
return ByteBuffer.wrap(buf);
}

@Override
public String decode(byte[] buffer) {
public String decode(final byte[] buffer) {
final int length = buffer.length;
StringBuilder result = new StringBuilder(length);
final StringBuilder result = new StringBuilder(length);

for (int i = 0; i < length; ++i) {
byte b = buffer[i];
final byte b = buffer[i];
if (b == 0) { // Trailing null
break;
}
@@ -203,7 +200,7 @@ public class TarUtils {
final int offset,
final int length,
final boolean negative) {
byte[] remainder = new byte[length - 1];
final byte[] remainder = new byte[length - 1];
System.arraycopy(buffer, offset + 1, remainder, 0, length - 1);
BigInteger val = new BigInteger(remainder);
if (negative) {
@@ -234,8 +231,8 @@ public class TarUtils {
}

// Helper method to generate the exception message
private static String exceptionMessage(byte[] buffer, final int offset,
final int length, int current, final byte currentByte) {
private static String exceptionMessage(final byte[] buffer, final int offset,
final int length, final int current, final byte currentByte) {
// default charset is good enough for an exception message,
//
// the alternative was to modify parseOctal and
@@ -260,13 +257,13 @@ public class TarUtils {
* @param length The maximum number of bytes to parse.
* @return The entry name.
*/
public static String parseName(byte[] buffer, final int offset, final int length) {
public static String parseName(final byte[] buffer, final int offset, final int length) {
try {
return parseName(buffer, offset, length, DEFAULT_ENCODING);
} catch (IOException ex) {
} catch (final IOException ex) {
try {
return parseName(buffer, offset, length, FALLBACK_ENCODING);
} catch (IOException ex2) {
} catch (final IOException ex2) {
// impossible
throw new RuntimeException(ex2);
}
@@ -284,7 +281,7 @@ public class TarUtils {
* @param encoding name of the encoding to use for file names
* @return The entry name.
*/
public static String parseName(byte[] buffer, final int offset,
public static String parseName(final byte[] buffer, final int offset,
final int length,
final ZipEncoding encoding)
throws IOException {
@@ -296,7 +293,7 @@ public class TarUtils {
}
}
if (len > 0) {
byte[] b = new byte[len];
final byte[] b = new byte[len];
System.arraycopy(buffer, offset, b, 0, len);
return encoding.decode(b);
}
@@ -318,14 +315,14 @@ public class TarUtils {
* @param length The maximum number of header bytes to copy.
* @return The updated offset, i.e. offset + length
*/
public static int formatNameBytes(String name, byte[] buf, final int offset, final int length) {
public static int formatNameBytes(final String name, final byte[] buf, final int offset, final int length) {
try {
return formatNameBytes(name, buf, offset, length, DEFAULT_ENCODING);
} catch (IOException ex) {
} catch (final IOException ex) {
try {
return formatNameBytes(name, buf, offset, length,
FALLBACK_ENCODING);
} catch (IOException ex2) {
} catch (final IOException ex2) {
// impossible
throw new RuntimeException(ex2);
}
@@ -348,7 +345,7 @@ public class TarUtils {
* @param encoding name of the encoding to use for file names
* @return The updated offset, i.e. offset + length
*/
public static int formatNameBytes(String name, byte[] buf, final int offset,
public static int formatNameBytes(final String name, final byte[] buf, final int offset,
final int length,
final ZipEncoding encoding)
throws IOException {
@@ -377,7 +374,7 @@ public class TarUtils {
* @param length length of buffer to fill
* @throws IllegalArgumentException if the value will not fit in the buffer
*/
public static void formatUnsignedOctalString(final long value, byte[] buffer,
public static void formatUnsignedOctalString(final long value, final byte[] buffer,
final int offset, final int length) {
int remaining = length;
remaining--;
@@ -416,7 +413,7 @@ public class TarUtils {
* @return The updated offset, i.e offset+length
* @throws IllegalArgumentException if the value (and trailer) will not fit in the buffer
*/
public static int formatOctalBytes(final long value, byte[] buf, final int offset, final int length) {
public static int formatOctalBytes(final long value, final byte[] buf, final int offset, final int length) {

int idx=length-2; // For space and trailing null
formatUnsignedOctalString(value, buf, offset, idx);
@@ -441,9 +438,9 @@ public class TarUtils {
* @return The updated offset
* @throws IllegalArgumentException if the value (and trailer) will not fit in the buffer
*/
public static int formatLongOctalBytes(final long value, byte[] buf, final int offset, final int length) {
public static int formatLongOctalBytes(final long value, final byte[] buf, final int offset, final int length) {

int idx=length-1; // For space
final int idx=length-1; // For space

formatUnsignedOctalString(value, buf, offset, idx);
buf[offset + idx] = (byte) ' '; // Trailing space
@@ -468,7 +465,7 @@ public class TarUtils {
* will not fit in the buffer.
*/
public static int formatLongOctalOrBinaryBytes(
final long value, byte[] buf, final int offset, final int length) {
final long value, final byte[] buf, final int offset, final int length) {

// Check whether we are dealing with UID/GID or SIZE field
final long maxAsOctalChar = length == TarConstants.UIDLEN ? TarConstants.MAXID : TarConstants.MAXSIZE;
@@ -487,7 +484,7 @@ public class TarUtils {
return offset + length;
}

private static void formatLongBinary(final long value, byte[] buf,
private static void formatLongBinary(final long value, final byte[] buf,
final int offset, final int length,
final boolean negative) {
final int bits = (length - 1) * 8;
@@ -508,11 +505,11 @@ public class TarUtils {
}
}

private static void formatBigIntegerBinary(final long value, byte[] buf,
private static void formatBigIntegerBinary(final long value, final byte[] buf,
final int offset,
final int length,
final boolean negative) {
BigInteger val = BigInteger.valueOf(value);
final BigInteger val = BigInteger.valueOf(value);
final byte[] b = val.toByteArray();
final int len = b.length;
final int off = offset + length - len;
@@ -537,7 +534,7 @@ public class TarUtils {
* @return The updated value of offset, i.e. offset+length
* @throws IllegalArgumentException if the value (and trailer) will not fit in the buffer
*/
public static int formatCheckSumOctalBytes(final long value, byte[] buf, final int offset, final int length) {
public static int formatCheckSumOctalBytes(final long value, final byte[] buf, final int offset, final int length) {

int idx=length-2; // for NUL and space
formatUnsignedOctalString(value, buf, offset, idx);
@@ -557,7 +554,7 @@ public class TarUtils {
public static long computeCheckSum(final byte[] buf) {
long sum = 0;

for (byte element : buf) {
for (final byte element : buf) {
sum += BYTE_MASK & element;
}



+ 9
- 14
src/main/org/apache/tools/zip/AbstractUnicodeExtraField.java View File

@@ -45,15 +45,15 @@ public abstract class AbstractUnicodeExtraField implements ZipExtraField {
* @param len The length of the encoded filename or commentin
* <code>bytes</code>.
*/
protected AbstractUnicodeExtraField(String text, byte[] bytes, int off,
int len) {
CRC32 crc32 = new CRC32();
protected AbstractUnicodeExtraField(final String text, final byte[] bytes, final int off,
final int len) {
final CRC32 crc32 = new CRC32();
crc32.update(bytes, off, len);
nameCRC32 = crc32.getValue();

try {
unicodeName = text.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
} catch (final UnsupportedEncodingException e) {
throw new RuntimeException("FATAL: UTF-8 encoding not supported.",
e);
}
@@ -67,7 +67,7 @@ public abstract class AbstractUnicodeExtraField implements ZipExtraField {
* @param bytes The encoded of the filename or comment in the zip
* file.
*/
protected AbstractUnicodeExtraField(String text, byte[] bytes) {
protected AbstractUnicodeExtraField(final String text, final byte[] bytes) {

this(text, bytes, 0, bytes.length);
}
@@ -96,7 +96,7 @@ public abstract class AbstractUnicodeExtraField implements ZipExtraField {
* @param nameCRC32 The CRC32 checksum of the filename as encoded
* in the central directory of the zip file to set.
*/
public void setNameCRC32(long nameCRC32) {
public void setNameCRC32(final long nameCRC32) {
this.nameCRC32 = nameCRC32;
data = null;
}
@@ -116,7 +116,7 @@ public abstract class AbstractUnicodeExtraField implements ZipExtraField {
/**
* @param unicodeName The utf-8 encoded name to set.
*/
public void setUnicodeName(byte[] unicodeName) {
public void setUnicodeName(final byte[] unicodeName) {
if (unicodeName != null) {
this.unicodeName = new byte[unicodeName.length];
System.arraycopy(unicodeName, 0, this.unicodeName, 0,
@@ -128,7 +128,6 @@ public abstract class AbstractUnicodeExtraField implements ZipExtraField {
}

/** {@inheritDoc} */
@Override
public byte[] getCentralDirectoryData() {
if (data == null) {
this.assembleData();
@@ -142,7 +141,6 @@ public abstract class AbstractUnicodeExtraField implements ZipExtraField {
}

/** {@inheritDoc} */
@Override
public ZipShort getCentralDirectoryLength() {
if (data == null) {
assembleData();
@@ -151,20 +149,17 @@ public abstract class AbstractUnicodeExtraField implements ZipExtraField {
}

/** {@inheritDoc} */
@Override
public byte[] getLocalFileDataData() {
return getCentralDirectoryData();
}

/** {@inheritDoc} */
@Override
public ZipShort getLocalFileDataLength() {
return getCentralDirectoryLength();
}

/** {@inheritDoc} */
@Override
public void parseFromLocalFileData(byte[] buffer, int offset, int length)
public void parseFromLocalFileData(final byte[] buffer, final int offset, final int length)
throws ZipException {

if (length < 5) {
@@ -172,7 +167,7 @@ public abstract class AbstractUnicodeExtraField implements ZipExtraField {
+ " 5 bytes.");
}

int version = buffer[offset];
final int version = buffer[offset];

if (version != 0x01) {
throw new ZipException("Unsupported version [" + version


+ 4
- 7
src/main/org/apache/tools/zip/FallbackZipEncoding.java View File

@@ -56,7 +56,7 @@ class FallbackZipEncoding implements ZipEncoding {
* @param charset The name of the charset or {@code null} for
* the platform's default character set.
*/
public FallbackZipEncoding(String charset) {
public FallbackZipEncoding(final String charset) {
this.charset = charset;
}

@@ -64,8 +64,7 @@ class FallbackZipEncoding implements ZipEncoding {
* @see
* org.apache.tools.zip.ZipEncoding#canEncode(java.lang.String)
*/
@Override
public boolean canEncode(String name) {
public boolean canEncode(final String name) {
return true;
}

@@ -73,8 +72,7 @@ class FallbackZipEncoding implements ZipEncoding {
* @see
* org.apache.tools.zip.ZipEncoding#encode(java.lang.String)
*/
@Override
public ByteBuffer encode(String name) throws IOException {
public ByteBuffer encode(final String name) throws IOException {
if (this.charset == null) { // i.e. use default charset, see no-args constructor
return ByteBuffer.wrap(name.getBytes());
} else {
@@ -86,8 +84,7 @@ class FallbackZipEncoding implements ZipEncoding {
* @see
* org.apache.tools.zip.ZipEncoding#decode(byte[])
*/
@Override
public String decode(byte[] data) throws IOException {
public String decode(final byte[] data) throws IOException {
if (this.charset == null) { // i.e. use default charset, see no-args constructor
return new String(data);
} else {


+ 8
- 11
src/main/org/apache/tools/zip/NioZipEncoding.java View File

@@ -46,7 +46,7 @@ class NioZipEncoding implements ZipEncoding {
*
* @param charset The NIO charset to wrap.
*/
public NioZipEncoding(Charset charset) {
public NioZipEncoding(final Charset charset) {
this.charset = charset;
}

@@ -54,9 +54,8 @@ class NioZipEncoding implements ZipEncoding {
* @see
* org.apache.tools.zip.ZipEncoding#canEncode(java.lang.String)
*/
@Override
public boolean canEncode(String name) {
CharsetEncoder enc = this.charset.newEncoder();
public boolean canEncode(final String name) {
final CharsetEncoder enc = this.charset.newEncoder();
enc.onMalformedInput(CodingErrorAction.REPORT);
enc.onUnmappableCharacter(CodingErrorAction.REPORT);

@@ -67,19 +66,18 @@ class NioZipEncoding implements ZipEncoding {
* @see
* org.apache.tools.zip.ZipEncoding#encode(java.lang.String)
*/
@Override
public ByteBuffer encode(String name) {
CharsetEncoder enc = this.charset.newEncoder();
public ByteBuffer encode(final String name) {
final CharsetEncoder enc = this.charset.newEncoder();

enc.onMalformedInput(CodingErrorAction.REPORT);
enc.onUnmappableCharacter(CodingErrorAction.REPORT);

CharBuffer cb = CharBuffer.wrap(name);
final CharBuffer cb = CharBuffer.wrap(name);
ByteBuffer out = ByteBuffer.allocate(name.length()
+ (name.length() + 1) / 2);

while (cb.remaining() > 0) {
CoderResult res = enc.encode(cb, out,true);
final CoderResult res = enc.encode(cb, out,true);

if (res.isUnmappable() || res.isMalformed()) {

@@ -115,8 +113,7 @@ class NioZipEncoding implements ZipEncoding {
* @see
* org.apache.tools.zip.ZipEncoding#decode(byte[])
*/
@Override
public String decode(byte[] data) throws IOException {
public String decode(final byte[] data) throws IOException {
return this.charset.newDecoder()
.onMalformedInput(CodingErrorAction.REPORT)
.onUnmappableCharacter(CodingErrorAction.REPORT)


+ 21
- 25
src/main/org/apache/tools/zip/Simple8BitZipEncoding.java View File

@@ -53,13 +53,12 @@ class Simple8BitZipEncoding implements ZipEncoding {
public final char unicode;
public final byte code;

Simple8BitChar(byte code, char unicode) {
Simple8BitChar(final byte code, final char unicode) {
this.code = code;
this.unicode = unicode;
}

@Override
public int compareTo(Simple8BitChar a) {
public int compareTo(final Simple8BitChar a) {
return this.unicode - a.unicode;
}

@@ -70,9 +69,9 @@ class Simple8BitZipEncoding implements ZipEncoding {
}

@Override
public boolean equals(Object o) {
public boolean equals(final Object o) {
if (o instanceof Simple8BitChar) {
Simple8BitChar other = (Simple8BitChar) o;
final Simple8BitChar other = (Simple8BitChar) o;
return unicode == other.unicode && code == other.code;
}
return false;
@@ -101,9 +100,9 @@ class Simple8BitZipEncoding implements ZipEncoding {
* @param highChars The characters for byte values of 128 to 255
* stored as an array of 128 chars.
*/
public Simple8BitZipEncoding(char[] highChars) {
public Simple8BitZipEncoding(final char[] highChars) {
this.highChars = highChars.clone();
List<Simple8BitChar> temp =
final List<Simple8BitChar> temp =
new ArrayList<Simple8BitChar>(this.highChars.length);

byte code = 127;
@@ -122,7 +121,7 @@ class Simple8BitZipEncoding implements ZipEncoding {
* @param b The byte to decode.
* @return The associated character value.
*/
public char decodeByte(byte b) {
public char decodeByte(final byte b) {
// code 0-127
if (b >= 0) {
return (char) b;
@@ -136,13 +135,13 @@ class Simple8BitZipEncoding implements ZipEncoding {
* @param c The character to encode.
* @return Whether the given unicode character is covered by this encoding.
*/
public boolean canEncodeChar(char c) {
public boolean canEncodeChar(final char c) {

if (c >= 0 && c < 128) {
return true;
}

Simple8BitChar r = this.encodeHighChar(c);
final Simple8BitChar r = this.encodeHighChar(c);
return r != null;
}

@@ -155,14 +154,14 @@ class Simple8BitZipEncoding implements ZipEncoding {
* If {@code false} is returned, nothing is pushed to the
* byte buffer.
*/
public boolean pushEncodedChar(ByteBuffer bb, char c) {
public boolean pushEncodedChar(final ByteBuffer bb, final char c) {

if (c >= 0 && c < 128) {
bb.put((byte) c);
return true;
}

Simple8BitChar r = this.encodeHighChar(c);
final Simple8BitChar r = this.encodeHighChar(c);
if (r == null) {
return false;
}
@@ -176,7 +175,7 @@ class Simple8BitZipEncoding implements ZipEncoding {
* A {@code null} value is returned, if this character is not
* covered by this encoding.
*/
private Simple8BitChar encodeHighChar(char c) {
private Simple8BitChar encodeHighChar(final char c) {
// for performance an simplicity, yet another reincarnation of
// binary search...
int i0 = 0;
@@ -184,9 +183,9 @@ class Simple8BitZipEncoding implements ZipEncoding {

while (i1 > i0) {

int i = i0 + (i1 - i0) / 2;
final int i = i0 + (i1 - i0) / 2;

Simple8BitChar m = this.reverseMapping.get(i);
final Simple8BitChar m = this.reverseMapping.get(i);

if (m.unicode == c) {
return m;
@@ -203,7 +202,7 @@ class Simple8BitZipEncoding implements ZipEncoding {
return null;
}

Simple8BitChar r = this.reverseMapping.get(i0);
final Simple8BitChar r = this.reverseMapping.get(i0);

if (r.unicode != c) {
return null;
@@ -216,12 +215,11 @@ class Simple8BitZipEncoding implements ZipEncoding {
* @see
* org.apache.tools.zip.ZipEncoding#canEncode(java.lang.String)
*/
@Override
public boolean canEncode(String name) {
public boolean canEncode(final String name) {

for (int i=0;i<name.length();++i) {

char c = name.charAt(i);
final char c = name.charAt(i);

if (!this.canEncodeChar(c)) {
return false;
@@ -235,14 +233,13 @@ class Simple8BitZipEncoding implements ZipEncoding {
* @see
* org.apache.tools.zip.ZipEncoding#encode(java.lang.String)
*/
@Override
public ByteBuffer encode(String name) {
public ByteBuffer encode(final String name) {
ByteBuffer out = ByteBuffer.allocate(name.length()
+ 6 + (name.length() + 1) / 2);

for (int i=0;i<name.length();++i) {

char c = name.charAt(i);
final char c = name.charAt(i);

if (out.remaining() < 6) {
out = ZipEncodingHelper.growBuffer(out,out.position() + 6);
@@ -263,9 +260,8 @@ class Simple8BitZipEncoding implements ZipEncoding {
* @see
* org.apache.tools.zip.ZipEncoding#decode(byte[])
*/
@Override
public String decode(byte[] data) throws IOException {
char [] ret = new char[data.length];
public String decode(final byte[] data) throws IOException {
final char [] ret = new char[data.length];

for (int i=0;i<data.length;++i) {
ret[i] = this.decodeByte(data[i]);


+ 3
- 4
src/main/org/apache/tools/zip/UnicodeCommentExtraField.java View File

@@ -46,8 +46,8 @@ public class UnicodeCommentExtraField extends AbstractUnicodeExtraField {
* @param len The length of the encoded comment or comment in
* <code>bytes</code>.
*/
public UnicodeCommentExtraField(String text, byte[] bytes, int off,
int len) {
public UnicodeCommentExtraField(final String text, final byte[] bytes, final int off,
final int len) {
super(text, bytes, off, len);
}

@@ -58,12 +58,11 @@ public class UnicodeCommentExtraField extends AbstractUnicodeExtraField {
* @param comment The file comment
* @param bytes the bytes actually written to the archive
*/
public UnicodeCommentExtraField(String comment, byte[] bytes) {
public UnicodeCommentExtraField(final String comment, final byte[] bytes) {
super(comment, bytes);
}

/** {@inheritDoc} */
@Override
public ZipShort getHeaderId() {
return UCOM_ID;
}


+ 2
- 3
src/main/org/apache/tools/zip/UnicodePathExtraField.java View File

@@ -45,7 +45,7 @@ public class UnicodePathExtraField extends AbstractUnicodeExtraField {
* @param len The length of the encoded filename or comment in
* <code>bytes</code>.
*/
public UnicodePathExtraField(String text, byte[] bytes, int off, int len) {
public UnicodePathExtraField(final String text, final byte[] bytes, final int off, final int len) {
super(text, bytes, off, len);
}

@@ -56,12 +56,11 @@ public class UnicodePathExtraField extends AbstractUnicodeExtraField {
* @param name The file name
* @param bytes the bytes actually written to the archive
*/
public UnicodePathExtraField(String name, byte[] bytes) {
public UnicodePathExtraField(final String name, final byte[] bytes) {
super(name, bytes);
}

/** {@inheritDoc} */
@Override
public ZipShort getHeaderId() {
return UPATH_ID;
}


+ 67
- 68
src/main/org/apache/tools/zip/ZipFile.java View File

@@ -146,7 +146,7 @@ public class ZipFile {
*
* @throws IOException if an error occurs while reading the file.
*/
public ZipFile(File f) throws IOException {
public ZipFile(final File f) throws IOException {
this(f, null);
}

@@ -158,7 +158,7 @@ public class ZipFile {
*
* @throws IOException if an error occurs while reading the file.
*/
public ZipFile(String name) throws IOException {
public ZipFile(final String name) throws IOException {
this(new File(name), null);
}

@@ -172,7 +172,7 @@ public class ZipFile {
*
* @throws IOException if an error occurs while reading the file.
*/
public ZipFile(String name, String encoding) throws IOException {
public ZipFile(final String name, final String encoding) throws IOException {
this(new File(name), encoding, true);
}

@@ -186,7 +186,7 @@ public class ZipFile {
*
* @throws IOException if an error occurs while reading the file.
*/
public ZipFile(File f, String encoding) throws IOException {
public ZipFile(final File f, final String encoding) throws IOException {
this(f, encoding, true);
}

@@ -202,7 +202,7 @@ public class ZipFile {
*
* @throws IOException if an error occurs while reading the file.
*/
public ZipFile(File f, String encoding, boolean useUnicodeExtraFields)
public ZipFile(final File f, final String encoding, final boolean useUnicodeExtraFields)
throws IOException {
this.archiveName = f.getAbsolutePath();
this.encoding = encoding;
@@ -211,7 +211,7 @@ public class ZipFile {
archive = new RandomAccessFile(f, "r");
boolean success = false;
try {
Map<ZipEntry, NameAndComment> entriesWithoutUTF8Flag =
final Map<ZipEntry, NameAndComment> entriesWithoutUTF8Flag =
populateFromCentralDirectory();
resolveLocalFileHeaderData(entriesWithoutUTF8Flag);
success = true;
@@ -220,7 +220,7 @@ public class ZipFile {
try {
closed = true;
archive.close();
} catch (IOException e2) {
} catch (final IOException e2) {
// swallow, throw the original exception instead
}
}
@@ -254,11 +254,11 @@ public class ZipFile {
* on a null parameter
* @param zipfile file to close, can be null
*/
public static void closeQuietly(ZipFile zipfile) {
public static void closeQuietly(final ZipFile zipfile) {
if (zipfile != null) {
try {
zipfile.close();
} catch (IOException e) {
} catch (final IOException e) {
//ignore
}
}
@@ -287,7 +287,7 @@ public class ZipFile {
* @since Ant 1.9.0
*/
public Enumeration<ZipEntry> getEntriesInPhysicalOrder() {
ZipEntry[] allEntries = entries.toArray(new ZipEntry[0]);
final ZipEntry[] allEntries = entries.toArray(new ZipEntry[0]);
Arrays.sort(allEntries, OFFSET_COMPARATOR);
return Collections.enumeration(Arrays.asList(allEntries));
}
@@ -304,8 +304,8 @@ public class ZipFile {
* @return the ZipEntry corresponding to the given name - or
* {@code null} if not present.
*/
public ZipEntry getEntry(String name) {
LinkedList<ZipEntry> entriesOfThatName = nameMap.get(name);
public ZipEntry getEntry(final String name) {
final LinkedList<ZipEntry> entriesOfThatName = nameMap.get(name);
return entriesOfThatName != null ? entriesOfThatName.getFirst() : null;
}

@@ -318,8 +318,8 @@ public class ZipFile {
* given name
* @since 1.9.2
*/
public Iterable<ZipEntry> getEntries(String name) {
List<ZipEntry> entriesOfThatName = nameMap.get(name);
public Iterable<ZipEntry> getEntries(final String name) {
final List<ZipEntry> entriesOfThatName = nameMap.get(name);
return entriesOfThatName != null ? entriesOfThatName
: Collections.<ZipEntry>emptyList();
}
@@ -333,7 +333,7 @@ public class ZipFile {
* given name
* @since 1.9.2
*/
public Iterable<ZipEntry> getEntriesInPhysicalOrder(String name) {
public Iterable<ZipEntry> getEntriesInPhysicalOrder(final String name) {
ZipEntry[] entriesOfThatName = new ZipEntry[0];
if (nameMap.containsKey(name)) {
entriesOfThatName = nameMap.get(name).toArray(entriesOfThatName);
@@ -348,7 +348,7 @@ public class ZipFile {
* <p>May return false if it is set up to use encryption or a
* compression method that hasn't been implemented yet.</p>
*/
public boolean canReadEntryData(ZipEntry ze) {
public boolean canReadEntryData(final ZipEntry ze) {
return ZipUtil.canHandleEntryData(ze);
}

@@ -360,16 +360,16 @@ public class ZipFile {
* @throws IOException if unable to create an input stream from the zipentry
* @throws ZipException if the zipentry uses an unsupported feature
*/
public InputStream getInputStream(ZipEntry ze)
public InputStream getInputStream(final ZipEntry ze)
throws IOException, ZipException {
if (!(ze instanceof Entry)) {
return null;
}
// cast valididty is checked just above
OffsetEntry offsetEntry = ((Entry) ze).getOffsetEntry();
final OffsetEntry offsetEntry = ((Entry) ze).getOffsetEntry();
ZipUtil.checkRequestedFeatures(ze);
long start = offsetEntry.dataOffset;
BoundedInputStream bis =
final long start = offsetEntry.dataOffset;
final BoundedInputStream bis =
new BoundedInputStream(start, ze.getCompressedSize());
switch (ze.getMethod()) {
case ZipEntry.STORED:
@@ -446,7 +446,7 @@ public class ZipFile {
*/
private Map<ZipEntry, NameAndComment> populateFromCentralDirectory()
throws IOException {
HashMap<ZipEntry, NameAndComment> noUTF8Flag =
final HashMap<ZipEntry, NameAndComment> noUTF8Flag =
new HashMap<ZipEntry, NameAndComment>();

positionAtCentralDirectory();
@@ -477,14 +477,14 @@ public class ZipFile {
* added to this map.
*/
private void
readCentralDirectoryEntry(Map<ZipEntry, NameAndComment> noUTF8Flag)
readCentralDirectoryEntry(final Map<ZipEntry, NameAndComment> noUTF8Flag)
throws IOException {
archive.readFully(CFH_BUF);
int off = 0;
OffsetEntry offset = new OffsetEntry();
Entry ze = new Entry(offset);
final OffsetEntry offset = new OffsetEntry();
final Entry ze = new Entry(offset);

int versionMadeBy = ZipShort.getValue(CFH_BUF, off);
final int versionMadeBy = ZipShort.getValue(CFH_BUF, off);
off += SHORT;
ze.setPlatform((versionMadeBy >> BYTE_SHIFT) & NIBLET_MASK);

@@ -501,7 +501,7 @@ public class ZipFile {
ze.setMethod(ZipShort.getValue(CFH_BUF, off));
off += SHORT;

long time = ZipUtil.dosToJavaTime(ZipLong.getValue(CFH_BUF, off));
final long time = ZipUtil.dosToJavaTime(ZipLong.getValue(CFH_BUF, off));
ze.setTime(time);
off += WORD;

@@ -514,16 +514,16 @@ public class ZipFile {
ze.setSize(ZipLong.getValue(CFH_BUF, off));
off += WORD;

int fileNameLen = ZipShort.getValue(CFH_BUF, off);
final int fileNameLen = ZipShort.getValue(CFH_BUF, off);
off += SHORT;

int extraLen = ZipShort.getValue(CFH_BUF, off);
final int extraLen = ZipShort.getValue(CFH_BUF, off);
off += SHORT;

int commentLen = ZipShort.getValue(CFH_BUF, off);
final int commentLen = ZipShort.getValue(CFH_BUF, off);
off += SHORT;

int diskStart = ZipShort.getValue(CFH_BUF, off);
final int diskStart = ZipShort.getValue(CFH_BUF, off);
off += SHORT;

ze.setInternalAttributes(ZipShort.getValue(CFH_BUF, off));
@@ -532,7 +532,7 @@ public class ZipFile {
ze.setExternalAttributes(ZipLong.getValue(CFH_BUF, off));
off += WORD;

byte[] fileName = new byte[fileNameLen];
final byte[] fileName = new byte[fileNameLen];
archive.readFully(fileName);
ze.setName(entryEncoding.decode(fileName), fileName);

@@ -541,13 +541,13 @@ public class ZipFile {
// data offset will be filled later
entries.add(ze);

byte[] cdExtraData = new byte[extraLen];
final byte[] cdExtraData = new byte[extraLen];
archive.readFully(cdExtraData);
ze.setCentralDirectoryExtra(cdExtraData);

setSizesAndOffsetFromZip64Extra(ze, offset, diskStart);

byte[] comment = new byte[commentLen];
final byte[] comment = new byte[commentLen];
archive.readFully(comment);
ze.setComment(entryEncoding.decode(comment));

@@ -568,17 +568,17 @@ public class ZipFile {
* even if they are never used - and here a field with only one
* size would be invalid.</p>
*/
private void setSizesAndOffsetFromZip64Extra(ZipEntry ze,
OffsetEntry offset,
int diskStart)
private void setSizesAndOffsetFromZip64Extra(final ZipEntry ze,
final OffsetEntry offset,
final int diskStart)
throws IOException {
Zip64ExtendedInformationExtraField z64 =
final Zip64ExtendedInformationExtraField z64 =
(Zip64ExtendedInformationExtraField)
ze.getExtraField(Zip64ExtendedInformationExtraField.HEADER_ID);
if (z64 != null) {
boolean hasUncompressedSize = ze.getSize() == ZIP64_MAGIC;
boolean hasCompressedSize = ze.getCompressedSize() == ZIP64_MAGIC;
boolean hasRelativeHeaderOffset =
final boolean hasUncompressedSize = ze.getSize() == ZIP64_MAGIC;
final boolean hasCompressedSize = ze.getCompressedSize() == ZIP64_MAGIC;
final boolean hasRelativeHeaderOffset =
offset.headerOffset == ZIP64_MAGIC;
z64.reparseCentralDirectoryData(hasUncompressedSize,
hasCompressedSize,
@@ -706,7 +706,7 @@ public class ZipFile {
throws IOException {
positionAtEndOfCentralDirectoryRecord();
boolean found = false;
boolean searchedForZip64EOCD =
final boolean searchedForZip64EOCD =
archive.getFilePointer() > ZIP64_EOCDL_LENGTH;
if (searchedForZip64EOCD) {
archive.seek(archive.getFilePointer() - ZIP64_EOCDL_LENGTH);
@@ -765,7 +765,7 @@ public class ZipFile {
*/
private void positionAtEndOfCentralDirectoryRecord()
throws IOException {
boolean found = tryToLocateSignature(MIN_EOCD_SIZE, MAX_EOCD_SIZE,
final boolean found = tryToLocateSignature(MIN_EOCD_SIZE, MAX_EOCD_SIZE,
ZipOutputStream.EOCD_SIG);
if (!found) {
throw new ZipException("archive is not a ZIP archive");
@@ -777,9 +777,9 @@ public class ZipFile {
* for the given signature, positions the RandomaccessFile right
* at the signature if it has been found.
*/
private boolean tryToLocateSignature(long minDistanceFromEnd,
long maxDistanceFromEnd,
byte[] sig) throws IOException {
private boolean tryToLocateSignature(final long minDistanceFromEnd,
final long maxDistanceFromEnd,
final byte[] sig) throws IOException {
boolean found = false;
long off = archive.length() - minDistanceFromEnd;
final long stopSearching =
@@ -819,7 +819,7 @@ public class ZipFile {
private void skipBytes(final int count) throws IOException {
int totalSkipped = 0;
while (totalSkipped < count) {
int skippedNow = archive.skipBytes(count - totalSkipped);
final int skippedNow = archive.skipBytes(count - totalSkipped);
if (skippedNow <= 0) {
throw new EOFException();
}
@@ -849,42 +849,42 @@ public class ZipFile {
* <p>Also records the offsets for the data to read from the
* entries.</p>
*/
private void resolveLocalFileHeaderData(Map<ZipEntry, NameAndComment>
private void resolveLocalFileHeaderData(final Map<ZipEntry, NameAndComment>
entriesWithoutUTF8Flag)
throws IOException {
for (Iterator<ZipEntry> it = entries.iterator(); it.hasNext();) {
for (final Iterator<ZipEntry> it = entries.iterator(); it.hasNext();) {
// entries is filled in populateFromCentralDirectory and
// never modified
Entry ze = (Entry) it.next();
OffsetEntry offsetEntry = ze.getOffsetEntry();
long offset = offsetEntry.headerOffset;
final Entry ze = (Entry) it.next();
final OffsetEntry offsetEntry = ze.getOffsetEntry();
final long offset = offsetEntry.headerOffset;
archive.seek(offset + LFH_OFFSET_FOR_FILENAME_LENGTH);
archive.readFully(SHORT_BUF);
int fileNameLen = ZipShort.getValue(SHORT_BUF);
final int fileNameLen = ZipShort.getValue(SHORT_BUF);
archive.readFully(SHORT_BUF);
int extraFieldLen = ZipShort.getValue(SHORT_BUF);
final int extraFieldLen = ZipShort.getValue(SHORT_BUF);
int lenToSkip = fileNameLen;
while (lenToSkip > 0) {
int skipped = archive.skipBytes(lenToSkip);
final int skipped = archive.skipBytes(lenToSkip);
if (skipped <= 0) {
throw new IOException("failed to skip file name in"
+ " local file header");
}
lenToSkip -= skipped;
}
byte[] localExtraData = new byte[extraFieldLen];
final byte[] localExtraData = new byte[extraFieldLen];
archive.readFully(localExtraData);
ze.setExtra(localExtraData);
offsetEntry.dataOffset = offset + LFH_OFFSET_FOR_FILENAME_LENGTH
+ SHORT + SHORT + fileNameLen + extraFieldLen;

if (entriesWithoutUTF8Flag.containsKey(ze)) {
NameAndComment nc = entriesWithoutUTF8Flag.get(ze);
final NameAndComment nc = entriesWithoutUTF8Flag.get(ze);
ZipUtil.setNameAndCommentFromExtraFields(ze, nc.name,
nc.comment);
}

String name = ze.getName();
final String name = ze.getName();
LinkedList<ZipEntry> entriesOfThatName = nameMap.get(name);
if (entriesOfThatName == null) {
entriesOfThatName = new LinkedList<ZipEntry>();
@@ -914,7 +914,7 @@ public class ZipFile {
private long loc;
private boolean addDummyByte = false;

BoundedInputStream(long start, long remaining) {
BoundedInputStream(final long start, final long remaining) {
this.remaining = remaining;
loc = start;
}
@@ -935,7 +935,7 @@ public class ZipFile {
}

@Override
public int read(byte[] b, int off, int len) throws IOException {
public int read(final byte[] b, final int off, int len) throws IOException {
if (remaining <= 0) {
if (addDummyByte) {
addDummyByte = false;
@@ -976,7 +976,7 @@ public class ZipFile {
private static final class NameAndComment {
private final byte[] name;
private final byte[] comment;
private NameAndComment(byte[] name, byte[] comment) {
private NameAndComment(final byte[] name, final byte[] comment) {
this.name = name;
this.comment = comment;
}
@@ -992,21 +992,20 @@ public class ZipFile {
*/
private final Comparator<ZipEntry> OFFSET_COMPARATOR =
new Comparator<ZipEntry>() {
@Override
public int compare(ZipEntry e1, ZipEntry e2) {
public int compare(final ZipEntry e1, final ZipEntry e2) {
if (e1 == e2) {
return 0;
}

Entry ent1 = e1 instanceof Entry ? (Entry) e1 : null;
Entry ent2 = e2 instanceof Entry ? (Entry) e2 : null;
final Entry ent1 = e1 instanceof Entry ? (Entry) e1 : null;
final Entry ent2 = e2 instanceof Entry ? (Entry) e2 : null;
if (ent1 == null) {
return 1;
}
if (ent2 == null) {
return -1;
}
long val = (ent1.getOffsetEntry().headerOffset
final long val = (ent1.getOffsetEntry().headerOffset
- ent2.getOffsetEntry().headerOffset);
return val == 0 ? 0 : val < 0 ? -1 : +1;
}
@@ -1019,7 +1018,7 @@ public class ZipFile {

private final OffsetEntry offsetEntry;

Entry(OffsetEntry offset) {
Entry(final OffsetEntry offset) {
this.offsetEntry = offset;
}

@@ -1034,10 +1033,10 @@ public class ZipFile {
}

@Override
public boolean equals(Object other) {
public boolean equals(final Object other) {
if (super.equals(other)) {
// super.equals would return false if other were not an Entry
Entry otherEntry = (Entry) other;
final Entry otherEntry = (Entry) other;
return offsetEntry.headerOffset
== otherEntry.offsetEntry.headerOffset
&& offsetEntry.dataOffset


Loading…
Cancel
Save