Author: krosenvold
Date: Thu Nov 19 06:49:59 2015
New Revision: 1715107

URL: http://svn.apache.org/viewvc?rev=1715107&view=rev
Log:
Added closing of writer, even upon exception

Modified:
    
maven/plugins/trunk/maven-doap-plugin/src/main/java/org/apache/maven/plugin/doap/DoapMojo.java
    
maven/plugins/trunk/maven-doap-plugin/src/test/java/org/apache/maven/plugin/doap/stubs/DoapProjectStub.java

Modified: 
maven/plugins/trunk/maven-doap-plugin/src/main/java/org/apache/maven/plugin/doap/DoapMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-doap-plugin/src/main/java/org/apache/maven/plugin/doap/DoapMojo.java?rev=1715107&r1=1715106&r2=1715107&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-doap-plugin/src/main/java/org/apache/maven/plugin/doap/DoapMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-doap-plugin/src/main/java/org/apache/maven/plugin/doap/DoapMojo.java
 Thu Nov 19 06:49:59 2015
@@ -540,6 +540,69 @@ public class DoapMojo
             throw new MojoExecutionException( "Error creating DOAP file " + 
outputFile.getAbsolutePath(), e );
         }
 
+        try
+        {
+            doWrite( project, outputFile, w );
+        }
+        finally
+        {
+
+            try
+            {
+                w.close();
+            }
+            catch ( IOException e )
+            {
+                throw new MojoExecutionException( "Error when closing the 
writer.", e );
+            }
+        }
+
+        if ( !messages.getWarnMessages().isEmpty() )
+        {
+            for ( String warn : messages.getWarnMessages() )
+            {
+                getLog().warn( warn );
+            }
+        }
+
+        if ( !messages.getErrorMessages().isEmpty() )
+        {
+            getLog().error( "" );
+            for ( String error : messages.getErrorMessages() )
+            {
+                getLog().error( error );
+            }
+            getLog().error( "" );
+
+            if ( ASFExtOptionsUtil.isASFProject( project ) )
+            {
+                getLog().error( "For more information about the errors and 
possible solutions, "
+                                    + "please read the plugin documentation:" 
);
+                getLog().error( 
"http://maven.apache.org/plugins/maven-doap-plugin/usage.html#DOAP_ASF_Configuration";
 );
+                throw new MojoExecutionException( "The generated DOAP doesn't 
respect ASF rules, see above." );
+            }
+        }
+
+        if ( validate )
+        {
+            List<String> errors = DoapUtil.validate( outputFile );
+            if ( !errors.isEmpty() )
+            {
+                getLog().error( "" );
+                for ( String error : errors )
+                {
+                    getLog().error( error );
+                }
+                getLog().error( "" );
+
+                throw new MojoExecutionException( "Error parsing the generated 
DOAP file, see above." );
+            }
+        }
+    }
+
+    private void doWrite( MavenProject project, File outputFile, Writer w )
+        throws MojoExecutionException
+    {
         if ( asfExtOptions.isIncluded() )
         {
             getLog().info( "Generating an ASF DOAP file " + 
outputFile.getAbsolutePath() );
@@ -753,57 +816,6 @@ public class DoapMojo
         writeOrganizations( writer );
 
         writer.endElement(); // rdf:RDF
-
-        try
-        {
-            w.close();
-        }
-        catch ( IOException e )
-        {
-            throw new MojoExecutionException( "Error when closing the 
writer.", e );
-        }
-
-        if ( !messages.getWarnMessages().isEmpty() )
-        {
-            for ( String warn : messages.getWarnMessages() )
-            {
-                getLog().warn( warn );
-            }
-        }
-
-        if ( !messages.getErrorMessages().isEmpty() )
-        {
-            getLog().error( "" );
-            for ( String error : messages.getErrorMessages() )
-            {
-                getLog().error( error );
-            }
-            getLog().error( "" );
-
-            if ( ASFExtOptionsUtil.isASFProject( project ) )
-            {
-                getLog().error( "For more information about the errors and 
possible solutions, "
-                                    + "please read the plugin documentation:" 
);
-                getLog().error( 
"http://maven.apache.org/plugins/maven-doap-plugin/usage.html#DOAP_ASF_Configuration";
 );
-                throw new MojoExecutionException( "The generated DOAP doesn't 
respect ASF rules, see above." );
-            }
-        }
-
-        if ( validate )
-        {
-            List<String> errors = DoapUtil.validate( outputFile );
-            if ( !errors.isEmpty() )
-            {
-                getLog().error( "" );
-                for ( String error : errors )
-                {
-                    getLog().error( error );
-                }
-                getLog().error( "" );
-
-                throw new MojoExecutionException( "Error parsing the generated 
DOAP file, see above." );
-            }
-        }
     }
 
     /**

Modified: 
maven/plugins/trunk/maven-doap-plugin/src/test/java/org/apache/maven/plugin/doap/stubs/DoapProjectStub.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-doap-plugin/src/test/java/org/apache/maven/plugin/doap/stubs/DoapProjectStub.java?rev=1715107&r1=1715106&r2=1715107&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-doap-plugin/src/test/java/org/apache/maven/plugin/doap/stubs/DoapProjectStub.java
 (original)
+++ 
maven/plugins/trunk/maven-doap-plugin/src/test/java/org/apache/maven/plugin/doap/stubs/DoapProjectStub.java
 Thu Nov 19 06:49:59 2015
@@ -35,7 +35,9 @@ import org.apache.maven.model.Organizati
 import org.apache.maven.model.Scm;
 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>
@@ -52,19 +54,24 @@ public class DoapProjectStub
     public DoapProjectStub()
     {
         MavenXpp3Reader pomReader = new MavenXpp3Reader();
+        XmlStreamReader reader = null;
         try
         {
+            reader = ReaderFactory.newXmlReader(
+                new File( new File( super.getBasedir(), 
"/src/test/resources/unit/doap-configuration/" ),
+                          "doap-configuration-plugin-config.xml" ) );
             model =
-                pomReader.read( ReaderFactory.newXmlReader( new File(
-                                                                      new 
File( super.getBasedir(),
-                                                                               
 "/src/test/resources/unit/doap-configuration/" ),
-                                                                      
"doap-configuration-plugin-config.xml" ) ) );
+                pomReader.read( reader );
             setModel( model );
         }
         catch ( Exception e )
         {
             throw new RuntimeException( e );
         }
+        finally
+        {
+            IOUtil.close( reader );
+        }
 
         setGroupId( model.getGroupId() );
         setArtifactId( model.getArtifactId() );


Reply via email to