You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@archiva.apache.org by ma...@apache.org on 2019/09/21 22:08:54 UTC

[archiva] branch feature/storage_refactoring updated (836ef6a -> 98b437b)

This is an automated email from the ASF dual-hosted git repository.

martin_s pushed a change to branch feature/storage_refactoring
in repository https://gitbox.apache.org/repos/asf/archiva.git.


    from 836ef6a  Fixing search test
     new 9148a98  Setting directory hint for root path of asset
     new fd48fb5  Adding null checks for index manager
     new 98b437b  Migrating servlet to repository registry usage

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../repository/storage/FilesystemAsset.java        |  4 ++
 .../archiva/indexer/maven/MavenIndexManager.java   | 16 ++++++--
 .../apache/archiva/webdav/RepositoryServlet.java   | 48 +---------------------
 .../webdav/AbstractRepositoryServletTestCase.java  | 11 +++--
 .../archiva/webdav/RepositoryServletTest.java      |  7 ++--
 5 files changed, 28 insertions(+), 58 deletions(-)


[archiva] 01/03: Setting directory hint for root path of asset

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

martin_s pushed a commit to branch feature/storage_refactoring
in repository https://gitbox.apache.org/repos/asf/archiva.git

commit 9148a985c0302cc3dac9179871ec4b2d989c47bc
Author: Martin Stockhammer <ma...@apache.org>
AuthorDate: Sun Sep 22 00:07:12 2019 +0200

    Setting directory hint for root path of asset
---
 .../java/org/apache/archiva/repository/storage/FilesystemAsset.java   | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/archiva-modules/archiva-base/archiva-storage-fs/src/main/java/org/apache/archiva/repository/storage/FilesystemAsset.java b/archiva-modules/archiva-base/archiva-storage-fs/src/main/java/org/apache/archiva/repository/storage/FilesystemAsset.java
index 4e35e5d..271dc1e 100644
--- a/archiva-modules/archiva-base/archiva-storage-fs/src/main/java/org/apache/archiva/repository/storage/FilesystemAsset.java
+++ b/archiva-modules/archiva-base/archiva-storage-fs/src/main/java/org/apache/archiva/repository/storage/FilesystemAsset.java
@@ -118,6 +118,10 @@ public class FilesystemAsset implements StorageAsset, Comparable {
         this.setPermissionsForNew = false;
         this.basePath = null;
         this.storage = storage;
+        // The base directory is always a directory
+        if ("".equals(path) || "/".equals(path)) {
+            this.directoryHint = true;
+        }
         init();
     }
 


[archiva] 03/03: Migrating servlet to repository registry usage

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

martin_s pushed a commit to branch feature/storage_refactoring
in repository https://gitbox.apache.org/repos/asf/archiva.git

commit 98b437bbb20ec37142364fa7314eed309b73eb68
Author: Martin Stockhammer <ma...@apache.org>
AuthorDate: Sun Sep 22 00:08:46 2019 +0200

    Migrating servlet to repository registry usage
---
 .../apache/archiva/webdav/RepositoryServlet.java   | 48 +---------------------
 .../webdav/AbstractRepositoryServletTestCase.java  | 11 +++--
 .../archiva/webdav/RepositoryServletTest.java      |  7 ++--
 3 files changed, 12 insertions(+), 54 deletions(-)

diff --git a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/RepositoryServlet.java b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/RepositoryServlet.java
index 800b81b..ef1e6c1 100644
--- a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/RepositoryServlet.java
+++ b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/RepositoryServlet.java
@@ -26,7 +26,6 @@ import org.apache.archiva.configuration.ConfigurationListener;
 import org.apache.archiva.redback.integration.filter.authentication.HttpAuthenticator;
 import org.apache.archiva.repository.ManagedRepository;
 import org.apache.archiva.repository.RepositoryRegistry;
-import org.apache.archiva.repository.storage.StorageAsset;
 import org.apache.archiva.security.ServletAuthenticator;
 import org.apache.jackrabbit.webdav.DavException;
 import org.apache.jackrabbit.webdav.DavLocatorFactory;
