Search in sources :

Example 1 with IndexCreationFeature

use of org.apache.archiva.repository.features.IndexCreationFeature in project archiva by apache.

the class ArchivaIndexManagerMock method getIndexPath.

private Path getIndexPath(Repository repo) throws IOException {
    IndexCreationFeature icf = repo.getFeature(IndexCreationFeature.class).get();
    Path repoDir = repo.getLocalPath();
    URI indexDir = icf.getIndexPath();
    Path indexDirectory = null;
    if (!StringUtils.isEmpty(indexDir.toString())) {
        indexDirectory = PathUtil.getPathFromUri(indexDir);
        // not absolute so create it in repository directory
        if (!indexDirectory.isAbsolute()) {
            indexDirectory = repoDir.resolve(indexDirectory);
        }
    } else {
        indexDirectory = repoDir.resolve(".index");
    }
    if (!Files.exists(indexDirectory)) {
        Files.createDirectories(indexDirectory);
    }
    return indexDirectory;
}
Also used : Path(java.nio.file.Path) IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) URI(java.net.URI)

Example 2 with IndexCreationFeature

use of org.apache.archiva.repository.features.IndexCreationFeature in project archiva by apache.

the class MavenRepositoryProviderTest method getManagedConfiguration.

@Test
public void getManagedConfiguration() throws Exception {
    MavenManagedRepository repo = new MavenManagedRepository("test01", "My Test repo", Paths.get("target/repositories"));
    repo.setLocation(new URI("file:///this.is/a/test"));
    repo.setScanned(true);
    repo.setDescription(repo.getPrimaryLocale(), "This is a description");
    repo.setLayout("maven2");
    repo.setBlocksRedeployment(true);
    repo.setName(repo.getPrimaryLocale(), "test0002");
    repo.setSchedulingDefinition("0 0 05 ? * WED");
    repo.addActiveReleaseScheme(ReleaseScheme.RELEASE);
    repo.addActiveReleaseScheme(ReleaseScheme.SNAPSHOT);
    StagingRepositoryFeature stagingFeat = repo.getFeature(StagingRepositoryFeature.class).get();
    stagingFeat.setStageRepoNeeded(true);
    IndexCreationFeature indexCreationFeature = repo.getFeature(IndexCreationFeature.class).get();
    indexCreationFeature.setIndexPath(new URI("test/.indexes"));
    indexCreationFeature.setSkipPackedIndexCreation(true);
    ArtifactCleanupFeature artifactCleanupFeature = repo.getFeature(ArtifactCleanupFeature.class).get();
    artifactCleanupFeature.setRetentionPeriod(Period.ofDays(5));
    artifactCleanupFeature.setRetentionCount(7);
    artifactCleanupFeature.setDeleteReleasedSnapshots(true);
    ManagedRepositoryConfiguration cfg = provider.getManagedConfiguration(repo);
    assertEquals("/this.is/a/test", cfg.getLocation());
    assertTrue(cfg.isScanned());
    assertEquals("This is a description", cfg.getDescription());
    assertEquals("maven2", cfg.getLayout());
    assertTrue(cfg.isBlockRedeployments());
    assertEquals("test0002", cfg.getName());
    assertEquals("0 0 05 ? * WED", cfg.getRefreshCronExpression());
    assertTrue(cfg.isStageRepoNeeded());
    assertEquals("test/.indexes", cfg.getIndexDir());
    assertTrue(cfg.isSkipPackedIndexCreation());
    assertEquals(5, cfg.getRetentionPeriod());
    assertEquals(7, cfg.getRetentionCount());
    assertTrue(cfg.isDeleteReleasedSnapshots());
    assertTrue(cfg.isReleases());
    assertTrue(cfg.isSnapshots());
    assertTrue(cfg.isScanned());
}
Also used : IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) ArtifactCleanupFeature(org.apache.archiva.repository.features.ArtifactCleanupFeature) StagingRepositoryFeature(org.apache.archiva.repository.features.StagingRepositoryFeature) URI(java.net.URI) Test(org.junit.Test)

Example 3 with IndexCreationFeature

use of org.apache.archiva.repository.features.IndexCreationFeature in project archiva by apache.

the class MavenRepositoryProviderTest method getRemoteConfiguration.

