Search in sources :

Example 1 with DefaultArtifactType

use of org.eclipse.aether.artifact.DefaultArtifactType in project buck by facebook.

the class Resolver method getDependenciesFromPom.

private ImmutableList<Dependency> getDependenciesFromPom(Model model) {
    return model.getDependencies().stream().map(dep -> {
        ArtifactType stereotype = session.getArtifactTypeRegistry().get(dep.getType());
        if (stereotype == null) {
            stereotype = new DefaultArtifactType(dep.getType());
        }
        Map<String, String> props = null;
        boolean system = dep.getSystemPath() != null && dep.getSystemPath().length() > 0;
        if (system) {
            props = ImmutableMap.of(ArtifactProperties.LOCAL_PATH, dep.getSystemPath());
        }
        @SuppressWarnings("PMD.PrematureDeclaration") DefaultArtifact artifact = new DefaultArtifact(dep.getGroupId(), dep.getArtifactId(), dep.getClassifier(), null, dep.getVersion(), props, stereotype);
        ImmutableList<Exclusion> exclusions = FluentIterable.from(dep.getExclusions()).transform(input -> {
            String group = input.getGroupId();
            String artifact1 = input.getArtifactId();
            group = (group == null || group.length() == 0) ? "*" : group;
            artifact1 = (artifact1 == null || artifact1.length() == 0) ? "*" : artifact1;
            return new Exclusion(group, artifact1, "*", "*");
        }).toList();
        return new Dependency(artifact, dep.getScope(), dep.isOptional(), exclusions);
    }).collect(MoreCollectors.toImmutableList());
}
Also used : ServiceLocator(org.eclipse.aether.spi.locator.ServiceLocator) STGroupString(org.stringtemplate.v4.STGroupString) DefaultDependencyManagementInjector(org.apache.maven.model.management.DefaultDependencyManagementInjector) SortedSet(java.util.SortedSet) DependencyFilterUtils(org.eclipse.aether.util.filter.DependencyFilterUtils) Version(org.eclipse.aether.version.Version) URL(java.net.URL) TEST(org.eclipse.aether.util.artifact.JavaScopes.TEST) DefaultModelBuilderFactory(org.apache.maven.model.building.DefaultModelBuilderFactory) ArtifactDescriptorException(org.eclipse.aether.resolution.ArtifactDescriptorException) Matcher(java.util.regex.Matcher) ModelBuilder(org.apache.maven.model.building.ModelBuilder) FluentIterable(com.google.common.collect.FluentIterable) DefaultProfileSelector(org.apache.maven.model.profile.DefaultProfileSelector) SubArtifact(org.eclipse.aether.util.artifact.SubArtifact) Map(java.util.Map) DefaultArtifactType(org.eclipse.aether.artifact.DefaultArtifactType) Path(java.nio.file.Path) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) DefaultDependencyManagementImporter(org.apache.maven.model.composition.DefaultDependencyManagementImporter) LocalRepository(org.eclipse.aether.repository.LocalRepository) Function(com.google.common.base.Function) ImmutableMap(com.google.common.collect.ImmutableMap) RepositoryPolicy(org.eclipse.aether.repository.RepositoryPolicy) Collection(java.util.Collection) Artifact(org.eclipse.aether.artifact.Artifact) Executors(java.util.concurrent.Executors) Objects(java.util.Objects) CmdLineException(org.kohsuke.args4j.CmdLineException) List(java.util.List) ModelBuildingResult(org.apache.maven.model.building.ModelBuildingResult) ST(org.stringtemplate.v4.ST) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) ArtifactDescriptorResult(org.eclipse.aether.resolution.ArtifactDescriptorResult) DependencyResult(org.eclipse.aether.resolution.DependencyResult) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) Model(org.apache.maven.model.Model) RepositorySystem(org.eclipse.aether.RepositorySystem) DependencyFilter(org.eclipse.aether.graph.DependencyFilter) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) ArtifactDescriptorRequest(org.eclipse.aether.resolution.ArtifactDescriptorRequest) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) VersionScheme(org.eclipse.aether.version.VersionScheme) ArtifactProperties(org.eclipse.aether.artifact.ArtifactProperties) Dependency(org.eclipse.aether.graph.Dependency) JavaScopes(org.eclipse.aether.util.artifact.JavaScopes) MutableDirectedGraph(com.facebook.buck.graph.MutableDirectedGraph) GenericVersionScheme(org.eclipse.aether.util.version.GenericVersionScheme) Callable(java.util.concurrent.Callable) TraversableGraph(com.facebook.buck.graph.TraversableGraph) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) TreeSet(java.util.TreeSet) ArtifactType(org.eclipse.aether.artifact.ArtifactType) ImmutableList(com.google.common.collect.ImmutableList) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) Nullable(javax.annotation.Nullable) MoreCollectors(com.facebook.buck.util.MoreCollectors) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) CollectRequest(org.eclipse.aether.collection.CollectRequest) Resources(com.google.common.io.Resources) DefaultPluginConfigurationExpander(org.apache.maven.model.plugin.DefaultPluginConfigurationExpander) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Files(java.nio.file.Files) UTF_8(java.nio.charset.StandardCharsets.UTF_8) ModelBuildingException(org.apache.maven.model.building.ModelBuildingException) MostExecutors(com.facebook.buck.util.concurrent.MostExecutors) MavenRepositorySystemUtils(org.apache.maven.repository.internal.MavenRepositorySystemUtils) IOException(java.io.IOException) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) DependencyRequest(org.eclipse.aether.resolution.DependencyRequest) Maps(com.google.common.collect.Maps) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) InvalidVersionSpecificationException(org.eclipse.aether.version.InvalidVersionSpecificationException) ExecutionException(java.util.concurrent.ExecutionException) MorePaths(com.facebook.buck.io.MorePaths) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) Futures(com.google.common.util.concurrent.Futures) Ordering(com.google.common.collect.Ordering) RepositoryException(org.eclipse.aether.RepositoryException) Paths(java.nio.file.Paths) DefaultPluginManagementInjector(org.apache.maven.model.management.DefaultPluginManagementInjector) DefaultModelBuildingRequest(org.apache.maven.model.building.DefaultModelBuildingRequest) Exclusion(org.eclipse.aether.graph.Exclusion) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) DefaultArtifactType(org.eclipse.aether.artifact.DefaultArtifactType) ArtifactType(org.eclipse.aether.artifact.ArtifactType) ImmutableList(com.google.common.collect.ImmutableList) Exclusion(org.eclipse.aether.graph.Exclusion) DefaultArtifactType(org.eclipse.aether.artifact.DefaultArtifactType) STGroupString(org.stringtemplate.v4.STGroupString) Dependency(org.eclipse.aether.graph.Dependency) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Example 2 with DefaultArtifactType

