Author: krosenvold
Date: Thu Nov 19 06:50:15 2015
New Revision: 1715108

URL: http://svn.apache.org/viewvc?rev=1715108&view=rev
Log:
Close streams even in test cases

Modified:
    
maven/plugins/trunk/maven-site-plugin/src/test/java/org/apache/maven/plugins/site/stubs/SiteMavenProjectStub.java
    
maven/plugins/trunk/maven-source-plugin/src/test/java/org/apache/maven/plugins/source/stubs/Project001Stub.java
    
maven/plugins/trunk/maven-source-plugin/src/test/java/org/apache/maven/plugins/source/stubs/Project003Stub.java
    
maven/plugins/trunk/maven-source-plugin/src/test/java/org/apache/maven/plugins/source/stubs/Project005Stub.java
    
maven/plugins/trunk/maven-source-plugin/src/test/java/org/apache/maven/plugins/source/stubs/Project007Stub.java
    
maven/plugins/trunk/maven-source-plugin/src/test/java/org/apache/maven/plugins/source/stubs/Project009Stub.java
    
maven/plugins/trunk/maven-source-plugin/src/test/java/org/apache/maven/plugins/source/stubs/Project010Stub.java

Modified: 
maven/plugins/trunk/maven-site-plugin/src/test/java/org/apache/maven/plugins/site/stubs/SiteMavenProjectStub.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-site-plugin/src/test/java/org/apache/maven/plugins/site/stubs/SiteMavenProjectStub.java?rev=1715108&r1=1715107&r2=1715108&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-site-plugin/src/test/java/org/apache/maven/plugins/site/stubs/SiteMavenProjectStub.java
 (original)
+++ 
maven/plugins/trunk/maven-site-plugin/src/test/java/org/apache/maven/plugins/site/stubs/SiteMavenProjectStub.java
 Thu Nov 19 06:50:15 2015
@@ -27,7 +27,9 @@ import org.apache.maven.model.Model;
 import org.apache.maven.model.Site;
 import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
 import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
+import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.ReaderFactory;
+import org.codehaus.plexus.util.xml.XmlStreamReader;
 
 /**
  * @author <a href="mailto:vincent.sive...@gmail.com";>Vincent Siveton</a>
@@ -48,18 +50,24 @@ public class SiteMavenProjectStub
         MavenXpp3Reader pomReader = new MavenXpp3Reader();
         Model model;
 
+        XmlStreamReader reader = null;
         try
         {
             File pomFile =
                 new File( getBasedir(), pomFilePath == null ? 
"/src/test/resources/unit/interpolated-site/pom.xml"
                                 : pomFilePath );
-            model = pomReader.read( ReaderFactory.newXmlReader( pomFile ) );
+            reader = ReaderFactory.newXmlReader( pomFile );
+            model = pomReader.read( reader );
             setModel( model );
         }
         catch ( Exception e )
         {
             throw new RuntimeException( e );
         }
+        finally
+        {
+            IOUtil.close( reader);
+        }
         Site site = new Site();
         site.setId( "localhost" );
         distributionManagement.setSite( site );

Modified: 
maven/plugins/trunk/maven-source-plugin/src/test/java/org/apache/maven/plugins/source/stubs/Project001Stub.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-source-plugin/src/test/java/org/apache/maven/plugins/source/stubs/Project001Stub.java?rev=1715108&r1=1715107&r2=1715108&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-source-plugin/src/test/java/org/apache/maven/plugins/source/stubs/Project001Stub.java
 (original)
+++ 
maven/plugins/trunk/maven-source-plugin/src/test/java/org/apache/maven/plugins/source/stubs/Project001Stub.java
 Thu Nov 19 06:50:15 2015
@@ -1,12 +1,18 @@
 package org.apache.maven.plugins.source.stubs;
 
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-
 import org.apache.maven.model.Build;
 import org.apache.maven.model.Model;
 import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
+import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.ReaderFactory;
+import org.codehaus.plexus.util.xml.XmlStreamReader;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
@@ -27,9 +33,6 @@ import org.apache.maven.model.io.xpp3.Ma
  * under the License.
  */
 
-import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
-import org.codehaus.plexus.util.ReaderFactory;
-
 /**
  * @author <a href="mailto:och...@exist.com";>Maria Odea Ching</a>
  */
