You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by be...@apache.org on 2009/03/04 15:51:25 UTC

svn commit: r750029 - in /maven/components/trunk: maven-compat/src/main/java/org/apache/maven/artifact/resolver/ maven-core/src/main/java/org/apache/maven/plugin/ maven-repository/src/main/java/org/apache/maven/repository/

Author: bentmann
Date: Wed Mar  4 14:51:24 2009
New Revision: 750029

URL: http://svn.apache.org/viewvc?rev=750029&view=rev
Log:
o Added back some code to actually throw exceptions and abort the normal control flow in case artifact resolution fails

Added:
    maven/components/trunk/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultResolutionErrorHandler.java   (with props)
    maven/components/trunk/maven-compat/src/main/java/org/apache/maven/artifact/resolver/ResolutionErrorHandler.java   (with props)
Modified:
    maven/components/trunk/maven-compat/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionResult.java
    maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java
    maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManagerSupport.java
    maven/components/trunk/maven-repository/src/main/java/org/apache/maven/repository/LegacyMavenRepositorySystem.java

Modified: maven/components/trunk/maven-compat/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionResult.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-compat/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionResult.java?rev=750029&r1=750028&r2=750029&view=diff
==============================================================================
--- maven/components/trunk/maven-compat/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionResult.java (original)
+++ maven/components/trunk/maven-compat/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolutionResult.java Wed Mar  4 14:51:24 2009
@@ -44,7 +44,7 @@
 
     // Exceptions
 
-    private List<Exception> exceptions = new ArrayList<Exception>();
+    private List<Exception> exceptions;
 
     private List<Exception> versionRangeViolations;
 
@@ -104,6 +104,11 @@
         return requestedArtifacts;
     }
 
+    public boolean hasMissingArtifacts()
+    {
+        return missingArtifacts != null && !missingArtifacts.isEmpty();
+    }
+
     public List<Artifact> getMissingArtifacts()
     {
         return missingArtifacts == null ? Collections.<Artifact> emptyList() : missingArtifacts;
@@ -131,12 +136,12 @@
 
     public boolean hasExceptions()
     {
-        return exceptions.size() > 0;
+        return exceptions != null && !exceptions.isEmpty();
     }
 
     public List<Exception> getExceptions()
     {
-        return exceptions;
+        return exceptions == null ? Collections.<Exception> emptyList() : exceptions;
     }
 
     // ------------------------------------------------------------------------
@@ -159,6 +164,8 @@
 
         versionRangeViolations.add( e );
 
+        exceptions = initList( exceptions );
+
         exceptions.add( e );
 
         return this;
@@ -169,9 +176,9 @@
         return (OverConstrainedVersionException) versionRangeViolations.get( i );
     }
 
-    public List getVersionRangeViolations()
+    public List<Exception> getVersionRangeViolations()
     {
-        return versionRangeViolations == null ? Collections.EMPTY_LIST : versionRangeViolations;
+        return versionRangeViolations == null ? Collections.<Exception> emptyList() : versionRangeViolations;
     }
 
     // ------------------------------------------------------------------------
@@ -189,6 +196,8 @@
 
         metadataResolutionExceptions.add( e );
 
+        exceptions = initList( exceptions );
+
         exceptions.add( e );
 
         return this;
@@ -199,9 +208,10 @@
         return metadataResolutionExceptions.get( i );
     }
 
-    public List getMetadataResolutionExceptions()
+    public List<ArtifactResolutionException> getMetadataResolutionExceptions()
     {
-        return metadataResolutionExceptions == null ? Collections.EMPTY_LIST : metadataResolutionExceptions;
+        return metadataResolutionExceptions == null ? Collections.<ArtifactResolutionException> emptyList()
+                        : metadataResolutionExceptions;
     }
 
     // ------------------------------------------------------------------------
@@ -219,6 +229,8 @@
 
         errorArtifactExceptions.add( e );
 
+        exceptions = initList( exceptions );
+
         exceptions.add( e );
 
         return this;
@@ -249,6 +261,8 @@
 
         circularDependencyExceptions.add( e );
 
+        exceptions = initList( exceptions );
+
         exceptions.add( e );
 
         return this;

