Search in sources :

Example 1 with ConfigurableMavenResolverSystem

use of org.jboss.shrinkwrap.resolver.api.maven.ConfigurableMavenResolverSystem in project wildfly-swarm by wildfly-swarm.

the class Main method getResolvingHelper.

private static ArtifactResolvingHelper getResolvingHelper(final List<String> repos) {
    final ConfigurableMavenResolverSystem resolver = Maven.configureResolver().withMavenCentralRepo(true).withRemoteRepo(MavenRemoteRepositories.createRemoteRepository("jboss-public-repository-group", "https://repository.jboss.org/nexus/content/groups/public/", "default").setChecksumPolicy(MavenChecksumPolicy.CHECKSUM_POLICY_IGNORE).setUpdatePolicy(MavenUpdatePolicy.UPDATE_POLICY_NEVER));
    repos.forEach(r -> resolver.withRemoteRepo(MavenRemoteRepositories.createRemoteRepository(r, r, "default").setChecksumPolicy(MavenChecksumPolicy.CHECKSUM_POLICY_IGNORE).setUpdatePolicy(MavenUpdatePolicy.UPDATE_POLICY_NEVER)));
    return new ShrinkwrapArtifactResolvingHelper(resolver);
}
Also used : ShrinkwrapArtifactResolvingHelper(org.wildfly.swarm.arquillian.resolver.ShrinkwrapArtifactResolvingHelper) ConfigurableMavenResolverSystem(org.jboss.shrinkwrap.resolver.api.maven.ConfigurableMavenResolverSystem)

Example 2 with ConfigurableMavenResolverSystem

use of org.jboss.shrinkwrap.resolver.api.maven.ConfigurableMavenResolverSystem in project component-runtime by Talend.

the class Dependencies method resolve.

public static URL[] resolve(final MavenDependency dep) {
    return CACHE.computeIfAbsent(dep, d -> {
        final ConfigurableMavenResolverSystem resolver = Maven.configureResolver().withClassPathResolution(true).workOffline(Boolean.getBoolean("talend.component.junit.maven.offline"));
        REPOSITORIES.forEach(resolver::withRemoteRepo);
        resolver.addDependency(dep);
        return Stream.of(resolver.resolve().using(STRATEGY).asFile()).distinct().map(f -> {
            try {
                return f.toURI().toURL();
            } catch (final MalformedURLException e) {
                throw new IllegalStateException(e);
            }
        }).toArray(URL[]::new);
    });
}
Also used : AcceptScopesStrategy(org.jboss.shrinkwrap.resolver.api.maven.strategy.AcceptScopesStrategy) URL(java.net.URL) MavenResolutionStrategy(org.jboss.shrinkwrap.resolver.api.maven.strategy.MavenResolutionStrategy) MavenChecksumPolicy(org.jboss.shrinkwrap.resolver.api.maven.repository.MavenChecksumPolicy) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) Maven(org.jboss.shrinkwrap.resolver.api.maven.Maven) MavenRemoteRepository(org.jboss.shrinkwrap.resolver.api.maven.repository.MavenRemoteRepository) PomEquippedResolveStageBaseImpl(org.jboss.shrinkwrap.resolver.impl.maven.PomEquippedResolveStageBaseImpl) MavenDependency(org.jboss.shrinkwrap.resolver.api.maven.coordinate.MavenDependency) MavenWorkingSession(org.jboss.shrinkwrap.resolver.api.maven.MavenWorkingSession) ScopeType(org.jboss.shrinkwrap.resolver.api.maven.ScopeType) MavenRemoteRepositories(org.jboss.shrinkwrap.resolver.api.maven.repository.MavenRemoteRepositories) MalformedURLException(java.net.MalformedURLException) PomEquippedResolveStage(org.jboss.shrinkwrap.resolver.api.maven.PomEquippedResolveStage) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Field(java.lang.reflect.Field) File(java.io.File) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) List(java.util.List) Stream(java.util.stream.Stream) ConfigurableMavenResolverSystem(org.jboss.shrinkwrap.resolver.api.maven.ConfigurableMavenResolverSystem) MavenUpdatePolicy(org.jboss.shrinkwrap.resolver.api.maven.repository.MavenUpdatePolicy) PRIVATE(lombok.AccessLevel.PRIVATE) NoArgsConstructor(lombok.NoArgsConstructor) MalformedURLException(java.net.MalformedURLException) ConfigurableMavenResolverSystem(org.jboss.shrinkwrap.resolver.api.maven.ConfigurableMavenResolverSystem)

