finish unit test for getMergeConflictedArtifacts rest method

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1387384 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2012-09-18 22:00:57 +00:00
parent cfb78daaaa
commit 2103f2d60f
16 changed files with 217 additions and 131 deletions

View File

@ -27,7 +27,8 @@ import java.util.List;
/** /**
* A consumer of content (files) in the repository. * A consumer of content (files) in the repository.
* *
* * olamy: TODO/FIXME we must review this api, in the current situation we use prototype beans rather than singletons
* this is a bit memory consuming the better will be to ConsumerContext bean to transport repository context etc...
*/ */
public interface RepositoryContentConsumer public interface RepositoryContentConsumer
extends Consumer extends Consumer

View File

@ -51,7 +51,7 @@ public class ManagedRepository
*/ */
private ManagedRepository stagingRepository; private ManagedRepository stagingRepository;
private boolean scanned = false; private boolean scanned = true;
/** /**

View File

@ -220,8 +220,8 @@ public class DefaultManagedRepositoryAdmin
managedRepository.getCronExpression(), managedRepository.getIndexDirectory(), managedRepository.getCronExpression(), managedRepository.getIndexDirectory(),
managedRepository.getDaysOlder(), managedRepository.getRetentionCount(), managedRepository.getDaysOlder(), managedRepository.getRetentionCount(),
managedRepository.isDeleteReleasedSnapshots(), managedRepository.getDescription(), managedRepository.isDeleteReleasedSnapshots(), managedRepository.getDescription(),
managedRepository.isSkipPackedIndexCreation(), auditInformation, managedRepository.isSkipPackedIndexCreation(), managedRepository.isScanned(),
getArchivaConfiguration().getConfiguration() ) != null; auditInformation, getArchivaConfiguration().getConfiguration() ) != null;
createIndexContext( managedRepository ); createIndexContext( managedRepository );
return res; return res;
@ -234,7 +234,7 @@ public class DefaultManagedRepositoryAdmin
boolean stageRepoNeeded, String cronExpression, boolean stageRepoNeeded, String cronExpression,
String indexDir, int daysOlder, int retentionCount, String indexDir, int daysOlder, int retentionCount,
boolean deteleReleasedSnapshots, String description, boolean deteleReleasedSnapshots, String description,
boolean skipPackedIndexCreation, boolean skipPackedIndexCreation, boolean scanned,
AuditInformation auditInformation, AuditInformation auditInformation,
Configuration config ) Configuration config )
throws RepositoryAdminException throws RepositoryAdminException
@ -246,6 +246,7 @@ public class DefaultManagedRepositoryAdmin
repository.setBlockRedeployments( blockRedeployments ); repository.setBlockRedeployments( blockRedeployments );
repository.setReleases( releasesIncluded ); repository.setReleases( releasesIncluded );
repository.setSnapshots( snapshotsIncluded ); repository.setSnapshots( snapshotsIncluded );
repository.setScanned( scanned );
repository.setName( name ); repository.setName( name );
repository.setLocation( getRepositoryCommonValidator().removeExpressions( location ) ); repository.setLocation( getRepositoryCommonValidator().removeExpressions( location ) );
repository.setLayout( layout ); repository.setLayout( layout );
@ -286,14 +287,17 @@ public class DefaultManagedRepositoryAdmin
//scan repository when adding of repository is successful //scan repository when adding of repository is successful
try try
{ {
scanRepository( repoId, true ); if ( scanned )
// olamy no need of scanning staged repo {
/* scanRepository( repoId, true );
if ( stageRepoNeeded ) }
// TODO need a better to define scanning or not for staged repo
if ( stageRepoNeeded && scanned )
{ {
ManagedRepositoryConfiguration stagingRepository = getStageRepoConfig( repository ); ManagedRepositoryConfiguration stagingRepository = getStageRepoConfig( repository );
scanRepository( stagingRepository.getId(), true ); scanRepository( stagingRepository.getId(), true );
}*/ }
} }
catch ( Exception e ) catch ( Exception e )
{ {
@ -486,8 +490,8 @@ public class DefaultManagedRepositoryAdmin
managedRepository.getCronExpression(), managedRepository.getIndexDirectory(), managedRepository.getCronExpression(), managedRepository.getIndexDirectory(),
managedRepository.getDaysOlder(), managedRepository.getRetentionCount(), managedRepository.getDaysOlder(), managedRepository.getRetentionCount(),
managedRepository.isDeleteReleasedSnapshots(), managedRepository.getDescription(), managedRepository.isDeleteReleasedSnapshots(), managedRepository.getDescription(),
managedRepository.isSkipPackedIndexCreation(), auditInformation, managedRepository.isSkipPackedIndexCreation(), managedRepository.isScanned(),
getArchivaConfiguration().getConfiguration() ); auditInformation, getArchivaConfiguration().getConfiguration() );
// Save the repository configuration. // Save the repository configuration.
RepositorySession repositorySession = getRepositorySessionFactory().createSession(); RepositorySession repositorySession = getRepositorySessionFactory().createSession();
@ -631,10 +635,24 @@ public class DefaultManagedRepositoryAdmin
stagingRepository.setBlockRedeployments( repository.isBlockRedeployments() ); stagingRepository.setBlockRedeployments( repository.isBlockRedeployments() );
stagingRepository.setDaysOlder( repository.getDaysOlder() ); stagingRepository.setDaysOlder( repository.getDaysOlder() );
stagingRepository.setDeleteReleasedSnapshots( repository.isDeleteReleasedSnapshots() ); stagingRepository.setDeleteReleasedSnapshots( repository.isDeleteReleasedSnapshots() );
stagingRepository.setIndexDir( repository.getIndexDir() );
String path = repository.getLocation(); String path = repository.getLocation();
int lastIndex = path.replace( '\\', '/' ).lastIndexOf( '/' ); int lastIndex = path.replace( '\\', '/' ).lastIndexOf( '/' );
stagingRepository.setLocation( path.substring( 0, lastIndex ) + "/" + stagingRepository.getId() ); stagingRepository.setLocation( path.substring( 0, lastIndex ) + "/" + stagingRepository.getId() );
if ( StringUtils.isNotBlank( repository.getIndexDir() ) )
{
File indexDir = new File( repository.getIndexDir() );
// in case of absolute dir do not use the same
if ( indexDir.isAbsolute() )
{
stagingRepository.setIndexDir( stagingRepository.getLocation() + "/.index" );
}
else
{
stagingRepository.setIndexDir( repository.getIndexDir() );
}
}
stagingRepository.setRefreshCronExpression( repository.getRefreshCronExpression() ); stagingRepository.setRefreshCronExpression( repository.getRefreshCronExpression() );
stagingRepository.setReleases( repository.isReleases() ); stagingRepository.setReleases( repository.isReleases() );
stagingRepository.setRetentionCount( repository.getRetentionCount() ); stagingRepository.setRetentionCount( repository.getRetentionCount() );