use of org.eclipse.aether.artifact.DefaultArtifactType in project fabric8 by jboss-fuse.

the class AetherBasedResolver method newRepositorySystemSession.

private static DefaultRepositorySystemSession newRepositorySystemSession() {
    DefaultRepositorySystemSession session = new DefaultRepositorySystemSession();
    DependencyTraverser depTraverser = new FatArtifactTraverser();
    session.setDependencyTraverser(depTraverser);
    DependencyManager depManager = new ClassicDependencyManager();
    session.setDependencyManager(depManager);
    DependencySelector depFilter = new AndDependencySelector(new ScopeDependencySelector("test", "provided"), new OptionalDependencySelector(), new ExclusionDependencySelector());
    session.setDependencySelector(depFilter);
    DependencyGraphTransformer transformer = new ConflictResolver(new NearestVersionSelector(), new JavaScopeSelector(), new SimpleOptionalitySelector(), new JavaScopeDeriver());
    new ChainedDependencyGraphTransformer(transformer, new JavaDependencyContextRefiner());
    session.setDependencyGraphTransformer(transformer);
    DefaultArtifactTypeRegistry stereotypes = new DefaultArtifactTypeRegistry();
    stereotypes.add(new DefaultArtifactType("pom"));
    stereotypes.add(new DefaultArtifactType("maven-plugin", "jar", "", "java"));
    stereotypes.add(new DefaultArtifactType("jar", "jar", "", "java"));
    stereotypes.add(new DefaultArtifactType("ejb", "jar", "", "java"));
    stereotypes.add(new DefaultArtifactType("ejb-client", "jar", "client", "java"));
    stereotypes.add(new DefaultArtifactType("test-jar", "jar", "tests", "java"));
    stereotypes.add(new DefaultArtifactType("javadoc", "jar", "javadoc", "java"));
    stereotypes.add(new DefaultArtifactType("java-source", "jar", "sources", "java", false, false));
    stereotypes.add(new DefaultArtifactType("war", "war", "", "java", false, true));
    stereotypes.add(new DefaultArtifactType("ear", "ear", "", "java", false, true));
    stereotypes.add(new DefaultArtifactType("rar", "rar", "", "java", false, true));
    stereotypes.add(new DefaultArtifactType("par", "par", "", "java", false, true));
    session.setArtifactTypeRegistry(stereotypes);
    session.setArtifactDescriptorPolicy(new SimpleArtifactDescriptorPolicy(true, true));
    Properties sysProps = (Properties) System.getProperties().clone();
    session.setSystemProperties(sysProps);
    session.setConfigProperties(sysProps);
    // set timeout smaller than 30 minutes by default
    session.setConfigProperty(ConfigurationProperties.REQUEST_TIMEOUT, TimeUnit.MINUTES.toMillis(5));
    return session;
}
Also used : JavaDependencyContextRefiner(org.eclipse.aether.util.graph.transformer.JavaDependencyContextRefiner) ConflictResolver(org.eclipse.aether.util.graph.transformer.ConflictResolver) ClassicDependencyManager(org.eclipse.aether.util.graph.manager.ClassicDependencyManager) DependencyManager(org.eclipse.aether.collection.DependencyManager) JavaScopeDeriver(org.eclipse.aether.util.graph.transformer.JavaScopeDeriver) AndDependencySelector(org.eclipse.aether.util.graph.selector.AndDependencySelector) DependencyTraverser(org.eclipse.aether.collection.DependencyTraverser) ConfigurationProperties(org.eclipse.aether.ConfigurationProperties) ArtifactProperties(org.eclipse.aether.artifact.ArtifactProperties) Properties(java.util.Properties) FatArtifactTraverser(org.eclipse.aether.util.graph.traverser.FatArtifactTraverser) ChainedDependencyGraphTransformer(org.eclipse.aether.util.graph.transformer.ChainedDependencyGraphTransformer) OptionalDependencySelector(org.eclipse.aether.util.graph.selector.OptionalDependencySelector) SimpleOptionalitySelector(org.eclipse.aether.util.graph.transformer.SimpleOptionalitySelector) NearestVersionSelector(org.eclipse.aether.util.graph.transformer.NearestVersionSelector) ClassicDependencyManager(org.eclipse.aether.util.graph.manager.ClassicDependencyManager) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) DefaultArtifactTypeRegistry(org.eclipse.aether.util.artifact.DefaultArtifactTypeRegistry) JavaScopeSelector(org.eclipse.aether.util.graph.transformer.JavaScopeSelector) AndDependencySelector(org.eclipse.aether.util.graph.selector.AndDependencySelector) ScopeDependencySelector(org.eclipse.aether.util.graph.selector.ScopeDependencySelector) OptionalDependencySelector(org.eclipse.aether.util.graph.selector.OptionalDependencySelector) ExclusionDependencySelector(org.eclipse.aether.util.graph.selector.ExclusionDependencySelector) DependencySelector(org.eclipse.aether.collection.DependencySelector) ChainedDependencyGraphTransformer(org.eclipse.aether.util.graph.transformer.ChainedDependencyGraphTransformer) DependencyGraphTransformer(org.eclipse.aether.collection.DependencyGraphTransformer) DefaultArtifactType(org.eclipse.aether.artifact.DefaultArtifactType) SimpleArtifactDescriptorPolicy(org.eclipse.aether.util.repository.SimpleArtifactDescriptorPolicy) ScopeDependencySelector(org.eclipse.aether.util.graph.selector.ScopeDependencySelector) ExclusionDependencySelector(org.eclipse.aether.util.graph.selector.ExclusionDependencySelector)

Aggregations

MutableDirectedGraph (com.facebook.buck.graph.MutableDirectedGraph)1 TraversableGraph (com.facebook.buck.graph.TraversableGraph)1 MorePaths (com.facebook.buck.io.MorePaths)1 MoreCollectors (com.facebook.buck.util.MoreCollectors)1 MostExecutors (com.facebook.buck.util.concurrent.MostExecutors)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Function (com.google.common.base.Function)1 Preconditions (com.google.common.base.Preconditions)1 FluentIterable (com.google.common.collect.FluentIterable)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSetMultimap (com.google.common.collect.ImmutableSetMultimap)1 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)1 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)1 Maps (com.google.common.collect.Maps)1 Ordering (com.google.common.collect.Ordering)1 Resources (com.google.common.io.Resources)1 Futures (com.google.common.util.concurrent.Futures)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)1