@Test
public void getRemoteConfiguration() throws Exception {
    MavenRemoteRepository repo = new MavenRemoteRepository("test01", "My Test repo", Paths.get("target/remotes"));
    repo.setLocation(new URI("https://this.is/a/test"));
    repo.setScanned(true);
    repo.setDescription(repo.getPrimaryLocale(), "This is a description");
    repo.setLayout("maven2");
    repo.setName(repo.getPrimaryLocale(), "test0003");
    repo.setSchedulingDefinition("0 0 05 ? * WED");
    RemoteIndexFeature remoteIndexFeature = repo.getFeature(RemoteIndexFeature.class).get();
    remoteIndexFeature.setProxyId("proxyabc");
    remoteIndexFeature.setDownloadTimeout(Duration.ofSeconds(54));
    remoteIndexFeature.setDownloadRemoteIndex(false);
    remoteIndexFeature.setIndexUri(new URI("/this/remote/.index"));
    remoteIndexFeature.setDownloadRemoteIndexOnStartup(true);
    IndexCreationFeature indexCreationFeature = repo.getFeature(IndexCreationFeature.class).get();
    indexCreationFeature.setIndexPath(new URI("/this/local/.index"));
    RemoteRepositoryConfiguration cfg = provider.getRemoteConfiguration(repo);
    assertEquals("https://this.is/a/test", cfg.getUrl());
    assertEquals("This is a description", cfg.getDescription());
    assertEquals("maven2", cfg.getLayout());
    assertEquals("test0003", cfg.getName());
    assertEquals("0 0 05 ? * WED", cfg.getRefreshCronExpression());
    assertEquals("/this/remote/.index", cfg.getRemoteIndexUrl());
    assertEquals("proxyabc", cfg.getRemoteDownloadNetworkProxyId());
    assertEquals(54, cfg.getRemoteDownloadTimeout());
    assertFalse(cfg.isDownloadRemoteIndex());
    assertTrue(cfg.isDownloadRemoteIndexOnStartup());
    assertEquals("/this/local/.index", cfg.getIndexDir());
}
Also used : IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) RemoteIndexFeature(org.apache.archiva.repository.features.RemoteIndexFeature) RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration) URI(java.net.URI) Test(org.junit.Test)

Example 4 with IndexCreationFeature

use of org.apache.archiva.repository.features.IndexCreationFeature in project archiva by apache.

the class MavenRepositoryProviderTest method createManagedInstance.

@Test
public void createManagedInstance() throws Exception {
    ManagedRepositoryConfiguration repo = new ManagedRepositoryConfiguration();
    repo.setId("testm001");
    repo.setName("Managed Test Repo 001");
    repo.setDescription("This is a managed test");
    repo.setRetentionPeriod(37);
    repoLocation = Files.createTempDirectory("test-repo-001");
    repo.setLocation(repoLocation.toAbsolutePath().toString());
    repo.setSnapshots(true);
    repo.setReleases(true);
    repo.setRefreshCronExpression("4 0 0 ? * TUE");
    repo.setScanned(true);
    repo.setBlockRedeployments(true);
    repo.setDeleteReleasedSnapshots(true);
    repo.setRetentionCount(33);
    repo.setSkipPackedIndexCreation(true);
    repo.setStageRepoNeeded(true);
    repo.setIndexDir("testmanaged/.index");
    repo.setLayout("maven2");
    repo.setType(RepositoryType.MAVEN.toString());
    ManagedRepository mr = provider.createManagedInstance(repo);
    assertNotNull(mr.getLocation());
    String repoUri = repoLocation.toUri().toString();
    assertTrue(Files.exists(repoLocation));
    repoUri = repoUri.substring(0, repoUri.length() - 1);
    assertEquals(repoUri, mr.getLocation().toString());
    assertEquals("This is a managed test", mr.getDescription());
    assertEquals("Managed Test Repo 001", mr.getName());
    assertEquals(2, mr.getActiveReleaseSchemes().size());
    assertTrue(mr.getActiveReleaseSchemes().contains(ReleaseScheme.RELEASE));
    assertTrue(mr.getActiveReleaseSchemes().contains(ReleaseScheme.SNAPSHOT));
    assertEquals("testm001", mr.getId());
    assertTrue(mr.blocksRedeployments());
    assertEquals("4 0 0 ? * TUE", mr.getSchedulingDefinition());
    assertTrue(mr.isScanned());
    ArtifactCleanupFeature artifactCleanupFeature = mr.getFeature(ArtifactCleanupFeature.class).get();
    assertEquals(Period.ofDays(37), artifactCleanupFeature.getRetentionPeriod());
    assertTrue(artifactCleanupFeature.isDeleteReleasedSnapshots());
    assertEquals(33, artifactCleanupFeature.getRetentionCount());
    IndexCreationFeature indexCreationFeature = mr.getFeature(IndexCreationFeature.class).get();
    assertNotNull(indexCreationFeature.getIndexPath());
    assertEquals("testmanaged/.index", indexCreationFeature.getIndexPath().toString());
    assertFalse(indexCreationFeature.getIndexPath().isAbsolute());
    assertTrue(indexCreationFeature.isSkipPackedIndexCreation());
    StagingRepositoryFeature stagingRepositoryFeature = mr.getFeature(StagingRepositoryFeature.class).get();
    assertTrue(stagingRepositoryFeature.isStageRepoNeeded());
    assertNull(stagingRepositoryFeature.getStagingRepository());
}
Also used : IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) ManagedRepository(org.apache.archiva.repository.ManagedRepository) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) ArtifactCleanupFeature(org.apache.archiva.repository.features.ArtifactCleanupFeature) StagingRepositoryFeature(org.apache.archiva.repository.features.StagingRepositoryFeature) Test(org.junit.Test)

Example 5 with IndexCreationFeature

use of org.apache.archiva.repository.features.IndexCreationFeature in project archiva by apache.

the class MavenRepositoryProvider method updateManagedInstance.

