correctly close stream

git-svn-id: https://svn.apache.org/repos/asf/maven/plugins/trunk@1384325 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/pom.xml b/pom.xml
index 5c01a08..730ce48 100644
--- a/pom.xml
+++ b/pom.xml
@@ -116,6 +116,11 @@
       </exclusions>
     </dependency>
     <dependency>
+      <groupId>commons-io</groupId>
+      <artifactId>commons-io</artifactId>
+      <version>2.4</version>
+    </dependency>
+    <dependency>
       <groupId>org.apache.maven.shared</groupId>
       <artifactId>maven-plugin-testing-harness</artifactId>
       <version>1.1</version>
diff --git a/src/main/java/org/apache/maven/plugin/acr/AcrMojo.java b/src/main/java/org/apache/maven/plugin/acr/AcrMojo.java
index e91e6ac..28cfa88 100644
--- a/src/main/java/org/apache/maven/plugin/acr/AcrMojo.java
+++ b/src/main/java/org/apache/maven/plugin/acr/AcrMojo.java
@@ -19,6 +19,7 @@
  * under the License.
  */
 
+import org.apache.commons.io.IOUtils;
 import org.apache.maven.archiver.MavenArchiveConfiguration;
 import org.apache.maven.archiver.MavenArchiver;
 import org.apache.maven.artifact.DependencyResolutionRequiredException;
@@ -52,8 +53,8 @@
  * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
  * @version $Id:
  */
-@Mojo( name = "acr", requiresDependencyResolution = ResolutionScope.RUNTIME, threadSafe = true,
-       defaultPhase = LifecyclePhase.PACKAGE )
+@Mojo (name = "acr", requiresDependencyResolution = ResolutionScope.RUNTIME, threadSafe = true,
+       defaultPhase = LifecyclePhase.PACKAGE)
 public class AcrMojo
     extends AbstractMojo
 {
@@ -70,19 +71,19 @@
     /**
      * The directory for the generated jar.
      */
-    @Parameter( defaultValue = "${project.build.directory}", required = true, readonly = true )
+    @Parameter (defaultValue = "${project.build.directory}", required = true, readonly = true)
     private File basedir;
 
     /**
      * Directory that resources are copied to during the build.
      */
-    @Parameter( property = "outputDirectory", defaultValue = "${project.build.outputDirectory}" )
+    @Parameter (property = "outputDirectory", defaultValue = "${project.build.outputDirectory}")
     private File outputDirectory;
 
     /**
      * The name of the Application client JAR file to generate.
      */
-    @Parameter( property = "jarName", defaultValue = "${project.build.finalName}" )
+    @Parameter (property = "jarName", defaultValue = "${project.build.finalName}")
     private String jarName;
 
     /**
@@ -107,7 +108,7 @@
     /**
      * The Jar archiver.
      */
-    @Component( role = Archiver.class, hint = "jar" )
+    @Component (role = Archiver.class, hint = "jar")
     private JarArchiver jarArchiver;
 
     /**
@@ -121,20 +122,20 @@
      * To escape interpolated value with windows path.
      * c:\foo\bar will be replaced with c:\\foo\\bar.
      */
-    @Parameter( property = "acr.escapeBackslashesInFilePath", defaultValue = "false" )
+    @Parameter (property = "acr.escapeBackslashesInFilePath", defaultValue = "false")
     private boolean escapeBackslashesInFilePath;
 
     /**
      * An expression preceded with this String won't be interpolated.
      * \${foo} will be replaced with ${foo}.
      */
-    @Parameter( property = "acr.escapeString" )
+    @Parameter (property = "acr.escapeString")
     protected String escapeString;
 
     /**
      * To filter the deployment descriptor.
      */
-    @Parameter( property = "acr.filterDeploymentDescriptor", defaultValue = "false" )
+    @Parameter (property = "acr.filterDeploymentDescriptor", defaultValue = "false")
     private boolean filterDeploymentDescriptor;
 
     /**
@@ -145,7 +146,7 @@
 
     /**
      */
-    @Component( role = MavenFileFilter.class, hint = "default" )
+    @Component (role = MavenFileFilter.class, hint = "default")
     private MavenFileFilter mavenFileFilter;
 
     /**
@@ -155,7 +156,6 @@
 
     /**
      * Generates the application client jar file.
-     *
      */
     public void execute()
         throws MojoExecutionException
@@ -229,8 +229,8 @@
         catch ( ManifestException e )
         {
             throw new MojoExecutionException(
-                "There was a problem reading / creating the manifest for the JavaEE Application Client  archive: " +
-                    e.getMessage(), e );
+                "There was a problem reading / creating the manifest for the JavaEE Application Client  archive: "
+                    + e.getMessage(), e );
         }
         catch ( IOException e )
         {
@@ -240,8 +240,8 @@
         catch ( DependencyResolutionRequiredException e )
         {
             throw new MojoExecutionException(
-                "There was a problem resolving dependencies while creating the JavaEE Application Client archive: " +
-                    e.getMessage(), e );
+                "There was a problem resolving dependencies while creating the JavaEE Application Client archive: "
+                    + e.getMessage(), e );
         }
         catch ( MavenFilteringException e )
         {
@@ -276,7 +276,15 @@
     private String getEncoding( File xmlFile )
         throws IOException
     {
-        XmlStreamReader xmlReader = new XmlStreamReader( xmlFile );
-        return xmlReader.getEncoding();
+        XmlStreamReader xmlReader = null;
+        try
+        {
+            xmlReader = new XmlStreamReader( xmlFile );
+            return xmlReader.getEncoding();
+        }
+        finally
+        {
+            IOUtils.closeQuietly( xmlReader );
+        }
     }
 }