Search in sources :

Example 1 with MavenConfiguration

use of io.fabric8.maven.util.MavenConfiguration 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
        }
    }
}
Also used : MavenConfiguration(io.fabric8.maven.util.MavenConfiguration) MavenConfigurationImpl(io.fabric8.maven.util.MavenConfigurationImpl) MavenResolver(io.fabric8.maven.MavenResolver) DictionaryPropertyResolver(org.ops4j.util.property.DictionaryPropertyResolver) IOException(java.io.IOException) PropertyResolver(org.ops4j.util.property.PropertyResolver) DictionaryPropertyResolver(org.ops4j.util.property.DictionaryPropertyResolver)

Example 2 with MavenConfiguration

use of io.fabric8.maven.util.MavenConfiguration in project fabric8 by jboss-fuse.

the class AetherTimeoutTest method connectionTimeout.

@Test
public void connectionTimeout() throws Exception {
    final MavenConfigurationImpl mavenConfiguration = basicMavenConfigurationWithTwoTimeouts(5000, 500);
    mavenConfiguration.setSettings(settingsWithUnresponsiveRepository());
    Future<Boolean> ok = pool.submit(new ResolveArtifactTask(mavenConfiguration, 0));
    try {
        boolean resolved = ok.get(3000, TimeUnit.MILLISECONDS);
        assertFalse(resolved);
    } catch (TimeoutException e) {
        fail("Should fail due to connection timeout earlier.");
    }
}
Also used : MavenConfigurationImpl(io.fabric8.maven.util.MavenConfigurationImpl) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 3 with MavenConfiguration

use of io.fabric8.maven.util.MavenConfiguration 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();
    }
}
Also used : ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) MavenConfigurationImpl(io.fabric8.maven.util.MavenConfigurationImpl) ArtifactTransferException(org.eclipse.aether.transfer.ArtifactTransferException) MavenResolver(io.fabric8.maven.MavenResolver) RepositoryException(org.eclipse.aether.RepositoryException) IOException(java.io.IOException) ArtifactNotFoundException(org.eclipse.aether.transfer.ArtifactNotFoundException) Test(org.junit.Test)

Example 4 with MavenConfiguration

use of io.fabric8.maven.util.MavenConfiguration in project fabric8 by jboss-fuse.

the class AetherResolutionWithHintsTest method mavenConfiguration.

private MavenConfigurationImpl mavenConfiguration() {
    Properties properties = new Properties();
    properties.setProperty("pid.localRepository", "target/" + UUID.randomUUID().toString());
    properties.setProperty("pid.globalChecksumPolicy", "ignore");
    properties.setProperty("pid.timeout", "1000");
    properties.setProperty("pid.connection.retryCount", "0");
    return new MavenConfigurationImpl(new PropertiesPropertyResolver(properties), "pid");
}
Also used : MavenConfigurationImpl(io.fabric8.maven.util.MavenConfigurationImpl) PropertiesPropertyResolver(org.ops4j.util.property.PropertiesPropertyResolver) Properties(java.util.Properties)

Example 5 with MavenConfiguration

use of io.fabric8.maven.util.MavenConfiguration in project fabric8 by jboss-fuse.

the class ProfileWatcherImpl method retrieveMavenConfiguration.

protected MavenConfiguration retrieveMavenConfiguration() {
    MavenConfiguration mavenConfiguration = null;
    try {
        Configuration configuration = configurationAdmin.get().getConfiguration("org.ops4j.pax.url.mvn");
        if (configuration != null) {
            Dictionary dictonary = configuration.getProperties();
            if (dictonary != null) {
                DictionaryPropertyResolver resolver = new DictionaryPropertyResolver(dictonary);
                mavenConfiguration = new MavenConfigurationImpl(resolver, "org.ops4j.pax.url.mvn");
            }
        }
    } catch (IOException e) {
        LOG.error("Error retrieving maven configuration", e);
    }
    return mavenConfiguration;
}
Also used : MavenConfiguration(io.fabric8.maven.util.MavenConfiguration) Dictionary(java.util.Dictionary) MavenConfigurationImpl(io.fabric8.maven.util.MavenConfigurationImpl) Configuration(org.osgi.service.cm.Configuration) MavenConfiguration(io.fabric8.maven.util.MavenConfiguration) DictionaryPropertyResolver(org.ops4j.util.property.DictionaryPropertyResolver) IOException(java.io.IOException)

Aggregations

MavenConfigurationImpl (io.fabric8.maven.util.MavenConfigurationImpl)6 IOException (java.io.IOException)3 Test (org.junit.Test)3 MavenResolver (io.fabric8.maven.MavenResolver)2 MavenConfiguration (io.fabric8.maven.util.MavenConfiguration)2 TimeoutException (java.util.concurrent.TimeoutException)2 DictionaryPropertyResolver (org.ops4j.util.property.DictionaryPropertyResolver)2 Dictionary (java.util.Dictionary)1 Properties (java.util.Properties)1 RepositoryException (org.eclipse.aether.RepositoryException)1 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)1 ArtifactNotFoundException (org.eclipse.aether.transfer.ArtifactNotFoundException)1 ArtifactTransferException (org.eclipse.aether.transfer.ArtifactTransferException)1 PropertiesPropertyResolver (org.ops4j.util.property.PropertiesPropertyResolver)1 PropertyResolver (org.ops4j.util.property.PropertyResolver)1 Configuration (org.osgi.service.cm.Configuration)1