Example usage for com.google.gson.stream JsonReader endObject

List of usage examples for com.google.gson.stream JsonReader endObject

Introduction

In this page you can find the example usage for com.google.gson.stream JsonReader endObject.

Prototype

public void endObject() throws IOException 

Source Link

Document

Consumes the next token from the JSON stream and asserts that it is the end of the current object.

Usage

From source file:org.gradle.api.internal.artifacts.ivyservice.ivyresolve.parser.ModuleMetadataParser.java

License:Apache License

private void consumeVariant(JsonReader reader, MutableModuleComponentResolveMetadata metadata)
        throws IOException {
    reader.beginObject();//from w  w w . j a  va 2 s.  co  m
    String variantName = null;
    ImmutableAttributes attributes = ImmutableAttributes.EMPTY;
    List<ModuleFile> files = Collections.emptyList();
    List<ModuleDependency> dependencies = Collections.emptyList();
    List<ModuleDependencyConstraint> dependencyConstraints = Collections.emptyList();
    List<VariantCapability> capabilities = Collections.emptyList();
    while (reader.peek() != END_OBJECT) {
        String name = reader.nextName();
        if (name.equals("name")) {
            variantName = reader.nextString();
        } else if (name.equals("attributes")) {
            attributes = consumeAttributes(reader);
        } else if (name.equals("files")) {
            files = consumeFiles(reader);
        } else if (name.equals("dependencies")) {
            dependencies = consumeDependencies(reader);
        } else if (name.equals("dependencyConstraints")) {
            dependencyConstraints = consumeDependencyConstraints(reader);
        } else if (name.equals("capabilities")) {
            capabilities = consumeCapabilities(reader);
        } else if (name.equals("available-at")) {
            // For now just collect this as another dependency
            // TODO - collect this information and merge the metadata from the other module
            dependencies = consumeVariantLocation(reader);
        } else {
            consumeAny(reader);
        }
    }
    reader.endObject();

    MutableComponentVariant variant = metadata.addVariant(variantName, attributes);
    for (ModuleFile file : files) {
        variant.addFile(file.name, file.uri);
    }
    for (ModuleDependency dependency : dependencies) {
        variant.addDependency(dependency.group, dependency.module, dependency.versionConstraint,
                dependency.excludes, dependency.reason, dependency.attributes);
    }
    for (ModuleDependencyConstraint dependencyConstraint : dependencyConstraints) {
        variant.addDependencyConstraint(dependencyConstraint.group, dependencyConstraint.module,
                dependencyConstraint.versionConstraint, dependencyConstraint.reason,
                dependencyConstraint.attributes);
    }
    for (VariantCapability capability : capabilities) {
        variant.addCapability(capability.group, capability.name, capability.version);
    }
}

From source file:org.gradle.api.internal.artifacts.ivyservice.ivyresolve.parser.ModuleMetadataParser.java

License:Apache License

private List<ModuleDependency> consumeVariantLocation(JsonReader reader) throws IOException {
    String group = null;//w  w  w .  j av a  2 s.c o m
    String module = null;
    String version = null;
    reader.beginObject();
    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 = reader.nextString();
        } else {
            consumeAny(reader);
        }
    }
    reader.endObject();
    return ImmutableList.of(new ModuleDependency(group, module, new DefaultImmutableVersionConstraint(version),
            ImmutableList.<ExcludeMetadata>of(), null, ImmutableAttributes.EMPTY));
}

From source file:org.gradle.api.internal.artifacts.ivyservice.ivyresolve.parser.ModuleMetadataParser.java

License:Apache License

