@@ -463,16 +463,36 @@ private static Optional<List<String>> getInclusionMethodListFromServiceYaml(
463463 }
464464
465465 private static boolean shouldIncludeMethodInGeneration (
466- MethodDescriptor method , Optional <List <String >> optionalIncludeMethodsList ) {
466+ MethodDescriptor method ,
467+ Optional <com .google .api .Service > serviceYamlProtoOpt ,
468+ String protoPackage ) {
467469 // default to include all when no service yaml or no library setting section.
468- if (!optionalIncludeMethodsList .isPresent ()) {
470+ if (!serviceYamlProtoOpt .isPresent ()
471+ || serviceYamlProtoOpt .get ().getPublishing ().getLibrarySettingsCount () == 0 ) {
469472 return true ;
470473 }
471- // default to include all when nothing specified.
472- if (optionalIncludeMethodsList .get ().isEmpty ()) {
474+ List <ClientLibrarySettings > librarySettingsList =
475+ serviceYamlProtoOpt .get ().getPublishing ().getLibrarySettingsList ();
476+ // Validate for logging purpose, this should be validated upstream.
477+ // If library_settings.version does not match with proto package name
478+ // Give warnings and disregard this config. default to include all.
479+ if (!librarySettingsList .get (0 ).getVersion ().isEmpty ()
480+ && !protoPackage .equals (librarySettingsList .get (0 ).getVersion ())) {
481+ LOGGER .warning (
482+ "Service yaml config may be misconfigured. "
483+ + "Version in publishing.library_settings does not match proto package."
484+ + "Disregarding selective generation settings." );
473485 return true ;
474486 }
475- return optionalIncludeMethodsList .get ().contains (method .getFullName ());
487+ List <String > includeMethodsList =
488+ librarySettingsList
489+ .get (0 )
490+ .getJavaSettings ()
491+ .getCommon ()
492+ .getSelectiveGapicGeneration ()
493+ .getMethodsList ();
494+
495+ return includeMethodsList .contains (method .getFullName ());
476496 }
477497
478498 public static List <Service > parseService (
@@ -484,18 +504,16 @@ public static List<Service> parseService(
484504 Set <ResourceName > outputArgResourceNames ,
485505 Transport transport ) {
486506 String protoPackage = fileDescriptor .getPackage ();
487- Optional <List <String >> inclusionMethodListFromServiceYaml =
488- getInclusionMethodListFromServiceYaml (serviceYamlProtoOpt , protoPackage );
489507 return fileDescriptor .getServices ().stream ()
490508 .filter (
491509 serviceDescriptor -> {
492510 List <MethodDescriptor > methodsList = serviceDescriptor .getMethods ();
493511 List <MethodDescriptor > methodListSelected =
494512 methodsList .stream ()
495513 .filter (
496- method -> {
497- return shouldIncludeMethodInGeneration (method , inclusionMethodListFromServiceYaml );
498- } )
514+ method ->
515+ shouldIncludeMethodInGeneration (
516+ method , serviceYamlProtoOpt , protoPackage ) )
499517 .collect (Collectors .toList ());
500518 if (methodListSelected .isEmpty ()) {
501519 LOGGER .warning (
@@ -579,7 +597,7 @@ public static List<Service> parseService(
579597 .setMethods (
580598 parseMethods (
581599 s ,
582- inclusionMethodListFromServiceYaml ,
600+ protoPackage ,
583601 pakkage ,
584602 messageTypes ,
585603 resourceNames ,
@@ -771,7 +789,7 @@ public static Map<String, ResourceName> parseResourceNames(
771789 @ VisibleForTesting
772790 static List <Method > parseMethods (
773791 ServiceDescriptor serviceDescriptor ,
774- Optional < List < String >> inclusionMethodListFromServiceYaml ,
792+ String protoPackage ,
775793 String servicePackage ,
776794 Map <String , Message > messageTypes ,
777795 Map <String , ResourceName > resourceNames ,
@@ -785,7 +803,7 @@ static List<Method> parseMethods(
785803 Map <String , List <String >> autoPopulatedMethodsWithFields =
786804 parseAutoPopulatedMethodsAndFields (serviceYamlProtoOpt );
787805 for (MethodDescriptor protoMethod : serviceDescriptor .getMethods ()) {
788- if (!shouldIncludeMethodInGeneration (protoMethod , inclusionMethodListFromServiceYaml )) {
806+ if (!shouldIncludeMethodInGeneration (protoMethod , serviceYamlProtoOpt , protoPackage )) {
789807 continue ;
790808 }
791809 // Parse the method.
0 commit comments