]> source.dussan.org Git - archiva.git/commitdiff
MRM-813 tweak APC interface and ADRF AuditEvents
authorJonathan Sharp <forjsharp@gmail.com>
Fri, 17 Oct 2014 22:23:47 +0000 (15:23 -0700)
committerJonathan Sharp <forjsharp@gmail.com>
Fri, 17 Oct 2014 22:23:47 +0000 (15:23 -0700)
archiva-modules/archiva-base/archiva-proxy-api/src/main/java/org/apache/archiva/proxy/model/ProxyFetchResult.java [new file with mode: 0644]
archiva-modules/archiva-base/archiva-proxy-api/src/main/java/org/apache/archiva/proxy/model/RepositoryProxyConnectors.java
archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyConnectors.java
archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/proxy/MetadataTransferTest.java
archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResource.java
archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java
archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/ArchivaDavResourceFactoryTest.java

diff --git a/archiva-modules/archiva-base/archiva-proxy-api/src/main/java/org/apache/archiva/proxy/model/ProxyFetchResult.java b/archiva-modules/archiva-base/archiva-proxy-api/src/main/java/org/apache/archiva/proxy/model/ProxyFetchResult.java
new file mode 100644 (file)
index 0000000..28c2af0
--- /dev/null
@@ -0,0 +1,48 @@
+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;
+    }
+}
index 37b3732199500d5e975c04e1d6c9e00793d57c12..e63f6239385ea07faf7b3181f8b1b872c3e9d2fe 100644 (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
index 151dd61ea4f3664cf91eb0a38232b3e8ba3e2a33..0daa2d2013f46ea739fd8f659020bab5be560c5a 100644 (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 );
     }
 
     /**
index ed7f04b48325c31753728ed709e63e8e493f542c..8ed5767888e8d1b99695f6627987af8f1d3c2dc8 100644 (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 );
index f9a4d9e510ec7bca458dcc2d007b52bd02a65932..074d13bdae21c17689dec0458b1e5a19a74b8ed4 100644 (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 )
index 1e225a60a25367596c2626eb6140ff7703bdb35b..31e2b881f093d2e07acc1cc3dd90359bf9853370 100644 (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?
index b8e460e26e48475046db527429ad1bdceed29c1a..edb8ab3d4a773a3a8b40ba81b62ebc60a659dacb 100644 (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 );
         }
     }
 }