private List<ModuleDependency> consumeDependencies(JsonReader reader) throws IOException {
    List<ModuleDependency> dependencies = new ArrayList<ModuleDependency>();
    reader.beginArray();/*from w ww .  j  a v a 2  s  . co  m*/
    while (reader.peek() != END_ARRAY) {
        reader.beginObject();
        String group = null;
        String module = null;
        String reason = null;
        ImmutableAttributes attributes = ImmutableAttributes.EMPTY;
        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 if (name.equals("attributes")) {
                attributes = consumeAttributes(reader);
            } else {
                consumeAny(reader);
            }
        }
        dependencies.add(new ModuleDependency(group, module, version, excludes, reason, attributes));
        reader.endObject();
    }
    reader.endArray();
    return dependencies;
}

From source file:org.gradle.api.internal.artifacts.ivyservice.ivyresolve.parser.ModuleMetadataParser.java

License:Apache License

private List<VariantCapability> consumeCapabilities(JsonReader reader) throws IOException {
    ImmutableList.Builder<VariantCapability> capabilities = ImmutableList.builder();
    reader.beginArray();/*from  w  w  w  . j  ava 2  s . c o  m*/
    while (reader.peek() != END_ARRAY) {
        reader.beginObject();
        String group = null;
        String name = null;
        String version = null;
        while (reader.peek() != END_OBJECT) {
            String val = reader.nextName();
            if (val.equals("group")) {
                group = reader.nextString();
            } else if (val.equals("name")) {
                name = reader.nextString();
            } else if (val.equals("version")) {
                version = reader.nextString();
            }
        }
        capabilities.add(new VariantCapability(group, name, version));
        reader.endObject();
    }
    reader.endArray();
    return capabilities.build();
}

From source file:org.gradle.api.internal.artifacts.ivyservice.ivyresolve.parser.ModuleMetadataParser.java

License:Apache License

private List<ModuleDependencyConstraint> consumeDependencyConstraints(JsonReader reader) throws IOException {
    List<ModuleDependencyConstraint> dependencies = new ArrayList<ModuleDependencyConstraint>();
    reader.beginArray();// ww w .j  a v a  2s .c o m
    while (reader.peek() != END_ARRAY) {
        reader.beginObject();
        String group = null;
        String module = null;
        String reason = null;
        VersionConstraint version = null;
        ImmutableAttributes attributes = ImmutableAttributes.EMPTY;
        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 if (name.equals("attributes")) {
                attributes = consumeAttributes(reader);
            } else {
                consumeAny(reader);
            }
        }
        dependencies.add(new ModuleDependencyConstraint(group, module, version, reason, attributes));
        reader.endObject();
    }
    reader.endArray();
    return dependencies;
}

From source file:org.gradle.api.internal.artifacts.ivyservice.ivyresolve.parser.ModuleMetadataParser.java

License:Apache License

private ImmutableVersionConstraint consumeVersion(JsonReader reader) throws IOException {
    reader.beginObject();/*  w  w w.j a va2 s  . co  m*/
    String requiredVersion = "";
    String preferredVersion = "";
    String strictVersion = "";
    List<String> rejects = Lists.newArrayList();
    while (reader.peek() != END_OBJECT) {
        // At this stage, 'requires' implies 'prefers', 'strictly' implies 'requires'.
        String cst = reader.nextName();
        if ("prefers".equals(cst)) {
            preferredVersion = reader.nextString();
        } else if ("requires".equals(cst)) {
            requiredVersion = reader.nextString();
            preferredVersion = requiredVersion;
        } else if ("strictly".equals(cst)) {
            strictVersion = reader.nextString();
            requiredVersion = strictVersion;
            preferredVersion = strictVersion;
        } else if ("rejects".equals(cst)) {
            reader.beginArray();
            while (reader.peek() != END_ARRAY) {
                rejects.add(reader.nextString());
            }
            reader.endArray();
        }
    }
    reader.endObject();
    return DefaultImmutableVersionConstraint.of(preferredVersion, requiredVersion, strictVersion, rejects);
}

From source file:org.gradle.api.internal.artifacts.ivyservice.ivyresolve.parser.ModuleMetadataParser.java

License:Apache License

