use of org.apache.archiva.policies.Policy in project archiva by apache.
the class DefaultArchivaConfiguration method load.
@SuppressWarnings("unchecked")
private Configuration load() {
// TODO: should this be the same as section? make sure unnamed sections still work (eg, sys properties)
Registry subset = registry.getSubset(KEY);
if (subset.getString("version") == null) {
if (subset.getSubset("repositoryScanning").isEmpty()) {
// only for empty
subset = readDefaultConfiguration();
} else {
throw new RuntimeException("No version tag found in configuration. Archiva configuration version 1.x is not longer supported.");
}
}
Configuration config = new ConfigurationRegistryReader().read(subset);
// Resolving data and repositories directories
// If the config entries are absolute, the path is used as it is
// if the config entries are empty, they are resolved:
// dataDirectory = ${appserver.base}/data
// repositoryDirectory = ${dataDirectory}/repositories
// If the entries are relative they are resolved
// relative to the appserver.base, for dataDirectory
// relative to dataDirectory for repositoryBase
String dataDir = config.getArchivaRuntimeConfiguration().getDataDirectory();
if (StringUtils.isEmpty(dataDir)) {
dataDirectory = getAppServerBaseDir().resolve("data");
} else {
Path tmpDataDir = Paths.get(dataDir);
if (tmpDataDir.isAbsolute()) {
dataDirectory = tmpDataDir;
} else {
dataDirectory = getAppServerBaseDir().resolve(tmpDataDir);
}
}
config.getArchivaRuntimeConfiguration().setDataDirectory(dataDirectory.normalize().toString());
String repoBaseDir = config.getArchivaRuntimeConfiguration().getRepositoryBaseDirectory();
if (StringUtils.isEmpty(repoBaseDir)) {
repositoryBaseDirectory = dataDirectory.resolve("repositories");
} else {
Path tmpRepoBaseDir = Paths.get(repoBaseDir);
if (tmpRepoBaseDir.isAbsolute()) {
repositoryBaseDirectory = tmpRepoBaseDir;
} else {
dataDirectory.resolve(tmpRepoBaseDir);
}
}
String remoteRepoBaseDir = config.getArchivaRuntimeConfiguration().getRemoteRepositoryBaseDirectory();
if (StringUtils.isEmpty(remoteRepoBaseDir)) {
remoteRepositoryBaseDirectory = dataDirectory.resolve("remotes");
} else {
Path tmpRemoteRepoDir = Paths.get(remoteRepoBaseDir);
if (tmpRemoteRepoDir.isAbsolute()) {
remoteRepositoryBaseDirectory = tmpRemoteRepoDir;
} else {
dataDirectory.resolve(tmpRemoteRepoDir);
}
}
config.getRepositoryGroups();
config.getRepositoryGroupsAsMap();
if (!CollectionUtils.isEmpty(config.getRemoteRepositories())) {
List<RemoteRepositoryConfiguration> remoteRepos = config.getRemoteRepositories();
for (RemoteRepositoryConfiguration repo : remoteRepos) {
// [MRM-582] Remote Repositories with empty <username> and <password> fields shouldn't be created in configuration.
if (StringUtils.isBlank(repo.getUsername())) {
repo.setUsername(null);
}
if (StringUtils.isBlank(repo.getPassword())) {
repo.setPassword(null);
}
}
}
if (!config.getProxyConnectors().isEmpty()) {
// Fix Proxy Connector Settings.
// Create a copy of the list to read from (to prevent concurrent modification exceptions)
List<ProxyConnectorConfiguration> proxyConnectorList = new ArrayList<>(config.getProxyConnectors());
// Remove the old connector list.
config.getProxyConnectors().clear();
for (ProxyConnectorConfiguration connector : proxyConnectorList) {
// Fix policies
boolean connectorValid = true;
Map<String, String> policies = new HashMap<>();
// Make copy of policies
policies.putAll(connector.getPolicies());
// Clear out policies
connector.getPolicies().clear();
// Work thru policies. cleaning them up.
for (Entry<String, String> entry : policies.entrySet()) {
String policyId = entry.getKey();
String setting = entry.getValue();
// Upgrade old policy settings.
if ("releases".equals(policyId) || "snapshots".equals(policyId)) {
if ("ignored".equals(setting)) {
setting = AbstractUpdatePolicy.ALWAYS;
} else if ("disabled".equals(setting)) {
setting = AbstractUpdatePolicy.NEVER;
}
} else if ("cache-failures".equals(policyId)) {
if ("ignored".equals(setting)) {
setting = CachedFailuresPolicy.NO;
} else if ("cached".equals(setting)) {
setting = CachedFailuresPolicy.YES;
}
} else if ("checksum".equals(policyId)) {
if ("ignored".equals(setting)) {
setting = ChecksumPolicy.IGNORE;
}
}
// Validate existance of policy key.
if (policyExists(policyId)) {
Policy policy = findPolicy(policyId);
// Does option exist?
if (!policy.getOptions().contains(setting)) {
setting = policy.getDefaultOption();
}
connector.addPolicy(policyId, setting);
} else {
// Policy key doesn't exist. Don't add it to golden version.
log.warn("Policy [{}] does not exist.", policyId);
}
}
if (connectorValid) {
config.addProxyConnector(connector);
}
}
// Normalize the order fields in the proxy connectors.
Map<String, java.util.List<ProxyConnectorConfiguration>> proxyConnectorMap = config.getProxyConnectorAsMap();
for (List<ProxyConnectorConfiguration> connectors : proxyConnectorMap.values()) {
// Sort connectors by order field.
Collections.sort(connectors, ProxyConnectorConfigurationOrderComparator.getInstance());
// Normalize the order field values.
int order = 1;
for (ProxyConnectorConfiguration connector : connectors) {
connector.setOrder(order++);
}
}
}
this.defaultLocale = Locale.forLanguageTag(config.getArchivaRuntimeConfiguration().getDefaultLanguage());
this.languagePriorities = Locale.LanguageRange.parse(config.getArchivaRuntimeConfiguration().getLanguageRange());
return config;
}
use of org.apache.archiva.policies.Policy in project archiva by apache.
the class DefaultArchivaConfiguration method findPolicy.
private Policy findPolicy(String policyId) {
if (MapUtils.isEmpty(prePolicies)) {
log.error("No PreDownloadPolicies found!");
return null;
}
if (MapUtils.isEmpty(postPolicies)) {
log.error("No PostDownloadPolicies found!");
return null;
}
Policy policy;
policy = prePolicies.get(policyId);
if (policy != null) {
return policy;
}
policy = postPolicies.get(policyId);
if (policy != null) {
return policy;
}
policy = downloadErrorPolicies.get(policyId);
if (policy != null) {
return policy;
}
return null;
}
Aggregations