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