Search in sources :

Example 46 with ManagedRepositoryConfiguration

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

the class MavenRepositoryProvider method getManagedConfiguration.

@Override
public ManagedRepositoryConfiguration getManagedConfiguration(ManagedRepository managedRepository) throws RepositoryException {
    if (!(managedRepository instanceof MavenManagedRepository || managedRepository instanceof BasicManagedRepository)) {
        log.error("Wrong remote repository type " + managedRepository.getClass().getName());
        throw new RepositoryException("The given repository type cannot be handled by the maven provider: " + managedRepository.getClass().getName());
    }
    ManagedRepositoryConfiguration cfg = new ManagedRepositoryConfiguration();
    cfg.setType(managedRepository.getType().toString());
    cfg.setId(managedRepository.getId());
    cfg.setName(managedRepository.getName());
    cfg.setDescription(managedRepository.getDescription());
    cfg.setLocation(convertUriToPath(managedRepository.getLocation()));
    cfg.setLayout(managedRepository.getLayout());
    cfg.setRefreshCronExpression(managedRepository.getSchedulingDefinition());
    cfg.setScanned(managedRepository.isScanned());
    cfg.setBlockRedeployments(managedRepository.blocksRedeployments());
    StagingRepositoryFeature stagingRepositoryFeature = managedRepository.getFeature(StagingRepositoryFeature.class);
    cfg.setStageRepoNeeded(stagingRepositoryFeature.isStageRepoNeeded());
    IndexCreationFeature indexCreationFeature = managedRepository.getFeature(IndexCreationFeature.class);
    cfg.setIndexDir(convertUriToPath(indexCreationFeature.getIndexPath()));
    cfg.setPackedIndexDir(convertUriToPath(indexCreationFeature.getPackedIndexPath()));
    cfg.setSkipPackedIndexCreation(indexCreationFeature.isSkipPackedIndexCreation());
    ArtifactCleanupFeature artifactCleanupFeature = managedRepository.getFeature(ArtifactCleanupFeature.class);
    cfg.setRetentionCount(artifactCleanupFeature.getRetentionCount());
    cfg.setRetentionPeriod(artifactCleanupFeature.getRetentionPeriod().getDays());
    cfg.setDeleteReleasedSnapshots(artifactCleanupFeature.isDeleteReleasedSnapshots());
    cfg.setReleases(managedRepository.getActiveReleaseSchemes().contains(ReleaseScheme.RELEASE));
    cfg.setSnapshots(managedRepository.getActiveReleaseSchemes().contains(ReleaseScheme.SNAPSHOT));
    return cfg;
}
Also used : BasicManagedRepository(org.apache.archiva.repository.base.managed.BasicManagedRepository) IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) RepositoryException(org.apache.archiva.repository.RepositoryException) ArtifactCleanupFeature(org.apache.archiva.repository.features.ArtifactCleanupFeature) StagingRepositoryFeature(org.apache.archiva.repository.features.StagingRepositoryFeature)

Example 47 with ManagedRepositoryConfiguration

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

the class Maven2RepositoryMetadataResolverTest method setUp.

