]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1704] Refactor to remove maven specific part from various repository/metadata...
authorOlivier Lamy <olamy@apache.org>
Mon, 29 Oct 2012 20:58:54 +0000 (20:58 +0000)
committerOlivier Lamy <olamy@apache.org>
Mon, 29 Oct 2012 20:58:54 +0000 (20:58 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1403504 13f79535-47bb-0310-9956-ffa450edef68

13 files changed:
archiva-modules/archiva-base/archiva-proxy/pom.xml
archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/pom.xml
archiva-modules/archiva-base/archiva-repository-layer/src/main/resources/META-INF/spring-context.xml
archiva-modules/archiva-scheduler/archiva-scheduler-repository/pom.xml
archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/java/org/apache/archiva/scheduler/repository/DefaultRepositoryArchivaTaskScheduler.java [new file with mode: 0644]
archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/java/org/apache/archiva/scheduler/repository/RepositoryArchivaTaskScheduler.java [deleted file]
archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/java/org/apache/archiva/scheduler/repository/RepositoryTask.java [deleted file]
archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/java/org/apache/archiva/scheduler/repository/RepositoryTaskJob.java
archiva-modules/archiva-scheduler/pom.xml
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/AbstractRestService.java
archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/startup/ArchivaStartup.java
archiva-modules/plugins/maven2-repository/src/main/resources/META-INF/spring-context.xml
pom.xml

index 16a9948a57d47f2990ddf5116b49d846f44b8f73..56714b70cbd316a18fa6636451309e2fa433d08f 100644 (file)
       <groupId>org.apache.archiva</groupId>
       <artifactId>archiva-scheduler-api</artifactId>
     </dependency>
-    <dependency>
-      <groupId>org.apache.archiva</groupId>
-      <artifactId>archiva-scheduler-repository</artifactId>
-    </dependency>
     <dependency>
       <groupId>org.apache.archiva</groupId>
       <artifactId>archiva-repository-layer</artifactId>
       <groupId>org.apache.archiva</groupId>
       <artifactId>archiva-repository-scanner</artifactId>
     </dependency>
-    <!--dependency>
+    <dependency>
       <groupId>org.apache.archiva</groupId>
-      <artifactId>archiva-scheduler-repository</artifactId>
-    </dependency-->
+      <artifactId>archiva-scheduler-repository-api</artifactId>
+    </dependency>
     <dependency>
       <groupId>org.apache.archiva</groupId>
       <artifactId>archiva-proxy-common</artifactId>
index 4088371a512ba0bbf1dceaeef4de3d2de73043f4..2d72d1a1424ce0d74e783f6b6c94b0e1e1cf7eef 100644 (file)
       <groupId>org.apache.archiva</groupId>
       <artifactId>archiva-security-common</artifactId>
     </dependency>
-     <dependency>
+    <dependency>
       <groupId>org.apache.archiva</groupId>
-      <artifactId>archiva-scheduler-repository</artifactId>
+      <artifactId>archiva-scheduler-repository-api</artifactId>
     </dependency>
     <dependency>
       <groupId>org.apache.archiva</groupId>
       <artifactId>archiva-repository-admin-api</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.apache.archiva</groupId>
+      <artifactId>repository-statistics</artifactId>
+    </dependency>
     <dependency>
       <groupId>org.apache.archiva</groupId>
       <artifactId>archiva-plexus-bridge</artifactId>
       <groupId>javax.inject</groupId>
       <artifactId>javax.inject</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.apache.archiva.redback.components</groupId>
+      <artifactId>spring-taskqueue</artifactId>
+    </dependency>
     <dependency>
       <groupId>net.sf.beanlib</groupId>
       <artifactId>beanlib</artifactId>
index c49f9edb41347b9d573906a01a8c905a6f060493..ec802252d75bf19085ad535ee93697ca15635a25 100644 (file)
   <context:annotation-config/>
   <context:component-scan base-package="org.apache.archiva.repository"/>
 
-  <bean name="pathParser#legacy" class="org.apache.archiva.repository.content.LegacyPathParser">
-    <constructor-arg>
-      <ref bean="archivaConfiguration#default"/>
-    </constructor-arg>
-  </bean>
-
 </beans>
\ No newline at end of file
index fb3b736643a0d869f70fe18d0fc15adc0f3b8459..5bb2b77efbd4f91d218471952da016afc7fccdd6 100644 (file)
       <groupId>org.apache.archiva</groupId>
       <artifactId>archiva-scheduler-api</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.apache.archiva</groupId>
+      <artifactId>archiva-scheduler-repository-api</artifactId>
+      <version>${project.version}</version>
+    </dependency>
     <dependency>
       <groupId>commons-io</groupId>
       <artifactId>commons-io</artifactId>
diff --git a/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/java/org/apache/archiva/scheduler/repository/DefaultRepositoryArchivaTaskScheduler.java b/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/java/org/apache/archiva/scheduler/repository/DefaultRepositoryArchivaTaskScheduler.java
new file mode 100644 (file)
index 0000000..90a28a3
--- /dev/null
@@ -0,0 +1,380 @@
+package org.apache.archiva.scheduler.repository;
+
+/*
+ * 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.archiva.common.ArchivaException;
+import org.apache.archiva.configuration.ArchivaConfiguration;
+import org.apache.archiva.configuration.ConfigurationEvent;
+import org.apache.archiva.configuration.ConfigurationListener;
+import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
+import org.apache.archiva.metadata.repository.MetadataRepository;
+import org.apache.archiva.metadata.repository.MetadataRepositoryException;
+import org.apache.archiva.metadata.repository.RepositorySession;
+import org.apache.archiva.metadata.repository.RepositorySessionFactory;
+import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager;
+import org.apache.archiva.redback.components.scheduler.CronExpressionValidator;
+import org.apache.archiva.redback.components.scheduler.Scheduler;
+import org.apache.archiva.redback.components.taskqueue.TaskQueue;
+import org.apache.archiva.redback.components.taskqueue.TaskQueueException;
+import org.apache.archiva.scheduler.ArchivaTaskScheduler;
+import org.quartz.SchedulerException;
+import org.quartz.impl.JobDetailImpl;
+import org.quartz.impl.triggers.CronTriggerImpl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import javax.inject.Named;
+import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Default implementation of a scheduling component for archiva.
+ */
+@Service ("archivaTaskScheduler#repository")
+public class DefaultRepositoryArchivaTaskScheduler
+    implements RepositoryArchivaTaskScheduler, ConfigurationListener
+{
+    private Logger log = LoggerFactory.getLogger( getClass() );
+
+    /**
+     *
+     */
+    @Inject
+    private Scheduler scheduler;
+
+    @Inject
+    private CronExpressionValidator cronValidator;
+
+    /**
+     *
+     */
+    @Inject
+    @Named (value = "taskQueue#repository-scanning")
+    private TaskQueue repositoryScanningQueue;
+
+    /**
+     *
+     */
+    @Inject
+    private ArchivaConfiguration archivaConfiguration;
+
+    /**
+     *
+     */
+    @Inject
+    @Named (value = "repositoryStatisticsManager#default")
+    private RepositoryStatisticsManager repositoryStatisticsManager;
+
+    /**
+     * TODO: could have multiple implementations
+     */
+    @Inject
+    private RepositorySessionFactory repositorySessionFactory;
+
+    private static final String REPOSITORY_SCAN_GROUP = "rg";
+
+    private static final String REPOSITORY_JOB = "rj";
+
+    private static final String REPOSITORY_JOB_TRIGGER = "rjt";
+
+    static final String TASK_QUEUE = "TASK_QUEUE";
+
+    static final String TASK_REPOSITORY = "TASK_REPOSITORY";
+
+    public static final String CRON_HOURLY = "0 0 * * * ?";
+
+    private Set<String> jobs = new HashSet<String>();
+
+    private List<String> queuedRepos = new ArrayList<String>();
+
+    @PostConstruct
+    public void startup()
+        throws ArchivaException
+    {
+        archivaConfiguration.addListener( this );
+
+        List<ManagedRepositoryConfiguration> repositories =
+            archivaConfiguration.getConfiguration().getManagedRepositories();
+
+        RepositorySession repositorySession = repositorySessionFactory.createSession();
+        try
+        {
+            MetadataRepository metadataRepository = repositorySession.getRepository();
+            for ( ManagedRepositoryConfiguration repoConfig : repositories )
+            {
+                if ( repoConfig.isScanned() )
+                {
+                    try
+                    {
+                        scheduleRepositoryJobs( repoConfig );
+                    }
+                    catch ( SchedulerException e )
+                    {
+                        throw new ArchivaException( "Unable to start scheduler: " + e.getMessage(), e );
+                    }
+
+                    try
+                    {
+                        if ( !isPreviouslyScanned( repoConfig, metadataRepository ) )
+                        {
+                            queueInitialRepoScan( repoConfig );
+                        }
+                    }
+                    catch ( MetadataRepositoryException e )
+                    {
+                        log.warn( "Unable to determine if a repository is already scanned, skipping initial scan: "
+                                      + e.getMessage(), e );
+                    }
+                }
+            }
+        }
+        finally
+        {
+            repositorySession.close();
+        }
+
+    }
+
+
+    @PreDestroy
+    public void stop()
+        throws SchedulerException
+    {
+        for ( String job : jobs )
+        {
+            scheduler.unscheduleJob( job, REPOSITORY_SCAN_GROUP );
+        }
+        jobs.clear();
+        queuedRepos.clear();
+
+    }
+
+    @SuppressWarnings ("unchecked")
+    public boolean isProcessingRepositoryTask( String repositoryId )
+    {
+        synchronized ( repositoryScanningQueue )
+        {
+            List<RepositoryTask> queue = null;
+
+            try
+            {
+                queue = repositoryScanningQueue.getQueueSnapshot();
+            }
+            catch ( TaskQueueException e )
+            {
+                // not possible with plexus-taskqueue implementation, ignore
+            }
+
+            for ( RepositoryTask queuedTask : queue )
+            {
+                if ( queuedTask.getRepositoryId().equals( repositoryId ) )
+                {
+                    return true;
+                }
+            }
+            return false;
+        }
+    }
+
+    public boolean isProcessingRepositoryTask( RepositoryTask task )
+    {
+        synchronized ( repositoryScanningQueue )
+        {
+            List<RepositoryTask> queue = null;
+
+            try
+            {
+                queue = repositoryScanningQueue.getQueueSnapshot();
+            }
+            catch ( TaskQueueException e )
+            {
+                // not possible with plexus-taskqueue implementation, ignore
+            }
+
+            for ( RepositoryTask queuedTask : queue )
+            {
+                if ( task.equals( queuedTask ) )
+                {
+                    return true;
+                }
+            }
+            return false;
+        }
+    }
+
+    public void queueTask( RepositoryTask task )
+        throws TaskQueueException
+    {
+        synchronized ( repositoryScanningQueue )
+        {
+            if ( isProcessingRepositoryTask( task ) )
+            {
+                log.debug( "Repository task '{}' is already queued. Skipping task.", task );
+            }
+            else
+            {
+                // add check if the task is already queued if it is a file scan
+                repositoryScanningQueue.put( task );
+            }
+        }
+    }
+
+    public boolean unQueueTask( RepositoryTask task )
+        throws TaskQueueException
+    {
+        synchronized ( repositoryScanningQueue )
+        {
+            if ( !isProcessingRepositoryTask( task ) )
+            {
+                log.info( "cannot unqueue Repository task '{}' not already queued.", task );
+                return false;
+            }
+            else
+            {
+                return repositoryScanningQueue.remove( task );
+            }
+        }
+    }
+
+    public void configurationEvent( ConfigurationEvent event )
+    {
+        if ( event.getType() == ConfigurationEvent.SAVED )
+        {
+            for ( String job : jobs )
+            {
+                try
+                {
+                    scheduler.unscheduleJob( job, REPOSITORY_SCAN_GROUP );
+                }
+                catch ( SchedulerException e )
+                {
+                    log.error( "Error restarting the repository scanning job after property change." );
+                }
+            }
+            jobs.clear();
+
+            List<ManagedRepositoryConfiguration> repositories =
+                archivaConfiguration.getConfiguration().getManagedRepositories();
+
+            for ( ManagedRepositoryConfiguration repoConfig : repositories )
+            {
+                if ( repoConfig.getRefreshCronExpression() != null )
+                {
+                    try
+                    {
+                        scheduleRepositoryJobs( repoConfig );
+                    }
+                    catch ( SchedulerException e )
+                    {
+                        log.error( "error restarting job: " + REPOSITORY_JOB + ":" + repoConfig.getId() );
+                    }
+                }
+            }
+        }
+    }
+
+    @SuppressWarnings ("unchecked")
+    private boolean isPreviouslyScanned( ManagedRepositoryConfiguration repoConfig,
+                                         MetadataRepository metadataRepository )
+        throws MetadataRepositoryException
+    {
+        return repositoryStatisticsManager.getLastStatistics( metadataRepository, repoConfig.getId() ) != null;
+    }
+
+    // MRM-848: Pre-configured repository initially appear to be empty
+    private synchronized void queueInitialRepoScan( ManagedRepositoryConfiguration repoConfig )
+    {
+        String repoId = repoConfig.getId();
+        RepositoryTask task = new RepositoryTask();
+        task.setRepositoryId( repoId );
+
+        if ( !queuedRepos.contains( repoId ) )
+        {
+            log.info( "Repository [" + repoId + "] is queued to be scanned as it hasn't been previously." );
+
+            try
+            {
+                queuedRepos.add( repoConfig.getId() );
+                this.queueTask( task );
+            }
+            catch ( TaskQueueException e )
+            {
+                log.error( "Error occurred while queueing repository [" + repoId + "] task : " + e.getMessage() );
+            }
+        }
+    }
+
+    private synchronized void scheduleRepositoryJobs( ManagedRepositoryConfiguration repoConfig )
+        throws SchedulerException
+    {
+        if ( repoConfig.getRefreshCronExpression() == null )
+        {
+            log.warn( "Skipping job, no cron expression for {}", repoConfig.getId() );
+            return;
+        }
+
+        if ( !repoConfig.isScanned() )
+        {
+            log.warn( "Skipping job, repository scannable has been disabled for {}", repoConfig.getId() );
+            return;
+        }
+
+        // get the cron string for these database scanning jobs
+        String cronString = repoConfig.getRefreshCronExpression();
+
+        if ( !cronValidator.validate( cronString ) )
+        {
+            log.warn( "Cron expression [{}] for repository [{}] is invalid.  Defaulting to hourly.", cronString,
+                      repoConfig.getId() );
+            cronString = CRON_HOURLY;
+        }
+
+        // setup the unprocessed artifact job
+        JobDetailImpl repositoryJob =
+            new JobDetailImpl( REPOSITORY_JOB + ":" + repoConfig.getId(), REPOSITORY_SCAN_GROUP,
+                               RepositoryTaskJob.class );
+
+        repositoryJob.getJobDataMap().put( TASK_QUEUE, repositoryScanningQueue );
+        repositoryJob.getJobDataMap().put( TASK_REPOSITORY, repoConfig.getId() );
+
+        try
+        {
+            CronTriggerImpl trigger =
+                new CronTriggerImpl( REPOSITORY_JOB_TRIGGER + ":" + repoConfig.getId(), REPOSITORY_SCAN_GROUP,
+                                     cronString );
+
+            jobs.add( REPOSITORY_JOB + ":" + repoConfig.getId() );
+            scheduler.scheduleJob( repositoryJob, trigger );
+        }
+        catch ( ParseException e )
+        {
+            log.error( "ParseException in repository scanning cron expression, disabling repository scanning for '"
+                           + repoConfig.getId() + "': " + e.getMessage() );
+        }
+
+    }
+}
diff --git a/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/java/org/apache/archiva/scheduler/repository/RepositoryArchivaTaskScheduler.java b/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/java/org/apache/archiva/scheduler/repository/RepositoryArchivaTaskScheduler.java
deleted file mode 100644 (file)
index 65894ac..0000000
+++ /dev/null
@@ -1,381 +0,0 @@
-package org.apache.archiva.scheduler.repository;
-
-/*
- * 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.archiva.common.ArchivaException;
-import org.apache.archiva.configuration.ArchivaConfiguration;
-import org.apache.archiva.configuration.ConfigurationEvent;
-import org.apache.archiva.configuration.ConfigurationListener;
-import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
-import org.apache.archiva.metadata.repository.MetadataRepository;
-import org.apache.archiva.metadata.repository.MetadataRepositoryException;
-import org.apache.archiva.metadata.repository.RepositorySession;
-import org.apache.archiva.metadata.repository.RepositorySessionFactory;
-import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager;
-import org.apache.archiva.redback.components.scheduler.CronExpressionValidator;
-import org.apache.archiva.redback.components.scheduler.Scheduler;
-import org.apache.archiva.redback.components.taskqueue.TaskQueue;
-import org.apache.archiva.redback.components.taskqueue.TaskQueueException;
-import org.apache.archiva.scheduler.ArchivaTaskScheduler;
-import org.quartz.SchedulerException;
-import org.quartz.impl.JobDetailImpl;
-import org.quartz.impl.triggers.CronTriggerImpl;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.stereotype.Service;
-
-import javax.annotation.PostConstruct;
-import javax.annotation.PreDestroy;
-import javax.inject.Inject;
-import javax.inject.Named;
-import java.text.ParseException;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-/**
- * Default implementation of a scheduling component for archiva.
- */
-@Service ("archivaTaskScheduler#repository")
-public class RepositoryArchivaTaskScheduler
-    implements ArchivaTaskScheduler<RepositoryTask>, ConfigurationListener
-{
-    private Logger log = LoggerFactory.getLogger( RepositoryArchivaTaskScheduler.class );
-
-    /**
-     *
-     */
-    @Inject
-    private Scheduler scheduler;
-
-    @Inject
-    private CronExpressionValidator cronValidator;
-
-    /**
-     *
-     */
-    @Inject
-    @Named (value = "taskQueue#repository-scanning")
-    private TaskQueue repositoryScanningQueue;
-
-    /**
-     *
-     */
-    @Inject
-    private ArchivaConfiguration archivaConfiguration;
-
-    /**
-     *
-     */
-    @Inject
-    @Named (value = "repositoryStatisticsManager#default")
-    private RepositoryStatisticsManager repositoryStatisticsManager;
-
-    /**
-     * TODO: could have multiple implementations
-     */
-    @Inject
-    private RepositorySessionFactory repositorySessionFactory;
-
-    private static final String REPOSITORY_SCAN_GROUP = "rg";
-
-    private static final String REPOSITORY_JOB = "rj";
-
-    private static final String REPOSITORY_JOB_TRIGGER = "rjt";
-
-    static final String TASK_QUEUE = "TASK_QUEUE";
-
-    static final String TASK_REPOSITORY = "TASK_REPOSITORY";
-
-    public static final String CRON_HOURLY = "0 0 * * * ?";
-
-    private Set<String> jobs = new HashSet<String>();
-
-    private List<String> queuedRepos = new ArrayList<String>();
-
-    @PostConstruct
-    public void startup()
-        throws ArchivaException
-    {
-        archivaConfiguration.addListener( this );
-
-        List<ManagedRepositoryConfiguration> repositories =
-            archivaConfiguration.getConfiguration().getManagedRepositories();
-
-        RepositorySession repositorySession = repositorySessionFactory.createSession();
-        try
-        {
-            MetadataRepository metadataRepository = repositorySession.getRepository();
-            for ( ManagedRepositoryConfiguration repoConfig : repositories )
-            {
-                if ( repoConfig.isScanned() )
-                {
-                    try
-                    {
-                        scheduleRepositoryJobs( repoConfig );
-                    }
-                    catch ( SchedulerException e )
-                    {
-                        throw new ArchivaException( "Unable to start scheduler: " + e.getMessage(), e );
-                    }
-
-                    try
-                    {
-                        if ( !isPreviouslyScanned( repoConfig, metadataRepository ) )
-                        {
-                            queueInitialRepoScan( repoConfig );
-                        }
-                    }
-                    catch ( MetadataRepositoryException e )
-                    {
-                        log.warn( "Unable to determine if a repository is already scanned, skipping initial scan: "
-                                      + e.getMessage(), e );
-                    }
-                }
-            }
-        }
-        finally
-        {
-            repositorySession.close();
-        }
-
-    }
-
-
-    @PreDestroy
-    public void stop()
-        throws SchedulerException
-    {
-        for ( String job : jobs )
-        {
-            scheduler.unscheduleJob( job, REPOSITORY_SCAN_GROUP );
-        }
-        jobs.clear();
-        queuedRepos.clear();
-
-    }
-
-    @SuppressWarnings ("unchecked")
-    public boolean isProcessingRepositoryTask( String repositoryId )
-    {
-        synchronized ( repositoryScanningQueue )
-        {
-            List<RepositoryTask> queue = null;
-
-            try
-            {
-                queue = repositoryScanningQueue.getQueueSnapshot();
-            }
-            catch ( TaskQueueException e )
-            {
-                // not possible with plexus-taskqueue implementation, ignore
-            }
-
-            for ( RepositoryTask queuedTask : queue )
-            {
-                if ( queuedTask.getRepositoryId().equals( repositoryId ) )
-                {
-                    return true;
-                }
-            }
-            return false;
-        }
-    }
-
-    @SuppressWarnings ("unchecked")
-    private boolean isProcessingRepositoryTask( RepositoryTask task )
-    {
-        synchronized ( repositoryScanningQueue )
-        {
-            List<RepositoryTask> queue = null;
-
-            try
-            {
-                queue = repositoryScanningQueue.getQueueSnapshot();
-            }
-            catch ( TaskQueueException e )
-            {
-                // not possible with plexus-taskqueue implementation, ignore
-            }
-
-            for ( RepositoryTask queuedTask : queue )
-            {
-                if ( task.equals( queuedTask ) )
-                {
-                    return true;
-                }
-            }
-            return false;
-        }
-    }
-
-    public void queueTask( RepositoryTask task )
-        throws TaskQueueException
-    {
-        synchronized ( repositoryScanningQueue )
-        {
-            if ( isProcessingRepositoryTask( task ) )
-            {
-                log.debug( "Repository task '{}' is already queued. Skipping task.", task );
-            }
-            else
-            {
-                // add check if the task is already queued if it is a file scan
-                repositoryScanningQueue.put( task );
-            }
-        }
-    }
-
-    public boolean unQueueTask( RepositoryTask task )
-        throws TaskQueueException
-    {
-        synchronized ( repositoryScanningQueue )
-        {
-            if ( !isProcessingRepositoryTask( task ) )
-            {
-                log.info( "cannot unqueue Repository task '{}' not already queued.", task );
-                return false;
-            }
-            else
-            {
-                return repositoryScanningQueue.remove( task );
-            }
-        }
-    }
-
-    public void configurationEvent( ConfigurationEvent event )
-    {
-        if ( event.getType() == ConfigurationEvent.SAVED )
-        {
-            for ( String job : jobs )
-            {
-                try
-                {
-                    scheduler.unscheduleJob( job, REPOSITORY_SCAN_GROUP );
-                }
-                catch ( SchedulerException e )
-                {
-                    log.error( "Error restarting the repository scanning job after property change." );
-                }
-            }
-            jobs.clear();
-
-            List<ManagedRepositoryConfiguration> repositories =
-                archivaConfiguration.getConfiguration().getManagedRepositories();
-
-            for ( ManagedRepositoryConfiguration repoConfig : repositories )
-            {
-                if ( repoConfig.getRefreshCronExpression() != null )
-                {
-                    try
-                    {
-                        scheduleRepositoryJobs( repoConfig );
-                    }
-                    catch ( SchedulerException e )
-                    {
-                        log.error( "error restarting job: " + REPOSITORY_JOB + ":" + repoConfig.getId() );
-                    }
-                }
-            }
-        }
-    }
-
-    @SuppressWarnings ("unchecked")
-    private boolean isPreviouslyScanned( ManagedRepositoryConfiguration repoConfig,
-                                         MetadataRepository metadataRepository )
-        throws MetadataRepositoryException
-    {
-        return repositoryStatisticsManager.getLastStatistics( metadataRepository, repoConfig.getId() ) != null;
-    }
-
-    // MRM-848: Pre-configured repository initially appear to be empty
-    private synchronized void queueInitialRepoScan( ManagedRepositoryConfiguration repoConfig )
-    {
-        String repoId = repoConfig.getId();
-        RepositoryTask task = new RepositoryTask();
-        task.setRepositoryId( repoId );
-
-        if ( !queuedRepos.contains( repoId ) )
-        {
-            log.info( "Repository [" + repoId + "] is queued to be scanned as it hasn't been previously." );
-
-            try
-            {
-                queuedRepos.add( repoConfig.getId() );
-                this.queueTask( task );
-            }
-            catch ( TaskQueueException e )
-            {
-                log.error( "Error occurred while queueing repository [" + repoId + "] task : " + e.getMessage() );
-            }
-        }
-    }
-
-    private synchronized void scheduleRepositoryJobs( ManagedRepositoryConfiguration repoConfig )
-        throws SchedulerException
-    {
-        if ( repoConfig.getRefreshCronExpression() == null )
-        {
-            log.warn( "Skipping job, no cron expression for {}", repoConfig.getId() );
-            return;
-        }
-
-        if ( !repoConfig.isScanned() )
-        {
-            log.warn( "Skipping job, repository scannable has been disabled for {}", repoConfig.getId() );
-            return;
-        }
-
-        // get the cron string for these database scanning jobs
-        String cronString = repoConfig.getRefreshCronExpression();
-
-        if ( !cronValidator.validate( cronString ) )
-        {
-            log.warn( "Cron expression [{}] for repository [{}] is invalid.  Defaulting to hourly.", cronString,
-                      repoConfig.getId() );
-            cronString = CRON_HOURLY;
-        }
-
-        // setup the unprocessed artifact job
-        JobDetailImpl repositoryJob =
-            new JobDetailImpl( REPOSITORY_JOB + ":" + repoConfig.getId(), REPOSITORY_SCAN_GROUP,
-                               RepositoryTaskJob.class );
-
-        repositoryJob.getJobDataMap().put( TASK_QUEUE, repositoryScanningQueue );
-        repositoryJob.getJobDataMap().put( TASK_REPOSITORY, repoConfig.getId() );
-
-        try
-        {
-            CronTriggerImpl trigger =
-                new CronTriggerImpl( REPOSITORY_JOB_TRIGGER + ":" + repoConfig.getId(), REPOSITORY_SCAN_GROUP,
-                                     cronString );
-
-            jobs.add( REPOSITORY_JOB + ":" + repoConfig.getId() );
-            scheduler.scheduleJob( repositoryJob, trigger );
-        }
-        catch ( ParseException e )
-        {
-            log.error( "ParseException in repository scanning cron expression, disabling repository scanning for '"
-                           + repoConfig.getId() + "': " + e.getMessage() );
-        }
-
-    }
-}
diff --git a/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/java/org/apache/archiva/scheduler/repository/RepositoryTask.java b/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/main/java/org/apache/archiva/scheduler/repository/RepositoryTask.java
deleted file mode 100644 (file)
index b023cdd..0000000
+++ /dev/null
@@ -1,145 +0,0 @@
-package org.apache.archiva.scheduler.repository;
-
-import org.apache.archiva.redback.components.taskqueue.Task;
-
-import java.io.File;
-
-/*
- * 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.
- */
-
-/**
- * DataRefreshTask - task for discovering changes in the repository
- * and updating all associated data.
- *
- *
- */
-public class RepositoryTask
-    implements Task
-{
-    private String repositoryId;
-
-    private File resourceFile;
-
-    private boolean updateRelatedArtifacts;
-
-    private boolean scanAll;
-
-    public boolean isScanAll()
-    {
-        return scanAll;
-    }
-
-    public void setScanAll( boolean scanAll )
-    {
-        this.scanAll = scanAll;
-    }
-
-    public String getRepositoryId()
-    {
-        return repositoryId;
-    }
-
-    public void setRepositoryId( String repositoryId )
-    {
-        this.repositoryId = repositoryId;
-    }
-
-    public long getMaxExecutionTime()
-    {
-        return 0;
-    }
-
-    public File getResourceFile()
-    {
-        return resourceFile;
-    }
-
-    public void setResourceFile( File resourceFile )
-    {
-        this.resourceFile = resourceFile;
-    }
-
-    public boolean isUpdateRelatedArtifacts()
-    {
-        return updateRelatedArtifacts;
-    }
-
-    public void setUpdateRelatedArtifacts( boolean updateRelatedArtifacts )
-    {
-        this.updateRelatedArtifacts = updateRelatedArtifacts;
-    }
-
-    @Override
-    public String toString()
-    {
-        return "RepositoryTask [repositoryId=" + repositoryId + ", resourceFile=" + resourceFile + ", scanAll="
-            + scanAll + ", updateRelatedArtifacts=" + updateRelatedArtifacts + "]";
-    }
-
-    @Override
-    public int hashCode()
-    {
-        final int prime = 31;
-        int result = 1;
-        result = prime * result + ( ( repositoryId == null ) ? 0 : repositoryId.hashCode() );
-        result = prime * result + ( ( resourceFile == null ) ? 0 : resourceFile.hashCode() );
-        return result;
-    }
-
-    @Override
-    public boolean equals( Object obj )
-    {
-        if ( this == obj )
-        {
-            return true;
-        }
-        if ( obj == null )
-        {
-            return false;
-        }
-        if ( getClass() != obj.getClass() )
-        {
-            return false;
-        }
-        RepositoryTask other = (RepositoryTask) obj;
-        if ( repositoryId == null )
-        {
-            if ( other.repositoryId != null )
-            {
-                return false;
-            }
-        }
-        else if ( !repositoryId.equals( other.repositoryId ) )
-        {
-            return false;
-        }
-        if ( resourceFile == null )
-        {
-            if ( other.resourceFile != null )
-            {
-                return false;
-            }
-        }
-        else if ( !resourceFile.equals( other.resourceFile ) )
-        {
-            return false;
-        }
-        return true;
-    }
-}
index eea487d72c801fcb5bba774164459f9a2fec17d2..6789459b9329ca7f6422d3ca32e8be4a9fde9038 100644 (file)
@@ -44,9 +44,9 @@ public class RepositoryTaskJob
         JobDataMap dataMap = context.getJobDetail().getJobDataMap();
         setJobDataMap( dataMap );
 
-        TaskQueue taskQueue = (TaskQueue) dataMap.get( RepositoryArchivaTaskScheduler.TASK_QUEUE );
+        TaskQueue taskQueue = (TaskQueue) dataMap.get( DefaultRepositoryArchivaTaskScheduler.TASK_QUEUE );
 
-        String repositoryId = (String) dataMap.get( RepositoryArchivaTaskScheduler.TASK_REPOSITORY );
+        String repositoryId = (String) dataMap.get( DefaultRepositoryArchivaTaskScheduler.TASK_REPOSITORY );
         RepositoryTask task = new RepositoryTask();
         task.setRepositoryId( repositoryId );
 
index 4e215012a966d50e6749c031d1567df3372802b1..df0fe72890c46a0252b32291d10f86f1d47ddce8 100644 (file)
@@ -31,6 +31,7 @@
   <modules>
     <module>archiva-scheduler-api</module>
     <module>archiva-scheduler-indexing</module>
+    <module>archiva-scheduler-repository-api</module>
     <module>archiva-scheduler-repository</module>
   </modules>
 </project>
index 9a7ce13e2ec96fe7488da213a91c0ff7d7349aba..7d527361857435ac70e5b7656cc0c2fcb5785826 100644 (file)
@@ -38,7 +38,7 @@ import org.apache.archiva.repository.RepositoryContentFactory;
 import org.apache.archiva.repository.RepositoryException;
 import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
 import org.apache.archiva.rest.services.utils.ArtifactBuilder;
-import org.apache.archiva.scheduler.repository.RepositoryArchivaTaskScheduler;
+import org.apache.archiva.scheduler.repository.DefaultRepositoryArchivaTaskScheduler;
 import org.apache.archiva.scheduler.repository.RepositoryTask;
 import org.apache.archiva.security.AccessDeniedException;
 import org.apache.archiva.security.ArchivaSecurityException;
@@ -93,7 +93,7 @@ public abstract class AbstractRestService
 
     @Inject
     @Named ( value = "archivaTaskScheduler#repository" )
-    protected RepositoryArchivaTaskScheduler repositoryTaskScheduler;
+    protected DefaultRepositoryArchivaTaskScheduler repositoryTaskScheduler;
 
     @Context
     protected HttpServletRequest httpServletRequest;
index f35e7b76829d3feff74429a1443176a6c1b11bab..3d4a444eee3067a116a478747802fa87eca89795 100644 (file)
@@ -23,7 +23,7 @@ import org.apache.archiva.common.ArchivaException;
 import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
 import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException;
 import org.apache.archiva.redback.components.scheduler.DefaultScheduler;
-import org.apache.archiva.scheduler.repository.RepositoryArchivaTaskScheduler;
+import org.apache.archiva.scheduler.repository.DefaultRepositoryArchivaTaskScheduler;
 import org.apache.maven.index.NexusIndexer;
 import org.apache.maven.index.context.IndexingContext;
 import org.apache.archiva.redback.components.taskqueue.Task;
@@ -52,7 +52,7 @@ public class ArchivaStartup
 
     private ThreadedTaskQueueExecutor tqeIndexing;
 
-    private RepositoryArchivaTaskScheduler repositoryTaskScheduler;
+    private DefaultRepositoryArchivaTaskScheduler repositoryTaskScheduler;
 
     private PlexusSisuBridge plexusSisuBridge;
 
@@ -66,7 +66,7 @@ public class ArchivaStartup
         SecuritySynchronization securitySync = wac.getBean( SecuritySynchronization.class );
 
         repositoryTaskScheduler =
-            wac.getBean( "archivaTaskScheduler#repository", RepositoryArchivaTaskScheduler.class );
+            wac.getBean( "archivaTaskScheduler#repository", DefaultRepositoryArchivaTaskScheduler.class );
 
         Properties archivaRuntimeProperties = wac.getBean( "archivaRuntimeProperties", Properties.class );
 
index 1eb4daf9d3dec30703f1d6325c0ac420a24e1781..47125c353ff81e1aef6d33256da9b24d3e374989 100644 (file)
   <context:component-scan base-package="org.apache.archiva.dependency.tree.maven2,org.apache.archiva.metadata.repository.storage.maven2,
                                         org.apache.archiva.repository.content.maven2,org.apache.archiva.repository.content.legacy"/>
 
+
+  <bean name="pathParser#legacy" class="org.apache.archiva.repository.content.LegacyPathParser">
+    <constructor-arg>
+      <ref bean="archivaConfiguration#default"/>
+    </constructor-arg>
+  </bean>
+
 </beans>
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 659d191d28bad2a4d22a0be22acbe2dbdeeab252..c129639ef29e234cf04d183c33f5bd784d22ac52 100644 (file)
--- a/pom.xml
+++ b/pom.xml
         <artifactId>archiva-scheduler-api</artifactId>
         <version>${project.version}</version>
       </dependency>
+      <dependency>
+        <groupId>org.apache.archiva</groupId>
+        <artifactId>archiva-scheduler-repository-api</artifactId>
+        <version>${project.version}</version>
+      </dependency>
       <dependency>
         <groupId>org.apache.archiva</groupId>
         <artifactId>archiva-scheduler-repository</artifactId>