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