Search in sources :

Example 26 with ManagedRepositoryConfiguration

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

the class MavenProxyPropertyLoaderTest method testLoadValidMavenProxyConfiguration.

@Test
public void testLoadValidMavenProxyConfiguration() throws IOException, InvalidConfigurationException {
    Path confFile = ArchivaConfigurationTest.getTestFile("src/test/conf/maven-proxy-complete.conf");
    Configuration configuration = new Configuration();
    NetworkProxyConfiguration proxy = new NetworkProxyConfiguration();
    proxy.setHost("original-host");
    // overwritten
    configuration.addNetworkProxy(proxy);
    loader.load(Files.newInputStream(confFile), configuration);
    Map<String, ManagedRepositoryConfiguration> repositoryIdMap = configuration.getManagedRepositoriesAsMap();
    assertEquals("Count repositories", 1, repositoryIdMap.size());
    assertRepositoryExists("maven-proxy", "target", repositoryIdMap.get("maven-proxy"));
    Map<String, RemoteRepositoryConfiguration> remoteRepositoryMap = configuration.getRemoteRepositoriesAsMap();
    assertEquals("Count repositories", 4, remoteRepositoryMap.size());
    assertRepositoryExists("local-repo", "file://target", remoteRepositoryMap.get("local-repo"));
    assertRepositoryExists("www-ibiblio-org", "http://www.ibiblio.org/maven2", remoteRepositoryMap.get("www-ibiblio-org"));
    assertRepositoryExists("dist-codehaus-org", "http://dist.codehaus.org", remoteRepositoryMap.get("dist-codehaus-org"));
    assertRepositoryExists("private-example-com", "http://private.example.com/internal", remoteRepositoryMap.get("private-example-com"));
}
Also used : Path(java.nio.file.Path) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) NetworkProxyConfiguration(org.apache.archiva.configuration.model.NetworkProxyConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) NetworkProxyConfiguration(org.apache.archiva.configuration.model.NetworkProxyConfiguration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) Test(org.junit.Test)

Example 27 with ManagedRepositoryConfiguration

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

the class RepositoryConfigurationComparatorTest method createRepository.

private ManagedRepositoryConfiguration createRepository(String id) {
    ManagedRepositoryConfiguration repo = new ManagedRepositoryConfiguration();
    repo.setId(id);
    return repo;
}
Also used : ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration)

Example 28 with ManagedRepositoryConfiguration

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

the class DependencyTreeBuilderTestMaven3 method setUp.

@Before
@Override
public void setUp() throws Exception {
    super.setUp();
    Configuration configuration = new Configuration();
    ManagedRepositoryConfiguration repoConfig = new ManagedRepositoryConfiguration();
    repoConfig.setId(TEST_REPO_ID);
    repoConfig.setLocation(Paths.get("target/test-repository").toAbsolutePath().toString());
    configuration.addManagedRepository(repoConfig);
    config.getConfiguration().getProxyConnectors().clear();
    config.save(configuration);
    repositoryRegistry.reload();
// artifactFactory = ((DefaultDependencyTreeBuilder)this.builder).getFactory();
}
Also used : ArchivaConfiguration(org.apache.archiva.configuration.provider.ArchivaConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) Before(org.junit.Before)

Example 29 with ManagedRepositoryConfiguration

use of org.apache.archiva.configuration.model.ManagedRepositoryConfiguration 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);
    assertEquals(Period.ofDays(37), artifactCleanupFeature.getRetentionPeriod());
    assertTrue(artifactCleanupFeature.isDeleteReleasedSnapshots());
    assertEquals(33, artifactCleanupFeature.getRetentionCount());
    IndexCreationFeature indexCreationFeature = mr.getFeature(IndexCreationFeature.class);
    assertNotNull(indexCreationFeature.getIndexPath());
    assertEquals("testmanaged/.index", indexCreationFeature.getIndexPath().toString());
    assertFalse(indexCreationFeature.getIndexPath().isAbsolute());
    assertTrue(indexCreationFeature.isSkipPackedIndexCreation());
    StagingRepositoryFeature stagingRepositoryFeature = mr.getFeature(StagingRepositoryFeature.class);
    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.model.ManagedRepositoryConfiguration) ArtifactCleanupFeature(org.apache.archiva.repository.features.ArtifactCleanupFeature) StagingRepositoryFeature(org.apache.archiva.repository.features.StagingRepositoryFeature) Test(org.junit.Test)

Example 30 with ManagedRepositoryConfiguration

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

the class Maven2RepositoryMerger method createFolderStructure.

