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);
}
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);
}
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()));
}
}
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()));
}
}
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;
}
Aggregations