Repository: maven
Updated Branches:
  refs/heads/master 176cc1264 -> e91a209aa


o Updated to use the try-with-resources statement.


Project: http://git-wip-us.apache.org/repos/asf/maven/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven/commit/e91a209a
Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/e91a209a
Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/e91a209a

Branch: refs/heads/master
Commit: e91a209aa52f64cd0efa743b1496f97b01410f32
Parents: 176cc12
Author: Christian Schulte <schu...@apache.org>
Authored: Thu May 12 06:08:57 2016 +0200
Committer: Christian Schulte <schu...@apache.org>
Committed: Thu May 12 06:09:54 2016 +0200

----------------------------------------------------------------------
 .../internal/DefaultVersionRangeResolver.java   | 32 ++-------
 .../internal/DefaultVersionResolver.java        | 71 +++++++-------------
 .../internal/DefaultMavenPluginManager.java     |  4 +-
 3 files changed, 34 insertions(+), 73 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven/blob/e91a209a/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/DefaultVersionRangeResolver.java
----------------------------------------------------------------------
diff --git 
a/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/DefaultVersionRangeResolver.java
 
b/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/DefaultVersionRangeResolver.java
index 7df7847..43f5d3c 100644
--- 
a/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/DefaultVersionRangeResolver.java
+++ 
b/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/DefaultVersionRangeResolver.java
@@ -57,7 +57,7 @@ import org.eclipse.aether.version.VersionScheme;
 import javax.inject.Inject;
 import javax.inject.Named;
 import java.io.FileInputStream;
-import java.io.IOException;
+import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -259,27 +259,23 @@ public class DefaultVersionRangeResolver
     {
         Versioning versioning = null;
 
-        FileInputStream fis = null;
         try
         {
             if ( metadata != null )
             {
-
                 try ( SyncContext syncContext = 
syncContextFactory.newInstance( session, true ) )
                 {
                     syncContext.acquire( null, Collections.singleton( metadata 
) );
 
                     if ( metadata.getFile() != null && 
metadata.getFile().exists() )
                     {
-                        fis = new FileInputStream( metadata.getFile() );
-
-                        org.apache.maven.artifact.repository.metadata.Metadata 
m =
-                            new MetadataXpp3Reader().read( fis, false );
-
-                        fis.close();
-                        fis = null;
+                        try ( InputStream in = new FileInputStream( 
metadata.getFile() ) )
+                        {
+                            
org.apache.maven.artifact.repository.metadata.Metadata m =
+                                new MetadataXpp3Reader().read( in, false );
 
-                        versioning = m.getVersioning();
+                            versioning = m.getVersioning();
+                        }
                     }
                 }
             }
@@ -289,20 +285,6 @@ public class DefaultVersionRangeResolver
             invalidMetadata( session, trace, metadata, repository, e );
             result.addException( e );
         }
-        finally
-        {
-            try
-            {
-                if ( fis != null )
-                {
-                    fis.close();
-                }
-            }
-            catch ( final IOException e )
-            {
-                this.logger.warn( "Failure closing file.", e );
-            }
-        }
 
         return ( versioning != null ) ? versioning : new Versioning();
     }

http://git-wip-us.apache.org/repos/asf/maven/blob/e91a209a/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/DefaultVersionResolver.java
----------------------------------------------------------------------
diff --git 
a/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/DefaultVersionResolver.java
 
