xref: /aosp_15_r20/external/google-cloud-java/java-vision/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 Gilbride
18*55e87721SMatt Gilbride
19*55e87721SMatt Gilbride# restore deprecated resource name helpers
20*55e87721SMatt Gilbride# TODO: remove in version 2.0.0
21*55e87721SMatt GilbrideDEPRECATED_RESOURCE_NAME_HELPERS = """
22*55e87721SMatt Gilbride
23*55e87721SMatt Gilbrideprivate static final PathTemplate LOCATION_PATH_TEMPLATE =
24*55e87721SMatt Gilbride    PathTemplate.createWithoutUrlEncoding("projects/{project}/locations/{location}");
25*55e87721SMatt Gilbride
26*55e87721SMatt Gilbrideprivate static final PathTemplate PRODUCT_PATH_TEMPLATE =
27*55e87721SMatt Gilbride    PathTemplate.createWithoutUrlEncoding(
28*55e87721SMatt Gilbride        "projects/{project}/locations/{location}/products/{product}");
29*55e87721SMatt Gilbride
30*55e87721SMatt Gilbrideprivate static final PathTemplate PRODUCT_SET_PATH_TEMPLATE =
31*55e87721SMatt Gilbride    PathTemplate.createWithoutUrlEncoding(
32*55e87721SMatt Gilbride        "projects/{project}/locations/{location}/productSets/{product_set}");
33*55e87721SMatt Gilbride
34*55e87721SMatt Gilbrideprivate static final PathTemplate REFERENCE_IMAGE_PATH_TEMPLATE =
35*55e87721SMatt Gilbride    PathTemplate.createWithoutUrlEncoding(
36*55e87721SMatt Gilbride        "projects/{project}/locations/{location}/products/{product}/referenceImages/{reference_image}");
37*55e87721SMatt Gilbride
38*55e87721SMatt Gilbride/**
39*55e87721SMatt Gilbride  * Formats a string containing the fully-qualified path to represent a location resource.
40*55e87721SMatt Gilbride  *
41*55e87721SMatt Gilbride  * @deprecated Use the {@link LocationName} class instead.
42*55e87721SMatt Gilbride  */
43*55e87721SMatt Gilbride@Deprecated
44*55e87721SMatt Gilbridepublic static final String formatLocationName(String project, String location) {
45*55e87721SMatt Gilbride  return LOCATION_PATH_TEMPLATE.instantiate(
46*55e87721SMatt Gilbride      "project", project,
47*55e87721SMatt Gilbride      "location", location);
48*55e87721SMatt Gilbride}
49*55e87721SMatt Gilbride
50*55e87721SMatt Gilbride/**
51*55e87721SMatt Gilbride  * Formats a string containing the fully-qualified path to represent a product resource.
52*55e87721SMatt Gilbride  *
53*55e87721SMatt Gilbride  * @deprecated Use the {@link ProductName} class instead.
54*55e87721SMatt Gilbride  */
55*55e87721SMatt Gilbride@Deprecated
56*55e87721SMatt Gilbridepublic static final String formatProductName(String project, String location, String product) {
57*55e87721SMatt Gilbride  return PRODUCT_PATH_TEMPLATE.instantiate(
58*55e87721SMatt Gilbride      "project", project,
59*55e87721SMatt Gilbride      "location", location,
60*55e87721SMatt Gilbride      "product", product);
61*55e87721SMatt Gilbride}
62*55e87721SMatt Gilbride
63*55e87721SMatt Gilbride/**
64*55e87721SMatt Gilbride  * Formats a string containing the fully-qualified path to represent a product_set resource.
65*55e87721SMatt Gilbride  *
66*55e87721SMatt Gilbride  * @deprecated Use the {@link ProductSetName} class instead.
67*55e87721SMatt Gilbride  */
68*55e87721SMatt Gilbride@Deprecated
69*55e87721SMatt Gilbridepublic static final String formatProductSetName(
70*55e87721SMatt Gilbride    String project, String location, String productSet) {
71*55e87721SMatt Gilbride  return PRODUCT_SET_PATH_TEMPLATE.instantiate(
72*55e87721SMatt Gilbride      "project", project,
73*55e87721SMatt Gilbride      "location", location,
74*55e87721SMatt Gilbride      "product_set", productSet);
75*55e87721SMatt Gilbride}
76*55e87721SMatt Gilbride
77*55e87721SMatt Gilbride/**
78*55e87721SMatt Gilbride  * Formats a string containing the fully-qualified path to represent a reference_image resource.
79*55e87721SMatt Gilbride  *
80*55e87721SMatt Gilbride  * @deprecated Use the {@link ReferenceImageName} class instead.
81*55e87721SMatt Gilbride  */
82*55e87721SMatt Gilbride@Deprecated
83*55e87721SMatt Gilbridepublic static final String formatReferenceImageName(
84*55e87721SMatt Gilbride    String project, String location, String product, String referenceImage) {
85*55e87721SMatt Gilbride  return REFERENCE_IMAGE_PATH_TEMPLATE.instantiate(
86*55e87721SMatt Gilbride      "project", project,
87*55e87721SMatt Gilbride      "location", location,
88*55e87721SMatt Gilbride      "product", product,
89*55e87721SMatt Gilbride      "reference_image", referenceImage);
90*55e87721SMatt Gilbride}
91*55e87721SMatt Gilbride
92*55e87721SMatt Gilbride/**
93*55e87721SMatt Gilbride  * Parses the project from the given fully-qualified path which represents a location resource.
94*55e87721SMatt Gilbride  *
95*55e87721SMatt Gilbride  * @deprecated Use the {@link LocationName} class instead.
96*55e87721SMatt Gilbride  */
97*55e87721SMatt Gilbride@Deprecated
98*55e87721SMatt Gilbridepublic static final String parseProjectFromLocationName(String locationName) {
99*55e87721SMatt Gilbride  return LOCATION_PATH_TEMPLATE.parse(locationName).get("project");
100*55e87721SMatt Gilbride}
101*55e87721SMatt Gilbride
102*55e87721SMatt Gilbride/**
103*55e87721SMatt Gilbride  * Parses the location from the given fully-qualified path which represents a location resource.
104*55e87721SMatt Gilbride  *
105*55e87721SMatt Gilbride  * @deprecated Use the {@link LocationName} class instead.
106*55e87721SMatt Gilbride  */
107*55e87721SMatt Gilbride@Deprecated
108*55e87721SMatt Gilbridepublic static final String parseLocationFromLocationName(String locationName) {
109*55e87721SMatt Gilbride  return LOCATION_PATH_TEMPLATE.parse(locationName).get("location");
110*55e87721SMatt Gilbride}
111*55e87721SMatt Gilbride
112*55e87721SMatt Gilbride/**
113*55e87721SMatt Gilbride  * Parses the project from the given fully-qualified path which represents a product resource.
114*55e87721SMatt Gilbride  *
115*55e87721SMatt Gilbride  * @deprecated Use the {@link ProductName} class instead.
116*55e87721SMatt Gilbride  */
117*55e87721SMatt Gilbride@Deprecated
118*55e87721SMatt Gilbridepublic static final String parseProjectFromProductName(String productName) {
119*55e87721SMatt Gilbride  return PRODUCT_PATH_TEMPLATE.parse(productName).get("project");
120*55e87721SMatt Gilbride}
121*55e87721SMatt Gilbride
122*55e87721SMatt Gilbride/**
123*55e87721SMatt Gilbride  * Parses the location from the given fully-qualified path which represents a product resource.
124*55e87721SMatt Gilbride  *
125*55e87721SMatt Gilbride  * @deprecated Use the {@link ProductName} class instead.
126*55e87721SMatt Gilbride  */
127*55e87721SMatt Gilbride@Deprecated
128*55e87721SMatt Gilbridepublic static final String parseLocationFromProductName(String productName) {
129*55e87721SMatt Gilbride  return PRODUCT_PATH_TEMPLATE.parse(productName).get("location");
130*55e87721SMatt Gilbride}
131*55e87721SMatt Gilbride
132*55e87721SMatt Gilbride/**
133*55e87721SMatt Gilbride  * Parses the product from the given fully-qualified path which represents a product resource.
134*55e87721SMatt Gilbride  *
135*55e87721SMatt Gilbride  * @deprecated Use the {@link ProductName} class instead.
136*55e87721SMatt Gilbride  */
137*55e87721SMatt Gilbride@Deprecated
138*55e87721SMatt Gilbridepublic static final String parseProductFromProductName(String productName) {
139*55e87721SMatt Gilbride  return PRODUCT_PATH_TEMPLATE.parse(productName).get("product");
140*55e87721SMatt Gilbride}
141*55e87721SMatt Gilbride
142*55e87721SMatt Gilbride/**
143*55e87721SMatt Gilbride  * Parses the project from the given fully-qualified path which represents a product_set resource.
144*55e87721SMatt Gilbride  *
145*55e87721SMatt Gilbride  * @deprecated Use the {@link ProductSetName} class instead.
146*55e87721SMatt Gilbride  */
147*55e87721SMatt Gilbride@Deprecated
148*55e87721SMatt Gilbridepublic static final String parseProjectFromProductSetName(String productSetName) {
149*55e87721SMatt Gilbride  return PRODUCT_SET_PATH_TEMPLATE.parse(productSetName).get("project");
150*55e87721SMatt Gilbride}
151*55e87721SMatt Gilbride
152*55e87721SMatt Gilbride/**
153*55e87721SMatt Gilbride  * Parses the location from the given fully-qualified path which represents a product_set
154*55e87721SMatt Gilbride  * resource.
155*55e87721SMatt Gilbride  *
156*55e87721SMatt Gilbride  * @deprecated Use the {@link ProductSetName} class instead.
157*55e87721SMatt Gilbride  */
158*55e87721SMatt Gilbride@Deprecated
159*55e87721SMatt Gilbridepublic static final String parseLocationFromProductSetName(String productSetName) {
160*55e87721SMatt Gilbride  return PRODUCT_SET_PATH_TEMPLATE.parse(productSetName).get("location");
161*55e87721SMatt Gilbride}
162*55e87721SMatt Gilbride
163*55e87721SMatt Gilbride/**
164*55e87721SMatt Gilbride  * Parses the product_set from the given fully-qualified path which represents a product_set
165*55e87721SMatt Gilbride  * resource.
166*55e87721SMatt Gilbride  *
167*55e87721SMatt Gilbride  * @deprecated Use the {@link ProductSetName} class instead.
168*55e87721SMatt Gilbride  */
169*55e87721SMatt Gilbride@Deprecated
170*55e87721SMatt Gilbridepublic static final String parseProductSetFromProductSetName(String productSetName) {
171*55e87721SMatt Gilbride  return PRODUCT_SET_PATH_TEMPLATE.parse(productSetName).get("product_set");
172*55e87721SMatt Gilbride}
173*55e87721SMatt Gilbride
174*55e87721SMatt Gilbride/**
175*55e87721SMatt Gilbride  * Parses the project from the given fully-qualified path which represents a reference_image
176*55e87721SMatt Gilbride  * resource.
177*55e87721SMatt Gilbride  *
178*55e87721SMatt Gilbride  * @deprecated Use the {@link ReferenceImageName} class instead.
179*55e87721SMatt Gilbride  */
180*55e87721SMatt Gilbride@Deprecated
181*55e87721SMatt Gilbridepublic static final String parseProjectFromReferenceImageName(String referenceImageName) {
182*55e87721SMatt Gilbride  return REFERENCE_IMAGE_PATH_TEMPLATE.parse(referenceImageName).get("project");
183*55e87721SMatt Gilbride}
184*55e87721SMatt Gilbride
185*55e87721SMatt Gilbride/**
186*55e87721SMatt Gilbride  * Parses the location from the given fully-qualified path which represents a reference_image
187*55e87721SMatt Gilbride  * resource.
188*55e87721SMatt Gilbride  *
189*55e87721SMatt Gilbride  * @deprecated Use the {@link ReferenceImageName} class instead.
190*55e87721SMatt Gilbride  */
191*55e87721SMatt Gilbride@Deprecated
192*55e87721SMatt Gilbridepublic static final String parseLocationFromReferenceImageName(String referenceImageName) {
193*55e87721SMatt Gilbride  return REFERENCE_IMAGE_PATH_TEMPLATE.parse(referenceImageName).get("location");
194*55e87721SMatt Gilbride}
195*55e87721SMatt Gilbride
196*55e87721SMatt Gilbride/**
197*55e87721SMatt Gilbride  * Parses the product from the given fully-qualified path which represents a reference_image
198*55e87721SMatt Gilbride  * resource.
199*55e87721SMatt Gilbride  *
200*55e87721SMatt Gilbride  * @deprecated Use the {@link ReferenceImageName} class instead.
201*55e87721SMatt Gilbride  */
202*55e87721SMatt Gilbride@Deprecated
203*55e87721SMatt Gilbridepublic static final String parseProductFromReferenceImageName(String referenceImageName) {
204*55e87721SMatt Gilbride  return REFERENCE_IMAGE_PATH_TEMPLATE.parse(referenceImageName).get("product");
205*55e87721SMatt Gilbride}
206*55e87721SMatt Gilbride
207*55e87721SMatt Gilbride/**
208*55e87721SMatt Gilbride  * Parses the reference_image from the given fully-qualified path which represents a
209*55e87721SMatt Gilbride  * reference_image resource.
210*55e87721SMatt Gilbride  *
211*55e87721SMatt Gilbride  * @deprecated Use the {@link ReferenceImageName} class instead.
212*55e87721SMatt Gilbride  */
213*55e87721SMatt Gilbride@Deprecated
214*55e87721SMatt Gilbridepublic static final String parseReferenceImageFromReferenceImageName(String referenceImageName) {
215*55e87721SMatt Gilbride  return REFERENCE_IMAGE_PATH_TEMPLATE.parse(referenceImageName).get("reference_image");
216*55e87721SMatt Gilbride}
217*55e87721SMatt Gilbride"""
218*55e87721SMatt Gilbride
219*55e87721SMatt Gilbridefor library in s.get_staging_dirs():
220*55e87721SMatt Gilbride    # put any special-case replacements here
221*55e87721SMatt Gilbride    s.replace(
222*55e87721SMatt Gilbride        "owl-bot-staging/v1/google-cloud-vision/src/main/java/com/google/cloud/vision/v1/ProductSearchClient.java",
223*55e87721SMatt Gilbride        "private final OperationsClient operationsClient;",
224*55e87721SMatt Gilbride        f"private final OperationsClient operationsClient;\n{DEPRECATED_RESOURCE_NAME_HELPERS}"
225*55e87721SMatt Gilbride    )
226*55e87721SMatt Gilbride    s.replace(
227*55e87721SMatt Gilbride        "owl-bot-staging/v1/google-cloud-vision/src/main/java/com/google/cloud/vision/v1/ProductSearchClient.java",
228*55e87721SMatt Gilbride        "import com.google.api.gax.rpc.UnaryCallable;",
229*55e87721SMatt Gilbride        "import com.google.api.gax.rpc.UnaryCallable;\nimport com.google.api.pathtemplate.PathTemplate;"
230*55e87721SMatt Gilbride    )
231*55e87721SMatt Gilbride    s.move(library)
232*55e87721SMatt Gilbride
233*55e87721SMatt Gilbrides.remove_staging_dirs()
234*55e87721SMatt Gilbridejava.common_templates(monorepo=True, excludes=[
235*55e87721SMatt Gilbride    ".github/*",
236*55e87721SMatt Gilbride    ".kokoro/*",
237*55e87721SMatt Gilbride    "samples/*",
238*55e87721SMatt Gilbride    "CODE_OF_CONDUCT.md",
239*55e87721SMatt Gilbride    "CONTRIBUTING.md",
240*55e87721SMatt Gilbride    "LICENSE",
241*55e87721SMatt Gilbride    "SECURITY.md",
242*55e87721SMatt Gilbride    "java.header",
243*55e87721SMatt Gilbride    "license-checks.xml",
244*55e87721SMatt Gilbride    "renovate.json",
245*55e87721SMatt Gilbride    ".gitignore"
246*55e87721SMatt Gilbride])
247