org.jboss.shrinkwrap.resolver.api.maven.strategy.MavenResolutionStrategy Java Examples

The following examples show how to use org.jboss.shrinkwrap.resolver.api.maven.strategy.MavenResolutionStrategy. 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: shrinkwrap.java    From jbang with MIT License 5 votes vote down vote up
@Override
public Integer call() throws Exception { // your business logic goes here...
    System.out.println("Hello " + greeting);

    ConfigurableMavenResolverSystem resolver = Maven.configureResolver()
            .withRemoteRepo("jcenter", "https://jcenter.bintray.com/", "default")
            .withMavenCentralRepo(false);
    
    //System.setProperty("maven.repo.local", Settings.getLocalMavenRepo().toPath().toAbsolutePath().toString());

    List<File> artifacts = resolver.resolve("log4j:log4j:1.2.17")
            .using(new MavenResolutionStrategy() {

                @Override
                public TransitiveExclusionPolicy getTransitiveExclusionPolicy() {
                    return new TransitiveExclusionPolicy() {
                        @Override
                        public boolean allowOptional() {
                            return true;
                        }

                        @Override
                        public ScopeType[] getFilteredScopes() {
                            return new ScopeType[]{ScopeType.PROVIDED, ScopeType.TEST};
                        }
                    };
                }

                @Override
                public MavenResolutionFilter[] getResolutionFilters() {
                    return new MavenResolutionFilter[0];
                }
            })
            .asList(File.class);

    artifacts.forEach(System.out::println);

    return CommandLine.ExitCode.OK;
}
 
Example #2
Source File: ShrinkwrapArtifactResolvingHelper.java    From thorntail with Apache License 2.0 4 votes vote down vote up
@Override
public Set<ArtifactSpec> resolveAll(final Collection<ArtifactSpec> specs, boolean transitive, boolean defaultExcludes) {
    if (specs.isEmpty()) {
        return Collections.emptySet();
    }

    final Set<ArtifactSpec> resolvedSpecs = new HashSet<>();
    // If we don't need transitive dependencies, then perform a dependency resolution only for the artifacts that do not have
    // a file reference.
    if (!transitive) {
        specs.stream().filter(s -> s.file != null).forEach(resolvedSpecs::add);
        specs.removeAll(resolvedSpecs);
        if (specs.isEmpty()) {
            return resolvedSpecs;
        }
    }

    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);
            });

    resolvedSpecs.addAll(
            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())
    );
    return resolvedSpecs;
}