]> source.dussan.org Git - archiva.git/commitdiff
Migrating servlet to repository registry usage
authorMartin Stockhammer <martin_s@apache.org>
Sat, 21 Sep 2019 22:08:46 +0000 (00:08 +0200)
committerMartin Stockhammer <martin_s@apache.org>
Sat, 21 Sep 2019 22:09:54 +0000 (00:09 +0200)
archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/RepositoryServlet.java
archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/AbstractRepositoryServletTestCase.java
archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/RepositoryServletTest.java

index 800b81b26a7c31b73a8a1281e597044bb887fa9b..ef1e6c1a1c079274a0f28478016c214834f8dc92 100644 (file)
@@ -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());
 
index 2094ba34daeb608808fc7b898451fe1c68b9a1a9..c5b01e3cdd61d74cf947bfbded6f399ce51c2fbc 100644 (file)
@@ -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 ) );
         }
 
     }
index 024d3876ac7ed5bffb56920da51578cda7ed6e15..909d9c7c5ad3974fb3ab9432f51aacd8fa6df146 100644 (file)
@@ -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 );