Search in sources :

Example 31 with IvyArtifactName

use of org.gradle.internal.component.model.IvyArtifactName in project gradle by gradle.

the class DefaultArtifactMetadataSource method listModuleVersions.

@Override
public void listModuleVersions(ModuleDependencyMetadata dependency, ModuleIdentifier module, List<ResourcePattern> ivyPatterns, List<ResourcePattern> artifactPatterns, VersionLister versionLister, BuildableModuleVersionListingResolveResult result) {
    // List modules with missing metadata files
    IvyArtifactName dependencyArtifact = getPrimaryDependencyArtifact(dependency);
    versionLister.listVersions(module, dependencyArtifact, artifactPatterns, result);
}
Also used : DefaultIvyArtifactName(org.gradle.internal.component.model.DefaultIvyArtifactName) IvyArtifactName(org.gradle.internal.component.model.IvyArtifactName)

Example 32 with IvyArtifactName

use of org.gradle.internal.component.model.IvyArtifactName in project gradle by gradle.

the class DefaultArtifactSet method toResolvedVariant.

public static ResolvedVariant toResolvedVariant(VariantResolveMetadata variant, ModuleVersionIdentifier ownerId, ModuleSources moduleSources, ExcludeSpec exclusions, ArtifactResolver artifactResolver, Map<ComponentArtifactIdentifier, ResolvableArtifact> allResolvedArtifacts, ImmutableAttributes variantAttributes, CalculatedValueContainerFactory calculatedValueContainerFactory) {
    List<? extends ComponentArtifactMetadata> artifacts = variant.getArtifacts();
    ImmutableSet.Builder<ResolvableArtifact> resolvedArtifacts = ImmutableSet.builder();
    boolean hasExcludedArtifact = false;
    for (ComponentArtifactMetadata artifact : artifacts) {
        IvyArtifactName artifactName = artifact.getName();
        if (exclusions.excludesArtifact(ownerId.getModule(), artifactName)) {
            hasExcludedArtifact = true;
            continue;
        }
        ResolvableArtifact resolvedArtifact = allResolvedArtifacts.get(artifact.getId());
        if (resolvedArtifact == null) {
            if (artifact.isOptionalArtifact()) {
                DefaultBuildableArtifactResolveResult result = new DefaultBuildableArtifactResolveResult();
                artifactResolver.resolveArtifact(artifact, moduleSources, result);
                if (!result.isSuccessful()) {
                    // Optional artifact is not available
                    continue;
                }
            }
            ValueCalculator<File> artifactCalculator;
            if (artifactResolver instanceof ProjectArtifactResolver) {
                artifactCalculator = ((ProjectArtifactResolver) artifactResolver).resolveArtifactLater(artifact);
            } else {
                // TODO - push this up to all ArtifactResolver implementations
                artifactCalculator = new LazyArtifactSupplier(artifact, moduleSources, artifactResolver);
            }
            CalculatedValue<File> artifactSource = calculatedValueContainerFactory.create(Describables.of(artifact.getId()), artifactCalculator);
            resolvedArtifact = new DefaultResolvableArtifact(ownerId, artifactName, artifact.getId(), context -> context.add(artifact.getBuildDependencies()), artifactSource, calculatedValueContainerFactory);
            allResolvedArtifacts.put(artifact.getId(), resolvedArtifact);
        }
        resolvedArtifacts.add(resolvedArtifact);
    }
    VariantResolveMetadata.Identifier identifier = variant.getIdentifier();
    if (hasExcludedArtifact) {
        // An ad hoc variant, has no identifier
        identifier = null;
    }
    return ArtifactBackedResolvedVariant.create(identifier, variant.asDescribable(), variantAttributes, withImplicitCapability(variant, ownerId), resolvedArtifacts.build());
}
Also used : ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier) AttributesSchemaInternal(org.gradle.api.internal.attributes.AttributesSchemaInternal) DefaultResolvableArtifact(org.gradle.api.internal.artifacts.DefaultResolvableArtifact) ComponentArtifactMetadata(org.gradle.internal.component.model.ComponentArtifactMetadata) ModuleSources(org.gradle.internal.component.model.ModuleSources) ExtraExecutionGraphDependenciesResolverFactory(org.gradle.api.internal.artifacts.transform.ExtraExecutionGraphDependenciesResolverFactory) ComponentConfigurationIdentifier(org.gradle.internal.component.model.ComponentConfigurationIdentifier) ValueCalculator(org.gradle.internal.model.ValueCalculator) ComponentIdentifier(org.gradle.api.artifacts.component.ComponentIdentifier) VariantResolveMetadata(org.gradle.internal.component.model.VariantResolveMetadata) ConfigurationMetadata(org.gradle.internal.component.model.ConfigurationMetadata) ArtifactResolver(org.gradle.internal.resolve.resolver.ArtifactResolver) Describables(org.gradle.internal.Describables) ImmutableList(com.google.common.collect.ImmutableList) ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) NodeExecutionContext(org.gradle.api.internal.tasks.NodeExecutionContext) ProjectInternal(org.gradle.api.internal.project.ProjectInternal) ImmutableCapabilities(org.gradle.internal.component.external.model.ImmutableCapabilities) Map(java.util.Map) Describable(org.gradle.api.Describable) ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) Nullable(javax.annotation.Nullable) CapabilitiesMetadata(org.gradle.api.capabilities.CapabilitiesMetadata) TransformedVariantFactory(org.gradle.api.internal.artifacts.transform.TransformedVariantFactory) VariantDefinition(org.gradle.api.internal.artifacts.transform.VariantDefinition) ImmutableCapability(org.gradle.internal.component.external.model.ImmutableCapability) CalculatedValue(org.gradle.internal.model.CalculatedValue) ImmutableSet(com.google.common.collect.ImmutableSet) TaskDependencyResolveContext(org.gradle.api.internal.tasks.TaskDependencyResolveContext) ArtifactTypeRegistry(org.gradle.api.internal.artifacts.type.ArtifactTypeRegistry) Collection(java.util.Collection) VariantSelector(org.gradle.api.internal.artifacts.transform.VariantSelector) Set(java.util.Set) ComponentArtifactIdentifier(org.gradle.api.artifacts.component.ComponentArtifactIdentifier) ExcludeSpec(org.gradle.api.internal.artifacts.ivyservice.resolveengine.excludes.specs.ExcludeSpec) File(java.io.File) DefaultBuildableArtifactResolveResult(org.gradle.internal.resolve.result.DefaultBuildableArtifactResolveResult) List(java.util.List) CalculatedValueContainerFactory(org.gradle.internal.model.CalculatedValueContainerFactory) Spec(org.gradle.api.specs.Spec) IvyArtifactName(org.gradle.internal.component.model.IvyArtifactName) ProjectArtifactResolver(org.gradle.api.internal.artifacts.ivyservice.projectmodule.ProjectArtifactResolver) DefaultVariantMetadata(org.gradle.internal.component.model.DefaultVariantMetadata) ProjectArtifactResolver(org.gradle.api.internal.artifacts.ivyservice.projectmodule.ProjectArtifactResolver) VariantResolveMetadata(org.gradle.internal.component.model.VariantResolveMetadata) DefaultBuildableArtifactResolveResult(org.gradle.internal.resolve.result.DefaultBuildableArtifactResolveResult) DefaultResolvableArtifact(org.gradle.api.internal.artifacts.DefaultResolvableArtifact) ImmutableSet(com.google.common.collect.ImmutableSet) ComponentArtifactMetadata(org.gradle.internal.component.model.ComponentArtifactMetadata) DefaultResolvableArtifact(org.gradle.api.internal.artifacts.DefaultResolvableArtifact) IvyArtifactName(org.gradle.internal.component.model.IvyArtifactName) File(java.io.File)

