From b606a755c857badfe392afaadc023d1ce7b7b824 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Sat, 12 May 2012 23:15:53 +0000 Subject: [PATCH] take care to close stream in finally block git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/trunk@1337729 13f79535-47bb-0310-9956-ffa450edef68 --- .../plugin/generator/PluginDescriptorGenerator.java | 11 ++++++++--- .../tools/plugin/generator/PluginHelpGenerator.java | 7 +++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java index f1313e8..68ea254 100644 --- a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java +++ b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginDescriptorGenerator.java @@ -74,14 +74,20 @@ public class PluginDescriptorGenerator if ( tmpPropertiesFile.exists() ) { Properties properties = new Properties(); + FileInputStream fis = null; try { - properties.load( new FileInputStream( tmpPropertiesFile ) ); + fis = new FileInputStream( tmpPropertiesFile ); + properties.load( fis ); } catch ( IOException e ) { throw new GeneratorException( e.getMessage(), e ); } + finally + { + IOUtil.close( fis ); + } String helpPackageName = properties.getProperty( "helpPackageName" ); // if helpPackageName property is empty we have to rewrite the class with a better package name than empty if ( StringUtils.isEmpty( helpPackageName ) ) @@ -171,8 +177,7 @@ public class PluginDescriptorGenerator if ( pluginDescriptor.getMojos() != null ) { - @SuppressWarnings( "unchecked" ) - List descriptors = pluginDescriptor.getMojos(); + @SuppressWarnings( "unchecked" ) List descriptors = pluginDescriptor.getMojos(); for ( MojoDescriptor descriptor : descriptors ) { processMojoDescriptor( descriptor, w, cleanDescription ); diff --git a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginHelpGenerator.java b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginHelpGenerator.java index 4275a9a..d21c9b5 100644 --- a/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginHelpGenerator.java +++ b/maven-plugin-tools-api/src/main/java/org/apache/maven/tools/plugin/generator/PluginHelpGenerator.java @@ -133,14 +133,17 @@ public class PluginHelpGenerator tmpPropertiesFile.getParentFile().mkdirs(); } } - + FileOutputStream fos = null; try { - properties.store( new FileOutputStream( tmpPropertiesFile ), "maven plugin help generation informations" ); + fos = new FileOutputStream( tmpPropertiesFile ); + properties.store( fos, "maven plugin help generation informations" ); } catch ( IOException e ) { throw new GeneratorException( e.getMessage(), e ); + } finally { + IOUtil.close( fos ); } String sourcePath = helpImplementation.replace( '.', File.separatorChar ) + ".java";