org.wildfly.swarm.tools.ArtifactSpec Java Examples

The following examples show how to use org.wildfly.swarm.tools.ArtifactSpec. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GradleArtifactResolvingHelper.java    From wildfly-swarm with Apache License 2.0 6 votes vote down vote up
@Override
public Set<ArtifactSpec> resolveAll(final Set<ArtifactSpec> specs) throws Exception {
    if (specs.isEmpty()) {

        return specs;
    }

    final Set<ArtifactSpec> resolvedSpecs = new HashSet<>();

    doResolve(specs).forEach(dep -> dep.getModuleArtifacts()
            .forEach(artifact -> resolvedSpecs
                    .add(new ArtifactSpec(dep.getConfiguration(),
                                          dep.getModuleGroup(),
                                          artifact.getName(),
                                          dep.getModuleVersion(),
                                          artifact.getExtension(),
                                          artifact.getClassifier(),
                                          artifact.getFile()))));

    return resolvedSpecs.stream()
            .filter(a -> !"system".equals(a.scope))
            .collect(Collectors.toSet());
}
 
Example #2
Source File: ShrinkwrapArtifactResolvingHelper.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 6 votes vote down vote up
@Override
public Set<ArtifactSpec> resolveAll(final Set<ArtifactSpec> specs) {
    if (specs.isEmpty()) {

        return specs;
    }

    resetListeners();
    final MavenResolvedArtifact[] artifacts =
            withResolver(r -> r.resolve(specs.stream().map(ArtifactSpec::mavenGav).collect(Collectors.toList()))
                    .withTransitivity()
                    .as(MavenResolvedArtifact.class));

    return Arrays.stream(artifacts).map(artifact -> {
        final MavenCoordinate coord = artifact.getCoordinate();
        return new ArtifactSpec("compile",
                coord.getGroupId(),
                coord.getArtifactId(),
                coord.getVersion(),
                coord.getPackaging().getId(),
                coord.getClassifier(),
                artifact.asFile());
    }).collect(Collectors.toSet());
}
 
Example #3
Source File: GradleArtifactResolvingHelper.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 6 votes vote down vote up
private Set<ResolvedDependency> doResolve(final Collection<ArtifactSpec> deps) {
    final Configuration config = this.project.getConfigurations().detachedConfiguration();
    final DependencySet dependencySet = config.getDependencies();

    deps.forEach(spec -> {
        final DefaultExternalModuleDependency d =
                new DefaultExternalModuleDependency(spec.groupId(), spec.artifactId(), spec.version());
        final DefaultDependencyArtifact da =
                new DefaultDependencyArtifact(spec.artifactId(), spec.type(), spec.type(), spec.classifier(), null);
        d.addArtifact(da);
        d.getExcludeRules().add(new DefaultExcludeRule());
        dependencySet.add(d);
    });

    return config.getResolvedConfiguration().getFirstLevelModuleDependencies();
}
 
Example #4
Source File: GradleArtifactResolvingHelper.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 6 votes vote down vote up
@Override
public Set<ArtifactSpec> resolveAll(final Set<ArtifactSpec> specs) throws Exception {
    if (specs.isEmpty()) {

        return specs;
    }

    final Set<ArtifactSpec> resolvedSpecs = new HashSet<>();

    doResolve(specs).forEach(dep -> dep.getAllModuleArtifacts()
            .forEach(artifact -> resolvedSpecs
                    .add(new ArtifactSpec(dep.getConfiguration(),
                                          dep.getModuleGroup(),
                                          artifact.getName(),
                                          dep.getModuleVersion(),
                                          artifact.getExtension(),
                                          artifact.getClassifier(),
                                          artifact.getFile()))));

    return resolvedSpecs.stream()
            .filter(a -> !"system".equals(a.scope))
            .collect(Collectors.toSet());
}
 
