xref: /aosp_15_r20/external/google-cloud-java/java-grafeas/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
17import glob
18
19# License header
20license = """/*
21 * Copyright 2019 The Grafeas Authors. All rights reserved.
22 *
23 * Licensed under the Apache License, Version 2.0 (the "License");
24 * you may not use this file except in compliance with the License.
25 * You may obtain a copy of the License at
26 *
27 *     https://www.apache.org/licenses/LICENSE-2.0
28 *
29 * Unless required by applicable law or agreed to in writing, software
30 * distributed under the License is distributed on an "AS IS" BASIS,
31 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
32 * See the License for the specific language governing permissions and
33 * limitations under the License.
34 */
35"""
36protobuf_header = "// Generated by the protocol buffer compiler.  DO NOT EDIT!"
37
38# put any special-case replacements here
39for file in glob.glob('owl-bot-staging/v1/src/**/*.java', recursive=True):
40    if " * Copyright 2021 Google LLC" not in open(file).read() \
41        and protobuf_header in open(file).read() \
42        and license not in open(file).read():
43        s.replace(
44            f'owl-bot-staging/v1/src/**/*.java',
45            protobuf_header,
46            f"{license}\n{protobuf_header}"
47        )
48
49# strip out Google-specific parts
50# Remove default scope
51s.replace(
52    f'owl-bot-staging/v1/src/main/java/io/grafeas/v1/GrafeasGrpc.java',
53    f"package io.grafeas.v1;",
54    f"{license}\npackage io.grafeas.v1;"
55)
56s.replace(
57    f'owl-bot-staging/v1/src/**/GrafeasStubSettings.java',
58    r'^(.*)ImmutableList\.<String>builder\(\).add\(".*"\)\.build\(\);',
59    '\g<1>ImmutableList.of();'
60)
61# Remove default service endpoint
62s.replace(
63    f'owl-bot-staging/v1/src/**/GrafeasStubSettings.java',
64    '    return "containeranalysis.googleapis.com:443";',
65    '    return null;'
66)
67# Remove default service endpoint javadoc
68s.replace(
69    f'owl-bot-staging/v1/src/**/GrafeasStubSettings.java',
70    '\s+\*.*default service address.*\n\s+\*.*',
71    ''
72)
73for library in s.get_staging_dirs():
74    # put any special-case replacements here
75    s.move(library)
76
77s.remove_staging_dirs()
78java.common_templates(monorepo=True, excludes=[
79    ".github/*",
80    ".kokoro/*",
81    "samples/*",
82    "CODE_OF_CONDUCT.md",
83    "CONTRIBUTING.md",
84    "LICENSE",
85    "SECURITY.md",
86    "java.header",
87    "license-checks.xml",
88    "renovate.json",
89    ".gitignore"
90])
91