Cleanup of scheduler dependencies

This commit is contained in:
Martin Stockhammer 2020-02-02 22:02:26 +01:00
parent b4377a03b9
commit 302363c1ec
14 changed files with 172 additions and 223 deletions

View File

@ -69,6 +69,11 @@
</dependency>
<!-- Test scope -->
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>repository-statistics</artifactId>
<version>${archiva.version}</version>
</dependency>
<dependency>
<groupId>org.apache.archiva.components.cache</groupId>
<artifactId>archiva-components-spring-cache-ehcache</artifactId>

View File

@ -93,6 +93,11 @@
</dependency>
<!-- Test scope -->
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>repository-statistics</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>

View File

@ -19,8 +19,8 @@ package org.apache.archiva.repository.scanner;
* under the License.
*/
import org.apache.archiva.admin.model.RepositoryAdminException;
import org.apache.archiva.configuration.FileTypes;
import org.apache.archiva.consumers.ConsumerException;
import org.apache.archiva.consumers.InvalidRepositoryContentConsumer;
import org.apache.archiva.consumers.KnownRepositoryContentConsumer;
import org.apache.archiva.consumers.RepositoryContentConsumer;
@ -70,10 +70,11 @@ public class DefaultRepositoryScanner
return scan( repository, knownContentConsumers, invalidContentConsumers, ignoredPatterns, changesSince );
}
catch ( RepositoryAdminException e )
catch ( ConsumerException e )
{
throw new RepositoryScannerException( e.getMessage(), e );
} finally
throw new RepositoryScannerException( e.getMessage( ), e );
}
finally
{
repositoryContentConsumers.releaseSelectedKnownConsumers( knownContentConsumers );
}

View File

