From 266d5732477e34458ca9a04c463c15a9e8de24db Mon Sep 17 00:00:00 2001 From: Herve Boutemy Date: Mon, 17 Mar 2014 21:07:49 +0000 Subject: [PATCH] [MPLUGIN-255] Generated HelpMojo doesn't close resource stream Submitted by: Juan Hernandez applied with formatting fix git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/trunk@1578572 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/main/resources/help-class-source.vm | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/maven-plugin-tools-generators/src/main/resources/help-class-source.vm b/maven-plugin-tools-generators/src/main/resources/help-class-source.vm index f86a5f4..03d034c 100644 --- a/maven-plugin-tools-generators/src/main/resources/help-class-source.vm +++ b/maven-plugin-tools-generators/src/main/resources/help-class-source.vm @@ -95,9 +95,10 @@ public class HelpMojo throws MojoExecutionException { getLog().debug( "load plugin-help.xml: " + PLUGIN_HELP_PATH ); - InputStream is = getClass().getResourceAsStream( PLUGIN_HELP_PATH ); + InputStream is = null; try { + is = getClass().getResourceAsStream( PLUGIN_HELP_PATH ); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); return dBuilder.parse( is ); @@ -114,6 +115,20 @@ public class HelpMojo { throw new MojoExecutionException( e.getMessage(), e ); } + finally + { + if ( is != null ) + { + try + { + is.close(); + } + catch ( IOException e ) + { + throw new MojoExecutionException( e.getMessage(), e ); + } + } + } } /**