maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdca...@apache.org
Subject svn commit: r601954 - in /maven/artifact/trunk: ./ src/main/aspect/org/apache/maven/artifact/aspect/ src/main/java/org/apache/maven/artifact/repository/ src/main/java/org/apache/maven/artifact/repository/metadata/ src/test/java/org/apache/maven/artifac...
Date Fri, 07 Dec 2007 01:11:21 GMT
Author: jdcasey
Date: Thu Dec  6 17:11:19 2007
New Revision: 601954

URL: http://svn.apache.org/viewvc?rev=601954&view=rev
Log:
Fixing continuous checking of snapshot repos when requested metadata doesn't exist on the
remote side.

Added:
    maven/artifact/trunk/src/main/aspect/org/apache/maven/artifact/aspect/ResolverDebugAspect.aj
    maven/artifact/trunk/src/test/java/org/apache/maven/artifact/repository/metadata/DefaultRepositoryMetadataManagerTest.java
  (with props)
Modified:
    maven/artifact/trunk/pom.xml
    maven/artifact/trunk/src/main/aspect/org/apache/maven/artifact/aspect/ResolverCacheAspect.aj
    maven/artifact/trunk/src/main/java/org/apache/maven/artifact/repository/ArtifactRepositoryPolicy.java
    maven/artifact/trunk/src/main/java/org/apache/maven/artifact/repository/metadata/DefaultRepositoryMetadataManager.java
    maven/artifact/trunk/src/test/java/org/apache/maven/artifact/transform/TransformationManagerTest.java

Modified: maven/artifact/trunk/pom.xml
URL: http://svn.apache.org/viewvc/maven/artifact/trunk/pom.xml?rev=601954&r1=601953&r2=601954&view=diff
==============================================================================
--- maven/artifact/trunk/pom.xml (original)
+++ maven/artifact/trunk/pom.xml Thu Dec  6 17:11:19 2007
@@ -112,7 +112,7 @@
           <source>1.5</source>
         </configuration>
       </plugin>
-      <!--
+      <!-- 
       <plugin>
         <groupId>org.codehaus.mojo</groupId>
         <artifactId>aspectj-maven-plugin</artifactId>

