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.
*
*
* 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
extends Consumer

View File

@ -51,7 +51,7 @@ public class ManagedRepository
*/
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.getDaysOlder(), managedRepository.getRetentionCount(),
managedRepository.isDeleteReleasedSnapshots(), managedRepository.getDescription(),
managedRepository.isSkipPackedIndexCreation(), auditInformation,
getArchivaConfiguration().getConfiguration() ) != null;
managedRepository.isSkipPackedIndexCreation(), managedRepository.isScanned(),
auditInformation, getArchivaConfiguration().getConfiguration() ) != null;
createIndexContext( managedRepository );
return res;
@ -234,7 +234,7 @@ public class DefaultManagedRepositoryAdmin
boolean stageRepoNeeded, String cronExpression,
String indexDir, int daysOlder, int retentionCount,
boolean deteleReleasedSnapshots, String description,
boolean skipPackedIndexCreation,
boolean skipPackedIndexCreation, boolean scanned,
AuditInformation auditInformation,
Configuration config )
throws RepositoryAdminException
@ -246,6 +246,7 @@ public class DefaultManagedRepositoryAdmin
repository.setBlockRedeployments( blockRedeployments );
repository.setReleases( releasesIncluded );
repository.setSnapshots( snapshotsIncluded );
repository.setScanned( scanned );
repository.setName( name );
repository.setLocation( getRepositoryCommonValidator().removeExpressions( location ) );
repository.setLayout( layout );
@ -285,15 +286,18 @@ public class DefaultManagedRepositoryAdmin
//MRM-1342 Repository statistics report doesn't appear to be working correctly
//scan repository when adding of repository is successful
try
{
if ( scanned )
{
scanRepository( repoId, true );
// olamy no need of scanning staged repo
/*
if ( stageRepoNeeded )
}
// TODO need a better to define scanning or not for staged repo
if ( stageRepoNeeded && scanned )
{
ManagedRepositoryConfiguration stagingRepository = getStageRepoConfig( repository );
scanRepository( stagingRepository.getId(), true );
}*/
}
}
catch ( Exception e )
{
@ -486,8 +490,8 @@ public class DefaultManagedRepositoryAdmin
managedRepository.getCronExpression(), managedRepository.getIndexDirectory(),
managedRepository.getDaysOlder(), managedRepository.getRetentionCount(),
managedRepository.isDeleteReleasedSnapshots(), managedRepository.getDescription(),
managedRepository.isSkipPackedIndexCreation(), auditInformation,
getArchivaConfiguration().getConfiguration() );
managedRepository.isSkipPackedIndexCreation(), managedRepository.isScanned(),
auditInformation, getArchivaConfiguration().getConfiguration() );
// Save the repository configuration.
RepositorySession repositorySession = getRepositorySessionFactory().createSession();
@ -631,10 +635,24 @@ public class DefaultManagedRepositoryAdmin
stagingRepository.setBlockRedeployments( repository.isBlockRedeployments() );
stagingRepository.setDaysOlder( repository.getDaysOlder() );
stagingRepository.setDeleteReleasedSnapshots( repository.isDeleteReleasedSnapshots() );
stagingRepository.setIndexDir( repository.getIndexDir() );
String path = repository.getLocation();
int lastIndex = path.replace( '\\', '/' ).lastIndexOf( '/' );
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.setReleases( repository.isReleases() );
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.admin.ArchivaAdministration;
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.TriggerBeginScanClosure;
import org.apache.archiva.repository.scanner.functors.TriggerScanCompletedClosure;
import org.apache.commons.collections.Closure;
import org.apache.commons.collections.CollectionUtils;
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.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
@ -47,10 +47,8 @@ import java.util.Map;
/**
* RepositoryContentConsumerUtil
*
*
*/
@Service("repositoryContentConsumers")
@Service ("repositoryContentConsumers")
public class RepositoryContentConsumers
implements ApplicationContextAware
{
@ -163,8 +161,11 @@ public class RepositoryContentConsumers
public synchronized List<KnownRepositoryContentConsumer> getSelectedKnownConsumers()
throws RepositoryAdminException
{
if ( selectedKnownConsumers == null )
// FIXME only for testing
if ( selectedKnownConsumers != null )
{
return selectedKnownConsumers;
}
List<KnownRepositoryContentConsumer> ret = new ArrayList<KnownRepositoryContentConsumer>();
List<String> knownSelected = getSelectedKnownConsumerIds();
@ -176,9 +177,7 @@ public class RepositoryContentConsumers
ret.add( consumer );
}
}
this.selectedKnownConsumers = ret;
}
return selectedKnownConsumers;
return ret;
}
/**
@ -191,8 +190,13 @@ public class RepositoryContentConsumers
public synchronized List<InvalidRepositoryContentConsumer> getSelectedInvalidConsumers()
throws RepositoryAdminException
{
if ( selectedInvalidConsumers == null )
// FIXME only for testing
if ( selectedInvalidConsumers != null )
{
return selectedInvalidConsumers;
}
List<InvalidRepositoryContentConsumer> ret = new ArrayList<InvalidRepositoryContentConsumer>();
List<String> invalidSelected = getSelectedInvalidConsumerIds();
@ -204,11 +208,10 @@ public class RepositoryContentConsumers
ret.add( consumer );
}
}
selectedInvalidConsumers = ret;
}
return selectedInvalidConsumers;
return ret;
}
/**
* Get the list of {@link KnownRepositoryContentConsumer} objects that are
* 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.
*/
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.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.redback.components.scheduler.CronExpressionValidator;
import org.apache.archiva.scheduler.ArchivaTaskScheduler;
import org.quartz.SchedulerException;
import org.quartz.impl.JobDetailImpl;
import org.quartz.impl.triggers.CronTriggerImpl;
@ -54,7 +54,7 @@ import java.util.Set;
/**
* Default implementation of a scheduling component for archiva.
*/
@Service( "archivaTaskScheduler#repository" )
@Service ("archivaTaskScheduler#repository")
public class RepositoryArchivaTaskScheduler
implements ArchivaTaskScheduler<RepositoryTask>, ConfigurationListener
{
@ -73,7 +73,7 @@ public class RepositoryArchivaTaskScheduler
*
*/
@Inject
@Named( value = "taskQueue#repository-scanning" )
@Named (value = "taskQueue#repository-scanning")
private TaskQueue repositoryScanningQueue;
/**
@ -86,12 +86,11 @@ public class RepositoryArchivaTaskScheduler
*
*/
@Inject
@Named( value = "repositoryStatisticsManager#default" )
@Named (value = "repositoryStatisticsManager#default")
private RepositoryStatisticsManager repositoryStatisticsManager;
/**
* TODO: could have multiple implementations
*
*/
@Inject
private RepositorySessionFactory repositorySessionFactory;
@ -174,7 +173,7 @@ public class RepositoryArchivaTaskScheduler
}
@SuppressWarnings( "unchecked" )
@SuppressWarnings ("unchecked")
public boolean isProcessingRepositoryTask( String repositoryId )
{
synchronized ( repositoryScanningQueue )
@ -201,7 +200,7 @@ public class RepositoryArchivaTaskScheduler
}
}
@SuppressWarnings( "unchecked" )
@SuppressWarnings ("unchecked")
private boolean isProcessingRepositoryTask( RepositoryTask task )
{
synchronized ( repositoryScanningQueue )
@ -261,6 +260,7 @@ public class RepositoryArchivaTaskScheduler
}
}
}
public void configurationEvent( ConfigurationEvent event )
{
if ( event.getType() == ConfigurationEvent.SAVED )
@ -298,7 +298,7 @@ public class RepositoryArchivaTaskScheduler
}
}
@SuppressWarnings( "unchecked" )
@SuppressWarnings ("unchecked")
private boolean isPreviouslyScanned( ManagedRepositoryConfiguration repoConfig,
MetadataRepository metadataRepository )
throws MetadataRepositoryException
@ -334,13 +334,13 @@ public class RepositoryArchivaTaskScheduler
{
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;
}
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;
}
@ -349,14 +349,15 @@ public class RepositoryArchivaTaskScheduler
if ( !cronValidator.validate( cronString ) )
{
log.warn( "Cron expression [" + cronString + "] for repository [" + repoConfig.getId()
+ "] is invalid. Defaulting to hourly." );
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 );
new JobDetailImpl( REPOSITORY_JOB + ":" + repoConfig.getId(), REPOSITORY_SCAN_GROUP,
RepositoryTaskJob.class );
repositoryJob.getJobDataMap().put( TASK_QUEUE, repositoryScanningQueue );
repositoryJob.getJobDataMap().put( TASK_REPOSITORY, repoConfig.getId() );
@ -364,7 +365,8 @@ public class RepositoryArchivaTaskScheduler
try
{
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() );
scheduler.scheduleJob( repositoryJob, trigger );