Example 3 with ConfigurableMavenResolverSystem

use of org.jboss.shrinkwrap.resolver.api.maven.ConfigurableMavenResolverSystem in project bookkeeper by apache.

the class MavenClassLoader method createClassLoader.

private static MavenClassLoader createClassLoader(ConfigurableMavenResolverSystem resolver, String mainArtifact) throws Exception {
    Optional<String> slf4jVersion = Arrays.stream(resolver.resolve(mainArtifact).withTransitivity().asResolvedArtifact()).filter((a) -> a.getCoordinate().getGroupId().equals("org.slf4j") && a.getCoordinate().getArtifactId().equals("slf4j-log4j12")).map((a) -> a.getCoordinate().getVersion()).findFirst();
    List<MavenDependency> deps = Lists.newArrayList(MavenDependencies.createDependency(mainArtifact, ScopeType.COMPILE, false, MavenDependencies.createExclusion("org.slf4j:slf4j-log4j12"), MavenDependencies.createExclusion("log4j:log4j")));
    if (slf4jVersion.isPresent()) {
        deps.add(MavenDependencies.createDependency("org.slf4j:slf4j-simple:" + slf4jVersion.get(), ScopeType.COMPILE, false));
    }
    File[] files = resolver.addDependencies(deps.toArray(new MavenDependency[0])).resolve().withTransitivity().asFile();
    URLClassLoader cl = AccessController.doPrivileged(new PrivilegedAction<URLClassLoader>() {

        @Override
        public URLClassLoader run() {
            return new URLClassLoader(Arrays.stream(files).map((f) -> {
                try {
                    return f.toURI().toURL();
                } catch (Throwable t) {
                    throw new RuntimeException(t);
                }
            }).toArray(URL[]::new), ClassLoader.getSystemClassLoader());
        }
    });
    return new MavenClassLoader(cl);
}
Also used : ScopeType(org.jboss.shrinkwrap.resolver.api.maven.ScopeType) Arrays(java.util.Arrays) Proxy(java.lang.reflect.Proxy) Logger(org.slf4j.Logger) URL(java.net.URL) MethodHandles(java.lang.invoke.MethodHandles) LoggerFactory(org.slf4j.LoggerFactory) Closure(groovy.lang.Closure) PrivilegedAction(java.security.PrivilegedAction) Constructor(java.lang.reflect.Constructor) File(java.io.File) ArrayList(java.util.ArrayList) MavenDependencies(org.jboss.shrinkwrap.resolver.api.maven.coordinate.MavenDependencies) Maven(org.jboss.shrinkwrap.resolver.api.maven.Maven) URLClassLoader(java.net.URLClassLoader) List(java.util.List) Lists(com.google.common.collect.Lists) ConfigurableMavenResolverSystem(org.jboss.shrinkwrap.resolver.api.maven.ConfigurableMavenResolverSystem) Optional(java.util.Optional) InvocationHandler(java.lang.reflect.InvocationHandler) MavenDependency(org.jboss.shrinkwrap.resolver.api.maven.coordinate.MavenDependency) AccessController(java.security.AccessController) Method(java.lang.reflect.Method) URLClassLoader(java.net.URLClassLoader) File(java.io.File) MavenDependency(org.jboss.shrinkwrap.resolver.api.maven.coordinate.MavenDependency)

Example 4 with ConfigurableMavenResolverSystem

use of org.jboss.shrinkwrap.resolver.api.maven.ConfigurableMavenResolverSystem in project wildfly-swarm by wildfly-swarm.

the class ShrinkwrapArtifactResolvingHelper method defaultInstance.

