Search in sources :

Example 6 with ManagedRepositoryConfiguration

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

the class RepositoryServletDeployTest method testReleaseArtifactsRedeploymentIsAllowed.

@Test
public void testReleaseArtifactsRedeploymentIsAllowed() throws Exception {
    setupCleanRepo(repoRootInternal);
    ManagedRepositoryConfiguration managedRepo = archivaConfiguration.getConfiguration().findManagedRepositoryById(REPOID_INTERNAL);
    managedRepo.setBlockRedeployments(false);
    saveConfiguration(archivaConfiguration);
    String putUrl = "http://machine.com/repository/internal" + ARTIFACT_DEFAULT_LAYOUT;
    String metadataUrl = "http://machine.com/repository/internal/path/to/artifact/maven-metadata.xml";
    String checksumUrl = "http://machine.com/repository/internal" + ARTIFACT_DEFAULT_LAYOUT + ".sha1";
    InputStream is = getClass().getResourceAsStream("/artifact.jar");
    // verify that the file exists in resources-dir
    assertNotNull("artifact.jar inputstream", is);
    // send request #1 and verify it's successful
    WebRequest request = new PutMethodWebRequest(putUrl, is, "application/octet-stream");
    WebResponse response = getServletUnitClient().getResponse(request);
    assertResponseCreated(response);
    is = getClass().getResourceAsStream("/artifact.jar.sha1");
    request = new PutMethodWebRequest(checksumUrl, is, "application/octet-stream");
    response = getServletUnitClient().getResponse(request);
    assertResponseCreated(response);
    is = getClass().getResourceAsStream("/maven-metadata.xml");
    request = new PutMethodWebRequest(metadataUrl, is, "application/octet-stream");
    response = getServletUnitClient().getResponse(request);
    assertResponseCreated(response);
    // send request #2 and verify if it's still successful
    is = getClass().getResourceAsStream("/artifact.jar");
    request = new PutMethodWebRequest(putUrl, is, "application/octet-stream");
    response = getServletUnitClient().getResponse(request);
    assertResponseNoContent(response);
}
Also used : WebResponse(com.gargoylesoftware.htmlunit.WebResponse) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) WebRequest(com.gargoylesoftware.htmlunit.WebRequest) MkColMethodWebRequest(org.apache.archiva.webdav.mock.httpunit.MkColMethodWebRequest) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 7 with ManagedRepositoryConfiguration

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

the class RepositoryServletTest method testGetRepositoryAfterAdd.

@Test
public void testGetRepositoryAfterAdd() throws Exception {
    RepositoryServlet servlet = RepositoryServlet.class.cast(findServlet("repository"));
    assertNotNull(servlet);
    ArchivaConfiguration archivaConfiguration = servlet.getConfiguration();
    Configuration c = archivaConfiguration.getConfiguration();
    ManagedRepositoryConfiguration repo = new ManagedRepositoryConfiguration();
    repo.setId(NEW_REPOSITORY_ID);
    repo.setName(NEW_REPOSITORY_NAME);
    Path repoRoot = Paths.get("target/test-repository-root");
    if (!Files.exists(repoRoot)) {
        Files.createDirectories(repoRoot);
    }
    repo.setLocation(repoRoot.toAbsolutePath().toString());
    c.addManagedRepository(repo);
    saveConfiguration(archivaConfiguration);
    ManagedRepository repository = servlet.getRepository(NEW_REPOSITORY_ID);
    assertNotNull(repository);
    assertEquals(NEW_REPOSITORY_NAME, repository.getName());
    // check other is still intact
    assertRepositoryValid(servlet, REPOID_INTERNAL);
}
Also used : Path(java.nio.file.Path) ManagedRepository(org.apache.archiva.repository.ManagedRepository) 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) ArchivaConfiguration(org.apache.archiva.configuration.provider.ArchivaConfiguration) Test(org.junit.Test)

Example 8 with ManagedRepositoryConfiguration

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

the class RepositoryGroupHandler method updateReferences.

@Override
public void updateReferences(RepositoryGroup repo, RepositoryGroupConfiguration repositoryConfiguration) {
    if (repo instanceof EditableRepositoryGroup && repositoryConfiguration != null) {
        EditableRepositoryGroup eGroup = (EditableRepositoryGroup) repo;
        RepositoryHandler<ManagedRepository, ManagedRepositoryConfiguration> managedHandler = repositoryRegistry.getHandler(ManagedRepository.class, ManagedRepositoryConfiguration.class);
        eGroup.setRepositories(repositoryConfiguration.getRepositories().stream().map(managedHandler::get).collect(Collectors.toList()));
    }
}
Also used : ManagedRepository(org.apache.archiva.repository.ManagedRepository) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) EditableRepositoryGroup(org.apache.archiva.repository.EditableRepositoryGroup)

Example 9 with ManagedRepositoryConfiguration

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

the class ManagedRepositoryHandler method put.

