From: Olivier Lamy Date: Wed, 7 Sep 2011 12:18:55 +0000 (+0000) Subject: start using new repo admin module in webdav : need some other refactoring to remove... X-Git-Tag: archiva-1.4-M1~366 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=1032b3d5d12bf8c8e9035c3017ddd3345b3ab7ca;p=archiva.git start using new repo admin module in webdav : need some other refactoring to remove it completely git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1166148 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-modules/archiva-web/archiva-webdav/pom.xml b/archiva-modules/archiva-web/archiva-webdav/pom.xml index b7bf7e78f..1be3a0551 100644 --- a/archiva-modules/archiva-web/archiva-webdav/pom.xml +++ b/archiva-modules/archiva-web/archiva-webdav/pom.xml @@ -39,16 +39,20 @@ org.apache.archiva audit + + org.apache.archiva + archiva-repository-scanner + org.apache.archiva archiva-configuration - org.apache.archiva - archiva-repository-scanner + archiva-repository-admin org.apache.archiva @@ -166,6 +170,8 @@ -Xmx512m -Xms512m -client ${basedir}/target/appserver-base + ${project.build.outputDirectory} + ${project.build.outputDirectory} ${webdav.forkMode} diff --git a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/RepositoryServlet.java b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/RepositoryServlet.java index 59363bcf3..2aabf858a 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/RepositoryServlet.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/RepositoryServlet.java @@ -19,6 +19,10 @@ package org.apache.maven.archiva.webdav; * under the License. */ +import org.apache.archiva.admin.repository.RepositoryAdminException; +import org.apache.archiva.admin.repository.managed.ManagedRepository; +import org.apache.archiva.admin.repository.managed.ManagedRepositoryAdmin; +import org.apache.archiva.security.ServletAuthenticator; import org.apache.jackrabbit.webdav.DavException; import org.apache.jackrabbit.webdav.DavLocatorFactory; import org.apache.jackrabbit.webdav.DavMethods; @@ -34,8 +38,6 @@ import org.apache.jackrabbit.webdav.server.AbstractWebdavServlet; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.ConfigurationEvent; import org.apache.maven.archiva.configuration.ConfigurationListener; -import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; -import org.apache.archiva.security.ServletAuthenticator; import org.codehaus.redback.integration.filter.authentication.HttpAuthenticator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -62,7 +64,9 @@ public class RepositoryServlet private ArchivaConfiguration configuration; - private Map repositoryMap; + private ManagedRepositoryAdmin managedRepositoryAdmin; + + private Map repositoryMap; private DavLocatorFactory locatorFactory; @@ -76,7 +80,15 @@ public class RepositoryServlet throws ServletException { super.init( servletConfig ); - initServers( servletConfig ); + try + { + initServers( servletConfig ); + } + catch ( RepositoryAdminException e ) + { + log.error( e.getMessage(), e ); + throw new ServletException( e.getMessage(), e ); + } } /** @@ -156,6 +168,7 @@ public class RepositoryServlet } public synchronized void initServers( ServletConfig servletConfig ) + throws RepositoryAdminException { WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext( servletConfig.getServletContext() ); @@ -163,9 +176,11 @@ public class RepositoryServlet configuration = wac.getBean( "archivaConfiguration#default", ArchivaConfiguration.class ); configuration.addListener( this ); - repositoryMap = configuration.getConfiguration().getManagedRepositoriesAsMap(); + managedRepositoryAdmin = wac.getBean( ManagedRepositoryAdmin.class ); + + repositoryMap = managedRepositoryAdmin.getManagedRepositoriesAsMap(); - for ( ManagedRepositoryConfiguration repo : repositoryMap.values() ) + for ( ManagedRepository repo : repositoryMap.values() ) { File repoDir = new File( repo.getLocation() ); @@ -180,7 +195,7 @@ public class RepositoryServlet } } - resourceFactory = wac.getBean("davResourceFactory#archiva", DavResourceFactory.class ); + resourceFactory = wac.getBean( "davResourceFactory#archiva", DavResourceFactory.class ); locatorFactory = new ArchivaDavLocatorFactory(); ServletAuthenticator servletAuth = wac.getBean( ServletAuthenticator.class ); @@ -195,16 +210,25 @@ public class RepositoryServlet { if ( event.getType() == ConfigurationEvent.SAVED ) { - initRepositories(); + try + { + initRepositories(); + } + catch ( RepositoryAdminException e ) + { + log.error( e.getMessage(), e ); + throw new RuntimeException( e.getMessage(), e ); + } } } private void initRepositories() + throws RepositoryAdminException { synchronized ( repositoryMap ) { repositoryMap.clear(); - repositoryMap.putAll( configuration.getConfiguration().getManagedRepositoriesAsMap() ); + repositoryMap.putAll( managedRepositoryAdmin.getManagedRepositoriesAsMap() ); } synchronized ( reloadLock ) @@ -213,11 +237,12 @@ public class RepositoryServlet } } - public synchronized ManagedRepositoryConfiguration getRepository( String prefix ) + public synchronized ManagedRepository getRepository( String prefix ) + throws RepositoryAdminException { if ( repositoryMap.isEmpty() ) { - repositoryMap.putAll( configuration.getConfiguration().getManagedRepositoriesAsMap() ); + repositoryMap.putAll( managedRepositoryAdmin.getManagedRepositoriesAsMap() ); } return repositoryMap.get( prefix ); } diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/AbstractRepositoryServletTestCase.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/AbstractRepositoryServletTestCase.java index 2c42b67e2..cab60b2ec 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/AbstractRepositoryServletTestCase.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/AbstractRepositoryServletTestCase.java @@ -26,6 +26,7 @@ import com.meterware.servletunit.ServletUnitClient; import junit.framework.Assert; import junit.framework.TestCase; import net.sf.ehcache.CacheManager; +import org.apache.archiva.admin.repository.managed.ManagedRepository; import org.apache.commons.io.FileUtils; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.Configuration; @@ -173,8 +174,9 @@ public abstract class AbstractRepositoryServletTestCase } protected void assertRepositoryValid( RepositoryServlet servlet, String repoId ) + throws Exception { - ManagedRepositoryConfiguration repository = servlet.getRepository( repoId ); + ManagedRepository repository = servlet.getRepository( repoId ); assertNotNull( "Archiva Managed Repository id:<" + repoId + "> should exist.", repository ); File repoRoot = new File( repository.getLocation() ); assertTrue( "Archiva Managed Repository id:<" + repoId + "> should have a valid location on disk.", diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/RepositoryServletTest.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/RepositoryServletTest.java index 21d2bce30..835eaf9bb 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/RepositoryServletTest.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/RepositoryServletTest.java @@ -19,6 +19,7 @@ package org.apache.maven.archiva.webdav; * under the License. */ +import org.apache.archiva.admin.repository.managed.ManagedRepository; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.Configuration; import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; @@ -67,7 +68,7 @@ public class RepositoryServletTest c.removeManagedRepository( c.findManagedRepositoryById( REPOID_INTERNAL ) ); saveConfiguration( archivaConfiguration ); - ManagedRepositoryConfiguration repository = servlet.getRepository( REPOID_INTERNAL ); + ManagedRepository repository = servlet.getRepository( REPOID_INTERNAL ); assertNull( repository ); } @@ -92,7 +93,7 @@ public class RepositoryServletTest c.addManagedRepository( repo ); saveConfiguration( archivaConfiguration ); - ManagedRepositoryConfiguration repository = servlet.getRepository( NEW_REPOSITORY_ID ); + ManagedRepository repository = servlet.getRepository( NEW_REPOSITORY_ID ); assertNotNull( repository ); assertEquals( NEW_REPOSITORY_NAME, repository.getName() ); diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/UnauthenticatedRepositoryServlet.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/UnauthenticatedRepositoryServlet.java index 2f261d57e..f5bd767e0 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/UnauthenticatedRepositoryServlet.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/UnauthenticatedRepositoryServlet.java @@ -19,10 +19,12 @@ package org.apache.maven.archiva.webdav; * under the License. */ +import org.apache.archiva.admin.repository.RepositoryAdminException; + import javax.servlet.ServletConfig; /** - * UnauthenticatedRepositoryServlet + * UnauthenticatedRepositoryServlet * * @version $Id$ */ @@ -32,9 +34,16 @@ public class UnauthenticatedRepositoryServlet @Override public synchronized void initServers( ServletConfig servletConfig ) { - super.initServers(servletConfig); - + try + { + super.initServers( servletConfig ); + } + catch ( RepositoryAdminException e ) + { + throw new RuntimeException( e.getMessage(), e ); + } + UnauthenticatedDavSessionProvider sessionProvider = new UnauthenticatedDavSessionProvider(); - setDavSessionProvider(sessionProvider); + setDavSessionProvider( sessionProvider ); } } diff --git a/pom.xml b/pom.xml index 3f9a31dce..0a6bb09a7 100644 --- a/pom.xml +++ b/pom.xml @@ -1490,6 +1490,11 @@ 2.9 ${surefire.redirectTestOutputToFile} + + ${basedir}/target/appserver-base + ${project.build.outputDirectory} + ${project.build.outputDirectory} +