Search in sources :

Example 6 with VersionConstraint

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

the class ModuleMetadataParser method consumeDependencies.

private List<ModuleDependency> consumeDependencies(JsonReader reader) throws IOException {
    List<ModuleDependency> dependencies = new ArrayList<ModuleDependency>();
    reader.beginArray();
    while (reader.peek() != END_ARRAY) {
        reader.beginObject();
        String group = null;
        String module = null;
        String reason = null;
        VersionConstraint version = DefaultImmutableVersionConstraint.of();
        ImmutableList<ExcludeMetadata> excludes = ImmutableList.of();
        while (reader.peek() != END_OBJECT) {
            String name = reader.nextName();
            if (name.equals("group")) {
                group = reader.nextString();
            } else if (name.equals("module")) {
                module = reader.nextString();
            } else if (name.equals("version")) {
                version = consumeVersion(reader);
            } else if (name.equals("excludes")) {
                excludes = consumeExcludes(reader);
            } else if (name.equals("reason")) {
                reason = reader.nextString();
            } else {
                consumeAny(reader);
            }
        }
        dependencies.add(new ModuleDependency(group, module, version, excludes, reason));
        reader.endObject();
    }
    reader.endArray();
    return dependencies;
}
Also used : ImmutableVersionConstraint(org.gradle.api.internal.artifacts.ImmutableVersionConstraint) VersionConstraint(org.gradle.api.artifacts.VersionConstraint) DefaultImmutableVersionConstraint(org.gradle.api.internal.artifacts.dependencies.DefaultImmutableVersionConstraint) ArrayList(java.util.ArrayList) ExcludeMetadata(org.gradle.internal.component.model.ExcludeMetadata)

Example 7 with VersionConstraint

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

the class ModuleMetadataParser method consumeDependencyConstraints.

private List<ModuleDependencyConstraint> consumeDependencyConstraints(JsonReader reader) throws IOException {
    List<ModuleDependencyConstraint> dependencies = new ArrayList<ModuleDependencyConstraint>();
    reader.beginArray();
    while (reader.peek() != END_ARRAY) {
        reader.beginObject();
        String group = null;
        String module = null;
        String reason = null;
        VersionConstraint version = null;
        while (reader.peek() != END_OBJECT) {
            String name = reader.nextName();
            if (name.equals("group")) {
                group = reader.nextString();
            } else if (name.equals("module")) {
                module = reader.nextString();
            } else if (name.equals("version")) {
                version = consumeVersion(reader);
            } else if (name.equals("reason")) {
                reason = reader.nextString();
            } else {
                consumeAny(reader);
            }
        }
        dependencies.add(new ModuleDependencyConstraint(group, module, version, reason));
        reader.endObject();
    }
    reader.endArray();
    return dependencies;
}
Also used : ImmutableVersionConstraint(org.gradle.api.internal.artifacts.ImmutableVersionConstraint) VersionConstraint(org.gradle.api.artifacts.VersionConstraint) DefaultImmutableVersionConstraint(org.gradle.api.internal.artifacts.dependencies.DefaultImmutableVersionConstraint) ArrayList(java.util.ArrayList)

Example 8 with VersionConstraint

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

the class ModuleMetadataFileGenerator method writeDependency.

private void writeDependency(Dependency dependency, JsonWriter jsonWriter) throws IOException {
    jsonWriter.beginObject();
    if (dependency instanceof ProjectDependency) {
        ProjectDependency projectDependency = (ProjectDependency) dependency;
        ModuleVersionIdentifier identifier = projectDependencyResolver.resolve(ModuleVersionIdentifier.class, projectDependency);
        jsonWriter.name("group");
        jsonWriter.value(identifier.getGroup());
        jsonWriter.name("module");
        jsonWriter.value(identifier.getName());
        writeVersionConstraint(DefaultImmutableVersionConstraint.of(identifier.getVersion()), jsonWriter);
    } else {
        jsonWriter.name("group");
        jsonWriter.value(dependency.getGroup());
        jsonWriter.name("module");
        jsonWriter.value(dependency.getName());
        VersionConstraint vc;
        if (dependency instanceof ModuleVersionSelector) {
            vc = ((ExternalDependency) dependency).getVersionConstraint();
        } else {
            vc = DefaultImmutableVersionConstraint.of(Strings.nullToEmpty(dependency.getVersion()));
        }
        writeVersionConstraint(vc, jsonWriter);
    }
    if (dependency instanceof ModuleDependency) {
        writeExcludes((ModuleDependency) dependency, jsonWriter);
    }
    String reason = dependency.getReason();
    if (StringUtils.isNotEmpty(reason)) {
        jsonWriter.name("reason");
        jsonWriter.value(reason);
    }
    jsonWriter.endObject();
}
Also used : ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) VersionConstraint(org.gradle.api.artifacts.VersionConstraint) DefaultImmutableVersionConstraint(org.gradle.api.internal.artifacts.dependencies.DefaultImmutableVersionConstraint) ModuleVersionSelector(org.gradle.api.artifacts.ModuleVersionSelector) ModuleDependency(org.gradle.api.artifacts.ModuleDependency) ProjectDependency(org.gradle.api.artifacts.ProjectDependency)

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