mirror of https://github.com/apache/archiva.git
[MRM-1056] Option to force scanning of an artifact/repository regardless of file dates
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
This commit is contained in:
parent
372aaae288
commit
185d83243c
|
@ -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 ) )
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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() );
|
||||
}
|
||||
|
||||
}
|
|
@ -313,7 +313,7 @@ public class AdministrationServiceImpl
|
|||
}
|
||||
}
|
||||
|
||||
RepositoryTask task = TaskCreator.createRepositoryTask( repoId, "", false );
|
||||
RepositoryTask task = TaskCreator.createRepositoryTask( repoId, "" );
|
||||
|
||||
taskScheduler.queueRepositoryTask( task );
|
||||
|
||||
|
|
Loading…
Reference in New Issue