Search in sources :

Example 16 with ModuleComponentIdentifier

use of org.gradle.api.artifacts.component.ModuleComponentIdentifier in project gradle by gradle.

the class DefaultVersionedComponentChooser method selectNewestMatchingComponent.

public void selectNewestMatchingComponent(Collection<? extends ModuleComponentResolveState> versions, ComponentSelectionContext result, VersionSelector requestedVersionMatcher, VersionSelector rejectedVersionSelector) {
    Collection<SpecRuleAction<? super ComponentSelection>> rules = componentSelectionRules.getRules();
    // Loop over all listed versions, sorted by LATEST first
    for (ModuleComponentResolveState candidate : sortLatestFirst(versions)) {
        MetadataProvider metadataProvider = createMetadataProvider(candidate);
        boolean versionMatches = versionMatches(requestedVersionMatcher, candidate, metadataProvider);
        if (metadataIsNotUsable(result, metadataProvider)) {
            return;
        }
        String version = candidate.getVersion().getSource();
        if (!versionMatches) {
            result.notMatched(version);
            continue;
        }
        if (rejectedVersionSelector != null && rejectedVersionSelector.accept(version)) {
            // Mark this version as rejected and continue
            result.rejected(version);
            continue;
        } else {
            ModuleComponentIdentifier candidateIdentifier = candidate.getId();
            if (!isRejectedByRules(candidateIdentifier, rules, metadataProvider)) {
                result.matches(candidateIdentifier);
                return;
            }
        }
        // Mark this version as rejected
        result.rejected(version);
        if (requestedVersionMatcher.matchesUniqueVersion()) {
            // Only consider one candidate, because matchesUniqueVersion means that there's no ambiguity on the version number
            break;
        }
    }
    // if we reach this point, no match was found, either because there are no versions matching the selector
    // or all of them were rejected
    result.noMatchFound();
}
Also used : SpecRuleAction(org.gradle.internal.rules.SpecRuleAction) ModuleComponentIdentifier(org.gradle.api.artifacts.component.ModuleComponentIdentifier) ComponentSelection(org.gradle.api.artifacts.ComponentSelection) DefaultComponentSelection(org.gradle.api.internal.artifacts.DefaultComponentSelection)

Example 17 with ModuleComponentIdentifier

use of org.gradle.api.artifacts.component.ModuleComponentIdentifier in project gradle by gradle.

the class RepositoryChainComponentMetaDataResolver method isFetchingMetadataCheap.

@Override
public boolean isFetchingMetadataCheap(ComponentIdentifier identifier) {
    if (identifier instanceof ModuleComponentIdentifier) {
        for (ModuleComponentRepository repository : repositories) {
            ModuleComponentRepositoryAccess localAccess = repository.getLocalAccess();
            MetadataFetchingCost fetchingCost = localAccess.estimateMetadataFetchingCost((ModuleComponentIdentifier) identifier);
            if (fetchingCost.isFast()) {
                return true;
            } else if (fetchingCost.isExpensive()) {
                return false;
            }
        }
    }
    return true;
}
Also used : MetadataFetchingCost(org.gradle.api.internal.artifacts.repositories.resolver.MetadataFetchingCost) ModuleComponentIdentifier(org.gradle.api.artifacts.component.ModuleComponentIdentifier)

Example 18 with ModuleComponentIdentifier

use of org.gradle.api.artifacts.component.ModuleComponentIdentifier in project gradle by gradle.

the class RepositoryChainDependencyToComponentIdResolver method resolve.

public void resolve(DependencyMetadata dependency, ResolvedVersionConstraint resolvedVersionConstraint, BuildableComponentIdResolveResult result) {
    ComponentSelector componentSelector = dependency.getSelector();
    if (componentSelector instanceof ModuleComponentSelector) {
        ModuleComponentSelector module = (ModuleComponentSelector) componentSelector;
        if (resolvedVersionConstraint == null) {
            // TODO:DAZ This shouldn't be required, but `ExternalResourceResolverDescriptorParseContext` does not provide a resolved constraint
            VersionConstraint raw = module.getVersionConstraint();
            resolvedVersionConstraint = new DefaultResolvedVersionConstraint(raw, versionSelectorScheme);
        }
        VersionSelector preferredSelector = resolvedVersionConstraint.getPreferredSelector();
        if (preferredSelector.isDynamic()) {
            dynamicRevisionResolver.resolve(toModuleDependencyMetadata(dependency), preferredSelector, resolvedVersionConstraint.getRejectedSelector(), result);
        } else {
            String version = resolvedVersionConstraint.getPreferredVersion();
            ModuleComponentIdentifier id = new DefaultModuleComponentIdentifier(module.getGroup(), module.getModule(), version);
            ModuleVersionIdentifier mvId = moduleIdentifierFactory.moduleWithVersion(module.getGroup(), module.getModule(), version);
            result.resolved(id, mvId);
        }
    }
}
Also used : ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) DefaultResolvedVersionConstraint(org.gradle.api.internal.artifacts.dependencies.DefaultResolvedVersionConstraint) VersionConstraint(org.gradle.api.artifacts.VersionConstraint) ResolvedVersionConstraint(org.gradle.api.internal.artifacts.ResolvedVersionConstraint) ComponentSelector(org.gradle.api.artifacts.component.ComponentSelector) ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) DefaultResolvedVersionConstraint(org.gradle.api.internal.artifacts.dependencies.DefaultResolvedVersionConstraint) ModuleComponentIdentifier(org.gradle.api.artifacts.component.ModuleComponentIdentifier) DefaultModuleComponentIdentifier(org.gradle.internal.component.external.model.DefaultModuleComponentIdentifier) DefaultModuleComponentIdentifier(org.gradle.internal.component.external.model.DefaultModuleComponentIdentifier) VersionSelector(org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.VersionSelector)

