maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r674333 - in /maven: artifact/trunk/src/main/java/org/apache/maven/artifact/manager/ artifact/trunk/src/test/java/org/apache/maven/artifact/ artifact/trunk/src/test/java/org/apache/maven/artifact/manager/ components/trunk/maven-project/src/...
Date Sun, 06 Jul 2008 18:43:18 GMT
Author: brett
Date: Sun Jul  6 11:43:17 2008
New Revision: 674333

URL: http://svn.apache.org/viewvc?rev=674333&view=rev
Log:
[MARTIFACT-25] cache failed POM downloads in the local repository, obeying the <releases>
policy for checking for updates on them

Modified:
    maven/artifact/trunk/src/main/java/org/apache/maven/artifact/manager/DefaultUpdateCheckManager.java
    maven/artifact/trunk/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java
    maven/artifact/trunk/src/main/java/org/apache/maven/artifact/manager/UpdateCheckManager.java
    maven/artifact/trunk/src/main/java/org/apache/maven/artifact/manager/WagonManager.java
    maven/artifact/trunk/src/test/java/org/apache/maven/artifact/AbstractArtifactComponentTestCase.java
    maven/artifact/trunk/src/test/java/org/apache/maven/artifact/manager/DefaultUpdateCheckManagerTest.java
    maven/artifact/trunk/src/test/java/org/apache/maven/artifact/manager/DefaultWagonManagerTest.java
    maven/artifact/trunk/src/test/java/org/apache/maven/artifact/manager/WagonNoOp.java
    maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java

Modified: maven/artifact/trunk/src/main/java/org/apache/maven/artifact/manager/DefaultUpdateCheckManager.java
URL: http://svn.apache.org/viewvc/maven/artifact/trunk/src/main/java/org/apache/maven/artifact/manager/DefaultUpdateCheckManager.java?rev=674333&r1=674332&r2=674333&view=diff
==============================================================================
--- maven/artifact/trunk/src/main/java/org/apache/maven/artifact/manager/DefaultUpdateCheckManager.java
(original)
+++ maven/artifact/trunk/src/main/java/org/apache/maven/artifact/manager/DefaultUpdateCheckManager.java
Sun Jul  6 11:43:17 2008
@@ -73,6 +73,11 @@
         // release-artifact short circuit above.
         ArtifactRepositoryPolicy policy = repository.getSnapshots();
 
+        return isUpdateRequired( artifact, repository, policy );
+    }
+
+    private boolean isUpdateRequired( Artifact artifact, ArtifactRepository repository, ArtifactRepositoryPolicy
policy )
+    {
         File file = artifact.getFile();
 
         if ( !policy.isEnabled() )
@@ -346,4 +351,9 @@
         return new File( file.getParent(), TOUCHFILE_NAME );
     }
 
+    public boolean isPomUpdateRequired( Artifact artifact, ArtifactRepository repository
)
+    {
+        return isUpdateRequired( artifact, repository, repository.getReleases() );
+    }
+
 }

Modified: maven/artifact/trunk/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java
URL: http://svn.apache.org/viewvc/maven/artifact/trunk/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java?rev=674333&r1=674332&r2=674333&view=diff
==============================================================================
--- maven/artifact/trunk/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java
(original)
+++ maven/artifact/trunk/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java
Sun Jul  6 11:43:17 2008
@@ -19,6 +19,18 @@
  * under the License.
  */
 
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.security.NoSuchAlgorithmException;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.metadata.ArtifactMetadata;
 import org.apache.maven.artifact.repository.ArtifactRepository;
@@ -53,18 +65,6 @@
 import org.codehaus.plexus.util.FileUtils;
 import org.codehaus.plexus.util.xml.Xpp3Dom;
 
-import java.io.File;
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.security.NoSuchAlgorithmException;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
 /** @plexus.component */
 public class DefaultWagonManager
     extends AbstractLogEnabled
@@ -410,6 +410,42 @@
 
             artifact.setResolved( true );
         }