Modified: maven/artifact/trunk/src/main/aspect/org/apache/maven/artifact/aspect/ResolverCacheAspect.aj
URL: http://svn.apache.org/viewvc/maven/artifact/trunk/src/main/aspect/org/apache/maven/artifact/aspect/ResolverCacheAspect.aj?rev=601954&r1=601953&r2=601954&view=diff
==============================================================================
--- maven/artifact/trunk/src/main/aspect/org/apache/maven/artifact/aspect/ResolverCacheAspect.aj
(original)
+++ maven/artifact/trunk/src/main/aspect/org/apache/maven/artifact/aspect/ResolverCacheAspect.aj
Thu Dec  6 17:11:19 2007
@@ -26,187 +26,187 @@
 public privileged aspect ResolverCacheAspect
 {
 
-    declare parents: DefaultArtifactResolver implements Contextualizable;
-
-    private Map<String, Artifact> DefaultArtifactResolver.cachedSingleResolutions =
-        new HashMap<String, Artifact>();
-
-    private Map<String, ArtifactResolutionResult> DefaultArtifactResolver.cachedResolutionResults
=
-        new HashMap<String, ArtifactResolutionResult>();
-
-    private PlexusContainer DefaultArtifactResolver.container;
-    private Logger DefaultArtifactResolver.logger;
-
-    // NOTE: We implement advice on this method rather than setting the container instance
-    // directly, so we can still recover the container even if the resolver implementation
-    // happens to override the method.
-    public void DefaultArtifactResolver.contextualize( Context context ) throws ContextException
-    {
-        if ( container == null )
-        {
-            container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
-            logger = container.getLoggerManager().getLoggerForComponent( ArtifactResolver.ROLE
);
-
-            logger.debug( "DefaultArtifactResolver caching aspect captured PlexusContainer
instance." );
-        }
-    }
-
-    private pointcut deprecatedSingleResolveCall( Artifact artifact, DefaultArtifactResolver
resolver ):
-        execution( void DefaultArtifactResolver+.resolve( Artifact, .. ) )
-        && args( artifact, .. )
-        && this( resolver );
-
-    void around( Artifact artifact, DefaultArtifactResolver resolver )
-        throws ArtifactResolutionException, ArtifactNotFoundException:
-        deprecatedSingleResolveCall( artifact, resolver )
-    {
-        System.out.println( "Cache check for: " + artifact + " using resolver: " + resolver
+ " (has logger? " + ( resolver != null && resolver.logger != null ) + ")" );
-
-        String key = createCacheKey( null, (Set<Artifact>) Collections.singleton( artifact
), null, null );
-        resolver.logger.debug( "Checking artifact resolution cache for: " + key );
-
-        Artifact cached = resolver.cachedSingleResolutions.get( key );
-        if ( cached != null )
-        {
-            resolver.logger.debug( "Using cached copy of: " + key );
-            copyFromCached( artifact, cached );
-
-            return;
-        }
-
-        proceed( artifact, resolver );
-
-        resolver.logger.debug( "Caching: " + key );
-        resolver.cachedSingleResolutions.put( key, artifact );
-    }
-
-    private pointcut deprecatedTransitiveResolveCall( Set artifacts, Artifact originatingArtifact,
DefaultArtifactResolver resolver ):
-        execution( ArtifactResolutionResult DefaultArtifactResolver+.resolveTransitively(
Set, Artifact, .. ) )
-        && args( artifacts, originatingArtifact, .. )
-        && this( resolver );
-
-    @SuppressWarnings("unchecked")
-    ArtifactResolutionResult around( Set artifacts, Artifact originatingArtifact, DefaultArtifactResolver
resolver )
-        throws ArtifactResolutionException, ArtifactNotFoundException:
-        deprecatedTransitiveResolveCall( artifacts, originatingArtifact, resolver )
-    {
-        ArtifactFilter filter = null;
-        for ( Object arg : thisJoinPoint.getArgs() )
-        {
-            if ( arg instanceof ArtifactFilter )
-            {
-                filter = (ArtifactFilter) arg;
-                break;
-            }
-        }
-
-        String key = createCacheKey( originatingArtifact, artifacts, null, filter );
-        resolver.logger.debug( "Checking artifact resolution cache for: " + key );
-
-        ArtifactResolutionResult cached = resolver.cachedResolutionResults.get( key );
-        if ( cached != null )
-        {
-            resolver.logger.debug( "Using cached copy of: " + key );
-            return cached;
-        }
-
-        cached = proceed( artifacts, originatingArtifact, resolver );
-
-        resolver.logger.debug( "Caching: " + key );
-        resolver.cachedResolutionResults.put( key, cached );
-
-        return cached;
-    }
-
-    private pointcut resolveCallWithRequest( ArtifactResolutionRequest request, DefaultArtifactResolver
resolver ):
-        execution( ArtifactResolutionResult DefaultArtifactResolver+.resolve( ArtifactResolutionRequest
) )
-        && args( request )
-        && this( resolver );
-
-    @SuppressWarnings("unchecked")
-    ArtifactResolutionResult around( ArtifactResolutionRequest request, DefaultArtifactResolver
resolver ):
-        resolveCallWithRequest( request, resolver )
-    {
-        String key = createCacheKey( request.getArtifact(), request.getArtifactDependencies(),
-                                     request.getConflictResolvers(), request.getFilter()
);
-
-        resolver.logger.debug( "Checking artifact resolution cache for: " + key );
-
-        ArtifactResolutionResult cached = resolver.cachedResolutionResults.get( key );
-        if ( cached != null )
-        {
-            resolver.logger.debug( "Using cached copy of: " + key );
-            return cached;
-        }
-
-        cached = proceed( request, resolver );
-
-        resolver.logger.debug( "Caching: " + key );
-        resolver.cachedResolutionResults.put( key, cached );
-
-        return cached;
-    }
-
-    private void copyFromCached( Artifact artifact, Artifact cached )
-    {
-        artifact.setFile( cached.getFile() );
-        artifact.setResolved( cached.isResolved() );
-        artifact.setRepository( cached.getRepository() );
-        artifact.setDownloadUrl( cached.getDownloadUrl() );
-        artifact.setVersion( cached.getVersion() );
-
-        artifact.setAvailableVersions( cached.getAvailableVersions() );
-        artifact.setBaseVersion( cached.getBaseVersion() );
-        artifact.setDependencyTrail( cached.getDependencyTrail() );
-    }
-
-    private String createCacheKey( Artifact originatingArtifact, Set<Artifact> artifacts,
List<ConflictResolver> conflictResolvers, ArtifactFilter filter )
-    {
-        // NOTE: artifact sets in different orders can produce different results in transitive
resolution.
-        // Therefore, DO NOT sort this alphabetically first...preserve the set ordering,
if there is any.
-        // String[] ids = new String[artifacts.size()];
-        // int i=0;
-        // for ( Artifact artifact : artifacts )
-        // {
-        //     ids[i] = artifact.getId();
-        //     i++;
-        // }
-        //
-        // Arrays.sort( ids );
-
-        // TODO: Review. This will be ugly, and may not be great on the memory, but it should
work for now.
-        StringBuilder sb = new StringBuilder();
-
-        if ( originatingArtifact != null )
-        {
-            sb.append( originatingArtifact.getId() );
-            sb.append( ':' );
-        }
-
-        for ( Artifact artifact : artifacts )
-        {
-            sb.append( artifact.getId() );
-            sb.append( ':' );
-        }
-
-        if ( conflictResolvers != null )
-        {
-            for ( ConflictResolver conflictResolver : conflictResolvers )
-            {
-                sb.append( conflictResolver.hashCode() );
-                sb.append( ':' );
-            }
-        }
-
-        if ( filter != null )
-        {
-            sb.append( filter.hashCode() );
-            sb.append( ':' );
-        }
-
-        sb.setLength( sb.length() - 1 );
-
-        return sb.toString();
-    }
+//    declare parents: DefaultArtifactResolver implements Contextualizable;
+//
+//    private Map<String, Artifact> DefaultArtifactResolver.cachedSingleResolutions
=
+//        new HashMap<String, Artifact>();
+//
+//    private Map<String, ArtifactResolutionResult> DefaultArtifactResolver.cachedResolutionResults
=
+//        new HashMap<String, ArtifactResolutionResult>();
+//
+//    private PlexusContainer DefaultArtifactResolver.container;
+//    private Logger DefaultArtifactResolver.logger;
+//
+//    // NOTE: We implement advice on this method rather than setting the container instance
+//    // directly, so we can still recover the container even if the resolver implementation
+//    // happens to override the method.
+//    public void DefaultArtifactResolver.contextualize( Context context ) throws ContextException
+//    {
+//        if ( container == null )
+//        {
+//            container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
+//            logger = container.getLoggerManager().getLoggerForComponent( ArtifactResolver.ROLE
);
+//
+//            logger.debug( "DefaultArtifactResolver caching aspect captured PlexusContainer
instance." );
+//        }
+//    }
+//
+//    private pointcut deprecatedSingleResolveCall( Artifact artifact, DefaultArtifactResolver
resolver ):
+//        execution( void DefaultArtifactResolver+.resolve( Artifact, .. ) )
+//        && args( artifact, .. )
+//        && this( resolver );
+//
+//    void around( Artifact artifact, DefaultArtifactResolver resolver )
+//        throws ArtifactResolutionException, ArtifactNotFoundException:
+//        deprecatedSingleResolveCall( artifact, resolver )
+//    {
+//        System.out.println( "Cache check for: " + artifact + " using resolver: " + resolver
+ " (has logger? " + ( resolver != null && resolver.logger != null ) + ")" );
+//
+//        String key = createCacheKey( null, (Set<Artifact>) Collections.singleton(
artifact ), null, null );
+//        resolver.logger.debug( "Checking artifact resolution cache for: " + key );
+//
+//        Artifact cached = resolver.cachedSingleResolutions.get( key );
+//        if ( cached != null )
+//        {
+//            resolver.logger.debug( "Using cached copy of: " + key );
+//            copyFromCached( artifact, cached );
+//
+//            return;
+//        }
+//
+//        proceed( artifact, resolver );
+//
+//        resolver.logger.debug( "Caching: " + key );
+//        resolver.cachedSingleResolutions.put( key, artifact );
+//    }
+//
+//    private pointcut deprecatedTransitiveResolveCall( Set artifacts, Artifact originatingArtifact,
DefaultArtifactResolver resolver ):
+//        execution( ArtifactResolutionResult DefaultArtifactResolver+.resolveTransitively(
Set, Artifact, .. ) )
+//        && args( artifacts, originatingArtifact, .. )
+//        && this( resolver );
+//
+//    @SuppressWarnings("unchecked")
+//    ArtifactResolutionResult around( Set artifacts, Artifact originatingArtifact, DefaultArtifactResolver
resolver )
+//        throws ArtifactResolutionException, ArtifactNotFoundException:
+//        deprecatedTransitiveResolveCall( artifacts, originatingArtifact, resolver )
+//    {
+//        ArtifactFilter filter = null;
+//        for ( Object arg : thisJoinPoint.getArgs() )
+//        {
+//            if ( arg instanceof ArtifactFilter )
+//            {
+//                filter = (ArtifactFilter) arg;
+//                break;
+//            }
+//        }
+//
+//        String key = createCacheKey( originatingArtifact, artifacts, null, filter );
+//        resolver.logger.debug( "Checking artifact resolution cache for: " + key );
+//
+//        ArtifactResolutionResult cached = resolver.cachedResolutionResults.get( key );
+//        if ( cached != null )
+//        {
+//            resolver.logger.debug( "Using cached copy of: " + key );
+//            return cached;
+//        }
+//
+//        cached = proceed( artifacts, originatingArtifact, resolver );
+//
+//        resolver.logger.debug( "Caching: " + key );
+//        resolver.cachedResolutionResults.put( key, cached );
+//
+//        return cached;
+//    }
+//
+//    private pointcut resolveCallWithRequest( ArtifactResolutionRequest request, DefaultArtifactResolver
resolver ):
+//        execution( ArtifactResolutionResult DefaultArtifactResolver+.resolve( ArtifactResolutionRequest
) )
+//        && args( request )
+//        && this( resolver );
+//
+//    @SuppressWarnings("unchecked")
+//    ArtifactResolutionResult around( ArtifactResolutionRequest request, DefaultArtifactResolver
resolver ):
+//        resolveCallWithRequest( request, resolver )
+//    {
+//        String key = createCacheKey( request.getArtifact(), request.getArtifactDependencies(),
+//                                     request.getConflictResolvers(), request.getFilter()
);
+//
+//        resolver.logger.debug( "Checking artifact resolution cache for: " + key );
+//
+//        ArtifactResolutionResult cached = resolver.cachedResolutionResults.get( key );
+//        if ( cached != null )
+//        {
+//            resolver.logger.debug( "Using cached copy of: " + key );
+//            return cached;
+//        }
+//
+//        cached = proceed( request, resolver );
+//
+//        resolver.logger.debug( "Caching: " + key );
+//        resolver.cachedResolutionResults.put( key, cached );
+//
+//        return cached;
+//    }
+//
+//    private void copyFromCached( Artifact artifact, Artifact cached )
+//    {
+//        artifact.setFile( cached.getFile() );
+//        artifact.setResolved( cached.isResolved() );
+//        artifact.setRepository( cached.getRepository() );
+//        artifact.setDownloadUrl( cached.getDownloadUrl() );
+//        artifact.setVersion( cached.getVersion() );
+//
+//        artifact.setAvailableVersions( cached.getAvailableVersions() );
+//        artifact.setBaseVersion( cached.getBaseVersion() );
+//        artifact.setDependencyTrail( cached.getDependencyTrail() );
+//    }
+//
+//    private String createCacheKey( Artifact originatingArtifact, Set<Artifact> artifacts,
List<ConflictResolver> conflictResolvers, ArtifactFilter filter )
+//    {
+//        // NOTE: artifact sets in different orders can produce different results in transitive
resolution.
+//        // Therefore, DO NOT sort this alphabetically first...preserve the set ordering,
if there is any.
+//        // String[] ids = new String[artifacts.size()];
+//        // int i=0;
+//        // for ( Artifact artifact : artifacts )
+//        // {
+//        //     ids[i] = artifact.getId();
+//        //     i++;
+//        // }
+//        //
+//        // Arrays.sort( ids );
+//
+//        // TODO: Review. This will be ugly, and may not be great on the memory, but it
should work for now.
+//        StringBuilder sb = new StringBuilder();
+//
+//        if ( originatingArtifact != null )
+//        {
+//            sb.append( originatingArtifact.getId() );
+//            sb.append( ':' );
+//        }
+//
+//        for ( Artifact artifact : artifacts )
+//        {
+//            sb.append( artifact.getId() );
+//            sb.append( ':' );
+//        }
+//
+//        if ( conflictResolvers != null )
+//        {
+//            for ( ConflictResolver conflictResolver : conflictResolvers )
+//            {
+//                sb.append( conflictResolver.hashCode() );
+//                sb.append( ':' );
+//            }
+//        }
+//
+//        if ( filter != null )
+//        {
+//            sb.append( filter.hashCode() );
+//            sb.append( ':' );
+//        }
+//
+//        sb.setLength( sb.length() - 1 );
+//
+//        return sb.toString();
+//    }
 
 }