@ -24,6 +24,7 @@ import org.apache.archiva.admin.model.admin.ArchivaAdministration;
import org.apache.archiva.common.utils.BaseFile;
import org.apache.archiva.common.utils.PathUtil;
import org.apache.archiva.configuration.ArchivaConfiguration;
import org.apache.archiva.consumers.ConsumerException;
import org.apache.archiva.consumers.InvalidRepositoryContentConsumer;
import org.apache.archiva.consumers.KnownRepositoryContentConsumer;
import org.apache.archiva.consumers.RepositoryContentConsumer;
@ -34,7 +35,6 @@ import org.apache.archiva.repository.scanner.functors.ConsumerProcessFileClosure
import org.apache.archiva.repository.scanner.functors.TriggerBeginScanClosure;
import org.apache.archiva.repository.scanner.functors.TriggerScanCompletedClosure;
import org.apache.commons.collections4.Closure;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.IterableUtils;
import org.apache.commons.collections4.functors.IfClosure;
import org.springframework.beans.BeansException;
@ -96,9 +96,16 @@ public class RepositoryContentConsumers
* @return the list of consumer ids that have been selected by the configuration.
*/
public List<String> getSelectedKnownConsumerIds()
throws RepositoryAdminException
throws ConsumerException
{
return archivaAdministration.getKnownContentConsumers();
try
{
return archivaAdministration.getKnownContentConsumers();
}
catch ( RepositoryAdminException e )
{
throw new ConsumerException( e.getMessage( ), e );
}
}
/**
@ -114,9 +121,16 @@ public class RepositoryContentConsumers
* @return the list of consumer ids that have been selected by the configuration.
*/
public List<String> getSelectedInvalidConsumerIds()
throws RepositoryAdminException
throws ConsumerException
{
return archivaAdministration.getInvalidContentConsumers();
try
{
return archivaAdministration.getInvalidContentConsumers();
}
catch ( RepositoryAdminException e )
{
throw new ConsumerException( e.getMessage( ), e );
}
}
/**
@ -126,7 +140,7 @@ public class RepositoryContentConsumers
* @return the map of String ids to {@link KnownRepositoryContentConsumer} objects.
*/
public Map<String, KnownRepositoryContentConsumer> getSelectedKnownConsumersMap()
throws RepositoryAdminException
throws ConsumerException
{
Map<String, KnownRepositoryContentConsumer> consumerMap = new HashMap<>();
@ -145,7 +159,7 @@ public class RepositoryContentConsumers
* @return the map of String ids to {@link InvalidRepositoryContentConsumer} objects.
*/
public Map<String, InvalidRepositoryContentConsumer> getSelectedInvalidConsumersMap()
throws RepositoryAdminException
throws ConsumerException
{
Map<String, InvalidRepositoryContentConsumer> consumerMap = new HashMap<>();
@ -165,7 +179,7 @@ public class RepositoryContentConsumers
* by the active configuration.
*/
public List<KnownRepositoryContentConsumer> getSelectedKnownConsumers()
throws RepositoryAdminException
throws ConsumerException
{
// FIXME only for testing
if ( selectedKnownConsumers != null )
@ -210,7 +224,7 @@ public class RepositoryContentConsumers
* by the active configuration.
*/
public synchronized List<InvalidRepositoryContentConsumer> getSelectedInvalidConsumers()
throws RepositoryAdminException
throws ConsumerException
{
// FIXME only for testing
@ -221,7 +235,15 @@ public class RepositoryContentConsumers
List<InvalidRepositoryContentConsumer> ret = new ArrayList<>();
List<String> invalidSelected = getSelectedInvalidConsumerIds();
List<String> invalidSelected = null;
try
{
invalidSelected = getSelectedInvalidConsumerIds();
}
catch ( ConsumerException e )
{
e.printStackTrace( );
}
for ( InvalidRepositoryContentConsumer consumer : getAvailableInvalidConsumers() )
{
@ -264,13 +286,12 @@ public class RepositoryContentConsumers
* NOTE: Make sure that there is no repository scanning task executing before invoking this so as to prevent
* the index writer/reader of the current index-content consumer executing from getting closed. For an example,
* see ArchivaDavResource#executeConsumers( File ).
*
* @param repository the repository configuration to use.
* @param repository the repository configuration to use.
* @param localFile the local file to execute the consumers against.
* @param updateRelatedArtifacts TODO
*/
public void executeConsumers( ManagedRepository repository, Path localFile, boolean updateRelatedArtifacts )
throws RepositoryAdminException
throws ConsumerException
{
List<KnownRepositoryContentConsumer> selectedKnownConsumers = null;
// Run the repository consumers

View File

@ -150,6 +150,11 @@
<!-- TEST Scope -->
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>repository-statistics</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>

View File

@ -32,10 +32,6 @@
</properties>
<dependencies>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-repository-admin-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.archiva.components</groupId>
<artifactId>archiva-components-spring-taskqueue</artifactId>

View File

@ -32,30 +32,37 @@
</properties>
<dependencies>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-scheduler-repository-api</artifactId>
</dependency>
<dependency>
<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>
</dependency>
<dependency>
<groupId>org.apache.archiva.components</groupId>
<artifactId>archiva-components-spring-quartz</artifactId>
</dependency>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<artifactId>archiva-storage-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>repository-statistics</artifactId>
<artifactId>archiva-storage-fs</artifactId>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-consumer-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-filelock</artifactId>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-proxy-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-model</artifactId>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
@ -65,36 +72,76 @@
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-repository-scanner</artifactId>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-repository-layer</artifactId>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging-api</artifactId>
</exclusion>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-common</artifactId>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-repository-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>metadata-repository-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>metadata-statistics-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.archiva.components</groupId>
<artifactId>archiva-components-spring-taskqueue</artifactId>
</dependency>
<dependency>
<groupId>org.apache.archiva.components</groupId>
<artifactId>archiva-components-spring-quartz</artifactId>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
</dependency>
<!-- Test scope -->
<dependency>
<groupId>org.apache.maven.indexer</groupId>
<artifactId>indexer-core</artifactId>
<classifier>shaded-lucene</classifier>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-repository-admin-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jcl</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.archiva.maven</groupId>
<artifactId>archiva-maven-common</artifactId>
<scope>test</scope>
</dependency>
<dependency>
@ -102,10 +149,30 @@
<artifactId>archiva-maven-repository</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-provider-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-http-shared</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.indexer</groupId>
<artifactId>indexer-core</artifactId>
<classifier>shaded-lucene</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-test-utils</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
@ -119,18 +186,6 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.archiva.components.cache</groupId>
<artifactId>archiva-components-spring-cache-ehcache</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>

View File

@ -19,8 +19,6 @@ package org.apache.archiva.scheduler.repository;
* under the License.
*/
import org.apache.archiva.admin.model.RepositoryAdminException;
import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
import org.apache.archiva.metadata.repository.MetadataRepository;
import org.apache.archiva.metadata.repository.MetadataRepositoryException;
import org.apache.archiva.metadata.repository.RepositorySession;
@ -60,9 +58,6 @@ public class ArchivaRepositoryScanningTaskExecutor
@Inject
RepositoryRegistry repositoryRegistry;
@Inject
private ManagedRepositoryAdmin managedRepositoryAdmin;
@Inject
private RepositoryScanner repoScanner;
@ -195,15 +190,14 @@ public class ArchivaRepositoryScanningTaskExecutor
this.task = null;
}
}
catch ( RepositoryAdminException e )
{
log.error( e.getMessage(), e );
throw new TaskExecutionException( e.getMessage(), e );
}
catch ( MetadataRepositoryException e )
{
e.printStackTrace( );
}
catch ( org.apache.archiva.consumers.ConsumerException e )
{
e.printStackTrace( );
}
}
public Task getCurrentTaskInExecution()
@ -251,13 +245,4 @@ public class ArchivaRepositoryScanningTaskExecutor
this.repositoryStatisticsManager = repositoryStatisticsManager;
}
public ManagedRepositoryAdmin getManagedRepositoryAdmin()
{
return managedRepositoryAdmin;
}
public void setManagedRepositoryAdmin( ManagedRepositoryAdmin managedRepositoryAdmin )
{
this.managedRepositoryAdmin = managedRepositoryAdmin;
}
}

View File

@ -1,124 +0,0 @@
package org.apache.archiva.mock;
/*
* 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.admin.model.AuditInformation;
import org.apache.archiva.admin.model.RepositoryAdminException;
import org.apache.archiva.admin.model.beans.ManagedRepository;
import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
import org.apache.archiva.configuration.ArchivaConfiguration;
import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
/**
* @author Olivier Lamy
*/
public class MockManagedRepositoryAdmin
implements ManagedRepositoryAdmin
{
private ArchivaConfiguration archivaConfiguration;
@Override
public List<ManagedRepository> getManagedRepositories()
throws RepositoryAdminException
{
List<ManagedRepositoryConfiguration> managedRepoConfigs =
getArchivaConfiguration().getConfiguration().getManagedRepositories();
List<ManagedRepository> managedRepos = new ArrayList<>( managedRepoConfigs.size() );
for ( ManagedRepositoryConfiguration repoConfig : managedRepoConfigs )
{
// TODO add staging repo information back too
ManagedRepository repo =
new ManagedRepository( Locale.getDefault( ), repoConfig.getId(), repoConfig.getName(), repoConfig.getLocation(),
repoConfig.getLayout(), repoConfig.isSnapshots(), repoConfig.isReleases(),
repoConfig.isBlockRedeployments(), repoConfig.getRefreshCronExpression(),
repoConfig.getIndexDir(), repoConfig.isScanned(), repoConfig.getRetentionPeriod(),
repoConfig.getRetentionCount(), repoConfig.isDeleteReleasedSnapshots(), true );
managedRepos.add( repo );
}
return managedRepos;
}
@Override
public Map<String, ManagedRepository> getManagedRepositoriesAsMap()
throws RepositoryAdminException
{
return null;
}
@Override
public ManagedRepository getManagedRepository( String repositoryId )
throws RepositoryAdminException
{
List<ManagedRepository> repos = getManagedRepositories();
for ( ManagedRepository repo : repos )
{
if ( StringUtils.equals( repo.getId(), repositoryId ) )
{
return repo;
}
}
return null;
}
@Override
public Boolean deleteManagedRepository( String repositoryId, AuditInformation auditInformation,
boolean deleteContent )
throws RepositoryAdminException
{
return null;
}
@Override
public Boolean addManagedRepository( ManagedRepository managedRepository, boolean needStageRepo,
AuditInformation auditInformation )
throws RepositoryAdminException
{
return null;
}
@Override
public Boolean updateManagedRepository( ManagedRepository managedRepository, boolean needStageRepo,
AuditInformation auditInformation, boolean resetStats )
throws RepositoryAdminException
{
return null;
}
public ArchivaConfiguration getArchivaConfiguration()
{
return archivaConfiguration;
}
public void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration )
{
this.archivaConfiguration = archivaConfiguration;
}
}

