Merge branch 'MRM-813'

This commit is contained in:
Olivier Lamy 2014-10-20 17:08:22 +11:00
commit 5b59e0b108
9 changed files with 82 additions and 26 deletions

View File

@ -0,0 +1,53 @@
package org.apache.archiva.proxy.model;
/*
* 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;
/**
* A result from a proxy fetch operation.
*
* @since 2.1.2
*/
public class ProxyFetchResult
{
//The file returned
private File file;
//Was the local file modified by the fetch?
private boolean modified;
public ProxyFetchResult( File file, boolean modified )
{
this.file = file;
this.modified = modified;
}
public File getFile()
{
return file;
}
public boolean isModified()
{
return modified;
}
}

View File

@ -59,7 +59,7 @@ public interface RepositoryProxyConnectors
* @param logicalPath the metadata to fetch.
* @return the file that was obtained, or null if no content was obtained
*/
File fetchMetatadaFromProxies( ManagedRepositoryContent repository, String logicalPath );
ProxyFetchResult fetchMetadataFromProxies( ManagedRepositoryContent repository, String logicalPath );
/**
* Performs the fetch operation against the target repositories

View File

@ -48,6 +48,7 @@ import org.apache.archiva.policies.urlcache.UrlFailureCache;
import org.apache.archiva.proxy.common.WagonFactory;
import org.apache.archiva.proxy.common.WagonFactoryException;
import org.apache.archiva.proxy.common.WagonFactoryRequest;
import org.apache.archiva.proxy.model.ProxyFetchResult;
import org.apache.archiva.proxy.model.ProxyConnector;
import org.apache.archiva.proxy.model.RepositoryProxyConnectors;
import org.apache.archiva.redback.components.registry.Registry;
@ -447,7 +448,7 @@ public class DefaultRepositoryProxyConnectors
}
@Override
public File fetchMetatadaFromProxies( ManagedRepositoryContent repository, String logicalPath )
public ProxyFetchResult fetchMetadataFromProxies( ManagedRepositoryContent repository, String logicalPath )
{
File localFile = new File( repository.getRepoRoot(), logicalPath );
@ -517,14 +518,15 @@ public class DefaultRepositoryProxyConnectors
{
log.warn( "Unable to update metadata {}:{}", localFile.getAbsolutePath(), e.getMessage(), e );
}
}
if ( fileExists( localFile ) )
{
return localFile;
return new ProxyFetchResult( localFile, metadataNeedsUpdating );
}
return null;
return new ProxyFetchResult( null, false );
}
/**

View File

@ -31,6 +31,7 @@ import org.apache.archiva.policies.CachedFailuresPolicy;
import org.apache.archiva.policies.ChecksumPolicy;
import org.apache.archiva.policies.ReleasesPolicy;
import org.apache.archiva.policies.SnapshotsPolicy;
import org.apache.archiva.proxy.model.ProxyFetchResult;
import org.apache.archiva.repository.metadata.MetadataTools;
import org.apache.archiva.repository.metadata.RepositoryMetadataException;
import org.apache.archiva.repository.metadata.RepositoryMetadataWriter;
@ -124,9 +125,9 @@ public class MetadataTransferTest
ProjectReference metadata = createProjectReference( requestedResource );
File downloadedFile = proxyHandler.fetchMetatadaFromProxies( managedDefaultRepository,
File downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository,
managedDefaultRepository.toMetadataPath(
metadata ) );
metadata ) ).getFile();
assertNull( "Should not have downloaded a file.", downloadedFile );
assertNoTempFiles( expectedFile );
@ -987,9 +988,9 @@ public class MetadataTransferTest
ProjectReference metadata = createProjectReference( requestedResource );
File downloadedFile = proxyHandler.fetchMetatadaFromProxies( managedDefaultRepository,
File downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository,
managedDefaultRepository.toMetadataPath(
metadata ) );
metadata ) ).getFile();
assertNotNull( "Should have downloaded a file.", downloadedFile );
assertNoTempFiles( expectedFile );
@ -1013,9 +1014,9 @@ public class MetadataTransferTest
File expectedFile = new File( managedDefaultDir, requestedResource );
ProjectReference metadata = createProjectReference( requestedResource );
File downloadedFile = proxyHandler.fetchMetatadaFromProxies( managedDefaultRepository,
File downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository,
managedDefaultRepository.toMetadataPath(
metadata ) );
metadata ) ).getFile();
assertNull( downloadedFile );
assertNoTempFiles( expectedFile );
@ -1034,9 +1035,9 @@ public class MetadataTransferTest
VersionedReference metadata = createVersionedReference( requestedResource );
File downloadedFile = proxyHandler.fetchMetatadaFromProxies( managedDefaultRepository,
File downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository,
managedDefaultRepository.toMetadataPath(
metadata ) );
metadata ) ).getFile();
assertNotNull( "Should have downloaded a file.", downloadedFile );
assertNoTempFiles( expectedFile );
@ -1060,9 +1061,9 @@ public class MetadataTransferTest
File expectedFile = new File( managedDefaultDir, requestedResource );
VersionedReference metadata = createVersionedReference( requestedResource );
File downloadedFile = proxyHandler.fetchMetatadaFromProxies( managedDefaultRepository,
File downloadedFile = proxyHandler.fetchMetadataFromProxies( managedDefaultRepository,
managedDefaultRepository.toMetadataPath(
metadata ) );
metadata ) ).getFile();
assertNull( downloadedFile );
assertNoTempFiles( expectedFile );

View File

@ -868,7 +868,7 @@ define("archiva.search",["jquery","jquery.ui","i18n","jquery.tmpl","select2","kn
}
this.gridMetatadasViewModel = new ko.simpleGrid.viewModel({
this.gridMetadataViewModel = new ko.simpleGrid.viewModel({
data: self.entries,
pageSize: 10
});

View File

@ -788,7 +788,7 @@
<div id="artifact-details-metadatas-content" class="tab-pane">
<table class="table table-striped table-bordered" id="artifact-details-metadatas-content-table"
data-bind="simpleGrid: gridMetatadasViewModel,simpleGridTemplate:'artifact_metadata_properties_tmpl',pageLinksId:'artifactMetadata_Pagination'">
data-bind="simpleGrid: gridMetadataViewModel,simpleGridTemplate:'artifact_metadata_properties_tmpl',pageLinksId:'artifactMetadata_Pagination'">
</table>
<div id="artifactMetadata_Pagination"></div>

View File

@ -442,13 +442,13 @@ public class ArchivaDavResource
}
}
private void triggerAuditEvent( DavResource member, String event )
private void triggerAuditEvent( DavResource member, String action )
throws DavException
{
String path = logicalResource + "/" + member.getDisplayName();
ArchivaDavResource resource = checkDavResourceIsArchivaDavResource( member );
AuditEvent auditEvent = new AuditEvent( locator.getRepositoryId(), resource.principal, path, event );
AuditEvent auditEvent = new AuditEvent( locator.getRepositoryId(), resource.principal, path, action );
auditEvent.setRemoteIP( resource.remoteAddr );
for ( AuditListener listener : auditListeners )

View File

@ -47,6 +47,7 @@ import org.apache.archiva.model.ArchivaRepositoryMetadata;
import org.apache.archiva.model.ArtifactReference;
import org.apache.archiva.policies.ProxyDownloadException;
import org.apache.archiva.proxy.model.RepositoryProxyConnectors;
import org.apache.archiva.proxy.model.ProxyFetchResult;
import org.apache.archiva.redback.authentication.AuthenticationException;
import org.apache.archiva.redback.authentication.AuthenticationResult;
import org.apache.archiva.redback.authorization.AuthorizationException;
@ -626,9 +627,7 @@ public class ArchivaDavResourceFactory
{
boolean previouslyExisted = resourceFile.exists();
// Attempt to fetch the resource from any defined proxy.
boolean fromProxy =
fetchContentFromProxies( managedRepositoryContent, request, logicalResource );
boolean fromProxy = fetchContentFromProxies( managedRepositoryContent, request, logicalResource );
// At this point the incoming request can either be in default or
// legacy layout format.
@ -656,14 +655,14 @@ public class ArchivaDavResourceFactory
if ( fromProxy )
{
String event = ( previouslyExisted ? AuditEvent.MODIFY_FILE : AuditEvent.CREATE_FILE )
String action = ( previouslyExisted ? AuditEvent.MODIFY_FILE : AuditEvent.CREATE_FILE )
+ PROXIED_SUFFIX;
log.debug( "Proxied artifact '{}' in repository '{}' (current user '{}')",
resourceFile.getName(), managedRepositoryContent.getId(), activePrincipal );
triggerAuditEvent( request.getRemoteAddr(), archivaLocator.getRepositoryId(),
logicalResource.getPath(), event, activePrincipal );
logicalResource.getPath(), action, activePrincipal );
}
if ( !resourceFile.exists() )
@ -793,7 +792,7 @@ public class ArchivaDavResourceFactory
// Is it a Metadata resource?
if ( repositoryRequest.isDefault( path ) && repositoryRequest.isMetadata( path ) )
{
return connectors.fetchMetatadaFromProxies( managedRepository, path ) != null;
return connectors.fetchMetadataFromProxies( managedRepository, path ).isModified();
}
// Is it an Archetype Catalog?

View File

@ -33,6 +33,7 @@ import org.apache.archiva.configuration.ArchivaConfiguration;
import org.apache.archiva.configuration.Configuration;
import org.apache.archiva.configuration.RepositoryGroupConfiguration;
import org.apache.archiva.proxy.DefaultRepositoryProxyConnectors;
import org.apache.archiva.proxy.model.ProxyFetchResult;
import org.apache.archiva.repository.ManagedRepositoryContent;
import org.apache.archiva.repository.RepositoryContentFactory;
import org.apache.archiva.repository.content.legacy.LegacyPathParser;
@ -645,7 +646,7 @@ public class ArchivaDavResourceFactoryTest
extends DefaultRepositoryProxyConnectors
{
@Override
public File fetchMetatadaFromProxies( ManagedRepositoryContent repository, String logicalPath )
public ProxyFetchResult fetchMetadataFromProxies( ManagedRepositoryContent repository, String logicalPath )
{
File target = new File( repository.getRepoRoot(), logicalPath );
try
@ -657,7 +658,7 @@ public class ArchivaDavResourceFactoryTest
}
return target;
return new ProxyFetchResult( target, true );
}
}
}