Search in sources :

Example 1 with VersionConstraint

use of org.gradle.api.artifacts.VersionConstraint in project gradle by gradle.

the class DefaultIvyModulePublishMetadata method normalizeVersionForIvy.

/**
 * [1.0] is a valid version in maven, but not in Ivy: strip the surrounding '[' and ']' characters for ivy publish.
 */
private static LocalOriginDependencyMetadata normalizeVersionForIvy(LocalOriginDependencyMetadata dependency) {
    if (dependency.getSelector() instanceof ModuleComponentSelector) {
        ModuleComponentSelector selector = (ModuleComponentSelector) dependency.getSelector();
        VersionConstraint versionConstraint = selector.getVersionConstraint();
        DefaultImmutableVersionConstraint transformedConstraint = new DefaultImmutableVersionConstraint(VERSION_TRANSFORMER.transform(versionConstraint.getPreferredVersion()), CollectionUtils.collect(versionConstraint.getRejectedVersions(), VERSION_TRANSFORMER));
        ModuleComponentSelector newSelector = DefaultModuleComponentSelector.newSelector(selector.getGroup(), selector.getModule(), transformedConstraint);
        return dependency.withTarget(newSelector);
    }
    return dependency;
}
Also used : VersionConstraint(org.gradle.api.artifacts.VersionConstraint) DefaultImmutableVersionConstraint(org.gradle.api.internal.artifacts.dependencies.DefaultImmutableVersionConstraint) DefaultImmutableVersionConstraint(org.gradle.api.internal.artifacts.dependencies.DefaultImmutableVersionConstraint) ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) DefaultModuleComponentSelector(org.gradle.internal.component.external.model.DefaultModuleComponentSelector)

Example 2 with VersionConstraint

use of org.gradle.api.artifacts.VersionConstraint in project gradle by gradle.

the class ModuleComponentSelectorSerializer method read.

public ModuleComponentSelector read(Decoder decoder) throws IOException {
    String group = decoder.readString();
    String name = decoder.readString();
    VersionConstraint versionConstraint = readVersionConstraint(decoder);
    return newSelector(group, name, versionConstraint);
}
Also used : VersionConstraint(org.gradle.api.artifacts.VersionConstraint) DefaultImmutableVersionConstraint(org.gradle.api.internal.artifacts.dependencies.DefaultImmutableVersionConstraint)

Example 3 with VersionConstraint

use of org.gradle.api.artifacts.VersionConstraint in project gradle by gradle.

the class ModuleComponentSelectorSerializer method readVersionConstraint.

public VersionConstraint readVersionConstraint(Decoder decoder) throws IOException {
    String preferred = decoder.readString();
    int cpt = decoder.readSmallInt();
    List<String> rejects = Lists.newArrayListWithCapacity(cpt);
    for (int i = 0; i < cpt; i++) {
        rejects.add(decoder.readString());
    }
    return new DefaultImmutableVersionConstraint(preferred, rejects);
}
Also used : DefaultImmutableVersionConstraint(org.gradle.api.internal.artifacts.dependencies.DefaultImmutableVersionConstraint) VersionConstraint(org.gradle.api.artifacts.VersionConstraint) DefaultImmutableVersionConstraint(org.gradle.api.internal.artifacts.dependencies.DefaultImmutableVersionConstraint)

Example 4 with VersionConstraint

use of org.gradle.api.artifacts.VersionConstraint in project gradle by gradle.

the class ComponentSelectorSerializer method write.