Added: maven/artifact/trunk/src/main/aspect/org/apache/maven/artifact/aspect/ResolverDebugAspect.aj
URL: http://svn.apache.org/viewvc/maven/artifact/trunk/src/main/aspect/org/apache/maven/artifact/aspect/ResolverDebugAspect.aj?rev=601954&view=auto
==============================================================================
--- maven/artifact/trunk/src/main/aspect/org/apache/maven/artifact/aspect/ResolverDebugAspect.aj
(added)
+++ maven/artifact/trunk/src/main/aspect/org/apache/maven/artifact/aspect/ResolverDebugAspect.aj
Thu Dec  6 17:11:19 2007
@@ -0,0 +1,73 @@
+package org.apache.maven.artifact.aspect;
+
+import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
+
+import org.codehaus.plexus.logging.Logger;
+
+import org.apache.maven.artifact.metadata.ArtifactMetadata;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
+import org.apache.maven.artifact.repository.metadata.DefaultRepositoryMetadataManager;
+
+import java.io.File;
+import java.util.Date;
+
+public privileged aspect ResolverDebugAspect
+{
+
+    private pointcut resolveAlwaysCall( ArtifactMetadata metadata, ArtifactRepository repo,
File file ):
+        execution( void DefaultRepositoryMetadataManager.resolveAlways( ArtifactMetadata,
ArtifactRepository, File, .. ) )
+        && args( metadata, repo, file, .. );
+
+    void around( ArtifactMetadata metadata, ArtifactRepository repo, File file ):
+        resolveAlwaysCall( metadata, repo, file )
+    {
+        System.out.println( "Resolving repository metadata (" + metadata + ") for repository:
" + repo.getId() + ". Possible reasons:" );
+        System.out.println( "Last-Modified date: " + new Date( file.lastModified() ) + "
is beyond the updateInterval." );
+        System.out.println( "File: " + file.getAbsolutePath() + " exists? " + ( file.exists()
) );
+        System.out.println();
+
+        proceed( metadata, repo, file );
+
+        System.out.println( "After resolving to file:" + file.getAbsolutePath() + ":" );
+        System.out.println( "Last-Modified date: " + new Date( file.lastModified() ) );
+        System.out.println( "File exists? " + ( file.exists() ) );
+        System.out.println();
+    }
+
+    void around( String message, Logger logger ):
+        withincode( void DefaultRepositoryMetadataManager.resolveAlways( .. ) )
+        && call( void Logger.debug( String ) )
+        && args( message )
+        && target( logger )
+    {
+        logger.info( message );
+    }
+
+    void around( String message, Throwable e, Logger logger ):
+        withincode( void DefaultRepositoryMetadataManager.resolveAlways( .. ) )
+        && call( void Logger.debug( String, Throwable ) )
+        && args( message, e )
+        && target( logger )
+    {
+        logger.info( message, e );
+    }
+
+    private pointcut checkOutOfDateExecution( Date date, ArtifactRepositoryPolicy policy
):
+        execution( boolean ArtifactRepositoryPolicy.checkOutOfDate( Date ) )
+        && args( date )
+        && this( policy );
+
+    boolean around( Date date, ArtifactRepositoryPolicy policy ):
+        checkOutOfDateExecution( date, policy )
+    {
+        boolean result = proceed( date, policy );
+
+        if ( !ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER.equals( policy.getUpdatePolicy()
) )
+        {
+            System.out.println( "Is repository-update policy: \'" + policy.getUpdatePolicy()
+ "\' out of date for: " + date + "? " + result );
+        }
+
+        return result;
+    }
+}

Modified: maven/artifact/trunk/src/main/java/org/apache/maven/artifact/repository/ArtifactRepositoryPolicy.java
URL: http://svn.apache.org/viewvc/maven/artifact/trunk/src/main/java/org/apache/maven/artifact/repository/ArtifactRepositoryPolicy.java?rev=601954&r1=601953&r2=601954&view=diff
==============================================================================
--- maven/artifact/trunk/src/main/java/org/apache/maven/artifact/repository/ArtifactRepositoryPolicy.java
(original)
+++ maven/artifact/trunk/src/main/java/org/apache/maven/artifact/repository/ArtifactRepositoryPolicy.java
Thu Dec  6 17:11:19 2007
@@ -21,6 +21,7 @@
 
 import java.util.Calendar;
 import java.util.Date;
+import java.util.TimeZone;
 
 /**
  * Describes a set of policies for a repository to use under certain conditions.
@@ -115,11 +116,13 @@
         else if ( UPDATE_POLICY_DAILY.equals( updatePolicy ) )
         {
             // Get midnight boundary
-            Calendar cal = Calendar.getInstance();
+            Calendar cal = Calendar.getInstance( TimeZone.getTimeZone( "UTC" ) );
+
             cal.set( Calendar.HOUR_OF_DAY, 0 );
             cal.set( Calendar.MINUTE, 0 );
             cal.set( Calendar.SECOND, 0 );
             cal.set( Calendar.MILLISECOND, 0 );
+
             if ( cal.getTime().after( lastModified ) )
             {
                 checkForUpdates = true;

Modified: maven/artifact/trunk/src/main/java/org/apache/maven/artifact/repository/metadata/DefaultRepositoryMetadataManager.java
URL: http://svn.apache.org/viewvc/maven/artifact/trunk/src/main/java/org/apache/maven/artifact/repository/metadata/DefaultRepositoryMetadataManager.java?rev=601954&r1=601953&r2=601954&view=diff
==============================================================================
--- maven/artifact/trunk/src/main/java/org/apache/maven/artifact/repository/metadata/DefaultRepositoryMetadataManager.java
(original)
+++ maven/artifact/trunk/src/main/java/org/apache/maven/artifact/repository/metadata/DefaultRepositoryMetadataManager.java
Thu Dec  6 17:11:19 2007
@@ -24,15 +24,18 @@
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
 import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
+import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Writer;
 import org.apache.maven.wagon.ResourceDoesNotExistException;
 import org.apache.maven.wagon.TransferFailedException;
 import org.codehaus.plexus.logging.AbstractLogEnabled;
+import org.codehaus.plexus.logging.Logger;
 import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.ReaderFactory;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
 import java.io.File;
 import java.io.FileNotFoundException;
+import java.io.FileWriter;
 import java.io.IOException;
 import java.io.Reader;
 import java.util.Date;
@@ -52,11 +55,23 @@
     /** @plexus.requirement */
     private WagonManager wagonManager;
 
+    protected DefaultRepositoryMetadataManager( WagonManager wagonManager, Logger logger
)
+    {
+        this.wagonManager = wagonManager;
+        enableLogging( logger );
+    }
+
+    public DefaultRepositoryMetadataManager()
+    {
+    }
+
     public void resolve( RepositoryMetadata metadata,
                          List remoteRepositories,
                          ArtifactRepository localRepository )
         throws RepositoryMetadataResolutionException
     {
+//        MetadataTouchfile touchfile = new MetadataTouchfile( metadata, localRepository
);
+
         for ( Iterator i = remoteRepositories.iterator(); i.hasNext(); )
         {
             ArtifactRepository repository = (ArtifactRepository) i.next();
@@ -77,6 +92,11 @@
                 File file = new File( localRepository.getBasedir(),
                     localRepository.pathOfLocalRepositoryMetadata( metadata, repository )
);
 
+//                Date lastMod = touchfile.getLastModified( repository.getId(), getLogger()
);
+
+//                boolean checkForUpdates =
+//                    ( lastMod == null ) || policy.checkOutOfDate( lastMod ) || !file.exists();
+
                 boolean checkForUpdates =
                     policy.checkOutOfDate( new Date( file.lastModified() ) ) || !file.exists();
 
@@ -93,6 +113,10 @@
                         // TODO: [jc; 08-Nov-2005] revisit this for 2.1
                         // suppressing logging to avoid logging this error twice.
                     }
+//                    finally
+//                    {
+//                        touchfile.touch( repository.getId(), getLogger() );
+//                    }
                 }
 
                 // TODO: should this be inside the above check?
