]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1056] Option to force scanning of an artifact/repository regardless of file...
authorMaria Odea B. Ching <oching@apache.org>
Fri, 18 Sep 2009 08:58:50 +0000 (08:58 +0000)
committerMaria Odea B. Ching <oching@apache.org>
Fri, 18 Sep 2009 08:58:50 +0000 (08:58 +0000)
o added new method for creating task with scanAll flag
o added unit tests for creating tasks with different configs

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@816545 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/DefaultArchivaTaskScheduler.java
archiva-modules/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/RepositoryTaskJob.java
archiva-modules/archiva-scheduled/src/main/java/org/apache/maven/archiva/scheduled/tasks/TaskCreator.java
archiva-modules/archiva-scheduled/src/test/java/org/apache/maven/archiva/scheduled/tasks/TaskCreatorTest.java [new file with mode: 0644]
archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java

index 5f713197d512bfc7c52051da8d7c49cdf3eee29f..de956ef8ccc31b8747d68542d80791111f3328e1 100644 (file)
@@ -428,7 +428,7 @@ public class DefaultArchivaTaskScheduler
     private synchronized void queueInitialRepoScan( ManagedRepositoryConfiguration repoConfig )
     {
         String repoId = repoConfig.getId();        
-        RepositoryTask task = TaskCreator.createRepositoryTask( repoId, "initial-scan", true );
+        RepositoryTask task = TaskCreator.createRepositoryTask( repoId, "initial-scan" );
 
         if ( queuedRepos.contains( repoId ) )
         {
index cb9e183bb43a43cc4fa98adf30e822b21691830f..9088847df23424b7b7a40e4805e915600b09aa92 100644 (file)
@@ -59,7 +59,7 @@ public class RepositoryTaskJob
         TaskQueue taskQueue = (TaskQueue) dataMap.get( TASK_QUEUE );
         String queuePolicy = dataMap.get( TASK_QUEUE_POLICY ).toString();
 
-        RepositoryTask task = TaskCreator.createRepositoryTask( (String) dataMap.get( TASK_REPOSITORY ), "", true );
+        RepositoryTask task = TaskCreator.createRepositoryTask( (String) dataMap.get( TASK_REPOSITORY ), "" );
         task.setName( context.getJobDetail().getName() );
 
         try
index f7bcc5df13f6985d8599c0b2c3a189c729a4ecca..32ea4620f91ce2f8dc74c416a2de0b8af26ea409 100644 (file)
@@ -31,7 +31,7 @@ import org.apache.maven.archiva.scheduled.DefaultArchivaTaskScheduler;
  */
 public class TaskCreator
 {
-    public static RepositoryTask createRepositoryTask( String repositoryId, String taskNameSuffix, boolean scanAll )
+    public static RepositoryTask createRepositoryTask( String repositoryId, String taskNameSuffix )
     {
         String suffix = "";
         if( !StringUtils.isEmpty( taskNameSuffix ) )
@@ -43,18 +43,34 @@ public class TaskCreator
         task.setRepositoryId( repositoryId );
         task.setName( DefaultArchivaTaskScheduler.REPOSITORY_JOB + ":" + repositoryId + suffix );
         task.setQueuePolicy( ArchivaTask.QUEUE_POLICY_WAIT );
+                
+        return task;
+    }
+    
+    public static RepositoryTask createRepositoryTask( String repositoryId, String taskNameSuffix, boolean scanAll )
+    {
+        RepositoryTask task = createRepositoryTask( repositoryId, taskNameSuffix );
         task.setScanAll( scanAll );
         
         return task;
     }
         
     public static RepositoryTask createRepositoryTask( String repositoryId, String taskNameSuffix, File resourceFile,
-                                                       boolean updateRelatedArtifacts, boolean scanAll )
+                                                       boolean updateRelatedArtifacts )
     {
-        RepositoryTask task = createRepositoryTask( repositoryId, taskNameSuffix, scanAll );
+        RepositoryTask task = createRepositoryTask( repositoryId, taskNameSuffix );
         task.setResourceFile( resourceFile );
         task.setUpdateRelatedArtifacts( updateRelatedArtifacts );
-
+        
+        return task;
+    }
+    
+    public static RepositoryTask createRepositoryTask( String repositoryId, String taskNameSuffix, File resourceFile,
+                                                       boolean updateRelatedArtifacts, boolean scanAll )
+    {
+        RepositoryTask task = createRepositoryTask( repositoryId, taskNameSuffix, resourceFile, updateRelatedArtifacts );
+        task.setScanAll( scanAll );
+        
         return task;
     }
     
diff --git a/archiva-modules/archiva-scheduled/src/test/java/org/apache/maven/archiva/scheduled/tasks/TaskCreatorTest.java b/archiva-modules/archiva-scheduled/src/test/java/org/apache/maven/archiva/scheduled/tasks/TaskCreatorTest.java
new file mode 100644 (file)
index 0000000..271221a
--- /dev/null
@@ -0,0 +1,115 @@
+package org.apache.maven.archiva.scheduled.tasks;
+
+/*
+ * 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 java.io.File;
+
+import org.apache.maven.archiva.scheduled.DefaultArchivaTaskScheduler;
+import org.codehaus.plexus.spring.PlexusInSpringTestCase;
+
+public class TaskCreatorTest
+    extends PlexusInSpringTestCase
+{
+    private static final String REPO_ID = "test-repo";
+
+    private static final String TASKNAME_SUFFIX = "test-task";
+
+    public void testCreateRepositoryTask()
+        throws Exception
+    {
+        RepositoryTask task = TaskCreator.createRepositoryTask( REPO_ID, "" );
+
+        assertEquals( "Incorrect repository id set.", REPO_ID, task.getRepositoryId() );
+        assertEquals( "Incorrect queue policy set.", ArchivaTask.QUEUE_POLICY_WAIT, task.getQueuePolicy() );
+        assertEquals( "Incorrect task name set.", DefaultArchivaTaskScheduler.REPOSITORY_JOB + ":" + REPO_ID,
+                      task.getName() );
+    }
+
+    public void testCreateRepositoryTaskWithTaskNameSuffix()
+        throws Exception
+    {
+        RepositoryTask task = TaskCreator.createRepositoryTask( REPO_ID, TASKNAME_SUFFIX );
+
+        assertBasicTaskDetails( task );
+    }
+
+    public void testCreateRepositoryTaskScanAllArtifacts()
+        throws Exception
+    {
+        RepositoryTask task = TaskCreator.createRepositoryTask( REPO_ID, TASKNAME_SUFFIX, true );
+
+        assertBasicTaskDetails( task );
+        assertTrue( task.scanAll );
+    }
+
+    public void testCreateRepositoryTaskDoNotScanAllArtifacts()
+        throws Exception
+    {
+        RepositoryTask task = TaskCreator.createRepositoryTask( REPO_ID, TASKNAME_SUFFIX, false );
+
+        assertBasicTaskDetails( task );
+        assertFalse( task.scanAll );
+    }
+
+    public void testCreateRepositoryTaskForArtifactUpdateAllRelated()
+        throws Exception
+    {
+        File resource = new File( getBasedir(), "target/test-classes/test.jar" );
+        RepositoryTask task = TaskCreator.createRepositoryTask( REPO_ID, TASKNAME_SUFFIX, resource, true );
+
+        assertBasicTaskDetails( task );
+        assertEquals( "Incorrect resource file set.", resource, task.getResourceFile() );
+        assertTrue( task.updateRelatedArtifacts );
+    }
+
+    public void testCreateRepositoryTaskForArtifactDoNotUpdateAllRelated()
+        throws Exception
+    {
+        File resource = new File( getBasedir(), "target/test-classes/test.jar" );
+        RepositoryTask task = TaskCreator.createRepositoryTask( REPO_ID, TASKNAME_SUFFIX, resource, false );
+
+        assertBasicTaskDetails( task );
+        assertEquals( "Incorrect resource file set.", resource, task.getResourceFile() );
+        assertFalse( task.updateRelatedArtifacts );
+    }
+
+    public void testCreateIndexingTask()
+        throws Exception
+    {
+        File resource = new File( getBasedir(), "target/test-classes/test.jar" );
+        ArtifactIndexingTask task = TaskCreator.createIndexingTask( REPO_ID, resource, ArtifactIndexingTask.ADD );
+
+        assertEquals( "Incorrect repository id set.", REPO_ID, task.getRepositoryId() );
+        assertEquals( "Incorrect queue policy set.", ArchivaTask.QUEUE_POLICY_WAIT, task.getQueuePolicy() );
+        assertEquals( "Incorrect task name set.", DefaultArchivaTaskScheduler.INDEXING_JOB + ":" + REPO_ID + ":" +
+            resource.getName() + ":" + ArtifactIndexingTask.ADD, task.getName() );
+        assertEquals( "Incorrect action set.", ArtifactIndexingTask.ADD, task.getAction() );
+        assertEquals( "Incorrect resource file set.", resource, task.getResourceFile() );
+    }
+
+    private void assertBasicTaskDetails( RepositoryTask task )
+    {
+        assertEquals( "Incorrect repository id set.", REPO_ID, task.getRepositoryId() );
+        assertEquals( "Incorrect task name set.", DefaultArchivaTaskScheduler.REPOSITORY_JOB + ":" + REPO_ID + ":" +
+            TASKNAME_SUFFIX, task.getName() );
+        assertEquals( "Incorrect queue policy set.", ArchivaTask.QUEUE_POLICY_WAIT, task.getQueuePolicy() );
+    }
+
+}
index 3279c79c787182f7b0118b31d62395072a1207e3..623b324752ebf6dc9fccff96c950f0f3956a5634 100644 (file)
@@ -313,7 +313,7 @@ public class AdministrationServiceImpl
             }
         }
 
-        RepositoryTask task = TaskCreator.createRepositoryTask( repoId, "", false );
+        RepositoryTask task = TaskCreator.createRepositoryTask( repoId, "" );
 
         taskScheduler.queueRepositoryTask( task );