File tree Expand file tree Collapse file tree 5 files changed +29
-7
lines changed 
gapic-generator-java/src/main/java/com/google/api/generator Expand file tree Collapse file tree 5 files changed +29
-7
lines changed Original file line number Diff line number Diff line change 1515package  com .google .api .generator ;
1616
1717import  com .google .api .generator .gapic .Generator ;
18+ import  com .google .api .generator .gapic .protoparser .NoServicesFoundException ;
1819import  com .google .protobuf .ExtensionRegistry ;
1920import  com .google .protobuf .compiler .PluginProtos .CodeGeneratorRequest ;
2021import  com .google .protobuf .compiler .PluginProtos .CodeGeneratorResponse ;
@@ -25,7 +26,12 @@ public static void main(String[] args) throws IOException {
2526    ExtensionRegistry  registry  = ExtensionRegistry .newInstance ();
2627    ProtoRegistry .registerAllExtensions (registry );
2728    CodeGeneratorRequest  request  = CodeGeneratorRequest .parseFrom (System .in , registry );
28-     CodeGeneratorResponse  response  = Generator .generateGapic (request );
29-     response .writeTo (System .out );
29+     try  {
30+       CodeGeneratorResponse  response  = Generator .generateGapic (request );
31+       response .writeTo (System .out );
32+     } catch  (NoServicesFoundException  ex ) {
33+       // If no services are found in the protos we will no-op 
34+       System .err .println ("No services found to generate" );
35+     }
3036  }
3137}
Original file line number Diff line number Diff line change 1414
1515package  com .google .api .generator .gapic ;
1616
17+ import  com .google .api .gax .rpc .StatusCode .Code ;
1718import  com .google .api .generator .gapic .composer .Composer ;
1819import  com .google .api .generator .gapic .model .GapicClass ;
1920import  com .google .api .generator .gapic .model .GapicContext ;
2021import  com .google .api .generator .gapic .model .GapicPackageInfo ;
2122import  com .google .api .generator .gapic .model .ReflectConfig ;
23+ import  com .google .api .generator .gapic .protoparser .NoServicesFoundException ;
2224import  com .google .api .generator .gapic .protoparser .Parser ;
2325import  com .google .api .generator .gapic .protowriter .Writer ;
2426import  com .google .protobuf .compiler .PluginProtos .CodeGeneratorRequest ;
2527import  com .google .protobuf .compiler .PluginProtos .CodeGeneratorResponse ;
2628import  java .util .List ;
2729
2830public  class  Generator  {
29-   public  static  CodeGeneratorResponse  generateGapic (CodeGeneratorRequest  request ) {
31+   public  static  CodeGeneratorResponse  generateGapic (CodeGeneratorRequest  request )
32+       throws  NoServicesFoundException  {
3033    GapicContext  context  = Parser .parse (request );
3134    List <GapicClass > clazzes  = Composer .composeServiceClasses (context );
3235    GapicPackageInfo  packageInfo  = Composer .composePackageInfo (context );
Original file line number Diff line number Diff line change 2929import  com .google .api .generator .gapic .model .GapicPackageInfo ;
3030import  com .google .api .generator .gapic .model .Sample ;
3131import  com .google .api .generator .gapic .model .Service ;
32- import  com .google .common . base . Preconditions ;
32+ import  com .google .api . generator . gapic . protoparser . NoServicesFoundException ;
3333import  com .google .common .base .Strings ;
3434import  javax .annotation .Generated ;
3535
@@ -44,7 +44,9 @@ public class ClientLibraryPackageInfoComposer {
4444  private  static  final  String  SERVICE_DESCRIPTION_HEADER_PATTERN  = "Service Description: %s" ;
4545
4646  public  static  GapicPackageInfo  generatePackageInfo (GapicContext  context ) {
47-     Preconditions .checkState (!context .services ().isEmpty (), "No services found to generate" );
47+     if  (context .services ().isEmpty ()) {
48+       throw  new  NoServicesFoundException ("No services found to generate" );
49+     }
4850    // Pick some service's package, as we assume they are all the same. 
4951    String  libraryPakkage  = context .services ().get (0 ).pakkage ();
5052
Original file line number Diff line number Diff line change 1+ package  com .google .api .generator .gapic .protoparser ;
2+ 
3+ public  class  NoServicesFoundException  extends  IllegalStateException  {
4+ 
5+   public  NoServicesFoundException () {}
6+   public  NoServicesFoundException (String  message ) {
7+     super (message );
8+   }
9+ }
Original file line number Diff line number Diff line change @@ -115,7 +115,7 @@ public GapicParserException(String errorMessage) {
115115    }
116116  }
117117
118-   public  static  GapicContext  parse (CodeGeneratorRequest  request ) {
118+   public  static  GapicContext  parse (CodeGeneratorRequest  request ) throws   NoServicesFoundException   {
119119    Optional <String > gapicYamlConfigPathOpt  =
120120        PluginArgumentParser .parseGapicYamlConfigPath (request );
121121    Optional <List <GapicBatchingSettings >> batchingSettingsOpt  =
@@ -175,7 +175,9 @@ public static GapicContext parse(CodeGeneratorRequest request) {
175175            mixinServices ,
176176            transport );
177177
178-     Preconditions .checkState (!services .isEmpty (), "No services found to generate" );
178+     if  (services .isEmpty ()) {
179+       throw  new  NoServicesFoundException ();
180+     }
179181
180182    // TODO(vam-google): Figure out whether we should keep this allowlist or bring 
181183    // back the unused resource names for all APIs. 
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments