Search in sources :

Example 41 with ManagedRepositoryConfiguration

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

the class FileMetadataRepositoryTest method createManagedRepository.

private static ManagedRepositoryConfiguration createManagedRepository(String repoId, Path directory) {
    ManagedRepositoryConfiguration managedRepository = new ManagedRepositoryConfiguration();
    managedRepository.setId(repoId);
    managedRepository.setLocation(directory.resolve(repoId).toAbsolutePath().toString());
    return managedRepository;
}
Also used : ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration)

Example 42 with ManagedRepositoryConfiguration

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

the class Maven2RepositoryMetadataResolverMRM1411RepoGroupTest method setUp.

@Before
@Override
public void setUp() throws Exception {
    super.setUp();
    c = new Configuration();
    testRepo = new ManagedRepositoryConfiguration();
    testRepo.setId(TEST_REPO_ID);
    testRepo.setLocation(Paths.get("target/test-repository").toAbsolutePath().toString());
    testRepo.setReleases(true);
    testRepo.setSnapshots(false);
    c.addManagedRepository(testRepo);
    testRepoS = new ManagedRepositoryConfiguration();
    testRepoS.setId(TEST_SNAP_REPO_ID);
    testRepoS.setLocation(Paths.get("target/test-repositorys").toAbsolutePath().toString());
    testRepoS.setReleases(false);
    testRepoS.setSnapshots(true);
    c.addManagedRepository(testRepoS);
    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);
    ProxyConnectorConfiguration proxyConnectors = new ProxyConnectorConfiguration();
    proxyConnectors.setSourceRepoId(TEST_SNAP_REPO_ID);
    proxyConnectors.setTargetRepoId(TEST_REMOTE_REPO_ID);
    proxyConnectors.setDisabled(false);
    c.addProxyConnector(proxyConnectors);
    List<String> repos = new ArrayList<>();
    repos.add(TEST_REPO_ID);
    repos.add(TEST_SNAP_REPO_ID);
    RepositoryGroupConfiguration repoGroup = new RepositoryGroupConfiguration();
    repoGroup.setId(TEST_REPO_GROUP_ID);
    repoGroup.setRepositories(repos);
    c.addRepositoryGroup(repoGroup);
    configuration.save(c);
    repositoryRegistry.reload();
    assertFalse(c.getManagedRepositories().get(0).isSnapshots());
    assertTrue(c.getManagedRepositories().get(0).isReleases());
    assertTrue(c.getManagedRepositories().get(1).isSnapshots());
    assertFalse(c.getManagedRepositories().get(1).isReleases());
    wagonFactory = mock(WagonFactory.class);
    storage.setWagonFactory(wagonFactory);
    Wagon wagon = new MockWagon();
    when(wagonFactory.getWagon(new WagonFactoryRequest().protocol("wagon#http"))).thenReturn(wagon);
}
Also used : RepositoryGroupConfiguration(org.apache.archiva.configuration.RepositoryGroupConfiguration) WagonFactoryRequest(org.apache.archiva.proxy.common.WagonFactoryRequest) ArchivaConfiguration(org.apache.archiva.configuration.ArchivaConfiguration) RepositoryGroupConfiguration(org.apache.archiva.configuration.RepositoryGroupConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.ProxyConnectorConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Configuration(org.apache.archiva.configuration.Configuration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) ArrayList(java.util.ArrayList) RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.ProxyConnectorConfiguration) WagonFactory(org.apache.archiva.proxy.common.WagonFactory) Wagon(org.apache.maven.wagon.Wagon) Before(org.junit.Before)

Example 43 with ManagedRepositoryConfiguration

use of org.apache.archiva.configuration.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.save(configuration);
// artifactFactory = ((DefaultDependencyTreeBuilder)this.builder).getFactory();
}
Also used : ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) ArchivaConfiguration(org.apache.archiva.configuration.ArchivaConfiguration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Configuration(org.apache.archiva.configuration.Configuration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) Before(org.junit.Before)

Example 44 with ManagedRepositoryConfiguration

use of org.apache.archiva.configuration.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).get();
    cfg.setStageRepoNeeded(stagingRepositoryFeature.isStageRepoNeeded());
    IndexCreationFeature indexCreationFeature = managedRepository.getFeature(IndexCreationFeature.class).get();
    cfg.setIndexDir(convertUriToPath(indexCreationFeature.getIndexPath()));
    cfg.setPackedIndexDir(convertUriToPath(indexCreationFeature.getPackedIndexPath()));
    cfg.setSkipPackedIndexCreation(indexCreationFeature.isSkipPackedIndexCreation());
    ArtifactCleanupFeature artifactCleanupFeature = managedRepository.getFeature(ArtifactCleanupFeature.class).get();
    cfg.setRetentionCount(artifactCleanupFeature.getRetentionCount());
    cfg.setRetentionPeriod(artifactCleanupFeature.getRetentionPeriod().getDays());
    cfg.setDeleteReleasedSnapshots(artifactCleanupFeature.isDeleteReleasedSnapshots());
    if (managedRepository.getActiveReleaseSchemes().contains(ReleaseScheme.RELEASE)) {
        cfg.setReleases(true);
    } else {
        cfg.setReleases(false);
    }
    if (managedRepository.getActiveReleaseSchemes().contains(ReleaseScheme.SNAPSHOT)) {
        cfg.setSnapshots(true);
    } else {
        cfg.setSnapshots(false);
    }
    return cfg;
}
Also used : BasicManagedRepository(org.apache.archiva.repository.BasicManagedRepository) IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) RepositoryException(org.apache.archiva.repository.RepositoryException) ArtifactCleanupFeature(org.apache.archiva.repository.features.ArtifactCleanupFeature) StagingRepositoryFeature(org.apache.archiva.repository.features.StagingRepositoryFeature)

