Search in sources :

Example 46 with Configuration

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

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

the class Maven2RepositoryMetadataResolverMRM1411RepoGroupTest method testGetProjectVersionMetadataWithParentNoRemoteReposConfigured.

@Test
public void testGetProjectVersionMetadataWithParentNoRemoteReposConfigured() throws Exception {
    // remove configuration
    Configuration config = configuration.getConfiguration();
    RemoteRepositoryConfiguration remoteRepo = config.findRemoteRepositoryById(TEST_REMOTE_REPO_ID);
    config.removeRemoteRepository(remoteRepo);
    configuration.save(config);
    copyTestArtifactWithParent("src/test/resources/com/example/test/test-artifact-module-a", "target/test-repository/com/example/test/test-artifact-module-a");
    copyTestArtifactWithParent("src/test/resources/com/example/test/test-artifact-root", "target/test-repository/com/example/test/test-artifact-root");
    copyTestArtifactWithParent("src/test/resources/com/example/test/test-artifact-parent", "target/test-repository/com/example/test/test-artifact-parent");
    ReadMetadataRequest readMetadataRequest = new ReadMetadataRequest().repositoryId(TEST_REPO_ID).namespace("com.example.test").projectId("test-artifact-module-a").projectVersion("1.0");
    ProjectVersionMetadata metadata = storage.readProjectVersionMetadata(readMetadataRequest);
    assertEquals("1.0", metadata.getId());
    MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet(MavenProjectFacet.FACET_ID);
    assertNotNull(facet);
    assertEquals("com.example.test", facet.getGroupId());
    assertEquals("test-artifact-module-a", facet.getArtifactId());
    assertEquals("jar", facet.getPackaging());
    List<String> paths = new ArrayList<>();
    paths.add("target/test-repository/com/example/test/test-artifact-module-a");
    paths.add("target/test-repository/com/example/test/test-artifact-parent");
    paths.add("target/test-repository/com/example/test/test-artifact-root");
    deleteTestArtifactWithParent(paths);
}
Also used : ArchivaConfiguration(org.apache.archiva.configuration.provider.ArchivaConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.model.ProxyConnectorConfiguration) RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) ReadMetadataRequest(org.apache.archiva.metadata.repository.storage.ReadMetadataRequest) ProjectVersionMetadata(org.apache.archiva.metadata.model.ProjectVersionMetadata) ArrayList(java.util.ArrayList) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) Test(org.junit.Test)

Example 48 with Configuration

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

Example 49 with Configuration

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

the class ArchivaConfigurationMRM789Test method testGetConfigurationFromDefaultsWithDefaultRepoLocationAlreadyExisting.