Added: maven/components/trunk/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultResolutionErrorHandler.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultResolutionErrorHandler.java?rev=750029&view=auto
==============================================================================
--- maven/components/trunk/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultResolutionErrorHandler.java (added)
+++ maven/components/trunk/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultResolutionErrorHandler.java Wed Mar  4 14:51:24 2009
@@ -0,0 +1,88 @@
+package org.apache.maven.artifact.resolver;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.codehaus.plexus.component.annotations.Component;
+
+/**
+ * @author Benjamin Bentmann
+ */
+@Component( role = ResolutionErrorHandler.class )
+public class DefaultResolutionErrorHandler
+    implements ResolutionErrorHandler
+{
+
+    public void throwErrors( ArtifactResolutionRequest request, ArtifactResolutionResult result )
+        throws ArtifactResolutionException
+    {
+        // Metadata cannot be found
+
+        if ( result.hasMetadataResolutionExceptions() )
+        {
+            throw result.getMetadataResolutionException( 0 );
+        }
+
+        // Metadata cannot be retrieved
+
+        // Cyclic Dependency Error
+
+        if ( result.hasCircularDependencyExceptions() )
+        {
+            throw result.getCircularDependencyException( 0 );
+        }
+
+        // Version Range Violation
+
+        if ( result.hasVersionRangeViolations() )
+        {
+            throw result.getVersionRangeViolation( 0 );
+        }
+
+        // Transfer Error
+
+        if ( result.hasErrorArtifactExceptions() )
+        {
+            throw result.getErrorArtifactExceptions().get( 0 );
+        }
+
+        if ( result.hasMissingArtifacts() )
+        {
+            throw new MultipleArtifactsNotFoundException( request.getArtifact(), toList( result.getArtifacts() ),
+                                                          result.getMissingArtifacts(), request.getRemoteRepostories() );
+        }
+
+        // this should never happen since we checked all possible error sources before but better be sure
+        if ( result.hasExceptions() )
+        {
+            throw new ArtifactResolutionException( "Unknown error during artifact resolution, " + request + ", "
+                + result.getExceptions(), request.getArtifact(), request.getRemoteRepostories() );
+        }
+    }
+
+    private static <T> List<T> toList( Collection<T> items )
+    {
+        return ( items != null ) ? new ArrayList<T>( items ) : null;
+    }
+
+}

Propchange: maven/components/trunk/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultResolutionErrorHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultResolutionErrorHandler.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/components/trunk/maven-compat/src/main/java/org/apache/maven/artifact/resolver/ResolutionErrorHandler.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-compat/src/main/java/org/apache/maven/artifact/resolver/ResolutionErrorHandler.java?rev=750029&view=auto
==============================================================================
--- maven/components/trunk/maven-compat/src/main/java/org/apache/maven/artifact/resolver/ResolutionErrorHandler.java (added)
+++ maven/components/trunk/maven-compat/src/main/java/org/apache/maven/artifact/resolver/ResolutionErrorHandler.java Wed Mar  4 14:51:24 2009
@@ -0,0 +1,31 @@
+package org.apache.maven.artifact.resolver;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * @author Benjamin Bentmann
+ */
+public interface ResolutionErrorHandler
+{
+
+    public void throwErrors( ArtifactResolutionRequest request, ArtifactResolutionResult result )
+        throws ArtifactResolutionException;
+
+}

Propchange: maven/components/trunk/maven-compat/src/main/java/org/apache/maven/artifact/resolver/ResolutionErrorHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-compat/src/main/java/org/apache/maven/artifact/resolver/ResolutionErrorHandler.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java?rev=750029&r1=750028&r2=750029&view=diff
==============================================================================
--- maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java (original)
+++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java Wed Mar  4 14:51:24 2009
@@ -43,6 +43,7 @@
 import org.apache.maven.artifact.resolver.ArtifactResolutionException;
 import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
 import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
+import org.apache.maven.artifact.resolver.ResolutionErrorHandler;
 import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
 import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
 import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
@@ -140,6 +141,9 @@
     protected MavenRepositorySystem repositorySystem;
 
     @Requirement
+    private ResolutionErrorHandler resolutionErrorHandler;
+
+    @Requirement
     protected RuntimeInformation runtimeInformation;
 
     @Requirement
@@ -445,11 +449,7 @@
             .setMetadataSource( repositorySystem );        
         
         ArtifactResolutionResult result = repositorySystem.resolve( request );
-        
-        if ( result.hasExceptions() )
-        {
-            result.getExceptions().get(  0 ).printStackTrace();
-        }
+        resolutionErrorHandler.throwErrors( request, result );
         
         Set<Artifact> resolved = new LinkedHashSet<Artifact>();
 
@@ -1494,7 +1494,7 @@
                          
         ArtifactResolutionResult result = repositorySystem.resolve( request );
 
