示例#1
0
def load_versions(filename: str, default_group_id: str) -> Mapping[str, module.Module]:
    if not os.path.isfile(filename):
        return {}
    modules = {}
    with open(filename, "r") as fp:
        for line in fp:
            line = line.strip()
            if line.startswith("#"):
                continue

            parts = line.split(":")
            if len(parts) == 3:
                artifact_id = parts[0]
                group_id = (
                    default_group_id
                    if artifact_id.startswith("google-")
                    else "com.google.api.grpc"
                )
                modules[artifact_id] = module.Module(
                    group_id=group_id,
                    artifact_id=artifact_id,
                    release_version=parts[1],
                    version=parts[2],
                )

    return modules
示例#2
0
def main():
    with open(".repo-metadata.json", "r") as fp:
        repo_metadata = json.load(fp)

    group_id, artifact_id = repo_metadata["distribution_name"].split(":")
    name = repo_metadata["name_pretty"]

    existing_modules = load_versions("versions.txt", group_id)

    if artifact_id not in existing_modules:
        existing_modules[artifact_id] = module.Module(
            group_id=group_id,
            artifact_id=artifact_id,
            version="0.0.1-SNAPSHOT",
            release_version="0.0.0",
        )
    main_module = existing_modules[artifact_id]

    parent_artifact_id = f"{artifact_id}-parent"
    if parent_artifact_id not in existing_modules:
        existing_modules[parent_artifact_id] = module.Module(
            group_id=group_id,
            artifact_id=parent_artifact_id,
            version=main_module.version,
            release_version=main_module.release_version,
        )
    parent_module = existing_modules[parent_artifact_id]

    for path in glob.glob("proto-google-*"):
        if not path in existing_modules:
            existing_modules[path] = module.Module(
                group_id="com.google.api.grpc",
                artifact_id=path,
                version=main_module.version,
                release_version=main_module.release_version,
            )

        if not os.path.isfile(f"{path}/pom.xml"):
            print(f"creating missing proto pom: {path}")
            templates.render(
                template_name="proto_pom.xml.j2",
                output_name=f"{path}/pom.xml",
                module=existing_modules[path],
                parent_module=parent_module,
                main_module=main_module,
            )

    for path in glob.glob("grpc-google-*"):
        if not path in existing_modules:
            existing_modules[path] = module.Module(
                group_id="com.google.api.grpc",
                artifact_id=path,
                version=main_module.version,
                release_version=main_module.release_version,
            )

        if not os.path.isfile(f"{path}/pom.xml"):
            proto_artifact_id = path.replace("grpc-", "proto-")
            print(f"creating missing grpc pom: {path}")
            templates.render(
                template_name="grpc_pom.xml.j2",
                output_name=f"{path}/pom.xml",
                module=existing_modules[path],
                parent_module=parent_module,
                main_module=main_module,
                proto_module=existing_modules[proto_artifact_id],
            )
    proto_modules = [
        module
        for module in existing_modules.values()
        if module.artifact_id.startswith("proto-")
    ]
    grpc_modules = [
        module
        for module in existing_modules.values()
        if module.artifact_id.startswith("grpc-")
    ]
    modules = [main_module] + grpc_modules + proto_modules

    if not _is_cloud_client(proto_modules, grpc_modules):
        print("no proto or grpc modules - probably not a cloud client")
        return

    if os.path.isfile(f"{artifact_id}/pom.xml"):
        print("updating modules in cloud pom.xml")
        update_cloud_pom(f"{artifact_id}/pom.xml", proto_modules, grpc_modules)
    else:
        print("creating missing cloud pom.xml")
        templates.render(
            template_name="cloud_pom.xml.j2",
            output_name=f"{artifact_id}/pom.xml",
            module=main_module,
            parent_module=parent_module,
            repo=repo_metadata["repo"],
            name=name,
            description=repo_metadata["api_description"],
            proto_modules=proto_modules,
            grpc_modules=grpc_modules,
        )

    if os.path.isfile(f"{artifact_id}-bom/pom.xml"):
        print("updating modules in bom pom.xml")
        update_bom_pom(f"{artifact_id}-bom/pom.xml", modules)
    else:
        print("creating missing bom pom.xml")
        templates.render(
            template_name="bom_pom.xml.j2",
            output_name=f"{artifact_id}-bom/pom.xml",
            repo=repo_metadata["repo"],
            name=name,
            modules=modules,
            main_module=main_module,
        )

    if os.path.isfile("pom.xml"):
        print("updating modules in parent pom.xml")
        update_parent_pom("pom.xml", modules)
    else:
        print("creating missing parent pom.xml")
        templates.render(
            template_name="parent_pom.xml.j2",
            output_name="./pom.xml",
            repo=repo_metadata["repo"],
            modules=modules,
            main_module=main_module,
            name=name,
        )

    if os.path.isfile("versions.txt"):
        print("updating modules in versions.txt")
    else:
        print("creating missing versions.txt")
    templates.render(
        template_name="versions.txt.j2", output_name="./versions.txt", modules=modules,
    )