+
+        // XXX: This is not really intended for the long term - unspecified POMs should be
converted to failures
+        //      meaning caching would be unnecessary. The code for this is here instead of
the MavenMetadataSource
+        //      to keep the logic related to update checks enclosed, and so to keep the rules
reasonably consistent
+        //      with release metadata
+        else if ( "pom".equals( artifact.getType() ) && !artifact.getFile().exists()
)
+        {
+            // if POM is not present locally, try and get it if it's forced, out of date,
or has not been attempted yet  
+            if ( force || updateCheckManager.isPomUpdateRequired( artifact, repository )
)
+            {
+                getLogger().debug( "Trying repository " + repository.getId() );
+
+                try
+                {
+                    getRemoteFile( getMirrorRepository( repository ), artifact.getFile(),
remotePath, downloadMonitor,
+                                   policy.getChecksumPolicy(), false );
+                }
+                catch ( ResourceDoesNotExistException e )
+                {
+                    // cache the POM failure
+                    updateCheckManager.touch( artifact, repository );
+                    
+                    throw e;
+                }
+
+                getLogger().debug( "  Artifact resolved" );
+
+                artifact.setResolved( true );
+            }
+            else
+            {
+                // cached failure - pass on the failure
+                throw new ResourceDoesNotExistException( "Failure was cached in the local
repository" );
+            }
+        }
+        
         // If it's not a snapshot artifact, then we don't care what the force flag says.
If it's on the local
         // system, it's resolved. Releases are presumed to be immutable, so release artifacts
are not ever updated.
         // NOTE: This is NOT the case for metadata files on relese-only repositories. This
metadata may contain information
@@ -1153,4 +1189,9 @@
     {
         credentialsDataSource = cds;
     }
+
+    public void setUpdateCheckManager( UpdateCheckManager updateCheckManager )
+    {
+        this.updateCheckManager = updateCheckManager;        
+    }
 }

Modified: maven/artifact/trunk/src/main/java/org/apache/maven/artifact/manager/UpdateCheckManager.java
URL: http://svn.apache.org/viewvc/maven/artifact/trunk/src/main/java/org/apache/maven/artifact/manager/UpdateCheckManager.java?rev=674333&r1=674332&r2=674333&view=diff
==============================================================================
--- maven/artifact/trunk/src/main/java/org/apache/maven/artifact/manager/UpdateCheckManager.java
(original)
+++ maven/artifact/trunk/src/main/java/org/apache/maven/artifact/manager/UpdateCheckManager.java
Sun Jul  6 11:43:17 2008
@@ -37,4 +37,6 @@
 
 	void touch( RepositoryMetadata metadata, ArtifactRepository repository, File file );
 
+    boolean isPomUpdateRequired( Artifact artifact, ArtifactRepository repository );
+
 }

Modified: maven/artifact/trunk/src/main/java/org/apache/maven/artifact/manager/WagonManager.java
URL: http://svn.apache.org/viewvc/maven/artifact/trunk/src/main/java/org/apache/maven/artifact/manager/WagonManager.java?rev=674333&r1=674332&r2=674333&view=diff
==============================================================================
--- maven/artifact/trunk/src/main/java/org/apache/maven/artifact/manager/WagonManager.java
(original)
+++ maven/artifact/trunk/src/main/java/org/apache/maven/artifact/manager/WagonManager.java
Sun Jul  6 11:43:17 2008
@@ -37,6 +37,8 @@
 import java.io.File;
 import java.util.Collection;
 import java.util.List;
