You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ah...@apache.org on 2006/05/16 22:45:42 UTC
svn commit: r407056 - in /maven/maven-1/core/trunk/src:
java/org/apache/maven/ java/org/apache/maven/cli/
java/org/apache/maven/jelly/ java/org/apache/maven/plugin/
java/org/apache/maven/util/ test/java/org/apache/maven/plugin/
Author: aheritier
Date: Tue May 16 13:45:41 2006
New Revision: 407056
URL: http://svn.apache.org/viewcvs?rev=407056&view=rev
Log:
Close InputStreams
PR : MAVEN-1761
Modified:
maven/maven-1/core/trunk/src/java/org/apache/maven/MavenUtils.java
maven/maven-1/core/trunk/src/java/org/apache/maven/cli/App.java
maven/maven-1/core/trunk/src/java/org/apache/maven/jelly/JellyUtils.java
maven/maven-1/core/trunk/src/java/org/apache/maven/plugin/JellyScriptHousing.java
maven/maven-1/core/trunk/src/java/org/apache/maven/plugin/PluginCacheManager.java
maven/maven-1/core/trunk/src/java/org/apache/maven/plugin/PluginScriptParser.java
maven/maven-1/core/trunk/src/java/org/apache/maven/util/Expand.java
maven/maven-1/core/trunk/src/java/org/apache/maven/util/MD5Sum.java
maven/maven-1/core/trunk/src/test/java/org/apache/maven/plugin/PluginCacheManagerTest.java
maven/maven-1/core/trunk/src/test/java/org/apache/maven/plugin/PluginManagerTest.java
Modified: maven/maven-1/core/trunk/src/java/org/apache/maven/MavenUtils.java
URL: http://svn.apache.org/viewcvs/maven/maven-1/core/trunk/src/java/org/apache/maven/MavenUtils.java?rev=407056&r1=407055&r2=407056&view=diff
==============================================================================
--- maven/maven-1/core/trunk/src/java/org/apache/maven/MavenUtils.java (original)
+++ maven/maven-1/core/trunk/src/java/org/apache/maven/MavenUtils.java Tue May 16 13:45:41 2006
@@ -187,13 +187,30 @@
{
// 1)
Project project = null;
+ FileReader fr = null;
try
{
- project = new Project( new FileReader( projectDescriptor ) );
+ fr = new FileReader( projectDescriptor );
+ project = new Project( fr );
}
- catch (Exception e)
+ catch ( Exception e )
+ {
+ throw new MavenException( "Error parsing project.xml '" + projectDescriptor.getAbsolutePath() + "'", e );
+ }
+ finally
{
- throw new MavenException("Error parsing project.xml '" + projectDescriptor.getAbsolutePath() + "'", e);
+ if ( fr != null )
+ {
+ try
+ {
+ fr.close();
+ }
+ catch ( IOException e )
+ {
+ // Nothing to do
+ }
+ fr = null;
+ }
}
// 2)
@@ -699,17 +716,34 @@
*/
private static Properties loadProperties( File file )
{
+ FileInputStream fis = null;
try
{
if ( file.exists() )
{
- return loadProperties( new FileInputStream (file) );
+ fis = new FileInputStream( file );
+ return loadProperties( fis );
}
}
catch ( Exception e )
{
// ignore
- log.debug("Unexpected error loading properties", e);
+ log.debug( "Unexpected error loading properties", e );
+ }
+ finally
+ {
+ if ( fis != null )
+ {
+ try
+ {
+ fis.close();
+ }
+ catch ( IOException e )
+ {
+ // Nothing to do
+ }
+ fis = null;
+ }
}
return null;
Modified: maven/maven-1/core/trunk/src/java/org/apache/maven/cli/App.java
URL: http://svn.apache.org/viewcvs/maven/maven-1/core/trunk/src/java/org/apache/maven/cli/App.java?rev=407056&r1=407055&r2=407056&view=diff
==============================================================================
--- maven/maven-1/core/trunk/src/java/org/apache/maven/cli/App.java (original)
+++ maven/maven-1/core/trunk/src/java/org/apache/maven/cli/App.java Tue May 16 13:45:41 2006
@@ -802,13 +802,30 @@
}
Properties buildProperties = new Properties();
+ FileInputStream fis=null;
try
{
- buildProperties.load( new FileInputStream( System.getProperty( "user.home" ) + "/build.properties" ) );
+ fis = new FileInputStream( System.getProperty( "user.home" ) + "/build.properties" );
+ buildProperties.load( fis );
}
catch ( IOException e )
{
log.error( MavenUtils.getMessage( "displayInfo.error" ) + e.getMessage() );
+ }
+ finally
+ {
+ if ( fis != null )
+ {
+ try
+ {
+ fis.close();
+ }
+ catch ( IOException e )
+ {
+ // Nothing to do
+ }
+ fis = null;
+ }
}
log.info( MavenUtils.getMessage( "displayInfo.info2" ) + buildProperties );
exit( RC_OK );
Modified: maven/maven-1/core/trunk/src/java/org/apache/maven/jelly/JellyUtils.java
URL: http://svn.apache.org/viewcvs/maven/maven-1/core/trunk/src/java/org/apache/maven/jelly/JellyUtils.java?rev=407056&r1=407055&r2=407056&view=diff
==============================================================================
--- maven/maven-1/core/trunk/src/java/org/apache/maven/jelly/JellyUtils.java (original)
+++ maven/maven-1/core/trunk/src/java/org/apache/maven/jelly/JellyUtils.java Tue May 16 13:45:41 2006
@@ -19,6 +19,7 @@
import java.io.File;
import java.io.FileInputStream;
+import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
@@ -34,6 +35,7 @@
import org.apache.commons.jelly.parser.XMLParser;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.maven.MavenUtils;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
@@ -120,8 +122,28 @@
{
return;
}
+ FileInputStream fis = null;
+ try
+ {
+ fis = new FileInputStream( scriptFile );
+ runScript( fis, scriptFile.toURL().toString(), rootUrl, context, output );
+ }
+ finally
+ {
+ if ( fis != null )
+ {
+ try
+ {
+ fis.close();
+ }
+ catch ( IOException e )
+ {
+ // Nothing to do
+ }
+ fis = null;
+ }
- runScript( new FileInputStream( scriptFile ), scriptFile.toURL().toString(), rootUrl, context, output );
+ }
}
/**
@@ -136,7 +158,29 @@
public static Script compileScript( File scriptFile, JellyContext context )
throws Exception
{
- return compileScript( new FileInputStream( scriptFile ), scriptFile.toURL().toString(), context );
+ FileInputStream fis=null;
+ Script result = null;
+ try
+ {
+ fis = new FileInputStream( scriptFile );
+ result = compileScript( fis, scriptFile.toURL().toString(), context );
+ }
+ finally
+ {
+ if ( fis != null )
+ {
+ try
+ {
+ fis.close();
+ }
+ catch ( IOException e )
+ {
+ // Nothing to do
+ }
+ fis = null;
+ }
+ }
+ return result;
}
/**
@@ -199,7 +243,29 @@
InputSource source = null;
if ( encoding != null )
{
- source = new InputSource( new InputStreamReader( scriptInputStream, encoding ) );
+ InputStreamReader isr = null;
+ try
+ {
+ isr = new InputStreamReader( scriptInputStream, encoding );
+ source = new InputSource( isr );
+
+ }
+ finally
+ {
+ if ( isr != null )
+ {
+ try
+ {
+ isr.close();
+ }
+ catch ( IOException e )
+ {
+ // Nothing to do
+ }
+ isr = null;
+ }
+ }
+
}
else
{
Modified: maven/maven-1/core/trunk/src/java/org/apache/maven/plugin/JellyScriptHousing.java
URL: http://svn.apache.org/viewcvs/maven/maven-1/core/trunk/src/java/org/apache/maven/plugin/JellyScriptHousing.java?rev=407056&r1=407055&r2=407056&view=diff
==============================================================================
--- maven/maven-1/core/trunk/src/java/org/apache/maven/plugin/JellyScriptHousing.java (original)
+++ maven/maven-1/core/trunk/src/java/org/apache/maven/plugin/JellyScriptHousing.java Tue May 16 13:45:41 2006
@@ -172,14 +172,31 @@
void parse( PluginDefinitionHandler handler ) throws MavenException
{
+ FileInputStream fis = null;
try
{
- parse( handler, source.getAbsolutePath(), new FileInputStream( source ) );
+ fis = new FileInputStream( source );
+ parse( handler, source.getAbsolutePath(), fis );
}
catch ( FileNotFoundException e )
{
throw new MavenException( "Error reading plugin script", e );
}
+ finally
+ {
+ if ( fis != null )
+ {
+ try
+ {
+ fis.close();
+ }
+ catch ( IOException e )
+ {
+ // Nothing to do
+ }
+ fis = null;
+ }
+ }
}
/**
@@ -216,10 +233,28 @@
if ( propsFile.exists() )
{
Properties props = new Properties();
- FileInputStream in = new FileInputStream( propsFile );
- props.load( in );
- in.close();
- map.putAll( props );
+ FileInputStream in = null;
+ try
+ {
+ in = new FileInputStream( propsFile );
+ props.load( in );
+ map.putAll( props );
+ }
+ finally
+ {
+ if ( in != null )
+ {
+ try
+ {
+ in.close();
+ }
+ catch ( IOException e )
+ {
+ // Nothing to do
+ }
+ in = null;
+ }
+ }
}
return map;
Modified: maven/maven-1/core/trunk/src/java/org/apache/maven/plugin/PluginCacheManager.java
URL: http://svn.apache.org/viewcvs/maven/maven-1/core/trunk/src/java/org/apache/maven/plugin/PluginCacheManager.java?rev=407056&r1=407055&r2=407056&view=diff
==============================================================================
--- maven/maven-1/core/trunk/src/java/org/apache/maven/plugin/PluginCacheManager.java (original)
+++ maven/maven-1/core/trunk/src/java/org/apache/maven/plugin/PluginCacheManager.java Tue May 16 13:45:41 2006
@@ -231,7 +231,14 @@
{
if ( stream != null )
{
- stream.close();
+ try
+ {
+ stream.close();
+ }
+ catch ( IOException e )
+ {
+ // Nothing to do
+ }
}
}
return properties;
Modified: maven/maven-1/core/trunk/src/java/org/apache/maven/plugin/PluginScriptParser.java
URL: http://svn.apache.org/viewcvs/maven/maven-1/core/trunk/src/java/org/apache/maven/plugin/PluginScriptParser.java?rev=407056&r1=407055&r2=407056&view=diff
==============================================================================
--- maven/maven-1/core/trunk/src/java/org/apache/maven/plugin/PluginScriptParser.java (original)
+++ maven/maven-1/core/trunk/src/java/org/apache/maven/plugin/PluginScriptParser.java Tue May 16 13:45:41 2006
@@ -113,10 +113,12 @@
else
{
log.debug( rawName + " importing from uri " + importUri );
+ FileInputStream fis = null;
try
{
File f = new File( importUri );
- jellyScriptHousing.parse( handler, f.getAbsolutePath(), new FileInputStream( f ) );
+ fis = new FileInputStream( new File( importUri ) );
+ jellyScriptHousing.parse( handler, f.getAbsolutePath(), fis );
}
catch ( MavenException e )
{
@@ -125,6 +127,20 @@
catch ( IOException e )
{
log.debug( "Skipping: error reading from uri " + importUri );
+ }
+ finally
+ {
+ if ( fis != null )
+ {
+ try
+ {
+ fis.close();
+ }
+ catch ( IOException e )
+ {
+ // Nothing to do
+ }
+ }
}
}
}
Modified: maven/maven-1/core/trunk/src/java/org/apache/maven/util/Expand.java
URL: http://svn.apache.org/viewcvs/maven/maven-1/core/trunk/src/java/org/apache/maven/util/Expand.java?rev=407056&r1=407055&r2=407056&view=diff
==============================================================================
--- maven/maven-1/core/trunk/src/java/org/apache/maven/util/Expand.java (original)
+++ maven/maven-1/core/trunk/src/java/org/apache/maven/util/Expand.java Tue May 16 13:45:41 2006
@@ -73,10 +73,12 @@
protected void expandFile() throws IOException
{
ZipInputStream zis = null;
+ FileInputStream fis = null;
try
{
// code from WarExpand
- zis = new ZipInputStream( new FileInputStream( source ) );
+ fis = new FileInputStream( source );
+ zis = new ZipInputStream( fis );
ZipEntry ze = null;
setFileUtils(FileUtils.newFileUtils());
@@ -91,6 +93,17 @@
}
finally
{
+ if ( fis != null )
+ {
+ try
+ {
+ fis.close();
+ }
+ catch ( IOException e )
+ {
+ // intentionally left blank
+ }
+ }
if ( zis != null )
{
try
Modified: maven/maven-1/core/trunk/src/java/org/apache/maven/util/MD5Sum.java
URL: http://svn.apache.org/viewcvs/maven/maven-1/core/trunk/src/java/org/apache/maven/util/MD5Sum.java?rev=407056&r1=407055&r2=407056&view=diff
==============================================================================
--- maven/maven-1/core/trunk/src/java/org/apache/maven/util/MD5Sum.java (original)
+++ maven/maven-1/core/trunk/src/java/org/apache/maven/util/MD5Sum.java Tue May 16 13:45:41 2006
@@ -20,6 +20,7 @@
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
+import java.io.IOException;
import java.io.InputStream;
import java.security.MessageDigest;
@@ -137,6 +138,15 @@
while ( ( len = stream.read( buf, 0, 1024 ) ) != -1 )
{
baos.write( buf, 0, len );
+ }
+
+ try
+ {
+ stream.close();
+ }
+ catch ( IOException e )
+ {
+ // Nothing to do
}
return baos.toByteArray();
Modified: maven/maven-1/core/trunk/src/test/java/org/apache/maven/plugin/PluginCacheManagerTest.java
URL: http://svn.apache.org/viewcvs/maven/maven-1/core/trunk/src/test/java/org/apache/maven/plugin/PluginCacheManagerTest.java?rev=407056&r1=407055&r2=407056&view=diff
==============================================================================
--- maven/maven-1/core/trunk/src/test/java/org/apache/maven/plugin/PluginCacheManagerTest.java (original)
+++ maven/maven-1/core/trunk/src/test/java/org/apache/maven/plugin/PluginCacheManagerTest.java Tue May 16 13:45:41 2006
@@ -54,7 +54,9 @@
{
PluginCacheManager pgb = new PluginCacheManager();
JellyScriptHousing housing = new JellyScriptHousing( new File( PLUGIN_SCRIPT ).getParentFile(), null );
- housing.parse( pgb, PLUGIN_SCRIPT, new FileInputStream( new File( PLUGIN_SCRIPT )));
+ FileInputStream fis = new FileInputStream( new File( PLUGIN_SCRIPT ));
+ housing.parse( pgb, PLUGIN_SCRIPT, fis);
+ fis.close();
assertEquals("Generate docs in APT format>xdoc:generate-from-pom",
pgb.getGoalCache().getProperty("apt:generate"));
Modified: maven/maven-1/core/trunk/src/test/java/org/apache/maven/plugin/PluginManagerTest.java
URL: http://svn.apache.org/viewcvs/maven/maven-1/core/trunk/src/test/java/org/apache/maven/plugin/PluginManagerTest.java?rev=407056&r1=407055&r2=407056&view=diff
==============================================================================
--- maven/maven-1/core/trunk/src/test/java/org/apache/maven/plugin/PluginManagerTest.java (original)
+++ maven/maven-1/core/trunk/src/test/java/org/apache/maven/plugin/PluginManagerTest.java Tue May 16 13:45:41 2006
@@ -98,7 +98,9 @@
context.setVariable(MavenConstants.MAVEN_UNPACKED_PLUGINS_DIR, fakeUnpackedPlugins);
// fake forehead up - must be done before MavenSession creation
- Forehead.getInstance().config(new FileInputStream(basedir + SOURCE_BASE + "forehead.conf"));
+ FileInputStream fis = new FileInputStream(basedir + SOURCE_BASE + "forehead.conf");
+ Forehead.getInstance().config(fis);
+ fis.close();
// setup maven session
MavenSession mavenSession = new MavenSession();