use of org.apache.archiva.repository.RepositoryException in project archiva by apache.
the class DefaultManagedRepositoryAdmin method addManagedRepository.
@Override
public Boolean addManagedRepository(ManagedRepository managedRepository, boolean needStageRepo, AuditInformation auditInformation) throws RepositoryAdminException {
log.debug("addManagedRepository {}, {}, {}", managedRepository.getId(), needStageRepo, auditInformation);
getRepositoryCommonValidator().basicValidation(managedRepository, false);
getRepositoryCommonValidator().validateManagedRepository(managedRepository);
triggerAuditEvent(managedRepository.getId(), null, AuditEvent.ADD_MANAGED_REPO, auditInformation);
ManagedRepositoryConfiguration repoConfig = getRepositoryConfiguration(managedRepository);
if (needStageRepo) {
repoConfig.setStageRepoNeeded(true);
}
Configuration configuration = getArchivaConfiguration().getConfiguration();
try {
org.apache.archiva.repository.ManagedRepository newRepo = repositoryRegistry.putRepository(repoConfig, configuration);
log.debug("Added new repository {}", newRepo.getId());
org.apache.archiva.repository.ManagedRepository stagingRepo = null;
addRepositoryRoles(newRepo.getId());
if (newRepo.supportsFeature(StagingRepositoryFeature.class)) {
StagingRepositoryFeature stf = newRepo.getFeature(StagingRepositoryFeature.class).get();
stagingRepo = stf.getStagingRepository();
if (stf.isStageRepoNeeded() && stagingRepo != null) {
addRepositoryRoles(stagingRepo.getId());
triggerAuditEvent(stagingRepo.getId(), null, AuditEvent.ADD_MANAGED_REPO, auditInformation);
}
}
saveConfiguration(configuration);
// scan repository when adding of repository is successful
try {
if (newRepo.isScanned()) {
scanRepository(newRepo.getId(), true);
}
if (stagingRepo != null && stagingRepo.isScanned()) {
scanRepository(stagingRepo.getId(), true);
}
} catch (Exception e) {
log.warn("Unable to scan repository [{}]: {}", newRepo.getId(), e.getMessage(), e);
}
} catch (RepositoryException e) {
log.error("Could not add managed repository {}" + managedRepository);
throw new RepositoryAdminException("Could not add repository " + e.getMessage());
} catch (RoleManagerException e) {
log.error("Could not add repository roles for repository [{}]: {}", managedRepository.getId(), e.getMessage(), e);
throw new RepositoryAdminException("Could not add roles to repository " + e.getMessage());
}
return Boolean.TRUE;
}
use of org.apache.archiva.repository.RepositoryException in project archiva by apache.
the class DefaultManagedRepositoryAdmin method updateManagedRepository.
@Override
public Boolean updateManagedRepository(ManagedRepository managedRepository, boolean needStageRepo, AuditInformation auditInformation, boolean resetStats) throws RepositoryAdminException {
log.debug("updateManagedConfiguration repo {} needStage {} resetStats {} ", managedRepository, needStageRepo, resetStats);
// Ensure that the fields are valid.
getRepositoryCommonValidator().basicValidation(managedRepository, true);
getRepositoryCommonValidator().validateManagedRepository(managedRepository);
Configuration configuration = getArchivaConfiguration().getConfiguration();
ManagedRepositoryConfiguration updatedRepoConfig = getRepositoryConfiguration(managedRepository);
updatedRepoConfig.setStageRepoNeeded(needStageRepo);
org.apache.archiva.repository.ManagedRepository oldRepo = repositoryRegistry.getManagedRepository(managedRepository.getId());
boolean stagingExists = false;
if (oldRepo.supportsFeature(StagingRepositoryFeature.class)) {
stagingExists = oldRepo.getFeature(StagingRepositoryFeature.class).get().getStagingRepository() != null;
}
boolean updateIndexContext = !StringUtils.equals(updatedRepoConfig.getIndexDir(), managedRepository.getIndexDirectory());
org.apache.archiva.repository.ManagedRepository newRepo;
// TODO remove content from old if path has changed !!!!!
try {
newRepo = repositoryRegistry.putRepository(updatedRepoConfig, configuration);
if (newRepo.supportsFeature(StagingRepositoryFeature.class)) {
org.apache.archiva.repository.ManagedRepository stagingRepo = newRepo.getFeature(StagingRepositoryFeature.class).get().getStagingRepository();
if (stagingRepo != null && !stagingExists) {
triggerAuditEvent(stagingRepo.getId(), null, AuditEvent.ADD_MANAGED_REPO, auditInformation);
addRepositoryRoles(stagingRepo.getId());
}
}
} catch (RepositoryException e) {
log.error("Could not update repository {}: {}", managedRepository.getId(), e.getMessage(), e);
throw new RepositoryAdminException("Could not update repository " + managedRepository.getId());
} catch (RoleManagerException e) {
log.error("Error during role update of stage repo {}", managedRepository.getId(), e);
throw new RepositoryAdminException("Could not update repository " + managedRepository.getId());
}
triggerAuditEvent(managedRepository.getId(), null, AuditEvent.MODIFY_MANAGED_REPO, auditInformation);
try {
getArchivaConfiguration().save(configuration);
} catch (RegistryException | IndeterminateConfigurationException e) {
log.error("Could not save repository configuration: {}", e.getMessage(), e);
throw new RepositoryAdminException("Could not save repository configuration: " + e.getMessage());
}
// Save the repository configuration.
RepositorySession repositorySession = getRepositorySessionFactory().createSession();
try {
if (resetStats) {
log.debug("call repositoryStatisticsManager.deleteStatistics");
getRepositoryStatisticsManager().deleteStatistics(repositorySession.getRepository(), managedRepository.getId());
repositorySession.save();
}
} catch (MetadataRepositoryException e) {
throw new RepositoryAdminException(e.getMessage(), e);
} finally {
repositorySession.close();
}
if (updateIndexContext) {
try {
repositoryRegistry.resetIndexingContext(newRepo);
} catch (IndexUpdateFailedException e) {
e.printStackTrace();
}
}
return true;
}
use of org.apache.archiva.repository.RepositoryException in project archiva by apache.
the class RepositoryProviderMock method updateRemoteInstance.
@SuppressWarnings("unchecked")
@Override
public void updateRemoteInstance(EditableRemoteRepository remoteRepository, RemoteRepositoryConfiguration configuration) throws RepositoryException {
try {
remoteRepository.setName(remoteRepository.getPrimaryLocale(), configuration.getName());
remoteRepository.setBaseUri(new URI(""));
remoteRepository.setDescription(remoteRepository.getPrimaryLocale(), configuration.getDescription());
remoteRepository.setLayout(configuration.getLayout());
remoteRepository.setSchedulingDefinition(configuration.getRefreshCronExpression());
remoteRepository.setCheckPath(configuration.getCheckPath());
remoteRepository.setExtraHeaders(configuration.getExtraHeaders());
remoteRepository.setExtraParameters(configuration.getExtraParameters());
remoteRepository.setTimeout(Duration.ofSeconds(configuration.getTimeout()));
char[] pwd = configuration.getPassword() == null ? "".toCharArray() : configuration.getPassword().toCharArray();
remoteRepository.setCredentials(new PasswordCredentials(configuration.getUsername(), pwd));
remoteRepository.setLocation(new URI(configuration.getUrl() == null ? "" : configuration.getUrl()));
RemoteIndexFeature rif = remoteRepository.getFeature(RemoteIndexFeature.class).get();
rif.setDownloadRemoteIndexOnStartup(configuration.isDownloadRemoteIndexOnStartup());
rif.setDownloadRemoteIndex(configuration.isDownloadRemoteIndex());
rif.setIndexUri(new URI(configuration.getIndexDir()));
rif.setDownloadTimeout(Duration.ofSeconds(configuration.getRemoteDownloadTimeout()));
rif.setProxyId(configuration.getRemoteDownloadNetworkProxyId());
} catch (Exception e) {
throw new RepositoryException("Error", e);
}
}
use of org.apache.archiva.repository.RepositoryException in project archiva by apache.
the class MavenRepositoryProvider method getRemoteConfiguration.
@Override
public RemoteRepositoryConfiguration getRemoteConfiguration(RemoteRepository remoteRepository) throws RepositoryException {
if (!(remoteRepository instanceof MavenRemoteRepository)) {
log.error("Wrong remote repository type " + remoteRepository.getClass().getName());
throw new RepositoryException("The given repository type cannot be handled by the maven provider: " + remoteRepository.getClass().getName());
}
RemoteRepositoryConfiguration cfg = new RemoteRepositoryConfiguration();
cfg.setType(remoteRepository.getType().toString());
cfg.setId(remoteRepository.getId());
cfg.setName(remoteRepository.getName());
cfg.setDescription(remoteRepository.getDescription());
cfg.setUrl(remoteRepository.getLocation().toString());
cfg.setTimeout((int) remoteRepository.getTimeout().toMillis() / 1000);
cfg.setCheckPath(remoteRepository.getCheckPath());
RepositoryCredentials creds = remoteRepository.getLoginCredentials();
if (creds != null) {
if (creds instanceof PasswordCredentials) {
PasswordCredentials pCreds = (PasswordCredentials) creds;
cfg.setPassword(new String(pCreds.getPassword()));
cfg.setUsername(pCreds.getUsername());
}
}
cfg.setLayout(remoteRepository.getLayout());
cfg.setExtraParameters(remoteRepository.getExtraParameters());
cfg.setExtraHeaders(remoteRepository.getExtraHeaders());
cfg.setRefreshCronExpression(remoteRepository.getSchedulingDefinition());
IndexCreationFeature indexCreationFeature = remoteRepository.getFeature(IndexCreationFeature.class).get();
cfg.setIndexDir(convertUriToPath(indexCreationFeature.getIndexPath()));
cfg.setPackedIndexDir(convertUriToPath(indexCreationFeature.getPackedIndexPath()));
RemoteIndexFeature remoteIndexFeature = remoteRepository.getFeature(RemoteIndexFeature.class).get();
cfg.setRemoteIndexUrl(remoteIndexFeature.getIndexUri().toString());
cfg.setRemoteDownloadTimeout((int) remoteIndexFeature.getDownloadTimeout().get(ChronoUnit.SECONDS));
cfg.setDownloadRemoteIndexOnStartup(remoteIndexFeature.isDownloadRemoteIndexOnStartup());
cfg.setDownloadRemoteIndex(remoteIndexFeature.isDownloadRemoteIndex());
cfg.setRemoteDownloadNetworkProxyId(remoteIndexFeature.getProxyId());
return cfg;
}
use of org.apache.archiva.repository.RepositoryException in project archiva by apache.
the class MavenRepositoryProvider method updateRemoteInstance.
@Override
public void updateRemoteInstance(EditableRemoteRepository repo, RemoteRepositoryConfiguration cfg) throws RepositoryException {
setBaseConfig(repo, cfg);
repo.setCheckPath(cfg.getCheckPath());
repo.setSchedulingDefinition(cfg.getRefreshCronExpression());
try {
repo.setLocation(new URI(cfg.getUrl()));
} catch (UnsupportedURIException | URISyntaxException e) {
log.error("Could not set remote url " + cfg.getUrl());
throw new RepositoryException("The url config is not a valid uri: " + cfg.getUrl());
}
repo.setTimeout(Duration.ofSeconds(cfg.getTimeout()));
RemoteIndexFeature remoteIndexFeature = repo.getFeature(RemoteIndexFeature.class).get();
remoteIndexFeature.setDownloadRemoteIndex(cfg.isDownloadRemoteIndex());
remoteIndexFeature.setDownloadRemoteIndexOnStartup(cfg.isDownloadRemoteIndexOnStartup());
remoteIndexFeature.setDownloadTimeout(Duration.ofSeconds(cfg.getRemoteDownloadTimeout()));
remoteIndexFeature.setProxyId(cfg.getRemoteDownloadNetworkProxyId());
if (cfg.isDownloadRemoteIndex()) {
try {
remoteIndexFeature.setIndexUri(new URI(cfg.getRemoteIndexUrl()));
} catch (URISyntaxException e) {
log.error("Could not set remote index url " + cfg.getRemoteIndexUrl());
remoteIndexFeature.setDownloadRemoteIndex(false);
remoteIndexFeature.setDownloadRemoteIndexOnStartup(false);
}
}
for (Object key : cfg.getExtraHeaders().keySet()) {
repo.addExtraHeader(key.toString(), cfg.getExtraHeaders().get(key).toString());
}
for (Object key : cfg.getExtraParameters().keySet()) {
repo.addExtraParameter(key.toString(), cfg.getExtraParameters().get(key).toString());
}
PasswordCredentials credentials = new PasswordCredentials("", new char[0]);
if (cfg.getPassword() != null && cfg.getUsername() != null) {
credentials.setPassword(cfg.getPassword().toCharArray());
credentials.setUsername(cfg.getUsername());
repo.setCredentials(credentials);
} else {
credentials.setPassword(new char[0]);
}
IndexCreationFeature indexCreationFeature = repo.getFeature(IndexCreationFeature.class).get();
if (cfg.getIndexDir() != null) {
indexCreationFeature.setIndexPath(getURIFromString(cfg.getIndexDir()));
}
if (cfg.getPackedIndexDir() != null) {
indexCreationFeature.setPackedIndexPath(getURIFromString(cfg.getPackedIndexDir()));
}
log.debug("Updated remote instance {}", repo);
}
Aggregations