You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by gi...@apache.org on 2018/11/17 10:59:40 UTC

[1/3] ant git commit: Make CharSet backwards compatible

Repository: ant
Updated Branches:
  refs/heads/master fbfad85ae -> 1e30b48a0


Make CharSet backwards compatible

Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/ab13b876
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/ab13b876
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/ab13b876

Branch: refs/heads/master
Commit: ab13b876c6cca733449a5b2a4bf3386f3013ddd2
Parents: fbfad85
Author: Gintas Grigelionis <gi...@apache.org>
Authored: Sat Nov 17 11:23:03 2018 +0100
Committer: Gintas Grigelionis <gi...@apache.org>
Committed: Sat Nov 17 11:24:24 2018 +0100

----------------------------------------------------------------------
 .../org/apache/tools/ant/types/CharSet.java     | 47 ++++++++++++++++++++
 .../tools/ant/types/EnumeratedAttribute.java    |  2 +-
 .../org/apache/tools/ant/types/CharSetTest.java | 46 +++++++++++++++++--
 3 files changed, 91 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant/blob/ab13b876/src/main/org/apache/tools/ant/types/CharSet.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/CharSet.java b/src/main/org/apache/tools/ant/types/CharSet.java
index ed41230..d55af40 100644
--- a/src/main/org/apache/tools/ant/types/CharSet.java
+++ b/src/main/org/apache/tools/ant/types/CharSet.java
@@ -18,7 +18,9 @@
 package org.apache.tools.ant.types;
 
 import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 
@@ -60,6 +62,30 @@ public class CharSet extends EnumeratedAttribute {
     }
 
     /**
+     * Convenience methood: get US-ASCII CharSet.
+     * @return the default value.
+     */
+    public static CharSet getAscii() {
+        return new CharSet(StandardCharsets.US_ASCII.name());
+    }
+
+    /**
+     * Convenience method: get UTF-8 CharSet.
+     * @return the default value.
+     */
+    public static CharSet getUtf8() {
+        return new CharSet(StandardCharsets.UTF_8.name());
+    }
+
+    /**
+     * Tell if CharSet values are aliases.
+     * @return true if CharSet values are aliases.
+     */
+    public boolean equivalent(CharSet cs) {
+        return getCharset().name().equals(cs.getCharset().name());
+    }
+
+    /**
      * Convert this enumerated type to a <code>Charset</code>.
      * @return a <code>Charset</code> object.
      */
@@ -75,4 +101,25 @@ public class CharSet extends EnumeratedAttribute {
     public String[] getValues() {
         return VALUES.toArray(new String[0]);
     }
+
+    /**
+     * Accept additional values for backwards compatibility
+     * (some java.io encoding names not available in java.nio)
+     * @param value the <code>String</code> value of the attribute
+     */
+    @Override
+    public final void setValue(final String value) {
+        String realValue = value;
+        if (value == null || value.isEmpty()) {
+           realValue = Charset.defaultCharset().name();
+       } else {
+           for (String v : Arrays.asList(value, value.toLowerCase(), value.toUpperCase())) {
+               if (VALUES.contains(v)) {
+                   realValue = v;
+                   break;
+               }
+           }
+        }
+        super.setValue(realValue);
+    }
 }

