http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/optional/extension/JarLibDisplayTask.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/extension/JarLibDisplayTask.java b/src/main/org/apache/tools/ant/taskdefs/optional/extension/JarLibDisplayTask.java index da12cd0..0f31657 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/extension/JarLibDisplayTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/extension/JarLibDisplayTask.java @@ -18,7 +18,7 @@ package org.apache.tools.ant.taskdefs.optional.extension; import java.io.File; -import java.util.Iterator; +import java.util.List; import java.util.Vector; import org.apache.tools.ant.BuildException; @@ -49,7 +49,7 @@ public class JarLibDisplayTask extends Task { * Filesets specifying all the librarys * to display information about. */ - private final Vector libraryFileSets = new Vector(); + private final List<FileSet> libraryFileSets = new Vector<>(); /** * The JAR library to display information for. @@ -66,7 +66,7 @@ public class JarLibDisplayTask extends Task { * @param fileSet a set of files about which library data will be displayed. */ public void addFileset(final FileSet fileSet) { - libraryFileSets.addElement(fileSet); + libraryFileSets.add(fileSet); } /** @@ -74,26 +74,23 @@ public class JarLibDisplayTask extends Task { * * @throws BuildException if the task fails. */ + @Override public void execute() throws BuildException { validate(); final LibraryDisplayer displayer = new LibraryDisplayer(); // Check if list of files to check has been specified - if (!libraryFileSets.isEmpty()) { - final Iterator iterator = libraryFileSets.iterator(); - while (iterator.hasNext()) { - final FileSet fileSet = (FileSet) iterator.next(); - final DirectoryScanner scanner - = fileSet.getDirectoryScanner(getProject()); + if (libraryFileSets.isEmpty()) { + displayer.displayLibrary(libraryFile); + } else { + for (FileSet fileSet : libraryFileSets) { + final DirectoryScanner scanner = + fileSet.getDirectoryScanner(getProject()); final File basedir = scanner.getBasedir(); - final String[] files = scanner.getIncludedFiles(); - for (int i = 0; i < files.length; i++) { - final File file = new File(basedir, files[ i ]); - displayer.displayLibrary(file); + for (String filename : scanner.getIncludedFiles()) { + displayer.displayLibrary(new File(basedir, filename)); } } - } else { - displayer.displayLibrary(libraryFile); } } @@ -103,17 +100,14 @@ public class JarLibDisplayTask extends Task { * @throws BuildException if invalid parameters found */ private void validate() throws BuildException { - if (null == libraryFile && libraryFileSets.isEmpty()) { - final String message = "File attribute not specified."; - throw new BuildException(message); - } - if (null != libraryFile && !libraryFile.exists()) { - final String message = "File '" + libraryFile + "' does not exist."; - throw new BuildException(message); - } - if (null != libraryFile && !libraryFile.isFile()) { - final String message = "\'" + libraryFile + "\' is not a file."; - throw new BuildException(message); + if (null == libraryFile) { + if (libraryFileSets.isEmpty()) { + throw new BuildException("File attribute not specified."); + } + } else if (!libraryFile.exists()) { + throw new BuildException("File '%s' does not exist.", libraryFile); + } else if (!libraryFile.isFile()) { + throw new BuildException("'%s' is not a file.", libraryFile); } } }
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/optional/extension/JarLibManifestTask.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/extension/JarLibManifestTask.java b/src/main/org/apache/tools/ant/taskdefs/optional/extension/JarLibManifestTask.java index a5105e2..6e53294 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/extension/JarLibManifestTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/extension/JarLibManifestTask.java @@ -22,15 +22,17 @@ import java.io.IOException; import java.io.OutputStream; import java.nio.file.Files; import java.util.ArrayList; -import java.util.Iterator; +import java.util.List; import java.util.jar.Attributes; import java.util.jar.Manifest; +import java.util.stream.Collectors; +import java.util.stream.IntStream; +import java.util.stream.Stream; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.MagicNames; import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; -import org.apache.tools.ant.util.FileUtils; /** * Generates a manifest that declares all the dependencies. @@ -72,19 +74,19 @@ public final class JarLibManifestTask extends Task { * ExtensionAdapter objects representing * dependencies required by library. */ - private final ArrayList dependencies = new ArrayList(); + private final List<ExtensionSet> dependencies = new ArrayList<>(); /** * ExtensionAdapter objects representing optional * dependencies required by library. */ - private final ArrayList optionals = new ArrayList(); + private final List<ExtensionSet> optionals = new ArrayList<>(); /** * Extra attributes the user specifies for main section * in manifest. */ - private final ArrayList extraAttributes = new ArrayList(); + private final List<ExtraAttribute> extraAttributes = new ArrayList<>(); /** * The location where generated manifest is placed. @@ -106,7 +108,8 @@ public final class JarLibManifestTask extends Task { public void addConfiguredExtension(final ExtensionAdapter extensionAdapter) throws BuildException { if (null != extension) { - throw new BuildException("Can not have multiple extensions defined in one library."); + throw new BuildException( + "Can not have multiple extensions defined in one library."); } extension = extensionAdapter.toExtension(); } @@ -143,6 +146,7 @@ public final class JarLibManifestTask extends Task { * * @throws BuildException if the task fails. */ + @Override public void execute() throws BuildException { validate(); @@ -160,13 +164,13 @@ public final class JarLibManifestTask extends Task { } //Add all the dependency data to manifest for dependencies - final ArrayList depends = toExtensions(dependencies); + final List<Extension> depends = toExtensions(dependencies); appendExtensionList(attributes, Extension.EXTENSION_LIST, "lib", depends.size()); appendLibraryList(attributes, "lib", depends); // Add all the dependency data to manifest for "optional" //dependencies - final ArrayList option = toExtensions(optionals); + final List<Extension> option = toExtensions(optionals); appendExtensionList(attributes, Extension.OPTIONAL_EXTENSION_LIST, "opt", option.size()); appendLibraryList(attributes, "opt", option); @@ -188,7 +192,7 @@ public final class JarLibManifestTask extends Task { throw new BuildException("Destfile attribute not specified."); } if (destFile.exists() && !destFile.isFile()) { - throw new BuildException(destFile + " is not a file."); + throw new BuildException("%s is not a file.", destFile); } } @@ -199,12 +203,8 @@ public final class JarLibManifestTask extends Task { * attributes to */ private void appendExtraAttributes(final Attributes attributes) { - final Iterator iterator = extraAttributes.iterator(); - while (iterator.hasNext()) { - final ExtraAttribute attribute = - (ExtraAttribute) iterator.next(); - attributes.putValue(attribute.getName(), - attribute.getValue()); + for (ExtraAttribute attribute : extraAttributes) { + attributes.putValue(attribute.getName(), attribute.getValue()); } } @@ -215,13 +215,9 @@ public final class JarLibManifestTask extends Task { * @throws IOException if error writing file */ private void writeManifest(final Manifest manifest) throws IOException { - OutputStream output = null; - try { - output = Files.newOutputStream(destFile.toPath()); + try (OutputStream output = Files.newOutputStream(destFile.toPath())) { manifest.write(output); output.flush(); - } finally { - FileUtils.close(output); } } @@ -237,12 +233,11 @@ public final class JarLibManifestTask extends Task { * @throws BuildException if an error occurs */ private void appendLibraryList(final Attributes attributes, final String listPrefix, - final ArrayList extensions) throws BuildException { + final List<Extension> extensions) throws BuildException { final int size = extensions.size(); for (int i = 0; i < size; i++) { - final Extension ext = (Extension) extensions.get(i); - final String prefix = listPrefix + i + "-"; - Extension.addExtension(ext, prefix, attributes); + Extension.addExtension(extensions.get(i), listPrefix + i + "-", + attributes); } } @@ -259,15 +254,10 @@ public final class JarLibManifestTask extends Task { */ private void appendExtensionList(final Attributes attributes, final Attributes.Name extensionKey, final String listPrefix, final int size) { - final StringBuffer sb = new StringBuffer(); - for (int i = 0; i < size; i++) { - sb.append(listPrefix); - sb.append(i); - sb.append(' '); - } //add in something like //"Extension-List: javahelp java3d" - attributes.put(extensionKey, sb.toString()); + attributes.put(extensionKey, IntStream.range(0, size) + .mapToObj(i -> listPrefix + i).collect(Collectors.joining(" "))); } /** @@ -276,17 +266,10 @@ public final class JarLibManifestTask extends Task { * @param extensionSets the list of ExtensionSets to add to list * @throws BuildException if an error occurs */ - private ArrayList toExtensions(final ArrayList extensionSets) throws BuildException { - final ArrayList results = new ArrayList(); - - final int size = extensionSets.size(); - for (int i = 0; i < size; i++) { - final ExtensionSet set = (ExtensionSet) extensionSets.get(i); - final Extension[] extensions = set.toExtensions(getProject()); - for (int j = 0; j < extensions.length; j++) { - results.add(extensions[ j ]); - } - } - return results; + private List<Extension> toExtensions(final List<ExtensionSet> extensionSets) + throws BuildException { + final Project prj = getProject(); + return extensionSets.stream().map(xset -> xset.toExtensions(prj)) + .flatMap(Stream::of).collect(Collectors.toList()); } } http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/optional/extension/JarLibResolveTask.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/extension/JarLibResolveTask.java b/src/main/org/apache/tools/ant/taskdefs/optional/extension/JarLibResolveTask.java index c13194f..5cdc32f 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/extension/JarLibResolveTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/extension/JarLibResolveTask.java @@ -19,6 +19,7 @@ package org.apache.tools.ant.taskdefs.optional.extension; import java.io.File; import java.util.ArrayList; +import java.util.List; import java.util.jar.Manifest; import org.apache.tools.ant.BuildException; @@ -49,7 +50,7 @@ public class JarLibResolveTask extends Task { /** * The set of resolvers to use to attempt to locate library. */ - private final ArrayList resolvers = new ArrayList(); + private final List<ExtensionResolver> resolvers = new ArrayList<>(); /** * Flag to indicate that you should check that @@ -132,9 +133,8 @@ public class JarLibResolveTask extends Task { */ public void addConfiguredExtension(final ExtensionAdapter extension) { if (null != requiredExtension) { - final String message = "Can not specify extension to " - + "resolve multiple times."; - throw new BuildException(message); + throw new BuildException( + "Can not specify extension to resolve multiple times."); } requiredExtension = extension.toExtension(); } @@ -144,6 +144,7 @@ public class JarLibResolveTask extends Task { * * @throws BuildException if the task fails. */ + @Override public void execute() throws BuildException { validate(); @@ -160,28 +161,26 @@ public class JarLibResolveTask extends Task { return; } - final int size = resolvers.size(); - for (int i = 0; i < size; i++) { - final ExtensionResolver resolver = - (ExtensionResolver) resolvers.get(i); - + for (ExtensionResolver resolver : resolvers) { getProject().log("Searching for extension using Resolver:" + resolver, Project.MSG_VERBOSE); - try { - final File file = resolver.resolve(requiredExtension, getProject()); + final File file = + resolver.resolve(requiredExtension, getProject()); try { checkExtension(file); return; } catch (final BuildException be) { - final String message = "File " + file + " returned by " - + "resolver failed to satisfy extension due to: " + be.getMessage(); - getProject().log(message, Project.MSG_WARN); + getProject().log("File " + file + " returned by " + + "resolver failed to satisfy extension due to: " + + be.getMessage(), Project.MSG_WARN); } } catch (final BuildException be) { - final String message = "Failed to resolve extension to file " + "using resolver " - + resolver + " due to: " + be; - getProject().log(message, Project.MSG_WARN); + getProject() + .log( + "Failed to resolve extension to file " + + "using resolver " + resolver + " due to: " + be, + Project.MSG_WARN); } } missingExtension(); @@ -210,10 +209,10 @@ public class JarLibResolveTask extends Task { */ private void checkExtension(final File file) { if (!file.exists()) { - throw new BuildException("File " + file + " does not exist"); + throw new BuildException("File %s does not exist", file); } if (!file.isFile()) { - throw new BuildException("File " + file + " is not a file"); + throw new BuildException("File %s is not a file", file); } if (!checkExtension) { getProject().log("Setting property to " + file @@ -223,9 +222,7 @@ public class JarLibResolveTask extends Task { getProject().log("Checking file " + file + " to see if it satisfies extension", Project.MSG_VERBOSE); final Manifest manifest = ExtensionUtil.getManifest(file); - final Extension[] extensions = Extension.getAvailable(manifest); - for (int i = 0; i < extensions.length; i++) { - final Extension extension = extensions[ i ]; + for (final Extension extension : Extension.getAvailable(manifest)) { if (extension.isCompatibleWith(requiredExtension)) { setLibraryProperty(file); return; @@ -256,13 +253,10 @@ public class JarLibResolveTask extends Task { */ private void validate() throws BuildException { if (null == propertyName) { - final String message = "Property attribute must be specified."; - throw new BuildException(message); + throw new BuildException("Property attribute must be specified."); } - if (null == requiredExtension) { - final String message = "Extension element must be specified."; - throw new BuildException(message); + throw new BuildException("Extension element must be specified."); } } } http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/optional/extension/LibFileSet.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/extension/LibFileSet.java b/src/main/org/apache/tools/ant/taskdefs/optional/extension/LibFileSet.java index b21719e..bade00f 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/extension/LibFileSet.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/extension/LibFileSet.java @@ -25,8 +25,7 @@ import org.apache.tools.ant.types.FileSet; * how they are to be handled when building manifests. * */ -public class LibFileSet - extends FileSet { +public class LibFileSet extends FileSet { /** * Flag indicating whether should include the * "Implementation-URL" attribute in manifest. http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/optional/extension/LibraryDisplayer.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/extension/LibraryDisplayer.java b/src/main/org/apache/tools/ant/taskdefs/optional/extension/LibraryDisplayer.java index b0ee4f8..d3eb056 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/extension/LibraryDisplayer.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/extension/LibraryDisplayer.java @@ -20,6 +20,8 @@ package org.apache.tools.ant.taskdefs.optional.extension; import java.io.File; import java.text.ParseException; import java.util.jar.Manifest; +import java.util.stream.Collectors; +import java.util.stream.Stream; import org.apache.tools.ant.BuildException; @@ -72,32 +74,28 @@ class LibraryDisplayer { if (0 != available.length) { System.out.println("Extensions Supported By Library:"); for (int i = 0; i < available.length; i++) { - final Extension extension = available[ i ]; - System.out.println(extension.toString()); + System.out.println(available[i]); } } if (0 != required.length) { System.out.println("Extensions Required By Library:"); for (int i = 0; i < required.length; i++) { - final Extension extension = required[ i ]; - System.out.println(extension.toString()); + System.out.println(required[i]); } } if (0 != options.length) { System.out.println("Extensions that will be used by Library if present:"); for (int i = 0; i < options.length; i++) { - final Extension extension = options[ i ]; - System.out.println(extension.toString()); + System.out.println(options[i]); } } if (0 != specifications.length) { System.out.println("Specifications Supported By Library:"); for (int i = 0; i < specifications.length; i++) { - final Specification specification = specifications[ i ]; - displaySpecification(specification); + displaySpecification(specifications[i]); } } } @@ -138,12 +136,9 @@ class LibraryDisplayer { private void displaySpecification(final Specification specification) { final String[] sections = specification.getSections(); if (null != sections) { - final StringBuffer sb = new StringBuffer("Sections: "); - for (int i = 0; i < sections.length; i++) { - sb.append(" "); - sb.append(sections[ i ]); - } - System.out.println(sb); + System.out.print("Sections: "); + System.out + .println(Stream.of(sections).collect(Collectors.joining(" "))); } System.out.println(specification.toString()); } http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/optional/extension/Specification.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/extension/Specification.java b/src/main/org/apache/tools/ant/taskdefs/optional/extension/Specification.java index 1e4bb7b..ea8405c 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/extension/Specification.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/extension/Specification.java @@ -19,11 +19,14 @@ package org.apache.tools.ant.taskdefs.optional.extension; import java.text.ParseException; import java.util.ArrayList; -import java.util.Arrays; +import java.util.Collections; import java.util.Iterator; +import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.jar.Attributes; import java.util.jar.Manifest; +import java.util.stream.Stream; import org.apache.tools.ant.util.DeweyDecimal; import org.apache.tools.ant.util.StringUtils; @@ -167,25 +170,17 @@ public final class Specification { public static Specification[] getSpecifications(final Manifest manifest) throws ParseException { if (null == manifest) { - return new Specification[ 0 ]; + return new Specification[0]; } + final List<Specification> results = new ArrayList<>(); - final ArrayList results = new ArrayList(); - - final Map entries = manifest.getEntries(); - final Iterator keys = entries.keySet().iterator(); - while (keys.hasNext()) { - final String key = (String) keys.next(); - final Attributes attributes = (Attributes) entries.get(key); - final Specification specification - = getSpecification(key, attributes); - if (null != specification) { - results.add(specification); - } + for (Map.Entry<String, Attributes> e : manifest.getEntries() + .entrySet()) { + Optional.ofNullable(getSpecification(e.getKey(), e.getValue())) + .ifPresent(results::add); } - - final ArrayList trimmedResults = removeDuplicates(results); - return (Specification[]) trimmedResults.toArray(new Specification[trimmedResults.size()]); + return removeDuplicates(results) + .toArray(new Specification[removeDuplicates(results).size()]); } /** @@ -239,10 +234,10 @@ public final class Specification { this.specificationVersion = new DeweyDecimal(specificationVersion); } catch (final NumberFormatException nfe) { - final String error = "Bad specification version format '" - + specificationVersion + "' in '" + specificationTitle - + "'. (Reason: " + nfe + ")"; - throw new IllegalArgumentException(error); + throw new IllegalArgumentException( + "Bad specification version format '" + specificationVersion + + "' in '" + specificationTitle + "'. (Reason: " + nfe + + ")"); } } @@ -253,13 +248,7 @@ public final class Specification { if (null == this.specificationTitle) { throw new NullPointerException("specificationTitle"); } - - String[] copy = null; - if (null != sections) { - copy = new String[ sections.length ]; - System.arraycopy(sections, 0, copy, 0, sections.length); - } - this.sections = copy; + this.sections = sections == null ? null : sections.clone(); } /** @@ -324,12 +313,7 @@ public final class Specification { * or null if relevant to no sections. */ public String[] getSections() { - if (null == sections) { - return null; - } - final String[] newSections = new String[ sections.length ]; - System.arraycopy(sections, 0, newSections, 0, sections.length); - return newSections; + return sections == null ? null : sections.clone(); } /** @@ -390,7 +374,7 @@ public final class Specification { * @return true if the specification is compatible with this specification */ public boolean isCompatibleWith(final Specification other) { - return (COMPATIBLE == getCompatibilityWith(other)); + return COMPATIBLE == getCompatibilityWith(other); } /** @@ -398,11 +382,12 @@ public final class Specification { * * @return string representation of object. */ + @Override public String toString() { final String brace = ": "; - final StringBuffer sb - = new StringBuffer(SPECIFICATION_TITLE.toString()); + final StringBuilder sb + = new StringBuilder(SPECIFICATION_TITLE.toString()); sb.append(brace); sb.append(specificationTitle); sb.append(StringUtils.LINE_SEP); @@ -441,7 +426,6 @@ public final class Specification { sb.append(implementationVendor); sb.append(StringUtils.LINE_SEP); } - return sb.toString(); } @@ -467,30 +451,24 @@ public final class Specification { * @param list the array of results to trim * @return an array list with all duplicates removed */ - private static ArrayList removeDuplicates(final ArrayList list) { - final ArrayList results = new ArrayList(); - final ArrayList sections = new ArrayList(); - while (list.size() > 0) { - final Specification specification = (Specification) list.remove(0); - final Iterator iterator = list.iterator(); - while (iterator.hasNext()) { - final Specification other = (Specification) iterator.next(); + private static List<Specification> removeDuplicates(final List<Specification> list) { + final List<Specification> results = new ArrayList<>(); + final List<String> sections = new ArrayList<>(); + while (!list.isEmpty()) { + final Specification specification = list.remove(0); + for (final Iterator<Specification> iterator = + list.iterator(); iterator.hasNext();) { + final Specification other = iterator.next(); if (isEqual(specification, other)) { - final String[] otherSections = other.getSections(); - if (null != otherSections) { - sections.addAll(Arrays.asList(otherSections)); - } + Optional.ofNullable(other.getSections()) + .ifPresent(s -> Collections.addAll(sections, s)); iterator.remove(); } } - - final Specification merged = - mergeInSections(specification, sections); - results.add(merged); + results.add(mergeInSections(specification, sections)); //Reset list of sections sections.clear(); } - return results; } @@ -522,22 +500,23 @@ public final class Specification { * @return the merged specification */ private static Specification mergeInSections(final Specification specification, - final ArrayList sectionsToAdd) { - if (0 == sectionsToAdd.size()) { + final List<String> sectionsToAdd) { + if (sectionsToAdd.isEmpty()) { return specification; } - sectionsToAdd.addAll(Arrays.asList(specification.getSections())); - - final String[] sections = - (String[]) sectionsToAdd.toArray(new String[sectionsToAdd.size()]); + Stream<String> sections = + Stream + .concat( + Optional.ofNullable(specification.getSections()) + .map(Stream::of).orElse(Stream.empty()), + sectionsToAdd.stream()); return new Specification(specification.getSpecificationTitle(), specification.getSpecificationVersion().toString(), specification.getSpecificationVendor(), specification.getImplementationTitle(), specification.getImplementationVersion(), - specification.getImplementationVendor(), - sections); + specification.getImplementationVendor(), sections.toArray(String[]::new)); } /** http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/optional/extension/resolvers/AntResolver.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/extension/resolvers/AntResolver.java b/src/main/org/apache/tools/ant/taskdefs/optional/extension/resolvers/AntResolver.java index 6284679..b174455 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/extension/resolvers/AntResolver.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/extension/resolvers/AntResolver.java @@ -66,6 +66,7 @@ public class AntResolver implements ExtensionResolver { * @return the file resolved * @throws BuildException if the file cannot be resolved */ + @Override public File resolve(final Extension extension, final Project project) throws BuildException { validate(); @@ -111,6 +112,7 @@ public class AntResolver implements ExtensionResolver { * Returns a string representation * @return the string representation */ + @Override public String toString() { return "Ant[" + antfile + "==>" + destfile + "]"; } http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/optional/extension/resolvers/LocationResolver.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/extension/resolvers/LocationResolver.java b/src/main/org/apache/tools/ant/taskdefs/optional/extension/resolvers/LocationResolver.java index e2fec02..8d3e9bc 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/extension/resolvers/LocationResolver.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/extension/resolvers/LocationResolver.java @@ -46,19 +46,19 @@ public class LocationResolver implements ExtensionResolver { * @return the file resolved * @throws BuildException if no location is set */ + @Override public File resolve(final Extension extension, final Project project) throws BuildException { if (null == location) { - final String message = "No location specified for resolver"; - throw new BuildException(message); + throw new BuildException("No location specified for resolver"); } - return project.resolveFile(location); } /** * Returns a string representation of the Location * @return the string representation */ + @Override public String toString() { return "Location[" + location + "]"; } http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/optional/extension/resolvers/URLResolver.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/extension/resolvers/URLResolver.java b/src/main/org/apache/tools/ant/taskdefs/optional/extension/resolvers/URLResolver.java index d693b89..7e3dca5 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/extension/resolvers/URLResolver.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/extension/resolvers/URLResolver.java @@ -66,6 +66,7 @@ public class URLResolver implements ExtensionResolver { * @return file the file resolved * @throws BuildException if the URL is invalid */ + @Override public File resolve(final Extension extension, final Project project) throws BuildException { validate(); @@ -110,16 +111,15 @@ public class URLResolver implements ExtensionResolver { */ private void validate() { if (null == url) { - final String message = "Must specify URL"; - throw new BuildException(message); + throw new BuildException("Must specify URL"); } - if (null == destdir && null == destfile) { - final String message = "Must specify destination file or directory"; - throw new BuildException(message); - } else if (null != destdir && null != destfile) { - final String message = "Must not specify both destination file or directory"; - throw new BuildException(message); + throw new BuildException( + "Must specify destination file or directory"); + } + if (null != destdir && null != destfile) { + throw new BuildException( + "Must not specify both destination file or directory"); } } @@ -127,6 +127,7 @@ public class URLResolver implements ExtensionResolver { * Returns a string representation of the URL * @return the string representation */ + @Override public String toString() { return "URL[" + url + "]"; } http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/optional/i18n/Translate.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/i18n/Translate.java b/src/main/org/apache/tools/ant/taskdefs/optional/i18n/Translate.java index 685468a..42e2be1 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/i18n/Translate.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/i18n/Translate.java @@ -23,11 +23,12 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; -import java.io.OutputStream; import java.io.OutputStreamWriter; import java.nio.file.Files; import java.util.Hashtable; +import java.util.List; import java.util.Locale; +import java.util.Map; import java.util.Vector; import org.apache.tools.ant.BuildException; @@ -138,12 +139,12 @@ public class Translate extends MatchingTask { /** * Vector to hold source file sets. */ - private Vector filesets = new Vector(); + private List<FileSet> filesets = new Vector<>(); /** * Holds key value pairs loaded from resource bundle file */ - private Hashtable resourceMap = new Hashtable(); + private Map<String, String> resourceMap = new Hashtable<>(); /** * Used to resolve file names. @@ -269,7 +270,7 @@ public class Translate extends MatchingTask { * @param set the fileset to be added */ public void addFileset(FileSet set) { - filesets.addElement(set); + filesets.add(set); } /** @@ -281,6 +282,7 @@ public class Translate extends MatchingTask { * <li>endtoken</li> * </ul> */ + @Override public void execute() throws BuildException { if (bundle == null) { throw new BuildException("The bundle attribute must be set.", @@ -319,7 +321,7 @@ public class Translate extends MatchingTask { if (!toDir.exists()) { toDir.mkdirs(); } else if (toDir.isFile()) { - throw new BuildException(toDir + " is not a directory"); + throw new BuildException("%s is not a directory", toDir); } if (srcEncoding == null) { @@ -362,23 +364,18 @@ public class Translate extends MatchingTask { Locale locale = new Locale(bundleLanguage, bundleCountry, bundleVariant); + String language = locale.getLanguage().length() > 0 ? "_" + locale.getLanguage() : ""; String country = locale.getCountry().length() > 0 ? "_" + locale.getCountry() : ""; String variant = locale.getVariant().length() > 0 ? "_" + locale.getVariant() : ""; - String bundleFile = bundle + language + country + variant; - processBundle(bundleFile, BUNDLE_SPECIFIED_LANGUAGE_COUNTRY_VARIANT, false); - - bundleFile = bundle + language + country; - processBundle(bundleFile, BUNDLE_SPECIFIED_LANGUAGE_COUNTRY, false); - - bundleFile = bundle + language; - processBundle(bundleFile, BUNDLE_SPECIFIED_LANGUAGE, false); - - bundleFile = bundle; - processBundle(bundleFile, BUNDLE_NOMATCH, false); + + processBundle(bundle + language + country + variant, BUNDLE_SPECIFIED_LANGUAGE_COUNTRY_VARIANT, false); + processBundle(bundle + language + country, BUNDLE_SPECIFIED_LANGUAGE_COUNTRY, false); + processBundle(bundle + language, BUNDLE_SPECIFIED_LANGUAGE, false); + processBundle(bundle, BUNDLE_NOMATCH, false); //Load default locale bundle files //using default file encoding scheme. @@ -392,14 +389,9 @@ public class Translate extends MatchingTask { ? "_" + locale.getVariant() : ""; bundleEncoding = System.getProperty("file.encoding"); - bundleFile = bundle + language + country + variant; - processBundle(bundleFile, BUNDLE_DEFAULT_LANGUAGE_COUNTRY_VARIANT, false); - - bundleFile = bundle + language + country; - processBundle(bundleFile, BUNDLE_DEFAULT_LANGUAGE_COUNTRY, false); - - bundleFile = bundle + language; - processBundle(bundleFile, BUNDLE_DEFAULT_LANGUAGE, true); + processBundle(bundle + language + country + variant, BUNDLE_DEFAULT_LANGUAGE_COUNTRY_VARIANT, false); + processBundle(bundle + language + country, BUNDLE_DEFAULT_LANGUAGE_COUNTRY, false); + processBundle(bundle + language, BUNDLE_DEFAULT_LANGUAGE, true); } /** @@ -431,11 +423,9 @@ public class Translate extends MatchingTask { * are not overwritten. Bundle's encoding scheme is used. */ private void loadResourceMap(InputStream ins) throws BuildException { - try { - BufferedReader in = null; - InputStreamReader isr = new InputStreamReader(ins, bundleEncoding); - in = new BufferedReader(isr); - String line = null; + try (BufferedReader in = + new BufferedReader(new InputStreamReader(ins, bundleEncoding))) { + String line; while ((line = in.readLine()) != null) { //So long as the line isn't empty and isn't a comment... if (line.trim().length() > 1 && '#' != line.charAt(0) && '!' != line.charAt(0)) { @@ -475,9 +465,6 @@ public class Translate extends MatchingTask { } } } - if (in != null) { - in.close(); - } } catch (IOException ioe) { throw new BuildException(ioe.getMessage(), getLocation()); } @@ -497,9 +484,7 @@ public class Translate extends MatchingTask { */ private void translate() throws BuildException { int filesProcessed = 0; - 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()); String[] srcFiles = ds.getIncludedFiles(); for (int j = 0; j < srcFiles.length; j++) { @@ -549,18 +534,14 @@ public class Translate extends MatchingTask { } private void translateOneFile(File src, File dest) throws IOException { - BufferedWriter out = null; - BufferedReader in = null; - try { - OutputStream fos = Files.newOutputStream(dest.toPath()); - out = new BufferedWriter(new OutputStreamWriter(fos, destEncoding)); - InputStream fis = Files.newInputStream(src.toPath()); - in = new BufferedReader(new InputStreamReader(fis, srcEncoding)); - String line; + try (BufferedWriter out = new BufferedWriter(new OutputStreamWriter( + Files.newOutputStream(dest.toPath()), destEncoding)); + BufferedReader in = new BufferedReader(new InputStreamReader( + Files.newInputStream(src.toPath()), srcEncoding))) { LineTokenizer lineTokenizer = new LineTokenizer(); lineTokenizer.setIncludeDelims(true); - line = lineTokenizer.getToken(in); - while ((line) != null) { + String line = lineTokenizer.getToken(in); + while (line != null) { // 2003-02-21 new replace algorithm by tbee ([email protected]) // because it wasn't able to replace something like "@aaa;@bbb;" @@ -602,7 +583,7 @@ public class Translate extends MatchingTask { } else { // find the replace string if (resourceMap.containsKey(token)) { - replace = (String) resourceMap.get(token); + replace = resourceMap.get(token); } else { log("Replacement string missing for: " + token, Project.MSG_VERBOSE); @@ -625,9 +606,6 @@ public class Translate extends MatchingTask { out.write(line); line = lineTokenizer.getToken(in); } - } finally { - FileUtils.close(in); - FileUtils.close(out); } } } http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/optional/image/Image.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/image/Image.java b/src/main/org/apache/tools/ant/taskdefs/optional/image/Image.java index 5cef009..53b234b 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/image/Image.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/image/Image.java @@ -28,7 +28,6 @@ import javax.media.jai.JAI; import javax.media.jai.PlanarImage; import org.apache.tools.ant.BuildException; -import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.Project; import org.apache.tools.ant.taskdefs.MatchingTask; import org.apache.tools.ant.types.FileSet; @@ -39,7 +38,6 @@ import org.apache.tools.ant.types.optional.image.Rotate; import org.apache.tools.ant.types.optional.image.Scale; import org.apache.tools.ant.types.optional.image.TransformOperation; import org.apache.tools.ant.util.FileNameMapper; -import org.apache.tools.ant.util.FileUtils; import org.apache.tools.ant.util.IdentityMapper; import org.apache.tools.ant.util.StringUtils; @@ -60,9 +58,9 @@ import com.sun.media.jai.codec.FileSeekableStream; */ public class Image extends MatchingTask { // CheckStyle:VisibilityModifier OFF - bc - protected Vector instructions = new Vector(); + protected Vector<ImageOperation> instructions = new Vector<>(); protected boolean overwrite = false; - protected Vector filesets = new Vector(); + protected Vector<FileSet> filesets = new Vector<>(); protected File srcDir = null; protected File destDir = null; @@ -85,7 +83,7 @@ public class Image extends MatchingTask { * @param set the FileSet to add. */ public void addFileset(FileSet set) { - filesets.addElement(set); + filesets.add(set); } /** @@ -230,9 +228,7 @@ public class Image extends MatchingTask { continue; } - for (int j = 0; j < dstNames.length; ++j){ - - final String dstName = dstNames[j]; + for (String dstName : dstNames) { final File dstFile = new File(dstDir, dstName).getAbsoluteFile(); if (dstFile.exists()){ @@ -271,6 +267,7 @@ public class Image extends MatchingTask { * @param file The file to be processed. * @deprecated this method isn't used anymore */ + @Deprecated public void processFile(File file) { processFile(file, new File(destDir == null ? srcDir : destDir, file.getName())); @@ -287,14 +284,10 @@ public class Image extends MatchingTask { try { log("Processing File: " + file.getAbsolutePath()); - FileSeekableStream input = null; PlanarImage image = null; - try { - input = new FileSeekableStream(file); + try (FileSeekableStream input = new FileSeekableStream(file)) { image = JAI.create("stream", input); - final int size = instructions.size(); - for (int i = 0; i < size; i++) { - Object instr = instructions.elementAt(i); + for (ImageOperation instr : instructions) { if (instr instanceof TransformOperation) { image = ((TransformOperation) instr) .executeTransformOperation(image); @@ -302,33 +295,25 @@ public class Image extends MatchingTask { log("Not a TransformOperation: " + instr); } } - } finally { - FileUtils.close(input); } File dstParent = newFile.getParentFile(); if (!dstParent.isDirectory() && !(dstParent.mkdirs() || dstParent.isDirectory())) { - throw new BuildException("Failed to create parent directory " - + dstParent); + throw new BuildException("Failed to create parent directory %s", + dstParent); } if ((overwrite && newFile.exists()) && (!newFile.equals(file))) { newFile.delete(); } - OutputStream stream = null; - try { - stream = Files.newOutputStream(newFile.toPath()); - + try (OutputStream stream = Files.newOutputStream(newFile.toPath())) { JAI.create("encode", image, stream, - str_encoding.toUpperCase(Locale.ENGLISH), - null); + str_encoding.toUpperCase(Locale.ENGLISH), null); stream.flush(); - } finally { - FileUtils.close(stream); } - } catch (IOException err) { + } catch (IOException | RuntimeException err) { if (!file.equals(newFile)){ newFile.delete(); } @@ -337,15 +322,6 @@ public class Image extends MatchingTask { } else { throw new BuildException(err); } - } catch (java.lang.RuntimeException rerr) { - if (!file.equals(newFile)){ - newFile.delete(); - } - if (!failonerror) { - log("Error processing file: " + rerr); - } else { - throw new BuildException(rerr); - } } } @@ -353,6 +329,7 @@ public class Image extends MatchingTask { * Executes the Task. * @throws BuildException on error. */ + @Override public void execute() throws BuildException { validateAttributes(); @@ -363,29 +340,20 @@ public class Image extends MatchingTask { int writeCount = 0; // build mapper - final FileNameMapper mapper; - if (mapperElement==null){ - mapper = new IdentityMapper(); - } else { - mapper = mapperElement.getImplementation(); - } + final FileNameMapper mapper = mapperElement == null + ? new IdentityMapper() : mapperElement.getImplementation(); // deal with specified srcDir if (srcDir != null) { - final DirectoryScanner ds = super.getDirectoryScanner(srcDir); - - final String[] files = ds.getIncludedFiles(); - writeCount += processDir(srcDir, files, dest, mapper); + writeCount += processDir(srcDir, + super.getDirectoryScanner(srcDir).getIncludedFiles(), dest, + mapper); } // deal with the filesets - final int size = filesets.size(); - for (int i = 0; i < size; i++) { - final FileSet fs = (FileSet) filesets.elementAt(i); - final DirectoryScanner ds = - fs.getDirectoryScanner(getProject()); - final String[] files = ds.getIncludedFiles(); - final File fromDir = fs.getDir(getProject()); - writeCount += processDir(fromDir, files, dest, mapper); + for (FileSet fs : filesets) { + writeCount += processDir(fs.getDir(getProject()), + fs.getDirectoryScanner(getProject()).getIncludedFiles(), + dest, mapper); } if (writeCount>0){ @@ -406,16 +374,16 @@ public class Image extends MatchingTask { * @throws BuildException on error. */ protected void validateAttributes() throws BuildException { - if (srcDir == null && filesets.size() == 0) { - throw new BuildException("Specify at least one source" - + "--a srcDir or a fileset."); + if (srcDir == null && filesets.isEmpty()) { + throw new BuildException( + "Specify at least one source--a srcDir or a fileset."); } if (srcDir == null && destDir == null) { throw new BuildException("Specify the destDir, or the srcDir."); } - if (str_encoding.equalsIgnoreCase("jpg")) { + if ("jpg".equalsIgnoreCase(str_encoding)) { str_encoding = "JPEG"; - } else if (str_encoding.equalsIgnoreCase("tif")) { + } else if ("tif".equalsIgnoreCase(str_encoding)) { str_encoding = "TIFF"; } } http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/optional/j2ee/AbstractHotDeploymentTool.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/j2ee/AbstractHotDeploymentTool.java b/src/main/org/apache/tools/ant/taskdefs/optional/j2ee/AbstractHotDeploymentTool.java index fdbde74..21d8478 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/j2ee/AbstractHotDeploymentTool.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/j2ee/AbstractHotDeploymentTool.java @@ -87,13 +87,14 @@ public abstract class AbstractHotDeploymentTool implements HotDeploymentTool { * base class. Subclasses should check attributes accordingly. * @exception org.apache.tools.ant.BuildException if the attributes are invalid or incomplete. */ + @Override public void validateAttributes() throws BuildException { if (task.getAction() == null) { throw new BuildException("The \"action\" attribute must be set"); } if (!isActionValid()) { - throw new BuildException("Invalid action \"" + task.getAction() + "\" passed"); + throw new BuildException("Invalid action \"%s\" passed", task.getAction()); } if (classpath == null) { @@ -102,17 +103,11 @@ public abstract class AbstractHotDeploymentTool implements HotDeploymentTool { } /** - * Perform the actual deployment. - * It's up to the subclasses to implement the actual behavior. - * @exception org.apache.tools.ant.BuildException if the attributes are invalid or incomplete. - */ - public abstract void deploy() throws BuildException; - - /** * Sets the parent task. * @param task a ServerDeploy object representing the parent task. * @ant.attribute ignore="true" */ + @Override public void setTask(ServerDeploy task) { this.task = task; } http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/optional/j2ee/GenericHotDeploymentTool.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/j2ee/GenericHotDeploymentTool.java b/src/main/org/apache/tools/ant/taskdefs/optional/j2ee/GenericHotDeploymentTool.java index 5a5abba..1cb0a7e 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/j2ee/GenericHotDeploymentTool.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/j2ee/GenericHotDeploymentTool.java @@ -70,8 +70,9 @@ public class GenericHotDeploymentTool extends AbstractHotDeploymentTool { * For this generic implementation, the only valid action is "deploy" * @return true if the "action" attribute is valid, false if not. */ + @Override protected boolean isActionValid() { - return (getTask().getAction().equals(VALID_ACTIONS[0])); + return getTask().getAction().equals(VALID_ACTIONS[0]); } /** @@ -79,6 +80,7 @@ public class GenericHotDeploymentTool extends AbstractHotDeploymentTool { * @param task An ServerDeploy object representing the parent task. * @ant.attribute ignored="true" */ + @Override public void setTask(ServerDeploy task) { super.setTask(task); java = new Java(task); @@ -90,6 +92,7 @@ public class GenericHotDeploymentTool extends AbstractHotDeploymentTool { * supplied classpath, classname, JVM args, and command line arguments. * @exception org.apache.tools.ant.BuildException if the attributes are invalid or incomplete. */ + @Override public void deploy() throws BuildException { java.setClassname(className); java.setClasspath(getClasspath()); @@ -103,6 +106,7 @@ public class GenericHotDeploymentTool extends AbstractHotDeploymentTool { * Ensures the className and arguments attribute have been set. * @exception org.apache.tools.ant.BuildException if the attributes are invalid or incomplete. */ + @Override public void validateAttributes() throws BuildException { super.validateAttributes(); http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/optional/j2ee/JonasHotDeploymentTool.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/j2ee/JonasHotDeploymentTool.java b/src/main/org/apache/tools/ant/taskdefs/optional/j2ee/JonasHotDeploymentTool.java index c7a33a1..6e7f118 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/j2ee/JonasHotDeploymentTool.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/j2ee/JonasHotDeploymentTool.java @@ -53,8 +53,8 @@ public class JonasHotDeploymentTool extends GenericHotDeploymentTool implements /** * All the valid actions that weblogic.deploy permits * */ - private static final String[] VALID_ACTIONS - = {ACTION_DELETE, ACTION_DEPLOY, ACTION_LIST, ACTION_UNDEPLOY, ACTION_UPDATE}; + private static final String[] VALID_ACTIONS = { ACTION_DELETE, + ACTION_DEPLOY, ACTION_LIST, ACTION_UNDEPLOY, ACTION_UPDATE }; /** * Description of the Field @@ -76,7 +76,6 @@ public class JonasHotDeploymentTool extends GenericHotDeploymentTool implements */ private int davidPort; - /** * Set the host for the David ORB; required if * ORB==david. @@ -87,7 +86,6 @@ public class JonasHotDeploymentTool extends GenericHotDeploymentTool implements davidHost = inValue; } - /** * Set the port for the David ORB; required if * ORB==david. @@ -98,7 +96,6 @@ public class JonasHotDeploymentTool extends GenericHotDeploymentTool implements davidPort = inValue; } - /** * set the jonas root directory (-Dinstall.root=). This * element is required. @@ -109,7 +106,6 @@ public class JonasHotDeploymentTool extends GenericHotDeploymentTool implements jonasroot = inValue; } - /** * * Choose your ORB : RMI, JEREMIE, DAVID, ...; optional. @@ -124,14 +120,13 @@ public class JonasHotDeploymentTool extends GenericHotDeploymentTool implements orb = inValue; } - /** * gets the classpath field. * *@return A Path representing the "classpath" attribute. */ + @Override public Path getClasspath() { - Path aClassPath = super.getClasspath(); if (aClassPath == null) { @@ -147,7 +142,6 @@ public class JonasHotDeploymentTool extends GenericHotDeploymentTool implements return aClassPath; } - /** * Validates the passed in attributes. <p> * @@ -161,6 +155,7 @@ public class JonasHotDeploymentTool extends GenericHotDeploymentTool implements *@exception BuildException Description * of Exception */ + @Override public void validateAttributes() throws BuildException { // super.validateAttributes(); // don't want to call this method @@ -172,7 +167,7 @@ public class JonasHotDeploymentTool extends GenericHotDeploymentTool implements } if (!isActionValid()) { - throw new BuildException("Invalid action \"" + action + "\" passed"); + throw new BuildException("Invalid action \"%s\" passed", action); } if (getClassName() == null) { @@ -213,9 +208,9 @@ public class JonasHotDeploymentTool extends GenericHotDeploymentTool implements java.createArg().setLine("-n " + getServer()); } - if (action.equals(ACTION_DEPLOY) - || action.equals(ACTION_UPDATE) - || action.equals("redeploy")) { + if (ACTION_DEPLOY.equals(action) + || ACTION_UPDATE.equals(action) + || "redeploy".equals(action)) { java.createArg().setLine("-a " + getTask().getSource()); } else if (action.equals(ACTION_DELETE) || action.equals(ACTION_UNDEPLOY)) { java.createArg().setLine("-r " + getTask().getSource()); @@ -224,7 +219,6 @@ public class JonasHotDeploymentTool extends GenericHotDeploymentTool implements } } - /** * Determines if the action supplied is valid. <p> * @@ -234,19 +228,17 @@ public class JonasHotDeploymentTool extends GenericHotDeploymentTool implements *@return true if the action attribute is valid, false if * not. */ + @Override protected boolean isActionValid() { - boolean valid = false; - String action = getTask().getAction(); - for (int i = 0; i < VALID_ACTIONS.length; i++) { - if (action.equals(VALID_ACTIONS[i])) { - valid = true; - break; + for (String validAction : VALID_ACTIONS) { + if (action.equals(validAction)) { + return true; } } - - return valid; + // TODO what about redeploy, mentioned in #validateAttribute + return false; } } http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/optional/j2ee/ServerDeploy.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/j2ee/ServerDeploy.java b/src/main/org/apache/tools/ant/taskdefs/optional/j2ee/ServerDeploy.java index 8965b8e..7947a7b 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/j2ee/ServerDeploy.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/j2ee/ServerDeploy.java @@ -19,7 +19,7 @@ package org.apache.tools.ant.taskdefs.optional.j2ee; import java.io.File; -import java.util.Enumeration; +import java.util.List; import java.util.Vector; import org.apache.tools.ant.BuildException; @@ -44,7 +44,7 @@ public class ServerDeploy extends Task { private File source; /** The vendor specific tool for deploying the component **/ - private Vector vendorTools = new Vector(); + private List<AbstractHotDeploymentTool> vendorTools = new Vector<>(); /////////////////////////////////////////////////////////////////////////// // @@ -60,7 +60,7 @@ public class ServerDeploy extends Task { */ public void addGeneric(GenericHotDeploymentTool tool) { tool.setTask(this); - vendorTools.addElement(tool); + vendorTools.add(tool); } /** @@ -71,7 +71,7 @@ public class ServerDeploy extends Task { */ public void addWeblogic(WebLogicHotDeploymentTool tool) { tool.setTask(this); - vendorTools.addElement(tool); + vendorTools.add(tool); } /** @@ -82,7 +82,7 @@ public class ServerDeploy extends Task { */ public void addJonas(JonasHotDeploymentTool tool) { tool.setTask(this); - vendorTools.addElement(tool); + vendorTools.add(tool); } @@ -100,10 +100,9 @@ public class ServerDeploy extends Task { * @exception org.apache.tools.ant.BuildException if the attributes * are invalid or incomplete, or a failure occurs in the deployment process. */ + @Override public void execute() throws BuildException { - for (Enumeration e = vendorTools.elements(); - e.hasMoreElements();) { - HotDeploymentTool tool = (HotDeploymentTool) e.nextElement(); + for (HotDeploymentTool tool : vendorTools) { tool.validateAttributes(); tool.deploy(); } http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/optional/j2ee/WebLogicHotDeploymentTool.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/j2ee/WebLogicHotDeploymentTool.java b/src/main/org/apache/tools/ant/taskdefs/optional/j2ee/WebLogicHotDeploymentTool.java index da87509..e186dcb 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/j2ee/WebLogicHotDeploymentTool.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/j2ee/WebLogicHotDeploymentTool.java @@ -59,6 +59,7 @@ public class WebLogicHotDeploymentTool extends AbstractHotDeploymentTool * tools is executed. * @exception org.apache.tools.ant.BuildException if the attributes are invalid or incomplete. */ + @Override public void deploy() { Java java = new Java(getTask()); java.setFork(true); @@ -79,6 +80,7 @@ public class WebLogicHotDeploymentTool extends AbstractHotDeploymentTool * be supplied. * @exception org.apache.tools.ant.BuildException if the attributes are invalid or incomplete */ + @Override public void validateAttributes() throws BuildException { super.validateAttributes(); @@ -92,22 +94,22 @@ public class WebLogicHotDeploymentTool extends AbstractHotDeploymentTool // check for missing application on deploy & update if ((action.equals(ACTION_DEPLOY) || action.equals(ACTION_UPDATE)) && application == null) { - throw new BuildException("The application attribute must be set " - + "if action = " + action); + throw new BuildException( + "The application attribute must be set if action = %s", action); } // check for missing source on deploy & update if ((action.equals(ACTION_DEPLOY) || action.equals(ACTION_UPDATE)) && getTask().getSource() == null) { - throw new BuildException("The source attribute must be set if " - + "action = " + action); + throw new BuildException( + "The source attribute must be set if action = %s", action); } // check for missing application on delete & undeploy if ((action.equals(ACTION_DELETE) || action.equals(ACTION_UNDEPLOY)) && application == null) { - throw new BuildException("The application attribute must be set if " - + "action = " + action); + throw new BuildException( + "The application attribute must be set if action = %s", action); } } @@ -119,17 +121,17 @@ public class WebLogicHotDeploymentTool extends AbstractHotDeploymentTool */ public String getArguments() throws BuildException { String action = getTask().getAction(); - String args = null; if (action.equals(ACTION_DEPLOY) || action.equals(ACTION_UPDATE)) { - args = buildDeployArgs(); - } else if (action.equals(ACTION_DELETE) || action.equals(ACTION_UNDEPLOY)) { - args = buildUndeployArgs(); - } else if (action.equals(ACTION_LIST)) { - args = buildListArgs(); + return buildDeployArgs(); } - - return args; + if (action.equals(ACTION_DELETE) || action.equals(ACTION_UNDEPLOY)) { + return buildUndeployArgs(); + } + if (action.equals(ACTION_LIST)) { + return buildListArgs(); + } + return null; } /** @@ -137,19 +139,16 @@ public class WebLogicHotDeploymentTool extends AbstractHotDeploymentTool * <p>Valid actions are contained in the static array VALID_ACTIONS * @return true if the action attribute is valid, false if not. */ + @Override protected boolean isActionValid() { - boolean valid = false; - String action = getTask().getAction(); - for (int i = 0; i < VALID_ACTIONS.length; i++) { - if (action.equals(VALID_ACTIONS[i])) { - valid = true; - break; + for (String validAction : VALID_ACTIONS) { + if (action.equals(validAction)) { + return true; } } - - return valid; + return false; } /** http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JJDoc.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JJDoc.java b/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JJDoc.java index a4dc0f4..d3aff08 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JJDoc.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JJDoc.java @@ -20,8 +20,8 @@ package org.apache.tools.ant.taskdefs.optional.javacc; import java.io.File; import java.io.IOException; -import java.util.Enumeration; import java.util.Hashtable; +import java.util.Map; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; @@ -44,7 +44,7 @@ public class JJDoc extends Task { private static final String TEXT = "TEXT"; private static final String ONE_TABLE = "ONE_TABLE"; - private final Hashtable optionalAttrs = new Hashtable(); + private final Map<String, Object> optionalAttrs = new Hashtable<>(); private String outputFile = null; private boolean plainText = false; @@ -65,7 +65,7 @@ public class JJDoc extends Task { * @param plainText a <code>boolean</code> value. */ public void setText(boolean plainText) { - optionalAttrs.put(TEXT, plainText ? Boolean.TRUE : Boolean.FALSE); + optionalAttrs.put(TEXT, Boolean.valueOf(plainText)); this.plainText = plainText; } @@ -74,7 +74,7 @@ public class JJDoc extends Task { * @param oneTable a <code>boolean</code> value. */ public void setOnetable(boolean oneTable) { - optionalAttrs.put(ONE_TABLE, oneTable ? Boolean.TRUE : Boolean.FALSE); + optionalAttrs.put(ONE_TABLE, Boolean.valueOf(oneTable)); } /** @@ -124,19 +124,15 @@ public class JJDoc extends Task { * Do the task. * @throws BuildException if there is an error. */ + @Override public void execute() throws BuildException { // load command line with optional attributes - Enumeration iter = optionalAttrs.keys(); - while (iter.hasMoreElements()) { - String name = (String) iter.nextElement(); - Object value = optionalAttrs.get(name); - cmdl.createArgument() - .setValue("-" + name + ":" + value.toString()); - } + optionalAttrs.forEach((name, value) -> cmdl.createArgument() + .setValue("-" + name + ":" + value.toString())); if (targetFile == null || !targetFile.isFile()) { - throw new BuildException("Invalid target: " + targetFile); + throw new BuildException("Invalid target: %s", targetFile); } if (outputFile != null) { @@ -195,8 +191,8 @@ public class JJDoc extends Task { suffix = DEFAULT_SUFFIX_TEXT; } - if ((optionalOutputFile == null) || optionalOutputFile.equals("")) { - int filePos = javaccFile.lastIndexOf("/"); + if ((optionalOutputFile == null) || optionalOutputFile.isEmpty()) { + int filePos = javaccFile.lastIndexOf('/'); if (filePos >= 0) { javaccFile = javaccFile.substring(filePos + 1); http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JJTree.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JJTree.java b/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JJTree.java index f5d126e..e3bca20 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JJTree.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JJTree.java @@ -20,8 +20,8 @@ package org.apache.tools.ant.taskdefs.optional.javacc; import java.io.File; import java.io.IOException; -import java.util.Enumeration; import java.util.Hashtable; +import java.util.Map; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; @@ -54,7 +54,7 @@ public class JJTree extends Task { private static final String VISITOR_EXCEPTION = "VISITOR_EXCEPTION"; private static final String NODE_PREFIX = "NODE_PREFIX"; - private final Hashtable optionalAttrs = new Hashtable(); + private final Map<String, Object> optionalAttrs = new Hashtable<>(); private String outputFile = null; @@ -74,7 +74,7 @@ public class JJTree extends Task { * @param buildNodeFiles a <code>boolean</code> value. */ public void setBuildnodefiles(boolean buildNodeFiles) { - optionalAttrs.put(BUILD_NODE_FILES, buildNodeFiles ? Boolean.TRUE : Boolean.FALSE); + optionalAttrs.put(BUILD_NODE_FILES, Boolean.valueOf(buildNodeFiles)); } /** @@ -82,7 +82,7 @@ public class JJTree extends Task { * @param multi a <code>boolean</code> value. */ public void setMulti(boolean multi) { - optionalAttrs.put(MULTI, multi ? Boolean.TRUE : Boolean.FALSE); + optionalAttrs.put(MULTI, Boolean.valueOf(multi)); } /** @@ -90,7 +90,7 @@ public class JJTree extends Task { * @param nodeDefaultVoid a <code>boolean</code> value. */ public void setNodedefaultvoid(boolean nodeDefaultVoid) { - optionalAttrs.put(NODE_DEFAULT_VOID, nodeDefaultVoid ? Boolean.TRUE : Boolean.FALSE); + optionalAttrs.put(NODE_DEFAULT_VOID, Boolean.valueOf(nodeDefaultVoid)); } /** @@ -98,7 +98,7 @@ public class JJTree extends Task { * @param nodeFactory a <code>boolean</code> value. */ public void setNodefactory(boolean nodeFactory) { - optionalAttrs.put(NODE_FACTORY, nodeFactory ? Boolean.TRUE : Boolean.FALSE); + optionalAttrs.put(NODE_FACTORY, Boolean.valueOf(nodeFactory)); } /** @@ -106,7 +106,7 @@ public class JJTree extends Task { * @param nodeScopeHook a <code>boolean</code> value. */ public void setNodescopehook(boolean nodeScopeHook) { - optionalAttrs.put(NODE_SCOPE_HOOK, nodeScopeHook ? Boolean.TRUE : Boolean.FALSE); + optionalAttrs.put(NODE_SCOPE_HOOK, Boolean.valueOf(nodeScopeHook)); } /** @@ -114,7 +114,7 @@ public class JJTree extends Task { * @param nodeUsesParser a <code>boolean</code> value. */ public void setNodeusesparser(boolean nodeUsesParser) { - optionalAttrs.put(NODE_USES_PARSER, nodeUsesParser ? Boolean.TRUE : Boolean.FALSE); + optionalAttrs.put(NODE_USES_PARSER, Boolean.valueOf(nodeUsesParser)); } /** @@ -122,7 +122,7 @@ public class JJTree extends Task { * @param staticParser a <code>boolean</code> value. */ public void setStatic(boolean staticParser) { - optionalAttrs.put(STATIC, staticParser ? Boolean.TRUE : Boolean.FALSE); + optionalAttrs.put(STATIC, Boolean.valueOf(staticParser)); } /** @@ -130,7 +130,7 @@ public class JJTree extends Task { * @param visitor a <code>boolean</code> value. */ public void setVisitor(boolean visitor) { - optionalAttrs.put(VISITOR, visitor ? Boolean.TRUE : Boolean.FALSE); + optionalAttrs.put(VISITOR, Boolean.valueOf(visitor)); } /** @@ -214,21 +214,18 @@ public class JJTree extends Task { * Run the task. * @throws BuildException on error. */ + @Override public void execute() throws BuildException { // load command line with optional attributes - Enumeration iter = optionalAttrs.keys(); - while (iter.hasMoreElements()) { - String name = (String) iter.nextElement(); - Object value = optionalAttrs.get(name); - cmdl.createArgument().setValue("-" + name + ":" + value.toString()); - } + optionalAttrs.forEach((name, value) -> cmdl.createArgument() + .setValue("-" + name + ":" + value.toString())); if (targetFile == null || !targetFile.isFile()) { - throw new BuildException("Invalid target: " + targetFile); + throw new BuildException("Invalid target: %s", targetFile); } - File javaFile = null; + File javaFile; // use the directory containing the target as the output directory if (outputDirectory == null) { @@ -305,8 +302,8 @@ public class JJTree extends Task { outputDir); String jjtreeFile = destFile.getAbsolutePath().replace('\\', '/'); - if ((optionalOutputFile == null) || optionalOutputFile.equals("")) { - int filePos = jjtreeFile.lastIndexOf("/"); + if ((optionalOutputFile == null) || optionalOutputFile.isEmpty()) { + int filePos = jjtreeFile.lastIndexOf('/'); if (filePos >= 0) { jjtreeFile = jjtreeFile.substring(filePos + 1); @@ -328,7 +325,7 @@ public class JJTree extends Task { } } - if ((outputDir == null) || outputDir.equals("")) { + if ((outputDir == null) || outputDir.isEmpty()) { outputDir = getDefaultOutputDirectory(); } @@ -363,17 +360,17 @@ public class JJTree extends Task { String root = getRoot(new File(destFile)).getAbsolutePath(); - if ((root.length() > 1) + if (root.length() > 1 && destFile.startsWith(root.substring(0, root.length() - 1))) { - throw new BuildException("Drive letter in 'outputfile' not " - + "supported: " + destFile); + throw new BuildException( + "Drive letter in 'outputfile' not supported: %s", destFile); } return destFile; } private String makeOutputFileRelative(String destFile) { - StringBuffer relativePath = new StringBuffer(); + StringBuilder relativePath = new StringBuilder(); String defaultOutputDirectory = getDefaultOutputDirectory(); int nextPos = defaultOutputDirectory.indexOf('/'); int startPos = nextPos + 1; @@ -388,10 +385,7 @@ public class JJTree extends Task { startPos = nextPos + 1; } } - - relativePath.append(destFile); - - return relativePath.toString(); + return relativePath.append(destFile).toString(); } private String getDefaultOutputDirectory() { @@ -410,7 +404,6 @@ public class JJTree extends Task { while (root.getParent() != null) { root = root.getParentFile(); } - return root; } } http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JavaCC.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JavaCC.java b/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JavaCC.java index 86713da..c35db1b 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JavaCC.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JavaCC.java @@ -20,8 +20,8 @@ package org.apache.tools.ant.taskdefs.optional.javacc; import java.io.File; import java.io.InputStream; -import java.util.Enumeration; import java.util.Hashtable; +import java.util.Map; import org.apache.tools.ant.AntClassLoader; import org.apache.tools.ant.BuildException; @@ -64,7 +64,7 @@ public class JavaCC extends Task { private static final String KEEP_LINE_COLUMN = "KEEP_LINE_COLUMN"; private static final String JDK_VERSION = "JDK_VERSION"; - private final Hashtable optionalAttrs = new Hashtable(); + private final Map<String, Object> optionalAttrs = new Hashtable<>(); // required attributes private File outputDirectory = null; @@ -79,19 +79,19 @@ public class JavaCC extends Task { protected static final String[] ARCHIVE_LOCATIONS = //NOSONAR new String[] { - "JavaCC.zip", - "bin/lib/JavaCC.zip", - "bin/lib/javacc.jar", - "javacc.jar", // used by jpackage for JavaCC 3.x - }; + "JavaCC.zip", + "bin/lib/JavaCC.zip", + "bin/lib/javacc.jar", + "javacc.jar", // used by jpackage for JavaCC 3.x + }; protected static final int[] ARCHIVE_LOCATIONS_VS_MAJOR_VERSION = //NOSONAR new int[] { - 1, - 2, - 3, - 3, - }; + 1, + 2, + 3, + 3, + }; protected static final String COM_PACKAGE = "COM.sun.labs."; protected static final String COM_JAVACC_CLASS = "javacc.Main"; @@ -331,19 +331,16 @@ public class JavaCC extends Task { * Run the task. * @throws BuildException on error. */ + @Override public void execute() throws BuildException { // load command line with optional attributes - Enumeration iter = optionalAttrs.keys(); - while (iter.hasMoreElements()) { - String name = (String) iter.nextElement(); - Object value = optionalAttrs.get(name); - cmdl.createArgument().setValue("-" + name + ":" + value.toString()); - } + optionalAttrs.forEach((name, value) -> cmdl.createArgument() + .setValue("-" + name + ":" + value)); // check the target is a file if (targetFile == null || !targetFile.isFile()) { - throw new BuildException("Invalid target: " + targetFile); + throw new BuildException("Invalid target: %s", targetFile); } // use the directory containing the target as the output directory @@ -523,8 +520,9 @@ public class JavaCC extends Task { } } - throw new BuildException("Could not find a path to JavaCC.zip " - + "or javacc.jar from '" + home + "'."); + throw new BuildException( + "Could not find a path to JavaCC.zip or javacc.jar from '%s'.", + home); } /** http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/optional/javah/JavahAdapterFactory.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/javah/JavahAdapterFactory.java b/src/main/org/apache/tools/ant/taskdefs/optional/javah/JavahAdapterFactory.java index 481a97d..2244e5b 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/javah/JavahAdapterFactory.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/javah/JavahAdapterFactory.java @@ -42,7 +42,8 @@ public class JavahAdapterFactory { public static String getDefault() { if (JavaEnvUtils.isKaffe()) { return Kaffeh.IMPLEMENTATION_NAME; - } else if (JavaEnvUtils.isGij()) { + } + if (JavaEnvUtils.isGij()) { return Gcjh.IMPLEMENTATION_NAME; } return ForkingJavah.IMPLEMENTATION_NAME; @@ -84,20 +85,23 @@ public class JavahAdapterFactory { if ((JavaEnvUtils.isKaffe() && choice == null) || Kaffeh.IMPLEMENTATION_NAME.equals(choice)) { return new Kaffeh(); - } else if ((JavaEnvUtils.isGij() && choice == null) + } + if ((JavaEnvUtils.isGij() && choice == null) || Gcjh.IMPLEMENTATION_NAME.equals(choice)) { return new Gcjh(); - } else if (ForkingJavah.IMPLEMENTATION_NAME.equals(choice)) { + } + if (ForkingJavah.IMPLEMENTATION_NAME.equals(choice)) { return new ForkingJavah(); - } else if (SunJavah.IMPLEMENTATION_NAME.equals(choice)) { + } + if (SunJavah.IMPLEMENTATION_NAME.equals(choice)) { return new SunJavah(); - } else if (choice != null) { + } + if (choice != null) { return resolveClassName(choice, // Memory leak in line below log.getProject() .createClassLoader(classpath)); } - return new ForkingJavah(); } @@ -113,7 +117,7 @@ public class JavahAdapterFactory { private static JavahAdapter resolveClassName(String className, ClassLoader loader) throws BuildException { - return (JavahAdapter) ClasspathUtils.newInstance(className, + return ClasspathUtils.newInstance(className, loader != null ? loader : JavahAdapterFactory.class.getClassLoader(), JavahAdapter.class); } http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/optional/javah/SunJavah.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/javah/SunJavah.java b/src/main/org/apache/tools/ant/taskdefs/optional/javah/SunJavah.java index 7911b17..dbfd05c 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/javah/SunJavah.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/javah/SunJavah.java @@ -44,10 +44,11 @@ public class SunJavah implements JavahAdapter { * @throws BuildException if there is an error. * @since Ant 1.6.3 */ + @Override public boolean compile(Javah javah) throws BuildException { Commandline cmd = setupJavahCommand(javah); ExecuteJava ej = new ExecuteJava(); - Class c = null; + Class<?> c; try { try { // first search for the "old" javah class in 1.4.2 tools.jar
