--- /dev/null
+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.
+ */
+public class ProxyFetchResult
+{
+
+ //The file returned
+ File file;
+
+ //Was the local file modified by the fetch?
+ boolean modified;
+
+ public ProxyFetchResult( File file, boolean modified) {
+ this.file = file;
+ this.modified = modified;
+ }
+
+ public File getFile() {
+ return file;
+ }
+
+ public boolean isModified() {
+ return modified;
+ }
+}
* @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
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;
}
@Override
- public File fetchMetatadaFromProxies( ManagedRepositoryContent repository, String logicalPath )
+ public ProxyFetchResult fetchMetadataFromProxies( ManagedRepositoryContent repository, String logicalPath )
{
File localFile = new File( repository.getRepoRoot(), logicalPath );
{
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 );
}
/**
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;
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 );
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 );
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 );
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 );
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 );
}
}
- 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 )
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;
{
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.
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() )
// 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?
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;
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
}
- return target;
+ return new ProxyFetchResult( target, true );
}
}
}