Search in sources :

Example 61 with Configuration

use of org.apache.archiva.configuration.Configuration 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 62 with Configuration

use of org.apache.archiva.configuration.Configuration 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)

Example 63 with Configuration

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

the class Maven2RepositoryMergerTest method testMerge.

@Test
public void testMerge() throws Exception {
    String targetRepoPath = "target/test-repository-target";
    Path mergedArtifact = Paths.get(targetRepoPath, "com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100308.230825-1.jar");
    Path mavenMetadata = Paths.get(targetRepoPath, "com/example/test/test-artifact/maven-metadata.xml");
    Path pom = Paths.get(targetRepoPath, "com/example/test/test-artifact/1.0-SNAPSHOT/test-artifact-1.0-20100308.230825-1.pom");
    assertFalse(Files.exists(mergedArtifact));
    assertFalse(Files.exists(mavenMetadata));
    assertFalse(Files.exists(pom));
    Configuration c = new Configuration();
    ManagedRepositoryConfiguration testRepo = new ManagedRepositoryConfiguration();
    testRepo.setId(TEST_REPO_ID);
    testRepo.setLocation("target/test-repository");
    RepositoryScanningConfiguration repoScanConfig = new RepositoryScanningConfiguration();
    List<String> knownContentConsumers = new ArrayList<>();
    knownContentConsumers.add("metadata-updater12");
    repoScanConfig.setKnownContentConsumers(knownContentConsumers);
    c.setRepositoryScanning(repoScanConfig);
    ManagedRepositoryConfiguration targetRepo = new ManagedRepositoryConfiguration();
    targetRepo.setId("target-rep");
    targetRepo.setLocation(targetRepoPath);
    c.addManagedRepository(testRepo);
    c.addManagedRepository(targetRepo);
    configuration.save(c);
    when(metadataRepository.getArtifacts(TEST_REPO_ID)).thenReturn(getArtifacts());
    repositoryMerger.merge(metadataRepository, TEST_REPO_ID, "target-rep");
    verify(metadataRepository).getArtifacts(TEST_REPO_ID);
    assertTrue(Files.exists(mergedArtifact));
    assertTrue(Files.exists(mavenMetadata));
    assertTrue(Files.exists(pom));
}
Also used : Path(java.nio.file.Path) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) RepositoryScanningConfiguration(org.apache.archiva.configuration.RepositoryScanningConfiguration) ArchivaConfiguration(org.apache.archiva.configuration.ArchivaConfiguration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Configuration(org.apache.archiva.configuration.Configuration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) ArrayList(java.util.ArrayList) RepositoryScanningConfiguration(org.apache.archiva.configuration.RepositoryScanningConfiguration) Test(org.junit.Test)

Aggregations

Configuration (org.apache.archiva.configuration.Configuration)63 ArchivaConfiguration (org.apache.archiva.configuration.ArchivaConfiguration)30 ManagedRepositoryConfiguration (org.apache.archiva.configuration.ManagedRepositoryConfiguration)29 ProxyConnectorConfiguration (org.apache.archiva.configuration.ProxyConnectorConfiguration)21 RemoteRepositoryConfiguration (org.apache.archiva.configuration.RemoteRepositoryConfiguration)19 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)18 ContextConfiguration (org.springframework.test.context.ContextConfiguration)16 NetworkConfiguration (org.apache.archiva.admin.model.beans.NetworkConfiguration)13 UiConfiguration (org.apache.archiva.admin.model.beans.UiConfiguration)13 WebappConfiguration (org.apache.archiva.configuration.WebappConfiguration)13 IndeterminateConfigurationException (org.apache.archiva.configuration.IndeterminateConfigurationException)11 RepositoryGroupConfiguration (org.apache.archiva.configuration.RepositoryGroupConfiguration)11 RegistryException (org.apache.archiva.redback.components.registry.RegistryException)11 Before (org.junit.Before)11 ArrayList (java.util.ArrayList)10 Test (org.junit.Test)10 Path (java.nio.file.Path)8 RepositoryException (org.apache.archiva.repository.RepositoryException)7 IOException (java.io.IOException)4 NetworkProxyConfiguration (org.apache.archiva.configuration.NetworkProxyConfiguration)4