xref: /aosp_15_r20/external/google-cloud-java/java-tasks/owlbot.py (revision 55e87721aa1bc457b326496a7ca40f3ea1a63287)
1# Copyright 2021 Google LLC
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     https://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15import synthtool as s
16from synthtool.languages import java
17
18
19GET_IAM_POLICY = """
20  public final Policy getIamPolicy(QueueName queueName) {
21    return getIamPolicy((ResourceName) queueName);
22  }
23"""
24GET_IAM_POLICY_PREVIOUS = r'(\s+public final Policy getIamPolicy\(GetIamPolicyRequest request\) {\n\s+return .*\n\s+})'
25
26SET_IAM_POLICY = """
27  public final Policy setIamPolicy(QueueName queue, Policy policy) {
28    return setIamPolicy((ResourceName) queue, policy);
29  }
30"""
31SET_IAM_POLICY_PREVIOUS = r'(\s+public final Policy setIamPolicy\(SetIamPolicyRequest request\) {\n\s+return .*\n\s+})'
32
33TEST_IAM_POLICY = """
34  public final TestIamPermissionsResponse testIamPermissions(
35      QueueName queue, List<String> permissions) {
36    return testIamPermissions((ResourceName) queue, permissions);
37  }
38"""
39TEST_IAM_POLICY_PREVIOUS = r'(\spublic final TestIamPermissionsResponse testIamPermissions\(TestIamPermissionsRequest request\) {\n\s+return .*\n\s+})'
40
41for library in s.get_staging_dirs():
42    # put any special-case replacements here
43    version = library.parts[len(library.parts) - 1]
44    service = 'tasks'
45    s.replace(
46        f'owl-bot-staging/{version}/google-cloud-{service}/src/main/java/com/google/cloud/tasks/{version}/CloudTasksClient.java',
47        GET_IAM_POLICY_PREVIOUS,
48        "\g<1>\n\n" + GET_IAM_POLICY
49    )
50    s.replace(
51        f'owl-bot-staging/{version}/google-cloud-{service}/src/main/java/com/google/cloud/tasks/{version}/CloudTasksClient.java',
52        SET_IAM_POLICY_PREVIOUS,
53        "\g<1>\n\n" + SET_IAM_POLICY
54    )
55    s.replace(
56        f'owl-bot-staging/{version}/google-cloud-{service}/src/main/java/com/google/cloud/tasks/{version}/CloudTasksClient.java',
57        TEST_IAM_POLICY_PREVIOUS,
58        "\g<1>\n\n" + TEST_IAM_POLICY
59    )
60    s.move(library)
61
62s.remove_staging_dirs()
63java.common_templates(monorepo=True, excludes=[
64    ".github/*",
65    ".kokoro/*",
66    "samples/*",
67    "CODE_OF_CONDUCT.md",
68    "CONTRIBUTING.md",
69    "LICENSE",
70    "SECURITY.md",
71    "java.header",
72    "license-checks.xml",
73    "renovate.json",
74    ".gitignore"
75])
76