Example #5
Source File: GradleArtifactResolvingHelper.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 6 votes vote down vote up
@Override
public ArtifactSpec resolve(final ArtifactSpec spec) {
    if (spec.file != null) {
        return spec;
    }

    final Iterator<ResolvedDependency> iterator =
            doResolve(new HashSet<>(Collections.singletonList(spec))).iterator();
    if (iterator.hasNext()) {
        spec.file = iterator.next()
                .getModuleArtifacts()
                .iterator().next()
                .getFile();

        return spec;
    }

    return null;
}
 
Example #6
Source File: MavenArtifactResolvingHelperTest.java    From thorntail with Apache License 2.0 6 votes vote down vote up
/**
 * Artifact extensions (suffixes) should be converted from artifact types according to this table:
 *
 * https://maven.apache.org/ref/3.6.0/maven-core/artifact-handlers.html
 */
@Test
public void testArtifactExtensions() throws Exception {
    // prepare mocks - always find an artifact in local repo
    Mockito.when(localRepositoryManager.find(Mockito.any(), Mockito.any(LocalArtifactRequest.class)))
            .thenReturn(new LocalArtifactResult(new LocalArtifactRequest())
                    .setAvailable(true).setFile(new File("test.jar")));


    MavenArtifactResolvingHelper artifactResolverHelper =
            new MavenArtifactResolvingHelper(resolver, system, sessionMock, null);
    // try to resolve artifacts with various packagings
    List<ArtifactSpec> artifacts = Arrays.asList(createSpec("ejb"), createSpec("pom"), createSpec("javadoc"));
    Set<ArtifactSpec> result = artifactResolverHelper.resolveAll(artifacts, false, false);


    Assert.assertEquals(3, result.size());
    ArgumentCaptor<LocalArtifactRequest> captor = ArgumentCaptor.forClass(LocalArtifactRequest.class);
    Mockito.verify(localRepositoryManager, Mockito.times(3)).find(Mockito.any(), captor.capture());
    // verify artifact extensions
    Assert.assertEquals("jar", captor.getAllValues().get(0).getArtifact().getExtension()); // packaging ejb
    Assert.assertEquals("pom", captor.getAllValues().get(1).getArtifact().getExtension()); // packaging pom
    Assert.assertEquals("jar", captor.getAllValues().get(2).getArtifact().getExtension()); // packaging javadoc
}
 
Example #7
Source File: MavenArtifactResolvingHelper.java    From thorntail with Apache License 2.0 6 votes vote down vote up
@Override
public ArtifactSpec resolve(ArtifactSpec spec) {
    if (spec.file == null) {
        final DefaultArtifact artifact = new DefaultArtifact(spec.groupId(), spec.artifactId(), spec.classifier(),
                typeToExtension(spec.type()), spec.version(), new DefaultArtifactType(spec.type()));

        final LocalArtifactResult localResult = this.session.getLocalRepositoryManager()
                .find(this.session, new LocalArtifactRequest(artifact, this.remoteRepositories, null));
        if (localResult.isAvailable()) {
            spec.file = localResult.getFile();
        } else {
            try {
                final ArtifactResult result = resolver.resolveArtifact(this.session,
                        new ArtifactRequest(artifact, this.remoteRepositories, null));
                if (result.isResolved()) {
                    spec.file = result.getArtifact().getFile();
                }
            } catch (ArtifactResolutionException e) {
                e.printStackTrace();
            }
        }
    }

    return spec.file != null ? spec : null;
}
 
Example #8
Source File: DependencyDescriptorTest.java    From thorntail with Apache License 2.0 6 votes vote down vote up
/**
 * The dependency descriptor will be serialized and consumed between the Gradle daemon and the Arquillian adapter. This
 * test ensures that the basics are working fine.
 */