+import java.util.Map;
+import java.util.Set;
 
 /**
  * Manages <a href="http://maven.apache.org/wagon">Wagon</a> related operations
in Maven.

Modified: maven/artifact/trunk/src/test/java/org/apache/maven/artifact/AbstractArtifactComponentTestCase.java
URL: http://svn.apache.org/viewvc/maven/artifact/trunk/src/test/java/org/apache/maven/artifact/AbstractArtifactComponentTestCase.java?rev=674333&r1=674332&r2=674333&view=diff
==============================================================================
--- maven/artifact/trunk/src/test/java/org/apache/maven/artifact/AbstractArtifactComponentTestCase.java
(original)
+++ maven/artifact/trunk/src/test/java/org/apache/maven/artifact/AbstractArtifactComponentTestCase.java
Sun Jul  6 11:43:17 2008
@@ -41,6 +41,26 @@
 public abstract class AbstractArtifactComponentTestCase
     extends PlexusTestCase
 {
+    protected ArtifactFactory artifactFactory;
+
+    @Override
+    protected void setUp()
+        throws Exception
+    {
+        super.setUp();
+
+        artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
+    }
+    
+    @Override
+    protected void tearDown()
+        throws Exception
+    {
+        release( artifactFactory );
+        
+        super.tearDown();
+    }
+
     protected abstract String component();
 
     /**
@@ -248,8 +268,6 @@
     protected Artifact createArtifact( String groupId, String artifactId, String version,
String type )
         throws Exception
     {
-        ArtifactFactory artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE
);
-
         return artifactFactory.createBuildArtifact( groupId, artifactId, version, type );
     }
 

Modified: maven/artifact/trunk/src/test/java/org/apache/maven/artifact/manager/DefaultUpdateCheckManagerTest.java
URL: http://svn.apache.org/viewvc/maven/artifact/trunk/src/test/java/org/apache/maven/artifact/manager/DefaultUpdateCheckManagerTest.java?rev=674333&r1=674332&r2=674333&view=diff
==============================================================================
--- maven/artifact/trunk/src/test/java/org/apache/maven/artifact/manager/DefaultUpdateCheckManagerTest.java
(original)
+++ maven/artifact/trunk/src/test/java/org/apache/maven/artifact/manager/DefaultUpdateCheckManagerTest.java
Sun Jul  6 11:43:17 2008
@@ -1,5 +1,24 @@
 package org.apache.maven.artifact.manager;
 
+/*
+ * 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.io.File;
 
 import org.apache.maven.artifact.AbstractArtifactComponentTestCase;
@@ -86,6 +105,60 @@
         assertNotNull( updateCheckManager.readLastUpdated( touchFile, remoteRepository.getId()
) );
     }
 
+    public void testPom() throws Exception
+    {
+        ArtifactRepository remoteRepository = remoteRepository();
+
+        ArtifactRepository localRepository = localRepository();
+
+        Artifact a = createArtifact( "a", "0.0.1", "pom" );
+        File file = new File( localRepository.getBasedir(), 
+                              localRepository.pathOf( a ) );
+        file.delete();
+        a.setFile( file );
+
+        File touchFile = updateCheckManager.getTouchfile( a );
+        touchFile.delete();
+
+        assertTrue( updateCheckManager.isPomUpdateRequired( a, remoteRepository ) );
+
+        file.getParentFile().mkdirs();
+        file.createNewFile();
+        updateCheckManager.touch( a, remoteRepository );
+
+        assertFalse( updateCheckManager.isPomUpdateRequired( a, remoteRepository ) );
+
+        assertNull( updateCheckManager.readLastUpdated( touchFile, remoteRepository.getId()
) );
+        
+        assertFalse( updateCheckManager.getTouchfile( a ).exists() );
+    }
+
+    public void testMissingPom()
+        throws Exception
+    {
+        ArtifactRepository remoteRepository = remoteRepository();
+
+        ArtifactRepository localRepository = localRepository();
+
+        Artifact a = createArtifact( "a", "0.0.1", "pom" );
+        File file = new File( localRepository.getBasedir(), 
+                              localRepository.pathOf( a ) );
+        file.delete();
+        a.setFile( file );
+
+        File touchFile = updateCheckManager.getTouchfile( a );
+        touchFile.delete();
+
+        assertTrue( updateCheckManager.isPomUpdateRequired( a, remoteRepository ) );
+
+        updateCheckManager.touch( a, remoteRepository );
+
+        assertFalse( updateCheckManager.isPomUpdateRequired( a, remoteRepository ) );
+
+        assertFalse( file.exists() );
+        assertNotNull( updateCheckManager.readLastUpdated( touchFile, remoteRepository.getId()
) );
+    }
+
     public void testMetadata() throws Exception
     {
         ArtifactRepository remoteRepository = remoteRepository();

Modified: maven/artifact/trunk/src/test/java/org/apache/maven/artifact/manager/DefaultWagonManagerTest.java
URL: http://svn.apache.org/viewvc/maven/artifact/trunk/src/test/java/org/apache/maven/artifact/manager/DefaultWagonManagerTest.java?rev=674333&r1=674332&r2=674333&view=diff
==============================================================================
--- maven/artifact/trunk/src/test/java/org/apache/maven/artifact/manager/DefaultWagonManagerTest.java
(original)
+++ maven/artifact/trunk/src/test/java/org/apache/maven/artifact/manager/DefaultWagonManagerTest.java
Sun Jul  6 11:43:17 2008
@@ -20,9 +20,11 @@
  */
 
 import java.io.File;