public void write(Encoder encoder, ComponentSelector value) throws IOException {
    if (value == null) {
        throw new IllegalArgumentException("Provided component selector may not be null");
    }
    Implementation implementation = resolveImplementation(value);
    encoder.writeByte(implementation.getId());
    if (implementation == Implementation.MODULE) {
        ModuleComponentSelector moduleComponentSelector = (ModuleComponentSelector) value;
        encoder.writeString(moduleComponentSelector.getGroup());
        encoder.writeString(moduleComponentSelector.getModule());
        VersionConstraint versionConstraint = moduleComponentSelector.getVersionConstraint();
        writeVersionConstraint(encoder, versionConstraint);
    } else if (implementation == Implementation.BUILD) {
        ProjectComponentSelector projectComponentSelector = (ProjectComponentSelector) value;
        encoder.writeString(projectComponentSelector.getBuildName());
        encoder.writeString(projectComponentSelector.getProjectPath());
    } else if (implementation == Implementation.LIBRARY) {
        LibraryComponentSelector libraryComponentSelector = (LibraryComponentSelector) value;
        encoder.writeString(libraryComponentSelector.getProjectPath());
        encoder.writeNullableString(libraryComponentSelector.getLibraryName());
        encoder.writeNullableString(libraryComponentSelector.getVariant());
    } else {
        throw new IllegalStateException("Unsupported implementation type: " + implementation);
    }
}
Also used : ImmutableVersionConstraint(org.gradle.api.internal.artifacts.ImmutableVersionConstraint) VersionConstraint(org.gradle.api.artifacts.VersionConstraint) DefaultImmutableVersionConstraint(org.gradle.api.internal.artifacts.dependencies.DefaultImmutableVersionConstraint) DefaultModuleComponentSelector(org.gradle.internal.component.external.model.DefaultModuleComponentSelector) ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) ProjectComponentSelector(org.gradle.api.artifacts.component.ProjectComponentSelector) DefaultProjectComponentSelector(org.gradle.internal.component.local.model.DefaultProjectComponentSelector) LibraryComponentSelector(org.gradle.api.artifacts.component.LibraryComponentSelector) DefaultLibraryComponentSelector(org.gradle.internal.component.local.model.DefaultLibraryComponentSelector)

Example 5 with VersionConstraint

use of org.gradle.api.artifacts.VersionConstraint 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)

Aggregations

VersionConstraint (org.gradle.api.artifacts.VersionConstraint)8 DefaultImmutableVersionConstraint (org.gradle.api.internal.artifacts.dependencies.DefaultImmutableVersionConstraint)7 ModuleComponentSelector (org.gradle.api.artifacts.component.ModuleComponentSelector)3 ImmutableVersionConstraint (org.gradle.api.internal.artifacts.ImmutableVersionConstraint)3 ArrayList (java.util.ArrayList)2 ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)2 DefaultModuleComponentSelector (org.gradle.internal.component.external.model.DefaultModuleComponentSelector)2 ModuleDependency (org.gradle.api.artifacts.ModuleDependency)1 ModuleVersionSelector (org.gradle.api.artifacts.ModuleVersionSelector)1 ProjectDependency (org.gradle.api.artifacts.ProjectDependency)1 ComponentSelector (org.gradle.api.artifacts.component.ComponentSelector)1 LibraryComponentSelector (org.gradle.api.artifacts.component.LibraryComponentSelector)1 ModuleComponentIdentifier (org.gradle.api.artifacts.component.ModuleComponentIdentifier)1 ProjectComponentSelector (org.gradle.api.artifacts.component.ProjectComponentSelector)1 ResolvedVersionConstraint (org.gradle.api.internal.artifacts.ResolvedVersionConstraint)1 DefaultResolvedVersionConstraint (org.gradle.api.internal.artifacts.dependencies.DefaultResolvedVersionConstraint)1 VersionSelector (org.gradle.api.internal.artifacts.ivyservice.ivyresolve.strategy.VersionSelector)1 DefaultModuleComponentIdentifier (org.gradle.internal.component.external.model.DefaultModuleComponentIdentifier)1 DefaultLibraryComponentSelector (org.gradle.internal.component.local.model.DefaultLibraryComponentSelector)1 DefaultProjectComponentSelector (org.gradle.internal.component.local.model.DefaultProjectComponentSelector)1