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/12/20 19:52:51 UTC
[1/6] ant git commit: Sonar false positives for resource leaks
Repository: ant
Updated Branches:
refs/heads/master 990a664c4 -> 2bb5b057d
Sonar false positives for resource leaks
Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/ac1b7652
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/ac1b7652
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/ac1b7652
Branch: refs/heads/master
Commit: ac1b7652ddd5f4e01eb7e3e5e58f9d22900229a0
Parents: 8925f08
Author: Stefan Bodewig <bo...@apache.org>
Authored: Tue Dec 20 20:37:53 2016 +0100
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Tue Dec 20 20:39:52 2016 +0100
----------------------------------------------------------------------
src/main/org/apache/tools/ant/Main.java | 5 ++++-
src/main/org/apache/tools/ant/taskdefs/Truncate.java | 4 ++--
src/main/org/apache/tools/ant/taskdefs/cvslib/CvsTagDiff.java | 2 +-
.../org/apache/tools/ant/taskdefs/optional/PropertyFile.java | 2 +-
.../org/apache/tools/ant/taskdefs/optional/ejb/IPlanetEjbc.java | 3 ++-
.../apache/tools/ant/taskdefs/optional/jdepend/JDependTask.java | 2 +-
.../tools/ant/types/selectors/ContainsRegexpSelector.java | 2 +-
.../org/apache/tools/ant/types/selectors/ContainsSelector.java | 4 ++--
src/main/org/apache/tools/ant/util/FileUtils.java | 2 +-
src/main/org/apache/tools/zip/ZipFile.java | 4 +++-
10 files changed, 18 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ant/blob/ac1b7652/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 edce9c1..81e4ef1 100644
--- a/src/main/org/apache/tools/ant/Main.java
+++ b/src/main/org/apache/tools/ant/Main.java
@@ -355,7 +355,10 @@ public class Main implements AntMain {
try {
final File logFile = new File(args[i + 1]);
i++;
- logTo = new PrintStream(new FileOutputStream(logFile));
+ // life-cycle of FileOutputStream is controlled by
+ // logTo which becomes "out" and is closed in
+ // handleLogfile
+ logTo = new PrintStream(new FileOutputStream(logFile)); //NOSONAR
isLogFileUsed = true;
} catch (final IOException ioe) {
final String msg = "Cannot write on the specified log file. "
http://git-wip-us.apache.org/repos/asf/ant/blob/ac1b7652/src/main/org/apache/tools/ant/taskdefs/Truncate.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/Truncate.java b/src/main/org/apache/tools/ant/taskdefs/Truncate.java
index 6f43c05..cb8fd4a 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Truncate.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Truncate.java
@@ -167,7 +167,7 @@ public class Truncate extends Task {
}
RandomAccessFile raf = null;
try {
- raf = new RandomAccessFile(f, READ_WRITE);
+ raf = new RandomAccessFile(f, READ_WRITE); //NOSONAR
} catch (Exception e) {
throw new BuildException("Could not open " + f + " for writing", e);
}
@@ -202,4 +202,4 @@ public class Truncate extends Task {
return path;
}
-}
\ No newline at end of file
+}
http://git-wip-us.apache.org/repos/asf/ant/blob/ac1b7652/src/main/org/apache/tools/ant/taskdefs/cvslib/CvsTagDiff.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/cvslib/CvsTagDiff.java b/src/main/org/apache/tools/ant/taskdefs/cvslib/CvsTagDiff.java
index a90bcc0..6f17402 100644
--- a/src/main/org/apache/tools/ant/taskdefs/cvslib/CvsTagDiff.java
+++ b/src/main/org/apache/tools/ant/taskdefs/cvslib/CvsTagDiff.java
@@ -299,7 +299,7 @@ public class CvsTagDiff extends AbstractCvsTask {
BufferedReader reader = null;
try {
- reader = new BufferedReader(new FileReader(tmpFile));
+ reader = new BufferedReader(new FileReader(tmpFile)); //NOSONAR
// entries are of the form:
//CVS 1.11
http://git-wip-us.apache.org/repos/asf/ant/blob/ac1b7652/src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java b/src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java
index 162cab1..7c778da 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java
@@ -260,7 +260,7 @@ public class PropertyFile extends Task {
throw new BuildException(x, getLocation());
}
try {
- OutputStream os = new FileOutputStream(propertyfile);
+ OutputStream os = new FileOutputStream(propertyfile); //NOSONAR
try {
try {
os.write(baos.toByteArray());
http://git-wip-us.apache.org/repos/asf/ant/blob/ac1b7652/src/main/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetEjbc.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetEjbc.java b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetEjbc.java
index 41e90d0..984fc37 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetEjbc.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetEjbc.java
@@ -727,7 +727,8 @@ public class IPlanetEjbc {
} else {
location = (String) fileDtds.get(publicId);
if (location != null) {
- inputStream = new FileInputStream(location);
+ // closed when the InputSource is closed
+ inputStream = new FileInputStream(location); //NOSONAR
}
}
} catch (IOException e) {
http://git-wip-us.apache.org/repos/asf/ant/blob/ac1b7652/src/main/org/apache/tools/ant/taskdefs/optional/jdepend/JDependTask.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/jdepend/JDependTask.java b/src/main/org/apache/tools/ant/taskdefs/optional/jdepend/JDependTask.java
index 21f03fe..9d2e9ae 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/jdepend/JDependTask.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/jdepend/JDependTask.java
@@ -459,7 +459,7 @@ public class JDependTask extends Task {
PrintWriter pw = null;
if (getOutputFile() != null) {
try {
- fw = new FileWriter(getOutputFile().getPath());
+ fw = new FileWriter(getOutputFile().getPath()); //NOSONAR
} catch (IOException e) {
String msg = "JDepend Failed when creating the output file: "
+ e.getMessage();
http://git-wip-us.apache.org/repos/asf/ant/blob/ac1b7652/src/main/org/apache/tools/ant/types/selectors/ContainsRegexpSelector.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/selectors/ContainsRegexpSelector.java b/src/main/org/apache/tools/ant/types/selectors/ContainsRegexpSelector.java
index 4da3b6f..334f37e 100644
--- a/src/main/org/apache/tools/ant/types/selectors/ContainsRegexpSelector.java
+++ b/src/main/org/apache/tools/ant/types/selectors/ContainsRegexpSelector.java
@@ -184,7 +184,7 @@ public class ContainsRegexpSelector extends BaseExtendSelector
}
try {
- in = new BufferedReader(new InputStreamReader(r.getInputStream()));
+ in = new BufferedReader(new InputStreamReader(r.getInputStream())); //NOSONAR
} catch (Exception e) {
throw new BuildException("Could not get InputStream from "
+ r.toLongString(), e);
http://git-wip-us.apache.org/repos/asf/ant/blob/ac1b7652/src/main/org/apache/tools/ant/types/selectors/ContainsSelector.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/selectors/ContainsSelector.java b/src/main/org/apache/tools/ant/types/selectors/ContainsSelector.java
index 6dabaf4..a1004a8 100644
--- a/src/main/org/apache/tools/ant/types/selectors/ContainsSelector.java
+++ b/src/main/org/apache/tools/ant/types/selectors/ContainsSelector.java
@@ -187,9 +187,9 @@ public class ContainsSelector extends BaseExtendSelector implements ResourceSele
BufferedReader in = null;
try {
if (encoding != null) {
- in = new BufferedReader(new InputStreamReader(r.getInputStream(), encoding));
+ in = new BufferedReader(new InputStreamReader(r.getInputStream(), encoding)); //NOSONAR
} else {
- in = new BufferedReader(new InputStreamReader(r.getInputStream()));
+ in = new BufferedReader(new InputStreamReader(r.getInputStream())); //NOSONAR
}
} catch (Exception e) {
throw new BuildException("Could not get InputStream from "
http://git-wip-us.apache.org/repos/asf/ant/blob/ac1b7652/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 bcef5ec..c2a60ed 100644
--- a/src/main/org/apache/tools/ant/util/FileUtils.java
+++ b/src/main/org/apache/tools/ant/util/FileUtils.java
@@ -1708,7 +1708,7 @@ public class FileUtils {
*/
public String getDefaultEncoding() {
InputStreamReader is = new InputStreamReader(
- new InputStream() {
+ new InputStream() { //NOSONAR
public int read() {
return -1;
}
http://git-wip-us.apache.org/repos/asf/ant/blob/ac1b7652/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 f342310..1be53cd 100644
--- a/src/main/org/apache/tools/zip/ZipFile.java
+++ b/src/main/org/apache/tools/zip/ZipFile.java
@@ -370,8 +370,10 @@ public class ZipFile implements Closeable {
final OffsetEntry offsetEntry = ((Entry) ze).getOffsetEntry();
ZipUtil.checkRequestedFeatures(ze);
final long start = offsetEntry.dataOffset;
+ // doesn't get closed if the method is not supported, but
+ // doesn't hold any resources either
final BoundedInputStream bis =
- new BoundedInputStream(start, ze.getCompressedSize());
+ new BoundedInputStream(start, ze.getCompressedSize()); //NOSONAR
switch (ze.getMethod()) {
case ZipEntry.STORED:
return bis;
[2/6] ant git commit: plug resource leaks detected by Sonar
Posted by bo...@apache.org.
plug resource leaks detected by Sonar
Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/032e888a
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/032e888a
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/032e888a
Branch: refs/heads/master
Commit: 032e888aace67eb95884b2ae40230f2656c4e0d0
Parents: ac1b765
Author: Stefan Bodewig <bo...@apache.org>
Authored: Tue Dec 20 20:41:19 2016 +0100
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Tue Dec 20 20:41:19 2016 +0100
----------------------------------------------------------------------
.../apache/tools/ant/taskdefs/AntStructure.java | 6 +++++-
.../apache/tools/ant/taskdefs/Available.java | 22 +++++++++++++-------
.../apache/tools/ant/taskdefs/optional/Rpm.java | 12 +++++++----
.../optional/depend/DirectoryIterator.java | 4 ++++
.../optional/extension/ExtensionUtil.java | 20 ++++++++++++++++--
.../ant/taskdefs/optional/jlink/jlink.java | 3 +++
.../taskdefs/optional/sound/AntSoundPlayer.java | 3 +++
.../tools/ant/types/resources/ResourceList.java | 7 +++++--
.../tools/ant/types/resources/Tokens.java | 3 ++-
9 files changed, 62 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ant/blob/032e888a/src/main/org/apache/tools/ant/taskdefs/AntStructure.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/AntStructure.java b/src/main/org/apache/tools/ant/taskdefs/AntStructure.java
index 20f811a..707f4b9 100644
--- a/src/main/org/apache/tools/ant/taskdefs/AntStructure.java
+++ b/src/main/org/apache/tools/ant/taskdefs/AntStructure.java
@@ -36,6 +36,7 @@ import org.apache.tools.ant.Task;
import org.apache.tools.ant.TaskContainer;
import org.apache.tools.ant.types.EnumeratedAttribute;
import org.apache.tools.ant.types.Reference;
+import org.apache.tools.ant.util.FileUtils;
/**
* Creates a partial DTD for Ant from the currently known tasks.
@@ -84,9 +85,12 @@ public class AntStructure extends Task {
PrintWriter out = null;
try {
+ FileOutputStream fos = null;
try {
- out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(output), "UTF8"));
+ fos = new FileOutputStream(output);
+ out = new PrintWriter(new OutputStreamWriter(fos, "UTF8"));
} catch (final UnsupportedEncodingException ue) {
+ FileUtils.close(fos);
/*
* Plain impossible with UTF8, see
* http://java.sun.com/j2se/1.5.0/docs/guide/intl/encoding.doc.html
http://git-wip-us.apache.org/repos/asf/ant/blob/032e888a/src/main/org/apache/tools/ant/taskdefs/Available.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/Available.java b/src/main/org/apache/tools/ant/taskdefs/Available.java
index 816568e..f4919a1 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Available.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Available.java
@@ -19,6 +19,7 @@
package org.apache.tools.ant.taskdefs;
import java.io.File;
+import java.io.InputStream;
import org.apache.tools.ant.AntClassLoader;
import org.apache.tools.ant.BuildException;
@@ -421,16 +422,21 @@ public class Available extends Task implements Condition {
* Check if a given resource can be loaded.
*/
private boolean checkResource(String resource) {
- if (loader != null) {
- return (loader.getResourceAsStream(resource) != null);
- } else {
- ClassLoader cL = this.getClass().getClassLoader();
- if (cL != null) {
- return (cL.getResourceAsStream(resource) != null);
+ InputStream is = null;
+ try {
+ if (loader != null) {
+ is = loader.getResourceAsStream(resource);
} else {
- return
- (ClassLoader.getSystemResourceAsStream(resource) != null);
+ ClassLoader cL = this.getClass().getClassLoader();
+ if (cL != null) {
+ is = cL.getResourceAsStream(resource);
+ } else {
+ is = ClassLoader.getSystemResourceAsStream(resource);
+ }
}
+ return is != null;
+ } finally {
+ FileUtils.close(is);
}
}
http://git-wip-us.apache.org/repos/asf/ant/blob/032e888a/src/main/org/apache/tools/ant/taskdefs/optional/Rpm.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/Rpm.java b/src/main/org/apache/tools/ant/taskdefs/optional/Rpm.java
index b395a16..a48ed96 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/Rpm.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/Rpm.java
@@ -149,11 +149,13 @@ public class Rpm extends Task {
}
} else {
if (output != null) {
+ FileOutputStream fos = null;
try {
- BufferedOutputStream bos
- = new BufferedOutputStream(new FileOutputStream(output));
+ fos = new FileOutputStream(output);
+ BufferedOutputStream bos = new BufferedOutputStream(fos);
outputstream = new PrintStream(bos);
} catch (IOException e) {
+ FileUtils.close(fos);
throw new BuildException(e, getLocation());
}
} else if (!quiet) {
@@ -162,11 +164,13 @@ public class Rpm extends Task {
outputstream = new LogOutputStream(this, Project.MSG_DEBUG);
}
if (error != null) {
+ FileOutputStream fos = null;
try {
- BufferedOutputStream bos
- = new BufferedOutputStream(new FileOutputStream(error));
+ fos = new FileOutputStream(error);
+ BufferedOutputStream bos = new BufferedOutputStream(fos);
errorstream = new PrintStream(bos);
} catch (IOException e) {
+ FileUtils.close(fos);
throw new BuildException(e, getLocation());
}
} else if (!quiet) {
http://git-wip-us.apache.org/repos/asf/ant/blob/032e888a/src/main/org/apache/tools/ant/taskdefs/optional/depend/DirectoryIterator.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/depend/DirectoryIterator.java b/src/main/org/apache/tools/ant/taskdefs/optional/depend/DirectoryIterator.java
index ebf244a..e12f684 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/depend/DirectoryIterator.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/depend/DirectoryIterator.java
@@ -133,6 +133,7 @@ public class DirectoryIterator implements ClassFileIterator {
FileInputStream inFileStream
= new FileInputStream(element);
+ try {
if (element.getName().endsWith(".class")) {
// create a data input stream from the jar
@@ -143,6 +144,9 @@ public class DirectoryIterator implements ClassFileIterator {
nextElement = javaClass;
}
+ } finally {
+ inFileStream.close();
+ }
}
} else {
// this iterator is exhausted. Can we pop one off the stack
http://git-wip-us.apache.org/repos/asf/ant/blob/032e888a/src/main/org/apache/tools/ant/taskdefs/optional/extension/ExtensionUtil.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/extension/ExtensionUtil.java b/src/main/org/apache/tools/ant/taskdefs/optional/extension/ExtensionUtil.java
index 089c789..ce66050 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/extension/ExtensionUtil.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/extension/ExtensionUtil.java
@@ -130,8 +130,9 @@ public final class ExtensionUtil {
final boolean includeImpl,
final boolean includeURL)
throws BuildException {
+ JarFile jarFile = null;
try {
- final JarFile jarFile = new JarFile(file);
+ jarFile = new JarFile(file);
final Extension[] extensions =
Extension.getAvailable(jarFile.getManifest());
for (int i = 0; i < extensions.length; i++) {
@@ -140,6 +141,8 @@ public final class ExtensionUtil {
}
} catch (final Exception e) {
throw new BuildException(e.getMessage(), e);
+ } finally {
+ close(jarFile);
}
}
@@ -201,8 +204,9 @@ public final class ExtensionUtil {
*/
static Manifest getManifest(final File file)
throws BuildException {
+ JarFile jarFile = null;
try {
- final JarFile jarFile = new JarFile(file);
+ jarFile = new JarFile(file);
Manifest m = jarFile.getManifest();
if (m == null) {
throw new BuildException(file + " doesn't have a MANIFEST");
@@ -210,6 +214,18 @@ public final class ExtensionUtil {
return m;
} catch (final IOException ioe) {
throw new BuildException(ioe.getMessage(), ioe);
+ } finally {
+ close(jarFile);
+ }
+ }
+
+ private static void close(JarFile device) {
+ if (null != device) {
+ try {
+ device.close();
+ } catch (IOException e) {
+ //ignore
+ }
}
}
}
http://git-wip-us.apache.org/repos/asf/ant/blob/032e888a/src/main/org/apache/tools/ant/taskdefs/optional/jlink/jlink.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/jlink/jlink.java b/src/main/org/apache/tools/ant/taskdefs/optional/jlink/jlink.java
index a788727..3916477 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/jlink/jlink.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/jlink/jlink.java
@@ -223,6 +223,7 @@ public class jlink {
return;
}
ZipFile zipf = new ZipFile(f);
+ try {
Enumeration entries = zipf.entries();
while (entries.hasMoreElements()) {
@@ -267,7 +268,9 @@ public class jlink {
output.closeEntry();
}
}
+ } finally {
zipf.close();
+ }
}
http://git-wip-us.apache.org/repos/asf/ant/blob/032e888a/src/main/org/apache/tools/ant/taskdefs/optional/sound/AntSoundPlayer.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/sound/AntSoundPlayer.java b/src/main/org/apache/tools/ant/taskdefs/optional/sound/AntSoundPlayer.java
index 7988bc6..2a99124 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/sound/AntSoundPlayer.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/sound/AntSoundPlayer.java
@@ -117,6 +117,7 @@ public class AntSoundPlayer implements LineListener, BuildListener {
DataLine.Info info = new DataLine.Info(Clip.class, format,
AudioSystem.NOT_SPECIFIED);
try {
+ try {
audioClip = (Clip) AudioSystem.getLine(info);
audioClip.addLineListener(this);
audioClip.open(audioInputStream);
@@ -133,7 +134,9 @@ public class AntSoundPlayer implements LineListener, BuildListener {
playClip(audioClip, loops);
}
audioClip.drain();
+ } finally {
audioClip.close();
+ }
} else {
project.log("Can't get data from file " + file.getName());
}
http://git-wip-us.apache.org/repos/asf/ant/blob/032e888a/src/main/org/apache/tools/ant/types/resources/ResourceList.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/resources/ResourceList.java b/src/main/org/apache/tools/ant/types/resources/ResourceList.java
index 8b77e1b..6c16b5e 100644
--- a/src/main/org/apache/tools/ant/types/resources/ResourceList.java
+++ b/src/main/org/apache/tools/ant/types/resources/ResourceList.java
@@ -195,15 +195,18 @@ public class ResourceList extends DataType implements ResourceCollection {
crh.setPrimaryReader(input);
crh.setFilterChains(filterChains);
crh.setProject(getProject());
- BufferedReader reader = new BufferedReader(crh.getAssembledReader());
-
Union streamResources = new Union();
+ BufferedReader reader = new BufferedReader(crh.getAssembledReader());
+ try {
streamResources.setCache(true);
String line = null;
while ((line = reader.readLine()) != null) {
streamResources.add(parse(line));
}
+ } finally {
+ reader.close();
+ }
return streamResources;
} catch (final IOException ioe) {
http://git-wip-us.apache.org/repos/asf/ant/blob/032e888a/src/main/org/apache/tools/ant/types/resources/Tokens.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/resources/Tokens.java b/src/main/org/apache/tools/ant/types/resources/Tokens.java
index 0a518c3..458f8c1 100644
--- a/src/main/org/apache/tools/ant/types/resources/Tokens.java
+++ b/src/main/org/apache/tools/ant/types/resources/Tokens.java
@@ -60,8 +60,8 @@ public class Tokens extends BaseResourceCollectionWrapper {
ConcatResourceInputStream cat = new ConcatResourceInputStream(rc);
cat.setManagingComponent(this);
+ InputStreamReader rdr = null;
try {
- InputStreamReader rdr = null;
if (encoding == null) {
rdr = new InputStreamReader(cat);
} else {
@@ -81,6 +81,7 @@ public class Tokens extends BaseResourceCollectionWrapper {
} catch (IOException e) {
throw new BuildException("Error reading tokens", e);
} finally {
+ FileUtils.close(rdr);
FileUtils.close(cat);
}
}
[4/6] ant git commit: Merge branch '1.9.x'
Posted by bo...@apache.org.
Merge branch '1.9.x'
Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/89b267ef
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/89b267ef
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/89b267ef
Branch: refs/heads/master
Commit: 89b267eff1e82d85deccd1532d000529af62e1be
Parents: 990a664 c8a72df
Author: Stefan Bodewig <bo...@apache.org>
Authored: Tue Dec 20 20:45:02 2016 +0100
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Tue Dec 20 20:45:02 2016 +0100
----------------------------------------------------------------------
src/main/org/apache/tools/ant/Main.java | 5 +-
.../apache/tools/ant/taskdefs/AntStructure.java | 6 +-
.../apache/tools/ant/taskdefs/Available.java | 22 ++++--
.../org/apache/tools/ant/taskdefs/Truncate.java | 4 +-
.../tools/ant/taskdefs/cvslib/CvsTagDiff.java | 2 +-
.../ant/taskdefs/optional/PropertyFile.java | 2 +-
.../apache/tools/ant/taskdefs/optional/Rpm.java | 12 ++-
.../optional/depend/DirectoryIterator.java | 16 ++--
.../ant/taskdefs/optional/ejb/IPlanetEjbc.java | 3 +-
.../optional/extension/ExtensionUtil.java | 20 ++++-
.../taskdefs/optional/jdepend/JDependTask.java | 2 +-
.../ant/taskdefs/optional/jlink/jlink.java | 81 ++++++++++----------
.../taskdefs/optional/sound/AntSoundPlayer.java | 33 ++++----
.../tools/ant/types/resources/ResourceList.java | 15 ++--
.../tools/ant/types/resources/Tokens.java | 3 +-
.../types/selectors/ContainsRegexpSelector.java | 2 +-
.../ant/types/selectors/ContainsSelector.java | 4 +-
.../org/apache/tools/ant/util/FileUtils.java | 2 +-
src/main/org/apache/tools/zip/ZipFile.java | 4 +-
19 files changed, 144 insertions(+), 94 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ant/blob/89b267ef/src/main/org/apache/tools/ant/taskdefs/optional/PropertyFile.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ant/blob/89b267ef/src/main/org/apache/tools/ant/util/FileUtils.java
----------------------------------------------------------------------
[6/6] ant git commit: use FileUtils
Posted by bo...@apache.org.
use FileUtils
Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/2bb5b057
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/2bb5b057
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/2bb5b057
Branch: refs/heads/master
Commit: 2bb5b057ddcf9d14e353e26d481f24a18e20752a
Parents: 851a0b2
Author: Stefan Bodewig <bo...@apache.org>
Authored: Tue Dec 20 20:52:31 2016 +0100
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Tue Dec 20 20:52:31 2016 +0100
----------------------------------------------------------------------
.../taskdefs/optional/extension/ExtensionUtil.java | 14 +++-----------
1 file changed, 3 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ant/blob/2bb5b057/src/main/org/apache/tools/ant/taskdefs/optional/extension/ExtensionUtil.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/extension/ExtensionUtil.java b/src/main/org/apache/tools/ant/taskdefs/optional/extension/ExtensionUtil.java
index ce66050..00d4599 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/extension/ExtensionUtil.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/extension/ExtensionUtil.java
@@ -29,6 +29,7 @@ import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.FileSet;
+import org.apache.tools.ant.util.FileUtils;
/**
* A set of useful methods relating to extensions.
@@ -142,7 +143,7 @@ public final class ExtensionUtil {
} catch (final Exception e) {
throw new BuildException(e.getMessage(), e);
} finally {
- close(jarFile);
+ FileUtils.close(jarFile);
}
}
@@ -215,17 +216,8 @@ public final class ExtensionUtil {
} catch (final IOException ioe) {
throw new BuildException(ioe.getMessage(), ioe);
} finally {
- close(jarFile);
+ FileUtils.close(jarFile);
}
}
- private static void close(JarFile device) {
- if (null != device) {
- try {
- device.close();
- } catch (IOException e) {
- //ignore
- }
- }
- }
}
[3/6] 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/c8a72df5
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/c8a72df5
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/c8a72df5
Branch: refs/heads/master
Commit: c8a72df5913d2f6816b66837bee8030633fa9189
Parents: 032e888
Author: Stefan Bodewig <bo...@apache.org>
Authored: Tue Dec 20 20:43:46 2016 +0100
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Tue Dec 20 20:43:46 2016 +0100
----------------------------------------------------------------------
.../optional/depend/DirectoryIterator.java | 14 ++--
.../ant/taskdefs/optional/jlink/jlink.java | 80 ++++++++++----------
.../taskdefs/optional/sound/AntSoundPlayer.java | 34 ++++-----
.../tools/ant/types/resources/ResourceList.java | 10 +--
4 files changed, 69 insertions(+), 69 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ant/blob/c8a72df5/src/main/org/apache/tools/ant/taskdefs/optional/depend/DirectoryIterator.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/depend/DirectoryIterator.java b/src/main/org/apache/tools/ant/taskdefs/optional/depend/DirectoryIterator.java
index e12f684..af28c96 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/depend/DirectoryIterator.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/depend/DirectoryIterator.java
@@ -134,16 +134,16 @@ public class DirectoryIterator implements ClassFileIterator {
= new FileInputStream(element);
try {
- if (element.getName().endsWith(".class")) {
+ if (element.getName().endsWith(".class")) {
- // create a data input stream from the jar
- // input stream
- ClassFile javaClass = new ClassFile();
+ // create a data input stream from the jar
+ // input stream
+ ClassFile javaClass = new ClassFile();
- javaClass.read(inFileStream);
+ javaClass.read(inFileStream);
- nextElement = javaClass;
- }
+ nextElement = javaClass;
+ }
} finally {
inFileStream.close();
}
http://git-wip-us.apache.org/repos/asf/ant/blob/c8a72df5/src/main/org/apache/tools/ant/taskdefs/optional/jlink/jlink.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/jlink/jlink.java b/src/main/org/apache/tools/ant/taskdefs/optional/jlink/jlink.java
index 3916477..b2c5d0f 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/jlink/jlink.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/jlink/jlink.java
@@ -224,52 +224,52 @@ public class jlink {
}
ZipFile zipf = new ZipFile(f);
try {
- Enumeration entries = zipf.entries();
-
- while (entries.hasMoreElements()) {
- ZipEntry inputEntry = (ZipEntry) entries.nextElement();
- //Ignore manifest entries. They're bound to cause conflicts between
- //files that are being merged. User should supply their own
- //manifest file when doing the merge.
- String inputEntryName = inputEntry.getName();
- int index = inputEntryName.indexOf("META-INF");
-
- if (index < 0) {
- //META-INF not found in the name of the entry. Go ahead and process it.
- try {
- output.putNextEntry(processEntry(zipf, inputEntry));
- } catch (ZipException ex) {
- //If we get here, it could be because we are trying to put a
- //directory entry that already exists.
- //For example, we're trying to write "com", but a previous
- //entry from another mergefile was called "com".
- //In that case, just ignore the error and go on to the
- //next entry.
- String mess = ex.getMessage();
-
- if (mess.indexOf("duplicate") >= 0) {
- //It was the duplicate entry.
- continue;
- } else {
- // I hate to admit it, but we don't know what happened
- // here. Throw the Exception.
- throw ex;
+ Enumeration entries = zipf.entries();
+
+ while (entries.hasMoreElements()) {
+ ZipEntry inputEntry = (ZipEntry) entries.nextElement();
+ //Ignore manifest entries. They're bound to cause conflicts between
+ //files that are being merged. User should supply their own
+ //manifest file when doing the merge.
+ String inputEntryName = inputEntry.getName();
+ int index = inputEntryName.indexOf("META-INF");
+
+ if (index < 0) {
+ //META-INF not found in the name of the entry. Go ahead and process it.
+ try {
+ output.putNextEntry(processEntry(zipf, inputEntry));
+ } catch (ZipException ex) {
+ //If we get here, it could be because we are trying to put a
+ //directory entry that already exists.
+ //For example, we're trying to write "com", but a previous
+ //entry from another mergefile was called "com".
+ //In that case, just ignore the error and go on to the
+ //next entry.
+ String mess = ex.getMessage();
+
+ if (mess.indexOf("duplicate") >= 0) {
+ //It was the duplicate entry.
+ continue;
+ } else {
+ // I hate to admit it, but we don't know what happened
+ // here. Throw the Exception.
+ throw ex;
+ }
}
- }
- InputStream in = zipf.getInputStream(inputEntry);
- int len = buffer.length;
- int count = -1;
+ InputStream in = zipf.getInputStream(inputEntry);
+ int len = buffer.length;
+ int count = -1;
- while ((count = in.read(buffer, 0, len)) > 0) {
- output.write(buffer, 0, count);
+ while ((count = in.read(buffer, 0, len)) > 0) {
+ output.write(buffer, 0, count);
+ }
+ in.close();
+ output.closeEntry();
}
- in.close();
- output.closeEntry();
}
- }
} finally {
- zipf.close();
+ zipf.close();
}
}
http://git-wip-us.apache.org/repos/asf/ant/blob/c8a72df5/src/main/org/apache/tools/ant/taskdefs/optional/sound/AntSoundPlayer.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/sound/AntSoundPlayer.java b/src/main/org/apache/tools/ant/taskdefs/optional/sound/AntSoundPlayer.java
index 2a99124..5007c45 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/sound/AntSoundPlayer.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/sound/AntSoundPlayer.java
@@ -117,25 +117,25 @@ public class AntSoundPlayer implements LineListener, BuildListener {
DataLine.Info info = new DataLine.Info(Clip.class, format,
AudioSystem.NOT_SPECIFIED);
try {
- try {
- audioClip = (Clip) AudioSystem.getLine(info);
- audioClip.addLineListener(this);
- audioClip.open(audioInputStream);
- } catch (LineUnavailableException e) {
- project.log("The sound device is currently unavailable");
- return;
- } catch (IOException e) {
- e.printStackTrace();
- }
+ try {
+ audioClip = (Clip) AudioSystem.getLine(info);
+ audioClip.addLineListener(this);
+ audioClip.open(audioInputStream);
+ } catch (LineUnavailableException e) {
+ project.log("The sound device is currently unavailable");
+ return;
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
- if (duration != null) {
- playClip(audioClip, duration.longValue());
- } else {
- playClip(audioClip, loops);
- }
- audioClip.drain();
+ if (duration != null) {
+ playClip(audioClip, duration.longValue());
+ } else {
+ playClip(audioClip, loops);
+ }
+ audioClip.drain();
} finally {
- audioClip.close();
+ audioClip.close();
}
} else {
project.log("Can't get data from file " + file.getName());
http://git-wip-us.apache.org/repos/asf/ant/blob/c8a72df5/src/main/org/apache/tools/ant/types/resources/ResourceList.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/resources/ResourceList.java b/src/main/org/apache/tools/ant/types/resources/ResourceList.java
index 6c16b5e..da83ea9 100644
--- a/src/main/org/apache/tools/ant/types/resources/ResourceList.java
+++ b/src/main/org/apache/tools/ant/types/resources/ResourceList.java
@@ -198,12 +198,12 @@ public class ResourceList extends DataType implements ResourceCollection {
Union streamResources = new Union();
BufferedReader reader = new BufferedReader(crh.getAssembledReader());
try {
- streamResources.setCache(true);
+ streamResources.setCache(true);
- String line = null;
- while ((line = reader.readLine()) != null) {
- streamResources.add(parse(line));
- }
+ String line = null;
+ while ((line = reader.readLine()) != null) {
+ streamResources.add(parse(line));
+ }
} finally {
reader.close();
}
[5/6] ant git commit: try-with-resources
Posted by bo...@apache.org.
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/851a0b20
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/851a0b20
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/851a0b20
Branch: refs/heads/master
Commit: 851a0b208613f7b15816adb6acb799dddd95fb69
Parents: 89b267e
Author: Stefan Bodewig <bo...@apache.org>
Authored: Tue Dec 20 20:52:17 2016 +0100
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Tue Dec 20 20:52:17 2016 +0100
----------------------------------------------------------------------
.../ant/taskdefs/optional/depend/DirectoryIterator.java | 8 ++------
.../org/apache/tools/ant/taskdefs/optional/jlink/jlink.java | 5 +----
.../org/apache/tools/ant/types/resources/ResourceList.java | 5 +----
3 files changed, 4 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ant/blob/851a0b20/src/main/org/apache/tools/ant/taskdefs/optional/depend/DirectoryIterator.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/depend/DirectoryIterator.java b/src/main/org/apache/tools/ant/taskdefs/optional/depend/DirectoryIterator.java
index af28c96..fbb963e 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/depend/DirectoryIterator.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/depend/DirectoryIterator.java
@@ -130,10 +130,8 @@ public class DirectoryIterator implements ClassFileIterator {
} else {
// we have a file. create a stream for it
- FileInputStream inFileStream
- = new FileInputStream(element);
-
- try {
+ try (FileInputStream inFileStream
+ = new FileInputStream(element)) {
if (element.getName().endsWith(".class")) {
// create a data input stream from the jar
@@ -144,8 +142,6 @@ public class DirectoryIterator implements ClassFileIterator {
nextElement = javaClass;
}
- } finally {
- inFileStream.close();
}
}
} else {
http://git-wip-us.apache.org/repos/asf/ant/blob/851a0b20/src/main/org/apache/tools/ant/taskdefs/optional/jlink/jlink.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/jlink/jlink.java b/src/main/org/apache/tools/ant/taskdefs/optional/jlink/jlink.java
index b2c5d0f..aa193ea 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/jlink/jlink.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/jlink/jlink.java
@@ -222,8 +222,7 @@ public class jlink {
if (!f.exists()) {
return;
}
- ZipFile zipf = new ZipFile(f);
- try {
+ try (ZipFile zipf = new ZipFile(f)) {
Enumeration entries = zipf.entries();
while (entries.hasMoreElements()) {
@@ -268,8 +267,6 @@ public class jlink {
output.closeEntry();
}
}
- } finally {
- zipf.close();
}
}
http://git-wip-us.apache.org/repos/asf/ant/blob/851a0b20/src/main/org/apache/tools/ant/types/resources/ResourceList.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/resources/ResourceList.java b/src/main/org/apache/tools/ant/types/resources/ResourceList.java
index da83ea9..fbb226c 100644
--- a/src/main/org/apache/tools/ant/types/resources/ResourceList.java
+++ b/src/main/org/apache/tools/ant/types/resources/ResourceList.java
@@ -196,16 +196,13 @@ public class ResourceList extends DataType implements ResourceCollection {
crh.setFilterChains(filterChains);
crh.setProject(getProject());
Union streamResources = new Union();
- BufferedReader reader = new BufferedReader(crh.getAssembledReader());
- try {
+ try (BufferedReader reader = new BufferedReader(crh.getAssembledReader())) {
streamResources.setCache(true);
String line = null;
while ((line = reader.readLine()) != null) {
streamResources.add(parse(line));
}
- } finally {
- reader.close();
}
return streamResources;