View File

@ -20,6 +20,7 @@ package org.apache.archiva.scheduler.repository;
*/
import junit.framework.TestCase;
import org.apache.archiva.common.utils.FileUtils;
import org.apache.archiva.configuration.ArchivaConfiguration;
import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.archiva.metadata.repository.MetadataRepository;
@ -30,7 +31,6 @@ import org.apache.archiva.repository.ManagedRepository;
import org.apache.archiva.repository.RepositoryRegistry;
import org.apache.archiva.scheduler.repository.model.RepositoryTask;
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
import org.codehaus.plexus.util.FileUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.runner.RunWith;
@ -101,12 +101,12 @@ public abstract class AbstractArchivaRepositoryScanningTaskExecutorTest
Path sourceRepoDir = Paths.get( "src/test/repositories/default-repository" );
repoDir = Paths.get( "target/default-repository" );
org.apache.archiva.common.utils.FileUtils.deleteDirectory( repoDir );
FileUtils.deleteDirectory( repoDir );
assertFalse( "Default Test Repository should not exist.", Files.exists(repoDir) );
Files.createDirectories(repoDir);
FileUtils.copyDirectoryStructure( sourceRepoDir.toFile(), repoDir.toFile() );
org.apache.commons.io.FileUtils.copyDirectory( sourceRepoDir.toFile(), repoDir.toFile() );
// set the timestamps to a time well in the past
Calendar cal = Calendar.getInstance();
cal.add( Calendar.YEAR, -1 );

