maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hbout...@apache.org
Subject git commit: code simplification
Date Thu, 17 Jan 2013 21:56:21 GMT
Updated Branches:
  refs/heads/master 0824df85f -> d22d94903


code simplification

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

Branch: refs/heads/master
Commit: d22d94903ae67ea271d9bd52fc7765e595cd6361
Parents: 0824df8
Author: Hervé Boutemy <hboutemy@apache.org>
Authored: Thu Jan 17 22:56:18 2013 +0100
Committer: Hervé Boutemy <hboutemy@apache.org>
Committed: Thu Jan 17 22:56:18 2013 +0100

----------------------------------------------------------------------
 .../internal/DefaultVersionResolver.java           |   95 ++++++++-------
 1 files changed, 53 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven/blob/d22d9490/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 f360e33..24e9531 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
@@ -22,6 +22,7 @@ package org.apache.maven.repository.internal;
 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;
@@ -36,6 +37,7 @@ import org.codehaus.plexus.component.annotations.Component;
 import org.codehaus.plexus.component.annotations.Requirement;
 import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 import org.sonatype.aether.RepositoryCache;
 import org.sonatype.aether.RepositoryEvent.EventType;
 import org.sonatype.aether.RepositorySystemSession;
@@ -149,8 +151,6 @@ public class DefaultVersionResolver
     public VersionResult resolveVersion( RepositorySystemSession session, VersionRequest
request )
         throws VersionResolutionException
     {
-        RequestTrace trace = DefaultRequestTrace.newChild( request.getTrace(), request );
-
         Artifact artifact = request.getArtifact();
 
         String version = artifact.getVersion();
@@ -219,6 +219,8 @@ public class DefaultVersionResolver
 
             metadataRequests.add( new MetadataRequest( metadata, null, request.getRequestContext()
) );
 
+            RequestTrace trace = DefaultRequestTrace.newChild( request.getTrace(), request
);
+
             for ( RemoteRepository repository : request.getRepositories() )
             {
                 MetadataRequest metadataRequest =
@@ -319,50 +321,35 @@ public class DefaultVersionResolver
     {
         Versioning versioning = null;
 
-        FileInputStream fis = null;
+        SyncContext syncContext = syncContextFactory.newInstance( session, true );
+
         try
         {
-            if ( metadata != null )
-            {
-                SyncContext syncContext = syncContextFactory.newInstance( session, true );
+            syncContext.acquire( null, Collections.singleton( metadata ) );
 
-                try
-                {
-                    syncContext.acquire( null, Collections.singleton( metadata ) );
+            versioning = readMavenRepositoryMetadataVersioning( metadata.getFile() );
 
-                    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 );
-                        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
)
-                        {
-                            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()
-                                    + "'" );
-                            }
-                        }
-                    }
-                }
-                finally
+            /*
+             * 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 )
+            {
+                Snapshot snapshot = versioning.getSnapshot();
+                if ( snapshot != null && snapshot.getBuildNumber() > 0 )
                 {
-                    syncContext.release();
+                    Versioning repaired = new Versioning();
+                    repaired.setLastUpdated( versioning.getLastUpdated() );
+                    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()
+                        + "'" );
                 }
             }
         }
@@ -373,12 +360,36 @@ public class DefaultVersionResolver
         }
         finally
         {
-            IOUtil.close( fis );
+            syncContext.release();
         }
 
         return ( versioning != null ) ? versioning : new Versioning();
     }
 
+    private Versioning readMavenRepositoryMetadataVersioning( File metadataFile )
+        throws IOException, XmlPullParserException
+    {
+        if ( metadataFile == null ||! metadataFile.exists() )
+        {
+            return null;
+        }
+
+        InputStream is = null;
+        try
+        {
+            is = new FileInputStream( metadataFile );
+
+            MetadataXpp3Reader reader = new MetadataXpp3Reader();
+            org.apache.maven.artifact.repository.metadata.Metadata m = reader.read( is, false
);
+
+            return m.getVersioning();
+        }
+        finally
+        {
+            IOUtil.close( is );
+        }
+    }
+
     private void invalidMetadata( RepositorySystemSession session, RequestTrace trace, Metadata
metadata,
                                   ArtifactRepository repository, Exception exception )
     {


Mime
View raw message