use of org.apache.archiva.configuration.Configuration in project archiva by apache.
the class RepositoryRegistry method putRepository.
/**
* Adds a new repository to the current list, or replaces the repository definition with
* the same id, if it exists already.
* The change is saved to the configuration immediately.
*
* @param managedRepository the new repository.
* @throws RepositoryException if the new repository could not be saved to the configuration.
*/
public ManagedRepository putRepository(ManagedRepository managedRepository) throws RepositoryException {
rwLock.writeLock().lock();
try {
final String id = managedRepository.getId();
if (remoteRepositories.containsKey(id)) {
throw new RepositoryException("There exists a remote repository with id " + id + ". Could not update with managed repository.");
}
ManagedRepository originRepo = managedRepositories.put(id, managedRepository);
try {
if (originRepo != null) {
originRepo.close();
}
RepositoryProvider provider = getProvider(managedRepository.getType());
ManagedRepositoryConfiguration newCfg = provider.getManagedConfiguration(managedRepository);
Configuration configuration = getArchivaConfiguration().getConfiguration();
updateRepositoryReferences(provider, managedRepository, newCfg, configuration);
ManagedRepositoryConfiguration oldCfg = configuration.findManagedRepositoryById(id);
if (oldCfg != null) {
configuration.removeManagedRepository(oldCfg);
}
configuration.addManagedRepository(newCfg);
getArchivaConfiguration().save(configuration);
return managedRepository;
} catch (Exception e) {
// Rollback
if (originRepo != null) {
managedRepositories.put(id, originRepo);
} else {
managedRepositories.remove(id);
}
log.error("Exception during configuration update {}", e.getMessage(), e);
throw new RepositoryException("Could not save the configuration" + (e.getMessage() == null ? "" : ": " + e.getMessage()));
}
} finally {
rwLock.writeLock().unlock();
}
}
use of org.apache.archiva.configuration.Configuration in project archiva by apache.
the class RepositoryRegistry method putRepository.
/**
* Adds a remote repository, or overwrites the repository definition with the same id, if it exists already.
* The modification is saved to the configuration immediately.
*
* @param remoteRepository the remote repository to add
* @throws RepositoryException if an error occurs during configuration save
*/
public RemoteRepository putRepository(RemoteRepository remoteRepository) throws RepositoryException {
rwLock.writeLock().lock();
try {
Configuration configuration = getArchivaConfiguration().getConfiguration();
try {
RemoteRepository repo = putRepository(remoteRepository, configuration);
getArchivaConfiguration().save(configuration);
return repo;
} catch (RegistryException | IndeterminateConfigurationException e) {
log.error("Error while saving remote repository {}", e.getMessage(), e);
throw new RepositoryException("Could not save the configuration" + (e.getMessage() == null ? "" : ": " + e.getMessage()));
}
} finally {
rwLock.writeLock().unlock();
}
}
use of org.apache.archiva.configuration.Configuration in project archiva by apache.
the class FileMetadataRepositoryTest method createTestConfiguration.
protected static ArchivaConfiguration createTestConfiguration(Path directory) {
ArchivaConfiguration config = mock(ArchivaConfiguration.class);
Configuration configData = new Configuration();
configData.addManagedRepository(createManagedRepository(TEST_REPO_ID, directory));
configData.addManagedRepository(createManagedRepository("other-repo", directory));
when(config.getConfiguration()).thenReturn(configData);
return config;
}
use of org.apache.archiva.configuration.Configuration in project archiva by apache.
the class Maven2RepositoryMetadataResolverMRM1411RepoGroupTest method setUp.
@Before
@Override
public void setUp() throws Exception {
super.setUp();
c = new Configuration();
testRepo = new ManagedRepositoryConfiguration();
testRepo.setId(TEST_REPO_ID);
testRepo.setLocation(Paths.get("target/test-repository").toAbsolutePath().toString());
testRepo.setReleases(true);
testRepo.setSnapshots(false);
c.addManagedRepository(testRepo);
testRepoS = new ManagedRepositoryConfiguration();
testRepoS.setId(TEST_SNAP_REPO_ID);
testRepoS.setLocation(Paths.get("target/test-repositorys").toAbsolutePath().toString());
testRepoS.setReleases(false);
testRepoS.setSnapshots(true);
c.addManagedRepository(testRepoS);
RemoteRepositoryConfiguration testRemoteRepo = new RemoteRepositoryConfiguration();
testRemoteRepo.setId(TEST_REMOTE_REPO_ID);
testRemoteRepo.setLayout("default");
testRemoteRepo.setName("Central Repository");
testRemoteRepo.setUrl("http://central.repo.com/maven2");
testRemoteRepo.setTimeout(10);
c.addRemoteRepository(testRemoteRepo);
ProxyConnectorConfiguration proxyConnector = new ProxyConnectorConfiguration();
proxyConnector.setSourceRepoId(TEST_REPO_ID);
proxyConnector.setTargetRepoId(TEST_REMOTE_REPO_ID);
proxyConnector.setDisabled(false);
c.addProxyConnector(proxyConnector);
ProxyConnectorConfiguration proxyConnectors = new ProxyConnectorConfiguration();
proxyConnectors.setSourceRepoId(TEST_SNAP_REPO_ID);
proxyConnectors.setTargetRepoId(TEST_REMOTE_REPO_ID);
proxyConnectors.setDisabled(false);
c.addProxyConnector(proxyConnectors);
List<String> repos = new ArrayList<>();
repos.add(TEST_REPO_ID);
repos.add(TEST_SNAP_REPO_ID);
RepositoryGroupConfiguration repoGroup = new RepositoryGroupConfiguration();
repoGroup.setId(TEST_REPO_GROUP_ID);
repoGroup.setRepositories(repos);
c.addRepositoryGroup(repoGroup);
configuration.save(c);
repositoryRegistry.reload();
assertFalse(c.getManagedRepositories().get(0).isSnapshots());
assertTrue(c.getManagedRepositories().get(0).isReleases());
assertTrue(c.getManagedRepositories().get(1).isSnapshots());
assertFalse(c.getManagedRepositories().get(1).isReleases());
wagonFactory = mock(WagonFactory.class);
storage.setWagonFactory(wagonFactory);
Wagon wagon = new MockWagon();
when(wagonFactory.getWagon(new WagonFactoryRequest().protocol("wagon#http"))).thenReturn(wagon);
}
use of org.apache.archiva.configuration.Configuration in project archiva by apache.
the class Maven2RepositoryMetadataResolverMRM1411Test 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("target/test-classes/com/example/test/test-artifact-module-a", "target/test-repository/com/example/test/test-artifact-module-a");
ProjectVersionMetadata metadata = storage.readProjectVersionMetadata(new ReadMetadataRequest(TEST_REPO_ID, "com.example.test", "test-artifact-module-a", "1.0"));
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);
}
Aggregations