maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From car...@apache.org
Subject svn commit: r574414 - /maven/components/branches/maven-2.0.x/maven-artifact-manager/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java
Date Tue, 11 Sep 2007 00:36:32 GMT
Author: carlos
Date: Mon Sep 10 17:36:31 2007
New Revision: 574414

URL: http://svn.apache.org/viewvc?rev=574414&view=rev
Log:
Improve readingness of code. Merged rev# 574413

Modified:
    maven/components/branches/maven-2.0.x/maven-artifact-manager/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java

Modified: maven/components/branches/maven-2.0.x/maven-artifact-manager/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java
URL: http://svn.apache.org/viewvc/maven/components/branches/maven-2.0.x/maven-artifact-manager/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java?rev=574414&r1=574413&r2=574414&view=diff
==============================================================================
--- maven/components/branches/maven-2.0.x/maven-artifact-manager/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java
(original)
+++ maven/components/branches/maven-2.0.x/maven-artifact-manager/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java
Mon Sep 10 17:36:31 2007
@@ -83,160 +83,162 @@
                           boolean force )
         throws ArtifactResolutionException, ArtifactNotFoundException
     {
-        if ( artifact != null )
+        if ( artifact == null )
         {
-            if ( Artifact.SCOPE_SYSTEM.equals( artifact.getScope() ) )
-            {
-                File systemFile = artifact.getFile();
+            return;
+        }
 
-                if ( systemFile == null )
-                {
-                    throw new ArtifactNotFoundException(
-                        "System artifact: " + artifact + " has no file attached", artifact
);
-                }
+        if ( Artifact.SCOPE_SYSTEM.equals( artifact.getScope() ) )
+        {
+            File systemFile = artifact.getFile();
 
-                if ( !systemFile.exists() )
-                {
-                    throw new ArtifactNotFoundException(
-                        "System artifact: " + artifact + " not found in path: " + systemFile,
artifact );
-                }
-                else
-                {
-                    artifact.setResolved( true );
-                }
+            if ( systemFile == null )
+            {
+                throw new ArtifactNotFoundException(
+                    "System artifact: " + artifact + " has no file attached", artifact );
             }
-            else if ( !artifact.isResolved() )
+
+            if ( !systemFile.exists() )
             {
-                // ----------------------------------------------------------------------
-                // Check for the existence of the artifact in the specified local
-                // ArtifactRepository. If it is present then simply return as the
-                // request for resolution has been satisfied.
-                // ----------------------------------------------------------------------
+                throw new ArtifactNotFoundException(
+                    "System artifact: " + artifact + " not found in path: " + systemFile,
artifact );
+            }
+            else
+            {
+                artifact.setResolved( true );
+            }
+        }
+        else if ( !artifact.isResolved() )
+        {
+            // ----------------------------------------------------------------------
+            // Check for the existence of the artifact in the specified local
+            // ArtifactRepository. If it is present then simply return as the
+            // request for resolution has been satisfied.
+            // ----------------------------------------------------------------------
 
-                String localPath = localRepository.pathOf( artifact );
+            String localPath = localRepository.pathOf( artifact );
 
-                artifact.setFile( new File( localRepository.getBasedir(), localPath ) );
+            artifact.setFile( new File( localRepository.getBasedir(), localPath ) );
 
-                transformationManager.transformForResolve( artifact, remoteRepositories,
localRepository );
+            transformationManager.transformForResolve( artifact, remoteRepositories, localRepository
);
 
-                boolean localCopy = false;
-                for ( Iterator i = artifact.getMetadataList().iterator(); i.hasNext(); )
+            boolean localCopy = false;
+            for ( Iterator i = artifact.getMetadataList().iterator(); i.hasNext(); )
+            {
+                ArtifactMetadata m = (ArtifactMetadata) i.next();
+                if ( m instanceof SnapshotArtifactRepositoryMetadata )
                 {
-                    ArtifactMetadata m = (ArtifactMetadata) i.next();
-                    if ( m instanceof SnapshotArtifactRepositoryMetadata )
-                    {
-                        SnapshotArtifactRepositoryMetadata snapshotMetadata = (SnapshotArtifactRepositoryMetadata)
m;
+                    SnapshotArtifactRepositoryMetadata snapshotMetadata = (SnapshotArtifactRepositoryMetadata)
m;
 
-                        Metadata metadata = snapshotMetadata.getMetadata();
-                        if ( metadata != null )
+                    Metadata metadata = snapshotMetadata.getMetadata();
+                    if ( metadata != null )
+                    {
+                        Versioning versioning = metadata.getVersioning();
+                        if ( versioning != null )
                         {
-                            Versioning versioning = metadata.getVersioning();
-                            if ( versioning != null )
+                            Snapshot snapshot = versioning.getSnapshot();
+                            if ( snapshot != null )
                             {
-                                Snapshot snapshot = versioning.getSnapshot();
-                                if ( snapshot != null )
-                                {
-                                    localCopy = snapshot.isLocalCopy();
-                                }
+                                localCopy = snapshot.isLocalCopy();
                             }
                         }
                     }
                 }
+            }
 
-                File destination = artifact.getFile();
-                List repositories = remoteRepositories;
+            File destination = artifact.getFile();
+            List repositories = remoteRepositories;
 
-                // TODO: would prefer the snapshot transformation took care of this. Maybe
we need a "shouldresolve" flag.
-                if ( artifact.isSnapshot() && artifact.getBaseVersion().equals( artifact.getVersion()
) &&
-                    destination.exists() && !localCopy )
-                {
-                    Date comparisonDate = new Date( destination.lastModified() );
-
-                    // cull to list of repositories that would like an update
-                    repositories = new ArrayList( remoteRepositories );
-                    for ( Iterator i = repositories.iterator(); i.hasNext(); )
-                    {
-                        ArtifactRepository repository = (ArtifactRepository) i.next();
-                        ArtifactRepositoryPolicy policy = repository.getSnapshots();
-                        if ( !policy.isEnabled() || !policy.checkOutOfDate( comparisonDate
) )
-                        {
-                            i.remove();
-                        }
-                    }
+            // TODO: would prefer the snapshot transformation took care of this. Maybe we
need a "shouldresolve" flag.
+            if ( artifact.isSnapshot() && artifact.getBaseVersion().equals( artifact.getVersion()
) &&
+                destination.exists() && !localCopy )
+            {
+                Date comparisonDate = new Date( destination.lastModified() );
 
-                    if ( !repositories.isEmpty() )
+                // cull to list of repositories that would like an update
+                repositories = new ArrayList( remoteRepositories );
+                for ( Iterator i = repositories.iterator(); i.hasNext(); )
+                {
+                    ArtifactRepository repository = (ArtifactRepository) i.next();
+                    ArtifactRepositoryPolicy policy = repository.getSnapshots();
+                    if ( !policy.isEnabled() || !policy.checkOutOfDate( comparisonDate )
)
                     {
-                        // someone wants to check for updates
-                        force = true;
+                        i.remove();
                     }
                 }
-                boolean resolved = false;
-                if ( !destination.exists() || force )
+
+                if ( !repositories.isEmpty() )
                 {
-                    if ( !wagonManager.isOnline() )
-                    {
-                        throw new ArtifactNotFoundException( "System is offline.", artifact
);
-                    }
+                    // someone wants to check for updates
+                    force = true;
+                }
+            }
+            boolean resolved = false;
+            if ( !destination.exists() || force )
+            {
+                if ( !wagonManager.isOnline() )
+                {
+                    throw new ArtifactNotFoundException( "System is offline.", artifact );
+                }
 
-                    try
+                try
+                {
+                    // TODO: force should be passed to the wagon manager
+                    if ( artifact.getRepository() != null )
                     {
-                        // TODO: force should be passed to the wagon manager
-                        if ( artifact.getRepository() != null )
-                        {
-                            // the transformations discovered the artifact - so use it exclusively
-                            wagonManager.getArtifact( artifact, artifact.getRepository()
);
-                        }
-                        else
-                        {
-                            wagonManager.getArtifact( artifact, repositories );
-                        }
-
-                        if ( !artifact.isResolved() && !destination.exists() )
-                        {
-                            throw new ArtifactResolutionException(
-                                "Failed to resolve artifact, possibly due to a repository
list that is not appropriately equipped for this artifact's metadata.",
-                                artifact, remoteRepositories );
-                        }
+                        // the transformations discovered the artifact - so use it exclusively
+                        wagonManager.getArtifact( artifact, artifact.getRepository() );
                     }
-                    catch ( ResourceDoesNotExistException e )
+                    else
                     {
-                        throw new ArtifactNotFoundException( e.getMessage(), artifact, remoteRepositories,
e );
+                        wagonManager.getArtifact( artifact, repositories );
                     }
-                    catch ( TransferFailedException e )
+
+                    if ( !artifact.isResolved() && !destination.exists() )
                     {
-                        throw new ArtifactResolutionException( e.getMessage(), artifact,
remoteRepositories, e );
+                        throw new ArtifactResolutionException(
+                            "Failed to resolve artifact, possibly due to a repository list
that is not appropriately equipped for this artifact's metadata.",
+                            artifact, remoteRepositories );
                     }
-
-                    resolved = true;
                 }
-                else if ( destination.exists() )
+                catch ( ResourceDoesNotExistException e )
                 {
-                    // locally resolved...no need to hit the remote repo.
-                    artifact.setResolved( true );
+                    throw new ArtifactNotFoundException( e.getMessage(), artifact, remoteRepositories,
e );
+                }
+                catch ( TransferFailedException e )
+                {
+                    throw new ArtifactResolutionException( e.getMessage(), artifact, remoteRepositories,
e );
                 }
 
-                if ( artifact.isSnapshot() && !artifact.getBaseVersion().equals(
artifact.getVersion() ) )
+                resolved = true;
+            }
+            else if ( destination.exists() )
+            {
+                // locally resolved...no need to hit the remote repo.
+                artifact.setResolved( true );
+            }
+
+            if ( artifact.isSnapshot() && !artifact.getBaseVersion().equals( artifact.getVersion()
) )
+            {
+                String version = artifact.getVersion();
+                artifact.selectVersion( artifact.getBaseVersion() );
+                File copy = new File( localRepository.getBasedir(), localRepository.pathOf(
artifact ) );
+                if ( resolved || !copy.exists() )
                 {
-                    String version = artifact.getVersion();
-                    artifact.selectVersion( artifact.getBaseVersion() );
-                    File copy = new File( localRepository.getBasedir(), localRepository.pathOf(
artifact ) );
-                    if ( resolved || !copy.exists() )
+                    // recopy file if it was reresolved, or doesn't exist.
+                    try
                     {
-                        // recopy file if it was reresolved, or doesn't exist.
-                        try
-                        {
-                            FileUtils.copyFile( destination, copy );
-                        }
-                        catch ( IOException e )
-                        {
-                            throw new ArtifactResolutionException(
-                                "Unable to copy resolved artifact for local use: " + e.getMessage(),
artifact,
-                                remoteRepositories, e );
-                        }
+                        FileUtils.copyFile( destination, copy );
+                    }
+                    catch ( IOException e )
+                    {
+                        throw new ArtifactResolutionException(
+                            "Unable to copy resolved artifact for local use: " + e.getMessage(),
artifact,
+                            remoteRepositories, e );
                     }
-                    artifact.setFile( copy );
-                    artifact.selectVersion( version );
                 }
+                artifact.setFile( copy );
+                artifact.selectVersion( version );
             }
         }
     }



Mime
View raw message