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