private ImmutableList<ExcludeMetadata> consumeExcludes(JsonReader reader) throws IOException {
    ImmutableList.Builder<ExcludeMetadata> builder = new ImmutableList.Builder<ExcludeMetadata>();
    reader.beginArray();/*from   ww  w  .ja v a2s.c  om*/
    while (reader.peek() != END_ARRAY) {
        reader.beginObject();
        String group = null;
        String module = 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 {
                consumeAny(reader);
            }
        }
        reader.endObject();
        ExcludeMetadata exclude = excludeRuleConverter.createExcludeRule(group, module);
        builder.add(exclude);
    }
    reader.endArray();
    return builder.build();
}

From source file:org.gradle.api.internal.artifacts.ivyservice.ivyresolve.parser.ModuleMetadataParser.java

License:Apache License

private List<ModuleFile> consumeFiles(JsonReader reader) throws IOException {
    List<ModuleFile> files = new ArrayList<ModuleFile>();
    reader.beginArray();//from  ww  w .j  ava  2 s . c  o  m
    while (reader.peek() != END_ARRAY) {
        reader.beginObject();
        String fileName = null;
        String fileUri = null;
        while (reader.peek() != END_OBJECT) {
            String name = reader.nextName();
            if (name.equals("name")) {
                fileName = reader.nextString();
            } else if (name.equals("url")) {
                fileUri = reader.nextString();
            } else {
                consumeAny(reader);
            }
        }
        reader.endObject();
        files.add(new ModuleFile(fileName, fileUri));
    }
    reader.endArray();
    return files;
}

From source file:org.gradle.api.internal.artifacts.ivyservice.ivyresolve.parser.ModuleMetadataParser.java

License:Apache License

private ImmutableAttributes consumeAttributes(JsonReader reader) throws IOException {
    ImmutableAttributes attributes = ImmutableAttributes.EMPTY;
    reader.beginObject();/*w ww  .  ja  va2s .  c o m*/
    while (reader.peek() != END_OBJECT) {
        String attrName = reader.nextName();
        if (reader.peek() == BOOLEAN) {
            boolean attrValue = reader.nextBoolean();
            attributes = attributesFactory.concat(attributes, Attribute.of(attrName, Boolean.class), attrValue);
        } else {
            String attrValue = reader.nextString();
            attributes = attributesFactory.concat(attributes, Attribute.of(attrName, String.class),
                    new CoercingStringValueSnapshot(attrValue, instantiator));
        }
    }
    reader.endObject();
    return attributes;
}

From source file:org.gradle.nativeplatform.toolchain.internal.msvcpp.version.CommandLineToolVersionLocator.java

License:Apache License

private VisualStudioInstallCandidate readInstall(JsonReader reader) throws IOException {
    String visualStudioInstallPath = null;
    String visualStudioVersion = null;

    reader.beginObject();/*from  w ww.j  a  v  a2s . c om*/
    while (reader.hasNext()) {
        String key = reader.nextName();
        if (key.equals(INSTALLATION_PATH_KEY)) {
            visualStudioInstallPath = reader.nextString();
        } else if (key.equals(INSTALLATION_VERSION_KEY)) {
            visualStudioVersion = reader.nextString();
        } else {
            reader.skipValue();
        }
    }
    reader.endObject();

    File visualStudioInstallDir = new File(visualStudioInstallPath);
    VisualCppInstallCandidate visualCppMetadata = findVisualCppMetadata(visualStudioInstallDir,
            visualStudioVersion);

    if (visualCppMetadata == null) {
        LOGGER.debug("Ignoring candidate Visual Studio version " + visualStudioVersion + " at "
                + visualStudioInstallPath + " because it does not appear to be a valid installation");
        return null;
    } else {
        return new VisualStudioMetadataBuilder().installDir(visualStudioInstallDir)
                .visualCppDir(visualCppMetadata.getVisualCppDir())
                .version(VersionNumber.parse(visualStudioVersion))
                .visualCppVersion(visualCppMetadata.getVersion()).build();
    }
}