use of org.apache.archiva.configuration.model.ManagedRepositoryConfiguration in project archiva by apache.
the class MavenRepositoryMapperTest method update.
@Test
void update() {
MavenRepositoryMapper mapper = new MavenRepositoryMapper();
MavenManagedRepository repo = new MavenManagedRepository();
ManagedRepositoryConfiguration result = new ManagedRepositoryConfiguration();
repo.setId("repo01");
repo.setName("Repo 01");
repo.setDescription("This is repo 01");
repo.setLocation("/data/repo01");
repo.setHasStagingRepository(true);
repo.setSchedulingDefinition("0,1,2 * * * *");
repo.setPackedIndexPath(".index");
repo.setIndexPath(".indexer");
repo.setIndex(true);
repo.setDeleteSnapshotsOfRelease(false);
repo.setBlocksRedeployments(false);
repo.setReleaseSchemes(Arrays.asList(ReleaseScheme.RELEASE.name(), ReleaseScheme.SNAPSHOT.name()));
repo.setCharacteristic(Repository.CHARACTERISTIC_MANAGED);
repo.setScanned(true);
repo.setRetentionPeriod(Period.ofDays(10));
repo.setRetentionCount(15);
repo.setSkipPackedIndexCreation(false);
repo.setStagingRepository("stage-repo01");
mapper.update(repo, result);
assertNotNull(result);
assertEquals("repo01", result.getId());
assertEquals("Repo 01", result.getName());
assertEquals("This is repo 01", result.getDescription());
assertEquals("/data/repo01", result.getLocation());
assertTrue(result.isStageRepoNeeded());
assertEquals("0,1,2 * * * *", result.getRefreshCronExpression());
assertEquals(".indexer", result.getIndexDir());
assertEquals(".index", result.getPackedIndexDir());
assertFalse(result.isDeleteReleasedSnapshots());
assertFalse(result.isBlockRedeployments());
assertTrue(result.isSnapshots());
assertTrue(result.isReleases());
assertTrue(result.isScanned());
assertEquals(10, result.getRetentionPeriod());
assertEquals(15, result.getRetentionCount());
assertFalse(result.isSkipPackedIndexCreation());
}
use of org.apache.archiva.configuration.model.ManagedRepositoryConfiguration in project archiva by apache.
the class AuditManagerTest method setUp.
@Override
@Before
public void setUp() throws Exception {
super.setUp();
auditManager = new DefaultAuditManager();
metadataRepository = mock(MetadataRepository.class);
repositorySessionFactory = mock(RepositorySessionFactory.class);
session = mock(RepositorySession.class);
auditManager.setRepositorySessionFactory(repositorySessionFactory);
ManagedRepositoryConfiguration repository = new ManagedRepositoryConfiguration();
repository.setId(TEST_REPO_ID);
repository.setLocation("");
}
use of org.apache.archiva.configuration.model.ManagedRepositoryConfiguration in project archiva by apache.
the class RepositoryProviderMock method getManagedConfiguration.
@Override
public ManagedRepositoryConfiguration getManagedConfiguration(ManagedRepository managedRepository) {
ManagedRepositoryConfiguration configuration = new ManagedRepositoryConfiguration();
configuration.setId(managedRepository.getId());
configuration.setName(managedRepository.getName());
configuration.setLocation(managedRepository.getLocation() == null ? "" : managedRepository.getLocation().toString());
configuration.setBlockRedeployments(managedRepository.blocksRedeployments());
configuration.setDescription(managedRepository.getDescription());
configuration.setScanned(managedRepository.isScanned());
configuration.setRefreshCronExpression(managedRepository.getSchedulingDefinition());
configuration.setReleases(managedRepository.getActiveReleaseSchemes().contains(ReleaseScheme.RELEASE));
configuration.setSnapshots(managedRepository.getActiveReleaseSchemes().contains(ReleaseScheme.SNAPSHOT));
configuration.setLayout(managedRepository.getLayout());
ArtifactCleanupFeature acf = managedRepository.getFeature(ArtifactCleanupFeature.class);
configuration.setRetentionPeriod(acf.getRetentionPeriod().getDays());
configuration.setDeleteReleasedSnapshots(acf.isDeleteReleasedSnapshots());
configuration.setRetentionCount(acf.getRetentionCount());
IndexCreationFeature icf = managedRepository.getFeature(IndexCreationFeature.class);
configuration.setSkipPackedIndexCreation(icf.isSkipPackedIndexCreation());
configuration.setIndexDir(icf.getIndexPath() == null ? "" : icf.getIndexPath().toString());
StagingRepositoryFeature srf = managedRepository.getFeature(StagingRepositoryFeature.class);
configuration.setStageRepoNeeded(srf.isStageRepoNeeded());
return configuration;
}
use of org.apache.archiva.configuration.model.ManagedRepositoryConfiguration in project archiva by apache.
the class DefaultManagedRepositoryAdmin method addManagedRepository.
@Override
public Boolean addManagedRepository(ManagedRepository managedRepository, boolean needStageRepo, AuditInformation auditInformation) throws RepositoryAdminException {
log.debug("addManagedRepository {}, {}, {}", managedRepository.getId(), needStageRepo, auditInformation);
getRepositoryCommonValidator().basicValidation(managedRepository, false);
getRepositoryCommonValidator().validateManagedRepository(managedRepository);
triggerAuditEvent(managedRepository.getId(), null, AuditEvent.ADD_MANAGED_REPO, auditInformation);
ManagedRepositoryConfiguration repoConfig = getRepositoryConfiguration(managedRepository);
if (needStageRepo) {
repoConfig.setStageRepoNeeded(true);
}
Configuration configuration = getArchivaConfiguration().getConfiguration();
try {
org.apache.archiva.repository.ManagedRepository newRepo = repositoryRegistry.putRepository(repoConfig);
log.debug("Added new repository {}", newRepo.getId());
addRepositoryRoles(newRepo.getId());
// scan repository when adding of repository is successful
try {
if (newRepo.isScanned()) {
scanRepository(newRepo.getId(), true);
}
org.apache.archiva.repository.ManagedRepository stagingRepo = newRepo.getFeature(StagingRepositoryFeature.class).getStagingRepository();
if (stagingRepo != null) {
if (stagingRepo.isScanned()) {
scanRepository(stagingRepo.getId(), true);
}
addRepositoryRoles(stagingRepo.getId());
}
} catch (Exception e) {
log.warn("Unable to scan repository [{}]: {}", newRepo.getId(), e.getMessage(), e);
}
} catch (RepositoryException e) {
log.error("Could not add managed repository {}" + managedRepository);
throw new RepositoryAdminException("Could not add repository " + e.getMessage());
} catch (RoleManagerException e) {
log.error("Could not add repository roles for repository [{}]: {}", managedRepository.getId(), e.getMessage(), e);
throw new RepositoryAdminException("Could not add roles to repository " + e.getMessage());
}
return Boolean.TRUE;
}
use of org.apache.archiva.configuration.model.ManagedRepositoryConfiguration in project archiva by apache.
the class DefaultManagedRepositoryAdmin method updateManagedRepository.
@Override
public Boolean updateManagedRepository(ManagedRepository managedRepository, boolean needStageRepo, AuditInformation auditInformation, boolean resetStats) throws RepositoryAdminException {
log.debug("updateManagedConfiguration repo {} needStage {} resetStats {} ", managedRepository, needStageRepo, resetStats);
// Ensure that the fields are valid.
getRepositoryCommonValidator().basicValidation(managedRepository, true);
getRepositoryCommonValidator().validateManagedRepository(managedRepository);
ManagedRepositoryConfiguration updatedRepoConfig = getRepositoryConfiguration(managedRepository);
updatedRepoConfig.setStageRepoNeeded(needStageRepo);
org.apache.archiva.repository.ManagedRepository oldRepo = repositoryRegistry.getManagedRepository(managedRepository.getId());
boolean stagingExists = false;
if (oldRepo.supportsFeature(StagingRepositoryFeature.class)) {
stagingExists = oldRepo.getFeature(StagingRepositoryFeature.class).getStagingRepository() != null;
}
boolean updateIndexContext = !StringUtils.equals(updatedRepoConfig.getIndexDir(), managedRepository.getIndexDirectory());
org.apache.archiva.repository.ManagedRepository newRepo;
// TODO remove content from old if path has changed !!!!!
try {
newRepo = repositoryRegistry.putRepository(updatedRepoConfig);
if (newRepo.supportsFeature(StagingRepositoryFeature.class)) {
org.apache.archiva.repository.ManagedRepository stagingRepo = newRepo.getFeature(StagingRepositoryFeature.class).getStagingRepository();
if (stagingRepo != null && !stagingExists) {
triggerAuditEvent(stagingRepo.getId(), null, AuditEvent.ADD_MANAGED_REPO, auditInformation);
addRepositoryRoles(stagingRepo.getId());
}
}
} catch (RepositoryException e) {
log.error("Could not update repository {}: {}", managedRepository.getId(), e.getMessage(), e);
throw new RepositoryAdminException("Could not update repository " + managedRepository.getId());
} catch (RoleManagerException e) {
log.error("Error during role update of stage repo {}", managedRepository.getId(), e);
throw new RepositoryAdminException("Could not update repository " + managedRepository.getId());
}
triggerAuditEvent(managedRepository.getId(), null, AuditEvent.MODIFY_MANAGED_REPO, auditInformation);
// Save the repository configuration.
RepositorySession repositorySession = null;
try {
repositorySession = getRepositorySessionFactory().createSession();
} catch (MetadataRepositoryException e) {
e.printStackTrace();
}
try {
if (resetStats) {
log.debug("call repositoryStatisticsManager.deleteStatistics");
getRepositoryStatisticsManager().deleteStatistics(managedRepository.getId());
repositorySession.save();
}
} catch (MetadataRepositoryException | MetadataSessionException e) {
throw new RepositoryAdminException(e.getMessage(), e);
} finally {
repositorySession.close();
}
if (updateIndexContext) {
try {
repositoryRegistry.resetIndexingContext(newRepo);
} catch (IndexUpdateFailedException e) {
e.printStackTrace();
}
}
return true;
}
Aggregations