Example 33 with IvyArtifactName

use of org.gradle.internal.component.model.IvyArtifactName in project gradle by gradle.

the class ModuleExclusions method forExclude.

private ExcludeSpec forExclude(ExcludeMetadata r) {
    return metadataToExcludeCache.computeIfAbsent(r, rule -> {
        // For custom ivy pattern matchers, don't inspect the rule any more deeply: this prevents us from doing smart merging later
        if (!PatternMatchers.isExactMatcher(rule.getMatcher())) {
            return factory.ivyPatternExclude(rule.getModuleId(), rule.getArtifact(), rule.getMatcher());
        }
        ModuleIdentifier moduleId = rule.getModuleId();
        IvyArtifactName artifact = rule.getArtifact();
        boolean anyOrganisation = isWildcard(moduleId.getGroup());
        boolean anyModule = isWildcard(moduleId.getName());
        // Build a strongly typed (mergeable) exclude spec for each supplied rule
        if (artifact == null) {
            if (!anyOrganisation && !anyModule) {
                return factory.moduleId(moduleId);
            } else if (!anyModule) {
                return factory.module(moduleId.getName());
            } else if (!anyOrganisation) {
                return factory.group(moduleId.getGroup());
            } else {
                return factory.everything();
            }
        } else {
            return factory.ivyPatternExclude(moduleId, artifact, rule.getMatcher());
        }
    });
}
Also used : IvyArtifactName(org.gradle.internal.component.model.IvyArtifactName) ModuleIdentifier(org.gradle.api.artifacts.ModuleIdentifier)