View File

@ -22,16 +22,16 @@ package org.apache.archiva.repository.scanner;
import org.apache.archiva.admin.model.RepositoryAdminException; import org.apache.archiva.admin.model.RepositoryAdminException;
import org.apache.archiva.admin.model.admin.ArchivaAdministration; import org.apache.archiva.admin.model.admin.ArchivaAdministration;
import org.apache.archiva.admin.model.beans.ManagedRepository; import org.apache.archiva.admin.model.beans.ManagedRepository;
import org.apache.archiva.common.utils.BaseFile;
import org.apache.archiva.consumers.InvalidRepositoryContentConsumer;
import org.apache.archiva.consumers.KnownRepositoryContentConsumer;
import org.apache.archiva.consumers.functors.ConsumerWantsFilePredicate;
import org.apache.archiva.repository.scanner.functors.ConsumerProcessFileClosure; import org.apache.archiva.repository.scanner.functors.ConsumerProcessFileClosure;
import org.apache.archiva.repository.scanner.functors.TriggerBeginScanClosure; import org.apache.archiva.repository.scanner.functors.TriggerBeginScanClosure;
import org.apache.archiva.repository.scanner.functors.TriggerScanCompletedClosure; import org.apache.archiva.repository.scanner.functors.TriggerScanCompletedClosure;
import org.apache.commons.collections.Closure; import org.apache.commons.collections.Closure;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.functors.IfClosure; import org.apache.commons.collections.functors.IfClosure;
import org.apache.archiva.common.utils.BaseFile;
import org.apache.archiva.consumers.InvalidRepositoryContentConsumer;
import org.apache.archiva.consumers.KnownRepositoryContentConsumer;
import org.apache.archiva.consumers.functors.ConsumerWantsFilePredicate;
import org.springframework.beans.BeansException; import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware; import org.springframework.context.ApplicationContextAware;
@ -47,10 +47,8 @@ import java.util.Map;
/** /**
* RepositoryContentConsumerUtil * RepositoryContentConsumerUtil
*
*
*/ */
@Service("repositoryContentConsumers") @Service ("repositoryContentConsumers")
public class RepositoryContentConsumers public class RepositoryContentConsumers
implements ApplicationContextAware implements ApplicationContextAware
{ {
@ -163,22 +161,23 @@ public class RepositoryContentConsumers
public synchronized List<KnownRepositoryContentConsumer> getSelectedKnownConsumers() public synchronized List<KnownRepositoryContentConsumer> getSelectedKnownConsumers()
throws RepositoryAdminException throws RepositoryAdminException
{ {
if ( selectedKnownConsumers == null ) // FIXME only for testing
if ( selectedKnownConsumers != null )
{ {
List<KnownRepositoryContentConsumer> ret = new ArrayList<KnownRepositoryContentConsumer>(); return selectedKnownConsumers;
List<String> knownSelected = getSelectedKnownConsumerIds();
for ( KnownRepositoryContentConsumer consumer : getAvailableKnownConsumers() )
{
if ( knownSelected.contains( consumer.getId() ) || consumer.isPermanent() )
{
ret.add( consumer );
}
}
this.selectedKnownConsumers = ret;
} }
return selectedKnownConsumers; List<KnownRepositoryContentConsumer> ret = new ArrayList<KnownRepositoryContentConsumer>();
List<String> knownSelected = getSelectedKnownConsumerIds();
for ( KnownRepositoryContentConsumer consumer : getAvailableKnownConsumers() )
{
if ( knownSelected.contains( consumer.getId() ) || consumer.isPermanent() )
{
ret.add( consumer );
}
}
return ret;
} }
/** /**
@ -191,24 +190,28 @@ public class RepositoryContentConsumers
public synchronized List<InvalidRepositoryContentConsumer> getSelectedInvalidConsumers() public synchronized List<InvalidRepositoryContentConsumer> getSelectedInvalidConsumers()
throws RepositoryAdminException throws RepositoryAdminException
{ {
if ( selectedInvalidConsumers == null )
// FIXME only for testing
if ( selectedInvalidConsumers != null )
{ {
List<InvalidRepositoryContentConsumer> ret = new ArrayList<InvalidRepositoryContentConsumer>(); return selectedInvalidConsumers;
List<String> invalidSelected = getSelectedInvalidConsumerIds();
for ( InvalidRepositoryContentConsumer consumer : getAvailableInvalidConsumers() )
{
if ( invalidSelected.contains( consumer.getId() ) || consumer.isPermanent() )
{
ret.add( consumer );
}
}
selectedInvalidConsumers = ret;
} }
return selectedInvalidConsumers;
List<InvalidRepositoryContentConsumer> ret = new ArrayList<InvalidRepositoryContentConsumer>();
List<String> invalidSelected = getSelectedInvalidConsumerIds();
for ( InvalidRepositoryContentConsumer consumer : getAvailableInvalidConsumers() )
{
if ( invalidSelected.contains( consumer.getId() ) || consumer.isPermanent() )
{
ret.add( consumer );
}
}
return ret;
} }
/** /**
* Get the list of {@link KnownRepositoryContentConsumer} objects that are * Get the list of {@link KnownRepositoryContentConsumer} objects that are
* available and present in the classpath and as components in the IoC. * available and present in the classpath and as components in the IoC.

View File

@ -19,21 +19,21 @@ package org.apache.archiva.scheduler.repository;
* under the License. * under the License.
*/ */
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.Scheduler;
import org.apache.archiva.scheduler.ArchivaTaskScheduler;
import org.apache.archiva.common.ArchivaException; import org.apache.archiva.common.ArchivaException;
import org.apache.archiva.configuration.ArchivaConfiguration; import org.apache.archiva.configuration.ArchivaConfiguration;
import org.apache.archiva.configuration.ConfigurationEvent; import org.apache.archiva.configuration.ConfigurationEvent;
import org.apache.archiva.configuration.ConfigurationListener; import org.apache.archiva.configuration.ConfigurationListener;
import org.apache.archiva.configuration.ManagedRepositoryConfiguration; 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.TaskQueue;
import org.apache.archiva.redback.components.taskqueue.TaskQueueException; import org.apache.archiva.redback.components.taskqueue.TaskQueueException;
import org.apache.archiva.redback.components.scheduler.CronExpressionValidator; import org.apache.archiva.scheduler.ArchivaTaskScheduler;
import org.quartz.SchedulerException; import org.quartz.SchedulerException;
import org.quartz.impl.JobDetailImpl; import org.quartz.impl.JobDetailImpl;
import org.quartz.impl.triggers.CronTriggerImpl; import org.quartz.impl.triggers.CronTriggerImpl;
@ -54,7 +54,7 @@ import java.util.Set;
/** /**
* Default implementation of a scheduling component for archiva. * Default implementation of a scheduling component for archiva.
*/ */
@Service( "archivaTaskScheduler#repository" ) @Service ("archivaTaskScheduler#repository")
public class RepositoryArchivaTaskScheduler public class RepositoryArchivaTaskScheduler
implements ArchivaTaskScheduler<RepositoryTask>, ConfigurationListener implements ArchivaTaskScheduler<RepositoryTask>, ConfigurationListener
{ {
@ -73,7 +73,7 @@ public class RepositoryArchivaTaskScheduler
* *
*/ */
@Inject @Inject
@Named( value = "taskQueue#repository-scanning" ) @Named (value = "taskQueue#repository-scanning")
private TaskQueue repositoryScanningQueue; private TaskQueue repositoryScanningQueue;
/** /**
@ -86,12 +86,11 @@ public class RepositoryArchivaTaskScheduler
* *
*/ */
@Inject @Inject
@Named( value = "repositoryStatisticsManager#default" ) @Named (value = "repositoryStatisticsManager#default")
private RepositoryStatisticsManager repositoryStatisticsManager; private RepositoryStatisticsManager repositoryStatisticsManager;
/** /**
* TODO: could have multiple implementations * TODO: could have multiple implementations
*
*/ */
@Inject @Inject
private RepositorySessionFactory repositorySessionFactory; private RepositorySessionFactory repositorySessionFactory;
@ -174,7 +173,7 @@ public class RepositoryArchivaTaskScheduler
} }
@SuppressWarnings( "unchecked" ) @SuppressWarnings ("unchecked")
public boolean isProcessingRepositoryTask( String repositoryId ) public boolean isProcessingRepositoryTask( String repositoryId )
{ {
synchronized ( repositoryScanningQueue ) synchronized ( repositoryScanningQueue )
@ -201,7 +200,7 @@ public class RepositoryArchivaTaskScheduler
} }
} }
@SuppressWarnings( "unchecked" ) @SuppressWarnings ("unchecked")
private boolean isProcessingRepositoryTask( RepositoryTask task ) private boolean isProcessingRepositoryTask( RepositoryTask task )
{ {
synchronized ( repositoryScanningQueue ) synchronized ( repositoryScanningQueue )
@ -261,6 +260,7 @@ public class RepositoryArchivaTaskScheduler
} }
} }
} }
public void configurationEvent( ConfigurationEvent event ) public void configurationEvent( ConfigurationEvent event )
{ {
if ( event.getType() == ConfigurationEvent.SAVED ) if ( event.getType() == ConfigurationEvent.SAVED )
@ -298,7 +298,7 @@ public class RepositoryArchivaTaskScheduler
} }
} }
@SuppressWarnings( "unchecked" ) @SuppressWarnings ("unchecked")
private boolean isPreviouslyScanned( ManagedRepositoryConfiguration repoConfig, private boolean isPreviouslyScanned( ManagedRepositoryConfiguration repoConfig,
MetadataRepository metadataRepository ) MetadataRepository metadataRepository )
throws MetadataRepositoryException throws MetadataRepositoryException
@ -334,13 +334,13 @@ public class RepositoryArchivaTaskScheduler
{ {
if ( repoConfig.getRefreshCronExpression() == null ) if ( repoConfig.getRefreshCronExpression() == null )
{ {
log.warn( "Skipping job, no cron expression for " + repoConfig.getId() ); log.warn( "Skipping job, no cron expression for {}", repoConfig.getId() );
return; return;
} }
if ( !repoConfig.isScanned() ) if ( !repoConfig.isScanned() )
{ {
log.warn( "Skipping job, repository scannable has been disabled for " + repoConfig.getId() ); log.warn( "Skipping job, repository scannable has been disabled for {}", repoConfig.getId() );
return; return;
} }
@ -349,14 +349,15 @@ public class RepositoryArchivaTaskScheduler
if ( !cronValidator.validate( cronString ) ) if ( !cronValidator.validate( cronString ) )
{ {
log.warn( "Cron expression [" + cronString + "] for repository [" + repoConfig.getId() log.warn( "Cron expression [{}] for repository [{}] is invalid. Defaulting to hourly.", cronString,
+ "] is invalid. Defaulting to hourly." ); repoConfig.getId() );
cronString = CRON_HOURLY; cronString = CRON_HOURLY;
} }
// setup the unprocessed artifact job // setup the unprocessed artifact job
JobDetailImpl repositoryJob = JobDetailImpl repositoryJob =
new JobDetailImpl( REPOSITORY_JOB + ":" + repoConfig.getId(), REPOSITORY_SCAN_GROUP, RepositoryTaskJob.class ); new JobDetailImpl( REPOSITORY_JOB + ":" + repoConfig.getId(), REPOSITORY_SCAN_GROUP,
RepositoryTaskJob.class );
repositoryJob.getJobDataMap().put( TASK_QUEUE, repositoryScanningQueue ); repositoryJob.getJobDataMap().put( TASK_QUEUE, repositoryScanningQueue );
repositoryJob.getJobDataMap().put( TASK_REPOSITORY, repoConfig.getId() ); repositoryJob.getJobDataMap().put( TASK_REPOSITORY, repoConfig.getId() );
@ -364,7 +365,8 @@ public class RepositoryArchivaTaskScheduler
try try
{ {
CronTriggerImpl trigger = CronTriggerImpl trigger =
new CronTriggerImpl( REPOSITORY_JOB_TRIGGER + ":" + repoConfig.getId(), REPOSITORY_SCAN_GROUP, cronString ); new CronTriggerImpl( REPOSITORY_JOB_TRIGGER + ":" + repoConfig.getId(), REPOSITORY_SCAN_GROUP,
cronString );
jobs.add( REPOSITORY_JOB + ":" + repoConfig.getId() ); jobs.add( REPOSITORY_JOB + ":" + repoConfig.getId() );
scheduler.scheduleJob( repositoryJob, trigger ); scheduler.scheduleJob( repositoryJob, trigger );

View File

@ -18,7 +18,7 @@ package org.apache.archiva.rest.api.services;
* under the License. * under the License.
*/ */
import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.maven2.model.Artifact;
import org.apache.archiva.redback.authorization.RedbackAuthorization; import org.apache.archiva.redback.authorization.RedbackAuthorization;
import javax.ws.rs.GET; import javax.ws.rs.GET;
@ -45,6 +45,6 @@ public interface MergeRepositoriesService
* <b>permissions are checked in impl</b> * <b>permissions are checked in impl</b>
* @since 1.4-M3 * @since 1.4-M3
*/ */
List<ArtifactMetadata> getMergeConflictedArtifacts( @PathParam ( "repositoryId" ) String repositoryId ) List<Artifact> getMergeConflictedArtifacts( @PathParam ( "repositoryId" ) String repositoryId )
throws ArchivaRestServiceException; throws ArchivaRestServiceException;
} }

View File

@ -396,6 +396,11 @@
<version>${tomcat7Version}</version> <version>${tomcat7Version}</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-metadata-consumer</artifactId>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
@ -408,10 +413,9 @@
<configuration> <configuration>
<excludes> <excludes>
<exclude>src/test/repo-with-osgi/**</exclude> <exclude>src/test/repo-with-osgi/**</exclude>
<exclude>src/test/repo-with-osgi-stage/**</exclude>
<exclude>src/test/repo-with-classifier-only/**</exclude> <exclude>src/test/repo-with-classifier-only/**</exclude>
<exclude>src/test/repo-with-snapshots/**</exclude> <exclude>src/test/repo-with-snapshots/**</exclude>
<exclude>src/test/resources/target-repo/**</exclude>
<exclude>src/test/resources/test-repository-stage/**</exclude>
</excludes> </excludes>
</configuration> </configuration>
</plugin> </plugin>
@ -443,30 +447,13 @@
<redback.jdbc.url>${redbackTestJdbcUrl}</redback.jdbc.url> <redback.jdbc.url>${redbackTestJdbcUrl}</redback.jdbc.url>
<redback.jdbc.driver.name>${redbackTestJdbcDriver}</redback.jdbc.driver.name> <redback.jdbc.driver.name>${redbackTestJdbcDriver}</redback.jdbc.driver.name>
<basedir>${basedir}</basedir> <basedir>${basedir}</basedir>
<builddir>${project.build.directory}</builddir>
<org.apache.jackrabbit.maxCacheMemory>1</org.apache.jackrabbit.maxCacheMemory> <org.apache.jackrabbit.maxCacheMemory>1</org.apache.jackrabbit.maxCacheMemory>
<org.apache.jackrabbit.maxMemoryPerCache>1</org.apache.jackrabbit.maxMemoryPerCache> <org.apache.jackrabbit.maxMemoryPerCache>1</org.apache.jackrabbit.maxMemoryPerCache>
<!--org.apache.jackrabbit.minMemoryPerCache>1</org.apache.jackrabbit.minMemoryPerCache--> <!--org.apache.jackrabbit.minMemoryPerCache>1</org.apache.jackrabbit.minMemoryPerCache-->
</systemPropertyVariables> </systemPropertyVariables>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>test-repository</id>
<phase>generate-test-resources</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<includeArtifactIds>test-repository</includeArtifactIds>
<outputDirectory>target/test-repository</outputDirectory>
<excludes>META-INF/**</excludes>
</configuration>
</execution>
</executions>
</plugin>
</plugins> </plugins>
</build> </build>

View File

@ -26,13 +26,17 @@ import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
import org.apache.archiva.audit.AuditEvent; import org.apache.archiva.audit.AuditEvent;
import org.apache.archiva.audit.AuditListener; import org.apache.archiva.audit.AuditListener;
import org.apache.archiva.common.utils.VersionUtil; import org.apache.archiva.common.utils.VersionUtil;
import org.apache.archiva.maven2.model.Artifact;
import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.repository.RepositorySessionFactory; import org.apache.archiva.metadata.repository.RepositorySessionFactory;
import org.apache.archiva.redback.rest.services.RedbackAuthenticationThreadLocal; import org.apache.archiva.redback.rest.services.RedbackAuthenticationThreadLocal;
import org.apache.archiva.redback.rest.services.RedbackRequestInformation; import org.apache.archiva.redback.rest.services.RedbackRequestInformation;
import org.apache.archiva.redback.users.User; import org.apache.archiva.redback.users.User;
import org.apache.archiva.redback.users.UserManager; import org.apache.archiva.redback.users.UserManager;
import org.apache.archiva.maven2.model.Artifact; 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.api.services.ArchivaRestServiceException;
import org.apache.archiva.rest.services.utils.ArtifactBuilder;
import org.apache.archiva.security.AccessDeniedException; import org.apache.archiva.security.AccessDeniedException;
import org.apache.archiva.security.ArchivaSecurityException; import org.apache.archiva.security.ArchivaSecurityException;
import org.apache.archiva.security.PrincipalNotFoundException; import org.apache.archiva.security.PrincipalNotFoundException;
@ -72,7 +76,7 @@ public abstract class AbstractRestService
@Inject @Inject
@Named( value = "repositorySessionFactory" ) @Named (value = "repositorySessionFactory")
protected RepositorySessionFactory repositorySessionFactory; protected RepositorySessionFactory repositorySessionFactory;
@Inject @Inject
@ -81,6 +85,9 @@ public abstract class AbstractRestService
@Inject @Inject
protected ManagedRepositoryAdmin managedRepositoryAdmin; protected ManagedRepositoryAdmin managedRepositoryAdmin;
@Inject
protected RepositoryContentFactory repositoryContentFactory;
@Context @Context
protected HttpServletRequest httpServletRequest; protected HttpServletRequest httpServletRequest;
@ -235,4 +242,34 @@ public abstract class AbstractRestService
Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e ); Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e );
} }
} }
protected List<Artifact> buildArtifacts( List<ArtifactMetadata> artifactMetadatas, String repositoryId )
throws ArchivaRestServiceException
{
try
{
if ( artifactMetadatas != null && !artifactMetadatas.isEmpty() )
{
List<Artifact> artifacts = new ArrayList<Artifact>( artifactMetadatas.size() );
for ( ArtifactMetadata artifact : artifactMetadatas )
{
ArtifactBuilder builder =
new ArtifactBuilder().forArtifactMetadata( artifact ).withManagedRepositoryContent(
repositoryContentFactory.getManagedRepositoryContent( repositoryId ) );
Artifact art = builder.build();
art.setUrl( getArtifactUrl( art ) );
artifacts.add( art );
}
return artifacts;
}
return Collections.emptyList();
}
catch ( RepositoryException e )
{
log.error( e.getMessage(), e );
throw new ArchivaRestServiceException( e.getMessage(),
Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e );
}
}
} }

View File

@ -51,8 +51,8 @@ import org.apache.archiva.rest.api.model.Entry;
import org.apache.archiva.rest.api.model.VersionsList; import org.apache.archiva.rest.api.model.VersionsList;
import org.apache.archiva.rest.api.services.ArchivaRestServiceException; import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
import org.apache.archiva.rest.api.services.BrowseService; import org.apache.archiva.rest.api.services.BrowseService;
import org.apache.archiva.rest.services.utils.ArtifactBuilder;
import org.apache.archiva.rest.services.utils.ArtifactContentEntryComparator; import org.apache.archiva.rest.services.utils.ArtifactContentEntryComparator;
import org.apache.archiva.rest.services.utils.ArtifactDownloadInfoBuilder;
import org.apache.archiva.security.ArchivaSecurityException; import org.apache.archiva.security.ArchivaSecurityException;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
@ -686,26 +686,10 @@ public class DefaultBrowseService
metadataResolver.resolveArtifacts( session, repoId, groupId, artifactId, version ) ); metadataResolver.resolveArtifacts( session, repoId, groupId, artifactId, version ) );
Collections.sort( artifacts, ArtifactMetadataVersionComparator.INSTANCE ); Collections.sort( artifacts, ArtifactMetadataVersionComparator.INSTANCE );
for ( ArtifactMetadata artifact : artifacts ) return buildArtifacts( artifacts, repositoryId );
{
ArtifactDownloadInfoBuilder builder =
new ArtifactDownloadInfoBuilder().forArtifactMetadata( artifact ).withManagedRepositoryContent(
repositoryContentFactory.getManagedRepositoryContent( repoId ) );
Artifact art = builder.build();
art.setUrl( getArtifactUrl( art ) );
artifactDownloadInfos.add( art );
}
} }
} }
catch ( RepositoryException e )
{
log.error( e.getMessage(), e );
throw new ArchivaRestServiceException( e.getMessage(),
Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e );
}
catch ( MetadataResolutionException e ) catch ( MetadataResolutionException e )
{ {
log.error( e.getMessage(), e ); log.error( e.getMessage(), e );

View File

@ -18,6 +18,7 @@ package org.apache.archiva.rest.services;
* under the License. * under the License.
*/ */
import org.apache.archiva.maven2.model.Artifact;
import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.repository.RepositorySession; import org.apache.archiva.metadata.repository.RepositorySession;
import org.apache.archiva.rest.api.services.ArchivaRestServiceException; import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
@ -43,15 +44,19 @@ public class DefaultMergeRepositoriesService
@Named ( value = "repositoryMerger#maven2" ) @Named ( value = "repositoryMerger#maven2" )
private Maven2RepositoryMerger repositoryMerger; private Maven2RepositoryMerger repositoryMerger;
public List<ArtifactMetadata> getMergeConflictedArtifacts( String repositoryId )
public List<Artifact> getMergeConflictedArtifacts( String repositoryId )
throws ArchivaRestServiceException throws ArchivaRestServiceException
{ {
String sourceRepoId = repositoryId + "-stage"; String sourceRepoId = repositoryId + "-stage";
RepositorySession repositorySession = repositorySessionFactory.createSession(); RepositorySession repositorySession = repositorySessionFactory.createSession();
try try
{ {
return repositoryMerger.getConflictingArtifacts( repositorySession.getRepository(), sourceRepoId, List<ArtifactMetadata> artifactMetadatas =
repositoryId ); repositoryMerger.getConflictingArtifacts( repositorySession.getRepository(), sourceRepoId,
repositoryId );
return buildArtifacts( artifactMetadatas, repositoryId );
} }
catch ( Exception e ) catch ( Exception e )
{ {
@ -61,5 +66,6 @@ public class DefaultMergeRepositoriesService
{ {
repositorySession.close(); repositorySession.close();
} }
} }
} }

View File

@ -70,11 +70,11 @@ import org.apache.archiva.scheduler.indexing.ArchivaIndexingTaskExecutor;
import org.apache.archiva.scheduler.indexing.ArtifactIndexingTask; import org.apache.archiva.scheduler.indexing.ArtifactIndexingTask;
import org.apache.archiva.scheduler.indexing.DownloadRemoteIndexException; import org.apache.archiva.scheduler.indexing.DownloadRemoteIndexException;
import org.apache.archiva.scheduler.indexing.DownloadRemoteIndexScheduler; import org.apache.archiva.scheduler.indexing.DownloadRemoteIndexScheduler;
import org.apache.archiva.scheduler.repository.ArchivaRepositoryScanningTaskExecutor;
import org.apache.archiva.scheduler.repository.RepositoryArchivaTaskScheduler; import org.apache.archiva.scheduler.repository.RepositoryArchivaTaskScheduler;
import org.apache.archiva.scheduler.repository.RepositoryTask; import org.apache.archiva.scheduler.repository.RepositoryTask;
import org.apache.archiva.security.ArchivaSecurityException; import org.apache.archiva.security.ArchivaSecurityException;
import org.apache.archiva.security.common.ArchivaRoleConstants; import org.apache.archiva.security.common.ArchivaRoleConstants;
import org.apache.archiva.stagerepository.merge.Maven2RepositoryMerger;
import org.apache.archiva.xml.XMLException; import org.apache.archiva.xml.XMLException;
import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
@ -86,7 +86,6 @@ import org.springframework.stereotype.Service;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;

View File

@ -34,26 +34,26 @@ import java.util.Locale;
* @author Olivier Lamy * @author Olivier Lamy
* @since 1.4-M3 * @since 1.4-M3
*/ */
public class ArtifactDownloadInfoBuilder public class ArtifactBuilder
{ {
private ManagedRepositoryContent managedRepositoryContent; private ManagedRepositoryContent managedRepositoryContent;
private ArtifactMetadata artifactMetadata; private ArtifactMetadata artifactMetadata;
public ArtifactDownloadInfoBuilder() public ArtifactBuilder()
{ {
// no op // no op
} }
public ArtifactDownloadInfoBuilder withManagedRepositoryContent( ManagedRepositoryContent managedRepositoryContent ) public ArtifactBuilder withManagedRepositoryContent( ManagedRepositoryContent managedRepositoryContent )
{ {
this.managedRepositoryContent = managedRepositoryContent; this.managedRepositoryContent = managedRepositoryContent;
return this; return this;
} }
public ArtifactDownloadInfoBuilder forArtifactMetadata( ArtifactMetadata artifactMetadata ) public ArtifactBuilder forArtifactMetadata( ArtifactMetadata artifactMetadata )
{ {
this.artifactMetadata = artifactMetadata; this.artifactMetadata = artifactMetadata;
return this; return this;

View File

@ -441,6 +441,7 @@ public abstract class AbstractArchivaRestTest
System.getProperty( "java.io.tmpdir" ) + "/target/.index-" + Long.toString( new Date().getTime() ) ); System.getProperty( "java.io.tmpdir" ) + "/target/.index-" + Long.toString( new Date().getTime() ) );
managedRepository.setStageRepoNeeded( stageNeeded ); managedRepository.setStageRepoNeeded( stageNeeded );
managedRepository.setSnapshots( true );
ManagedRepositoriesService service = getManagedRepositoriesService( authorizationHeader ); ManagedRepositoriesService service = getManagedRepositoriesService( authorizationHeader );
service.addManagedRepository( managedRepository ); service.addManagedRepository( managedRepository );
@ -463,10 +464,17 @@ public abstract class AbstractArchivaRestTest
createAndIndexRepo( testRepoId, repoPath, true, false ); createAndIndexRepo( testRepoId, repoPath, true, false );
} }
protected void createStagedNeededAndIndexRepo( String testRepoId, String repoPath ) protected void createStagedNeededRepo( String testRepoId, String repoPath, boolean scan )
throws Exception throws Exception
{ {
createAndIndexRepo( testRepoId, repoPath, true, true ); createAndIndexRepo( testRepoId, repoPath, scan, true );
RepositoriesService repositoriesService = getRepositoriesService( authorizationHeader );
repositoriesService.scanRepositoryDirectoriesNow( testRepoId );
if ( scan )
{
repositoriesService.scanRepositoryNow( testRepoId + "-stage", true );
repositoriesService.scanRepositoryDirectoriesNow( testRepoId + "-stage" );
}
} }

View File

@ -18,8 +18,13 @@ package org.apache.archiva.rest.services;
* under the License. * under the License.
*/ */
import org.apache.archiva.metadata.model.ArtifactMetadata; import org.apache.archiva.maven2.model.Artifact;
import org.apache.archiva.rest.api.services.BrowseService;
import org.apache.archiva.rest.api.services.MergeRepositoriesService; import org.apache.archiva.rest.api.services.MergeRepositoriesService;
import org.apache.commons.io.FileUtils;
import org.fest.assertions.api.Assertions;
import org.junit.After;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import java.io.File; import java.io.File;
@ -31,23 +36,59 @@ import java.util.List;
public class MergeRepositoriesServiceTest public class MergeRepositoriesServiceTest
extends AbstractArchivaRestTest extends AbstractArchivaRestTest
{ {
@Override
@Before
public void startServer()
throws Exception
{
FileUtils.copyDirectory( new File( System.getProperty( "basedir" ), "src/test/repo-with-osgi" ),
new File( System.getProperty( "builddir" ), "test-repository" ) );
FileUtils.copyDirectory( new File( System.getProperty( "basedir" ), "src/test/repo-with-osgi-stage" ),
new File( System.getProperty( "builddir" ), "test-repository-stage" ) );
super.startServer();
}
@Override
@After
public void stopServer()
throws Exception
{
// TODO delete repositories
super.stopServer();
FileUtils.deleteDirectory( new File( System.getProperty( "builddir" ), "test-repository" ) );
FileUtils.deleteDirectory( new File( System.getProperty( "builddir" ), "test-repository-stage" ) );
}
@Test @Test
public void mergeConflictedArtifacts() public void mergeConflictedArtifacts()
throws Exception throws Exception
{ {
try try
{ {
String testRepoId = "test-repo"; String testRepoId = "test-repository";
createStagedNeededAndIndexRepo( testRepoId, new File( "target/target-repo" ).getAbsolutePath() ); createStagedNeededRepo( testRepoId,
new File( System.getProperty( "builddir" ), "test-repository" ).getAbsolutePath(),
true );
// force jcr data population !
BrowseService browseService = getBrowseService( authorizationHeader, false );
browseService.getRootGroups( testRepoId );
browseService.getRootGroups( testRepoId + "-stage" );
MergeRepositoriesService service = getMergeRepositoriesService(); MergeRepositoriesService service = getMergeRepositoriesService();
List<ArtifactMetadata> artifactMetadatas = service.getMergeConflictedArtifacts( testRepoId ); List<Artifact> artifactMetadatas = service.getMergeConflictedArtifacts( testRepoId );
log.info( "conflicts: {}", artifactMetadatas ); log.info( "conflicts: {}", artifactMetadatas );
Assertions.assertThat( artifactMetadatas ).isNotNull().isNotEmpty().hasSize( 8 );
deleteTestRepo( testRepoId ); deleteTestRepo( testRepoId );
} catch( Exception e) }
catch ( Exception e )
{ {
log.error( e.getMessage(), e ); log.error( e.getMessage(), e );
throw e; throw e;

View File

@ -72,8 +72,8 @@ define("archiva.repositories",["jquery","i18n","jquery.tmpl","bootstrap","jquery
this.retentionCount=ko.observable(retentionCount); this.retentionCount=ko.observable(retentionCount);
this.retentionCount.subscribe(function(newValue){self.modified(true)}); this.retentionCount.subscribe(function(newValue){self.modified(true)});
//private boolean scanned = false; //private boolean scanned = true;
this.scanned=ko.observable(scanned); this.scanned=ko.observable(scanned?scanned:true);
this.scanned.subscribe(function(newValue){self.modified(true)}); this.scanned.subscribe(function(newValue){self.modified(true)});
//private boolean deleteReleasedSnapshots; //private boolean deleteReleasedSnapshots;

View File

@ -38,7 +38,7 @@ import org.apache.archiva.repository.RepositoryContentFactory;
import org.apache.archiva.repository.RepositoryException; import org.apache.archiva.repository.RepositoryException;
import org.apache.archiva.repository.RepositoryNotFoundException; import org.apache.archiva.repository.RepositoryNotFoundException;
import org.apache.archiva.maven2.model.Artifact; import org.apache.archiva.maven2.model.Artifact;
import org.apache.archiva.rest.services.utils.ArtifactDownloadInfoBuilder; import org.apache.archiva.rest.services.utils.ArtifactBuilder;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
@ -219,7 +219,7 @@ public class ShowArtifactAction
this.artifacts.put( artifact.getVersion(), l ); this.artifacts.put( artifact.getVersion(), l );
} }
ArtifactDownloadInfoBuilder builder = new ArtifactDownloadInfoBuilder().forArtifactMetadata( ArtifactBuilder builder = new ArtifactBuilder().forArtifactMetadata(
artifact ).withManagedRepositoryContent( artifact ).withManagedRepositoryContent(
repositoryFactory.getManagedRepositoryContent( repositoryId ) ); repositoryFactory.getManagedRepositoryContent( repositoryId ) );
l.add( builder.build() ); l.add( builder.build() );