http://git-wip-us.apache.org/repos/asf/ant/blob/ab13b876/src/main/org/apache/tools/ant/types/EnumeratedAttribute.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/EnumeratedAttribute.java b/src/main/org/apache/tools/ant/types/EnumeratedAttribute.java
index dac3966..80884c3 100644
--- a/src/main/org/apache/tools/ant/types/EnumeratedAttribute.java
+++ b/src/main/org/apache/tools/ant/types/EnumeratedAttribute.java
@@ -88,7 +88,7 @@ public abstract class EnumeratedAttribute {
      * @param value the <code>String</code> value of the attribute
      * @throws BuildException if the value is not valid for the attribute
      */
-    public final void setValue(String value) throws BuildException {
+    public void setValue(String value) throws BuildException {
         int idx = indexOfValue(value);
         if (idx == -1) {
             throw new BuildException(value + " is not a legal value for this attribute");

http://git-wip-us.apache.org/repos/asf/ant/blob/ab13b876/src/tests/junit/org/apache/tools/ant/types/CharSetTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/types/CharSetTest.java b/src/tests/junit/org/apache/tools/ant/types/CharSetTest.java
index 47d8021..16dda9f 100644
--- a/src/tests/junit/org/apache/tools/ant/types/CharSetTest.java
+++ b/src/tests/junit/org/apache/tools/ant/types/CharSetTest.java
@@ -27,7 +27,10 @@ import java.util.Arrays;
 import java.util.Collection;
 
 import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.equalToIgnoringCase;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
 
 @RunWith(Enclosed.class)
 public class CharSetTest {
@@ -37,7 +40,10 @@ public class CharSetTest {
         // requires JUnit 4.12
         @Parameterized.Parameters(name = "legal argument: |{0}|")
         public static Collection<String> data() {
-            return Arrays.asList("UTF-8", "ISO-8859-1", "037", "us", "IBM500");
+            return Arrays.asList("UTF-8", "ISO-8859-1", "037", "us", "IBM500",
+                    // some java.io encodings are not provided as aliases in java.nio.charset
+                    // so, for backwards compatibility, the case should not matter
+                    "ascii", "utf-8", "Cp1252");
         }
 
         @Parameterized.Parameter
@@ -46,7 +52,7 @@ public class CharSetTest {
         @Test
         public void testCorrectNames() {
             CharSet cs = new CharSet(argument);
-            assertThat(argument, equalTo(cs.getValue()));
+            assertThat(argument, equalToIgnoringCase(cs.getValue()));
         }
     }
 
@@ -63,7 +69,41 @@ public class CharSetTest {
 
         @Test(expected = BuildException.class)
         public void testNonExistentNames() {
-            new CharSet().setValue(argument);
+            new CharSet(argument);
+        }
+    }
+
+    @RunWith(Parameterized.class)
+    public static class LegalEquivalenceTest {
+        // requires JUnit 4.12
+        @Parameterized.Parameters(name = "equivalent argument: |{0}|")
+        public static Collection<String> data() {
+            return Arrays.asList("UTF8", "unicode-1-1-utf-8");
+        }
+
+        @Parameterized.Parameter
+        public String argument;
+
+        @Test
+        public void testCorrectNames() {
+            assertTrue(new CharSet(argument).equivalent(CharSet.getUtf8()));
+        }
+    }
+
+    @RunWith(Parameterized.class)
+    public static class IncorrectEquivalenceTest {
+        // requires JUnit 4.12
+        @Parameterized.Parameters(name = "non-equivalent argument: |{0}|")
+        public static Collection<String> data() {
+            return Arrays.asList("us", "ISO-8859-1", "default");
+        }
+
+        @Parameterized.Parameter
+        public String argument;
+
+        @Test
+        public void testIncorrectNames() {
+            assertFalse(new CharSet(argument).equivalent(CharSet.getUtf8()));
         }
     }
 


[2/3] ant git commit: Update javadoc

Posted by gi...@apache.org.
Update javadoc

Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/1078b579
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/1078b579
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/1078b579

Branch: refs/heads/master
Commit: 1078b579044e16c0e1d8fb5f52be665104fad51f
Parents: ab13b87
Author: Gintas Grigelionis <gi...@apache.org>
Authored: Sat Nov 17 11:33:25 2018 +0100
Committer: Gintas Grigelionis <gi...@apache.org>
Committed: Sat Nov 17 11:33:25 2018 +0100

----------------------------------------------------------------------
 .../org/apache/tools/ant/taskdefs/condition/IsLastModified.java  | 1 +
 .../optional/junitlauncher/confined/ListenerDefinition.java      | 4 ++++
 2 files changed, 5 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant/blob/1078b579/src/main/org/apache/tools/ant/taskdefs/condition/IsLastModified.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/condition/IsLastModified.java b/src/main/org/apache/tools/ant/taskdefs/condition/IsLastModified.java
index cd2cb65..7c52d62 100644
--- a/src/main/org/apache/tools/ant/taskdefs/condition/IsLastModified.java
+++ b/src/main/org/apache/tools/ant/taskdefs/condition/IsLastModified.java
@@ -208,6 +208,7 @@ public class IsLastModified extends ProjectComponent implements Condition {
             setValue(s);
         }
 
+        /** {@inheritDoc}. */
         @Override
         public String[] getValues() {
             return new String[] {

http://git-wip-us.apache.org/repos/asf/ant/blob/1078b579/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/confined/ListenerDefinition.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/confined/ListenerDefinition.java b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/confined/ListenerDefinition.java
index 9eaf147..fea8c79 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/confined/ListenerDefinition.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/confined/ListenerDefinition.java
@@ -156,8 +156,12 @@ public class ListenerDefinition {
         return propertyHelper.testIfCondition(this.ifProperty) && propertyHelper.testUnlessCondition(this.unlessProperty);
     }
 
+    /**
+     * defines available listener types.
+     */
     public static class ListenerType extends EnumeratedAttribute {
 
+        /** {@inheritDoc}. */
         @Override
         public String[] getValues() {
             return new String[]{LEGACY_PLAIN, LEGACY_BRIEF, LEGACY_XML};


Re: [3/3] ant git commit: Use try-with-resources

Posted by Stefan Bodewig <bo...@apache.org>.
On 2018-11-18, Stefan Bodewig wrote:

> In Manifest

>>      /** Encoding to be used for JAR files. */
>> -    public static final String JAR_ENCODING = "UTF-8";
>>>    public static final Charset JAR_ENCODING = StandardCharsets.UTF_8;

> chnages the type of a public constant which is not backwards
> compatible. Besides, this really is not related to try-with-resources at
> all.

> Please revert this part.

Just saw you've already taken care of this part in your next commit.
Thank you.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: [3/3] ant git commit: Use try-with-resources

Posted by Stefan Bodewig <bo...@apache.org>.
On 2018-11-17, <gi...@apache.org> wrote:

in EchoXml

> -        } catch (BuildException e) {
> -            throw e;
> -        } catch (Exception e) {
> +        } catch (IOException e) {
>              throw new BuildException(e);

before your change we'd wrap arbitrary RuntimeExceptions into
BuildExceptions, after your change they'll just escape the method
unwrapped.

Please revert this part.

In Manifest

>      /** Encoding to be used for JAR files. */
> -    public static final String JAR_ENCODING = "UTF-8";
> +    public static final Charset JAR_ENCODING = StandardCharsets.UTF_8;

chnages the type of a public constant which is not backwards
compatible. Besides, this really is not related to try-with-resources at
all.

Please revert this part.

In AntAnalyzer

> -                    ZipFile zipFile = null;
> -                    InputStream inStream = null;
> -                    try {
...
> +                    try (InputStream inStream = container.getName().endsWith(".class")
> +                            ? Files.newInputStream(Paths.get(container.getPath()))
> +                            : new ZipFile(container.getPath()).getInputStream(new ZipEntry(
> +                                    classname.replace('.', '/') + ".class"))) {

I believe this will not close the ZipFile (which implements
AutoCloseable itself). Please ensure it is closes when needed.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


[3/3] ant git commit: Use try-with-resources

Posted by gi...@apache.org.
Use try-with-resources

Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/1e30b48a
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/1e30b48a
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/1e30b48a

Branch: refs/heads/master
Commit: 1e30b48a0ef0977f0daa492ee7d811c40d589e6e
Parents: 1078b57
Author: Gintas Grigelionis <gi...@apache.org>
Authored: Sat Nov 17 11:46:26 2018 +0100
Committer: Gintas Grigelionis <gi...@apache.org>
Committed: Sat Nov 17 11:46:26 2018 +0100

----------------------------------------------------------------------
 .../org/apache/tools/ant/AntClassLoader.java    |  6 +---
 .../tools/ant/ArgumentProcessorRegistry.java    |  8 +----
 .../org/apache/tools/ant/ComponentHelper.java   |  7 +----
 src/main/org/apache/tools/ant/Main.java         |  6 +---
 .../tools/ant/helper/ProjectHelperImpl.java     | 22 ++++++--------
 .../org/apache/tools/ant/taskdefs/EchoXML.java  | 28 +++++++-----------
 .../org/apache/tools/ant/taskdefs/Jikes.java    | 27 +++++------------
 .../org/apache/tools/ant/taskdefs/Manifest.java | 31 +++++++-------------
 .../org/apache/tools/ant/taskdefs/Property.java | 27 +++++------------
 .../tools/ant/taskdefs/compilers/Javac12.java   |  6 +---
 .../tools/ant/taskdefs/email/Message.java       |  3 +-
 .../ant/taskdefs/optional/TraXLiaison.java      | 19 ++++--------
 .../taskdefs/optional/depend/AntAnalyzer.java   | 19 +++---------
 .../optional/junit/JUnitTestRunner.java         | 18 +++---------
 .../modifiedselector/HashvalueAlgorithm.java    | 12 +++-----
 .../org/apache/tools/ant/util/FileUtils.java    |  1 -
 16 files changed, 67 insertions(+), 173 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant/blob/1e30b48a/src/main/org/apache/tools/ant/AntClassLoader.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/AntClassLoader.java b/src/main/org/apache/tools/ant/AntClassLoader.java
index db4df96..3ab7c62 100644
--- a/src/main/org/apache/tools/ant/AntClassLoader.java
+++ b/src/main/org/apache/tools/ant/AntClassLoader.java
@@ -1343,9 +1343,7 @@ public class AntClassLoader extends ClassLoader implements SubBuildListener, Clo
         // we can find the class we want.
         final String classFilename = getClassFilename(name);
         for (final File pathComponent : pathComponents) {
-            InputStream stream = null;
-            try {
-                stream = getResourceStream(pathComponent, classFilename);
+            try (InputStream stream = getResourceStream(pathComponent, classFilename)) {
                 if (stream != null) {
                     log("Loaded from " + pathComponent + " "
                         + classFilename, Project.MSG_DEBUG);
@@ -1357,8 +1355,6 @@ public class AntClassLoader extends ClassLoader implements SubBuildListener, Clo
                 // ioe.printStackTrace();
                 log("Exception reading component " + pathComponent + " (reason: "
                     + ioe.getMessage() + ")", Project.MSG_VERBOSE);
-            } finally {
-                FileUtils.close(stream);
             }
         }
         throw new ClassNotFoundException(name);

http://git-wip-us.apache.org/repos/asf/ant/blob/1e30b48a/src/main/org/apache/tools/ant/ArgumentProcessorRegistry.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/ArgumentProcessorRegistry.java b/src/main/org/apache/tools/ant/ArgumentProcessorRegistry.java
index eb53c4f..fa58f4e 100644
--- a/src/main/org/apache/tools/ant/ArgumentProcessorRegistry.java
+++ b/src/main/org/apache/tools/ant/ArgumentProcessorRegistry.java
@@ -28,7 +28,6 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
-import org.apache.tools.ant.util.FileUtils;
 import org.apache.tools.ant.util.LoaderUtils;
 
 /**
@@ -146,16 +145,11 @@ public class ArgumentProcessorRegistry {
 
     private ArgumentProcessor getProcessorByService(InputStream is)
             throws IOException {
-        InputStreamReader isr = null;
-        try {
-            isr = new InputStreamReader(is, StandardCharsets.UTF_8);
-            BufferedReader rd = new BufferedReader(isr);
+        try (BufferedReader rd = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) {
             String processorClassName = rd.readLine();
             if (processorClassName != null && !processorClassName.isEmpty()) {
                 return getProcessor(processorClassName);
             }
-        } finally {
-            FileUtils.close(isr);
         }
         return null;
     }

http://git-wip-us.apache.org/repos/asf/ant/blob/1e30b48a/src/main/org/apache/tools/ant/ComponentHelper.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/ComponentHelper.java b/src/main/org/apache/tools/ant/ComponentHelper.java
index 28fa824..bdb6f11 100644
--- a/src/main/org/apache/tools/ant/ComponentHelper.java
+++ b/src/main/org/apache/tools/ant/ComponentHelper.java
@@ -40,7 +40,6 @@ import org.apache.tools.ant.launch.Launcher;
 import org.apache.tools.ant.taskdefs.Definer;
 import org.apache.tools.ant.taskdefs.Property;
 import org.apache.tools.ant.taskdefs.Typedef;
-import org.apache.tools.ant.util.FileUtils;
 
 /**
  * Component creation and configuration.
@@ -785,9 +784,7 @@ public class ComponentHelper  {
             String resource = type ? MagicNames.TYPEDEFS_PROPERTIES_RESOURCE
                     : MagicNames.TASKDEF_PROPERTIES_RESOURCE;
             String errorString = type ? ERROR_NO_TYPE_LIST_LOAD : ERROR_NO_TASK_LIST_LOAD;
-            InputStream in = null;
-            try {
-                in = ComponentHelper.class.getResourceAsStream(resource);
+            try (InputStream in = ComponentHelper.class.getResourceAsStream(resource)) {
                 if (in == null) {
                     throw new BuildException(errorString);
                 }
@@ -796,8 +793,6 @@ public class ComponentHelper  {
                 defaultDefinitions[idx] = p;
             } catch (IOException e) {
                 throw new BuildException(errorString, e);
-            } finally {
-                FileUtils.close(in);
             }
         }
         return defaultDefinitions[idx];

http://git-wip-us.apache.org/repos/asf/ant/blob/1e30b48a/src/main/org/apache/tools/ant/Main.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/Main.java b/src/main/org/apache/tools/ant/Main.java
index 4e078e0..1d42b87 100644
--- a/src/main/org/apache/tools/ant/Main.java
+++ b/src/main/org/apache/tools/ant/Main.java
@@ -637,15 +637,11 @@ public class Main implements AntMain {
     private void loadPropertyFiles() {
         for (final String filename : propertyFiles) {
             final Properties props = new Properties();
-            InputStream fis = null;
-            try {
-                fis = Files.newInputStream(Paths.get(filename));
+            try (InputStream fis = Files.newInputStream(Paths.get(filename))) {
                 props.load(fis);
             } catch (final IOException e) {
                 System.out.println("Could not load property file "
                                    + filename + ": " + e.getMessage());
-            } finally {
-                FileUtils.close(fis);
             }
 
             // ensure that -D properties take precedence

http://git-wip-us.apache.org/repos/asf/ant/blob/1e30b48a/src/main/org/apache/tools/ant/helper/ProjectHelperImpl.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/helper/ProjectHelperImpl.java b/src/main/org/apache/tools/ant/helper/ProjectHelperImpl.java
index e6461b6..388a2ff 100644
--- a/src/main/org/apache/tools/ant/helper/ProjectHelperImpl.java
+++ b/src/main/org/apache/tools/ant/helper/ProjectHelperImpl.java
@@ -113,22 +113,20 @@ public class ProjectHelperImpl extends ProjectHelper {
                 + "default plugin");
         }
         File bFile = (File) source;
-        InputStream inputStream = null;
-        InputSource inputSource = null;
 
         this.project = project;
         this.buildFile = new File(bFile.getAbsolutePath());
         buildFileParent = new File(this.buildFile.getParent());
 
         try {
-            try {
-                parser = JAXPUtils.getParser();
-            } catch (BuildException e) {
-                parser = new XMLReaderAdapter(JAXPUtils.getXMLReader());
-            }
+            parser = JAXPUtils.getParser();
+        } catch (BuildException e) {
+            parser = new XMLReaderAdapter(JAXPUtils.getXMLReader());
+        }
+
+        try (InputStream inputStream = Files.newInputStream(bFile.toPath())) {
             String uri = FILE_UTILS.toURI(bFile.getAbsolutePath());
-            inputStream = Files.newInputStream(bFile.toPath());
-            inputSource = new InputSource(inputStream);
+            InputSource inputSource = new InputSource(inputStream);
             inputSource.setSystemId(uri);
             project.log("parsing buildfile " + bFile + " with URI = " + uri, Project.MSG_VERBOSE);
             HandlerBase hb = new RootHandler(this);
@@ -138,8 +136,8 @@ public class ProjectHelperImpl extends ProjectHelper {
             parser.setDTDHandler(hb);
             parser.parse(inputSource);
         } catch (SAXParseException exc) {
-            Location location = new Location(exc.getSystemId(), exc.getLineNumber(), exc
-                    .getColumnNumber());
+            Location location = new Location(exc.getSystemId(), exc.getLineNumber(),
+                    exc.getColumnNumber());
 
             Throwable t = exc.getException();
             if (t instanceof BuildException) {
@@ -162,8 +160,6 @@ public class ProjectHelperImpl extends ProjectHelper {
             throw new BuildException("Encoding of project file is invalid.", exc);
         } catch (IOException exc) {
             throw new BuildException("Error reading project file: " + exc.getMessage(), exc);
-        } finally {
-            FileUtils.close(inputStream);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/ant/blob/1e30b48a/src/main/org/apache/tools/ant/taskdefs/EchoXML.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/EchoXML.java b/src/main/org/apache/tools/ant/taskdefs/EchoXML.java
index 91b6d8b..2f29948 100644
--- a/src/main/org/apache/tools/ant/taskdefs/EchoXML.java
+++ b/src/main/org/apache/tools/ant/taskdefs/EchoXML.java
@@ -18,6 +18,7 @@
 package org.apache.tools.ant.taskdefs;
 
 import java.io.File;
+import java.io.IOException;
 import java.io.OutputStream;
 
 import org.apache.tools.ant.BuildException;
@@ -76,26 +77,17 @@ public class EchoXML extends XMLFragment {
      * Execute the task.
      */
     public void execute() {
-        DOMElementWriter writer =
-            new DOMElementWriter(!append, namespacePolicy.getPolicy());
-        OutputStream os = null;
-        try {
-            if (file != null) {
-                os = FileUtils.newOutputStream(file.toPath(), append);
-            } else {
-                os = new LogOutputStream(this, Project.MSG_INFO);
-            }
-            Node n = getFragment().getFirstChild();
-            if (n == null) {
-                throw new BuildException(ERROR_NO_XML);
-            }
+        Node n = getFragment().getFirstChild();
+        if (n == null) {
+            throw new BuildException(ERROR_NO_XML);
+        }
+
+        DOMElementWriter writer = new DOMElementWriter(!append, namespacePolicy.getPolicy());
+        try (OutputStream os = (file == null) ? new LogOutputStream(this, Project.MSG_INFO)
+                : FileUtils.newOutputStream(file.toPath(), append)) {
             writer.write((Element) n, os);
-        } catch (BuildException e) {
-            throw e;
-        } catch (Exception e) {
+        } catch (IOException e) {
             throw new BuildException(e);
-        } finally {
-            FileUtils.close(os);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/ant/blob/1e30b48a/src/main/org/apache/tools/ant/taskdefs/Jikes.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/Jikes.java b/src/main/org/apache/tools/ant/taskdefs/Jikes.java
index 3896001..676cf8b 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Jikes.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Jikes.java
@@ -21,10 +21,10 @@ import java.io.BufferedWriter;
 import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
-import java.util.Locale;
 
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Project;
+import org.apache.tools.ant.taskdefs.condition.Os;
 import org.apache.tools.ant.util.FileUtils;
 
 /**
@@ -78,18 +78,12 @@ public class Jikes {
         File tmpFile = null;
 
         try {
-            String myos = System.getProperty("os.name");
-
             // Windows has a 32k limit on total arg size, so
             // create a temporary file to store all the arguments
-
-            if (myos.toLowerCase(Locale.ENGLISH).contains("windows")
-                && args.length > MAX_FILES_ON_COMMAND_LINE) {
-                BufferedWriter out = null;
-                try {
-                    tmpFile = FileUtils.getFileUtils().createTempFile("jikes",
-                            "tmp", null, false, true);
-                    out = new BufferedWriter(new FileWriter(tmpFile));
+            if (Os.isFamily(Os.FAMILY_WINDOWS) && args.length > MAX_FILES_ON_COMMAND_LINE) {
+                tmpFile = FileUtils.getFileUtils().createTempFile("jikes",
+                        "tmp", null, false, true);
+                try (BufferedWriter out = new BufferedWriter(new FileWriter(tmpFile))) {
                     for (String arg : args) {
                         out.write(arg);
                         out.newLine();
@@ -98,10 +92,7 @@ public class Jikes {
                     commandArray = new String[] {command,
                                                "@" + tmpFile.getAbsolutePath()};
                 } catch (IOException e) {
-                    throw new BuildException("Error creating temporary file",
-                                             e);
-                } finally {
-                    FileUtils.close(out);
+                    throw new BuildException("Error creating temporary file", e);
                 }
             } else {
                 commandArray = new String[args.length + 1];
@@ -123,10 +114,8 @@ public class Jikes {
                 throw new BuildException("Error running Jikes compiler", e);
             }
         } finally {
-            if (tmpFile != null) {
-                if (!tmpFile.delete()) {
-                    tmpFile.deleteOnExit();
-                }
+            if (tmpFile != null && !tmpFile.delete()) {
+                tmpFile.deleteOnExit();
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/ant/blob/1e30b48a/src/main/org/apache/tools/ant/taskdefs/Manifest.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/Manifest.java b/src/main/org/apache/tools/ant/taskdefs/Manifest.java
index b3a37e2..3f17aed 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Manifest.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Manifest.java
@@ -25,7 +25,7 @@ import java.io.InputStreamReader;
 import java.io.PrintWriter;
 import java.io.Reader;
 import java.io.StringWriter;
-import java.io.UnsupportedEncodingException;
+import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
 import java.util.Collections;
 import java.util.Enumeration;
@@ -37,7 +37,6 @@ import java.util.Objects;
 import java.util.Vector;
 
 import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.util.FileUtils;
 import org.apache.tools.ant.util.StreamUtils;
 
 /**
@@ -93,7 +92,7 @@ public class Manifest {
                         + "with \"" + ATTRIBUTE_FROM + "\" in \"";
 
     /** Encoding to be used for JAR files. */
-    public static final String JAR_ENCODING = "UTF-8";
+    public static final Charset JAR_ENCODING = StandardCharsets.UTF_8;
 
     private static final String ATTRIBUTE_MANIFEST_VERSION_LC =
         ATTRIBUTE_MANIFEST_VERSION.toLowerCase(Locale.ENGLISH);
@@ -751,35 +750,25 @@ public class Manifest {
      *            default manifest
      */
     public static Manifest getDefaultManifest() throws BuildException {
-        InputStreamReader insr = null;
         String defManifest = "/org/apache/tools/ant/defaultManifest.mf";
         try (InputStream in = Manifest.class.getResourceAsStream(defManifest)) {
             if (in == null) {
                 throw new BuildException("Could not find default manifest: %s",
                     defManifest);
             }
-            try {
-                insr = new InputStreamReader(in, StandardCharsets.UTF_8);
-                Manifest defaultManifest = new Manifest(insr);
-                String version = System.getProperty("java.runtime.version");
-                if (version == null) {
-                    version = System.getProperty("java.vm.version");
-                }
-                Attribute createdBy = new Attribute("Created-By",
-                    version + " ("
-                    + System.getProperty("java.vm.vendor") + ")");
-                defaultManifest.getMainSection().storeAttribute(createdBy);
-                return defaultManifest;
-            } catch (UnsupportedEncodingException e) {
-                insr = new InputStreamReader(in);
-                return new Manifest(insr);
+            Manifest defaultManifest = new Manifest(new InputStreamReader(in, JAR_ENCODING));
+            String version = System.getProperty("java.runtime.version");
+            if (version == null) {
+                version = System.getProperty("java.vm.version");
             }
+            Attribute createdBy = new Attribute("Created-By", version
+                    + " (" + System.getProperty("java.vm.vendor") + ")");
+            defaultManifest.getMainSection().storeAttribute(createdBy);
+            return defaultManifest;
         } catch (ManifestException e) {
             throw new BuildException("Default manifest is invalid !!", e);
         } catch (IOException e) {
             throw new BuildException("Unable to read default manifest", e);
-        } finally {
-            FileUtils.close(insr);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/ant/blob/1e30b48a/src/main/org/apache/tools/ant/taskdefs/Property.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/Property.java b/src/main/org/apache/tools/ant/taskdefs/Property.java
index 3178796..34455a0 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Property.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Property.java
@@ -648,33 +648,20 @@ public class Property extends Task {
     protected void loadResource(String name) {
         Properties props = new Properties();
         log("Resource Loading " + name, Project.MSG_VERBOSE);
-        ClassLoader cL = null;
-        boolean cleanup = false;
-        if (classpath != null) {
-            cleanup = true;
-            cL = getProject().createClassLoader(classpath);
-        } else {
-            cL = this.getClass().getClassLoader();
-        }
-        InputStream is = null;
-        try {
-            if (cL == null) {
-                is = ClassLoader.getSystemResourceAsStream(name);
+        ClassLoader cL = (classpath == null) ? this.getClass().getClassLoader()
+                : getProject().createClassLoader(classpath);
+        try (InputStream is = (cL == null) ? ClassLoader.getSystemResourceAsStream(name)
+                : cL.getResourceAsStream(name)) {
+            if (is == null) {
+                log("Unable to find resource " + name, Project.MSG_WARN);
             } else {
-                is = cL.getResourceAsStream(name);
-            }
-
-            if (is != null) {
                 loadProperties(props, is, name.endsWith(".xml"));
                 addProperties(props);
-            } else {
-                log("Unable to find resource " + name, Project.MSG_WARN);
             }
         } catch (IOException ex) {
             throw new BuildException(ex, getLocation());
         } finally {
-            FileUtils.close(is);
-            if (cleanup && cL != null) {
+            if (classpath != null && cL != null) {
                 ((AntClassLoader) cL).cleanup();
             }
         }

http://git-wip-us.apache.org/repos/asf/ant/blob/1e30b48a/src/main/org/apache/tools/ant/taskdefs/compilers/Javac12.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/compilers/Javac12.java b/src/main/org/apache/tools/ant/taskdefs/compilers/Javac12.java
index 4c1a9a3..3c67777 100644
--- a/src/main/org/apache/tools/ant/taskdefs/compilers/Javac12.java
+++ b/src/main/org/apache/tools/ant/taskdefs/compilers/Javac12.java
@@ -26,7 +26,6 @@ import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.taskdefs.LogOutputStream;
 import org.apache.tools.ant.types.Commandline;
-import org.apache.tools.ant.util.FileUtils;
 import org.apache.tools.ant.util.JavaEnvUtils;
 
 /**
@@ -50,8 +49,7 @@ public class Javac12 extends DefaultCompilerAdapter {
         attributes.log("Using classic compiler", Project.MSG_VERBOSE);
         Commandline cmd = setupJavacCommand(true);
 
-        OutputStream logstr = new LogOutputStream(attributes, Project.MSG_WARN);
-        try {
+        try (OutputStream logstr = new LogOutputStream(attributes, Project.MSG_WARN)) {
             // Create an instance of the compiler, redirecting output to
             // the project log
             Class<?> c = Class.forName(CLASSIC_COMPILER_CLASSNAME);
@@ -78,8 +76,6 @@ public class Javac12 extends DefaultCompilerAdapter {
                 throw new BuildException("Error starting classic compiler: ",
                                          ex, location);
             }
-        } finally {
-            FileUtils.close(logstr);
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/ant/blob/1e30b48a/src/main/org/apache/tools/ant/taskdefs/email/Message.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/email/Message.java b/src/main/org/apache/tools/ant/taskdefs/email/Message.java
index fc07396..27a524a 100644
--- a/src/main/org/apache/tools/ant/taskdefs/email/Message.java
+++ b/src/main/org/apache/tools/ant/taskdefs/email/Message.java
@@ -119,8 +119,7 @@ public class Message extends ProjectComponent {
                     : new BufferedWriter(new OutputStreamWriter(ps, charset));
             if (messageSource != null) {
                 // Read message from a file
-                try (Reader freader = getReader(messageSource);
-                     BufferedReader in = new BufferedReader(freader)) {
+                try (BufferedReader in = new BufferedReader(getReader(messageSource))) {
                     String line;
                     while ((line = in.readLine()) != null) {
                         out.write(getProject().replaceProperties(line));

http://git-wip-us.apache.org/repos/asf/ant/blob/1e30b48a/src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java b/src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java
index ebfd501..bd02a3c 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java
@@ -187,27 +187,18 @@ public class TraXLiaison implements XSLTLiaison4, ErrorListener, XSLTLoggerAware
             createTransformer();
         }
 
-        InputStream fis = null;
-        OutputStream fos = null;
-        try {
-            fis = new BufferedInputStream(Files.newInputStream(infile.toPath()));
-            fos = new BufferedOutputStream(Files.newOutputStream(outfile.toPath()));
+        // autoclose all handles, otherwise the garbage collector will close them...
+        // and Windows may complain about not being able to delete files.
+        try (InputStream fis = new BufferedInputStream(Files.newInputStream(infile.toPath()));
+             OutputStream fos = new BufferedOutputStream(Files.newOutputStream(outfile.toPath()))) {
             final StreamResult res = new StreamResult(fos);
             // not sure what could be the need of this...
             res.setSystemId(JAXPUtils.getSystemId(outfile));
-            final Source src = getSource(fis, infile);
-
             // set parameters on each transformation, maybe something has changed
             //(e.g. value of file name parameter)
             setTransformationParameters();
 
-            transformer.transform(src, res);
-        } finally {
-            // make sure to close all handles, otherwise the garbage
-            // collector will close them...whenever possible and
-            // Windows may complain about not being able to delete files.
-            FileUtils.close(fis);
-            FileUtils.close(fos);
+            transformer.transform(getSource(fis, infile), res);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/ant/blob/1e30b48a/src/main/org/apache/tools/ant/taskdefs/optional/depend/AntAnalyzer.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/depend/AntAnalyzer.java b/src/main/org/apache/tools/ant/taskdefs/optional/depend/AntAnalyzer.java
index 6ddcd0b..b9c93fa 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/depend/AntAnalyzer.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/depend/AntAnalyzer.java
@@ -29,7 +29,6 @@ import java.util.Vector;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipFile;
 
-import org.apache.tools.ant.util.FileUtils;
 import org.apache.tools.ant.util.depend.AbstractAnalyzer;
 
 /**
@@ -69,23 +68,13 @@ public class AntAnalyzer extends AbstractAnalyzer {
                     }
                     containers.add(container);
 
-                    ZipFile zipFile = null;
-                    InputStream inStream = null;
-                    try {
-                        if (container.getName().endsWith(".class")) {
-                            inStream = Files.newInputStream(Paths.get(container.getPath()));
-                        } else {
-                            zipFile = new ZipFile(container.getPath());
-                            String entryName = classname.replace('.', '/') + ".class";
-                            ZipEntry entry = new ZipEntry(entryName);
-                            inStream = zipFile.getInputStream(entry);
-                        }
+                    try (InputStream inStream = container.getName().endsWith(".class")
+                            ? Files.newInputStream(Paths.get(container.getPath()))
+                            : new ZipFile(container.getPath()).getInputStream(new ZipEntry(
+                                    classname.replace('.', '/') + ".class"))) {
                         ClassFile classFile = new ClassFile();
                         classFile.read(inStream);
                         analyzedDeps.addAll(classFile.getClassRefs());
-                    } finally {
-                        FileUtils.close(inStream);
-                        FileUtils.close(zipFile);
                     }
                 } catch (IOException ioe) {
                     // ignore

http://git-wip-us.apache.org/repos/asf/ant/blob/1e30b48a/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java b/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java
index 7c0b0cd..da21ab6 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java
@@ -1203,28 +1203,18 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR
     private static void registerNonCrash()
             throws IOException {
         if (crashFile != null) {
-            FileWriter out = null;
-            try {
-                out = new FileWriter(crashFile);
+            try (FileWriter out = new FileWriter(crashFile)) {
                 out.write(Constants.TERMINATED_SUCCESSFULLY + "\n");
                 out.flush();
-            } finally {
-                FileUtils.close(out);
             }
         }
     }
 
     private static void registerTestCase(final String testCase) {
         if (crashFile != null) {
-            try {
-                FileWriter out = null;
-                try {
-                    out = new FileWriter(crashFile);
-                    out.write(testCase + "\n");
-                    out.flush();
-                } finally {
-                    FileUtils.close(out);
-                }
+            try (FileWriter out = new FileWriter(crashFile)) {
+                out.write(testCase + "\n");
+                out.flush();
             } catch (final IOException e) {
                 // ignored.
             }

http://git-wip-us.apache.org/repos/asf/ant/blob/1e30b48a/src/main/org/apache/tools/ant/types/selectors/modifiedselector/HashvalueAlgorithm.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/selectors/modifiedselector/HashvalueAlgorithm.java b/src/main/org/apache/tools/ant/types/selectors/modifiedselector/HashvalueAlgorithm.java
index ab8849d..c8c3749 100644
--- a/src/main/org/apache/tools/ant/types/selectors/modifiedselector/HashvalueAlgorithm.java
+++ b/src/main/org/apache/tools/ant/types/selectors/modifiedselector/HashvalueAlgorithm.java
@@ -53,18 +53,14 @@ public class HashvalueAlgorithm implements Algorithm {
      // Because the content is only read the file will not be damaged. I tested
      // with JPG, ZIP and PDF as binary files.
     public String getValue(File file) {
-        Reader r = null;
-        try {
-            if (!file.canRead()) {
-                return null;
-            }
-            r = new FileReader(file);
+        if (!file.canRead()) {
+            return null;
+        }
+        try (Reader r = new FileReader(file)) {
             int hash = FileUtils.readFully(r).hashCode();
             return Integer.toString(hash);
         } catch (Exception e) {
             return null;
-        } finally {
-            FileUtils.close(r);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/ant/blob/1e30b48a/src/main/org/apache/tools/ant/util/FileUtils.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/util/FileUtils.java b/src/main/org/apache/tools/ant/util/FileUtils.java
index 2bbd2f3..e6e7344 100644
--- a/src/main/org/apache/tools/ant/util/FileUtils.java
+++ b/src/main/org/apache/tools/ant/util/FileUtils.java
@@ -31,7 +31,6 @@ import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLConnection;
 import java.nio.channels.Channel;
-import java.nio.file.FileSystem;
 import java.nio.file.Files;
 import java.nio.file.NoSuchFileException;
 import java.nio.file.Path;