http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/Sleep.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/Sleep.java b/src/main/org/apache/tools/ant/taskdefs/Sleep.java index 6468c39..5a59c19 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Sleep.java +++ b/src/main/org/apache/tools/ant/taskdefs/Sleep.java @@ -64,15 +64,12 @@ public class Sleep extends Task { */ private int milliseconds = 0; - - /** * Creates new instance */ public Sleep() { } - /** * seconds to add to the sleep time * @@ -82,7 +79,6 @@ public class Sleep extends Task { this.seconds = seconds; } - /** * hours to add to the sleep time. * @@ -92,7 +88,6 @@ public class Sleep extends Task { this.hours = hours; } - /** * minutes to add to the sleep time * @@ -102,7 +97,6 @@ public class Sleep extends Task { this.minutes = minutes; } - /** * milliseconds to add to the sleep time * @@ -112,7 +106,6 @@ public class Sleep extends Task { this.milliseconds = milliseconds; } - /** * sleep for a period of time * @@ -126,7 +119,6 @@ public class Sleep extends Task { } } - /** * flag controlling whether to break the build on an error. * @@ -136,7 +128,6 @@ public class Sleep extends Task { this.failOnError = failOnError; } - /** * return time to sleep * @@ -150,7 +141,6 @@ public class Sleep extends Task { // CheckStyle:MagicNumber ON } - /** * verify parameters * @@ -159,12 +149,10 @@ public class Sleep extends Task { public void validate() throws BuildException { if (getSleepTime() < 0) { - throw new BuildException("Negative sleep periods are not " - + "supported"); + throw new BuildException("Negative sleep periods are not supported"); } } - /** * Executes this build task. Throws org.apache.tools.ant.BuildException * if there is an error during task execution. @@ -183,12 +171,9 @@ public class Sleep extends Task { } catch (Exception e) { if (failOnError) { throw new BuildException(e); - } else { - String text = e.toString(); - log(text, Project.MSG_ERR); } + log(e.toString(), Project.MSG_ERR); } } } -
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/StreamPumper.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/StreamPumper.java b/src/main/org/apache/tools/ant/taskdefs/StreamPumper.java index 59d886b..0b91d5b 100644 --- a/src/main/org/apache/tools/ant/taskdefs/StreamPumper.java +++ b/src/main/org/apache/tools/ant/taskdefs/StreamPumper.java @@ -55,7 +55,6 @@ public class StreamPumper implements Runnable { this(is, os, closeWhenExhausted, false); } - /** * Create a new StreamPumper. * @@ -112,6 +111,7 @@ public class StreamPumper implements Runnable { * * Terminates as soon as the input stream is closed or an error occurs. */ + @Override public void run() { synchronized (this) { started = true; @@ -120,8 +120,8 @@ public class StreamPumper implements Runnable { final byte[] buf = new byte[bufferSize]; - int length; try { + int length; while (true) { waitForInput(is); http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/SubAnt.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/SubAnt.java b/src/main/org/apache/tools/ant/taskdefs/SubAnt.java index c374d83..17351b5 100644 --- a/src/main/org/apache/tools/ant/taskdefs/SubAnt.java +++ b/src/main/org/apache/tools/ant/taskdefs/SubAnt.java @@ -19,7 +19,7 @@ package org.apache.tools.ant.taskdefs; import java.io.File; import java.io.IOException; -import java.util.Enumeration; +import java.util.List; import java.util.Vector; import org.apache.tools.ant.BuildException; @@ -72,12 +72,12 @@ public class SubAnt extends Task { private boolean failOnError = true; private String output = null; - private Vector properties = new Vector(); - private Vector references = new Vector(); - private Vector propertySets = new Vector(); + private List<Property> properties = new Vector<>(); + private List<Ant.Reference> references = new Vector<>(); + private List<PropertySet> propertySets = new Vector<>(); /** the targets to call on the new project */ - private Vector/*<TargetElement>*/ targets = new Vector(); + private List<TargetElement> targets = new Vector<>(); /** * Get the default build file name to use when launching the task. @@ -296,11 +296,7 @@ public class SubAnt extends Task { ant = createAntTask(directory); String antfilename = file.getAbsolutePath(); ant.setAntfile(antfilename); - final int size = targets.size(); - for (int i = 0; i < size; i++) { - TargetElement targetElement = (TargetElement) targets.get(i); - ant.addConfiguredTarget(targetElement); - } + targets.forEach(ant::addConfiguredTarget); try { if (verbose) { @@ -331,13 +327,15 @@ public class SubAnt extends Task { private boolean isHardError(Throwable t) { if (t instanceof BuildException) { return isHardError(t.getCause()); - } else if (t instanceof OutOfMemoryError) { + } + if (t instanceof OutOfMemoryError) { return true; - } else if (t instanceof ThreadDeath) { + } + if (t instanceof ThreadDeath) { return true; - } else { // incl. t == null - return false; } + // incl. t == null + return false; } /** @@ -392,8 +390,7 @@ public class SubAnt extends Task { * @since Ant 1.7 */ public void addConfiguredTarget(TargetElement t) { - String name = t.getName(); - if ("".equals(name)) { + if (t.getName().isEmpty()) { throw new BuildException("target name must not be empty"); } targets.add(t); @@ -445,7 +442,7 @@ public class SubAnt extends Task { * @param p the property to pass on explicitly to the sub-build. */ public void addProperty(Property p) { - properties.addElement(p); + properties.add(p); } /** @@ -455,7 +452,7 @@ public class SubAnt extends Task { * @param r the reference to pass on explicitly to the sub-build. */ public void addReference(Ant.Reference r) { - references.addElement(r); + references.add(r); } /** @@ -464,7 +461,7 @@ public class SubAnt extends Task { * @param ps the propertyset */ public void addPropertyset(PropertySet ps) { - propertySets.addElement(ps); + propertySets.add(ps); } /** @@ -591,18 +588,14 @@ public class SubAnt extends Task { } antTask.setInheritAll(inheritAll); - for (Enumeration i = properties.elements(); i.hasMoreElements();) { - copyProperty(antTask.createProperty(), (Property) i.nextElement()); - } - for (Enumeration i = propertySets.elements(); i.hasMoreElements();) { - antTask.addPropertyset((PropertySet) i.nextElement()); - } + properties.forEach(p -> copyProperty(antTask.createProperty(), p)); + + propertySets.forEach(antTask::addPropertyset); antTask.setInheritRefs(inheritRefs); - for (Enumeration i = references.elements(); i.hasMoreElements();) { - antTask.addReference((Ant.Reference) i.nextElement()); - } + + references.forEach(antTask::addReference); return antTask; } http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/Sync.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/Sync.java b/src/main/org/apache/tools/ant/taskdefs/Sync.java index bcdfd52..cadb342 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Sync.java +++ b/src/main/org/apache/tools/ant/taskdefs/Sync.java @@ -19,12 +19,12 @@ package org.apache.tools.ant.taskdefs; import java.io.File; -import java.util.Enumeration; +import java.util.Collections; import java.util.HashSet; -import java.util.Iterator; import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; +import java.util.stream.Stream; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.DirectoryScanner; @@ -105,7 +105,7 @@ public class Sync extends Task { File toDir = myCopy.getToDir(); // The complete list of files to copy - Set allFiles = myCopy.nonOrphans; + Set<String> allFiles = myCopy.nonOrphans; // If the destination directory didn't already exist, // or was empty, then no previous file removal is necessary! @@ -124,7 +124,7 @@ public class Sync extends Task { // will hold the directories matched by SyncTarget in reversed // lexicographic order (order is important, that's why we use // a LinkedHashSet - Set preservedDirectories = new LinkedHashSet(); + Set<File> preservedDirectories = new LinkedHashSet<>(); // Get rid of all files not listed in the source filesets. log("PASS#2: Removing orphan files from " + toDir, Project.MSG_DEBUG); @@ -186,15 +186,15 @@ public class Sync extends Task { * Position 0 of the array is the number of orphaned directories. * Position 1 of the array is the number or orphaned files. */ - private int[] removeOrphanFiles(Set nonOrphans, File toDir, - Set preservedDirectories) { - int[] removedCount = new int[] {0, 0}; + private int[] removeOrphanFiles(Set<String> nonOrphans, File toDir, + Set<File> preservedDirectories) { + int[] removedCount = new int[] { 0, 0 }; String[] excls = - (String[]) nonOrphans.toArray(new String[nonOrphans.size() + 1]); + nonOrphans.toArray(new String[nonOrphans.size() + 1]); // want to keep toDir itself excls[nonOrphans.size()] = ""; - DirectoryScanner ds = null; + DirectoryScanner ds; if (syncTarget != null) { FileSet fs = syncTarget.toFileSet(false); fs.setDir(toDir); @@ -213,8 +213,8 @@ public class Sync extends Task { FileSelector[] s = syncTarget.getSelectors(getProject()); if (s.length > 0) { NoneSelector ns = new NoneSelector(); - for (int i = 0; i < s.length; i++) { - ns.appendSelector(s[i]); + for (FileSelector element : s) { + ns.appendSelector(element); } fs.appendSelector(ns); } @@ -227,8 +227,8 @@ public class Sync extends Task { ds.scan(); String[] files = ds.getIncludedFiles(); - for (int i = 0; i < files.length; i++) { - File f = new File(toDir, files[i]); + for (String file : files) { + File f = new File(toDir, file); log("Removing orphan file: " + f, Project.MSG_DEBUG); f.delete(); ++removedCount[1]; @@ -282,7 +282,7 @@ public class Sync extends Task { * @return the number of empty directories actually removed. */ private int removeEmptyDirectories(File dir, boolean removeIfEmpty, - Set preservedEmptyDirectories) { + Set<File> preservedEmptyDirectories) { int removedCount = 0; if (dir.isDirectory()) { File[] children = dir.listFiles(); @@ -323,11 +323,9 @@ public class Sync extends Task { * * @since Ant 1.8.0 */ - private int removeEmptyDirectories(Set preservedEmptyDirectories) { + private int removeEmptyDirectories(Set<File> preservedEmptyDirectories) { int removedCount = 0; - for (Iterator iter = preservedEmptyDirectories.iterator(); - iter.hasNext();) { - File f = (File) iter.next(); + for (File f : preservedEmptyDirectories) { String[] s = f.list(); if (s == null || s.length == 0) { log("Removing empty directory: " + f, Project.MSG_DEBUG); @@ -434,8 +432,8 @@ public class Sync extends Task { */ public void addPreserveInTarget(SyncTarget s) { if (syncTarget != null) { - throw new BuildException("you must not specify multiple " - + "preserveintarget elements."); + throw new BuildException( + "you must not specify multiple preserveintarget elements."); } syncTarget = s; } @@ -457,11 +455,7 @@ public class Sync extends Task { // List of files that must be copied, irrelevant from the // fact that they are newer or not than the destination. - private Set nonOrphans = new HashSet(); - - /** Constructor for MyCopy. */ - public MyCopy() { - } + private Set<String> nonOrphans = new HashSet<>(); /** * @see Copy#scan(File, File, String[], String[]) @@ -474,12 +468,8 @@ public class Sync extends Task { super.scan(fromDir, toDir, files, dirs); - for (int i = 0; i < files.length; ++i) { - nonOrphans.add(files[i]); - } - for (int i = 0; i < dirs.length; ++i) { - nonOrphans.add(dirs[i]); - } + Collections.addAll(nonOrphans, files); + Collections.addAll(nonOrphans, dirs); } /** @@ -487,12 +477,11 @@ public class Sync extends Task { */ /** {@inheritDoc} */ @Override - protected Map scan(Resource[] resources, File toDir) { + protected Map<Resource, String[]> scan(Resource[] resources, File toDir) { assertTrue("No mapper", mapperElement == null); - for (int i = 0; i < resources.length; i++) { - nonOrphans.add(resources[i].getName()); - } + Stream.of(resources).map(Resource::getName).forEach(nonOrphans::add); + return super.scan(resources, toDir); } @@ -539,6 +528,7 @@ public class Sync extends Task { * This just changes the default value of "defaultexcludes" from * true to false. */ + // TODO does it? ^ public SyncTarget() { super(); } @@ -551,8 +541,8 @@ public class Sync extends Task { */ @Override public void setDir(File dir) throws BuildException { - throw new BuildException("preserveintarget doesn't support the dir " - + "attribute"); + throw new BuildException( + "preserveintarget doesn't support the dir attribute"); } /** @@ -586,8 +576,8 @@ public class Sync extends Task { PatternSet ps = mergePatterns(getProject()); fs.appendIncludes(ps.getIncludePatterns(getProject())); fs.appendExcludes(ps.getExcludePatterns(getProject())); - for (Enumeration e = selectorElements(); e.hasMoreElements();) { - fs.appendSelector((FileSelector) e.nextElement()); + for (FileSelector sel : getSelectors(getProject())) { + fs.appendSelector(sel); } fs.setDefaultexcludes(getDefaultexcludes()); } http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/Tar.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/Tar.java b/src/main/org/apache/tools/ant/taskdefs/Tar.java index 653cc5b..f51a056 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Tar.java +++ b/src/main/org/apache/tools/ant/taskdefs/Tar.java @@ -29,7 +29,6 @@ import java.nio.file.Files; 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; @@ -111,10 +110,10 @@ public class Tar extends MatchingTask { private TarLongFileMode longFileMode = new TarLongFileMode(); // need to keep the package private version for backwards compatibility - Vector<TarFileSet> filesets = new Vector<TarFileSet>(); + Vector<TarFileSet> filesets = new Vector<>(); // we must keep two lists since other classes may modify the // filesets Vector (it is package private) without us noticing - private final Vector<ResourceCollection> resourceCollections = new Vector<ResourceCollection>(); + private final List<ResourceCollection> resourceCollections = new Vector<>(); // CheckStyle:VisibilityModifier ON @@ -200,8 +199,7 @@ public class Tar extends MatchingTask { */ @Deprecated public void setLongfile(final String mode) { - log("DEPRECATED - The setLongfile(String) method has been deprecated." - + " Use setLongfile(Tar.TarLongFileMode) instead."); + log("DEPRECATED - The setLongfile(String) method has been deprecated. Use setLongfile(Tar.TarLongFileMode) instead."); this.longFileMode = new TarLongFileMode(); longFileMode.setValue(mode); } @@ -275,8 +273,7 @@ public class Tar extends MatchingTask { getLocation()); } - @SuppressWarnings("unchecked") - final Vector<TarFileSet> savedFileSets = (Vector<TarFileSet>) filesets.clone(); + final Vector<TarFileSet> savedFileSets = new Vector<>(filesets); try { if (baseDir != null) { if (!baseDir.exists()) { @@ -290,20 +287,19 @@ public class Tar extends MatchingTask { filesets.addElement(mainFileSet); } - if (filesets.size() == 0 && resourceCollections.size() == 0) { - throw new BuildException("You must supply either a basedir " - + "attribute or some nested resource" - + " collections.", - getLocation()); + if (filesets.isEmpty() && resourceCollections.isEmpty()) { + throw new BuildException( + "You must supply either a basedir attribute or some nested resource collections.", + getLocation()); } // check if tar is out of date with respect to each // fileset boolean upToDate = true; - for(final TarFileSet tfs : filesets) { + for (final TarFileSet tfs : filesets) { upToDate &= check(tfs); } - for(final ResourceCollection rcol : resourceCollections) { + for (final ResourceCollection rcol : resourceCollections) { upToDate &= check(rcol); } @@ -316,19 +312,17 @@ public class Tar extends MatchingTask { final File parent = tarFile.getParentFile(); if (parent != null && !parent.isDirectory() && !(parent.mkdirs() || parent.isDirectory())) { - throw new BuildException("Failed to create missing parent" - + " directory for " + tarFile); + throw new BuildException( + "Failed to create missing parent directory for %s", + tarFile); } log("Building tar: " + tarFile.getAbsolutePath(), Project.MSG_INFO); - TarOutputStream tOut = null; - try { - tOut = new TarOutputStream( - compression.compress( - new BufferedOutputStream( - Files.newOutputStream(tarFile.toPath()))), - encoding); + try (TarOutputStream tOut = new TarOutputStream( + compression.compress(new BufferedOutputStream( + Files.newOutputStream(tarFile.toPath()))), + encoding)) { tOut.setDebug(true); if (longFileMode.isTruncateMode()) { tOut.setLongFileMode(TarOutputStream.LONGFILE_TRUNCATE); @@ -352,8 +346,6 @@ public class Tar extends MatchingTask { } catch (final IOException ioe) { final String msg = "Problem creating TAR: " + ioe.getMessage(); throw new BuildException(msg, ioe, getLocation()); - } finally { - FileUtils.close(tOut); } } finally { filesets = savedFileSets; @@ -603,8 +595,8 @@ public class Tar extends MatchingTask { } else if (!rc.isFilesystemOnly() && !supportsNonFileResources()) { throw new BuildException("only filesystem resources are supported"); } else if (rc.isFilesystemOnly()) { - final Set<File> basedirs = new HashSet<File>(); - final Map<File, List<String>> basedirToFilesMap = new HashMap<File, List<String>>(); + final Set<File> basedirs = new HashSet<>(); + final Map<File, List<String>> basedirToFilesMap = new HashMap<>(); for (final Resource res : rc) { final FileResource r = ResourceUtils .asFileResource(res.as(FileProvider.class)); @@ -615,7 +607,7 @@ public class Tar extends MatchingTask { basedirs.add(base); List<String> files = basedirToFilesMap.get(base); if (files == null) { - files = new Vector<String>(); + files = new Vector<>(); basedirToFilesMap.put(base, files); } if (base == Copy.NULL_FILE_PLACEHOLDER) { @@ -630,9 +622,7 @@ public class Tar extends MatchingTask { upToDate &= check(tmpBase, files); } } else { // non-file resources - final Iterator<Resource> iter = rc.iterator(); - while (upToDate && iter.hasNext()) { - final Resource r = iter.next(); + for (Resource r : rc) { upToDate = archiveIsUpToDate(r); } } @@ -654,10 +644,10 @@ public class Tar extends MatchingTask { upToDate = false; } - for (int i = 0; i < files.length; ++i) { - if (tarFile.equals(new File(basedir, files[i]))) { - throw new BuildException("A tar file cannot include " - + "itself", getLocation()); + for (String file : files) { + if (tarFile.equals(new File(basedir, file))) { + throw new BuildException("A tar file cannot include itself", + getLocation()); } } return upToDate; @@ -695,20 +685,17 @@ public class Tar extends MatchingTask { afs = (ArchiveFileSet) rc; } if (afs != null && afs.size() > 1 - && afs.getFullpath(this.getProject()).length() > 0) { - throw new BuildException("fullpath attribute may only " - + "be specified for " - + "filesets that specify a " - + "single file."); + && !afs.getFullpath(this.getProject()).isEmpty()) { + throw new BuildException( + "fullpath attribute may only be specified for filesets that specify a single file."); } final TarFileSet tfs = asTarFileSet(afs); if (isFileFileSet(rc)) { final FileSet fs = (FileSet) rc; - final String[] files = getFileNames(fs); - for (int i = 0; i < files.length; i++) { - final File f = new File(fs.getDir(getProject()), files[i]); - final String name = files[i].replace(File.separatorChar, '/'); + for (String file : getFileNames(fs)) { + final File f = new File(fs.getDir(getProject()), file); + final String name = file.replace(File.separatorChar, '/'); tarFile(f, tOut, name, tfs); } } else if (rc.isFilesystemOnly()) { @@ -745,7 +732,7 @@ public class Tar extends MatchingTask { 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]; + 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); @@ -762,7 +749,7 @@ public class Tar extends MatchingTask { * @since Ant 1.7 */ protected TarFileSet asTarFileSet(final ArchiveFileSet archiveFileSet) { - TarFileSet tfs = null; + TarFileSet tfs; if (archiveFileSet != null && archiveFileSet instanceof TarFileSet) { tfs = (TarFileSet) archiveFileSet; } else { @@ -840,7 +827,6 @@ public class Tar extends MatchingTask { if (files == null) { files = getFileNames(this); } - return files; } @@ -894,7 +880,7 @@ public class Tar extends MatchingTask { POSIX = "posix", OMIT = "omit"; - private final String[] validModes = { + private static final String[] VALID_MODES = { WARN, FAIL, TRUNCATE, GNU, POSIX, OMIT }; @@ -909,7 +895,7 @@ public class Tar extends MatchingTask { */ @Override public String[] getValues() { - return validModes; + return VALID_MODES; } /** @@ -994,7 +980,7 @@ public class Tar extends MatchingTask { */ @Override public String[] getValues() { - return new String[] {NONE, GZIP, BZIP2, XZ }; + return new String[] { NONE, GZIP, BZIP2, XZ }; } /** @@ -1010,14 +996,14 @@ public class Tar extends MatchingTask { final String v = getValue(); if (GZIP.equals(v)) { return new GZIPOutputStream(ostream); - } else if (XZ.equals(v)) { + } + if (XZ.equals(v)) { return newXZOutputStream(ostream); - } else { - if (BZIP2.equals(v)) { - ostream.write('B'); - ostream.write('Z'); - return new CBZip2OutputStream(ostream); - } + } + if (BZIP2.equals(v)) { + ostream.write('B'); + ostream.write('Z'); + return new CBZip2OutputStream(ostream); } return ostream; } http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/Taskdef.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/Taskdef.java b/src/main/org/apache/tools/ant/taskdefs/Taskdef.java index a7d0b71..159c443 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Taskdef.java +++ b/src/main/org/apache/tools/ant/taskdefs/Taskdef.java @@ -43,7 +43,6 @@ public class Taskdef extends Typedef { * This sets the adapter and the adaptto classes to * TaskAdapter and Task. */ - public Taskdef() { setAdapterClass(TaskAdapter.class); setAdaptToClass(Task.class); http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/TempFile.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/TempFile.java b/src/main/org/apache/tools/ant/taskdefs/TempFile.java index 5f55a37..1247cf1 100644 --- a/src/main/org/apache/tools/ant/taskdefs/TempFile.java +++ b/src/main/org/apache/tools/ant/taskdefs/TempFile.java @@ -80,7 +80,6 @@ public class TempFile extends Task { this.property = property; } - /** * Sets the destination directory. If not set, * the basedir directory is used instead. @@ -91,7 +90,6 @@ public class TempFile extends Task { this.destDir = destDir; } - /** * Sets the optional prefix string for the temp file. * @@ -101,7 +99,6 @@ public class TempFile extends Task { this.prefix = prefix; } - /** * Sets the optional suffix string for the temp file. * @@ -149,8 +146,9 @@ public class TempFile extends Task { * * @exception BuildException if something goes wrong with the build */ + @Override public void execute() throws BuildException { - if (property == null || property.length() == 0) { + if (property == null || property.isEmpty()) { throw new BuildException("no property specified"); } if (destDir == null) { http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/Touch.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/Touch.java b/src/main/org/apache/tools/ant/taskdefs/Touch.java index c6d79b7..c2de10e 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Touch.java +++ b/src/main/org/apache/tools/ant/taskdefs/Touch.java @@ -23,6 +23,7 @@ import java.io.IOException; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.util.List; import java.util.Locale; import java.util.Vector; @@ -79,9 +80,11 @@ public class Touch extends Task { } }; + @Override public DateFormat getPrimaryFormat() { return primary.get(); } + @Override public DateFormat getFallbackFormat() { return fallback.get(); } @@ -91,7 +94,7 @@ public class Touch extends Task { private File file; private long millis = -1; private String dateTime; - private Vector filesets = new Vector(); + private List<FileSet> filesets = new Vector<>(); private Union resources; private boolean dateTimeConfigured; private boolean mkdirs; @@ -100,12 +103,6 @@ public class Touch extends Task { private DateFormatFactory dfFactory = DEFAULT_DF_FACTORY; /** - * Construct a new <code>Touch</code> task. - */ - public Touch() { - } - - /** * Sets a single source file to touch. If the file does not exist * an empty file will be created. * @param file the <code>File</code> to touch. @@ -165,9 +162,11 @@ public class Touch extends Task { */ public void setPattern(final String pattern) { dfFactory = new DateFormatFactory() { + @Override public DateFormat getPrimaryFormat() { return new SimpleDateFormat(pattern); } + @Override public DateFormat getFallbackFormat() { return null; } @@ -191,8 +190,8 @@ public class Touch extends Task { */ public void add(FileNameMapper fileNameMapper) throws BuildException { if (this.fileNameMapper != null) { - throw new BuildException("Only one mapper may be added to the " - + getTaskName() + " task."); + throw new BuildException( + "Only one mapper may be added to the %s task.", getTaskName()); } this.fileNameMapper = fileNameMapper; } @@ -231,8 +230,8 @@ public class Touch extends Task { */ protected synchronized void checkConfiguration() throws BuildException { if (file == null && resources == null) { - throw new BuildException("Specify at least one source" - + "--a file or resource collection."); + throw new BuildException( + "Specify at least one source--a file or resource collection."); } if (file != null && file.exists() && file.isDirectory()) { throw new BuildException("Use a resource collection to touch directories."); @@ -262,10 +261,9 @@ public class Touch extends Task { throw new BuildException(pe.getMessage(), pe, getLocation()); } if (workmillis < 0) { - throw new BuildException("Date of " + dateTime - + " results in negative " + "milliseconds value " - + "relative to epoch " + "(January 1, 1970, " - + "00:00:00 GMT)."); + throw new BuildException( + "Date of %s results in negative milliseconds value relative to epoch (January 1, 1970, 00:00:00 GMT).", + dateTime); } } log("Setting millis to " + workmillis + " from datetime attribute", @@ -282,6 +280,7 @@ public class Touch extends Task { * @throws BuildException * if an error occurs. */ + @Override public void execute() throws BuildException { checkConfiguration(); touch(); @@ -313,16 +312,12 @@ public class Touch extends Task { // deal with filesets in a special way since the task // originally also used the directories and Union won't return // them. - final int size = filesets.size(); - for (int i = 0; i < size; i++) { - FileSet fs = (FileSet) filesets.elementAt(i); + for (FileSet fs : filesets) { DirectoryScanner ds = fs.getDirectoryScanner(getProject()); File fromDir = fs.getDir(getProject()); - String[] srcDirs = ds.getIncludedDirectories(); - - for (int j = 0; j < srcDirs.length; j++) { - touch(new FileResource(fromDir, srcDirs[j]), defaultTimestamp); + for (String srcDir : ds.getIncludedDirectories()) { + touch(new FileResource(fromDir, srcDir), defaultTimestamp); } } } @@ -335,6 +330,7 @@ public class Touch extends Task { * @throws BuildException on error * @deprecated since 1.6.x. */ + @Deprecated protected void touch(File file) { touch(file, getTimestamp()); } @@ -378,8 +374,8 @@ public class Touch extends Task { } } if (!file.canWrite()) { - throw new BuildException("Can not change modification date of " - + "read-only file " + file); + throw new BuildException( + "Can not change modification date of read-only file %s", file); } FILE_UTILS.setFileLastModified(file, modTime); } http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/Tstamp.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/Tstamp.java b/src/main/org/apache/tools/ant/taskdefs/Tstamp.java index 805427a..0610c39 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Tstamp.java +++ b/src/main/org/apache/tools/ant/taskdefs/Tstamp.java @@ -21,8 +21,8 @@ package org.apache.tools.ant.taskdefs; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; -import java.util.Enumeration; import java.util.HashMap; +import java.util.List; import java.util.Locale; import java.util.Map; import java.util.NoSuchElementException; @@ -45,7 +45,7 @@ import org.apache.tools.ant.types.EnumeratedAttribute; */ public class Tstamp extends Task { - private Vector customFormats = new Vector(); + private List<CustomFormat> customFormats = new Vector<>(); private String prefix = ""; /** @@ -66,15 +66,12 @@ public class Tstamp extends Task { * the standard ones, to get their retaliation in early. * @throws BuildException on error. */ + @Override public void execute() throws BuildException { try { Date d = new Date(); - Enumeration i = customFormats.elements(); - while (i.hasMoreElements()) { - CustomFormat cts = (CustomFormat) i.nextElement(); - cts.execute(getProject(), d, getLocation()); - } + customFormats.forEach(cts -> cts.execute(getProject(), d, getLocation())); SimpleDateFormat dstamp = new SimpleDateFormat ("yyyyMMdd"); setProperty("DSTAMP", dstamp.format(d)); @@ -97,7 +94,7 @@ public class Tstamp extends Task { */ public CustomFormat createFormat() { CustomFormat cts = new CustomFormat(); - customFormats.addElement(cts); + customFormats.add(cts); return cts; } @@ -129,12 +126,6 @@ public class Tstamp extends Task { private int field = Calendar.DATE; /** - * Create a format - */ - public CustomFormat() { - } - - /** * The property to receive the date/time string in the given pattern * @param propertyName the name of the property. */ @@ -211,9 +202,9 @@ public class Tstamp extends Task { * encapsulate operations on the unit in its own * class. */ + @Deprecated public void setUnit(String unit) { - log("DEPRECATED - The setUnit(String) method has been deprecated." - + " Use setUnit(Tstamp.Unit) instead."); + log("DEPRECATED - The setUnit(String) method has been deprecated. Use setUnit(Tstamp.Unit) instead."); Unit u = new Unit(); u.setValue(unit); field = u.getCalendarField(); @@ -305,19 +296,19 @@ public class Tstamp extends Task { YEAR }; - private Map calendarFields = new HashMap(); + private Map<String, Integer> calendarFields = new HashMap<>(); /** Constructor for Unit enumerated type. */ public Unit() { calendarFields.put(MILLISECOND, - new Integer(Calendar.MILLISECOND)); - calendarFields.put(SECOND, new Integer(Calendar.SECOND)); - calendarFields.put(MINUTE, new Integer(Calendar.MINUTE)); - calendarFields.put(HOUR, new Integer(Calendar.HOUR_OF_DAY)); - calendarFields.put(DAY, new Integer(Calendar.DATE)); - calendarFields.put(WEEK, new Integer(Calendar.WEEK_OF_YEAR)); - calendarFields.put(MONTH, new Integer(Calendar.MONTH)); - calendarFields.put(YEAR, new Integer(Calendar.YEAR)); + Integer.valueOf(Calendar.MILLISECOND)); + calendarFields.put(SECOND, Integer.valueOf(Calendar.SECOND)); + calendarFields.put(MINUTE, Integer.valueOf(Calendar.MINUTE)); + calendarFields.put(HOUR, Integer.valueOf(Calendar.HOUR_OF_DAY)); + calendarFields.put(DAY, Integer.valueOf(Calendar.DATE)); + calendarFields.put(WEEK, Integer.valueOf(Calendar.WEEK_OF_YEAR)); + calendarFields.put(MONTH, Integer.valueOf(Calendar.MONTH)); + calendarFields.put(YEAR, Integer.valueOf(Calendar.YEAR)); } /** @@ -326,14 +317,14 @@ public class Tstamp extends Task { */ public int getCalendarField() { String key = getValue().toLowerCase(Locale.ENGLISH); - Integer i = (Integer) calendarFields.get(key); - return i.intValue(); + return calendarFields.get(key).intValue(); } /** * Get the valid values. * @return the value values. */ + @Override public String[] getValues() { return UNITS; } http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/Typedef.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/Typedef.java b/src/main/org/apache/tools/ant/taskdefs/Typedef.java index 87276e2..069cf53 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Typedef.java +++ b/src/main/org/apache/tools/ant/taskdefs/Typedef.java @@ -18,8 +18,6 @@ package org.apache.tools.ant.taskdefs; - - /** * * Adds a data type definition to the current project. http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/Unpack.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/Unpack.java b/src/main/org/apache/tools/ant/taskdefs/Unpack.java index ccc4577..88ecb8c 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Unpack.java +++ b/src/main/org/apache/tools/ant/taskdefs/Unpack.java @@ -50,6 +50,7 @@ public abstract class Unpack extends Task { * @ant.attribute ignore="true" * @param src a <code>String</code> value */ + @Deprecated public void setSrc(String src) { log("DEPRECATED - The setSrc(String) method has been deprecated." + " Use setSrc(File) instead."); @@ -65,6 +66,7 @@ public abstract class Unpack extends Task { * @ant.attribute ignore="true" * @param dest a <code>String</code> value */ + @Deprecated public void setDest(String dest) { log("DEPRECATED - The setDest(String) method has been deprecated." + " Use setDest(File) instead."); @@ -85,22 +87,20 @@ public abstract class Unpack extends Task { */ public void setSrcResource(Resource src) { if (!src.isExists()) { - throw new BuildException( - "the archive " + src.getName() + " doesn't exist"); + throw new BuildException("the archive %s doesn't exist", + src.getName()); } if (src.isDirectory()) { - throw new BuildException( - "the archive " + src.getName() + " can't be a directory"); + throw new BuildException("the archive %s can't be a directory", + src.getName()); } FileProvider fp = src.as(FileProvider.class); if (fp != null) { source = fp.getFile(); } else if (!supportsNonFileResources()) { throw new BuildException( - "The source " + src.getName() - + " is not a FileSystem " - + "Only FileSystem resources are" - + " supported."); + "The source %s is not a FileSystem Only FileSystem resources are supported.", + src.getName()); } srcResource = src; } @@ -111,8 +111,8 @@ public abstract class Unpack extends Task { */ public void addConfigured(ResourceCollection a) { if (a.size() != 1) { - throw new BuildException("only single argument resource collections" - + " are supported as archives"); + throw new BuildException( + "only single argument resource collections are supported as archives"); } setSrcResource(a.iterator().next()); } @@ -163,6 +163,7 @@ public abstract class Unpack extends Task { * Execute the task. * @throws BuildException on error */ + @Override public void execute() throws BuildException { File savedDest = dest; // may be altered in validate try { @@ -199,7 +200,7 @@ public abstract class Unpack extends Task { private String getLastNamePart(Resource r) { String n = r.getName(); - int idx = n.lastIndexOf("/"); + int idx = n.lastIndexOf('/'); return idx < 0 ? n : n.substring(idx + 1); } } http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/Untar.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/Untar.java b/src/main/org/apache/tools/ant/taskdefs/Untar.java index 430aa54..fa26c35 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Untar.java +++ b/src/main/org/apache/tools/ant/taskdefs/Untar.java @@ -37,8 +37,6 @@ import org.apache.tools.bzip2.CBZip2InputStream; import org.apache.tools.tar.TarEntry; import org.apache.tools.tar.TarInputStream; - - /** * Untar a file. * <p>PatternSets are used to select files to extract @@ -86,33 +84,32 @@ public class Untar extends Expand { * * @since Ant 1.8.0 */ + @Override public void setScanForUnicodeExtraFields(boolean b) { - throw new BuildException("The " + getTaskName() - + " task doesn't support the encoding" - + " attribute", getLocation()); + throw new BuildException( + "The " + getTaskName() + + " task doesn't support the encoding attribute", + getLocation()); } /** * @see Expand#expandFile(FileUtils, File, File) */ /** {@inheritDoc} */ + @Override protected void expandFile(FileUtils fileUtils, File srcF, File dir) { - InputStream fis = null; if (!srcF.exists()) { throw new BuildException("Unable to untar " + srcF + " as the file does not exist", getLocation()); } - try { - fis = Files.newInputStream(srcF.toPath()); + try (InputStream fis = Files.newInputStream(srcF.toPath())) { expandStream(srcF.getPath(), fis, dir); } catch (IOException ioe) { throw new BuildException("Error while expanding " + srcF.getPath() + "\n" + ioe.toString(), ioe, getLocation()); - } finally { - FileUtils.close(fis); } } @@ -123,6 +120,7 @@ public class Untar extends Expand { * @param dir the destination directory * @since Ant 1.7 */ + @Override protected void expandResource(Resource srcR, File dir) { if (!srcR.isExists()) { throw new BuildException("Unable to untar " @@ -131,15 +129,11 @@ public class Untar extends Expand { getLocation()); } - InputStream i = null; - try { - i = srcR.getInputStream(); + try (InputStream i = srcR.getInputStream()) { expandStream(srcR.getName(), i, dir); } catch (IOException ioe) { throw new BuildException("Error while expanding " + srcR.getName(), ioe, getLocation()); - } finally { - FileUtils.close(i); } } @@ -148,16 +142,13 @@ public class Untar extends Expand { */ private void expandStream(String name, InputStream stream, File dir) throws IOException { - TarInputStream tis = null; - try { - tis = - new TarInputStream(compression.decompress(name, - new BufferedInputStream(stream)), - getEncoding()); + try (TarInputStream tis = new TarInputStream( + compression.decompress(name, new BufferedInputStream(stream)), + getEncoding())) { log("Expanding: " + name + " into " + dir, Project.MSG_INFO); - TarEntry te = null; boolean empty = true; FileNameMapper mapper = getMapper(); + TarEntry te; while ((te = tis.getNextEntry()) != null) { empty = false; extractFile(FileUtils.getFileUtils(), null, dir, tis, @@ -165,11 +156,9 @@ public class Untar extends Expand { te.isDirectory(), mapper); } if (empty && getFailOnEmptyArchive()) { - throw new BuildException("archive '" + name + "' is empty"); + throw new BuildException("archive '%s' is empty", name); } log("expand complete", Project.MSG_VERBOSE); - } finally { - FileUtils.close(tis); } } @@ -213,8 +202,9 @@ public class Untar extends Expand { * * @return valid values */ + @Override public String[] getValues() { - return new String[] {NONE, GZIP, BZIP2, XZ}; + return new String[] { NONE, GZIP, BZIP2, XZ }; } /** @@ -234,19 +224,18 @@ public class Untar extends Expand { final String v = getValue(); if (GZIP.equals(v)) { return new GZIPInputStream(istream); - } else if (XZ.equals(v)) { + } + if (XZ.equals(v)) { return newXZInputStream(istream); - } else { - if (BZIP2.equals(v)) { - final char[] magic = new char[] {'B', 'Z'}; - for (int i = 0; i < magic.length; i++) { - if (istream.read() != magic[i]) { - throw new BuildException( - "Invalid bz2 file." + name); - } + } + if (BZIP2.equals(v)) { + final char[] magic = new char[] { 'B', 'Z' }; + for (int i = 0; i < magic.length; i++) { + if (istream.read() != magic[i]) { + throw new BuildException("Invalid bz2 file." + name); } - return new CBZip2InputStream(istream); } + return new CBZip2InputStream(istream); } return istream; } http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/UpToDate.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/UpToDate.java b/src/main/org/apache/tools/ant/taskdefs/UpToDate.java index e5c85ce..03babd9 100644 --- a/src/main/org/apache/tools/ant/taskdefs/UpToDate.java +++ b/src/main/org/apache/tools/ant/taskdefs/UpToDate.java @@ -19,7 +19,8 @@ package org.apache.tools.ant.taskdefs; import java.io.File; -import java.util.Enumeration; +import java.util.Iterator; +import java.util.List; import java.util.Vector; import org.apache.tools.ant.BuildException; @@ -51,7 +52,7 @@ public class UpToDate extends Task implements Condition { private String value; private File sourceFile; private File targetFile; - private Vector sourceFileSets = new Vector(); + private List<FileSet> sourceFileSets = new Vector<>(); private Union sourceResources = new Union(); // CheckStyle:VisibilityModifier OFF - bc @@ -110,7 +111,7 @@ public class UpToDate extends Task implements Condition { * @param fs the source files */ public void addSrcfiles(final FileSet fs) { - sourceFileSets.addElement(fs); + sourceFileSets.add(fs); } /** @@ -150,24 +151,23 @@ public class UpToDate extends Task implements Condition { * see if the target(s) is/are up-to-date. * @return true if the target(s) is/are up-to-date */ + @Override public boolean eval() { - if (sourceFileSets.size() == 0 && sourceResources.size() == 0 + if (sourceFileSets.isEmpty() && sourceResources.isEmpty() && sourceFile == null) { - throw new BuildException("At least one srcfile or a nested " - + "<srcfiles> or <srcresources> element " - + "must be set."); + throw new BuildException( + "At least one srcfile or a nested <srcfiles> or <srcresources> element must be set."); } - if ((sourceFileSets.size() > 0 || sourceResources.size() > 0) + if (!(sourceFileSets.isEmpty() && sourceResources.isEmpty()) && sourceFile != null) { - throw new BuildException("Cannot specify both the srcfile " - + "attribute and a nested <srcfiles> " - + "or <srcresources> element."); + throw new BuildException( + "Cannot specify both the srcfile attribute and a nested <srcfiles> or <srcresources> element."); } if (targetFile == null && mapperElement == null) { - throw new BuildException("The targetfile attribute or a nested " - + "mapper element must be set."); + throw new BuildException( + "The targetfile attribute or a nested mapper element must be set."); } // if the target file is not there, then it can't be up-to-date @@ -179,8 +179,8 @@ public class UpToDate extends Task implements Condition { // if the source file isn't there, throw an exception if (sourceFile != null && !sourceFile.exists()) { - throw new BuildException(sourceFile.getAbsolutePath() - + " not found."); + throw new BuildException("%s not found.", + sourceFile.getAbsolutePath()); } boolean upToDate = true; @@ -204,12 +204,12 @@ public class UpToDate extends Task implements Condition { // reasons. If we use the code for union below, we'll always // scan all filesets, even if we know the target is out of // date after the first test. - Enumeration e = sourceFileSets.elements(); - while (upToDate && e.hasMoreElements()) { - FileSet fs = (FileSet) e.nextElement(); + + Iterator<FileSet> iter = sourceFileSets.iterator(); + while (upToDate && iter.hasNext()) { + FileSet fs = iter.next(); DirectoryScanner ds = fs.getDirectoryScanner(getProject()); - upToDate = scanDir(fs.getDir(getProject()), - ds.getIncludedFiles()); + upToDate = scanDir(fs.getDir(getProject()), ds.getIncludedFiles()); } if (upToDate) { @@ -223,12 +223,12 @@ public class UpToDate extends Task implements Condition { return upToDate; } - /** * Sets property to true if target file(s) have a more recent timestamp * than (each of) the corresponding source file(s). * @throws BuildException on error */ + @Override public void execute() throws BuildException { if (property == null) { throw new BuildException("property attribute is required.", @@ -264,14 +264,11 @@ public class UpToDate extends Task implements Condition { } private FileNameMapper getMapper() { - FileNameMapper mapper = null; if (mapperElement == null) { MergingMapper mm = new MergingMapper(); mm.setTo(targetFile.getAbsolutePath()); - mapper = mm; - } else { - mapper = mapperElement.getImplementation(); + return mm; } - return mapper; + return mapperElement.getImplementation(); } } http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/VerifyJar.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/VerifyJar.java b/src/main/org/apache/tools/ant/taskdefs/VerifyJar.java index 4ab2142..5f9c8f3 100644 --- a/src/main/org/apache/tools/ant/taskdefs/VerifyJar.java +++ b/src/main/org/apache/tools/ant/taskdefs/VerifyJar.java @@ -45,6 +45,9 @@ public class VerifyJar extends AbstractJarSignerTask { */ public static final String ERROR_NO_FILE = "Not found :"; + /** Error output if there is a failure to verify the jar. */ + public static final String ERROR_NO_VERIFY = "Failed to verify "; + /** * The string we look for in the text to indicate direct verification */ @@ -55,8 +58,6 @@ public class VerifyJar extends AbstractJarSignerTask { */ private boolean certificates = false; private BufferingOutputFilter outputCache = new BufferingOutputFilter(); - /** Error output if there is a failure to verify the jar. */ - public static final String ERROR_NO_VERIFY = "Failed to verify "; /** * Ask for certificate information to be printed @@ -70,6 +71,7 @@ public class VerifyJar extends AbstractJarSignerTask { * verify our jar files * @throws BuildException on error. */ + @Override public void execute() throws BuildException { //validation logic final boolean hasJar = jar != null; @@ -92,11 +94,9 @@ public class VerifyJar extends AbstractJarSignerTask { FileProvider fr = r.as(FileProvider.class); verifyOneJar(fr.getFile()); } - } finally { endExecution(); } - } /** @@ -135,8 +135,8 @@ public class VerifyJar extends AbstractJarSignerTask { //deal with jdk1.4.2 bug: if (ex != null) { if (results.indexOf("zip file closed") >= 0) { - log("You are running " + JARSIGNER_COMMAND + " against a JVM with" - + " a known bug that manifests as an IllegalStateException.", + log("You are running " + JARSIGNER_COMMAND + + " against a JVM with a known bug that manifests as an IllegalStateException.", Project.MSG_WARN); } else { throw ex; @@ -154,11 +154,13 @@ public class VerifyJar extends AbstractJarSignerTask { private BufferingOutputFilterReader buffer; + @Override public Reader chain(Reader rdr) { buffer = new BufferingOutputFilterReader(rdr); return buffer; } + @Override public String toString() { return buffer.toString(); } @@ -183,6 +185,7 @@ public class VerifyJar extends AbstractJarSignerTask { this.next = next; } + @Override public int read(char[] cbuf, int off, int len) throws IOException { //hand down int result = next.read(cbuf, off, len); @@ -192,10 +195,12 @@ public class VerifyJar extends AbstractJarSignerTask { return result; } + @Override public void close() throws IOException { next.close(); } + @Override public String toString() { return buffer.toString(); } http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/WaitFor.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/WaitFor.java b/src/main/org/apache/tools/ant/taskdefs/WaitFor.java index d23beab..4bcc0e9 100644 --- a/src/main/org/apache/tools/ant/taskdefs/WaitFor.java +++ b/src/main/org/apache/tools/ant/taskdefs/WaitFor.java @@ -89,7 +89,6 @@ public class WaitFor extends ConditionBase { super("waitfor"); } - /** * Constructor that takes the name of the task in the task name. * @@ -108,7 +107,6 @@ public class WaitFor extends ConditionBase { maxWait = time; } - /** * Set the max wait time unit * @param unit an enumerated <code>Unit</code> value @@ -117,8 +115,6 @@ public class WaitFor extends ConditionBase { maxWaitMultiplier = unit.getMultiplier(); } - - /** * Set the time between each check * @param time a <code>long</code> value @@ -150,15 +146,15 @@ public class WaitFor extends ConditionBase { */ public void execute() throws BuildException { if (countConditions() > 1) { - throw new BuildException("You must not nest more than one " - + "condition into " - + getTaskName()); + throw new BuildException( + "You must not nest more than one condition into %s", + getTaskName()); } if (countConditions() < 1) { - throw new BuildException("You must nest a condition into " - + getTaskName()); + throw new BuildException("You must nest a condition into %s", + getTaskName()); } - Condition c = (Condition) getConditions().nextElement(); + Condition c = getConditions().nextElement(); try { long maxWaitMillis = calculateMaxWaitMillis(); long checkEveryMillis = calculateCheckEveryMillis(); @@ -244,16 +240,16 @@ public class WaitFor extends ConditionBase { MILLISECOND, SECOND, MINUTE, HOUR, DAY, WEEK }; - private Map timeTable = new HashMap(); + private Map<String, Long> timeTable = new HashMap<>(); /** Constructor the Unit enumerated type. */ public Unit() { - timeTable.put(MILLISECOND, new Long(1L)); - timeTable.put(SECOND, new Long(ONE_SECOND)); - timeTable.put(MINUTE, new Long(ONE_MINUTE)); - timeTable.put(HOUR, new Long(ONE_HOUR)); - timeTable.put(DAY, new Long(ONE_DAY)); - timeTable.put(WEEK, new Long(ONE_WEEK)); + timeTable.put(MILLISECOND, Long.valueOf(1L)); + timeTable.put(SECOND, Long.valueOf(ONE_SECOND)); + timeTable.put(MINUTE, Long.valueOf(ONE_MINUTE)); + timeTable.put(HOUR, Long.valueOf(ONE_HOUR)); + timeTable.put(DAY, Long.valueOf(ONE_DAY)); + timeTable.put(WEEK, Long.valueOf(ONE_WEEK)); } /** @@ -262,14 +258,14 @@ public class WaitFor extends ConditionBase { */ public long getMultiplier() { String key = getValue().toLowerCase(Locale.ENGLISH); - Long l = (Long) timeTable.get(key); - return l.longValue(); + return timeTable.get(key).longValue(); } /** * @see EnumeratedAttribute#getValues() */ /** {@inheritDoc} */ + @Override public String[] getValues() { return UNITS; } http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/War.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/War.java b/src/main/org/apache/tools/ant/taskdefs/War.java index 7daf08e..146d325 100644 --- a/src/main/org/apache/tools/ant/taskdefs/War.java +++ b/src/main/org/apache/tools/ant/taskdefs/War.java @@ -27,7 +27,6 @@ import org.apache.tools.ant.types.ZipFileSet; import org.apache.tools.ant.util.FileUtils; import org.apache.tools.zip.ZipOutputStream; - /** * <p>An extension of <jar> to create a WAR archive. * Contains special treatment for files that should end up in the @@ -49,6 +48,10 @@ import org.apache.tools.zip.ZipOutputStream; */ public class War extends Jar { + private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); + /** path to web.xml file */ + private static final String XML_DESCRIPTOR_PATH = "WEB-INF/web.xml"; + /** * our web.xml deployment descriptor */ @@ -60,10 +63,6 @@ public class War extends Jar { private boolean needxmlfile = true; private File addedWebXmlFile; - private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); - /** path to web.xml file */ - private static final String XML_DESCRIPTOR_PATH = "WEB-INF/web.xml"; - /** Constructor for the War Task. */ public War() { super(); @@ -92,9 +91,8 @@ public class War extends Jar { public void setWebxml(File descr) { deploymentDescriptor = descr; if (!deploymentDescriptor.exists()) { - throw new BuildException("Deployment descriptor: " - + deploymentDescriptor - + " does not exist."); + throw new BuildException("Deployment descriptor: does not exist.", + deploymentDescriptor); } // Create a ZipFileSet for this file, and pass it up. @@ -104,7 +102,6 @@ public class War extends Jar { super.addFileset(fs); } - /** * Set the policy on the web.xml file, that is, whether or not it is needed * @param needxmlfile whether a web.xml file is needed. Default: true @@ -117,7 +114,6 @@ public class War extends Jar { * add files under WEB-INF/lib/ * @param fs the zip file set to add */ - public void addLib(ZipFileSet fs) { // We just set the prefix for this fileset, and pass it up. fs.setPrefix("WEB-INF/lib/"); @@ -190,13 +186,10 @@ public class War extends Jar { //check to see if we warn or not if (!FILE_UTILS.fileNameEquals(addedWebXmlFile, file)) { logWhenWriting("Warning: selected " + archiveType - + " files include a second " - + XML_DESCRIPTOR_PATH - + " which will be ignored.\n" - + "The duplicate entry is at " + file + '\n' - + "The file that will be used is " - + addedWebXmlFile, - Project.MSG_WARN); + + " files include a second " + XML_DESCRIPTOR_PATH + + " which will be ignored.\nThe duplicate entry is at " + + file + "\nThe file that will be used is " + + addedWebXmlFile, Project.MSG_WARN); } } else { //no added file, yet @@ -212,7 +205,6 @@ public class War extends Jar { } } - /** * Make sure we don't think we already have a web.xml next time this task * gets executed. @@ -224,8 +216,8 @@ public class War extends Jar { && needxmlfile && !isInUpdateMode() && hasUpdatedFile()) { - throw new BuildException("No WEB-INF/web.xml file was added.\n" - + "If this is your intent, set needxmlfile='false' "); + throw new BuildException( + "No WEB-INF/web.xml file was added.\nIf this is your intent, set needxmlfile='false' "); } addedWebXmlFile = null; super.cleanUp(); http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/WhichResource.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/WhichResource.java b/src/main/org/apache/tools/ant/taskdefs/WhichResource.java index d19918a..73ad779 100644 --- a/src/main/org/apache/tools/ant/taskdefs/WhichResource.java +++ b/src/main/org/apache/tools/ant/taskdefs/WhichResource.java @@ -105,14 +105,11 @@ public class WhichResource extends Task { setcount++; } - if (setcount == 0) { - throw new BuildException("One of classname or resource must" - + " be specified"); + throw new BuildException("One of classname or resource must be specified"); } if (setcount > 1) { - throw new BuildException("Only one of classname or resource can" - + " be specified"); + throw new BuildException("Only one of classname or resource can be specified"); } if (property == null) { throw new BuildException("No property defined"); @@ -123,6 +120,7 @@ public class WhichResource extends Task { * execute it * @throws BuildException on error */ + @Override public void execute() throws BuildException { validate(); if (classpath != null) { @@ -154,8 +152,7 @@ public class WhichResource extends Task { } log("Searching for " + resource, Project.MSG_VERBOSE); - URL url; - url = loader.getResource(resource); + URL url = loader.getResource(resource); if (url != null) { //set the property loc = url.toExternalForm();