b/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/DefaultVersionResolver.java
index eb2efd7..0d5a880 100644
--- 
a/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/DefaultVersionResolver.java
+++ 
b/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/DefaultVersionResolver.java
@@ -63,6 +63,7 @@ import javax.inject.Named;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -324,72 +325,52 @@ public class DefaultVersionResolver
     {
         Versioning versioning = null;
 
-        FileInputStream fis = null;
         try
         {
             if ( metadata != null )
             {
-
                 try ( SyncContext syncContext = 
syncContextFactory.newInstance( session, true ) )
                 {
                     syncContext.acquire( null, Collections.singleton( metadata 
) );
 
                     if ( metadata.getFile() != null && 
metadata.getFile().exists() )
                     {
-                        fis = new FileInputStream( metadata.getFile() );
-
-                        org.apache.maven.artifact.repository.metadata.Metadata 
m =
-                            new MetadataXpp3Reader().read( fis, false );
-
-                        fis.close();
-                        fis = null;
-
-                        versioning = m.getVersioning();
-
-                        /*
-                         * NOTE: Users occasionally misuse the id "local" for 
remote repos which screws up the metadata
-                         * of the local repository. This is especially 
troublesome during snapshot resolution so we try
-                         * to handle that gracefully.
-                         */
-                        if ( versioning != null && repository instanceof 
LocalRepository )
+                        try ( InputStream in = new FileInputStream( 
metadata.getFile() ) )
                         {
-                            if ( versioning.getSnapshot() != null && 
versioning.getSnapshot().getBuildNumber() > 0 )
-                            {
-                                Versioning repaired = new Versioning();
-                                repaired.setLastUpdated( 
versioning.getLastUpdated() );
-                                Snapshot snapshot = new Snapshot();
-                                snapshot.setLocalCopy( true );
-                                repaired.setSnapshot( snapshot );
-                                versioning = repaired;
-
-                                throw new IOException( "Snapshot information 
corrupted with remote repository data"
-                                                           + ", please verify 
that no remote repository uses the id '"
-                                                           + 
repository.getId() + "'" );
-                            }
+                            
org.apache.maven.artifact.repository.metadata.Metadata m =
+                                new MetadataXpp3Reader().read( in, false );
+
+                            versioning = m.getVersioning();
                         }
                     }
                 }
             }
+
+            /*
+             * NOTE: Users occasionally misuse the id "local" for remote repos 
which screws up the metadata
+             * of the local repository. This is especially troublesome during 
snapshot resolution so we try
+             * to handle that gracefully.
+             */
+            if ( versioning != null && repository instanceof LocalRepository
+                     && versioning.getSnapshot() != null && 
versioning.getSnapshot().getBuildNumber() > 0 )
+            {
+                Versioning repaired = new Versioning();
+                repaired.setLastUpdated( versioning.getLastUpdated() );
+                Snapshot snapshot = new Snapshot();
+                snapshot.setLocalCopy( true );
+                repaired.setSnapshot( snapshot );
+                versioning = repaired;
+
+                throw new IOException( "Snapshot information corrupted with 
remote repository data"
+                                           + ", please verify that no remote 
repository uses the id '"
+                                           + repository.getId() + "'" );
+            }
         }
         catch ( Exception e )
         {
             invalidMetadata( session, trace, metadata, repository, e );
             result.addException( e );
         }
-        finally
-        {
-            try
-            {
-                if ( fis != null )
-                {
-                    fis.close();
-                }
-            }
-            catch ( final IOException e )
-            {
-                this.logger.warn( "Failure closing file.", e );
-            }
-        }
 
         return ( versioning != null ) ? versioning : new Versioning();
     }

http://git-wip-us.apache.org/repos/asf/maven/blob/e91a209a/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java
----------------------------------------------------------------------
diff --git 
a/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java
 
b/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java
index bad1454..4111434 100644
--- 
a/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java
+++ 
b/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java
@@ -262,10 +262,8 @@ public class DefaultMavenPluginManager
     private PluginDescriptor parsePluginDescriptor( InputStream is, Plugin 
plugin, String descriptorLocation )
         throws PluginDescriptorParsingException
     {
-        try
+        try ( Reader reader = ReaderFactory.newXmlReader( is ) )
         {
-            Reader reader = ReaderFactory.newXmlReader( is );
-
             PluginDescriptor pluginDescriptor = builder.build( reader, 
descriptorLocation );
 
             return pluginDescriptor;

Reply via email to