@Override
public ManagedRepository put(ManagedRepository repository) throws RepositoryException {
    final String id = repository.getId();
    ManagedRepository originRepo = getRepositories().remove(id);
    if (originRepo == null && repositoryHandlerManager.isRegisteredId(id)) {
        throw new RepositoryException("There exists a repository with id " + id + ". Could not update with managed repository.");
    }
    try {
        if (originRepo != null && repository != originRepo) {
            deactivateRepository(originRepo);
            pushEvent(LifecycleEvent.UNREGISTERED, originRepo);
        }
        RepositoryProvider provider = getProvider(repository.getType());
        ManagedRepositoryConfiguration newCfg = provider.getManagedConfiguration(repository);
        getConfigurationHandler().getLock().writeLock().lock();
        try {
            Configuration configuration = getConfigurationHandler().getBaseConfiguration();
            updateReferences(repository, newCfg);
            ManagedRepositoryConfiguration oldCfg = configuration.findManagedRepositoryById(id);
            if (oldCfg != null) {
                configuration.removeManagedRepository(oldCfg);
            }
            configuration.addManagedRepository(newCfg);
            getConfigurationHandler().save(configuration, ConfigurationHandler.REGISTRY_EVENT_TAG);
            setLastState(repository, RepositoryState.SAVED);
            activateRepository(repository);
        } finally {
            getConfigurationHandler().getLock().writeLock().unlock();
        }
        getRepositories().put(id, repository);
        setLastState(repository, RepositoryState.REGISTERED);
        return repository;
    } catch (Exception e) {
        // Rollback only partly, because repository is closed already
        if (originRepo != null) {
            getRepositories().put(id, originRepo);
        } else {
            getRepositories().remove(id);
        }
        log.error("Exception during configuration update {}", e.getMessage(), e);
        throw new RepositoryException("Could not save the configuration" + (e.getMessage() == null ? "" : ": " + e.getMessage()));
    }
}
Also used : ManagedRepository(org.apache.archiva.repository.ManagedRepository) EditableManagedRepository(org.apache.archiva.repository.EditableManagedRepository) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) RepositoryException(org.apache.archiva.repository.RepositoryException) RepositoryProvider(org.apache.archiva.repository.RepositoryProvider) IndexCreationFailedException(org.apache.archiva.indexer.IndexCreationFailedException) RegistryException(org.apache.archiva.components.registry.RegistryException) RepositoryException(org.apache.archiva.repository.RepositoryException) IOException(java.io.IOException) IndeterminateConfigurationException(org.apache.archiva.configuration.provider.IndeterminateConfigurationException)

Example 10 with ManagedRepositoryConfiguration

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

the class ManagedRepositoryHandler method put.

@Override
public ManagedRepository put(ManagedRepositoryConfiguration repositoryConfiguration) throws RepositoryException {
    final String id = repositoryConfiguration.getId();
    final RepositoryType repositoryType = RepositoryType.valueOf(repositoryConfiguration.getType());
    final RepositoryProvider provider = getProvider(repositoryType);
    ReentrantReadWriteLock.WriteLock configLock = this.getConfigurationHandler().getLock().writeLock();
    configLock.lock();
    ManagedRepository repo = null;
    ManagedRepository oldRepository = null;
    Configuration configuration = null;
    try {
        boolean updated = false;
        configuration = getConfigurationHandler().getBaseConfiguration();
        repo = getRepositories().get(id);
        oldRepository = repo == null ? null : clone(repo, id);
        if (repo == null) {
            repo = put(repositoryConfiguration, configuration);
        } else {
            setRepositoryDefaults(repositoryConfiguration);
            provider.updateManagedInstance((EditableManagedRepository) repo, repositoryConfiguration);
            updated = true;
            pushEvent(LifecycleEvent.UPDATED, repo);
        }
        registerNewRepository(repositoryConfiguration, repo, configuration, updated);
    } catch (IndeterminateConfigurationException | RegistryException e) {
        if (oldRepository != null) {
            ManagedRepositoryConfiguration oldCfg = provider.getManagedConfiguration(oldRepository);
            provider.updateManagedInstance((EditableManagedRepository) repo, oldCfg);
            rollback(configuration, oldRepository, e, oldCfg);
        } else {
            getRepositories().remove(id);
        }
        log.error("Could not save the configuration for repository {}: {}", id, e.getMessage(), e);
        throw new RepositoryException("Could not save the configuration for repository " + id + ": " + e.getMessage());
    } finally {
        configLock.unlock();
    }
    return repo;
}
Also used : ManagedRepository(org.apache.archiva.repository.ManagedRepository) EditableManagedRepository(org.apache.archiva.repository.EditableManagedRepository) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) RepositoryType(org.apache.archiva.repository.RepositoryType) IndeterminateConfigurationException(org.apache.archiva.configuration.provider.IndeterminateConfigurationException) RepositoryException(org.apache.archiva.repository.RepositoryException) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) RegistryException(org.apache.archiva.components.registry.RegistryException) EditableManagedRepository(org.apache.archiva.repository.EditableManagedRepository) RepositoryProvider(org.apache.archiva.repository.RepositoryProvider)

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