Example 19 with ModuleComponentIdentifier

use of org.gradle.api.artifacts.component.ModuleComponentIdentifier in project gradle by gradle.

the class GradlePomModuleDescriptorParser method doParseDescriptor.

protected MutableMavenModuleResolveMetadata doParseDescriptor(DescriptorParseContext parserSettings, LocallyAvailableExternalResource resource, boolean validate) throws IOException, ParseException, SAXException {
    PomReader pomReader = new PomReader(resource, moduleIdentifierFactory);
    GradlePomModuleDescriptorBuilder mdBuilder = new GradlePomModuleDescriptorBuilder(pomReader, gradleVersionSelectorScheme, mavenVersionSelectorScheme);
    doParsePom(parserSettings, mdBuilder, pomReader);
    List<MavenDependencyDescriptor> dependencies = mdBuilder.getDependencies();
    ModuleComponentIdentifier cid = mdBuilder.getComponentIdentifier();
    MutableMavenModuleResolveMetadata metadata = metadataFactory.create(cid, dependencies);
    metadata.setStatus(mdBuilder.getStatus());
    if (pomReader.getRelocation() != null) {
        metadata.setPackaging("pom");
        metadata.setRelocated(true);
    } else {
        metadata.setPackaging(pomReader.getPackaging());
        metadata.setRelocated(false);
    }
    return metadata;
}
Also used : MutableMavenModuleResolveMetadata(org.gradle.internal.component.external.model.MutableMavenModuleResolveMetadata) MavenDependencyDescriptor(org.gradle.internal.component.external.model.MavenDependencyDescriptor) DefaultModuleComponentIdentifier(org.gradle.internal.component.external.model.DefaultModuleComponentIdentifier) ModuleComponentIdentifier(org.gradle.api.artifacts.component.ModuleComponentIdentifier)

Example 20 with ModuleComponentIdentifier

use of org.gradle.api.artifacts.component.ModuleComponentIdentifier in project gradle by gradle.

the class DefaultArtifactPublisher method toPublishMetaData.

private DefaultIvyModulePublishMetadata toPublishMetaData(Module module, Set<? extends ConfigurationInternal> configurations, boolean validateArtifacts) {
    ModuleComponentIdentifier id = DefaultModuleComponentIdentifier.newId(module.getGroup(), module.getName(), module.getVersion());
    DefaultIvyModulePublishMetadata publishMetaData = new DefaultIvyModulePublishMetadata(id, module.getStatus());
    addConfigurations(publishMetaData, configurations, validateArtifacts);
    return publishMetaData;
}
Also used : ModuleComponentIdentifier(org.gradle.api.artifacts.component.ModuleComponentIdentifier) DefaultModuleComponentIdentifier(org.gradle.internal.component.external.model.DefaultModuleComponentIdentifier)

Aggregations

ModuleComponentIdentifier (org.gradle.api.artifacts.component.ModuleComponentIdentifier)20 DefaultModuleComponentIdentifier (org.gradle.internal.component.external.model.DefaultModuleComponentIdentifier)9 NamespaceId (org.gradle.api.internal.artifacts.ivyservice.NamespaceId)3 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)2 ComponentSelection (org.gradle.api.artifacts.ComponentSelection)2 ComponentSelector (org.gradle.api.artifacts.component.ComponentSelector)2 ModuleComponentSelector (org.gradle.api.artifacts.component.ModuleComponentSelector)2 DefaultComponentSelection (org.gradle.api.internal.artifacts.DefaultComponentSelection)2 VersionSelector (org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.VersionSelector)2 MutableMavenModuleResolveMetadata (org.gradle.internal.component.external.model.MutableMavenModuleResolveMetadata)2 DefaultIvyArtifactName (org.gradle.internal.component.model.DefaultIvyArtifactName)2 IvyArtifactName (org.gradle.internal.component.model.IvyArtifactName)2 SpecRuleAction (org.gradle.internal.rules.SpecRuleAction)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 ExcludeRule (org.apache.ivy.core.module.descriptor.ExcludeRule)1 ArtifactView (org.gradle.api.artifacts.ArtifactView)1 ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)1 ModuleVersionSelector (org.gradle.api.artifacts.ModuleVersionSelector)1