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