use of org.apache.archiva.configuration.model.RemoteRepositoryConfiguration in project archiva by apache.
the class DefaultArchivaConfiguration method updateCheckPathDefaults.
/*
* Updates the checkpath list for repositories.
*
* We are replacing existing ones and adding new ones. This allows to update the list with new releases.
*
* We are also updating existing remote repositories, if they exist already.
*
* This update method should only be called, if the config version changes to avoid overwriting
* user repository settings all the time.
*/
private void updateCheckPathDefaults(Configuration config, Registry defaultConfiguration) {
List<RepositoryCheckPath> existingCheckPathList = config.getArchivaDefaultConfiguration().getDefaultCheckPaths();
HashMap<String, RepositoryCheckPath> existingCheckPaths = new HashMap<>();
HashMap<String, RepositoryCheckPath> newCheckPaths = new HashMap<>();
for (RepositoryCheckPath path : config.getArchivaDefaultConfiguration().getDefaultCheckPaths()) {
existingCheckPaths.put(path.getUrl(), path);
}
List defaultCheckPathsSubsets = defaultConfiguration.getSubsetList("archivaDefaultConfiguration.defaultCheckPaths.defaultCheckPath");
for (Iterator i = defaultCheckPathsSubsets.iterator(); i.hasNext(); ) {
RepositoryCheckPath v = readRepositoryCheckPath((Registry) i.next());
if (existingCheckPaths.containsKey(v.getUrl())) {
existingCheckPathList.remove(existingCheckPaths.get(v.getUrl()));
}
existingCheckPathList.add(v);
newCheckPaths.put(v.getUrl(), v);
}
// Remote repositories update
for (RemoteRepositoryConfiguration remoteRepositoryConfiguration : config.getRemoteRepositories()) {
String url = remoteRepositoryConfiguration.getUrl().toLowerCase();
if (newCheckPaths.containsKey(url)) {
String currentPath = remoteRepositoryConfiguration.getCheckPath();
String newPath = newCheckPaths.get(url).getPath();
log.info("Updating connection check path for repository {}, from '{}' to '{}'.", remoteRepositoryConfiguration.getId(), currentPath, newPath);
remoteRepositoryConfiguration.setCheckPath(newPath);
}
}
}
use of org.apache.archiva.configuration.model.RemoteRepositoryConfiguration in project archiva by apache.
the class MavenProxyPropertyLoader method load.
public void load(Properties props, Configuration configuration) throws InvalidConfigurationException {
// set up the managed repository
String localCachePath = getMandatoryProperty(props, REPO_LOCAL_STORE);
ManagedRepositoryConfiguration config = new ManagedRepositoryConfiguration();
config.setLocation(localCachePath);
config.setName("Imported Maven-Proxy Cache");
config.setId("maven-proxy");
config.setScanned(false);
config.setReleases(true);
config.setSnapshots(false);
configuration.addManagedRepository(config);
// Add the network proxies.
String propertyList = props.getProperty(PROXY_LIST);
if (propertyList != null) {
StringTokenizer tok = new StringTokenizer(propertyList, ",");
while (tok.hasMoreTokens()) {
String key = tok.nextToken();
if (StringUtils.isNotEmpty(key)) {
NetworkProxyConfiguration proxy = new NetworkProxyConfiguration();
proxy.setHost(getMandatoryProperty(props, "proxy." + key + ".host"));
proxy.setPort(Integer.parseInt(getMandatoryProperty(props, "proxy." + key + ".port")));
// the username and password isn't required
proxy.setUsername(props.getProperty("proxy." + key + ".username"));
proxy.setPassword(props.getProperty("proxy." + key + ".password"));
configuration.addNetworkProxy(proxy);
}
}
}
// Add the remote repository list
String repoList = getMandatoryProperty(props, REPO_LIST);
StringTokenizer tok = new StringTokenizer(repoList, ",");
while (tok.hasMoreTokens()) {
String key = tok.nextToken();
Properties repoProps = getSubset(props, "repo." + key + ".");
String url = getMandatoryProperty(props, "repo." + key + ".url");
String proxyKey = repoProps.getProperty("proxy");
// int cachePeriod = Integer.parseInt( repoProps.getProperty( "cache.period", "60" ) );
RemoteRepositoryConfiguration repository = new RemoteRepositoryConfiguration();
repository.setId(key);
repository.setName("Imported Maven-Proxy Remote Proxy");
repository.setUrl(url);
repository.setLayout("legacy");
configuration.addRemoteRepository(repository);
ProxyConnectorConfiguration proxyConnector = new ProxyConnectorConfiguration();
proxyConnector.setSourceRepoId("maven-proxy");
proxyConnector.setTargetRepoId(key);
proxyConnector.setProxyId(proxyKey);
// TODO: convert cachePeriod to closest "daily" or "hourly"
proxyConnector.addPolicy(ProxyConnectorConfiguration.POLICY_SNAPSHOTS, SnapshotsPolicy.DAILY.getId());
proxyConnector.addPolicy(ProxyConnectorConfiguration.POLICY_RELEASES, ReleasesPolicy.ALWAYS.getId());
configuration.addProxyConnector(proxyConnector);
}
}
use of org.apache.archiva.configuration.model.RemoteRepositoryConfiguration in project archiva by apache.
the class RemoteRepositoryHandlerTest method remove.
@Test
void remove() throws RepositoryException {
final String id = "test-repo-08";
RemoteRepositoryHandler repoHandler = createHandler();
RemoteRepositoryConfiguration configuration = new RemoteRepositoryConfiguration();
configuration.setId(id);
configuration.setName("n-" + id);
repoHandler.put(configuration);
assertTrue(hasRepositoryInConfig(id));
assertNotNull(repoHandler.get(id));
repoHandler.remove(id);
assertNull(repoHandler.get(id));
assertFalse(hasRepositoryInConfig(id));
}
use of org.apache.archiva.configuration.model.RemoteRepositoryConfiguration in project archiva by apache.
the class RemoteRepositoryHandlerTest method testPutWithoutRegister.
@Test
void testPutWithoutRegister() throws RepositoryException {
final String id = "test-repo-06";
RemoteRepositoryHandler repoHandler = createHandler();
Configuration aCfg = new Configuration();
RemoteRepositoryConfiguration configuration = new RemoteRepositoryConfiguration();
configuration.setId(id);
configuration.setName("n-" + id);
repoHandler.put(configuration, aCfg);
RemoteRepository repo = repoHandler.get(id);
assertNull(repo);
assertFalse(hasRepositoryInConfig(id));
assertTrue(aCfg.getRemoteRepositories().stream().anyMatch(g -> g != null && id.equals(g.getId())));
}
use of org.apache.archiva.configuration.model.RemoteRepositoryConfiguration in project archiva by apache.
the class RemoteRepositoryHandlerTest method putWithCheck_invalid.
@Test
void putWithCheck_invalid() throws RepositoryException {
final String id = "test-repo-07";
final String name = "n-" + id;
try {
RemoteRepositoryHandler repoHandler = createHandler();
BasicRemoteRepositoryValidator checker = new BasicRemoteRepositoryValidator(configurationHandler);
checker.setRepositoryRegistry(repositoryRegistry);
RemoteRepositoryConfiguration configuration = new RemoteRepositoryConfiguration();
configuration.setId("");
configuration.setName(name);
CheckedResult<RemoteRepository, Map<String, List<ValidationError>>> result = repoHandler.putWithCheck(configuration, checker);
assertNull(repoHandler.get(id));
assertNotNull(result.getResult());
assertNotNull(result.getResult().get("id"));
assertEquals(2, result.getResult().get("id").size());
assertEquals(ISEMPTY, result.getResult().get("id").get(0).getType());
assertFalse(hasRepositoryInConfig(id));
assertFalse(hasRepositoryInConfig(""));
} finally {
removeRepositoryFromConfig(id);
}
}
Aggregations