@Test
public void verifyEqualsAndHashCode() {
    DependencyDescriptor dd1 =
            new DefaultDependencyDescriptor("compile", "org.wildfly.swarm", "test-artifact", "0.0.0", "jar", null, null);
    DependencyDescriptor dd2 =
            new DefaultDependencyDescriptor("compile", "org.wildfly.swarm", "test-artifact", "0.0.0", "jar", null, null);

    Assert.assertEquals("Equals method doesn't seem to be working.", dd1, dd2);
    Assert.assertEquals("Hashcode method doesn't seem to be working.", dd1.hashCode(), dd2.hashCode());

    // Convert it to an artifact-spec and then back again and compare.
    ArtifactSpec a1 = GradleToolingHelper.toArtifactSpec(dd1);
    dd2 = new DefaultDependencyDescriptor(a1);
    Assert.assertEquals("Equals method doesn't seem to be working.", dd1, dd2);
    Assert.assertEquals("Hashcode method doesn't seem to be working.", dd1.hashCode(), dd2.hashCode());
}
 
Example #9
Source File: GradleDependencyDeclarationFactory.java    From thorntail with Apache License 2.0 6 votes vote down vote up
/**
 * Resolve the given collection of ArtifactSpec references. This method attempts the resolution and ensures that the
 * references are updated to be as complete as possible.
 *
 * @param collection the collection artifact specifications.
 */
private static void resolveDependencies(Collection<ArtifactSpec> collection, ShrinkwrapArtifactResolvingHelper helper) {
    // Identify the artifact specs that need resolution.
    // Ideally, there should be none at this point.
    collection.forEach(spec -> {
        if (spec.file == null) {
            // Resolve it.
            ArtifactSpec resolved = helper.resolve(spec);
            if (resolved != null) {
                spec.file = resolved.file;
            } else {
                throw new IllegalStateException("Unable to resolve artifact: " + spec.toString());
            }
        }
    });
}
 
Example #10
Source File: GradleDependencyAdapter.java    From thorntail with Apache License 2.0 6 votes vote down vote up
/**
 * Compute the dependencies of a given {@code IdeaModule} and group them by their scope.
 *
 * Note: This method does not follow project->project dependencies. It just makes a note of them in a separate collection.
 *
 * @param module the IdeaModule reference.
 */
@SuppressWarnings("UnstableApiUsage")
private void computeProjectDependencies(IdeaModule module) {
    ARTIFACT_DEPS_OF_PRJ.computeIfAbsent(module.getName(), moduleName -> {
        Map<String, Set<ArtifactSpec>> dependencies = new HashMap<>();
        module.getDependencies().forEach(dep -> {
            if (dep instanceof IdeaModuleDependency) {
                // Add the dependency to the list.
                String name = ((IdeaModuleDependency) dep).getTargetModuleName();
                PRJ_DEPS_OF_PRJ.computeIfAbsent(moduleName, key -> new HashSet<>()).add(name);
            } else if (dep instanceof ExternalDependency) {
                ExternalDependency extDep = (ExternalDependency) dep;
                GradleModuleVersion gav = extDep.getGradleModuleVersion();
                ArtifactSpec spec = new ArtifactSpec("compile", gav.getGroup(), gav.getName(), gav.getVersion(),
                                                     "jar", null, extDep.getFile());
                String depScope = dep.getScope().getScope();
                dependencies.computeIfAbsent(depScope, s -> new HashSet<>()).add(spec);
            }
        });
        return dependencies;
    });
}
 
Example #11
Source File: FatJarBuilder.java    From thorntail with Apache License 2.0 6 votes vote down vote up
private ArtifactSpec toArtifactSpec(Path pom, String jarPath) {
    try {
        // TODO support properties?
        String groupId = extract(pom, "/project/groupId",
                () -> extract(pom, "/project/parent/groupId"));
        String artifactId = extract(pom, "/project/artifactId");
        String version = extract(pom, "/project/version",
                () -> extract(pom, "/project/parent/version"));
        String packaging = extract(pom, "/project/packaging", "jar");
        String classifier = extract(pom, "/project/classifier", (String) null);

        return new ArtifactSpec("compile",
                groupId, artifactId, version, packaging, classifier,
                new File(jarPath));
    } catch (Exception e) {
        throw new RuntimeException("Failed to read artifact spec from pom " + pom + " you may have an invalid jar downloaded.", e);
    }
}
 
