You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bo...@apache.org on 2016/03/29 11:04:29 UTC

[1/3] ant git commit: even more FileUtils.close and try-with-resources cases

Repository: ant
Updated Branches:
  refs/heads/master d3a67a363 -> f7f58eeec


even more FileUtils.close and try-with-resources cases


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

Branch: refs/heads/master
Commit: 0906b0ad946dfea4732e15bfa389d3deec1be63d
Parents: d3a67a3
Author: Stefan Bodewig <bo...@apache.org>
Authored: Tue Mar 29 10:50:07 2016 +0200
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Tue Mar 29 10:50:07 2016 +0200

----------------------------------------------------------------------
 src/main/org/apache/tools/ant/AntClassLoader.java       |  7 +------
 .../org/apache/tools/ant/taskdefs/LogStreamHandler.java | 10 +++-------
 src/main/org/apache/tools/ant/taskdefs/SQLExec.java     | 12 ++----------
 .../org/apache/tools/ant/taskdefs/condition/Socket.java |  9 ++-------
 .../ant/taskdefs/cvslib/RedirectingStreamHandler.java   | 10 +++-------
 .../apache/tools/ant/util/depend/AbstractAnalyzer.java  |  8 +-------
 6 files changed, 12 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant/blob/0906b0ad/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 61cacce..103b118 100644
