]> source.dussan.org Git - archiva.git/commitdiff
start using new repo admin module in webdav : need some other refactoring to remove...
authorOlivier Lamy <olamy@apache.org>
Wed, 7 Sep 2011 12:18:55 +0000 (12:18 +0000)
committerOlivier Lamy <olamy@apache.org>
Wed, 7 Sep 2011 12:18:55 +0000 (12:18 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1166148 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-webdav/pom.xml
archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/RepositoryServlet.java
archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/AbstractRepositoryServletTestCase.java
archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/RepositoryServletTest.java
archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/UnauthenticatedRepositoryServlet.java
pom.xml

index b7bf7e78f2af7edbbc3c6a903c1616725a0529ef..1be3a0551e03e8b1071f785ea39de5f919db571e 100644 (file)
       <groupId>org.apache.archiva</groupId>
       <artifactId>audit</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.apache.archiva</groupId>
+      <artifactId>archiva-repository-scanner</artifactId>
+    </dependency>
     <dependency>
       <groupId>org.apache.archiva</groupId>
       <artifactId>archiva-configuration</artifactId>
-      <!-- TODO uncomment when repository admin will be finished
+      <!-- should be runtime but currently not possible due ConfigurationListener
       <scope>runtime</scope>
       -->
     </dependency>
     <dependency>
       <groupId>org.apache.archiva</groupId>
-      <artifactId>archiva-repository-scanner</artifactId>
+      <artifactId>archiva-repository-admin</artifactId>
     </dependency>
     <dependency>
       <groupId>org.apache.archiva</groupId>
           <argLine>-Xmx512m -Xms512m -client</argLine>
           <systemPropertyVariables>
             <appserver.base>${basedir}/target/appserver-base</appserver.base>
+            <plexus.home>${project.build.outputDirectory}</plexus.home>
+            <java.io.tmpdir>${project.build.outputDirectory}</java.io.tmpdir>
           </systemPropertyVariables>
           <forkMode>${webdav.forkMode}</forkMode>
         </configuration>
index 59363bcf31bcf9bd7eff82fb2d9b5e9a2af04809..2aabf858a71c3cb46a7eaee4faf180c7da6f5e2f 100644 (file)
@@ -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<String, ManagedRepositoryConfiguration> repositoryMap;
+    private ManagedRepositoryAdmin managedRepositoryAdmin;
+
+    private Map<String, ManagedRepository> 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 );
     }
index 2c42b67e2f61661f23c592a73e90c172f86994c2..cab60b2ec8048f0c517945b16cbcce8f5e09dee8 100644 (file)
@@ -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.",
index 21d2bce305bef3148ad7ab1e5d6e83972f2204f9..835eaf9bbdb0d8bbf672e2e96bc7e42766b410da 100644 (file)
@@ -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() );
 
index 2f261d57ef48f6e2e7d150d24ce73853216c6a6b..f5bd767e03cfc23027ea144293f27fa4c94e932c 100644 (file)
@@ -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 3f9a31dcef8981589682a092ec9c522a56b96244..0a6bb09a784412fc5541fc4f8e3a3dbfa5f11d0d 100644 (file)
--- a/pom.xml
+++ b/pom.xml
           <version>2.9</version>
           <configuration>
             <redirectTestOutputToFile>${surefire.redirectTestOutputToFile}</redirectTestOutputToFile>
+            <systemPropertyVariables>
+              <appserver.base>${basedir}/target/appserver-base</appserver.base>
+              <plexus.home>${project.build.outputDirectory}</plexus.home>
+              <java.io.tmpdir>${project.build.outputDirectory}</java.io.tmpdir>
+            </systemPropertyVariables>
           </configuration>
         </plugin>
         <plugin>