@Override
public void updateManagedInstance(EditableManagedRepository repo, ManagedRepositoryConfiguration cfg) throws RepositoryException {
    try {
        repo.setLocation(getURIFromString(cfg.getLocation()));
    } catch (UnsupportedURIException e) {
        throw new RepositoryException("The location entry is not a valid uri: " + cfg.getLocation());
    }
    setBaseConfig(repo, cfg);
    Path repoDir = repo.getLocalPath();
    if (!Files.exists(repoDir)) {
        log.debug("Creating repo directory {}", repoDir);
        try {
            Files.createDirectories(repoDir);
        } catch (IOException e) {
            log.error("Could not create directory {} for repository {}", repo.getLocalPath(), repo.getId(), e);
            throw new RepositoryException("Could not create directory for repository " + repo.getLocalPath());
        }
    }
    repo.setSchedulingDefinition(cfg.getRefreshCronExpression());
    repo.setBlocksRedeployment(cfg.isBlockRedeployments());
    repo.setScanned(cfg.isScanned());
    if (cfg.isReleases()) {
        repo.addActiveReleaseScheme(ReleaseScheme.RELEASE);
    }
    if (cfg.isSnapshots()) {
        repo.addActiveReleaseScheme(ReleaseScheme.SNAPSHOT);
    }
    StagingRepositoryFeature stagingRepositoryFeature = repo.getFeature(StagingRepositoryFeature.class).get();
    stagingRepositoryFeature.setStageRepoNeeded(cfg.isStageRepoNeeded());
    IndexCreationFeature indexCreationFeature = repo.getFeature(IndexCreationFeature.class).get();
    indexCreationFeature.setSkipPackedIndexCreation(cfg.isSkipPackedIndexCreation());
    indexCreationFeature.setIndexPath(getURIFromString(cfg.getIndexDir()));
    indexCreationFeature.setPackedIndexPath(getURIFromString(cfg.getPackedIndexDir()));
    /* -> Should be created by MavenIndexProvider

        Path indexPath;
        if (indexCreationFeature.getIndexPath().getScheme() == null) {
            indexPath = Paths.get(indexCreationFeature.getIndexPath().getPath());
        } else {
            indexPath = Paths.get(indexCreationFeature.getIndexPath());
        }
        Path absoluteIndexPath;
        if (indexPath.isAbsolute()) {
            absoluteIndexPath = indexPath;
        } else {
            absoluteIndexPath = PathUtil.getPathFromUri(repo.getLocation()).resolve(indexCreationFeature.getIndexPath().getPath());
        }
        try {
            Files.createDirectories(absoluteIndexPath);
        } catch (IOException e) {
            log.error("Could not create index directory {}", absoluteIndexPath);
            throw new RepositoryException("Could not create index directory " + absoluteIndexPath);
        }*/
    ArtifactCleanupFeature artifactCleanupFeature = repo.getFeature(ArtifactCleanupFeature.class).get();
    artifactCleanupFeature.setDeleteReleasedSnapshots(cfg.isDeleteReleasedSnapshots());
    artifactCleanupFeature.setRetentionCount(cfg.getRetentionCount());
    artifactCleanupFeature.setRetentionPeriod(Period.ofDays(cfg.getRetentionPeriod()));
}
Also used : Path(java.nio.file.Path) IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) UnsupportedURIException(org.apache.archiva.repository.UnsupportedURIException) RepositoryException(org.apache.archiva.repository.RepositoryException) IOException(java.io.IOException) ArtifactCleanupFeature(org.apache.archiva.repository.features.ArtifactCleanupFeature) StagingRepositoryFeature(org.apache.archiva.repository.features.StagingRepositoryFeature)

Aggregations

IndexCreationFeature (org.apache.archiva.repository.features.IndexCreationFeature)27 URI (java.net.URI)11 ArtifactCleanupFeature (org.apache.archiva.repository.features.ArtifactCleanupFeature)10 StagingRepositoryFeature (org.apache.archiva.repository.features.StagingRepositoryFeature)10 Path (java.nio.file.Path)9 RepositoryException (org.apache.archiva.repository.RepositoryException)6 IOException (java.io.IOException)5 ManagedRepositoryConfiguration (org.apache.archiva.configuration.ManagedRepositoryConfiguration)5 RemoteIndexFeature (org.apache.archiva.repository.features.RemoteIndexFeature)5 Test (org.junit.Test)5 PasswordCredentials (org.apache.archiva.repository.PasswordCredentials)4 RemoteRepositoryConfiguration (org.apache.archiva.configuration.RemoteRepositoryConfiguration)3 ManagedRepository (org.apache.archiva.repository.ManagedRepository)3 BasicManagedRepository (org.apache.archiva.repository.BasicManagedRepository)2 RemoteRepository (org.apache.archiva.repository.RemoteRepository)2 RepositoryCredentials (org.apache.archiva.repository.RepositoryCredentials)2 UnsupportedURIException (org.apache.archiva.repository.UnsupportedURIException)2 IndexingContext (org.apache.maven.index.context.IndexingContext)2 URISyntaxException (java.net.URISyntaxException)1 Files (java.nio.file.Files)1