You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@archiva.apache.org by Brett Porter <br...@apache.org> on 2007/10/12 06:03:40 UTC

Re: svn commit: r583862 - /maven/archiva/trunk/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java

Is there a test that reproduces this problem? JIRA issue?

On 11/10/2007, at 6:05 PM, joakime@apache.org wrote:

> Author: joakime
> Date: Thu Oct 11 09:05:24 2007
> New Revision: 583862
>
> URL: http://svn.apache.org/viewvc?rev=583862&view=rev
> Log:
> Correcting logic for determining if the local maven-metadata.xml  
> needs to be updated.
>
>
> Modified:
>     maven/archiva/trunk/archiva-base/archiva-proxy/src/main/java/ 
> org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java
>
> Modified: maven/archiva/trunk/archiva-base/archiva-proxy/src/main/ 
> java/org/apache/maven/archiva/proxy/ 
> DefaultRepositoryProxyConnectors.java
> URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/ 
> archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/ 
> DefaultRepositoryProxyConnectors.java? 
> rev=583862&r1=583861&r2=583862&view=diff
> ====================================================================== 
> ========
> --- maven/archiva/trunk/archiva-base/archiva-proxy/src/main/java/ 
> org/apache/maven/archiva/proxy/ 
> DefaultRepositoryProxyConnectors.java (original)
> +++ maven/archiva/trunk/archiva-base/archiva-proxy/src/main/java/ 
> org/apache/maven/archiva/proxy/ 
> DefaultRepositoryProxyConnectors.java Thu Oct 11 09:05:24 2007
> @@ -170,7 +170,8 @@
>          File localFile = toLocalFile( repository, metadata );
>
>          Properties requestProperties = new Properties();
> -        boolean hasFetched = false;
> +        boolean metadataNeedsUpdating = false;
> +        long originalTimestamp = getLastModified( localFile );
>
>          List<ProxyConnector> connectors = getProxyConnectors 
> ( repository );
>          for ( ProxyConnector connector : connectors )
> @@ -179,17 +180,21 @@
>              String targetPath = metadataTools.toPath( metadata );
>
>              File localRepoFile = toLocalRepoFile( repository,  
> targetRepository, targetPath );
> -            File downloadedFile = transferFile( connector,  
> targetRepository, targetPath, localRepoFile,
> -                                                requestProperties );
> +            long originalMetadataTimestamp = getLastModified 
> ( localRepoFile );
> +            transferFile( connector, targetRepository, targetPath,  
> localRepoFile, requestProperties );
>
> -            if ( fileExists( downloadedFile ) )
> +            if ( hasBeenUpdated( localRepoFile,  
> originalMetadataTimestamp ) )
>              {
> -                getLogger().debug( "Successfully transfered: " +  
> downloadedFile.getAbsolutePath() );
> -                hasFetched = true;
> +                metadataNeedsUpdating = true;
>              }
>          }
>
> -        if ( hasFetched || fileExists( localFile ) )
> +        if ( hasBeenUpdated( localFile, originalTimestamp ) )
> +        {
> +            metadataNeedsUpdating = true;
> +        }
> +
> +        if ( metadataNeedsUpdating )
>          {
>              try
>              {
> @@ -228,6 +233,27 @@
>          return null;
>      }
>
> +    private long getLastModified( File file )
> +    {
> +        if ( !file.exists() || !file.isFile() )
> +        {
> +            return 0;
> +        }
> +
> +        return file.lastModified();
> +    }
> +
> +    private boolean hasBeenUpdated( File file, long  
> originalLastModified )
> +    {
> +        if ( !file.exists() || !file.isFile() )
> +        {
> +            return false;
> +        }
> +
> +        long currentLastModified = getLastModified( file );
> +        return ( currentLastModified > originalLastModified );
> +    }
> +
>      /**
>       * Fetch from the proxies a metadata.xml file for the  
> groupId:artifactId metadata contents.
>       *
> @@ -239,7 +265,8 @@
>          File localFile = toLocalFile( repository, metadata );
>
>          Properties requestProperties = new Properties();
> -        boolean hasFetched = false;
> +        boolean metadataNeedsUpdating = false;
> +        long originalTimestamp = getLastModified( localFile );
>
>          List<ProxyConnector> connectors = getProxyConnectors 
> ( repository );
>          for ( ProxyConnector connector : connectors )
> @@ -248,17 +275,21 @@
>              String targetPath = metadataTools.toPath( metadata );
>
>              File localRepoFile = toLocalRepoFile( repository,  
> targetRepository, targetPath );
> -            File downloadedFile = transferFile( connector,  
> targetRepository, targetPath, localRepoFile,
> -                                                requestProperties );
> +            long originalMetadataTimestamp = getLastModified 
> ( localRepoFile );
> +            transferFile( connector, targetRepository, targetPath,  
> localRepoFile, requestProperties );
>
> -            if ( fileExists( downloadedFile ) )
> +            if ( hasBeenUpdated( localRepoFile,  
> originalMetadataTimestamp ) )
>              {
> -                getLogger().debug( "Successfully transfered: " +  
> downloadedFile.getAbsolutePath() );
> -                hasFetched = true;
> +                metadataNeedsUpdating = true;
>              }
>          }
>
> -        if ( hasFetched || fileExists( localFile ) )
> +        if ( hasBeenUpdated( localFile, originalTimestamp ) )
> +        {
> +            metadataNeedsUpdating = true;
> +        }
> +
> +        if ( metadataNeedsUpdating )
>          {
>              try
>              {
> @@ -428,7 +459,6 @@
>
>                  transferChecksum( wagon, remoteRepository,  
> remotePath, localFile, ".sha1" );
>                  transferChecksum( wagon, remoteRepository,  
> remotePath, localFile, ".md5" );
> -
>              }
>          }
>          catch ( ResourceDoesNotExistException e )
>

--
Brett Porter - brett@apache.org
Blog: http://www.devzuz.org/blogs/bporter/

Re: svn commit: r583862 - /maven/archiva/trunk/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java

Posted by Brett Porter <br...@apache.org>.
On 19/10/2007, at 4:24 AM, Joakim Erdfelt wrote:

> No jira.

ok... as you can see I'm trying to get in the habit of creating them  
even for simple things to make sure we keep track...

> This is only a squelching of an overactive process to be more sane.
> It falls into the performance detrimental bucket.
> As for unit tests, there are 2 that I'm aware of that test for this  
> situation already.

Sorry, I'm a bit confused - your commit log said "correcting logic" -  
in which case the tests for that situation should have been failing  
before the logic change fixed the problem.

Or is it just that the logic change was to write the metadata changes  
less often but with the same information, hence the performance  
detrimental aspect?

- Brett

--
Brett Porter - brett@apache.org
Blog: http://www.devzuz.org/blogs/bporter/

Re: svn commit: r583862 - /maven/archiva/trunk/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java

Posted by Joakim Erdfelt <jo...@erdfelt.com>.
No jira.
This is only a squelching of an overactive process to be more sane.
It falls into the performance detrimental bucket.
As for unit tests, there are 2 that I'm aware of that test for this 
situation already.

Brett Porter wrote:
> Is there a test that reproduces this problem? JIRA issue?
>
> On 11/10/2007, at 6:05 PM, joakime@apache.org wrote:
>
>> Author: joakime
>> Date: Thu Oct 11 09:05:24 2007
>> New Revision: 583862
>>
>> URL: http://svn.apache.org/viewvc?rev=583862&view=rev
>> Log:
>> Correcting logic for determining if the local maven-metadata.xml 
>> needs to be updated.
>>
>>
>> Modified:
>>     
>> maven/archiva/trunk/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java 
>>
>>
>> Modified: 
>> maven/archiva/trunk/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java 
>>
>> URL: 
>> http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java?rev=583862&r1=583861&r2=583862&view=diff 
>>
>> ============================================================================== 
>>
>> --- 
>> maven/archiva/trunk/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java 
>> (original)
>> +++ 
>> maven/archiva/trunk/archiva-base/archiva-proxy/src/main/java/org/apache/maven/archiva/proxy/DefaultRepositoryProxyConnectors.java 
>> Thu Oct 11 09:05:24 2007
>> @@ -170,7 +170,8 @@
>>          File localFile = toLocalFile( repository, metadata );
>>
>>          Properties requestProperties = new Properties();
>> -        boolean hasFetched = false;
>> +        boolean metadataNeedsUpdating = false;
>> +        long originalTimestamp = getLastModified( localFile );
>>
>>          List<ProxyConnector> connectors = getProxyConnectors( 
>> repository );
>>          for ( ProxyConnector connector : connectors )
>> @@ -179,17 +180,21 @@
>>              String targetPath = metadataTools.toPath( metadata );
>>
>>              File localRepoFile = toLocalRepoFile( repository, 
>> targetRepository, targetPath );
>> -            File downloadedFile = transferFile( connector, 
>> targetRepository, targetPath, localRepoFile,
>> -                                                requestProperties );
>> +            long originalMetadataTimestamp = getLastModified( 
>> localRepoFile );
>> +            transferFile( connector, targetRepository, targetPath, 
>> localRepoFile, requestProperties );
>>
>> -            if ( fileExists( downloadedFile ) )
>> +            if ( hasBeenUpdated( localRepoFile, 
>> originalMetadataTimestamp ) )
>>              {
>> -                getLogger().debug( "Successfully transfered: " + 
>> downloadedFile.getAbsolutePath() );
>> -                hasFetched = true;
>> +                metadataNeedsUpdating = true;
>>              }
>>          }
>>
>> -        if ( hasFetched || fileExists( localFile ) )
>> +        if ( hasBeenUpdated( localFile, originalTimestamp ) )
>> +        {
>> +            metadataNeedsUpdating = true;
>> +        }
>> +
>> +        if ( metadataNeedsUpdating )
>>          {
>>              try
>>              {
>> @@ -228,6 +233,27 @@
>>          return null;
>>      }
>>
>> +    private long getLastModified( File file )
>> +    {
>> +        if ( !file.exists() || !file.isFile() )
>> +        {
>> +            return 0;
>> +        }
>> +
>> +        return file.lastModified();
>> +    }
>> +
>> +    private boolean hasBeenUpdated( File file, long 
>> originalLastModified )
>> +    {
>> +        if ( !file.exists() || !file.isFile() )
>> +        {
>> +            return false;
>> +        }
>> +
>> +        long currentLastModified = getLastModified( file );
>> +        return ( currentLastModified > originalLastModified );
>> +    }
>> +
>>      /**
>>       * Fetch from the proxies a metadata.xml file for the 
>> groupId:artifactId metadata contents.
>>       *
>> @@ -239,7 +265,8 @@
>>          File localFile = toLocalFile( repository, metadata );
>>
>>          Properties requestProperties = new Properties();
>> -        boolean hasFetched = false;
>> +        boolean metadataNeedsUpdating = false;
>> +        long originalTimestamp = getLastModified( localFile );
>>
>>          List<ProxyConnector> connectors = getProxyConnectors( 
>> repository );
>>          for ( ProxyConnector connector : connectors )
>> @@ -248,17 +275,21 @@
>>              String targetPath = metadataTools.toPath( metadata );
>>
>>              File localRepoFile = toLocalRepoFile( repository, 
>> targetRepository, targetPath );
>> -            File downloadedFile = transferFile( connector, 
>> targetRepository, targetPath, localRepoFile,
>> -                                                requestProperties );
>> +            long originalMetadataTimestamp = getLastModified( 
>> localRepoFile );
>> +            transferFile( connector, targetRepository, targetPath, 
>> localRepoFile, requestProperties );
>>
>> -            if ( fileExists( downloadedFile ) )
>> +            if ( hasBeenUpdated( localRepoFile, 
>> originalMetadataTimestamp ) )
>>              {
>> -                getLogger().debug( "Successfully transfered: " + 
>> downloadedFile.getAbsolutePath() );
>> -                hasFetched = true;
>> +                metadataNeedsUpdating = true;
>>              }
>>          }
>>
>> -        if ( hasFetched || fileExists( localFile ) )
>> +        if ( hasBeenUpdated( localFile, originalTimestamp ) )
>> +        {
>> +            metadataNeedsUpdating = true;
>> +        }
>> +
>> +        if ( metadataNeedsUpdating )
>>          {
>>              try
>>              {
>> @@ -428,7 +459,6 @@
>>
>>                  transferChecksum( wagon, remoteRepository, 
>> remotePath, localFile, ".sha1" );
>>                  transferChecksum( wagon, remoteRepository, 
>> remotePath, localFile, ".md5" );
>> -
>>              }
>>          }
>>          catch ( ResourceDoesNotExistException e )
>>
>
> -- 
> Brett Porter - brett@apache.org
> Blog: http://www.devzuz.org/blogs/bporter/
>

-- 
- Joakim Erdfelt
  joakim@erdfelt.com
  Open Source Software (OSS) Developer