From 98b437bbb20ec37142364fa7314eed309b73eb68 Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Sun, 22 Sep 2019 00:08:46 +0200 Subject: [PATCH] Migrating servlet to repository registry usage --- .../archiva/webdav/RepositoryServlet.java | 48 +------------------ .../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 800b81b26..ef1e6c1a1 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 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 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 2094ba34d..c5b01e3cd 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 024d3876a..909d9c7c5 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 ); -- 2.39.5