@@ -51,10 +50,7 @@ import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
-import java.util.LinkedHashMap;
-import java.util.Map;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
-import java.util.stream.Collectors;
 
 /**
  * RepositoryServlet
@@ -69,8 +65,6 @@ public class RepositoryServlet
 
     RepositoryRegistry repositoryRegistry;
 
-    private Map<String, ManagedRepository> repositoryMap;
-
     private DavLocatorFactory locatorFactory;
 
     private DavResourceFactory resourceFactory;
@@ -176,23 +170,6 @@ public class RepositoryServlet
             configuration.addListener(this);
 
             repositoryRegistry = wac.getBean(RepositoryRegistry.class);
-            repositoryMap = new LinkedHashMap<>();
-
-            fillRepositoryMap();
-
-            for (ManagedRepository repo : repositoryMap.values()) {
-                StorageAsset repoDir = repo.getAsset("");
-
-                if (!repoDir.exists()) {
-                    try {
-                        repoDir.create();
-                    } catch (IOException e) {
-                        log.info("Unable to create missing directory for {}", repo.getLocation());
-                        continue;
-                    }
-                }
-            }
-
             resourceFactory = wac.getBean("davResourceFactory#archiva", DavResourceFactory.class);
             locatorFactory = new ArchivaDavLocatorFactory();
 
@@ -208,17 +185,6 @@ public class RepositoryServlet
         log.debug( "initServers done in {} ms", (end - start) );
     }
 
-    private void fillRepositoryMap() {
-        final Map<String, ManagedRepository> repos = repositoryRegistry.getManagedRepositories().stream().collect(Collectors.toMap(r -> r.getId(), r -> r));
-        rwLock.writeLock().lock();
-        try {
-            repositoryMap.clear();
-            repositoryMap.putAll(repos);
-        } finally {
-            rwLock.writeLock().unlock();
-        }
-    }
-
     @Override
     public void configurationEvent( ConfigurationEvent event )
     {
@@ -245,17 +211,7 @@ public class RepositoryServlet
     public ManagedRepository getRepository( String prefix )
         throws RepositoryAdminException
     {
-        rwLock.readLock().lock();
-        try {
-            if (repositoryMap.isEmpty()) {
-                rwLock.readLock().unlock();
-                fillRepositoryMap();
-                rwLock.readLock().lock();
-            }
-            return repositoryMap.get(prefix);
-        } finally {
-            rwLock.readLock().unlock();
-        }
+        return repositoryRegistry.getManagedRepository( prefix );
     }
 
     ArchivaConfiguration getConfiguration()
@@ -329,8 +285,6 @@ public class RepositoryServlet
             configuration = null;
             locatorFactory = null;
             sessionProvider = null;
-            repositoryMap.clear();
-            repositoryMap = null;
 
             WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
 
diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/AbstractRepositoryServletTestCase.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/AbstractRepositoryServletTestCase.java
index 2094ba3..c5b01e3 100644
--- a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/AbstractRepositoryServletTestCase.java
+++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/AbstractRepositoryServletTestCase.java
@@ -195,7 +195,10 @@ public abstract class AbstractRepositoryServletTestCase
             }
         } finally
         {
-            ctx.close(  );
+            if (ctx!=null)
+            {
+                ctx.close( );
+            }
         }
 
         CacheManager.getInstance().clearAll();
@@ -727,18 +730,18 @@ public abstract class AbstractRepositoryServletTestCase
 
         if ( Files.exists(repoRootInternal) )
         {
-            org.apache.archiva.common.utils.FileUtils.deleteDirectory( repoRootInternal );
+            org.apache.archiva.common.utils.FileUtils.deleteQuietly( repoRootInternal );
         }
 
         if ( Files.exists(repoRootLegacy) )
         {
-            org.apache.archiva.common.utils.FileUtils.deleteDirectory( repoRootLegacy );
+            org.apache.archiva.common.utils.FileUtils.deleteQuietly( repoRootLegacy );
         }
 
         String appserverBase = System.getProperty( "appserver.base" );
         if ( StringUtils.isNotEmpty( appserverBase ) )
         {
-            org.apache.archiva.common.utils.FileUtils.deleteDirectory( Paths.get( appserverBase ) );
+            org.apache.archiva.common.utils.FileUtils.deleteQuietly( Paths.get( appserverBase ) );
         }
 
     }
diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/RepositoryServletTest.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/RepositoryServletTest.java
index 024d387..909d9c7 100644
--- a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/RepositoryServletTest.java
+++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/RepositoryServletTest.java
@@ -79,6 +79,7 @@ public class RepositoryServletTest
         Configuration c = archivaConfiguration.getConfiguration();
         c.removeManagedRepository( c.findManagedRepositoryById( REPOID_INTERNAL ) );
         saveConfiguration( archivaConfiguration );
+        repositoryRegistry.removeRepository( REPOID_INTERNAL );
 
         org.apache.archiva.repository.ManagedRepository repository = servlet.getRepository( REPOID_INTERNAL );
         assertNull( repository );
@@ -117,9 +118,9 @@ public class RepositoryServletTest
     public void testGetRepositoryInvalidPathPassthroughPresent()
         throws Exception
     {
-        String path = REQUEST_PATH + ".index/filecontent/segments.gen";
+        String path = REQUEST_PATH + ".indexer/filecontent/segments.gen";
 
-        populateRepo( repoRootInternal, ".index/filecontent/segments.gen", "index file" );
+        populateRepo( repoRootInternal, ".indexer/filecontent/segments.gen", "index file" );
 
         WebRequest request = new GetMethodWebRequest( path );
         WebResponse response = getServletUnitClient().getResponse( request );
@@ -131,7 +132,7 @@ public class RepositoryServletTest
     public void testGetRepositoryInvalidPathPassthroughMissing()
         throws Exception
     {
-        String path = REQUEST_PATH + ".index/filecontent/foo.bar";
+        String path = REQUEST_PATH + ".indexer/filecontent/foo.bar";
 
         WebRequest request = new GetMethodWebRequest( path );
         WebResponse response = getServletUnitClient().getResponse( request );


[archiva] 02/03: Adding null checks for index manager

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

martin_s pushed a commit to branch feature/storage_refactoring
in repository https://gitbox.apache.org/repos/asf/archiva.git

commit fd48fb51b28d9b603fc3a4b23c37081a460e94a8
Author: Martin Stockhammer <ma...@apache.org>
AuthorDate: Sun Sep 22 00:08:17 2019 +0200

    Adding null checks for index manager
---
 .../apache/archiva/indexer/maven/MavenIndexManager.java  | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/archiva-modules/archiva-maven/archiva-maven-indexer/src/main/java/org/apache/archiva/indexer/maven/MavenIndexManager.java b/archiva-modules/archiva-maven/archiva-maven-indexer/src/main/java/org/apache/archiva/indexer/maven/MavenIndexManager.java
index 73a8900..4a4ad80 100644
--- a/archiva-modules/archiva-maven/archiva-maven-indexer/src/main/java/org/apache/archiva/indexer/maven/MavenIndexManager.java
+++ b/archiva-modules/archiva-maven/archiva-maven-indexer/src/main/java/org/apache/archiva/indexer/maven/MavenIndexManager.java
@@ -149,12 +149,17 @@ public class MavenIndexManager implements ArchivaIndexManager {
 
     public static IndexingContext getMvnContext( ArchivaIndexingContext context ) throws UnsupportedBaseContextException
     {
-        if ( !context.supports( IndexingContext.class ) )
+        if (context!=null)
         {
-            log.error( "The provided archiva index context does not support the maven IndexingContext" );
-            throw new UnsupportedBaseContextException( "The context does not support the Maven IndexingContext" );
+            if ( !context.supports( IndexingContext.class ) )
+            {
+                log.error( "The provided archiva index context does not support the maven IndexingContext" );
+                throw new UnsupportedBaseContextException( "The context does not support the Maven IndexingContext" );
+            }
+            return context.getBaseContext( IndexingContext.class );
+        } else {
+            return null;
         }
-        return context.getBaseContext( IndexingContext.class );
     }
 
     private StorageAsset getIndexPath( ArchivaIndexingContext ctx )
@@ -175,6 +180,9 @@ public class MavenIndexManager implements ArchivaIndexManager {
      */
     private void executeUpdateFunction( ArchivaIndexingContext context, IndexUpdateConsumer function ) throws IndexUpdateFailedException
     {
+        if (context==null) {
+            throw new IndexUpdateFailedException( "Given context is null" );
+        }
         IndexingContext indexingContext = null;
         try
         {