--- a/src/main/org/apache/tools/ant/AntClassLoader.java
+++ b/src/main/org/apache/tools/ant/AntClassLoader.java
@@ -1407,12 +1407,7 @@ public class AntClassLoader extends ClassLoader implements SubBuildListener {
      */
     public synchronized void cleanup() {
         for (final Enumeration<JarFile> e = jarFiles.elements(); e.hasMoreElements();) {
-            final JarFile jarFile = e.nextElement();
-            try {
-                jarFile.close();
-            } catch (final IOException ioe) {
-                // ignore
-            }
+            FileUtils.close(e.nextElement());
         }
         jarFiles = new Hashtable<File, JarFile>();
         if (project != null) {

http://git-wip-us.apache.org/repos/asf/ant/blob/0906b0ad/src/main/org/apache/tools/ant/taskdefs/LogStreamHandler.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/LogStreamHandler.java b/src/main/org/apache/tools/ant/taskdefs/LogStreamHandler.java
index ed16cf3..bc69c06 100644
--- a/src/main/org/apache/tools/ant/taskdefs/LogStreamHandler.java
+++ b/src/main/org/apache/tools/ant/taskdefs/LogStreamHandler.java
@@ -23,6 +23,7 @@ import java.io.IOException;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.ProjectComponent;
 import org.apache.tools.ant.Task;
+import org.apache.tools.ant.util.FileUtils;
 
 /**
  * Logs standard output and error of a subprocess to the log system of ant.
@@ -59,12 +60,7 @@ public class LogStreamHandler extends PumpStreamHandler {
      */
     public void stop() {
         super.stop();
-        try {
-            getErr().close();
-            getOut().close();
-        } catch (IOException e) {
-            // plain impossible
-            throw new BuildException(e);
-        }
+        FileUtils.close(getErr());
+        FileUtils.close(getOut());
     }
 }

http://git-wip-us.apache.org/repos/asf/ant/blob/0906b0ad/src/main/org/apache/tools/ant/taskdefs/SQLExec.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/SQLExec.java b/src/main/org/apache/tools/ant/taskdefs/SQLExec.java
index 6debd6d..c4076bc 100644
--- a/src/main/org/apache/tools/ant/taskdefs/SQLExec.java
+++ b/src/main/org/apache/tools/ant/taskdefs/SQLExec.java
@@ -692,19 +692,11 @@ public class SQLExec extends JDBCTask {
                 }
             } finally {
                 try {
-                    if (getStatement() != null) {
-                        getStatement().close();
-                    }
-                } catch (SQLException ex) {
-                    // ignore
-                }
-                try {
-                    if (getConnection() != null) {
-                        getConnection().close();
-                    }
+                    FileUtils.close(getStatement());
                 } catch (SQLException ex) {
                     // ignore
                 }
+                FileUtils.close(getConnection());
             }
 
             log(goodSql + " of " + totalSql + " SQL statements executed successfully");

http://git-wip-us.apache.org/repos/asf/ant/blob/0906b0ad/src/main/org/apache/tools/ant/taskdefs/condition/Socket.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/condition/Socket.java b/src/main/org/apache/tools/ant/taskdefs/condition/Socket.java
index d6a69ec..43a40e0 100644
--- a/src/main/org/apache/tools/ant/taskdefs/condition/Socket.java
+++ b/src/main/org/apache/tools/ant/taskdefs/condition/Socket.java
@@ -23,6 +23,7 @@ import java.io.IOException;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.ProjectComponent;
+import org.apache.tools.ant.util.FileUtils;
 
 /**
  * Condition to wait for a TCP/IP socket to have a listener. Its attributes are:
@@ -73,13 +74,7 @@ public class Socket extends ProjectComponent implements Condition {
         } catch (IOException e) {
             return false;
         } finally {
-          if (s != null) {
-            try {
-              s.close();
-            } catch (IOException ioe) {
-              // Intentionally left blank
-            }
-          }
+            FileUtils.close(s);
         }
         return true;
     }

http://git-wip-us.apache.org/repos/asf/ant/blob/0906b0ad/src/main/org/apache/tools/ant/taskdefs/cvslib/RedirectingStreamHandler.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/cvslib/RedirectingStreamHandler.java b/src/main/org/apache/tools/ant/taskdefs/cvslib/RedirectingStreamHandler.java
index 713de0c..e9b755d 100644
--- a/src/main/org/apache/tools/ant/taskdefs/cvslib/RedirectingStreamHandler.java
+++ b/src/main/org/apache/tools/ant/taskdefs/cvslib/RedirectingStreamHandler.java
@@ -22,6 +22,7 @@ import java.io.IOException;
 
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.taskdefs.PumpStreamHandler;
+import org.apache.tools.ant.util.FileUtils;
 
 /**
  * A dummy stream handler that just passes stuff to the parser.
@@ -49,13 +50,8 @@ class RedirectingStreamHandler
 
     public void stop() {
         super.stop();
-        try {
-            getErr().close();
-            getOut().close();
-        } catch (final IOException e) {
-            // plain impossible
-            throw new BuildException(e);
-        }
+        FileUtils.close(getErr());
+        FileUtils.close(getOut());
     }
 }
 

http://git-wip-us.apache.org/repos/asf/ant/blob/0906b0ad/src/main/org/apache/tools/ant/util/depend/AbstractAnalyzer.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/util/depend/AbstractAnalyzer.java b/src/main/org/apache/tools/ant/util/depend/AbstractAnalyzer.java
index 5c95d75..eb5f97a 100644
--- a/src/main/org/apache/tools/ant/util/depend/AbstractAnalyzer.java
+++ b/src/main/org/apache/tools/ant/util/depend/AbstractAnalyzer.java
@@ -267,16 +267,10 @@ public abstract class AbstractAnalyzer implements DependencyAnalyzer {
                 }
             } else {
                 // must be a zip of some sort
-                ZipFile zipFile = null;
-                try {
-                    zipFile = new ZipFile(element);
+                try (ZipFile zipFile = new ZipFile(element)) {
                     if (zipFile.getEntry(resourceLocation) != null) {
                         return element;
                     }
-                } finally {
-                    if (zipFile != null) {
-                        zipFile.close();
-                    }
                 }
             }
         }


[3/3] ant git commit: implement Closeable in ZipFile to be compatible with 1.9.7

Posted by bo...@apache.org.
implement Closeable in ZipFile to be compatible with 1.9.7


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

Branch: refs/heads/master
Commit: f7f58eeec17ba406384d992ccf0d3b00e073dedb
Parents: 311138d
Author: Stefan Bodewig <bo...@apache.org>
Authored: Tue Mar 29 11:03:56 2016 +0200
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Tue Mar 29 11:03:56 2016 +0200

----------------------------------------------------------------------
 src/main/org/apache/tools/zip/ZipFile.java | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant/blob/f7f58eee/src/main/org/apache/tools/zip/ZipFile.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/zip/ZipFile.java b/src/main/org/apache/tools/zip/ZipFile.java
index 20d8c43..f342310 100644
--- a/src/main/org/apache/tools/zip/ZipFile.java
+++ b/src/main/org/apache/tools/zip/ZipFile.java
@@ -24,6 +24,7 @@ import static org.apache.tools.zip.ZipConstants.WORD;
 import static org.apache.tools.zip.ZipConstants.ZIP64_MAGIC;
 import static org.apache.tools.zip.ZipConstants.ZIP64_MAGIC_SHORT;
 
+import java.io.Closeable;
 import java.io.EOFException;
 import java.io.File;
 import java.io.IOException;
@@ -72,7 +73,7 @@ import java.util.zip.ZipException;
  * </ul>
  *
  */
-public class ZipFile implements AutoCloseable {
+public class ZipFile implements Closeable {
     private static final int HASH_SIZE = 509;
     static final int NIBLET_MASK = 0x0f;
     static final int BYTE_SHIFT = 8;


[2/3] ant git commit: whitespace

Posted by bo...@apache.org.
whitespace


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

Branch: refs/heads/master
Commit: 311138d0aa08502d6bd1481c2488b4b9902874b5
Parents: 0906b0a
Author: Stefan Bodewig <bo...@apache.org>
Authored: Tue Mar 29 11:03:02 2016 +0200
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Tue Mar 29 11:03:02 2016 +0200

----------------------------------------------------------------------
 .../ant/taskdefs/optional/XMLValidateTask.java  | 54 ++++++++++----------
 1 file changed, 26 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant/blob/311138d0/src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java b/src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java
index 05c043d..26b49a2 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/XMLValidateTask.java
@@ -287,42 +287,40 @@ public class XMLValidateTask extends Task {
      */
     public void execute() throws BuildException {
         try {
-        int fileProcessed = 0;
-        if (file == null && (filesets.size() == 0)) {
-            throw new BuildException(
-                "Specify at least one source - " + "a file or a fileset.");
-        }
-
-
+            int fileProcessed = 0;
+            if (file == null && (filesets.size() == 0)) {
+                throw new BuildException(
+                    "Specify at least one source - " + "a file or a fileset.");
+            }
 
-        if (file != null) {
-            if (file.exists() && file.canRead() && file.isFile()) {
-                doValidate(file);
-                fileProcessed++;
-            } else {
-                String errorMsg = "File " + file + " cannot be read";
-                if (failOnError) {
-                    throw new BuildException(errorMsg);
+            if (file != null) {
+                if (file.exists() && file.canRead() && file.isFile()) {
+                    doValidate(file);
+                    fileProcessed++;
                 } else {
-                    log(errorMsg, Project.MSG_ERR);
+                    String errorMsg = "File " + file + " cannot be read";
+                    if (failOnError) {
+                        throw new BuildException(errorMsg);
+                    } else {
+                        log(errorMsg, Project.MSG_ERR);
+                    }
                 }
             }
-        }
 
-        final int size = filesets.size();
-        for (int i = 0; i < size; i++) {
+            final int size = filesets.size();
+            for (int i = 0; i < size; i++) {
 
-            FileSet fs = (FileSet) filesets.elementAt(i);
-            DirectoryScanner ds = fs.getDirectoryScanner(getProject());
-            String[] files = ds.getIncludedFiles();
+                FileSet fs = (FileSet) filesets.elementAt(i);
+                DirectoryScanner ds = fs.getDirectoryScanner(getProject());
+                String[] files = ds.getIncludedFiles();
 
-            for (int j = 0; j < files.length; j++) {
-                File srcFile = new File(fs.getDir(getProject()), files[j]);
-                doValidate(srcFile);
-                fileProcessed++;
+                for (int j = 0; j < files.length; j++) {
+                    File srcFile = new File(fs.getDir(getProject()), files[j]);
+                    doValidate(srcFile);
+                    fileProcessed++;
+                }
             }
-        }
-        onSuccessfulValidation(fileProcessed);
+            onSuccessfulValidation(fileProcessed);
         } finally {
             cleanup();
         }