-        if ( result.hasErrorArtifactExceptions() )
+        if ( result.hasMissingArtifacts() )
         {
             /*
              
@@ -1503,15 +1503,14 @@
             all we can do is warn and skip it. A better fix can be inserted into 2.1
             
             */
-            if ( isAggregator && checkMissingArtifactsInReactor( context.getSortedProjects(), result.getMissingArtifacts() ) )
-            {
-            }
-            else
+            if ( isAggregator
+                && checkMissingArtifactsInReactor( context.getSortedProjects(), result.getMissingArtifacts() ) )
             {
-                //we can't find all the artifacts in the reactor so bubble the exception up.
-                throw result.getErrorArtifactExceptions().get( 0 );
+                // all found, so clear up the result state to prevent the error handler from blowing up
+                result.setUnresolvedArtifacts( null );
             }
         }
+        resolutionErrorHandler.throwErrors( request, result );
         
         project.setArtifacts( result.getArtifacts() );
     }

Modified: maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManagerSupport.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManagerSupport.java?rev=750029&r1=750028&r2=750029&view=diff
==============================================================================
--- maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManagerSupport.java (original)
+++ maven/components/trunk/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManagerSupport.java Wed Mar  4 14:51:24 2009
@@ -27,6 +27,8 @@
 import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
 import org.apache.maven.artifact.resolver.ArtifactResolutionException;
 import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
+import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
+import org.apache.maven.artifact.resolver.ResolutionErrorHandler;
 import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
 import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
 import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
@@ -40,7 +42,6 @@
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.project.MavenProjectBuilder;
 import org.apache.maven.project.ProjectBuildingException;
-import org.apache.maven.project.artifact.InvalidDependencyVersionException;
 import org.apache.maven.realm.RealmManagementException;
 import org.apache.maven.realm.RealmScanningUtils;
 import org.apache.maven.repository.MavenRepositorySystem;
@@ -59,6 +60,9 @@
 {
     @Requirement
     private MavenRepositorySystem repositorySystem;
+
+    @Requirement
+    private ResolutionErrorHandler resolutionErrorHandler;
         
     @Requirement
     private MavenProjectBuilder mavenProjectBuilder;
@@ -112,7 +116,10 @@
 
         pluginArtifact = project.replaceWithActiveArtifact( pluginArtifact );
 
-        repositorySystem.resolve( new ArtifactResolutionRequest( pluginArtifact, localRepository, remoteRepositories ) );
+        ArtifactResolutionRequest request =
+            new ArtifactResolutionRequest( pluginArtifact, localRepository, remoteRepositories );
+        ArtifactResolutionResult result = repositorySystem.resolve( request );
+        resolutionErrorHandler.throwErrors( request, result );
 
         return pluginArtifact;
     }

Modified: maven/components/trunk/maven-repository/src/main/java/org/apache/maven/repository/LegacyMavenRepositorySystem.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-repository/src/main/java/org/apache/maven/repository/LegacyMavenRepositorySystem.java?rev=750029&r1=750028&r2=750029&view=diff
==============================================================================
--- maven/components/trunk/maven-repository/src/main/java/org/apache/maven/repository/LegacyMavenRepositorySystem.java (original)
+++ maven/components/trunk/maven-repository/src/main/java/org/apache/maven/repository/LegacyMavenRepositorySystem.java Wed Mar  4 14:51:24 2009
@@ -41,6 +41,7 @@
 import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
 import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
 import org.apache.maven.artifact.resolver.ArtifactResolver;
+import org.apache.maven.artifact.resolver.ResolutionErrorHandler;
 import org.apache.maven.artifact.resolver.filter.AndArtifactFilter;
 import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
 import org.apache.maven.artifact.resolver.filter.ExcludesArtifactFilter;
@@ -84,7 +85,10 @@
 
     @Requirement
     private MirrorBuilder mirrorBuilder;
-    
+
+    @Requirement
+    private ResolutionErrorHandler resolutionErrorHandler;
+
     @Requirement
     private Logger logger;
 
@@ -464,7 +468,10 @@
             projectArtifact = artifactFactory.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getScope() );
         }
 
-        resolve( new ArtifactResolutionRequest( projectArtifact, localRepository, remoteArtifactRepositories ) );
+        ArtifactResolutionRequest request =
+            new ArtifactResolutionRequest( projectArtifact, localRepository, remoteArtifactRepositories );
+        ArtifactResolutionResult result = resolve( request );
+        resolutionErrorHandler.throwErrors( request, result );
 
         File file = projectArtifact.getFile();
         artifact.setFile( file );