use of org.apache.archiva.configuration.model.RepositoryGroupConfiguration in project archiva by apache.
the class ArchivaDavResourceFactoryTest method testRepositoryGroupLastRepositoryRequiresAuthentication.
@Test
public void testRepositoryGroupLastRepositoryRequiresAuthentication() throws Exception {
DavResourceLocator locator = new ArchivaDavResourceLocator("", "/repository/" + LOCAL_REPO_GROUP + "/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", LOCAL_REPO_GROUP, new ArchivaDavLocatorFactory());
List<RepositoryGroupConfiguration> repoGroups = new ArrayList<>();
RepositoryGroupConfiguration repoGroup = new RepositoryGroupConfiguration();
repoGroup.setId(LOCAL_REPO_GROUP);
repoGroup.addRepository(INTERNAL_REPO);
repoGroup.addRepository(RELEASES_REPO);
repoGroups.add(repoGroup);
config.setRepositoryGroups(repoGroups);
ManagedRepositoryContent internalRepo = createManagedRepositoryContent(INTERNAL_REPO);
ManagedRepositoryContent releasesRepo = createManagedRepositoryContent(RELEASES_REPO);
try {
reset(archivaConfiguration);
reset(request);
reset(repoFactory);
when(archivaConfiguration.getConfiguration()).thenReturn(config);
when(request.getMethod()).thenReturn("GET");
when(request.getPathInfo()).thenReturn("org/apache/archiva");
when(repoFactory.getManagedRepositoryContent(INTERNAL_REPO)).thenReturn(internalRepo);
when(repoFactory.getManagedRepositoryContent(RELEASES_REPO)).thenReturn(releasesRepo);
when(request.getRemoteAddr()).thenReturn("http://localhost:8080");
when(request.getDavSession()).thenReturn(new ArchivaDavSession());
when(request.getContextPath()).thenReturn("");
when(repoRequest.isSupportFile("org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar")).thenReturn(false);
when(repoRequest.getLayout("org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar")).thenReturn("legacy");
when(repoRequest.toItemSelector("org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar")).thenReturn(null);
when(repoRequest.toNativePath("org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar")).thenReturn(Paths.get(config.findManagedRepositoryById(INTERNAL_REPO).getLocation(), "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar").toString());
when(repoRequest.isArchetypeCatalog("org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar")).thenReturn(false);
resourceFactory.createResource(locator, request, response);
verify(archivaConfiguration, times(3)).getConfiguration();
verify(request, times(3)).getMethod();
verify(request, atMost(2)).getPathInfo();
verify(request, times(2)).getRemoteAddr();
verify(request, times(2)).getDavSession();
verify(request, times(2)).getContextPath();
fail("A DavException with 401 error code should have been thrown.");
} catch (DavException e) {
assertEquals(401, e.getErrorCode());
}
}
use of org.apache.archiva.configuration.model.RepositoryGroupConfiguration in project archiva by apache.
the class MavenRepositoryProvider method getRepositoryGroupConfiguration.
@Override
public RepositoryGroupConfiguration getRepositoryGroupConfiguration(RepositoryGroup repositoryGroup) throws RepositoryException {
if (repositoryGroup.getType() != RepositoryType.MAVEN) {
throw new RepositoryException("The given repository group is not of MAVEN type");
}
RepositoryGroupConfiguration cfg = new RepositoryGroupConfiguration();
cfg.setId(repositoryGroup.getId());
cfg.setName(repositoryGroup.getName());
if (repositoryGroup.supportsFeature(IndexCreationFeature.class)) {
IndexCreationFeature indexCreationFeature = repositoryGroup.getFeature(IndexCreationFeature.class);
cfg.setMergedIndexPath(indexCreationFeature.getIndexPath().toString());
}
cfg.setMergedIndexTtl(repositoryGroup.getMergedIndexTTL());
cfg.setRepositories(repositoryGroup.getRepositories().stream().map(Repository::getId).collect(Collectors.toList()));
cfg.setCronExpression(repositoryGroup.getSchedulingDefinition());
return cfg;
}
use of org.apache.archiva.configuration.model.RepositoryGroupConfiguration in project archiva by apache.
the class RepositoryGroupHandler method put.
/**
* Adds a new repository group to the current list, or replaces the repository group definition with
* the same id, if it exists already.
* The change is saved to the configuration immediately.
*
* @param repositoryGroup the new repository group.
* @throws RepositoryException if the new repository group could not be saved to the configuration.
*/
@Override
public RepositoryGroup put(final RepositoryGroup repositoryGroup) throws RepositoryException {
final String id = repositoryGroup.getId();
RepositoryGroup originRepoGroup = getRepositories().remove(id);
try {
if (originRepoGroup != null && originRepoGroup != repositoryGroup) {
deactivateRepository(originRepoGroup);
pushEvent(new LifecycleEvent(LifecycleEvent.UNREGISTERED, this, originRepoGroup));
}
RepositoryProvider provider = getProvider(repositoryGroup.getType());
RepositoryGroupConfiguration newCfg = provider.getRepositoryGroupConfiguration(repositoryGroup);
ReentrantReadWriteLock.WriteLock configLock = this.getConfigurationHandler().getLock().writeLock();
configLock.lock();
try {
Configuration configuration = this.getConfigurationHandler().getBaseConfiguration();
updateReferences(repositoryGroup, newCfg);
RepositoryGroupConfiguration oldCfg = configuration.findRepositoryGroupById(id);
if (oldCfg != null) {
configuration.removeRepositoryGroup(oldCfg);
}
configuration.addRepositoryGroup(newCfg);
getConfigurationHandler().save(configuration, ConfigurationHandler.REGISTRY_EVENT_TAG);
setLastState(repositoryGroup, RepositoryState.SAVED);
activateRepository(repositoryGroup);
} finally {
configLock.unlock();
}
getRepositories().put(id, repositoryGroup);
setLastState(repositoryGroup, RepositoryState.REGISTERED);
return repositoryGroup;
} catch (Exception e) {
// Rollback
if (originRepoGroup != null) {
getRepositories().put(id, originRepoGroup);
} 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()), e);
}
}
use of org.apache.archiva.configuration.model.RepositoryGroupConfiguration in project archiva by apache.
the class RepositoryGroupHandler method newInstancesFromConfig.
@Override
public Map<String, RepositoryGroup> newInstancesFromConfig() {
try {
List<RepositoryGroupConfiguration> repositoryGroupConfigurations = this.getConfigurationHandler().getBaseConfiguration().getRepositoryGroups();
if (repositoryGroupConfigurations == null) {
return Collections.emptyMap();
}
Map<String, RepositoryGroup> repositoryGroupMap = new LinkedHashMap<>(repositoryGroupConfigurations.size());
for (RepositoryGroupConfiguration repoConfig : repositoryGroupConfigurations) {
RepositoryType repositoryType = RepositoryType.valueOf(repoConfig.getType());
if (super.providerMap.containsKey(repositoryType)) {
try {
RepositoryGroup repo = createNewRepositoryGroup(providerMap.get(repositoryType), repoConfig);
repositoryGroupMap.put(repo.getId(), repo);
} catch (Exception e) {
log.error("Could not create repository group {}: {}", repoConfig.getId(), e.getMessage(), e);
}
}
}
return repositoryGroupMap;
} catch (Throwable e) {
log.error("Could not initialize repositories from config: {}", e.getMessage(), e);
return Collections.emptyMap();
}
}
use of org.apache.archiva.configuration.model.RepositoryGroupConfiguration in project archiva by apache.
the class RepositoryGroupHandler method clone.
@Override
public RepositoryGroup clone(RepositoryGroup repo, String newId) throws RepositoryException {
RepositoryProvider provider = getProvider(repo.getType());
RepositoryGroupConfiguration cfg = provider.getRepositoryGroupConfiguration(repo);
cfg.setId(newId);
RepositoryGroup cloned = provider.createRepositoryGroup(cfg);
cloned.registerEventHandler(RepositoryEvent.ANY, repositoryRegistry);
setLastState(cloned, RepositoryState.CREATED);
return cloned;
}
Aggregations