Example #12
Source File: FatJarBuilder.java    From thorntail with Apache License 2.0 6 votes vote down vote up
private ArtifactOrFile urlToSpec(URL url) {
    String file = resolveUrlToFile(url);
    if (!url.toString().endsWith(".jar")) {
        return ArtifactOrFile.file(file);
    }
    // todo speed up?
    // todo: maybe speed up xml parsing?
    try (FileSystem fs = FileSystems.newFileSystem(Paths.get(file), getClass().getClassLoader())) {
        Optional<Path> maybePomXml = findPom(fs);

        ArtifactSpec spec = maybePomXml
                .map(pom -> toArtifactSpec(pom, file))
                .orElse(mockArtifactSpec(file)); // we should probably just skip'em
        return ArtifactOrFile.spec(spec);
    } catch (IOException e) {
        throw new RuntimeException("Failed to parse jar: " + file, e);
    }
}
 
Example #13
Source File: FatJarBuilder.java    From thorntail with Apache License 2.0 6 votes vote down vote up
private DeclaredDependencies declaredDependencies(List<ArtifactOrFile> specsOrUrls) {
    List<ArtifactSpec> specs =
            specsOrUrls.stream()
                    .filter(ArtifactOrFile::isJar)
                    .filter(ArtifactOrFile::hasSpec)
                    .map(ArtifactOrFile::spec)
                    .collect(toList());

    Arrays.stream(System.getProperty("thorntail.runner.extra-dependencies", "").split(","))
            .map(ArtifactSpec::fromMavenGav)
            .forEach(specs::add);

    return new DeclaredDependencies() {
        @Override
        public Collection<ArtifactSpec> getDirectDeps() {
            return specs;
        }

        @Override
        public Collection<ArtifactSpec> getTransientDeps(ArtifactSpec parent) {
            return Collections.emptyList();
        }
    };
}
 
Example #14
Source File: DependencyResolutionCache.java    From thorntail with Apache License 2.0 6 votes vote down vote up
public void storeCachedDependencies(Collection<ArtifactSpec> specs, List<ArtifactSpec> dependencySpecs, boolean defaultExcludes) {
    Path cachePath = getCacheFile(specs, defaultExcludes);

    if (cachePath == null) {
        return;
    }

    List<String> linesToStore = dependencySpecs.stream().map(ArtifactSpec::mavenGav).collect(Collectors.toList());

    try {
        storeToFile(cachePath, linesToStore);
    } catch (IOException e) {
        System.err.println("Failed to store cached dependencies to " + cachePath.toAbsolutePath().toString());
        e.printStackTrace();
        return;
    }
}
 
Example #15
Source File: GradleArtifactResolvingHelper.java    From wildfly-swarm with Apache License 2.0 6 votes vote down vote up
@Override
public ArtifactSpec resolve(final ArtifactSpec spec) {
    if (spec.file != null) {
        return spec;
    }

    final Iterator<ResolvedDependency> iterator =
            doResolve(new HashSet<>(Collections.singletonList(spec))).iterator();
    if (iterator.hasNext()) {
        spec.file = iterator.next()
                .getModuleArtifacts()
                .iterator().next()
                .getFile();

        return spec;
    }

    return null;
}
 