@Before
@Override
public void setUp() throws Exception {
    super.setUp();
    c = new Configuration();
    c.setVersion("2.0");
    testRepo = new ManagedRepositoryConfiguration();
    testRepo.setId(TEST_REPO_ID);
    testRepo.setLocation(Paths.get("target/test-repository").toAbsolutePath().toString());
    testRepo.setReleases(true);
    testRepo.setSnapshots(true);
    c.addManagedRepository(testRepo);
    RemoteRepositoryConfiguration testRemoteRepo = new RemoteRepositoryConfiguration();
    testRemoteRepo.setId(TEST_REMOTE_REPO_ID);
    testRemoteRepo.setLayout("default");
    testRemoteRepo.setName("Central Repository");
    testRemoteRepo.setUrl("http://central.repo.com/maven2");
    testRemoteRepo.setTimeout(10);
    c.addRemoteRepository(testRemoteRepo);
    ProxyConnectorConfiguration proxyConnector = new ProxyConnectorConfiguration();
    proxyConnector.setSourceRepoId(TEST_REPO_ID);
    proxyConnector.setTargetRepoId(TEST_REMOTE_REPO_ID);
    proxyConnector.setDisabled(false);
    c.addProxyConnector(proxyConnector);
    RepositoryScanningConfiguration scCfg = new RepositoryScanningConfiguration();
    c.setRepositoryScanning(scCfg);
    configuration.save(c);
    assertFalse(configuration.isDefaulted());
    repositoryRegistry.reload();
    assertTrue(c.getManagedRepositories().get(0).isSnapshots());
    assertTrue(c.getManagedRepositories().get(0).isReleases());
    wagonFactory = mock(WagonFactory.class);
    storage.setWagonFactory(wagonFactory);
    Wagon wagon = new MockWagon();
    when(wagonFactory.getWagon(new WagonFactoryRequest().protocol("wagon#http"))).thenReturn(wagon);
}
Also used : WagonFactoryRequest(org.apache.archiva.maven.common.proxy.WagonFactoryRequest) ArchivaConfiguration(org.apache.archiva.configuration.provider.ArchivaConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.model.ProxyConnectorConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) RepositoryScanningConfiguration(org.apache.archiva.configuration.model.RepositoryScanningConfiguration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) RepositoryScanningConfiguration(org.apache.archiva.configuration.model.RepositoryScanningConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.model.ProxyConnectorConfiguration) WagonFactory(org.apache.archiva.maven.common.proxy.WagonFactory) Wagon(org.apache.maven.wagon.Wagon) Before(org.junit.Before)

Example 48 with ManagedRepositoryConfiguration

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

the class DefaultRepositoryArchivaTaskScheduler method configurationEvent.

@Override
public void configurationEvent(ConfigurationEvent event) {
    if (event.getType() == ConfigurationEvent.SAVED) {
        for (String job : jobs) {
            try {
                scheduler.unscheduleJob(job, REPOSITORY_SCAN_GROUP);
            } catch (SchedulerException e) {
                log.error("Error restarting the repository scanning job after property change.");
            }
        }
        jobs.clear();
        List<ManagedRepositoryConfiguration> repositories = archivaConfiguration.getConfiguration().getManagedRepositories();
        for (ManagedRepositoryConfiguration repoConfig : repositories) {
            if (repoConfig.getRefreshCronExpression() != null) {
                try {
                    scheduleRepositoryJobs(repoConfig);
                } catch (SchedulerException e) {
                    log.error("error restarting job: '{}' : '{}'", REPOSITORY_JOB, repoConfig.getId());
                }
            }
        }
    }
}
Also used : SchedulerException(org.quartz.SchedulerException) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration)

Example 49 with ManagedRepositoryConfiguration

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

the class AbstractArchivaRepositoryScanningTaskExecutorTest method setUp.