@@ -44,13 +47,11 @@ public class Project001Stub
 
     public Project001Stub()
     {
-        MavenXpp3Reader pomReader = new MavenXpp3Reader();
         Model model;
 
         try
         {
-            model = pomReader.read(
-                ReaderFactory.newXmlReader( new File( getBasedir(), 
"target/test-classes/unit/project-001/pom.xml" ) ) );
+            model = readModelFromFile( new File( getBasedir(), 
"target/test-classes/unit/project-001/pom.xml" ) );
             setModel( model );
 
             setGroupId( model.getGroupId() );
@@ -74,8 +75,10 @@ public class Project001Stub
             testCompileSourceRoots.add( basedir + 
"/target/test-classes/unit/project-001/src/test/java" );
             setTestCompileSourceRoots( testCompileSourceRoots );
 
-            setResources( model.getBuild().getResources() );
-            setTestResources( model.getBuild().getTestResources() );
+            setResources( model.getBuild()
+                               .getResources() );
+            setTestResources( model.getBuild()
+                                   .getTestResources() );
 
             SourcePluginArtifactStub artifact =
                 new SourcePluginArtifactStub( getGroupId(), getArtifactId(), 
getVersion(), getPackaging(), null );
@@ -120,4 +123,20 @@ public class Project001Stub
     {
         this.testResources = testResources;
     }
+
+    static Model readModelFromFile(File file)
+        throws IOException, XmlPullParserException
+    {
+        MavenXpp3Reader pomReader = new MavenXpp3Reader();
+        XmlStreamReader reader = null;
+        try
+        {
+            reader = ReaderFactory.newXmlReader( file );
+            return pomReader.read( reader );
+        } finally {
+            IOUtil.close( reader );
+        }
+
+
+    }
 }

Modified: 
maven/plugins/trunk/maven-source-plugin/src/test/java/org/apache/maven/plugins/source/stubs/Project003Stub.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-source-plugin/src/test/java/org/apache/maven/plugins/source/stubs/Project003Stub.java?rev=1715108&r1=1715107&r2=1715108&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-source-plugin/src/test/java/org/apache/maven/plugins/source/stubs/Project003Stub.java
 (original)
+++ 
maven/plugins/trunk/maven-source-plugin/src/test/java/org/apache/maven/plugins/source/stubs/Project003Stub.java
 Thu Nov 19 06:50:15 2015
@@ -30,6 +30,8 @@ import org.apache.maven.model.io.xpp3.Ma
 import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
 import org.codehaus.plexus.util.ReaderFactory;
 
+import static 
org.apache.maven.plugins.source.stubs.Project001Stub.readModelFromFile;
+
 /**
  * @author <a href="mailto:och...@exist.com";>Maria Odea Ching</a>
  */
@@ -44,13 +46,11 @@ public class Project003Stub
 
     public Project003Stub()
     {
-        MavenXpp3Reader pomReader = new MavenXpp3Reader();
         Model model;
 
         try
         {
-            model = pomReader.read(
-                ReaderFactory.newXmlReader( new File( getBasedir(), 
"target/test-classes/unit/project-003/pom.xml" ) ) );
+            model = readModelFromFile( new File( getBasedir(), 
"target/test-classes/unit/project-003/pom.xml" ) );
             setModel( model );
 
             setGroupId( model.getGroupId() );

Modified: 
maven/plugins/trunk/maven-source-plugin/src/test/java/org/apache/maven/plugins/source/stubs/Project005Stub.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-source-plugin/src/test/java/org/apache/maven/plugins/source/stubs/Project005Stub.java?rev=1715108&r1=1715107&r2=1715108&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-source-plugin/src/test/java/org/apache/maven/plugins/source/stubs/Project005Stub.java
 (original)
+++ 
maven/plugins/trunk/maven-source-plugin/src/test/java/org/apache/maven/plugins/source/stubs/Project005Stub.java
 Thu Nov 19 06:50:15 2015
@@ -29,6 +29,8 @@ import org.apache.maven.model.io.xpp3.Ma
 import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
 import org.codehaus.plexus.util.ReaderFactory;
 
+import static 
org.apache.maven.plugins.source.stubs.Project001Stub.readModelFromFile;
+
 /**
  * @author <a href="mailto:och...@exist.com";>Maria Odea Ching</a>
  */
@@ -43,13 +45,10 @@ public class Project005Stub
 
     public Project005Stub()
     {
-        MavenXpp3Reader pomReader = new MavenXpp3Reader();
         Model model;
-
         try
         {
-            model = pomReader.read(
-                ReaderFactory.newXmlReader( new File( getBasedir(), 
"target/test-classes/unit/project-005/pom.xml" ) ) );
+            model = readModelFromFile( new File( getBasedir(), 
"target/test-classes/unit/project-005/pom.xml" ) );
             setModel( model );
 
             setGroupId( model.getGroupId() );

Modified: 
maven/plugins/trunk/maven-source-plugin/src/test/java/org/apache/maven/plugins/source/stubs/Project007Stub.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-source-plugin/src/test/java/org/apache/maven/plugins/source/stubs/Project007Stub.java?rev=1715108&r1=1715107&r2=1715108&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-source-plugin/src/test/java/org/apache/maven/plugins/source/stubs/Project007Stub.java
 (original)
+++ 
maven/plugins/trunk/maven-source-plugin/src/test/java/org/apache/maven/plugins/source/stubs/Project007Stub.java
 Thu Nov 19 06:50:15 2015
@@ -30,6 +30,8 @@ import org.apache.maven.model.io.xpp3.Ma
 import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
 import org.codehaus.plexus.util.ReaderFactory;
 
+import static 
org.apache.maven.plugins.source.stubs.Project001Stub.readModelFromFile;
+
 /**
  * @author <a href="mailto:och...@exist.com";>Maria Odea Ching</a>
  */
@@ -44,13 +46,10 @@ public class Project007Stub
 
     public Project007Stub()
     {
-        MavenXpp3Reader pomReader = new MavenXpp3Reader();
         Model model;
-
         try
         {
-            model = pomReader.read(
-                ReaderFactory.newXmlReader( new File( getBasedir(), 
"target/test-classes/unit/project-007/pom.xml" ) ) );
+            model = readModelFromFile( new File( getBasedir(), 
"target/test-classes/unit/project-007/pom.xml" ) );
             setModel( model );
 
             setGroupId( model.getGroupId() );

Modified: 
maven/plugins/trunk/maven-source-plugin/src/test/java/org/apache/maven/plugins/source/stubs/Project009Stub.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-source-plugin/src/test/java/org/apache/maven/plugins/source/stubs/Project009Stub.java?rev=1715108&r1=1715107&r2=1715108&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-source-plugin/src/test/java/org/apache/maven/plugins/source/stubs/Project009Stub.java
 (original)
+++ 
maven/plugins/trunk/maven-source-plugin/src/test/java/org/apache/maven/plugins/source/stubs/Project009Stub.java
 Thu Nov 19 06:50:15 2015
@@ -29,6 +29,8 @@ import org.apache.maven.model.io.xpp3.Ma
 import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
 import org.codehaus.plexus.util.ReaderFactory;
 
+import static 
org.apache.maven.plugins.source.stubs.Project001Stub.readModelFromFile;
+
 /**
  * @author Dennis Lundberg
  */
@@ -43,13 +45,12 @@ public class Project009Stub
 
     public Project009Stub()
     {
-        MavenXpp3Reader pomReader = new MavenXpp3Reader();
         Model model;
 
         try
         {
             final File pomFile = new File( getBasedir(), 
"target/test-classes/unit/project-009/pom.xml" );
-            model = pomReader.read( ReaderFactory.newXmlReader( pomFile ) );
+            model = readModelFromFile( pomFile );
             setModel( model );
             setFile( pomFile );
 

Modified: 
maven/plugins/trunk/maven-source-plugin/src/test/java/org/apache/maven/plugins/source/stubs/Project010Stub.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-source-plugin/src/test/java/org/apache/maven/plugins/source/stubs/Project010Stub.java?rev=1715108&r1=1715107&r2=1715108&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-source-plugin/src/test/java/org/apache/maven/plugins/source/stubs/Project010Stub.java
 (original)
+++ 
maven/plugins/trunk/maven-source-plugin/src/test/java/org/apache/maven/plugins/source/stubs/Project010Stub.java
 Thu Nov 19 06:50:15 2015
@@ -29,6 +29,8 @@ import org.apache.maven.model.io.xpp3.Ma
 import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
 import org.codehaus.plexus.util.ReaderFactory;
 
+import static 
org.apache.maven.plugins.source.stubs.Project001Stub.readModelFromFile;
+
 public class Project010Stub
     extends MavenProjectStub
 {
@@ -40,13 +42,11 @@ public class Project010Stub
 
     public Project010Stub()
     {
-        MavenXpp3Reader pomReader = new MavenXpp3Reader();
         Model model;
 
         try
         {
-            model = pomReader.read(
-                ReaderFactory.newXmlReader( new File( getBasedir(), 
"target/test-classes/unit/project-010/pom.xml" ) ) );
+            model = readModelFromFile( new File( getBasedir(), 
"target/test-classes/unit/project-010/pom.xml" ) );
             setModel( model );
 
             setFile(new File( getBasedir(), 
"target/test-classes/unit/project-010/pom.xml" ));


Reply via email to