Example #16
Source File: CachingArtifactResolvingHelper.java    From thorntail with Apache License 2.0 6 votes vote down vote up
private Set<ArtifactSpec> resolveInParallel(Collection<ArtifactSpec> toResolve) throws InterruptedException {
    ExecutorService threadPool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 10);
    List<Callable<ArtifactSpec>> callable = toResolve.stream()
            .map(spec -> (Callable<ArtifactSpec>) (() -> this.resolve(spec)))
            .collect(Collectors.toList());

    List<Future<ArtifactSpec>> futures = threadPool.invokeAll(
            callable
    );
    Set<ArtifactSpec> result = futures.stream()
            .map(this::safeGet)
            .filter(Objects::nonNull)
            .collect(Collectors.toSet());
    threadPool.shutdown();
    return result;
}
 
Example #17
Source File: CachingArtifactResolvingHelper.java    From thorntail with Apache License 2.0 6 votes vote down vote up
private Collection<ArtifactSpec> resolveDependencies(List<ArtifactSpec> dependencyNodes) {
    // if dependencies were previously resolved, we don't need to resolve using remote repositories
    dependencyNodes = new ArrayList<>(dependencyNodes);

    return dependencyNodes.parallelStream()
            .filter(node -> !"system".equals(node.scope))
            .map(node -> new ArtifactSpec(node.scope,
                    node.groupId(),
                    node.artifactId(),
                    node.version(),
                    "bundle".equals(node.type()) ? "jar" : node.type(),
                    node.classifier(),
                    null))
            .map(this::resolve)
            .filter(Objects::nonNull)
            .collect(Collectors.toSet());
}
 
Example #18
Source File: CachingArtifactResolvingHelper.java    From thorntail with Apache License 2.0 6 votes vote down vote up
@Override
public ArtifactSpec resolve(ArtifactSpec spec) {
    if (spec.file == null) {
        File maybeFile = artifactCache.getCachedFile(spec);
        if (!artifactCache.isKnownFailure(spec) && maybeFile == null) {
            System.out.println("no cached file for " + spec.mavenGav());
            maybeFile = resolveArtifactFile(spec);
            artifactCache.storeArtifactFile(spec, maybeFile);
        }

        if (maybeFile == null) {
            artifactCache.storeResolutionFailure(spec);
            return null;
        }
        spec.file = maybeFile;
    }

    return spec;
}
 
Example #19
Source File: CachingArtifactResolvingHelper.java    From thorntail with Apache License 2.0 6 votes vote down vote up
private File resolveArtifactFile(ArtifactSpec spec) {
    ArtifactRequest request = new ArtifactRequest();
    request.setArtifact(artifact(spec));

    remoteRepositories.forEach(request::addRepository);

    try {
        ArtifactResult artifactResult = repoSystem.resolveArtifact(session, request);

        return artifactResult.isResolved()
                ? artifactResult.getArtifact().getFile()
                : null;
    } catch (ArtifactResolutionException e) {
        e.printStackTrace();
        return null;
    }
}
 
Example #20
Source File: GradleArtifactResolvingHelper.java    From wildfly-swarm with Apache License 2.0 6 votes vote down vote up
private Set<ResolvedDependency> doResolve(final Collection<ArtifactSpec> deps) {
    final Configuration config = this.project.getConfigurations().detachedConfiguration();
    final DependencySet dependencySet = config.getDependencies();

    deps.stream()
            .forEach(spec -> {
                if (projects.containsKey(spec.groupId() + ":" + spec.artifactId() + ":" + spec.version())) {
                    dependencySet.add(new DefaultProjectDependency((ProjectInternal) projects.get(spec.groupId() + ":" + spec.artifactId() + ":" + spec.version()), new DefaultProjectAccessListener(), false));
                } else {
                    final DefaultExternalModuleDependency d =
                            new DefaultExternalModuleDependency(spec.groupId(), spec.artifactId(), spec.version());
                    final DefaultDependencyArtifact da =
                            new DefaultDependencyArtifact(spec.artifactId(), spec.type(), spec.type(), spec.classifier(), null);
                    d.addArtifact(da);
                    d.getExcludeRules().add(new DefaultExcludeRule());
                    dependencySet.add(d);
                }
            });

    return config.getResolvedConfiguration().getFirstLevelModuleDependencies();
}
 