// test for [MRM-789]
@Test
public void testGetConfigurationFromDefaultsWithDefaultRepoLocationAlreadyExisting() throws Exception {
    Path repo = Paths.get(org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/test-classes/existing_snapshots");
    Files.createDirectories(repo);
    repo = Paths.get(org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/test-classes/existing_internal");
    Files.createDirectories(repo);
    String existingTestDefaultArchivaConfigFile = FileUtils.readFileToString(getTestFile("target/test-classes/org/apache/archiva/configuration/test-default-archiva.xml").toFile(), FILE_ENCODING);
    existingTestDefaultArchivaConfigFile = StringUtils.replace(existingTestDefaultArchivaConfigFile, "${appserver.base}", org.apache.archiva.common.utils.FileUtils.getBasedir());
    Path generatedTestDefaultArchivaConfigFile = Paths.get(org.apache.archiva.common.utils.FileUtils.getBasedir(), "target/test-classes/org/apache/archiva/configuration/default-archiva.xml");
    FileUtils.writeStringToFile(generatedTestDefaultArchivaConfigFile.toFile(), existingTestDefaultArchivaConfigFile, Charset.forName(FILE_ENCODING));
    ArchivaConfiguration archivaConfiguration = lookup(ArchivaConfiguration.class, "test-defaults-default-repo-location-exists");
    Configuration configuration = archivaConfiguration.getConfiguration();
    assertConfiguration(configuration, 2, 2, 2);
    ManagedRepositoryConfiguration repository = configuration.getManagedRepositories().get(0);
    assertTrue("check managed repositories", repository.getLocation().endsWith("data/repositories/internal"));
    Files.deleteIfExists(generatedTestDefaultArchivaConfigFile);
    assertFalse(Files.exists(generatedTestDefaultArchivaConfigFile));
}
Also used : Path(java.nio.file.Path) RepositoryScanningConfiguration(org.apache.archiva.configuration.model.RepositoryScanningConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) WebappConfiguration(org.apache.archiva.configuration.model.WebappConfiguration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) Test(org.junit.Test)

Example 50 with Configuration

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

the class DefaultArchivaConfiguration method load.

@SuppressWarnings("unchecked")
private Configuration load() {
    // TODO: should this be the same as section? make sure unnamed sections still work (eg, sys properties)
    Registry subset = registry.getSubset(KEY);
    if (subset.getString("version") == null) {
        if (subset.getSubset("repositoryScanning").isEmpty()) {
            // only for empty
            subset = readDefaultConfiguration();
        } else {
            throw new RuntimeException("No version tag found in configuration. Archiva configuration version 1.x is not longer supported.");
        }
    }
    Configuration config = new ConfigurationRegistryReader().read(subset);
    // Resolving data and repositories directories
    // If the config entries are absolute, the path is used as it is
    // if the config entries are empty, they are resolved:
    // dataDirectory = ${appserver.base}/data
    // repositoryDirectory = ${dataDirectory}/repositories
    // If the entries are relative they are resolved
    // relative to the appserver.base, for dataDirectory
    // relative to dataDirectory for repositoryBase
    String dataDir = config.getArchivaRuntimeConfiguration().getDataDirectory();
    if (StringUtils.isEmpty(dataDir)) {
        dataDirectory = getAppServerBaseDir().resolve("data");
    } else {
        Path tmpDataDir = Paths.get(dataDir);
        if (tmpDataDir.isAbsolute()) {
            dataDirectory = tmpDataDir;
        } else {
            dataDirectory = getAppServerBaseDir().resolve(tmpDataDir);
        }
    }
    config.getArchivaRuntimeConfiguration().setDataDirectory(dataDirectory.normalize().toString());
    String repoBaseDir = config.getArchivaRuntimeConfiguration().getRepositoryBaseDirectory();
    if (StringUtils.isEmpty(repoBaseDir)) {
        repositoryBaseDirectory = dataDirectory.resolve("repositories");
    } else {
        Path tmpRepoBaseDir = Paths.get(repoBaseDir);
        if (tmpRepoBaseDir.isAbsolute()) {
            repositoryBaseDirectory = tmpRepoBaseDir;
        } else {
            dataDirectory.resolve(tmpRepoBaseDir);
        }
    }
    String remoteRepoBaseDir = config.getArchivaRuntimeConfiguration().getRemoteRepositoryBaseDirectory();
    if (StringUtils.isEmpty(remoteRepoBaseDir)) {
        remoteRepositoryBaseDirectory = dataDirectory.resolve("remotes");
    } else {
        Path tmpRemoteRepoDir = Paths.get(remoteRepoBaseDir);
        if (tmpRemoteRepoDir.isAbsolute()) {
            remoteRepositoryBaseDirectory = tmpRemoteRepoDir;
        } else {
            dataDirectory.resolve(tmpRemoteRepoDir);
        }
    }
    String repositoryGroupBaseDir = config.getArchivaRuntimeConfiguration().getRepositoryGroupBaseDirectory();
    if (StringUtils.isEmpty(repositoryGroupBaseDir)) {
        repositoryGroupBaseDirectory = dataDirectory.resolve("groups");
    } else {
        Path tmpGroupDir = Paths.get(repositoryGroupBaseDir);
        if (tmpGroupDir.isAbsolute()) {
            repositoryGroupBaseDirectory = tmpGroupDir;
        } else {
            dataDirectory.resolve(tmpGroupDir);
        }
    }
    config.getRepositoryGroups();
    config.getRepositoryGroupsAsMap();
    if (!CollectionUtils.isEmpty(config.getRemoteRepositories())) {
        List<RemoteRepositoryConfiguration> remoteRepos = config.getRemoteRepositories();
        for (RemoteRepositoryConfiguration repo : remoteRepos) {
            // [MRM-582] Remote Repositories with empty <username> and <password> fields shouldn't be created in configuration.
            if (StringUtils.isBlank(repo.getUsername())) {
                repo.setUsername(null);
            }
            if (StringUtils.isBlank(repo.getPassword())) {
                repo.setPassword(null);
            }
        }
    }
    if (!config.getProxyConnectors().isEmpty()) {
        // Fix Proxy Connector Settings.
        // Create a copy of the list to read from (to prevent concurrent modification exceptions)
        List<ProxyConnectorConfiguration> proxyConnectorList = new ArrayList<>(config.getProxyConnectors());
        // Remove the old connector list.
        config.getProxyConnectors().clear();
        for (ProxyConnectorConfiguration connector : proxyConnectorList) {
            // Fix policies
            boolean connectorValid = true;
            Map<String, String> policies = new HashMap<>();
            // Make copy of policies
            policies.putAll(connector.getPolicies());
            // Clear out policies
            connector.getPolicies().clear();
            // Work thru policies. cleaning them up.
            for (Entry<String, String> entry : policies.entrySet()) {
                String policyId = entry.getKey();
                String setting = entry.getValue();
                // Upgrade old policy settings.
                if ("releases".equals(policyId) || "snapshots".equals(policyId)) {
                    if ("ignored".equals(setting)) {
                        setting = AbstractUpdatePolicy.ALWAYS.getId();
                    } else if ("disabled".equals(setting)) {
                        setting = AbstractUpdatePolicy.NEVER.getId();
                    }
                } else if ("cache-failures".equals(policyId)) {
                    if ("ignored".equals(setting)) {
                        setting = CachedFailuresPolicy.NO.getId();
                    } else if ("cached".equals(setting)) {
                        setting = CachedFailuresPolicy.YES.getId();
                    }
                } else if ("checksum".equals(policyId)) {
                    if ("ignored".equals(setting)) {
                        setting = ChecksumPolicy.IGNORE.getId();
                    }
                }
                // Validate existance of policy key.
                connector.addPolicy(policyId, setting);
            }
            if (connectorValid) {
                config.addProxyConnector(connector);
            }
        }
        // Normalize the order fields in the proxy connectors.
        Map<String, java.util.List<ProxyConnectorConfiguration>> proxyConnectorMap = config.getProxyConnectorAsMap();
        for (List<ProxyConnectorConfiguration> connectors : proxyConnectorMap.values()) {
            // Sort connectors by order field.
            Collections.sort(connectors, ProxyConnectorConfigurationOrderComparator.getInstance());
            // Normalize the order field values.
            int order = 1;
            for (ProxyConnectorConfiguration connector : connectors) {
                connector.setOrder(order++);
            }
        }
    }
    this.defaultLocale = Locale.forLanguageTag(config.getArchivaRuntimeConfiguration().getDefaultLanguage());
    this.languagePriorities = Locale.LanguageRange.parse(config.getArchivaRuntimeConfiguration().getLanguageRange());
    return config;
}
Also used : Path(java.nio.file.Path) RepositoryCheckPath(org.apache.archiva.configuration.model.RepositoryCheckPath) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.model.ProxyConnectorConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) ConfigurationRegistryReader(org.apache.archiva.configuration.provider.io.registry.ConfigurationRegistryReader) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ProxyConnectorConfiguration(org.apache.archiva.configuration.model.ProxyConnectorConfiguration) CommonsConfigurationRegistry(org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry) Registry(org.apache.archiva.components.registry.Registry) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

Configuration (org.apache.archiva.configuration.model.Configuration)94 ManagedRepositoryConfiguration (org.apache.archiva.configuration.model.ManagedRepositoryConfiguration)56 ContextConfiguration (org.springframework.test.context.ContextConfiguration)45 RemoteRepositoryConfiguration (org.apache.archiva.configuration.model.RemoteRepositoryConfiguration)42 ProxyConnectorConfiguration (org.apache.archiva.configuration.model.ProxyConnectorConfiguration)34 ArchivaConfiguration (org.apache.archiva.configuration.provider.ArchivaConfiguration)34 WebappConfiguration (org.apache.archiva.configuration.model.WebappConfiguration)32 RepositoryGroupConfiguration (org.apache.archiva.configuration.model.RepositoryGroupConfiguration)29 Path (java.nio.file.Path)27 Test (org.junit.Test)26 NetworkProxyConfiguration (org.apache.archiva.configuration.model.NetworkProxyConfiguration)23 RepositoryScanningConfiguration (org.apache.archiva.configuration.model.RepositoryScanningConfiguration)23 RepositoryException (org.apache.archiva.repository.RepositoryException)22 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)14 ManagedRepository (org.apache.archiva.repository.ManagedRepository)13 IOException (java.io.IOException)12 ArrayList (java.util.ArrayList)12 RemoteRepository (org.apache.archiva.repository.RemoteRepository)12 Test (org.junit.jupiter.api.Test)12 LegacyArtifactPath (org.apache.archiva.configuration.model.LegacyArtifactPath)11