Search in sources :

Example 56 with Configuration

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

the class ArchivaConfigurationTest method testStoreConfigurationFailsWhenReadFromBothLocationsUserHasLists.

@Test
public void testStoreConfigurationFailsWhenReadFromBothLocationsUserHasLists() throws Exception {
    Path baseFile = getTestFile("target/test/test-file.xml");
    Files.deleteIfExists(baseFile);
    assertFalse(Files.exists(baseFile));
    Path userFile = getTestFile("target/test/test-file-user.xml");
    Files.deleteIfExists(userFile);
    assertFalse(Files.exists(userFile));
    Files.createDirectories(userFile.getParent());
    FileUtils.copyFile(getTestFile("src/test/conf/conf-user.xml").toFile(), userFile.toFile());
    Files.createDirectories(baseFile.getParent());
    FileUtils.writeStringToFile(baseFile.toFile(), "<configuration/>", Charset.forName("UTF-8"));
    ArchivaConfiguration archivaConfiguration = lookup(ArchivaConfiguration.class, "test-save-user");
    archivaConfiguration.reload();
    Configuration configuration = archivaConfiguration.getConfiguration();
    assertTrue("check value", configuration.getWebapp().getUi().isShowFindArtifacts());
    configuration.getWebapp().getUi().setShowFindArtifacts(false);
    archivaConfiguration.save(configuration);
    assertTrue("Check file exists", Files.exists(baseFile));
    assertEquals("Check base file is unchanged", "<configuration/>", FileUtils.readFileToString(baseFile.toFile(), Charset.forName("UTF-8")));
    assertTrue("Check file exists", Files.exists(userFile));
    assertFalse("Check base file is changed", "<configuration/>".equals(FileUtils.readFileToString(userFile.toFile(), Charset.forName("UTF-8"))));
    // check it
    configuration = archivaConfiguration.getConfiguration();
    assertFalse("check value", configuration.getWebapp().getUi().isShowFindArtifacts());
}
Also used : Path(java.nio.file.Path) LegacyArtifactPath(org.apache.archiva.configuration.model.LegacyArtifactPath) 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) RepositoryScanningConfiguration(org.apache.archiva.configuration.model.RepositoryScanningConfiguration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) WebappConfiguration(org.apache.archiva.configuration.model.WebappConfiguration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) NetworkProxyConfiguration(org.apache.archiva.configuration.model.NetworkProxyConfiguration) Test(org.junit.Test)

Example 57 with Configuration

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

the class FileTypes method getFileTypePatterns.

/**
 * Get the list of patterns for a specified filetype.
 * You will always get a list.  In this order.
 * <ul>
 * <li>The Configured List</li>
 * <li>The Default List</li>
 * <li>A single item list of <code>&quot;**&#47;*&quot;</code></li>
 * </ul>
 *
 * @param id the id to lookup.
 * @return the list of patterns.
 */
public List<String> getFileTypePatterns(String id) {
    Configuration config = archivaConfiguration.getConfiguration();
    Predicate selectedFiletype = new FiletypeSelectionPredicate(id);
    RepositoryScanningConfiguration repositoryScanningConfiguration = config.getRepositoryScanning();
    if (repositoryScanningConfiguration != null) {
        FileType filetype = IterableUtils.find(config.getRepositoryScanning().getFileTypes(), selectedFiletype);
        if ((filetype != null) && CollectionUtils.isNotEmpty(filetype.getPatterns())) {
            return filetype.getPatterns();
        }
    }
    List<String> defaultPatterns = defaultTypeMap.get(id);
    if (CollectionUtils.isEmpty(defaultPatterns)) {
        return Collections.singletonList("**/*");
    }
    return defaultPatterns;
}
Also used : RepositoryScanningConfiguration(org.apache.archiva.configuration.model.RepositoryScanningConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) FileType(org.apache.archiva.configuration.model.FileType) RepositoryScanningConfiguration(org.apache.archiva.configuration.model.RepositoryScanningConfiguration) Predicate(org.apache.commons.collections4.Predicate) FiletypeSelectionPredicate(org.apache.archiva.configuration.model.functors.FiletypeSelectionPredicate) FiletypeSelectionPredicate(org.apache.archiva.configuration.model.functors.FiletypeSelectionPredicate)

