Search in sources :

Example 41 with ManagedRepositoryConfiguration

use of org.apache.archiva.configuration.model.ManagedRepositoryConfiguration in project archiva by apache.

the class ManagedRepositoryHandlerTest method remove.

@Test
void remove() throws RepositoryException {
    final String id = "test-repo-08";
    ManagedRepositoryHandler repoHandler = createHandler();
    ManagedRepositoryConfiguration configuration = new ManagedRepositoryConfiguration();
    configuration.setId(id);
    configuration.setName("n-" + id);
    repoHandler.put(configuration);
    assertTrue(hasRepositoryInConfig(id));
    assertNotNull(repoHandler.get(id));
    repoHandler.remove(id);
    assertNull(repoHandler.get(id));
    assertFalse(hasRepositoryInConfig(id));
}
Also used : ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) Test(org.junit.jupiter.api.Test)

Example 42 with ManagedRepositoryConfiguration

use of org.apache.archiva.configuration.model.ManagedRepositoryConfiguration in project archiva by apache.

the class ManagedRepositoryHandlerTest method testPutWithoutRegister.

@Test
void testPutWithoutRegister() throws RepositoryException {
    final String id = "test-repo-06";
    ManagedRepositoryHandler repoHandler = createHandler();
    Configuration aCfg = new Configuration();
    ManagedRepositoryConfiguration configuration = new ManagedRepositoryConfiguration();
    configuration.setId(id);
    configuration.setName("n-" + id);
    repoHandler.put(configuration, aCfg);
    ManagedRepository repo = repoHandler.get(id);
    assertNull(repo);
    assertFalse(hasRepositoryInConfig(id));
    assertTrue(aCfg.getManagedRepositories().stream().anyMatch(g -> g != null && id.equals(g.getId())));
}
Also used : ArchivaConfiguration(org.apache.archiva.configuration.provider.ArchivaConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) CheckedResult(org.apache.archiva.repository.validation.CheckedResult) FilesystemStorage(org.apache.archiva.repository.storage.fs.FilesystemStorage) ArchivaRepositoryRegistry(org.apache.archiva.repository.base.ArchivaRepositoryRegistry) Inject(javax.inject.Inject) Repository(org.apache.archiva.repository.Repository) RepositoryContentFactory(org.apache.archiva.repository.RepositoryContentFactory) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) ISEMPTY(org.apache.archiva.repository.validation.ErrorKeys.ISEMPTY) IndexManagerFactory(org.apache.archiva.indexer.IndexManagerFactory) Map(java.util.Map) FileUtils(org.apache.archiva.common.utils.FileUtils) Named(javax.inject.Named) ConfigurationHandler(org.apache.archiva.repository.base.ConfigurationHandler) ValidationError(org.apache.archiva.repository.validation.ValidationError) Path(java.nio.file.Path) Configuration(org.apache.archiva.configuration.model.Configuration) RepositoryValidator(org.apache.archiva.repository.validation.RepositoryValidator) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) Iterator(java.util.Iterator) SpringExtension(org.springframework.test.context.junit.jupiter.SpringExtension) Files(java.nio.file.Files) FileLockManager(org.apache.archiva.common.filelock.FileLockManager) RepositoryException(org.apache.archiva.repository.RepositoryException) IOException(java.io.IOException) RepositoryType(org.apache.archiva.repository.RepositoryType) ManagedRepository(org.apache.archiva.repository.ManagedRepository) Test(org.junit.jupiter.api.Test) List(java.util.List) Paths(java.nio.file.Paths) ContextConfiguration(org.springframework.test.context.ContextConfiguration) DefaultFileLockManager(org.apache.archiva.common.filelock.DefaultFileLockManager) Assertions(org.junit.jupiter.api.Assertions) RepositoryState(org.apache.archiva.repository.RepositoryState) EditableManagedRepository(org.apache.archiva.repository.EditableManagedRepository) ManagedRepository(org.apache.archiva.repository.ManagedRepository) EditableManagedRepository(org.apache.archiva.repository.EditableManagedRepository) ArchivaConfiguration(org.apache.archiva.configuration.provider.ArchivaConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) Test(org.junit.jupiter.api.Test)

Example 43 with ManagedRepositoryConfiguration

use of org.apache.archiva.configuration.model.ManagedRepositoryConfiguration in project archiva by apache.

the class ManagedRepositoryHandlerTest method removeRepositoryFromConfig.

