use of io.fabric8.maven.url.internal.AetherBasedResolver in project fabric8 by jboss-fuse.
the class Activator method updated.
public void updated(Dictionary<String, ?> config) {
PropertyResolver propertyResolver;
if (config == null) {
propertyResolver = new PropertyResolver() {
@Override
public String get(String propertyName) {
return m_bundleContext.getProperty(propertyName);
}
};
} else {
propertyResolver = new DictionaryPropertyResolver(config);
}
MavenConfiguration mavenConfig = new MavenConfigurationImpl(propertyResolver, PID);
MavenResolver resolver = new AetherBasedResolver(mavenConfig);
MavenResolver oldResolver = m_resolver.getAndSet(resolver);
ServiceRegistration<MavenResolver> registration = m_bundleContext.registerService(MavenResolver.class, resolver, null);
registration = m_resolverReg.getAndSet(registration);
if (registration != null) {
registration.unregister();
}
if (oldResolver != null) {
try {
oldResolver.close();
} catch (IOException e) {
// Ignore
}
}
}
use of io.fabric8.maven.url.internal.AetherBasedResolver in project fabric8 by jboss-fuse.
the class AetherResolutionWithHintsTest method hintedResolution.
@Test
public void hintedResolution() throws Exception {
final MavenConfigurationImpl mavenConfiguration = mavenConfiguration();
mavenConfiguration.setSettings(settingsWithProxy());
MavenResolver resolver = new AetherBasedResolver(mavenConfiguration);
try {
resolver.download("mvn:org.ops4j.pax.web/pax-web-api/1");
fail("Resolution should fail");
} catch (IOException e) {
RepositoryException exception = ((AetherBasedResolver) resolver).findAetherException(e);
assertNotNull(exception);
assertTrue(exception instanceof ArtifactResolutionException);
ArtifactResolutionException are = (ArtifactResolutionException) exception;
assertThat(are.getResult().getExceptions().size(), equalTo(3));
assertTrue("Non-retryable exception", are.getResult().getExceptions().get(0) instanceof ArtifactNotFoundException);
assertTrue("Non-retryable exception", are.getResult().getExceptions().get(1) instanceof ArtifactNotFoundException);
assertTrue("Retryable exception", are.getResult().getExceptions().get(2) instanceof ArtifactTransferException);
assertFalse("Retryable exception", are.getResult().getExceptions().get(2) instanceof ArtifactNotFoundException);
try {
// try again with exception hint
resolver.download("mvn:org.ops4j.pax.web/pax-web-api/1", e);
fail("Resolution should fail");
} catch (IOException e2) {
exception = ((AetherBasedResolver) resolver).findAetherException(e2);
assertNotNull(exception);
assertTrue(exception instanceof ArtifactResolutionException);
are = (ArtifactResolutionException) exception;
assertThat(are.getResult().getExceptions().size(), equalTo(1));
assertTrue("Retryable exception", are.getResult().getExceptions().get(0) instanceof ArtifactTransferException);
assertFalse("Retryable exception", are.getResult().getExceptions().get(0) instanceof ArtifactNotFoundException);
}
} finally {
resolver.close();
}
}
use of io.fabric8.maven.url.internal.AetherBasedResolver in project fabric8 by jboss-fuse.
the class MavenResolvers method createMavenResolver.
public static MavenResolver createMavenResolver(Mirror mirror, Dictionary<String, String> properties, String pid, RepositorySystem repositorySystem) {
PropertiesPropertyResolver syspropsResolver = new PropertiesPropertyResolver(System.getProperties());
DictionaryPropertyResolver propertyResolver = new DictionaryPropertyResolver(properties, syspropsResolver);
MavenConfigurationImpl config = new MavenConfigurationImpl(propertyResolver, pid);
return new AetherBasedResolver(config, mirror, repositorySystem);
}
use of io.fabric8.maven.url.internal.AetherBasedResolver in project fabric8 by jboss-fuse.
the class MavenProxyServletSupportTest method createResolver.
private MavenResolver createResolver(String localRepo, List<String> remoteRepos, String proxyProtocol, String proxyHost, int proxyPort, String proxyUsername, String proxyPassword, String proxyNonProxyHosts) {
Hashtable<String, String> props = new Hashtable<>();
props.put("localRepository", localRepo);
if (remoteRepos != null) {
props.put("repositories", join(remoteRepos, ","));
}
MavenConfigurationImpl config = new MavenConfigurationImpl(new DictionaryPropertyResolver(props), null);
if (proxyProtocol != null) {
Proxy proxy = new Proxy();
proxy.setProtocol(proxyProtocol);
proxy.setHost(proxyHost);
proxy.setPort(proxyPort);
proxy.setUsername(proxyUsername);
proxy.setPassword(proxyPassword);
proxy.setNonProxyHosts(proxyNonProxyHosts);
config.getSettings().addProxy(proxy);
}
return new AetherBasedResolver(config);
}
use of io.fabric8.maven.url.internal.AetherBasedResolver in project fabric8 by jboss-fuse.
the class Log4jLogQuery method loadCoords.
protected String loadCoords(String coords, String filePath, String classifier) throws IOException {
String[] split = coords.split("/");
if (split != null && split.length > 2) {
String groupId = split[0];
String artifactId = split[1];
String version = split[2];
if (resolver == null) {
Properties defaultProperties = getDefaultProperties();
Properties systemProperties = System.getProperties();
if (config == null) {
Properties combined = new Properties();
combined.putAll(defaultProperties);
combined.putAll(systemProperties);
if (properties != null) {
combined.putAll(properties);
}
config = new MavenConfigurationImpl(new PropertiesPropertyResolver(combined), ServiceConstants.PID);
}
resolver = new AetherBasedResolver(config);
}
File file = resolver.resolveFile(groupId, artifactId, classifier, "jar", version);
if (file.exists() && file.isFile()) {
if (isRoot(filePath)) {
return jarIndex(file);
}
String fileUri = file.toURI().toString();
URL url = new URL("jar:" + fileUri + "!" + filePath);
return loadString(url);
}
}
return null;
}
Aggregations