Search in sources :

Example 51 with ManagedRepositoryConfiguration

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());
}
Also used : ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) MavenManagedRepository(org.apache.archiva.rest.api.v2.model.MavenManagedRepository) Test(org.junit.jupiter.api.Test)

Example 52 with ManagedRepositoryConfiguration

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("");
}
Also used : MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) RepositorySessionFactory(org.apache.archiva.metadata.repository.RepositorySessionFactory) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession) Before(org.junit.Before)

Example 53 with ManagedRepositoryConfiguration

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;
}
Also used : IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) ArtifactCleanupFeature(org.apache.archiva.repository.features.ArtifactCleanupFeature) StagingRepositoryFeature(org.apache.archiva.repository.features.StagingRepositoryFeature)

Example 54 with ManagedRepositoryConfiguration

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;
}
Also used : ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.model.ProxyConnectorConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) RepositoryException(org.apache.archiva.repository.RepositoryException) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) StagingRepositoryFeature(org.apache.archiva.repository.features.StagingRepositoryFeature) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) RoleManagerException(org.apache.archiva.redback.role.RoleManagerException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) RepositoryException(org.apache.archiva.repository.RepositoryException) MetadataSessionException(org.apache.archiva.metadata.repository.MetadataSessionException) IOException(java.io.IOException) IndexUpdateFailedException(org.apache.archiva.indexer.IndexUpdateFailedException) TaskQueueException(org.apache.archiva.components.taskqueue.TaskQueueException) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) RoleManagerException(org.apache.archiva.redback.role.RoleManagerException)

Example 55 with ManagedRepositoryConfiguration

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;
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) RepositoryException(org.apache.archiva.repository.RepositoryException) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession) MetadataSessionException(org.apache.archiva.metadata.repository.MetadataSessionException) IndexUpdateFailedException(org.apache.archiva.indexer.IndexUpdateFailedException) StagingRepositoryFeature(org.apache.archiva.repository.features.StagingRepositoryFeature) RoleManagerException(org.apache.archiva.redback.role.RoleManagerException)

Aggregations

ManagedRepositoryConfiguration (org.apache.archiva.configuration.model.ManagedRepositoryConfiguration)72 Configuration (org.apache.archiva.configuration.model.Configuration)27 ManagedRepository (org.apache.archiva.repository.ManagedRepository)18 ContextConfiguration (org.springframework.test.context.ContextConfiguration)18 Path (java.nio.file.Path)17 ProxyConnectorConfiguration (org.apache.archiva.configuration.model.ProxyConnectorConfiguration)14 RemoteRepositoryConfiguration (org.apache.archiva.configuration.model.RemoteRepositoryConfiguration)14 ArchivaConfiguration (org.apache.archiva.configuration.provider.ArchivaConfiguration)14 Test (org.junit.Test)14 StagingRepositoryFeature (org.apache.archiva.repository.features.StagingRepositoryFeature)13 EditableManagedRepository (org.apache.archiva.repository.EditableManagedRepository)11 RepositoryScanningConfiguration (org.apache.archiva.configuration.model.RepositoryScanningConfiguration)10 Test (org.junit.jupiter.api.Test)10 ArrayList (java.util.ArrayList)9 NetworkProxyConfiguration (org.apache.archiva.configuration.model.NetworkProxyConfiguration)9 RepositoryGroupConfiguration (org.apache.archiva.configuration.model.RepositoryGroupConfiguration)9 RepositoryException (org.apache.archiva.repository.RepositoryException)9 Before (org.junit.Before)8 IOException (java.io.IOException)7 ArtifactCleanupFeature (org.apache.archiva.repository.features.ArtifactCleanupFeature)7