public static ShrinkwrapArtifactResolvingHelper defaultInstance() {
    return INSTANCE.updateAndGet(e -> {
        if (e != null) {
            return e;
        }
        MavenRemoteRepository jbossPublic = MavenRemoteRepositories.createRemoteRepository("jboss-public-repository-group", "https://repository.jboss.org/nexus/content/groups/public/", "default");
        jbossPublic.setChecksumPolicy(MavenChecksumPolicy.CHECKSUM_POLICY_IGNORE);
        jbossPublic.setUpdatePolicy(MavenUpdatePolicy.UPDATE_POLICY_NEVER);
        MavenRemoteRepository gradleTools = MavenRemoteRepositories.createRemoteRepository("gradle", "http://repo.gradle.org/gradle/libs-releases-local", "default");
        gradleTools.setChecksumPolicy(MavenChecksumPolicy.CHECKSUM_POLICY_IGNORE);
        gradleTools.setUpdatePolicy(MavenUpdatePolicy.UPDATE_POLICY_NEVER);
        Boolean offline = Boolean.valueOf(System.getProperty("swarm.resolver.offline", "false"));
        final ConfigurableMavenResolverSystem resolver = Maven.configureResolver().withMavenCentralRepo(true).withRemoteRepo(jbossPublic).withRemoteRepo(gradleTools).workOffline(offline);
        final String additionalRepos = System.getProperty(SwarmInternalProperties.BUILD_REPOS);
        if (additionalRepos != null) {
            Arrays.asList(additionalRepos.split(",")).forEach(r -> {
                MavenRemoteRepository repo = MavenRemoteRepositories.createRemoteRepository(r, r, "default");
                repo.setChecksumPolicy(MavenChecksumPolicy.CHECKSUM_POLICY_IGNORE);
                repo.setUpdatePolicy(MavenUpdatePolicy.UPDATE_POLICY_NEVER);
                resolver.withRemoteRepo(repo);
            });
        }
        ShrinkwrapArtifactResolvingHelper helper = new ShrinkwrapArtifactResolvingHelper(resolver);
        helper.session().setCache(new SimpleRepositoryCache());
        helper.session().setUpdatePolicy(RepositoryPolicy.UPDATE_POLICY_DAILY);
        helper.session().setChecksumPolicy(RepositoryPolicy.CHECKSUM_POLICY_IGNORE);
        return helper;
    });
}
Also used : MavenRemoteRepository(org.jboss.shrinkwrap.resolver.api.maven.repository.MavenRemoteRepository) ConfigurableMavenResolverSystem(org.jboss.shrinkwrap.resolver.api.maven.ConfigurableMavenResolverSystem)

Example 5 with ConfigurableMavenResolverSystem

use of org.jboss.shrinkwrap.resolver.api.maven.ConfigurableMavenResolverSystem in project component-runtime by Talend.

the class BaseSpark method buildSparkHome.