Example #21
Source File: AbstractSwarmMojo.java    From thorntail with Apache License 2.0 5 votes vote down vote up
private static ArtifactSpec asBucketKey(Artifact artifact) {

        return new ArtifactSpec(
                artifact.getScope(),
                artifact.getGroupId(),
                artifact.getArtifactId(),
                artifact.getBaseVersion(),
                artifact.getType(),
                artifact.getClassifier(),
                artifact.getFile()
        );
    }
 
Example #22
Source File: DefaultDependencyDescriptor.java    From thorntail with Apache License 2.0 5 votes vote down vote up
/**
 * Construct a new instance of {@code DefaultDependencyDescriptor} from the given {@link ArtifactSpec} reference.
 */
public DefaultDependencyDescriptor(ArtifactSpec spec) {
    this.scope = spec.scope;
    this.groupId = spec.groupId();
    this.artifactId = spec.artifactId();
    this.version = spec.version();
    this.type = spec.type();
    this.classifier = spec.classifier();
    this.file = spec.file;
    this.spec = spec;
}
 
Example #23
Source File: GradleToolingHelper.java    From thorntail with Apache License 2.0 5 votes vote down vote up
/**
 * Translate the given dependency tree in to an instance of {@link DeclaredDependencies}.
 */
public static DeclaredDependencies toDeclaredDependencies(Map<DependencyDescriptor, Set<DependencyDescriptor>> depMap) {
    DeclaredDependencies dependencies = new DeclaredDependencies();
    depMap.forEach((directDep, resolvedDeps) -> {
        ArtifactSpec parent = toArtifactSpec(directDep);
        dependencies.add(parent);
        if (resolvedDeps != null) {
            resolvedDeps.forEach(d -> dependencies.add(parent, toArtifactSpec(d)));
        }
        dependencies.markComplete(parent);
    });
    return dependencies;
}
 
Example #24
Source File: GradleArtifactResolvingHelper.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@Override
public ArtifactSpec resolve(final ArtifactSpec spec) {
    Set<ArtifactSpec> resolved = GradleDependencyResolutionHelper.resolveArtifacts(project, Collections.singleton(spec),
                                                                                   false, false);
    ArtifactSpec result = null;
    if (!resolved.isEmpty()) {
        result = resolved.iterator().next();
        if (result.file == null) {
            result = null;
        }
    }
    return result;
}
 
Example #25
Source File: Main.java    From thorntail with Apache License 2.0 5 votes vote down vote up
private static void addSwarmFractions(BuildTool tool, final List<String> deps) {
    deps.stream().map(f -> f.split(":"))
            .map(parts -> {
                switch (parts.length) {
                    case 1:
                        final FractionDescriptor desc = FractionList.get()
                                .getFractionDescriptor("io.thorntail", parts[0]);
                        if (desc != null) {

                            return desc;
                        } else {
                            System.err.println("Warning: Unknown fraction: " + parts[0]);

                            return null;
                        }
                    case 2:

                        return new FractionDescriptor("io.thorntail", parts[0], parts[1]);
                    case 3:

                        return new FractionDescriptor(parts[0], parts[1], parts[2]);
                    default:
                        System.err.println("Warning: Invalid fraction specifier: " + String.join(":", parts));

                        return null;
                }
            })
            .filter(f -> f != null)
            .forEach(f -> tool.fraction(ArtifactSpec.fromFractionDescriptor(f)));
}
 
Example #26
Source File: ShrinkwrapArtifactResolvingHelper.java    From thorntail with Apache License 2.0 5 votes vote down vote up
public MavenDependency createMavenDependency(final ArtifactSpec spec) {
    final MavenCoordinate newCoordinate = MavenCoordinates.createCoordinate(
            spec.groupId(),
            spec.artifactId(),
            spec.version(),
            PackagingType.of(spec.type()),
            spec.classifier());
    return MavenDependencies.createDependency(newCoordinate, ScopeType.fromScopeType(spec.scope), false);
}
 