@@ -184,7 +208,7 @@
                 }
                 else
                 {
-                    if ( m.getVersioning() != null && m.getVersioning().getSnapshot()
!= null &&
+                    if ( ( m.getVersioning() != null ) && ( m.getVersioning().getSnapshot()
!= null ) &&
                         m.getVersioning().getSnapshot().isLocalCopy() )
                     {
                         m.getVersioning().getSnapshot().setLocalCopy( false );
@@ -213,7 +237,7 @@
         {
             Metadata metadata = readMetadata( metadataFile );
 
-            if ( repoMetadata.isSnapshot() && previousMetadata != null )
+            if ( repoMetadata.isSnapshot() && ( previousMetadata != null ) )
             {
                 previousMetadata.put( remoteRepository, metadata );
             }
@@ -340,10 +364,7 @@
             getLogger().debug( metadata + " could not be found on repository: " + repository.getId()
);
 
             // delete the local copy so the old details aren't used.
-            if ( file.exists() )
-            {
-                file.delete();
-            }
+            createMetadataStub( metadata, file );
         }
         catch ( TransferFailedException e )
         {
@@ -354,6 +375,36 @@
             repository.setBlacklisted( allowBlacklisting );
 
             throw e;
+        }
+    }
+
+    private void createMetadataStub( ArtifactMetadata metadata, File file )
+    {
+        Metadata md = new Metadata();
+
+        md.setArtifactId( metadata.getArtifactId() );
+        md.setGroupId( metadata.getGroupId() );
+        md.setVersion( metadata.getBaseVersion() );
+
+        Versioning versioning = new Versioning();
+        versioning.updateTimestamp();
+
+        md.setVersioning( versioning );
+
+        FileWriter writer = null;
+        try
+        {
+            file.getParentFile().mkdirs();
+            writer = new FileWriter( file );
+            new MetadataXpp3Writer().write( writer, md );
+        }
+        catch ( IOException e )
+        {
+            getLogger().debug( "Failed to write stub metadata to: " + file, e );
+        }
+        finally
+        {
+            IOUtil.close( writer );
         }
     }
 

Added: maven/artifact/trunk/src/test/java/org/apache/maven/artifact/repository/metadata/DefaultRepositoryMetadataManagerTest.java
URL: http://svn.apache.org/viewvc/maven/artifact/trunk/src/test/java/org/apache/maven/artifact/repository/metadata/DefaultRepositoryMetadataManagerTest.java?rev=601954&view=auto
==============================================================================
--- maven/artifact/trunk/src/test/java/org/apache/maven/artifact/repository/metadata/DefaultRepositoryMetadataManagerTest.java
(added)
+++ maven/artifact/trunk/src/test/java/org/apache/maven/artifact/repository/metadata/DefaultRepositoryMetadataManagerTest.java
Thu Dec  6 17:11:19 2007
@@ -0,0 +1,181 @@
+package org.apache.maven.artifact.repository.metadata;
+
+import org.apache.maven.artifact.manager.WagonManager;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
+import org.apache.maven.artifact.testutils.MockManager;
+import org.apache.maven.artifact.testutils.TestFileManager;
+import org.apache.maven.wagon.ResourceDoesNotExistException;
+import org.apache.maven.wagon.TransferFailedException;
+import org.codehaus.plexus.logging.Logger;
+import org.codehaus.plexus.logging.console.ConsoleLogger;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+import org.easymock.MockControl;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.TimeZone;
+
+import junit.framework.TestCase;
+
+public class DefaultRepositoryMetadataManagerTest
+    extends TestCase
+{
+
+    private MockManager mockManager = new MockManager();
+
+    private TestFileManager testFileManager = new TestFileManager(
+                                                                   "DefaultRepositoryMetadataManager.test.",
+                                                                   "" );
+
+    private MockControl wagonManagerCtl;
+
+    private WagonManager wagonManager;
+
+    @Override
+    public void setUp()
+        throws Exception
+    {
+        super.setUp();
+
+        wagonManagerCtl = MockControl.createControl( WagonManager.class );
+        mockManager.add( wagonManagerCtl );
+
+        wagonManager = (WagonManager) wagonManagerCtl.getMock();
+    }
+
+    @Override
+    public void tearDown()
+        throws Exception
+    {
+        testFileManager.cleanUp();
+
+        super.tearDown();
+    }
+
+    public void testResolveAlways_StubMetadataOnResourceNotFoundException()
+        throws RepositoryMetadataResolutionException, IOException, XmlPullParserException,
+        ParseException, InterruptedException
+    {
+        Date start = new Date();
+
+        // helps the lastUpdate interval be significantly different.
+        Thread.sleep( 1000 );
+
+        MockControl localRepoCtl = MockControl.createControl( ArtifactRepository.class );
+
+        mockManager.add( localRepoCtl );
+
+        ArtifactRepository localRepo = (ArtifactRepository) localRepoCtl.getMock();
+
+        File dir = testFileManager.createTempDir();
+        String path = "path/to/metadata.xml";
+
+        localRepo.getBasedir();
+        localRepoCtl.setReturnValue( dir.getAbsolutePath(), MockControl.ZERO_OR_MORE );
+
+        localRepo.pathOfLocalRepositoryMetadata( null, null );
+        localRepoCtl.setMatcher( MockControl.ALWAYS_MATCHER );
+        localRepoCtl.setReturnValue( path, MockControl.ZERO_OR_MORE );
+
+        localRepo.getId();
+        localRepoCtl.setReturnValue( "local", MockControl.ZERO_OR_MORE );
+
+        wagonManager.isOnline();
+        wagonManagerCtl.setReturnValue( true, MockControl.ZERO_OR_MORE );
+
+        try
+        {
+            wagonManager.getArtifactMetadata( null, null, null, null );
+            wagonManagerCtl.setMatcher( MockControl.ALWAYS_MATCHER );
+            wagonManagerCtl.setThrowable( new ResourceDoesNotExistException( "Test error"
) );
+        }
+        catch ( TransferFailedException e )
+        {
+            fail( "Should not happen during mock setup." );
+        }
+        catch ( ResourceDoesNotExistException e )
+        {
+            fail( "Should not happen during mock setup." );
+        }
+
+        MockControl metadataCtl = MockControl.createControl( RepositoryMetadata.class );
+        mockManager.add( metadataCtl );
+
+        RepositoryMetadata metadata = (RepositoryMetadata) metadataCtl.getMock();
+
+        String groupId = "group";
+        String artifactId = "artifact";
+        String baseVersion = "1-SNAPSHOT";
+
+        metadata.getGroupId();
+        metadataCtl.setReturnValue( groupId, MockControl.ZERO_OR_MORE );
+
+        metadata.getArtifactId();
+        metadataCtl.setReturnValue( artifactId, MockControl.ZERO_OR_MORE );
+
+        metadata.getBaseVersion();
+        metadataCtl.setReturnValue( baseVersion, MockControl.ZERO_OR_MORE );
+
+        metadata.setMetadata( null );
+        metadataCtl.setMatcher( MockControl.ALWAYS_MATCHER );
+        metadataCtl.setVoidCallable( 1 );
+
+        mockManager.replayAll();
+
+        Logger logger = new ConsoleLogger( Logger.LEVEL_DEBUG, "test" );
+
+        new DefaultRepositoryMetadataManager( wagonManager, logger ).resolveAlways( metadata,
+                                                                            localRepo,
+                                                                            localRepo );
+
+        // helps the lastUpdate interval be significantly different.
+        Thread.sleep( 1000 );
+
+        Date end = new Date();
+
+        FileReader reader = null;
+        try
+        {
+            reader = new FileReader( new File( dir, path ) );
+
+            Metadata md = new MetadataXpp3Reader().read( reader );
+            Versioning versioning = md.getVersioning();
+            assertNotNull( versioning );
+            assertTrue( ( versioning.getVersions() == null ) || versioning.getVersions().isEmpty()
);
+            assertNull( versioning.getSnapshot() );
+            assertNull( versioning.getLatest() );
+            assertNull( versioning.getRelease() );
+
+            String lastUpdate = versioning.getLastUpdated();
+            assertNotNull( lastUpdate );
+
+            TimeZone timezone = TimeZone.getTimeZone( "UTC" );
+            SimpleDateFormat fmt = new SimpleDateFormat( "yyyyMMddHHmmss" );
+            fmt.setTimeZone( timezone );
+
+            Date lastUpd = fmt.parse( lastUpdate );
+
+            SimpleDateFormat debugFmt = new SimpleDateFormat( "HH:mm:ss.SSS" );
+
+            System.out.println( "Start time of test: " + debugFmt.format( start ) );
+            System.out.println( "last update is set to: " + debugFmt.format( lastUpd ) );
+            System.out.println( "End time of test: " + debugFmt.format( end ) );
+
+            assertFalse( lastUpd.before( start ) );
+            assertFalse( lastUpd.after( end ) );
+        }
+        finally
+        {
+            IOUtil.close( reader );
+        }
+
+        mockManager.verifyAll();
+    }
+
+}

Propchange: maven/artifact/trunk/src/test/java/org/apache/maven/artifact/repository/metadata/DefaultRepositoryMetadataManagerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/artifact/trunk/src/test/java/org/apache/maven/artifact/repository/metadata/DefaultRepositoryMetadataManagerTest.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: maven/artifact/trunk/src/test/java/org/apache/maven/artifact/transform/TransformationManagerTest.java
URL: http://svn.apache.org/viewvc/maven/artifact/trunk/src/test/java/org/apache/maven/artifact/transform/TransformationManagerTest.java?rev=601954&r1=601953&r2=601954&view=diff
==============================================================================
--- maven/artifact/trunk/src/test/java/org/apache/maven/artifact/transform/TransformationManagerTest.java
(original)
+++ maven/artifact/trunk/src/test/java/org/apache/maven/artifact/transform/TransformationManagerTest.java
Thu Dec  6 17:11:19 2007
@@ -2,7 +2,6 @@
 
 import org.codehaus.plexus.PlexusTestCase;
 
-import java.util.ArrayList;
 import java.util.List;
 
 /** @author Jason van Zyl */
@@ -24,4 +23,5 @@
 
         assertTrue( "We expected the snapshot transformation and got " + tms.get(2), tms.get(2)
instanceof SnapshotTransformation );
     }
+
 }



Mime
View raw message