+import java.io.IOException;
 
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.DefaultArtifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.metadata.ArtifactMetadata;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
@@ -30,13 +32,18 @@
 import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
 import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
 import org.apache.maven.artifact.versioning.VersionRange;
+import org.apache.maven.wagon.ResourceDoesNotExistException;
+import org.apache.maven.wagon.TransferFailedException;
 import org.apache.maven.wagon.UnsupportedProtocolException;
 import org.apache.maven.wagon.Wagon;
+import org.apache.maven.wagon.authorization.AuthorizationException;
 import org.apache.maven.wagon.events.TransferListener;
 import org.apache.maven.wagon.observers.Debug;
 import org.apache.maven.wagon.repository.Repository;
 import org.codehaus.plexus.PlexusTestCase;
+import org.codehaus.plexus.util.FileUtils;
 import org.codehaus.plexus.util.xml.Xpp3Dom;
+import org.easymock.MockControl;
 
 /**
  * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
@@ -46,18 +53,205 @@
     extends PlexusTestCase
 {
 
-    private WagonManager wagonManager;
+    private DefaultWagonManager wagonManager;
 
     private TransferListener transferListener = new Debug();
 
+    private ArtifactFactory artifactFactory;
+
     protected void setUp()
         throws Exception
     {
         super.setUp();
 
-        wagonManager = (WagonManager) lookup( WagonManager.ROLE );
+        wagonManager = (DefaultWagonManager) lookup( WagonManager.ROLE );
+        
+        artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
+    }
+
+    public void testGetMissingPomUncached() throws TransferFailedException, UnsupportedProtocolException,
IOException
+    {
+        Artifact artifact = createTestPomArtifact( "target/test-data/get-missing-pom" );
+        
+        ArtifactRepository repo = createNoOpRepo();
+        
+        MockControl control = MockControl.createControl( UpdateCheckManager.class );
+        UpdateCheckManager updateCheckManager = (UpdateCheckManager) control.getMock();
+        wagonManager.setUpdateCheckManager( updateCheckManager );
+        
+        updateCheckManager.isPomUpdateRequired( artifact, repo );
+        control.setReturnValue( true );
+        updateCheckManager.touch( artifact, repo );        
+        control.replay();        
+        
+        try
+        {
+            wagonManager.getArtifact( artifact, repo, false );
+            
+            fail();
+        }
+        catch ( ResourceDoesNotExistException e )
+        {
+            assertTrue( true );
+        }
+        
+        assertFalse( artifact.getFile().exists() );
+        
+        control.verify();
+    }
+
+    private Artifact createTestPomArtifact( String directory )
+        throws IOException
+    {
+        File testData = getTestFile( directory );
+        FileUtils.deleteDirectory( testData );
+        testData.mkdirs();
+
+        Artifact artifact = artifactFactory.createProjectArtifact( "test", "test", "1.0"
);
+        artifact.setFile( new File( testData, "test-1.0.pom" ) );
+        assertFalse( artifact.getFile().exists() );
+        return artifact;
+    }
+    
+    public void testGetMissingPomCached() throws TransferFailedException, UnsupportedProtocolException,
IOException
+    {
+        Artifact artifact = createTestPomArtifact( "target/test-data/get-missing-pom" );
+        
+        ArtifactRepository repo = createNoOpRepo();
+        
+        MockControl control = MockControl.createControl( UpdateCheckManager.class );
+        UpdateCheckManager updateCheckManager = (UpdateCheckManager) control.getMock();
+        wagonManager.setUpdateCheckManager( updateCheckManager );
+        
+        updateCheckManager.isPomUpdateRequired( artifact, repo );
+        control.setReturnValue( false );
+        control.replay();        
+        
+        try
+        {
+            wagonManager.getArtifact( artifact, repo, false );
+            
+            fail();
+        }
+        catch ( ResourceDoesNotExistException e )
+        {
+            assertTrue( true );
+        }
+        
+        assertFalse( artifact.getFile().exists() );
+        
+        control.verify();
+    }
+    
+    public void testGetMissingPomCachedForced() throws TransferFailedException, UnsupportedProtocolException,
IOException
+    {
+        Artifact artifact = createTestPomArtifact( "target/test-data/get-missing-pom" );
+        
+        ArtifactRepository repo = createNoOpRepo();
+        
+        MockControl control = MockControl.createControl( UpdateCheckManager.class );
+        UpdateCheckManager updateCheckManager = (UpdateCheckManager) control.getMock();
+        wagonManager.setUpdateCheckManager( updateCheckManager );
+        
+        updateCheckManager.touch( artifact, repo );        
+        control.replay();        
+        
+        try
+        {
+            wagonManager.getArtifact( artifact, repo, true );
+            
+            fail();
+        }
+        catch ( ResourceDoesNotExistException e )
+        {
+            assertTrue( true );
+        }
+        
+        assertFalse( artifact.getFile().exists() );
+        
+        control.verify();
+    }
+    
+    public void testGetRemotePom()
+        throws TransferFailedException, ResourceDoesNotExistException, UnsupportedProtocolException,
IOException, AuthorizationException
+    {
+        Artifact artifact = createTestPomArtifact( "target/test-data/get-remote-pom" );
+        
+        ArtifactRepository repo = createNoOpRepo();
+        
+        WagonNoOp wagon = (WagonNoOp) wagonManager.getWagon( "noop" );
+        wagon.setExpectedContent( "expected" );
+        
+        MockControl control = MockControl.createControl( UpdateCheckManager.class );
+        UpdateCheckManager updateCheckManager = (UpdateCheckManager) control.getMock();
+        wagonManager.setUpdateCheckManager( updateCheckManager );
+        
+        updateCheckManager.isPomUpdateRequired( artifact, repo );
+        control.setReturnValue( true );
+        control.replay();        
+        
+        wagonManager.getArtifact( artifact, repo, false );
+        
+        assertTrue( artifact.getFile().exists() );
+        
+        control.verify();
+    }
+
+    public void testGetPomExistsLocally()
+        throws IOException, TransferFailedException, ResourceDoesNotExistException, UnsupportedProtocolException
+    {
+        Artifact artifact = createTestPomArtifact( "target/test-data/get-remote-pom" );
+        artifact.getFile().createNewFile();
+
+        ArtifactRepository repo = createNoOpRepo();
+
+        WagonNoOp wagon = (WagonNoOp) wagonManager.getWagon( "noop" );
+        wagon.setExpectedContent( "expected" );
+        
+        MockControl control = MockControl.createControl( UpdateCheckManager.class );
+        UpdateCheckManager updateCheckManager = (UpdateCheckManager) control.getMock();
+        wagonManager.setUpdateCheckManager( updateCheckManager );
+
+        control.replay();
+
+        wagonManager.getArtifact( artifact, repo, false );
+
+        assertTrue( artifact.getFile().exists() );
+
+        control.verify();
     }
 
+    public void testGetPomExistsLocallyForced()
+        throws IOException, TransferFailedException, ResourceDoesNotExistException, UnsupportedProtocolException
+    {
+        Artifact artifact = createTestPomArtifact( "target/test-data/get-remote-pom" );
+        artifact.getFile().createNewFile();
+
+        ArtifactRepository repo = createNoOpRepo();
+
+        WagonNoOp wagon = (WagonNoOp) wagonManager.getWagon( "noop" );
+        wagon.setExpectedContent( "expected" );
+        
+        MockControl control = MockControl.createControl( UpdateCheckManager.class );
+        UpdateCheckManager updateCheckManager = (UpdateCheckManager) control.getMock();
+        wagonManager.setUpdateCheckManager( updateCheckManager );
+
+        control.replay();
+
+        wagonManager.getArtifact( artifact, repo, true );
+
+        assertTrue( artifact.getFile().exists() );
+
+        control.verify();
+    }
+
+    private ArtifactRepository createNoOpRepo()
+    {
+        ArtifactRepository repo =
+            new DefaultArtifactRepository( "id", "noop://url", new ArtifactRepositoryLayoutStub()
);
+        return repo;
+    }
+    
     /**
      * checks the handling of urls
      */