private File buildSparkHome(final Version version) {
    final File sparkHome = new File(getRoot(), "spark/");
    Stream.of(version.libFolder(), "conf").map(n -> new File(sparkHome, n)).forEach(File::mkdirs);
    // deps
    final File libFolder = new File(sparkHome, version.libFolder());
    final ConfigurableMavenResolverSystem resolver = Maven.configureResolver();
    final MavenResolutionStrategy resolutionStrategy = new AcceptScopesStrategy(ScopeType.COMPILE, ScopeType.RUNTIME);
    Stream.of("org.apache.spark:spark-core_" + scalaVersion + ":" + sparkVersion, "org.apache.spark:spark-streaming_" + scalaVersion + ":" + sparkVersion).peek(dep -> LOGGER.info("Resolving " + dep + "...")).flatMap(dep -> Stream.of(resolver.resolve(dep).using(resolutionStrategy).asFile())).distinct().forEach(dep -> {
        try {
            LOGGER.debug("Copying " + dep.getName() + " dependency");
            Files.copy(dep.toPath(), new File(libFolder, dep.getName()).toPath(), StandardCopyOption.REPLACE_EXISTING);
        } catch (final IOException e) {
            fail(e.getMessage());
        }
    });
    if (version == Version.SPARK_1) {
        try {
            Files.write(new File(sparkHome, "RELEASE").toPath(), "fake release file cause it is tested in 1.6.3".getBytes(StandardCharsets.UTF_8), StandardOpenOption.CREATE_NEW);
        } catch (final IOException e) {
            fail(e.getMessage());
        }
        try (final JarOutputStream file = new JarOutputStream(new FileOutputStream(new File(sparkHome, version.libFolder() + "/spark-assembly-" + sparkVersion + "-hadoop2.6.0.jar")))) {
            file.putNextEntry(new ZipEntry("META-INF/marker"));
            file.write("just to let spark find the jar".getBytes(StandardCharsets.UTF_8));
        } catch (final IOException e) {
            fail(e.getMessage());
        }
    }
    if (isWin() && installWinUtils) {
        LOGGER.info("Downloading Hadoop winutils");
        // ensure hadoop winutils is locatable
        final String dll = hadoopBase + "/hadoop-" + hadoopVersion + "/bin/hadoop.dll";
        final String exe = hadoopBase + "/hadoop-" + hadoopVersion + "/bin/winutils.exe";
        new File(sparkHome, "bin").mkdirs();
        Stream.of(dll, exe).forEach(from -> {
            final File target = new File(sparkHome, "bin/" + from.substring(from.lastIndexOf('/') + 1));
            try {
                final URL url = new URL(from);
                try (final InputStream stream = url.openStream();
                    final OutputStream out = new FileOutputStream(target)) {
                    final byte[] buffer = new byte[8192];
                    int read;
                    while ((read = stream.read(buffer)) >= 0) {
                        out.write(read);
                    }
                } catch (final IOException e) {
                    throw new IllegalStateException(e);
                }
            } catch (final MalformedURLException e) {
                throw new IllegalArgumentException(e);
            }
        });
    }
    return sparkHome;
}
Also used : AcceptScopesStrategy(org.jboss.shrinkwrap.resolver.api.maven.strategy.AcceptScopesStrategy) URL(java.net.URL) MavenResolutionStrategy(org.jboss.shrinkwrap.resolver.api.maven.strategy.MavenResolutionStrategy) Optional.of(java.util.Optional.of) LoggerFactory(org.slf4j.LoggerFactory) SparkClusterRule(org.talend.sdk.component.runtime.testing.spark.SparkClusterRule) BooleanSupplier(java.util.function.BooleanSupplier) InetAddress(java.net.InetAddress) ServerSocket(java.net.ServerSocket) Maven(org.jboss.shrinkwrap.resolver.api.maven.Maven) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) Thread.sleep(java.lang.Thread.sleep) ENGLISH(java.util.Locale.ENGLISH) Path(java.nio.file.Path) ZipEntry(java.util.zip.ZipEntry) Collectors.toSet(java.util.stream.Collectors.toSet) ScopeType(org.jboss.shrinkwrap.resolver.api.maven.ScopeType) Predicate(java.util.function.Predicate) Collection(java.util.Collection) StandardOpenOption(java.nio.file.StandardOpenOption) Set(java.util.Set) Collectors.joining(java.util.stream.Collectors.joining) StandardCharsets(java.nio.charset.StandardCharsets) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) ClassLoaders(org.apache.ziplock.ClassLoaders) Stream(java.util.stream.Stream) ConfigurableMavenResolverSystem(org.jboss.shrinkwrap.resolver.api.maven.ConfigurableMavenResolverSystem) Optional(java.util.Optional) IntStream(java.util.stream.IntStream) Socket(java.net.Socket) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Getter(lombok.Getter) HashMap(java.util.HashMap) StandardCopyOption(java.nio.file.StandardCopyOption) ArrayList(java.util.ArrayList) UrlSet(org.apache.xbean.finder.UrlSet) JarEntry(java.util.jar.JarEntry) JarOutputStream(java.util.jar.JarOutputStream) OutputStream(java.io.OutputStream) Logger(org.slf4j.Logger) MalformedURLException(java.net.MalformedURLException) Files(java.nio.file.Files) Optional.ofNullable(java.util.Optional.ofNullable) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) Collectors.toList(java.util.stream.Collectors.toList) JarLocation.jarLocation(org.apache.ziplock.JarLocation.jarLocation) AllArgsConstructor(lombok.AllArgsConstructor) InputStream(java.io.InputStream) MalformedURLException(java.net.MalformedURLException) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) ByteArrayOutputStream(java.io.ByteArrayOutputStream) JarOutputStream(java.util.jar.JarOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) JarOutputStream(java.util.jar.JarOutputStream) AcceptScopesStrategy(org.jboss.shrinkwrap.resolver.api.maven.strategy.AcceptScopesStrategy) IOException(java.io.IOException) URL(java.net.URL) MavenResolutionStrategy(org.jboss.shrinkwrap.resolver.api.maven.strategy.MavenResolutionStrategy) FileOutputStream(java.io.FileOutputStream) File(java.io.File) ConfigurableMavenResolverSystem(org.jboss.shrinkwrap.resolver.api.maven.ConfigurableMavenResolverSystem)

Aggregations

ConfigurableMavenResolverSystem (org.jboss.shrinkwrap.resolver.api.maven.ConfigurableMavenResolverSystem)5 File (java.io.File)3 URL (java.net.URL)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Maven (org.jboss.shrinkwrap.resolver.api.maven.Maven)3 ScopeType (org.jboss.shrinkwrap.resolver.api.maven.ScopeType)3 MalformedURLException (java.net.MalformedURLException)2 Optional (java.util.Optional)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Lists (com.google.common.collect.Lists)1 Closure (groovy.lang.Closure)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 Thread.sleep (java.lang.Thread.sleep)1 MethodHandles (java.lang.invoke.MethodHandles)1