You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by el...@apache.org on 2020/11/16 15:26:16 UTC

[maven-archiver] branch close created (now 0c1577b)

This is an automated email from the ASF dual-hosted git repository.

elharo pushed a change to branch close
in repository https://gitbox.apache.org/repos/asf/maven-archiver.git.


      at 0c1577b  use try with resources

This branch includes the following new commits:

     new 0c1577b  use try with resources

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[maven-archiver] 01/01: use try with resources

Posted by el...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

elharo pushed a commit to branch close
in repository https://gitbox.apache.org/repos/asf/maven-archiver.git

commit 0c1577b5699b24bacea3bf988d3af95bb7f86438
Author: Elliotte Harold <el...@ibiblio.org>
AuthorDate: Mon Nov 16 10:25:57 2020 -0500

    use try with resources
---
 .../org/apache/maven/archiver/MavenArchiver.java   |  2 +-
 .../apache/maven/archiver/PomPropertiesUtil.java   | 43 ++++++----------------
 .../apache/maven/archiver/MavenArchiverTest.java   |  7 +---
 3 files changed, 15 insertions(+), 37 deletions(-)

diff --git a/src/main/java/org/apache/maven/archiver/MavenArchiver.java b/src/main/java/org/apache/maven/archiver/MavenArchiver.java
index 013aacd..a807b84 100644
--- a/src/main/java/org/apache/maven/archiver/MavenArchiver.java
+++ b/src/main/java/org/apache/maven/archiver/MavenArchiver.java
@@ -230,7 +230,7 @@ public class MavenArchiver
         }
         else
         {
-            // if the value is empty we have create an entry with an empty string
+            // if the value is empty, create an entry with an empty string
             // to prevent null print in the manifest file
             Manifest.Attribute attr = new Manifest.Attribute( key, "" );
             manifest.addConfiguredAttribute( attr );
diff --git a/src/main/java/org/apache/maven/archiver/PomPropertiesUtil.java b/src/main/java/org/apache/maven/archiver/PomPropertiesUtil.java
index 9fac0f7..e05b7f3 100644
--- a/src/main/java/org/apache/maven/archiver/PomPropertiesUtil.java
+++ b/src/main/java/org/apache/maven/archiver/PomPropertiesUtil.java
@@ -34,7 +34,6 @@ import java.util.Properties;
 
 import org.apache.maven.execution.MavenSession;
 import org.apache.maven.project.MavenProject;
-import org.apache.maven.shared.utils.io.IOUtil;
 import org.codehaus.plexus.archiver.Archiver;
 
 /**
@@ -47,19 +46,11 @@ public class PomPropertiesUtil
         throws IOException
     {
         Properties fileProps = new Properties();
-        InputStream istream = null;
-        try
+        try ( InputStream istream = new FileInputStream( file ) )
         {
-            istream = new FileInputStream( file );
             fileProps.load( istream );
-            istream.close();
-            istream = null;
             return fileProps;
         }
-        finally
-        {
-            IOUtil.close( istream );
-        }
     }
 
     private boolean sameContents( Properties props, File file )
@@ -87,41 +78,31 @@ public class PomPropertiesUtil
         {
             return;
         }
-        PrintWriter pw = new PrintWriter( outputFile, "ISO-8859-1" );
-        try
+        
+        try ( PrintWriter pw = new PrintWriter( outputFile, "ISO-8859-1" );
+              StringWriter sw = new StringWriter(); )
         {
-            StringWriter sw = new StringWriter();
+            
             properties.store( sw, null );
 
-            BufferedReader r = new BufferedReader( new StringReader( sw.toString() ) );
-
             List<String> lines = new ArrayList<String>();
-            String line;
-            while ( ( line = r.readLine() ) != null )
+            try ( BufferedReader r = new BufferedReader( new StringReader( sw.toString() ) ) )
             {
-                if ( !line.startsWith( "#" ) )
+                String line;
+                while ( ( line = r.readLine() ) != null )
                 {
-                    lines.add( line );
+                    if ( !line.startsWith( "#" ) )
+                    {
+                        lines.add( line );
+                    }
                 }
             }
 
-            r.close();
-            r = null;
-            sw.close();
-            sw = null;
-
             Collections.sort( lines );
             for ( String l : lines )
             {
                 pw.println( l );
             }
-
-            pw.close();
-            pw = null;
-        }
-        finally
-        {
-            IOUtil.close( pw );
         }
     }
 
diff --git a/src/test/java/org/apache/maven/archiver/MavenArchiverTest.java b/src/test/java/org/apache/maven/archiver/MavenArchiverTest.java
index dde6bac..07e2876 100644
--- a/src/test/java/org/apache/maven/archiver/MavenArchiverTest.java
+++ b/src/test/java/org/apache/maven/archiver/MavenArchiverTest.java
@@ -40,7 +40,6 @@ import org.codehaus.plexus.archiver.jar.JarArchiver;
 import org.codehaus.plexus.archiver.jar.ManifestException;
 import org.eclipse.aether.DefaultRepositorySystemSession;
 import org.eclipse.aether.RepositorySystemSession;
-import org.junit.Ignore;
 import org.junit.Test;
 
 import java.io.File;
@@ -131,9 +130,7 @@ public class MavenArchiverTest
             }
         };
 
-        Manifest manifest;
-
-        manifest = archiver.getManifest( session, project, config );
+        Manifest manifest = archiver.getManifest( session, project, config );
 
         assertThat( manifest.getMainAttributes() ).isNotNull();
 
@@ -274,7 +271,7 @@ public class MavenArchiverTest
 
         archiver.createArchive( session, project, config );
         
-        assertThat( history ).as( "History " + history + " time:" + time ).isEqualTo( jarFile.lastModified() );
+        assertThat( time ).as( "History " + history + " time:" + time ).isEqualTo( jarFile.lastModified() );
 
         config.setForced( true );
         archiver.createArchive( session, project, config );