@@ -310,9 +504,9 @@
                 new DefaultArtifact( "sample.group", "sample-art", VersionRange.createFromVersion(
"1.0" ),
                                      "artifactScope", "type", "classifier", null );
             artifact.setFile( tmpFile );
-            ArtifactRepository repo =
-                new DefaultArtifactRepository( "id", "noop://url", new ArtifactRepositoryLayoutStub()
);
+            ArtifactRepository repo = createNoOpRepo();
             WagonNoOp wagon = (WagonNoOp) wagonManager.getWagon( "noop" );
+            wagon.setExpectedContent( "" );
 
             /* getArtifact */
             assertFalse( "Transfer listener is registered before test",

Modified: maven/artifact/trunk/src/test/java/org/apache/maven/artifact/manager/WagonNoOp.java
URL: http://svn.apache.org/viewvc/maven/artifact/trunk/src/test/java/org/apache/maven/artifact/manager/WagonNoOp.java?rev=674333&r1=674332&r2=674333&view=diff
==============================================================================
--- maven/artifact/trunk/src/test/java/org/apache/maven/artifact/manager/WagonNoOp.java (original)
+++ maven/artifact/trunk/src/test/java/org/apache/maven/artifact/manager/WagonNoOp.java Sun
Jul  6 11:43:17 2008
@@ -27,10 +27,17 @@
 import org.apache.maven.wagon.TransferFailedException;
 import org.apache.maven.wagon.authorization.AuthorizationException;
 import org.apache.maven.wagon.resource.Resource;
+import org.codehaus.plexus.util.FileUtils;
 
 public class WagonNoOp
     extends AbstractWagon
 {
+    private String expectedContent;
+    
+    public void setExpectedContent( String expectedContent )
+    {
+        this.expectedContent = expectedContent ;
+    }
 
     public void closeConnection()
     {
@@ -51,7 +58,14 @@
         fireGetStarted( resource, destination );
         try
         {
-            destination.createNewFile();
+            if ( expectedContent != null )
+            {
+                FileUtils.fileWrite( destination.getAbsolutePath(), expectedContent );
+            }
+            else
+            {
+                throw new ResourceDoesNotExistException( "Mock wagon had no content set"
);
+            }
         }
         catch ( IOException e )
         {

Modified: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java?rev=674333&r1=674332&r2=674333&view=diff
==============================================================================
--- maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java
(original)
+++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java
Sun Jul  6 11:43:17 2008
@@ -133,14 +133,7 @@
                 }
                 catch ( InvalidProjectModelException e )
                 {
-                    if ( strictlyEnforceThePresenceOfAValidMavenPOM )
-                    {
-                        throw new ArtifactMetadataRetrievalException( "Invalid POM file for
artifact: '" +
-                            artifact.getDependencyConflictId() + "' Reason: " + e.getMessage(),
e, artifact );
-                    }
-
-                    getLogger().warn( "POM for \'" + pomArtifact +
-                        "\' is invalid. It will be ignored for artifact resolution. Reason:
" + e.getMessage() );
+                    handleInvalidOrMissingMavenPOM( artifact, e );
 
                     if ( getLogger().isDebugEnabled() )
                     {
@@ -167,11 +160,7 @@
                 }
                 catch ( ProjectBuildingException e )
                 {
-                    if ( strictlyEnforceThePresenceOfAValidMavenPOM )
-                    {
-                        throw new ArtifactMetadataRetrievalException( "Unable to read the
metadata file for artifact '" +
-                            artifact.getDependencyConflictId() + "': " + e.getMessage(),
e, artifact );
-                    }
+                    handleInvalidOrMissingMavenPOM( artifact, e );
                 }
 
                 if ( project != null )
@@ -293,6 +282,25 @@
         return result;
     }
 
+    private void handleInvalidOrMissingMavenPOM( Artifact artifact, ProjectBuildingException
e )
+        throws ArtifactMetadataRetrievalException
+    {
+        if ( strictlyEnforceThePresenceOfAValidMavenPOM )
+        {
+            throw new ArtifactMetadataRetrievalException( "Invalid POM file for artifact:
'" +
+                artifact.getDependencyConflictId() + "': " + e.getMessage(), e, artifact
);
+        }
+        else
+        {
+            getLogger().warn(
+                              "\n\tDEPRECATION: The POM for the artifact '"
+                                  + artifact.getDependencyConflictId()
+                                  + "' was invalid or not found on any repositories.\n"
+                                  + "\tThis may not be supported by future versions of Maven
and should be corrected as soon as possible.\n"
+                                  + "\tError given: " + e.getMessage() + "\n" );
+        }
+    }
+
     private void loadProjectBuilder()
         throws ComponentLookupException
     {



Mime
View raw message