Search in sources :

Example 1 with MavenResolver

use of io.fabric8.maven.MavenResolver 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 MavenResolver

use of io.fabric8.maven.MavenResolver 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 3 with MavenResolver

use of io.fabric8.maven.MavenResolver 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);
}
Also used : MavenConfigurationImpl(io.fabric8.maven.util.MavenConfigurationImpl) PropertiesPropertyResolver(org.ops4j.util.property.PropertiesPropertyResolver) DictionaryPropertyResolver(org.ops4j.util.property.DictionaryPropertyResolver) AetherBasedResolver(io.fabric8.maven.url.internal.AetherBasedResolver)

Example 4 with MavenResolver

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

the class MavenProxyResolutionTest method releaseIsAvailableInRemoteRepositoryNotUpdatingRelease.

@Test
public void releaseIsAvailableInRemoteRepositoryNotUpdatingRelease() throws IOException, InvalidMavenArtifactRequest {
    File remoteRepository = initFileRepository("rr");
    MavenResolver resolver = new ResolverBuilder().withRemoteRepositories(Collections.singletonList(remoteRepository)).withUpdatePolicy(RepositoryPolicy.UPDATE_POLICY_ALWAYS).build();
    MavenDownloadProxyServlet servlet = new MavenDownloadProxyServlet(resolver, runtime, null, 1, 0);
    mvnInstall(remoteRepository, "io.fabric8.test", "universalis-api", "0.1.0", at("10:00"), "a");
    File file = servlet.download("io/fabric8/test/universalis-api/0.1.0/universalis-api-0.1.0.jar");
    // first resolution
    assertThat(FileUtils.readFileToString(file), equalTo("a"));
    // don't do that, it's not proper use of maven. But sometimes we just have another deployment to public repository...
    mvnInstall(remoteRepository, "io.fabric8.test", "universalis-api", "0.1.0", at("11:00"), "b");
    // second resolution
    file = servlet.download("io/fabric8/test/universalis-api/0.1.0/universalis-api-0.1.0.jar");
    assertThat("Artifact won't be updated for release version", FileUtils.readFileToString(file), equalTo("a"));
}
Also used : MavenResolver(io.fabric8.maven.MavenResolver) File(java.io.File) Test(org.junit.Test)

Example 5 with MavenResolver

use of io.fabric8.maven.MavenResolver 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);
}
Also used : MavenConfigurationImpl(io.fabric8.maven.util.MavenConfigurationImpl) Proxy(org.apache.maven.settings.Proxy) Hashtable(java.util.Hashtable) DictionaryPropertyResolver(org.ops4j.util.property.DictionaryPropertyResolver) AetherBasedResolver(io.fabric8.maven.url.internal.AetherBasedResolver)

Aggregations

MavenResolver (io.fabric8.maven.MavenResolver)23 File (java.io.File)18 Test (org.junit.Test)11 IOException (java.io.IOException)9 Metadata (org.apache.maven.artifact.repository.metadata.Metadata)6 Hashtable (java.util.Hashtable)5 DownloadManager (io.fabric8.agent.download.DownloadManager)4 RuntimeProperties (io.fabric8.api.RuntimeProperties)4 AbstractRuntimeProperties (io.fabric8.api.scr.AbstractRuntimeProperties)4 MavenConfigurationImpl (io.fabric8.maven.util.MavenConfigurationImpl)4 HashMap (java.util.HashMap)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Server (org.eclipse.jetty.server.Server)3 ServerConnector (org.eclipse.jetty.server.ServerConnector)3 DictionaryPropertyResolver (org.ops4j.util.property.DictionaryPropertyResolver)3 DownloadCallback (io.fabric8.agent.download.DownloadCallback)2 Downloader (io.fabric8.agent.download.Downloader)2 StreamProvider (io.fabric8.agent.download.StreamProvider)2