Example 34 with IvyArtifactName

use of org.gradle.internal.component.model.IvyArtifactName in project gradle by gradle.

the class IvyBackedArtifactPublisher method publish.

public void publish(final Iterable<? extends PublicationAwareRepository> repositories, final Module module, final Configuration configuration, final File descriptor) throws PublishException {
    Set<ConfigurationInternal> allConfigurations = Cast.uncheckedCast(configuration.getAll());
    Set<ConfigurationInternal> configurationsToPublish = Cast.uncheckedCast(configuration.getHierarchy());
    if (descriptor != null) {
        // Convert once, in order to write the Ivy descriptor with _all_ configurations
        IvyModulePublishMetadata publishMetaData = toPublishMetaData(module, allConfigurations);
        validatePublishMetaData(publishMetaData);
        ivyModuleDescriptorWriter.write(publishMetaData, descriptor);
    }
    // Convert a second time with only the published configurations: this ensures that the correct artifacts are included
    BuildableIvyModulePublishMetadata publishMetaData = toPublishMetaData(module, configurationsToPublish);
    if (descriptor != null) {
        IvyArtifactName artifact = new DefaultIvyArtifactName("ivy", "ivy", "xml");
        publishMetaData.addArtifact(artifact, descriptor);
    }
    List<ModuleVersionPublisher> publishResolvers = new ArrayList<ModuleVersionPublisher>();
    for (PublicationAwareRepository repository : repositories) {
        ModuleVersionPublisher publisher = repository.createPublisher();
        publishResolvers.add(publisher);
    }
    dependencyPublisher.publish(publishResolvers, publishMetaData);
}
Also used : DefaultIvyArtifactName(org.gradle.internal.component.model.DefaultIvyArtifactName) DefaultIvyArtifactName(org.gradle.internal.component.model.DefaultIvyArtifactName) IvyArtifactName(org.gradle.internal.component.model.IvyArtifactName) ArrayList(java.util.ArrayList) BuildableIvyModulePublishMetadata(org.gradle.internal.component.external.model.BuildableIvyModulePublishMetadata) PublicationAwareRepository(org.gradle.api.internal.artifacts.repositories.PublicationAwareRepository) IvyModulePublishMetadata(org.gradle.internal.component.external.model.IvyModulePublishMetadata) BuildableIvyModulePublishMetadata(org.gradle.internal.component.external.model.BuildableIvyModulePublishMetadata) DefaultIvyModulePublishMetadata(org.gradle.internal.component.external.model.DefaultIvyModulePublishMetadata) ConfigurationInternal(org.gradle.api.internal.artifacts.configurations.ConfigurationInternal) ModuleVersionPublisher(org.gradle.api.internal.artifacts.ModuleVersionPublisher)

Example 35 with IvyArtifactName

use of org.gradle.internal.component.model.IvyArtifactName in project gradle by gradle.

the class ResourceVersionLister method newVisitor.