示例#3
0
def main():
    with open(".repo-metadata.json", "r") as fp:
        repo_metadata = json.load(fp)

    group_id, artifact_id = repo_metadata["distribution_name"].split(":")
    name = repo_metadata["name_pretty"]
    existing_modules = load_versions("versions.txt", group_id)

    # extra modules that need to be manages in versions.txt
    if "extra_versioned_modules" in repo_metadata:
        extra_managed_modules = repo_metadata["extra_versioned_modules"].split(
            ",")
    else:
        extra_managed_modules = ""

    # list of modules to be excluded from added to poms
    if "excluded_dependencies" in repo_metadata:
        excluded_dependencies_list = repo_metadata[
            "excluded_dependencies"].split(",")
    else:
        excluded_dependencies_list = ""

    # list of poms that have to be excluded from post processing
    if "excluded_poms" in repo_metadata:
        excluded_poms_list = repo_metadata["excluded_poms"].split(",")
    else:
        excluded_poms_list = ""

    if artifact_id not in existing_modules:
        existing_modules[artifact_id] = module.Module(
            group_id=group_id,
            artifact_id=artifact_id,
            version="0.0.1-SNAPSHOT",
            release_version="0.0.0",
        )
    main_module = existing_modules[artifact_id]

    parent_artifact_id = f"{artifact_id}-parent"

    if parent_artifact_id not in existing_modules:
        existing_modules[parent_artifact_id] = module.Module(
            group_id=group_id,
            artifact_id=parent_artifact_id,
            version=main_module.version,
            release_version=main_module.release_version,
        )
    parent_module = existing_modules[parent_artifact_id]

    required_dependencies = {}
    for dependency_module in existing_modules:
        if dependency_module not in excluded_dependencies_list:
            required_dependencies[dependency_module] = existing_modules[
                dependency_module]

    for path in glob.glob("proto-google-*"):
        if not path in existing_modules:
            existing_modules[path] = module.Module(
                group_id="com.google.api.grpc",
                artifact_id=path,
                version=main_module.version,
                release_version=main_module.release_version,
            )
            if path not in excluded_dependencies_list \
                    and path not in main_module.artifact_id:
                required_dependencies[path] = module.Module(
                    group_id="com.google.api.grpc",
                    artifact_id=path,
                    version=main_module.version,
                    release_version=main_module.release_version,
                )
        if not os.path.isfile(f"{path}/pom.xml"):
            print(f"creating missing proto pom: {path}")
            templates.render(
                template_name="proto_pom.xml.j2",
                output_name=f"{path}/pom.xml",
                module=required_dependencies[path],
                parent_module=parent_module,
                main_module=main_module,
            )
            if path not in excluded_dependencies_list \
                and path not in main_module.artifact_id:
                required_dependencies[path] = module.Module(
                    group_id="com.google.api.grpc",
                    artifact_id=path,
                    version=main_module.version,
                    release_version=main_module.release_version,
                )

    for path in glob.glob("grpc-google-*"):
        if not path in existing_modules:
            existing_modules[path] = module.Module(
                group_id="com.google.api.grpc",
                artifact_id=path,
                version=main_module.version,
                release_version=main_module.release_version,
            )
            if path not in excluded_dependencies_list \
                and path not in main_module.artifact_id:
                required_dependencies[path] = module.Module(
                    group_id="com.google.api.grpc",
                    artifact_id=path,
                    version=main_module.version,
                    release_version=main_module.release_version,
                )

        if not os.path.isfile(f"{path}/pom.xml"):
            proto_artifact_id = path.replace("grpc-", "proto-")
            print(f"creating missing grpc pom: {path}")
            templates.render(
                template_name="grpc_pom.xml.j2",
                output_name=f"{path}/pom.xml",
                module=required_dependencies[path],
                parent_module=parent_module,
                main_module=main_module,
                proto_module=existing_modules[proto_artifact_id],
            )
            if path not in excluded_dependencies_list \
                and path not in main_module.artifact_id:
                required_dependencies[path] = module.Module(
                    group_id="com.google.api.grpc",
                    artifact_id=path,
                    version=main_module.version,
                    release_version=main_module.release_version,
                )
    proto_modules = [
        module for module in required_dependencies.values()
        if module.artifact_id.startswith("proto-")
        and module.artifact_id not in parent_artifact_id
    ]
    grpc_modules = [
        module
        for module in required_dependencies.values()
        if module.artifact_id.startswith("grpc-") \
           and module.artifact_id not in parent_artifact_id
    ]
    if main_module in grpc_modules or main_module in proto_modules:
        modules = grpc_modules + proto_modules
    else:
        modules = [main_module] + grpc_modules + proto_modules

    if not _is_cloud_client(existing_modules):
        print("no proto or grpc modules - probably not a cloud client")
        return

    if os.path.isfile(f"{artifact_id}/pom.xml"):
        print("updating modules in cloud pom.xml")
        if artifact_id not in excluded_poms_list:
            update_cloud_pom(f"{artifact_id}/pom.xml", proto_modules,
                             grpc_modules)
    elif artifact_id not in excluded_poms_list:
        print("creating missing cloud pom.xml")
        templates.render(
            template_name="cloud_pom.xml.j2",
            output_name=f"{artifact_id}/pom.xml",
            module=main_module,
            parent_module=parent_module,
            repo=repo_metadata["repo"],
            name=name,
            description=repo_metadata["api_description"],
            proto_modules=proto_modules,
            grpc_modules=grpc_modules,
        )

    if os.path.isfile(f"{artifact_id}-bom/pom.xml"):
        print("updating modules in bom pom.xml")
        if artifact_id + "-bom" not in excluded_poms_list:
            update_bom_pom(f"{artifact_id}-bom/pom.xml", modules)
    elif artifact_id + "-bom" not in excluded_poms_list:
        print("creating missing bom pom.xml")
        templates.render(
            template_name="bom_pom.xml.j2",
            output_name=f"{artifact_id}-bom/pom.xml",
            repo=repo_metadata["repo"],
            name=name,
            modules=modules,
            main_module=main_module,
        )

    if os.path.isfile("pom.xml"):
        print("updating modules in parent pom.xml")
        update_parent_pom("pom.xml", modules)
    else:
        print("creating missing parent pom.xml")
        templates.render(
            template_name="parent_pom.xml.j2",
            output_name="./pom.xml",
            repo=repo_metadata["repo"],
            modules=modules,
            main_module=main_module,
            name=name,
        )

    if os.path.isfile("versions.txt"):
        print("updating modules in versions.txt")
    else:
        print("creating missing versions.txt")
    existing_modules.pop(parent_artifact_id)

    # add extra modules to versions.txt
    for dependency_module in extra_managed_modules:
        if dependency_module not in existing_modules:
            existing_modules[dependency_module] = module.Module(
                group_id="com.google.api.grpc",
                artifact_id=dependency_module,
                version=main_module.version,
                release_version=main_module.release_version,
            )
    templates.render(
        template_name="versions.txt.j2",
        output_name="./versions.txt",
        modules=existing_modules.values(),
    )