]> source.dussan.org Git - archiva.git/commitdiff
[MRM-336]: Repository Admin - "Index Repository" appears to not do anything.
authorJoakim Erdfelt <joakime@apache.org>
Wed, 16 May 2007 01:59:20 +0000 (01:59 +0000)
committerJoakim Erdfelt <joakime@apache.org>
Wed, 16 May 2007 01:59:20 +0000 (01:59 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@538404 13f79535-47bb-0310-9956-ffa450edef68

archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/RepositoryConfigurationToMapClosure.java [new file with mode: 0644]
archiva-base/archiva-model/src/main/mdo/archiva-base.xml
archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/DefaultArchivaTaskScheduler.java
archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/RepositoryTaskJob.java
archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/executors/ArchivaRepositoryScanningTaskExecutor.java
archiva-web/archiva-webapp/pom.xml
archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/repository/RepositoryServlet.java
archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/repositories.jsp

diff --git a/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/RepositoryConfigurationToMapClosure.java b/archiva-base/archiva-configuration/src/main/java/org/apache/maven/archiva/configuration/functors/RepositoryConfigurationToMapClosure.java
new file mode 100644 (file)
index 0000000..08ed115
--- /dev/null
@@ -0,0 +1,52 @@
+package org.apache.maven.archiva.configuration.functors;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.commons.collections.Closure;
+import org.apache.maven.archiva.configuration.RepositoryConfiguration;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * RepositoryConfigurationToMapClosure 
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class RepositoryConfigurationToMapClosure
+    implements Closure
+{
+    private Map map = new HashMap();
+
+    public void execute( Object input )
+    {
+        if ( input instanceof RepositoryConfiguration )
+        {
+            RepositoryConfiguration repo = (RepositoryConfiguration) input;
+            map.put( repo.getId(), repo );
+        }
+    }
+
+    public Map getMap()
+    {
+        return map;
+    }
+}
index 59cf67869cf36ae0c8271d6e7090ece25a43b146..17198a828f119182b568b5e41134145164f20621 100644 (file)
 
         buf.append( "\n  Duration          : " );
         buf.append( org.apache.maven.archiva.common.utils.DateUtil.getDuration( this.getDuration() ) );
-        buf.append( "\n  When Gathered     : " ).append( df.format( this.getWhenGathered() ) );
+        buf.append( "\n  When Gathered     : " );
+        if ( this.getWhenGathered() == null )
+        {
+            buf.append( "<null>" );
+        }
+        else
+        {
+            buf.append( df.format( this.getWhenGathered() ) );
+        }
+            
         buf.append( "\n  Total File Count  : " ).append( this.getTotalFileCount() );
         long averageMsPerFile = ( this.getDuration() / this.getTotalFileCount() );
         buf.append( "\n  Avg Time Per File : " );
index c8fd75229d1e5ebb0f04d78870dcb30e53ef509a..083e9b07d072567faf2fc95392785a9fac6d2c0c 100644 (file)
@@ -33,6 +33,7 @@ import org.codehaus.plexus.personality.plexus.lifecycle.phase.StartingException;
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.StoppingException;
 import org.codehaus.plexus.registry.Registry;
 import org.codehaus.plexus.registry.RegistryListener;
+import org.codehaus.plexus.scheduler.CronExpressionValidator;
 import org.codehaus.plexus.scheduler.Scheduler;
 import org.codehaus.plexus.taskqueue.TaskQueue;
 import org.codehaus.plexus.taskqueue.TaskQueueException;
@@ -89,6 +90,8 @@ public class DefaultArchivaTaskScheduler
 
     public static final String REPOSITORY_JOB_TRIGGER = "repository-job-trigger";
 
+    public static final String CRON_HOURLY = "0 0 * * * ?";
+
     public void start()
         throws StartingException
     {
@@ -100,7 +103,10 @@ public class DefaultArchivaTaskScheduler
             {
                 RepositoryConfiguration repoConfig = (RepositoryConfiguration) i.next();
 
-                scheduleRepositoryJobs( repoConfig );
+                if ( repoConfig.isManaged() && repoConfig.isIndexed() )
+                {
+                    scheduleRepositoryJobs( repoConfig );
+                }
             }
 
             scheduleDatabaseJobs();
@@ -123,6 +129,15 @@ public class DefaultArchivaTaskScheduler
         // get the cron string for these database scanning jobs
         String cronString = repoConfig.getRefreshCronExpression();
 
+        CronExpressionValidator cronValidator = new CronExpressionValidator();
+        if ( !cronValidator.validate( cronString ) )
+        {
+            getLogger().warn(
+                              "Cron expression [" + cronString + "] for repository [" + repoConfig.getId()
+                                  + "] is invalid.  Defaulting to hourly." );
+            cronString = CRON_HOURLY;
+        }
+
         // setup the unprocessed artifact job
         JobDetail repositoryJob = new JobDetail( REPOSITORY_JOB + ":" + repoConfig.getId(), REPOSITORY_SCAN_GROUP,
                                                  RepositoryTaskJob.class );
@@ -345,13 +360,13 @@ public class DefaultArchivaTaskScheduler
 
         return !queue.isEmpty();
     }
-    
+
     public void queueRepositoryTask( RepositoryTask task )
         throws TaskQueueException
     {
         repositoryScanningQueue.put( task );
     }
-    
+
     public void queueDatabaseTask( DatabaseTask task )
         throws TaskQueueException
     {
index cfe148860935fe5295dbf5fa2f51090e2f4e037b..e71d084fa981e8885a89fde1a41806375757ebf4 100644 (file)
@@ -39,7 +39,7 @@ public class RepositoryTaskJob
     static final String TASK_QUEUE = "TASK_QUEUE";
 
     static final String TASK_QUEUE_POLICY = "TASK_QUEUE_POLICY";
-    
+
     static final String TASK_REPOSITORY = "TASK_REPOSITORY";
 
     /**
@@ -58,8 +58,9 @@ public class RepositoryTaskJob
         TaskQueue taskQueue = (TaskQueue) dataMap.get( TASK_QUEUE );
         String queuePolicy = dataMap.get( TASK_QUEUE_POLICY ).toString();
 
-        ArchivaTask task = new RepositoryTask();
+        RepositoryTask task = new RepositoryTask();
         task.setName( context.getJobDetail().getName() );
+        task.setRepositoryId( (String) dataMap.get( TASK_REPOSITORY ) );
 
         try
         {
index 227f07346d0ab02a3463021cd8992535d5d0ec93..983cfa5f95d7b8f298808c0b18b98b857d4a2cbb 100644 (file)
@@ -20,6 +20,7 @@ package org.apache.maven.archiva.scheduled.executors;
  */
 
 import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang.StringUtils;
 import org.apache.maven.archiva.database.ArchivaDAO;
 import org.apache.maven.archiva.database.ArchivaDatabaseException;
 import org.apache.maven.archiva.database.RepositoryDAO;
@@ -79,8 +80,14 @@ public class ArchivaRepositoryScanningTaskExecutor
         throws TaskExecutionException
     {
         RepositoryTask repoTask = (RepositoryTask) task;
-        getLogger().info( "Executing task from queue with job name: " + repoTask.getName() );
+        
+        if ( StringUtils.isBlank( repoTask.getRepositoryId() ) )
+        {
+            throw new TaskExecutionException("Unable to execute RepositoryTask with blank repository Id.");
+        }
 
+        getLogger().info( "Executing task from queue with job name: " + repoTask.getName() );
+        
         try
         {
             ArchivaRepository arepo = repositoryDAO.getRepository( repoTask.getRepositoryId() );
@@ -97,7 +104,7 @@ public class ArchivaRepositoryScanningTaskExecutor
 
             RepositoryContentStatistics stats = repoScanner.scan( arepo, sinceWhen );
 
-            dao.save( stats );
+            stats = (RepositoryContentStatistics) dao.save( stats );
 
             getLogger().info( "Finished repository task: " + stats.toDump( arepo ) );
         }
index a25c376624398917bcec4bc4146ed38bbe467763..5ae5e347bc78f89adc9836cdec952926892234e8 100644 (file)
       <groupId>org.apache.maven.archiva</groupId>
       <artifactId>archiva-security</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.apache.maven.archiva</groupId>
+      <artifactId>archiva-core-consumers</artifactId>
+    </dependency>
     <dependency>
       <groupId>org.apache.maven.archiva</groupId>
       <artifactId>archiva-database-consumers</artifactId>
index 8feaadc3b09e078a9bee4938b7aa0c2919d96cf8..851c02f4c825bf6ea3a81041776a233e38bb5ad9 100644 (file)
@@ -19,12 +19,15 @@ package org.apache.maven.archiva.web.repository;
  * under the License.
  */
 
+import org.apache.commons.collections.Closure;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections.functors.IfClosure;
 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
 import org.apache.maven.archiva.configuration.ConfigurationNames;
-import org.apache.maven.archiva.database.ArchivaDAO;
-import org.apache.maven.archiva.database.ArchivaDatabaseException;
-import org.apache.maven.archiva.database.ObjectNotFoundException;
-import org.apache.maven.archiva.model.ArchivaRepository;
+import org.apache.maven.archiva.configuration.RepositoryConfiguration;
+import org.apache.maven.archiva.configuration.functors.LocalRepositoryPredicate;
+import org.apache.maven.archiva.configuration.functors.RepositoryConfigurationToMapClosure;
+import org.apache.maven.archiva.model.RepositoryURL;
 import org.apache.maven.archiva.security.ArchivaRoleConstants;
 import org.codehaus.plexus.redback.authentication.AuthenticationException;
 import org.codehaus.plexus.redback.authentication.AuthenticationResult;
@@ -45,8 +48,10 @@ import org.codehaus.plexus.webdav.util.WebdavMethodUtil;
 
 import java.io.File;
 import java.io.IOException;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
@@ -78,16 +83,13 @@ public class RepositoryServlet
      */
     private AuditLog audit;
 
-    /**
-     * @plexus.requirement role-hint="jdo"
-     */
-    private ArchivaDAO dao;
-
     /**
      * @plexus.requirement
      */
     private ArchivaConfiguration configuration;
 
+    private Map repositoryMap = new HashMap();
+
     public void initComponents()
         throws ServletException
     {
@@ -97,7 +99,8 @@ public class RepositoryServlet
         httpAuth = (HttpAuthenticator) lookup( HttpAuthenticator.ROLE, "basic" );
         audit = (AuditLog) lookup( AuditLog.ROLE );
 
-        dao = (ArchivaDAO) lookup( ArchivaDAO.ROLE, "jdo" );
+        updateRepositoryMap();
+
         configuration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class.getName() );
         configuration.addChangeListener( this );
     }
@@ -105,70 +108,60 @@ public class RepositoryServlet
     public void initServers( ServletConfig servletConfig )
         throws DavServerException
     {
-        try
+        List repositories = configuration.getConfiguration().getRepositories();
+        Iterator itrepos = repositories.iterator();
+        while ( itrepos.hasNext() )
         {
-            List repositories = dao.getRepositoryDAO().getRepositories();
-            Iterator itrepos = repositories.iterator();
-            while ( itrepos.hasNext() )
+            RepositoryConfiguration repo = (RepositoryConfiguration) itrepos.next();
+            if ( !repo.isManaged() )
             {
-                ArchivaRepository repo = (ArchivaRepository) itrepos.next();
-                if ( !repo.isManaged() )
-                {
-                    // Skip non-managed.
-                    continue;
-                }
+                // Skip non-managed.
+                continue;
+            }
 
-                File repoDir = new File( repo.getUrl().getPath() );
+            RepositoryURL url = new RepositoryURL( repo.getUrl() );
+            File repoDir = new File( url.getPath() );
 
-                if ( !repoDir.exists() )
+            if ( !repoDir.exists() )
+            {
+                if ( !repoDir.mkdirs() )
                 {
-                    if ( !repoDir.mkdirs() )
-                    {
-                        // Skip invalid directories.
-                        log( "Unable to create missing directory for " + repo.getUrl().getPath() );
-                        continue;
-                    }
+                    // Skip invalid directories.
+                    log( "Unable to create missing directory for " + url.getPath() );
+                    continue;
                 }
+            }
 
-                DavServerComponent server = createServer( repo.getId(), repoDir, servletConfig );
+            DavServerComponent server = createServer( repo.getId(), repoDir, servletConfig );
 
-                server.addListener( audit );
-            }
-        }
-        catch ( ArchivaDatabaseException e )
-        {
-            throw new DavServerException( "Unable to initialized dav servers: " + e.getMessage(), e );
+            server.addListener( audit );
         }
     }
 
-    public ArchivaRepository getRepository( DavServerRequest request )
+    public RepositoryConfiguration getRepository( DavServerRequest request )
     {
-        String id = request.getPrefix();
-        try
-        {
-            return dao.getRepositoryDAO().getRepository( id );
-        }
-        catch ( ObjectNotFoundException e )
-        {
-            log( "Unable to find repository for id [" + id + "]" );
-            return null;
-        }
-        catch ( ArchivaDatabaseException e )
-        {
-            log( "Unable to find repository for id [" + id + "]: " + e.getMessage(), e );
-            return null;
-        }
+        return (RepositoryConfiguration) repositoryMap.get( request.getPrefix() );
     }
 
     public String getRepositoryName( DavServerRequest request )
     {
-        ArchivaRepository repoConfig = getRepository( request );
+        RepositoryConfiguration repoConfig = getRepository( request );
         if ( repoConfig == null )
         {
             return "Unknown";
         }
 
-        return repoConfig.getModel().getName();
+        return repoConfig.getName();
+    }
+
+    private void updateRepositoryMap()
+    {
+        RepositoryConfigurationToMapClosure repoMapClosure = new RepositoryConfigurationToMapClosure();
+        Closure localRepoMap = IfClosure.getInstance( LocalRepositoryPredicate.getInstance(), repoMapClosure );
+        CollectionUtils.forAllDo( configuration.getConfiguration().getRepositories(), localRepoMap );
+        
+        this.repositoryMap.clear();
+        this.repositoryMap.putAll( repoMapClosure.getMap() );
     }
 
     public boolean isAuthenticated( DavServerRequest davRequest, HttpServletResponse response )
@@ -260,6 +253,8 @@ public class RepositoryServlet
     {
         if ( ConfigurationNames.isRepositories( propertyName ) )
         {
+            updateRepositoryMap();
+
             getDavManager().removeAllServers();
 
             try
index 8d98808d48f1122cd9e43c87bca54ef1318b4bf5..3a9f2e71405cc07710712e4c404b56afeeb15939 100644 (file)
                     <table>
                       <tr>
                         <th>Last Indexed</th>
-                        <td>${repository.stats.whenStarted}</td>
+                        <td>${repository.stats.whenGathered}</td>
                       </tr>
                       <tr>
                         <th>Duration</th>