private void createFolderStructure(String sourceRepoId, String targetRepoId, ArtifactMetadata artifactMetadata) throws IOException, RepositoryException {
    Configuration config = configuration.getConfiguration();
    ManagedRepositoryConfiguration targetRepoConfig = config.findManagedRepositoryById(targetRepoId);
    ManagedRepositoryConfiguration sourceRepoConfig = config.findManagedRepositoryById(sourceRepoId);
    Date lastUpdatedTimestamp = Calendar.getInstance().getTime();
    TimeZone timezone = TimeZone.getTimeZone("UTC");
    DateFormat fmt = new SimpleDateFormat("yyyyMMdd.HHmmss");
    fmt.setTimeZone(timezone);
    String timestamp = fmt.format(lastUpdatedTimestamp);
    String targetRepoPath = targetRepoConfig.getLocation();
    String sourceRepoPath = sourceRepoConfig.getLocation();
    String artifactPath = pathTranslator.toPath(artifactMetadata.getNamespace(), artifactMetadata.getProject(), artifactMetadata.getProjectVersion(), artifactMetadata.getId());
    Path sourceArtifactFile = Paths.get(sourceRepoPath, artifactPath);
    Path targetArtifactFile = Paths.get(targetRepoPath, artifactPath);
    log.debug("artifactPath {}", artifactPath);
    int lastIndex = artifactPath.lastIndexOf(RepositoryPathTranslator.PATH_SEPARATOR);
    Path targetFile = Paths.get(targetRepoPath, artifactPath.substring(0, lastIndex));
    if (!Files.exists(targetFile)) {
        // create the folder structure when it does not exist
        Files.createDirectories(targetFile);
    }
    // artifact copying
    copyFile(sourceArtifactFile, targetArtifactFile);
    // pom file copying
    // TODO need to use path translator to get the pom file path
    // String fileName = artifactMetadata.getProject() + "-" + artifactMetadata.getVersion() + ".pom";
    // 
    // File sourcePomFile =
    // pathTranslator.toFile( new File( sourceRepoPath ), artifactMetadata.getId(), artifactMetadata.getProject(),
    // artifactMetadata.getVersion(), fileName );
    // 
    // String relativePathToPomFile = sourcePomFile.getAbsolutePath().split( sourceRepoPath )[1];
    // File targetPomFile = new File( targetRepoPath, relativePathToPomFile );
    // pom file copying  (file path is taken with out using path translator)
    String index = artifactPath.substring(lastIndex + 1);
    int last = index.lastIndexOf('.');
    Path sourcePomFile = Paths.get(sourceRepoPath, artifactPath.substring(0, lastIndex) + "/" + artifactPath.substring(lastIndex + 1).substring(0, last) + ".pom");
    Path targetPomFile = Paths.get(targetRepoPath, artifactPath.substring(0, lastIndex) + "/" + artifactPath.substring(lastIndex + 1).substring(0, last) + ".pom");
    if (!Files.exists(targetPomFile) && Files.exists(sourcePomFile)) {
        copyFile(sourcePomFile, targetPomFile);
    }
    // explicitly update only if metadata-updater consumer is not enabled!
    if (!config.getRepositoryScanning().getKnownContentConsumers().contains("metadata-updater")) {
        // updating version metadata files
        FilesystemStorage fsStorage = new FilesystemStorage(Paths.get(sourceRepoPath), new DefaultFileLockManager());
        StorageAsset versionMetaDataFileInSourceRepo = pathTranslator.toFile(new FilesystemAsset(fsStorage, "", Paths.get(sourceRepoPath)), artifactMetadata.getNamespace(), artifactMetadata.getProject(), artifactMetadata.getVersion(), METADATA_FILENAME);
        if (versionMetaDataFileInSourceRepo.exists()) {
            // Pattern quote for windows path
            String relativePathToVersionMetadataFile = getRelativeAssetPath(versionMetaDataFileInSourceRepo);
            Path versionMetaDataFileInTargetRepo = Paths.get(targetRepoPath, relativePathToVersionMetadataFile);
            if (!Files.exists(versionMetaDataFileInTargetRepo)) {
                copyFile(versionMetaDataFileInSourceRepo.getFilePath(), versionMetaDataFileInTargetRepo);
            } else {
                updateVersionMetadata(versionMetaDataFileInTargetRepo, artifactMetadata, lastUpdatedTimestamp);
            }
        }
        // updating project meta data file
        StorageAsset projectDirectoryInSourceRepo = versionMetaDataFileInSourceRepo.getParent().getParent();
        StorageAsset projectMetadataFileInSourceRepo = projectDirectoryInSourceRepo.resolve(METADATA_FILENAME);
        if (projectMetadataFileInSourceRepo.exists()) {
            String relativePathToProjectMetadataFile = getRelativeAssetPath(projectMetadataFileInSourceRepo);
            Path projectMetadataFileInTargetRepo = Paths.get(targetRepoPath, relativePathToProjectMetadataFile);
            if (!Files.exists(projectMetadataFileInTargetRepo)) {
                copyFile(projectMetadataFileInSourceRepo.getFilePath(), projectMetadataFileInTargetRepo);
            } else {
                updateProjectMetadata(projectMetadataFileInTargetRepo, artifactMetadata, lastUpdatedTimestamp, timestamp);
            }
        }
    }
}
Also used : Path(java.nio.file.Path) ArchivaConfiguration(org.apache.archiva.configuration.provider.ArchivaConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) FilesystemStorage(org.apache.archiva.repository.storage.fs.FilesystemStorage) FilesystemAsset(org.apache.archiva.repository.storage.fs.FilesystemAsset) Date(java.util.Date) TimeZone(java.util.TimeZone) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) StorageAsset(org.apache.archiva.repository.storage.StorageAsset) DefaultFileLockManager(org.apache.archiva.common.filelock.DefaultFileLockManager) SimpleDateFormat(java.text.SimpleDateFormat)

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