// Helper method that removes a repo from the configuration
private void removeRepositoryFromConfig(String id) {
    Configuration configuration = configurationHandler.getBaseConfiguration();
    Iterator<ManagedRepositoryConfiguration> iter = configuration.getManagedRepositories().iterator();
    while (iter.hasNext()) {
        ManagedRepositoryConfiguration repo = iter.next();
        if (id.equals(repo.getId())) {
            iter.remove();
            break;
        }
    }
    try {
        configurationHandler.save(configuration);
    } catch (Throwable e) {
        System.err.println("Could not remove repo from config " + id);
    }
}
Also used : ArchivaConfiguration(org.apache.archiva.configuration.provider.ArchivaConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration)

Example 44 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) throws RepositoryException {
    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.setLayout(managedRepository.getLayout());
    configuration.setScanned(managedRepository.isScanned());
    configuration.setRefreshCronExpression(managedRepository.getSchedulingDefinition());
    configuration.setReleases(managedRepository.getActiveReleaseSchemes().contains(ReleaseScheme.RELEASE));
    configuration.setSnapshots(managedRepository.getActiveReleaseSchemes().contains(ReleaseScheme.SNAPSHOT));
    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 45 with ManagedRepositoryConfiguration

use of org.apache.archiva.configuration.model.ManagedRepositoryConfiguration in project archiva by apache.

the class MavenRepositoryProvider method getStageRepoConfig.

private ManagedRepositoryConfiguration getStageRepoConfig(ManagedRepositoryConfiguration repository) {
    ManagedRepositoryConfiguration stagingRepository = new ManagedRepositoryConfiguration();
    stagingRepository.setId(repository.getId() + StagingRepositoryFeature.STAGING_REPO_POSTFIX);
    stagingRepository.setLayout(repository.getLayout());
    stagingRepository.setName(repository.getName() + StagingRepositoryFeature.STAGING_REPO_POSTFIX);
    stagingRepository.setBlockRedeployments(repository.isBlockRedeployments());
    stagingRepository.setRetentionPeriod(repository.getRetentionPeriod());
    stagingRepository.setDeleteReleasedSnapshots(repository.isDeleteReleasedSnapshots());
    stagingRepository.setStageRepoNeeded(false);
    String path = repository.getLocation();
    int lastIndex = path.replace('\\', '/').lastIndexOf('/');
    stagingRepository.setLocation(path.substring(0, lastIndex) + "/" + stagingRepository.getId());
    if (StringUtils.isNotBlank(repository.getIndexDir())) {
        Path indexDir;
        try {
            if (repository.getIndexDir().startsWith("file:")) {
                indexDir = Paths.get(new URI(repository.getIndexDir()));
            } else {
                indexDir = Paths.get(repository.getIndexDir());
            }
            if (indexDir.isAbsolute()) {
                Path newDir = indexDir.getParent().resolve(indexDir.getFileName() + StagingRepositoryFeature.STAGING_REPO_POSTFIX);
                log.debug("Changing index directory {} -> {}", indexDir, newDir);
                stagingRepository.setIndexDir(newDir.toString());
            } else {
                log.debug("Keeping index directory {}", repository.getIndexDir());
                stagingRepository.setIndexDir(repository.getIndexDir());
            }
        } catch (URISyntaxException e) {
            log.error("Could not parse index path as uri {}", repository.getIndexDir());
            stagingRepository.setIndexDir("");
        }
    // in case of absolute dir do not use the same
    }
    if (StringUtils.isNotBlank(repository.getPackedIndexDir())) {
        Path packedIndexDir;
        packedIndexDir = Paths.get(repository.getPackedIndexDir());
        if (packedIndexDir.isAbsolute()) {
            Path newDir = packedIndexDir.getParent().resolve(packedIndexDir.getFileName() + StagingRepositoryFeature.STAGING_REPO_POSTFIX);
            log.debug("Changing index directory {} -> {}", packedIndexDir, newDir);
            stagingRepository.setPackedIndexDir(newDir.toString());
        } else {
            log.debug("Keeping index directory {}", repository.getPackedIndexDir());
            stagingRepository.setPackedIndexDir(repository.getPackedIndexDir());
        }
    // in case of absolute dir do not use the same
    }
    stagingRepository.setRefreshCronExpression(repository.getRefreshCronExpression());
    stagingRepository.setReleases(repository.isReleases());
    stagingRepository.setRetentionCount(repository.getRetentionCount());
    stagingRepository.setScanned(repository.isScanned());
    stagingRepository.setSnapshots(repository.isSnapshots());
    stagingRepository.setSkipPackedIndexCreation(repository.isSkipPackedIndexCreation());
    // stagingRepository.getDescription("")
    return stagingRepository;
}
Also used : Path(java.nio.file.Path) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

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