Search in sources :

Example 1 with MavenResolutionStrategy

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

the class ShrinkwrapArtifactResolvingHelper method resolveAll.

@Override
public Set<ArtifactSpec> resolveAll(final Collection<ArtifactSpec> specs, boolean transitive, boolean defaultExcludes) {
    if (specs.isEmpty()) {
        return Collections.emptySet();
    }
    MavenResolutionStrategy transitivityStrategy = (transitive ? TransitiveStrategy.INSTANCE : NonTransitiveStrategy.INSTANCE);
    resetListeners();
    final MavenResolvedArtifact[] artifacts = withResolver(r -> {
        specs.forEach(spec -> r.addDependency(createMavenDependency(spec)));
        return r.resolve().using(transitivityStrategy).as(MavenResolvedArtifact.class);
    });
    return Arrays.stream(artifacts).map(artifact -> {
        final MavenCoordinate coord = artifact.getCoordinate();
        return new ArtifactSpec(artifact.getScope().toString(), coord.getGroupId(), coord.getArtifactId(), coord.getVersion(), coord.getPackaging().getId(), coord.getClassifier(), artifact.asFile());
    }).collect(Collectors.toSet());
}
Also used : Arrays(java.util.Arrays) MavenResolutionStrategy(org.jboss.shrinkwrap.resolver.api.maven.strategy.MavenResolutionStrategy) MavenChecksumPolicy(org.jboss.shrinkwrap.resolver.api.maven.repository.MavenChecksumPolicy) Settings(org.apache.maven.settings.Settings) PackagingType(org.jboss.shrinkwrap.resolver.api.maven.PackagingType) AtomicReference(java.util.concurrent.atomic.AtomicReference) Maven(org.jboss.shrinkwrap.resolver.api.maven.Maven) MavenRemoteRepository(org.jboss.shrinkwrap.resolver.api.maven.repository.MavenRemoteRepository) ConfigurableMavenWorkingSessionImpl(org.jboss.shrinkwrap.resolver.impl.maven.ConfigurableMavenWorkingSessionImpl) TransitiveStrategy(org.jboss.shrinkwrap.resolver.api.maven.strategy.TransitiveStrategy) MavenDependency(org.jboss.shrinkwrap.resolver.api.maven.coordinate.MavenDependency) MavenCoordinates(org.jboss.shrinkwrap.resolver.api.maven.coordinate.MavenCoordinates) Method(java.lang.reflect.Method) ScopeType(org.jboss.shrinkwrap.resolver.api.maven.ScopeType) MavenRemoteRepositories(org.jboss.shrinkwrap.resolver.api.maven.repository.MavenRemoteRepositories) RepositoryPolicy(org.eclipse.aether.repository.RepositoryPolicy) Collection(java.util.Collection) SwarmInternalProperties(org.wildfly.swarm.spi.api.internal.SwarmInternalProperties) Set(java.util.Set) Collectors(java.util.stream.Collectors) File(java.io.File) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) InvocationTargetException(java.lang.reflect.InvocationTargetException) MavenDependencies(org.jboss.shrinkwrap.resolver.api.maven.coordinate.MavenDependencies) MavenWorkingSessionContainer(org.jboss.shrinkwrap.resolver.impl.maven.MavenWorkingSessionContainer) ArtifactResolvingHelper(org.wildfly.swarm.tools.ArtifactResolvingHelper) RepositoryListener(org.eclipse.aether.RepositoryListener) ConfigurableMavenResolverSystem(org.jboss.shrinkwrap.resolver.api.maven.ConfigurableMavenResolverSystem) MavenResolvedArtifact(org.jboss.shrinkwrap.resolver.api.maven.MavenResolvedArtifact) MavenUpdatePolicy(org.jboss.shrinkwrap.resolver.api.maven.repository.MavenUpdatePolicy) NonTransitiveStrategy(org.jboss.shrinkwrap.resolver.api.maven.strategy.NonTransitiveStrategy) MavenCoordinate(org.jboss.shrinkwrap.resolver.api.maven.coordinate.MavenCoordinate) Collections(java.util.Collections) ArtifactSpec(org.wildfly.swarm.tools.ArtifactSpec) MavenResolutionStrategy(org.jboss.shrinkwrap.resolver.api.maven.strategy.MavenResolutionStrategy) MavenResolvedArtifact(org.jboss.shrinkwrap.resolver.api.maven.MavenResolvedArtifact) ArtifactSpec(org.wildfly.swarm.tools.ArtifactSpec) MavenCoordinate(org.jboss.shrinkwrap.resolver.api.maven.coordinate.MavenCoordinate)

Example 2 with MavenResolutionStrategy

use of org.jboss.shrinkwrap.resolver.api.maven.strategy.MavenResolutionStrategy 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

File (java.io.File)2 Collection (java.util.Collection)2 Set (java.util.Set)2 ConfigurableMavenResolverSystem (org.jboss.shrinkwrap.resolver.api.maven.ConfigurableMavenResolverSystem)2 Maven (org.jboss.shrinkwrap.resolver.api.maven.Maven)2 ScopeType (org.jboss.shrinkwrap.resolver.api.maven.ScopeType)2 MavenResolutionStrategy (org.jboss.shrinkwrap.resolver.api.maven.strategy.MavenResolutionStrategy)2 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 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 InetAddress (java.net.InetAddress)1 MalformedURLException (java.net.MalformedURLException)1 ServerSocket (java.net.ServerSocket)1 Socket (java.net.Socket)1 URL (java.net.URL)1