Author: jlboudart
Date: Tue Aug 20 19:27:21 2013
New Revision: 1515937
URL: http://svn.apache.org/r1515937
Log:
Ensure all stream are closed
Modified:
ant/easyant/core/trunk/src/main/java/org/apache/easyant/core/EasyAntEngine.java
ant/easyant/core/trunk/src/main/java/org/apache/easyant/core/EasyAntMain.java
ant/easyant/core/trunk/src/main/java/org/apache/easyant/core/parser/EasyAntConfigParser.java
ant/easyant/core/trunk/src/main/java/org/apache/easyant/core/services/impl/DefaultPluginServiceImpl.java
ant/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/CoreRevisionCheckerTask.java
ant/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/PluginReport.java
ant/easyant/core/trunk/src/main/java/org/apache/ivy/core/cache/EasyantResolutionCacheManager.java
Modified:
ant/easyant/core/trunk/src/main/java/org/apache/easyant/core/EasyAntEngine.java
URL:
http://svn.apache.org/viewvc/ant/easyant/core/trunk/src/main/java/org/apache/easyant/core/EasyAntEngine.java?rev=1515937&r1=1515936&r2=1515937&view=diff
==============================================================================
---
ant/easyant/core/trunk/src/main/java/org/apache/easyant/core/EasyAntEngine.java
(original)
+++
ant/easyant/core/trunk/src/main/java/org/apache/easyant/core/EasyAntEngine.java
Tue Aug 20 19:27:21 2013
@@ -712,11 +712,12 @@ public class EasyAntEngine {
public static String getEasyAntVersion() {
if (easyantVersion == null) {
+ InputStream in = null;
+
try {
Properties props = new Properties();
- InputStream in =
Main.class.getResourceAsStream("/META-INF/version.properties");
+ in =
Main.class.getResourceAsStream("/META-INF/version.properties");
props.load(in);
- in.close();
StringBuffer msg = new StringBuffer();
msg.append("EasyAnt version ");
@@ -728,6 +729,14 @@ public class EasyAntEngine {
throw new BuildException("Could not load the version
information:" + ioe.getMessage());
} catch (NullPointerException npe) {
throw new BuildException("Could not load the version
information.");
+ } finally {
+ if (in != null) {
+ try {
+ in.close();
+ } catch (IOException e) {
+ // do nothing
+ }
+ }
}
}
return easyantVersion;
Modified:
ant/easyant/core/trunk/src/main/java/org/apache/easyant/core/EasyAntMain.java
URL:
http://svn.apache.org/viewvc/ant/easyant/core/trunk/src/main/java/org/apache/easyant/core/EasyAntMain.java?rev=1515937&r1=1515936&r2=1515937&view=diff
==============================================================================
---
ant/easyant/core/trunk/src/main/java/org/apache/easyant/core/EasyAntMain.java
(original)
+++
ant/easyant/core/trunk/src/main/java/org/apache/easyant/core/EasyAntMain.java
Tue Aug 20 19:27:21 2013
@@ -733,11 +733,11 @@ public class EasyAntMain implements AntM
*/
public static synchronized String getAntVersion() throws BuildException {
if (antVersion == null) {
+ InputStream in = null;
try {
Properties props = new Properties();
- InputStream in =
Main.class.getResourceAsStream("/org/apache/tools/ant/version.txt");
+ in =
Main.class.getResourceAsStream("/org/apache/tools/ant/version.txt");
props.load(in);
- in.close();
StringBuffer msg = new StringBuffer();
msg.append("Apache Ant version ");
@@ -749,6 +749,14 @@ public class EasyAntMain implements AntM
throw new BuildException("Could not load the version
information:" + ioe.getMessage());
} catch (NullPointerException npe) {
throw new BuildException("Could not load the version
information.");
+ } finally {
+ if (in != null) {
+ try {
+ in.close();
+ } catch (IOException e) {
+ // do nothing
+ }
+ }
}
}
return antVersion;
Modified:
ant/easyant/core/trunk/src/main/java/org/apache/easyant/core/parser/EasyAntConfigParser.java
URL:
http://svn.apache.org/viewvc/ant/easyant/core/trunk/src/main/java/org/apache/easyant/core/parser/EasyAntConfigParser.java?rev=1515937&r1=1515936&r2=1515937&view=diff
==============================================================================
---
ant/easyant/core/trunk/src/main/java/org/apache/easyant/core/parser/EasyAntConfigParser.java
(original)
+++
ant/easyant/core/trunk/src/main/java/org/apache/easyant/core/parser/EasyAntConfigParser.java
Tue Aug 20 19:27:21 2013
@@ -19,6 +19,7 @@ package org.apache.easyant.core.parser;
import java.io.File;
import java.io.FileInputStream;
+import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.text.ParseException;
@@ -196,20 +197,19 @@ public class EasyAntConfigParser {
if ("easyant-config/properties/property".equals(getContext())) {
if (attributes.getValue("file") != null ||
attributes.getValue("url") != null) {
Properties properties = new Properties();
+ InputStream is = null;
try {
- InputStream is = null;
if (attributes.getValue("file") != null) {
File f = new File(attributes.getValue("file"));
is = new FileInputStream(f);
properties.load(is);
- is.close();
} else if (attributes.getValue("url") != null) {
URL url = new URL(attributes.getValue("url"));
is = url.openStream();
properties.load(is);
- is.close();
}
+
Enumeration<?> propertiesEnum =
properties.propertyNames();
while (propertiesEnum.hasMoreElements()) {
String key = (String) propertiesEnum.nextElement();
@@ -221,7 +221,16 @@ public class EasyAntConfigParser {
} else if (attributes.getValue("url") != null) {
throw new SAXException("can't read property file
at : " + attributes.getValue("url"));
}
+ } finally {
+ if (is != null) {
+ try {
+ is.close();
+ } catch (IOException e) {
+ // do nothing
+ }
+ }
}
+
} else if (attributes.getValue("name") != null) {
easyAntConfiguration.getDefinedProps().put(attributes.getValue("name"),
attributes.getValue("value"));
Modified:
ant/easyant/core/trunk/src/main/java/org/apache/easyant/core/services/impl/DefaultPluginServiceImpl.java
URL:
http://svn.apache.org/viewvc/ant/easyant/core/trunk/src/main/java/org/apache/easyant/core/services/impl/DefaultPluginServiceImpl.java?rev=1515937&r1=1515936&r2=1515937&view=diff
==============================================================================
---
ant/easyant/core/trunk/src/main/java/org/apache/easyant/core/services/impl/DefaultPluginServiceImpl.java
(original)
+++
ant/easyant/core/trunk/src/main/java/org/apache/easyant/core/services/impl/DefaultPluginServiceImpl.java
Tue Aug 20 19:27:21 2013
@@ -383,8 +383,11 @@ public class DefaultPluginServiceImpl im
Properties propToLoad = new Properties();
File f = property.getFile();
if (f.exists()) {
+ FileInputStream fis = null;
+
try {
- propToLoad.load(new FileInputStream(f));
+ fis = new FileInputStream(f);
+ propToLoad.load(fis);
for (Iterator<?> iter = propToLoad.keySet().iterator();
iter.hasNext();) {
String key = (String) iter.next();
PropertyDescriptor propertyDescriptor = new
PropertyDescriptor(key);
@@ -400,8 +403,13 @@ public class DefaultPluginServiceImpl im
IOException ioe = new IOException("Unable to parse the
property file :" + property.getFile());
ioe.initCause(e);
throw ioe;
+ } finally {
+ if (fis != null) {
+ fis.close();
+ }
}
}
+
}
if (property.getName() != null) {
PropertyDescriptor propertyDescriptor = new
PropertyDescriptor(property.getName());
@@ -490,8 +498,8 @@ public class DefaultPluginServiceImpl im
targetReport.setName(target.getName());
StringBuilder sb = new StringBuilder();
Enumeration<?> targetDeps = target.getDependencies();
+ String t = (String) targetDeps.nextElement();
while (targetDeps.hasMoreElements()) {
- String t = (String) targetDeps.nextElement();
sb.append(t);
if (targetDeps.hasMoreElements()) {
sb.append(",");
Modified:
ant/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/CoreRevisionCheckerTask.java
URL:
http://svn.apache.org/viewvc/ant/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/CoreRevisionCheckerTask.java?rev=1515937&r1=1515936&r2=1515937&view=diff
==============================================================================
---
ant/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/CoreRevisionCheckerTask.java
(original)
+++
ant/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/CoreRevisionCheckerTask.java
Tue Aug 20 19:27:21 2013
@@ -91,16 +91,24 @@ public class CoreRevisionCheckerTask ext
public static synchronized String getEasyAntSpecVersion() throws
BuildException {
if (easyantSpecVersion == null) {
+ InputStream in = null;
try {
Properties props = new Properties();
- InputStream in =
CoreRevisionCheckerTask.class.getResourceAsStream("/META-INF/version.properties");
+ in =
CoreRevisionCheckerTask.class.getResourceAsStream("/META-INF/version.properties");
props.load(in);
- in.close();
easyantSpecVersion = props.getProperty("SPEC-VERSION");
} catch (IOException ioe) {
throw new BuildException("Could not load the version
information:" + ioe.getMessage());
} catch (NullPointerException npe) {
throw new BuildException("Could not load the version
information.");
+ } finally {
+ if (in != null) {
+ try {
+ in.close();
+ } catch (IOException e) {
+ // do nothing
+ }
+ }
}
}
return easyantSpecVersion;
Modified:
ant/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/PluginReport.java
URL:
http://svn.apache.org/viewvc/ant/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/PluginReport.java?rev=1515937&r1=1515936&r2=1515937&view=diff
==============================================================================
---
ant/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/PluginReport.java
(original)
+++
ant/easyant/core/trunk/src/main/java/org/apache/easyant/tasks/PluginReport.java
Tue Aug 20 19:27:21 2013
@@ -175,19 +175,26 @@ public class PluginReport extends Abstra
PluginService pluginService = (PluginService)
getProject().getReference(
EasyAntMagicNames.PLUGIN_SERVICE_INSTANCE);
-
+ OutputStream stream = null;
try {
EasyAntReport easyantReport =
pluginService.getPluginInfo(moduleIvy, sourceDirectory, conf);
ModuleRevisionId moduleRevisionId =
easyantReport.getModuleDescriptor().getModuleRevisionId();
File reportFile = new File(todir,
getOutputPattern(moduleRevisionId, conf, "xml"));
todir.mkdirs();
- OutputStream stream = new FileOutputStream(reportFile);
+ stream = new FileOutputStream(reportFile);
XMLEasyAntReportWriter writer = new XMLEasyAntReportWriter();
writer.output(easyantReport, stream);
- stream.close();
genStyled(reportFile, getReportStylePath(), easyantReport);
} catch (Exception e) {
throw new BuildException("impossible to generate report: " + e, e);
+ } finally {
+ if (stream != null) {
+ try {
+ stream.close();
+ } catch (IOException e) {
+ // do nothing
+ }
+ }
}
}
Modified:
ant/easyant/core/trunk/src/main/java/org/apache/ivy/core/cache/EasyantResolutionCacheManager.java
URL:
http://svn.apache.org/viewvc/ant/easyant/core/trunk/src/main/java/org/apache/ivy/core/cache/EasyantResolutionCacheManager.java?rev=1515937&r1=1515936&r2=1515937&view=diff
==============================================================================
---
ant/easyant/core/trunk/src/main/java/org/apache/ivy/core/cache/EasyantResolutionCacheManager.java
(original)
+++
ant/easyant/core/trunk/src/main/java/org/apache/ivy/core/cache/EasyantResolutionCacheManager.java
Tue Aug 20 19:27:21 2013
@@ -147,9 +147,16 @@ public class EasyantResolutionCacheManag
File parentsFile =
getResolvedIvyPropertiesInCache(ModuleRevisionId.newInstance(mrid,
mrid.getRevision()
+ "-parents"));
if (parentsFile.exists()) {
- FileInputStream in = new FileInputStream(parentsFile);
- paths.load(in);
- in.close();
+ FileInputStream in = null;
+ try {
+ in = new FileInputStream(parentsFile);
+ paths.load(in);
+
+ } finally {
+ if (in != null) {
+ in.close();
+ }
+ }
}
ParserSettings pSettings = new CacheParserSettings(settings, paths);
@@ -171,9 +178,15 @@ public class EasyantResolutionCacheManag
if (!paths.isEmpty()) {
File parentsFile =
getResolvedIvyPropertiesInCache(ModuleRevisionId.newInstance(mrevId,
mrevId.getRevision() + "-parents"));
- FileOutputStream out = new FileOutputStream(parentsFile);
- paths.store(out, null);
- out.close();
+ FileOutputStream out = null;
+ try {
+ out = new FileOutputStream(parentsFile);
+ paths.store(out, null);
+ } finally {
+ if (out != null) {
+ out.close();
+ }
+ }
}
}