Example 45 with ManagedRepositoryConfiguration

use of org.apache.archiva.configuration.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
        Path versionMetaDataFileInSourceRepo = pathTranslator.toFile(Paths.get(sourceRepoPath), artifactMetadata.getNamespace(), artifactMetadata.getProject(), artifactMetadata.getVersion(), METADATA_FILENAME);
        if (Files.exists(versionMetaDataFileInSourceRepo)) {
            // Pattern quote for windows path
            String relativePathToVersionMetadataFile = versionMetaDataFileInSourceRepo.toAbsolutePath().toString().split(Pattern.quote(sourceRepoPath))[1];
            Path versionMetaDataFileInTargetRepo = Paths.get(targetRepoPath, relativePathToVersionMetadataFile);
            if (!Files.exists(versionMetaDataFileInTargetRepo)) {
                copyFile(versionMetaDataFileInSourceRepo, versionMetaDataFileInTargetRepo);
            } else {
                updateVersionMetadata(versionMetaDataFileInTargetRepo, artifactMetadata, lastUpdatedTimestamp);
            }
        }
        // updating project meta data file
        Path projectDirectoryInSourceRepo = versionMetaDataFileInSourceRepo.getParent().getParent();
        Path projectMetadataFileInSourceRepo = projectDirectoryInSourceRepo.resolve(METADATA_FILENAME);
        if (Files.exists(projectMetadataFileInSourceRepo)) {
            String relativePathToProjectMetadataFile = projectMetadataFileInSourceRepo.toAbsolutePath().toString().split(Pattern.quote(sourceRepoPath))[1];
            Path projectMetadataFileInTargetRepo = Paths.get(targetRepoPath, relativePathToProjectMetadataFile);
            if (!Files.exists(projectMetadataFileInTargetRepo)) {
                copyFile(projectMetadataFileInSourceRepo, projectMetadataFileInTargetRepo);
            } else {
                updateProjectMetadata(projectMetadataFileInTargetRepo, artifactMetadata, lastUpdatedTimestamp, timestamp);
            }
        }
    }
}
Also used : Path(java.nio.file.Path) TimeZone(java.util.TimeZone) ArchivaConfiguration(org.apache.archiva.configuration.ArchivaConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) Configuration(org.apache.archiva.configuration.Configuration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Aggregations

ManagedRepositoryConfiguration (org.apache.archiva.configuration.ManagedRepositoryConfiguration)46 Configuration (org.apache.archiva.configuration.Configuration)17 ArchivaConfiguration (org.apache.archiva.configuration.ArchivaConfiguration)14 Path (java.nio.file.Path)9 ProxyConnectorConfiguration (org.apache.archiva.configuration.ProxyConnectorConfiguration)9 Before (org.junit.Before)9 ContextConfiguration (org.springframework.test.context.ContextConfiguration)9 Test (org.junit.Test)8 IndeterminateConfigurationException (org.apache.archiva.configuration.IndeterminateConfigurationException)7 RemoteRepositoryConfiguration (org.apache.archiva.configuration.RemoteRepositoryConfiguration)7 RegistryException (org.apache.archiva.redback.components.registry.RegistryException)7 StagingRepositoryFeature (org.apache.archiva.repository.features.StagingRepositoryFeature)7 ArrayList (java.util.ArrayList)6 RepositoryGroupConfiguration (org.apache.archiva.configuration.RepositoryGroupConfiguration)5 IndexUpdateFailedException (org.apache.archiva.indexer.IndexUpdateFailedException)5 ArtifactCleanupFeature (org.apache.archiva.repository.features.ArtifactCleanupFeature)5 IndexCreationFeature (org.apache.archiva.repository.features.IndexCreationFeature)5 IOException (java.io.IOException)4 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)4 RepositoryException (org.apache.archiva.repository.RepositoryException)4