Example #1
0
def _common_template_metadata() -> Dict[str, Any]:
    metadata = {}  # type: Dict[str, Any]
    repo_metadata = common._load_repo_metadata()
    if repo_metadata:
        metadata["repo"] = repo_metadata
        group_id, artifact_id = repo_metadata["distribution_name"].split(":")

        metadata["latest_version"] = latest_maven_version(
            group_id=group_id, artifact_id=artifact_id)

    metadata["latest_bom_version"] = latest_maven_version(
        group_id="com.google.cloud",
        artifact_id="libraries-bom",
    )

    metadata["samples"] = samples.all_samples(
        ["samples/**/src/main/java/**/*.java"])
    metadata["snippets"] = snippets.all_snippets(
        ["samples/**/src/main/java/**/*.java", "samples/**/pom.xml"])
    if repo_metadata and "min_java_version" in repo_metadata:
        metadata["min_java_version"] = repo_metadata["min_java_version"]
    else:
        metadata["min_java_version"] = DEFAULT_MIN_SUPPORTED_JAVA_VERSION

    return metadata
Example #2
0
def template_metadata() -> Dict[str, Any]:
    """Load node specific template metadata.

    Returns:
        Dictionary of metadata. Includes the entire parsed contents of the package.json file if
        present. Other expected fields:
        * quickstart (str): Contents of the quickstart snippet if available, otherwise, ""
        * samples (List[Dict[str, str]]): List of available samples. See synthtool.gcp.samples.all_samples()
    """
    metadata = {}
    try:
        metadata = read_metadata()
    except FileNotFoundError:
        pass

    all_samples = samples.all_samples(["samples/*.js"])

    # quickstart.js sample is special - only include it in the samples list if there is
    # a quickstart snippet present in the file
    quickstart_snippets = list(
        snippets.all_snippets_from_file("samples/quickstart.js").values()
    )
    metadata["quickstart"] = quickstart_snippets[0] if quickstart_snippets else ""
    metadata["samples"] = list(
        filter(
            lambda sample: sample["file"] != "samples/quickstart.js"
            or metadata["quickstart"],
            all_samples,
        )
    )
    return metadata
Example #3
0
def test_bad_metadata():
    with util.chdir(FIXTURES / "node_templates" / "bad_metadata"):
        all_samples = samples.all_samples(["samples/*.js"])

        # should have included additional meta-information provided.
        assert all_samples[0]["title"] == "Bad_metadata1"
        assert "usage" not in all_samples[0]
        assert all_samples[1]["title"] == "Metadata Example 1"
        assert all_samples[1]["usage"] == "node hello-world.js"
Example #4
0
def test_load_node_samples():
    with util.chdir(FIXTURES / "node_templates" / "standard"):
        all_samples = samples.all_samples(["samples/*.js"])

        # should have loaded samples.
        assert all_samples[3]["title"] == "Requester Pays"
        assert all_samples[3]["file"] == "samples/requesterPays.js"
        assert len(all_samples) == 4

        # should have included additional meta-information provided.
        assert all_samples[0]["title"] == "Metadata Example 1"
        assert all_samples[0]["usage"] == "node hello-world.js"
        assert all_samples[1]["title"] == "Metadata Example 2"
        assert all_samples[1]["usage"] == "node goodnight-moon.js"
Example #5
0
def common_templates(excludes: List[str] = [],
                     template_path: Optional[Path] = None,
                     **kwargs) -> None:
    """Generate common templates for a Java Library

    Fetches information about the repository from the .repo-metadata.json file,
    information about the latest artifact versions and copies the files into
    their expected location.

    Args:
        excludes (List[str], optional): List of template paths to ignore
        **kwargs: Additional options for CommonTemplates.java_library()
    """
    metadata = {}  # type: Dict[str, Any]
    repo_metadata = common._load_repo_metadata()
    if repo_metadata:
        metadata["repo"] = repo_metadata
        group_id, artifact_id = repo_metadata["distribution_name"].split(":")

        metadata["latest_version"] = latest_maven_version(
            group_id=group_id, artifact_id=artifact_id)

    metadata["latest_bom_version"] = latest_maven_version(
        group_id="com.google.cloud",
        artifact_id="libraries-bom",
    )

    metadata["samples"] = samples.all_samples(
        ["samples/**/src/main/java/**/*.java"])
    metadata["snippets"] = snippets.all_snippets(
        ["samples/**/src/main/java/**/*.java", "samples/**/pom.xml"])
    if repo_metadata and "min_java_version" in repo_metadata:
        metadata["min_java_version"] = repo_metadata["min_java_version"]
    else:
        metadata["min_java_version"] = DEFAULT_MIN_SUPPORTED_JAVA_VERSION

    kwargs["metadata"] = metadata
    templates = gcp.CommonTemplates(template_path=template_path).java_library(
        **kwargs)
    s.copy([templates], excludes=excludes, merge=_merge_common_templates)