Example #27
Source File: CachingArtifactResolvingHelper.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@Override
public Set<ArtifactSpec> resolveAll(Collection<ArtifactSpec> specs, boolean transitive, boolean defaultExcludes) throws Exception {
    if (specs.isEmpty()) {
        return Collections.emptySet();
    }
    Collection<ArtifactSpec> toResolve = specs;
    if (transitive) {
        toResolve = resolveDependencies(specs, defaultExcludes);
    }

    return resolveInParallel(toResolve);
}
 
Example #28
Source File: AbstractSwarmMojo.java    From thorntail with Apache License 2.0 5 votes vote down vote up
protected ArtifactSpec artifactToArtifactSpec(Artifact dep) {
    return new ArtifactSpec(dep.getScope(),
                            dep.getGroupId(),
                            dep.getArtifactId(),
                            dep.getBaseVersion(),
                            dep.getType(),
                            dep.getClassifier(),
                            dep.getFile());
}
 
Example #29
Source File: AbstractSwarmMojo.java    From thorntail with Apache License 2.0 5 votes vote down vote up
protected Map<ArtifactSpec, Set<ArtifactSpec>> createBuckets(Set<Artifact> transientDeps, List<Dependency> directDeps) {
    Map<ArtifactSpec, Set<ArtifactSpec>> buckets = new HashMap<>();
    for (Artifact dep : transientDeps) {
        if (dep.getDependencyTrail().isEmpty()) {
            throw new RuntimeException("Empty trail " + asBucketKey(dep));
        } else if (dep.getDependencyTrail().size() == 2) {
            ArtifactSpec key = asBucketKey(dep);
            //System.out.println("Appears to be top level: "+ key);
            if (!buckets.containsKey(key)) {
                buckets.put(key, new HashSet<>());
            }
        } else {

            String owner = dep.getDependencyTrail().get(1);
            String ownerScope = null;
            String[] tokens = owner.split(":");
            for (Dependency d : directDeps) {
                if (d.getGroupId().equals(tokens[0])
                        && d.getArtifactId().equals(tokens[1])) {
                    ownerScope = d.getScope();
                    break;
                }
            }

            assert ownerScope != null : "Failed to resolve owner scope";

            ArtifactSpec parent = DeclaredDependencies.createSpec(owner, ownerScope);
            if (!buckets.containsKey(parent)) {
                buckets.put(parent, new HashSet<>());
            }
            buckets.get(parent).add(asBucketKey(dep));
        }
    }
    return buckets;
}
 
Example #30
Source File: MavenArtifactResolvingHelper.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
@Override
public Set<ArtifactSpec> resolveAll(Set<ArtifactSpec> specs) throws Exception {
    if (specs.isEmpty()) {

        return specs;
    }

    final CollectRequest request = new CollectRequest();
    request.setRepositories(this.remoteRepositories);

    specs.forEach(spec -> request
            .addDependency(new Dependency(new DefaultArtifact(spec.groupId(),
                    spec.artifactId(),
                    spec.classifier(),
                    spec.type(),
                    spec.version()),
                    "compile")));

    CollectResult result = this.system.collectDependencies(this.session, request);

    PreorderNodeListGenerator gen = new PreorderNodeListGenerator();
    result.getRoot().accept(gen);

    return gen.getNodes().stream()
            .filter(node -> !"system".equals(node.getDependency().getScope()))
            .map(node -> {
                final Artifact artifact = node.getArtifact();

                return new ArtifactSpec(node.getDependency().getScope(),
                        artifact.getGroupId(),
                        artifact.getArtifactId(),
                        artifact.getVersion(),
                        artifact.getExtension(),
                        artifact.getClassifier(),
                        null);
            })
            .map(this::resolve)
            .filter(x -> x != null)
            .collect(Collectors.toSet());
}