public VersionPatternVisitor newVisitor(final ModuleIdentifier module, final Collection<String> dest, final ResourceAwareResolveResult result) {
    return new VersionPatternVisitor() {

        final Set<ExternalResourceName> directories = new HashSet<ExternalResourceName>();

        public void visit(ResourcePattern pattern, IvyArtifactName artifact) throws ResourceException {
            ExternalResourceName versionListPattern = pattern.toVersionListPattern(module, artifact);
            LOGGER.debug("Listing all in {}", versionListPattern);
            try {
                List<String> versionStrings = listRevisionToken(versionListPattern);
                for (String versionString : versionStrings) {
                    dest.add(versionString);
                }
            } catch (Exception e) {
                throw ResourceExceptions.failure(versionListPattern.getUri(), String.format("Could not list versions using %s.", pattern), e);
            }
        }

        // lists all the values a revision token listed by a given url lister
        private List<String> listRevisionToken(ExternalResourceName versionListPattern) {
            String pattern = versionListPattern.getPath();
            if (!pattern.contains(REVISION_TOKEN)) {
                LOGGER.debug("revision token not defined in pattern {}.", pattern);
                return Collections.emptyList();
            }
            String prefix = pattern.substring(0, pattern.indexOf(REVISION_TOKEN));
            if (revisionMatchesDirectoryName(pattern)) {
                ExternalResourceName parent = versionListPattern.getRoot().resolve(prefix);
                return listAll(parent);
            } else {
                int parentFolderSlashIndex = prefix.lastIndexOf(fileSeparator);
                String revisionParentFolder = parentFolderSlashIndex == -1 ? "" : prefix.substring(0, parentFolderSlashIndex + 1);
                ExternalResourceName parent = versionListPattern.getRoot().resolve(revisionParentFolder);
                LOGGER.debug("using {} to list all in {} ", repository, revisionParentFolder);
                if (!directories.add(parent)) {
                    return Collections.emptyList();
                }
                result.attempted(parent);
                List<String> all = repository.list(parent.getUri());
                if (all == null) {
                    return Collections.emptyList();
                }
                LOGGER.debug("found {} urls", all.size());
                Pattern regexPattern = createRegexPattern(pattern, parentFolderSlashIndex);
                List<String> ret = filterMatchedValues(all, regexPattern);
                LOGGER.debug("{} matched {}", ret.size(), pattern);
                return ret;
            }
        }

        private List<String> filterMatchedValues(List<String> all, final Pattern p) {
            List<String> ret = new ArrayList<String>(all.size());
            for (String path : all) {
                Matcher m = p.matcher(path);
                if (m.matches()) {
                    String value = m.group(1);
                    ret.add(value);
                }
            }
            return ret;
        }

        private Pattern createRegexPattern(String pattern, int prefixLastSlashIndex) {
            int endNameIndex = pattern.indexOf(fileSeparator, prefixLastSlashIndex + 1);
            String namePattern;
            if (endNameIndex != -1) {
                namePattern = pattern.substring(prefixLastSlashIndex + 1, endNameIndex);
            } else {
                namePattern = pattern.substring(prefixLastSlashIndex + 1);
            }
            namePattern = namePattern.replaceAll("\\.", "\\\\.");
            String acceptNamePattern = namePattern.replaceAll("\\[revision\\]", "(.+)");
            return Pattern.compile(acceptNamePattern);
        }

        private boolean revisionMatchesDirectoryName(String pattern) {
            int startToken = pattern.indexOf(REVISION_TOKEN);
            if (startToken > 0 && !pattern.substring(startToken - 1, startToken).equals(fileSeparator)) {
                // previous character is not a separator
                return false;
            }
            int endToken = startToken + REV_TOKEN_LENGTH;
            if (endToken < pattern.length() && !pattern.substring(endToken, endToken + 1).equals(fileSeparator)) {
                // next character is not a separator
                return false;
            }
            return true;
        }

        private List<String> listAll(ExternalResourceName parent) {
            if (!directories.add(parent)) {
                return Collections.emptyList();
            }
            LOGGER.debug("using {} to list all in {}", repository, parent);
            result.attempted(parent.toString());
            List<String> paths = repository.list(parent.getUri());
            if (paths == null) {
                return Collections.emptyList();
            }
            LOGGER.debug("found {} resources", paths.size());
            return paths;
        }
    };
}
Also used : Pattern(java.util.regex.Pattern) ExternalResourceName(org.gradle.internal.resource.ExternalResourceName) Matcher(java.util.regex.Matcher) ResourceException(org.gradle.api.resources.ResourceException) IvyArtifactName(org.gradle.internal.component.model.IvyArtifactName)

Aggregations

IvyArtifactName (org.gradle.internal.component.model.IvyArtifactName)52 DefaultIvyArtifactName (org.gradle.internal.component.model.DefaultIvyArtifactName)28 DefaultExclude (org.gradle.internal.component.external.descriptor.DefaultExclude)7 ExcludeMetadata (org.gradle.internal.component.model.ExcludeMetadata)7 File (java.io.File)6 Artifact (org.gradle.internal.component.external.descriptor.Artifact)6 ModuleIdentifier (org.gradle.api.artifacts.ModuleIdentifier)5 ComponentArtifactIdentifier (org.gradle.api.artifacts.component.ComponentArtifactIdentifier)5 ModuleComponentSelector (org.gradle.api.artifacts.component.ModuleComponentSelector)5 ImmutableList (com.google.common.collect.ImmutableList)4 DefaultImmutableVersionConstraint (org.gradle.api.internal.artifacts.dependencies.DefaultImmutableVersionConstraint)4 ComponentArtifactMetadata (org.gradle.internal.component.model.ComponentArtifactMetadata)4 ImmutableSet (com.google.common.collect.ImmutableSet)3 List (java.util.List)3 Map (java.util.Map)3 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)3 ModuleVersionSelector (org.gradle.api.artifacts.ModuleVersionSelector)3 DefaultResolvedArtifact (org.gradle.api.internal.artifacts.DefaultResolvedArtifact)3 ImmutableAttributes (org.gradle.api.internal.attributes.ImmutableAttributes)3 MavenScope (org.gradle.internal.component.external.descriptor.MavenScope)3