@Before
@Override
public void setUp() throws Exception {
    super.setUp();
    Path sourceRepoDir = Paths.get("src/test/repositories/default-repository");
    repoDir = Paths.get("target/default-repository");
    FileUtils.deleteDirectory(repoDir);
    assertFalse("Default Test Repository should not exist.", Files.exists(repoDir));
    Files.createDirectories(repoDir);
    org.apache.commons.io.FileUtils.copyDirectory(sourceRepoDir.toFile(), repoDir.toFile());
    // set the timestamps to a time well in the past
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.YEAR, -1);
    try (Stream<Path> stream = Files.walk(repoDir, FileVisitOption.FOLLOW_LINKS)) {
        stream.forEach(path -> {
            try {
                Files.setLastModifiedTime(path, FileTime.fromMillis(cal.getTimeInMillis()));
            } catch (IOException e) {
                e.printStackTrace();
            }
        });
    }
    PathMatcher m = FileSystems.getDefault().getPathMatcher("glob:**/.svn");
    Files.walk(repoDir, FileVisitOption.FOLLOW_LINKS).filter(Files::isDirectory).sorted(Comparator.reverseOrder()).filter(path -> m.matches(path)).forEach(path -> org.apache.archiva.common.utils.FileUtils.deleteQuietly(path));
    assertTrue("Default Test Repository should exist.", Files.exists(repoDir) && Files.isDirectory(repoDir));
    assertNotNull(archivaConfig);
    // Create it
    ManagedRepositoryConfiguration repositoryConfiguration = new ManagedRepositoryConfiguration();
    repositoryConfiguration.setId(TEST_REPO_ID);
    repositoryConfiguration.setName("Test Repository");
    repositoryConfiguration.setLocation(repoDir.toAbsolutePath().toString());
    for (ManagedRepository repo : repositoryRegistry.getManagedRepositories()) {
        repositoryRegistry.removeRepository(repo);
    }
    repositoryRegistry.putRepository(repositoryConfiguration);
    metadataRepository = mock(MetadataRepository.class);
    factory.setRepository(metadataRepository);
}
Also used : Path(java.nio.file.Path) DirtiesContext(org.springframework.test.annotation.DirtiesContext) MockRepositorySessionFactory(org.apache.archiva.mock.MockRepositorySessionFactory) ArchivaConfiguration(org.apache.archiva.configuration.provider.ArchivaConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) RunWith(org.junit.runner.RunWith) FileTime(java.nio.file.attribute.FileTime) RepositoryHandlerDependencies(org.apache.archiva.repository.base.RepositoryHandlerDependencies) Inject(javax.inject.Inject) Calendar(java.util.Calendar) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) After(org.junit.After) PathMatcher(java.nio.file.PathMatcher) FileUtils(org.apache.archiva.common.utils.FileUtils) TestCase(junit.framework.TestCase) Named(javax.inject.Named) Path(java.nio.file.Path) TaskExecutor(org.apache.archiva.components.taskqueue.execution.TaskExecutor) Before(org.junit.Before) Files(java.nio.file.Files) RepositoryRegistry(org.apache.archiva.repository.RepositoryRegistry) ArchivaSpringJUnit4ClassRunner(org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner) IOException(java.io.IOException) RepositoryTask(org.apache.archiva.scheduler.repository.model.RepositoryTask) ManagedRepository(org.apache.archiva.repository.ManagedRepository) Stream(java.util.stream.Stream) FileVisitOption(java.nio.file.FileVisitOption) Paths(java.nio.file.Paths) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Comparator(java.util.Comparator) FileSystems(java.nio.file.FileSystems) RepositoryStatisticsManager(org.apache.archiva.metadata.repository.stats.model.RepositoryStatisticsManager) RepositoryGroupHandler(org.apache.archiva.repository.base.group.RepositoryGroupHandler) Mockito.mock(org.mockito.Mockito.mock) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) PathMatcher(java.nio.file.PathMatcher) ManagedRepository(org.apache.archiva.repository.ManagedRepository) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) Calendar(java.util.Calendar) IOException(java.io.IOException) Before(org.junit.Before)

Example 50 with ManagedRepositoryConfiguration

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

the class MavenRepositoryMapperTest method updateWithNullValues.

@Test
void updateWithNullValues() {
    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(null);
    repo.setHasStagingRepository(true);
    repo.setSchedulingDefinition("0,1,2 * * * *");
    repo.setPackedIndexPath(null);
    repo.setIndexPath(null);
    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(null);
    repo.setRetentionCount(15);
    repo.setSkipPackedIndexCreation(false);
    repo.setStagingRepository(null);
    mapper.update(repo, result);
    assertNotNull(result);
    assertEquals("repo01", result.getId());
    assertEquals("Repo 01", result.getName());
    assertEquals("This is repo 01", result.getDescription());
    assertNotNull(result.getLocation());
    assertTrue(result.isStageRepoNeeded());
    assertEquals("0,1,2 * * * *", result.getRefreshCronExpression());
    assertEquals("", result.getIndexDir());
    assertEquals("", result.getPackedIndexDir());
    assertFalse(result.isDeleteReleasedSnapshots());
    assertFalse(result.isBlockRedeployments());
    assertTrue(result.isSnapshots());
    assertTrue(result.isReleases());
    assertTrue(result.isScanned());
    assertEquals(100, 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)

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