View File

@ -18,7 +18,7 @@ package org.apache.archiva.rest.api.services;
* 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 javax.ws.rs.GET;
@ -45,6 +45,6 @@ public interface MergeRepositoriesService
* <b>permissions are checked in impl</b>
* @since 1.4-M3
*/
List<ArtifactMetadata> getMergeConflictedArtifacts( @PathParam ( "repositoryId" ) String repositoryId )
List<Artifact> getMergeConflictedArtifacts( @PathParam ( "repositoryId" ) String repositoryId )
throws ArchivaRestServiceException;
}

View File

@ -396,6 +396,11 @@
<version>${tomcat7Version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-metadata-consumer</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
@ -408,10 +413,9 @@
<configuration>
<excludes>
<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-snapshots/**</exclude>
<exclude>src/test/resources/target-repo/**</exclude>
<exclude>src/test/resources/test-repository-stage/**</exclude>
</excludes>
</configuration>
</plugin>
@ -443,30 +447,13 @@
<redback.jdbc.url>${redbackTestJdbcUrl}</redback.jdbc.url>
<redback.jdbc.driver.name>${redbackTestJdbcDriver}</redback.jdbc.driver.name>
<basedir>${basedir}</basedir>
<builddir>${project.build.directory}</builddir>
<org.apache.jackrabbit.maxCacheMemory>1</org.apache.jackrabbit.maxCacheMemory>
<org.apache.jackrabbit.maxMemoryPerCache>1</org.apache.jackrabbit.maxMemoryPerCache>
<!--org.apache.jackrabbit.minMemoryPerCache>1</org.apache.jackrabbit.minMemoryPerCache-->
</systemPropertyVariables>
</configuration>
</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>
</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.AuditListener;
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.redback.rest.services.RedbackAuthenticationThreadLocal;
import org.apache.archiva.redback.rest.services.RedbackRequestInformation;
import org.apache.archiva.redback.users.User;
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.services.utils.ArtifactBuilder;
import org.apache.archiva.security.AccessDeniedException;
import org.apache.archiva.security.ArchivaSecurityException;
import org.apache.archiva.security.PrincipalNotFoundException;
@ -72,7 +76,7 @@ public abstract class AbstractRestService
@Inject
@Named( value = "repositorySessionFactory" )
@Named (value = "repositorySessionFactory")
protected RepositorySessionFactory repositorySessionFactory;
@Inject
@ -81,6 +85,9 @@ public abstract class AbstractRestService
@Inject
protected ManagedRepositoryAdmin managedRepositoryAdmin;
@Inject
protected RepositoryContentFactory repositoryContentFactory;
@Context
protected HttpServletRequest httpServletRequest;
@ -235,4 +242,34 @@ public abstract class AbstractRestService
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.services.ArchivaRestServiceException;
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.ArtifactDownloadInfoBuilder;
import org.apache.archiva.security.ArchivaSecurityException;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.io.FileUtils;
@ -686,26 +686,10 @@ public class DefaultBrowseService
metadataResolver.resolveArtifacts( session, repoId, groupId, artifactId, version ) );
Collections.sort( artifacts, ArtifactMetadataVersionComparator.INSTANCE );
for ( ArtifactMetadata artifact : artifacts )
{
ArtifactDownloadInfoBuilder builder =
new ArtifactDownloadInfoBuilder().forArtifactMetadata( artifact ).withManagedRepositoryContent(
repositoryContentFactory.getManagedRepositoryContent( repoId ) );
Artifact art = builder.build();
art.setUrl( getArtifactUrl( art ) );
artifactDownloadInfos.add( art );
}
return buildArtifacts( artifacts, repositoryId );
}
}
catch ( RepositoryException e )
{
log.error( e.getMessage(), e );
throw new ArchivaRestServiceException( e.getMessage(),
Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e );
}
catch ( MetadataResolutionException e )
{
log.error( e.getMessage(), e );

View File

@ -18,6 +18,7 @@ package org.apache.archiva.rest.services;
* under the License.
*/
import org.apache.archiva.maven2.model.Artifact;
import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.repository.RepositorySession;
import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
@ -43,15 +44,19 @@ public class DefaultMergeRepositoriesService
@Named ( value = "repositoryMerger#maven2" )
private Maven2RepositoryMerger repositoryMerger;
public List<ArtifactMetadata> getMergeConflictedArtifacts( String repositoryId )
public List<Artifact> getMergeConflictedArtifacts( String repositoryId )
throws ArchivaRestServiceException
{
String sourceRepoId = repositoryId + "-stage";
RepositorySession repositorySession = repositorySessionFactory.createSession();
try
{
return repositoryMerger.getConflictingArtifacts( repositorySession.getRepository(), sourceRepoId,
List<ArtifactMetadata> artifactMetadatas =
repositoryMerger.getConflictingArtifacts( repositorySession.getRepository(), sourceRepoId,
repositoryId );
return buildArtifacts( artifactMetadatas, repositoryId );
}
catch ( Exception e )
{
@ -61,5 +66,6 @@ public class DefaultMergeRepositoriesService
{
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.DownloadRemoteIndexException;
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.RepositoryTask;
import org.apache.archiva.security.ArchivaSecurityException;
import org.apache.archiva.security.common.ArchivaRoleConstants;
import org.apache.archiva.stagerepository.merge.Maven2RepositoryMerger;
import org.apache.archiva.xml.XMLException;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
@ -86,7 +86,6 @@ import org.springframework.stereotype.Service;
import javax.inject.Inject;
import javax.inject.Named;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;
import java.io.File;
import java.io.FileInputStream;

View File

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

View File

@ -441,6 +441,7 @@ public abstract class AbstractArchivaRestTest
System.getProperty( "java.io.tmpdir" ) + "/target/.index-" + Long.toString( new Date().getTime() ) );
managedRepository.setStageRepoNeeded( stageNeeded );
managedRepository.setSnapshots( true );
ManagedRepositoriesService service = getManagedRepositoriesService( authorizationHeader );
service.addManagedRepository( managedRepository );
@ -463,10 +464,17 @@ public abstract class AbstractArchivaRestTest
createAndIndexRepo( testRepoId, repoPath, true, false );
}
protected void createStagedNeededAndIndexRepo( String testRepoId, String repoPath )
protected void createStagedNeededRepo( String testRepoId, String repoPath, boolean scan )
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.
*/
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.commons.io.FileUtils;
import org.fest.assertions.api.Assertions;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.io.File;
@ -31,23 +36,59 @@ import java.util.List;
public class MergeRepositoriesServiceTest
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
public void mergeConflictedArtifacts()
throws Exception
{
try
{
String testRepoId = "test-repo";
createStagedNeededAndIndexRepo( testRepoId, new File( "target/target-repo" ).getAbsolutePath() );
String testRepoId = "test-repository";
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();
List<ArtifactMetadata> artifactMetadatas = service.getMergeConflictedArtifacts( testRepoId );
List<Artifact> artifactMetadatas = service.getMergeConflictedArtifacts( testRepoId );
log.info( "conflicts: {}", artifactMetadatas );
Assertions.assertThat( artifactMetadatas ).isNotNull().isNotEmpty().hasSize( 8 );
deleteTestRepo( testRepoId );
} catch( Exception e)
}
catch ( Exception e )
{
log.error( e.getMessage(), 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.subscribe(function(newValue){self.modified(true)});
//private boolean scanned = false;
this.scanned=ko.observable(scanned);
//private boolean scanned = true;
this.scanned=ko.observable(scanned?scanned:true);
this.scanned.subscribe(function(newValue){self.modified(true)});
//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.RepositoryNotFoundException;
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.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
@ -219,7 +219,7 @@ public class ShowArtifactAction
this.artifacts.put( artifact.getVersion(), l );
}
ArtifactDownloadInfoBuilder builder = new ArtifactDownloadInfoBuilder().forArtifactMetadata(
ArtifactBuilder builder = new ArtifactBuilder().forArtifactMetadata(
artifact ).withManagedRepositoryContent(
repositoryFactory.getManagedRepositoryContent( repositoryId ) );
l.add( builder.build() );