Example 58 with Configuration

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

the class AbstractRepositoryHandler method remove.

/**
 * Removes a repository group from the registry and configuration, if it exists.
 * The change is saved to the configuration immediately.
 *
 * @param id the id of the repository group to remove
 * @throws RepositoryException if an error occurs during configuration save
 */
@Override
public void remove(String id) throws RepositoryException {
    R repo = get(id);
    if (repo != null) {
        try {
            repo = getRepositories().remove(id);
            if (repo != null) {
                deactivateRepository(repo);
                Configuration configuration = this.configurationHandler.getBaseConfiguration();
                C cfg = findRepositoryConfiguration(configuration, id);
                if (cfg != null) {
                    removeRepositoryConfiguration(configuration, cfg);
                }
                this.configurationHandler.save(configuration, ConfigurationHandler.REGISTRY_EVENT_TAG);
                setLastState(repo, RepositoryState.UNREGISTERED);
            }
        } catch (RegistryException | IndeterminateConfigurationException e) {
            // Rollback
            log.error("Could not save config after repository removal: {}", e.getMessage(), e);
            getRepositories().put(repo.getId(), repo);
            throw new RepositoryException("Could not save configuration after repository removal: " + e.getMessage());
        }
    }
}
Also used : AbstractRepositoryConfiguration(org.apache.archiva.configuration.model.AbstractRepositoryConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) IndeterminateConfigurationException(org.apache.archiva.configuration.provider.IndeterminateConfigurationException) RepositoryException(org.apache.archiva.repository.RepositoryException) RegistryException(org.apache.archiva.components.registry.RegistryException)

Example 59 with Configuration

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

the class DefaultRemoteRepositoryAdmin method deleteRemoteRepository.

@Override
public Boolean deleteRemoteRepository(String repositoryId, AuditInformation auditInformation) throws RepositoryAdminException {
    triggerAuditEvent(repositoryId, null, AuditEvent.DELETE_REMOTE_REPO, auditInformation);
    Configuration configuration = getArchivaConfiguration().getConfiguration();
    RemoteRepository repo = repositoryRegistry.getRemoteRepository(repositoryId);
    if (repo == null) {
        throw new RepositoryAdminException("Could not delete repository " + repositoryId + ". The repository does not exist.");
    }
    try {
        repositoryRegistry.removeRepository(repo);
    } catch (RepositoryException e) {
        log.error("Deletion of remote repository failed {}: {}", repo.getId(), e.getMessage(), e);
        throw new RepositoryAdminException("Could not delete remote repository" + (e.getMessage() == null ? "" : ": " + e.getMessage()));
    }
    return Boolean.TRUE;
}
Also used : RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) RemoteRepository(org.apache.archiva.repository.RemoteRepository) RepositoryException(org.apache.archiva.repository.RepositoryException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException)

Example 60 with Configuration

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

the class RepositoryGroupHandlerTest method removeGroupFromConfig.

// Helper method that removes a group from the configuration
private void removeGroupFromConfig(String groupId) {
    Configuration configuration = configurationHandler.getBaseConfiguration();
    Iterator<RepositoryGroupConfiguration> groupIter = configuration.getRepositoryGroups().iterator();
    while (groupIter.hasNext()) {
        RepositoryGroupConfiguration group = groupIter.next();
        if (groupId.equals(group.getId())) {
            groupIter.remove();
            break;
        }
    }
    try {
        configurationHandler.save(configuration);
    } catch (Throwable e) {
        System.err.println("Could not remove repo group from config " + groupId);
    }
}
Also used : RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) ArchivaConfiguration(org.apache.archiva.configuration.provider.ArchivaConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) 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)

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