View File

@ -24,7 +24,7 @@ import org.apache.archiva.metadata.repository.stats.model.DefaultRepositoryStati
import org.apache.archiva.metadata.repository.stats.model.RepositoryStatistics;
import org.apache.archiva.model.ArtifactReference;
import org.apache.archiva.scheduler.repository.model.RepositoryTask;
import org.codehaus.plexus.util.FileUtils;
import org.apache.commons.io.FileUtils;
import org.junit.Test;
import org.springframework.test.context.ContextConfiguration;
@ -78,7 +78,7 @@ public class ArchivaRepositoryScanningTaskExecutorPhase2Test
Path newArtifactGroup = repoDir.resolve( "org/apache/archiva" );
assertFalse( "newArtifactGroup should not exist.", Files.exists(newArtifactGroup) );
FileUtils.copyDirectoryStructure( Paths.get( "target/test-classes/test-repo/org/apache/archiva" ).toFile(),
FileUtils.copyDirectory( Paths.get( "target/test-classes/test-repo/org/apache/archiva" ).toFile(),
newArtifactGroup.toFile() );
// update last modified date
@ -123,7 +123,7 @@ public class ArchivaRepositoryScanningTaskExecutorPhase2Test
Path newArtifactGroup = repoDir.resolve( "org/apache/archiva" );
assertFalse( "newArtifactGroup should not exist.", Files.exists(newArtifactGroup) );
FileUtils.copyDirectoryStructure( Paths.get( "target/test-classes/test-repo/org/apache/archiva" ).toFile(),
FileUtils.copyDirectory( Paths.get( "target/test-classes/test-repo/org/apache/archiva" ).toFile(),
newArtifactGroup.toFile() );
// update last modified date, placing shortly after last scan
@ -170,7 +170,7 @@ public class ArchivaRepositoryScanningTaskExecutorPhase2Test
Path newArtifactGroup = repoDir.resolve( "org/apache/archiva" );
assertFalse( "newArtifactGroup should not exist.", Files.exists(newArtifactGroup) );
FileUtils.copyDirectoryStructure( Paths.get( "target/test-classes/test-repo/org/apache/archiva" ).toFile(),
FileUtils.copyDirectory( Paths.get( "target/test-classes/test-repo/org/apache/archiva" ).toFile(),
newArtifactGroup.toFile() );
// update last modified date, placing in middle of last scan

View File

@ -29,9 +29,6 @@
<context:annotation-config/>
<bean name="managedRepoAdmin#test" class="org.apache.archiva.mock.MockManagedRepositoryAdmin">
<property name="archivaConfiguration" ref="archivaConfiguration#test-repository-scanning"/>
</bean>
<bean name="archivaAdministration#mock" class="org.apache.archiva.mock.MockArchivaAdministration">
<property name="archivaConfiguration" ref="archivaConfiguration#test-repository-scanning"/>
@ -42,7 +39,6 @@
</bean>
<bean name="taskExecutor#test-repository-scanning" class="org.apache.archiva.scheduler.repository.ArchivaRepositoryScanningTaskExecutor">
<property name="managedRepositoryAdmin" ref="managedRepoAdmin#test"/>
</bean>
<bean name="repositoryContentFactory#default" class="org.apache.archiva.repository.RepositoryContentFactory">

View File

@ -20,6 +20,7 @@ package org.apache.archiva.webdav;
*/
import org.apache.archiva.admin.model.admin.ArchivaAdministration;
import org.apache.archiva.consumers.ConsumerException;
import org.apache.archiva.consumers.InvalidRepositoryContentConsumer;
import org.apache.archiva.consumers.KnownRepositoryContentConsumer;
import org.apache.archiva.repository.scanner.RepositoryContentConsumers;
@ -35,13 +36,13 @@ public class StubRepositoryContentConsumers
}
@Override
public List<KnownRepositoryContentConsumer> getSelectedKnownConsumers()
public List<KnownRepositoryContentConsumer> getSelectedKnownConsumers() throws ConsumerException
{
return getAvailableKnownConsumers();
}
@Override
public synchronized List<InvalidRepositoryContentConsumer> getSelectedInvalidConsumers()
public synchronized List<InvalidRepositoryContentConsumer> getSelectedInvalidConsumers() throws ConsumerException
{
return getAvailableInvalidConsumers();
}

View File

@ -29,6 +29,9 @@ archiva-modules
archiva-repository-admin
archiva-repository-admin-api
archiva-repository-admin-default
archiva-scheduler
archiva-scheduler-api
archiva-scheduler-repository