11package com .flit .protoc ;
22
3+ import static com .flit .protoc .Parameter .PARAM_REQUEST ;
4+ import static com .flit .protoc .Parameter .PARAM_TARGET ;
5+ import static com .flit .protoc .Parameter .PARAM_TYPE ;
6+
37import com .flit .protoc .gen .Generator ;
48import com .flit .protoc .gen .GeneratorException ;
59import com .flit .protoc .gen .server .jaxrs .JaxrsGenerator ;
610import com .flit .protoc .gen .server .spring .SpringGenerator ;
711import com .flit .protoc .gen .server .undertow .UndertowGenerator ;
812import com .google .protobuf .compiler .PluginProtos .CodeGeneratorRequest ;
913import com .google .protobuf .compiler .PluginProtos .CodeGeneratorResponse ;
10-
14+ import java .util .Arrays ;
15+ import java .util .Collections ;
16+ import java .util .List ;
1117import java .util .Map ;
1218
13- import static com .flit .protoc .Parameter .PARAM_TARGET ;
14- import static com .flit .protoc .Parameter .PARAM_TYPE ;
15-
1619public class Plugin {
1720
1821 private final CodeGeneratorRequest request ;
@@ -23,7 +26,9 @@ public Plugin(CodeGeneratorRequest request) {
2326
2427 public CodeGeneratorResponse process () {
2528 if (!request .hasParameter ()) {
26- return CodeGeneratorResponse .newBuilder ().setError ("Usage: --flit_out=target=server,type=[spring|undertow|jaxrs]:<PATH>" ).build ();
29+ return CodeGeneratorResponse .newBuilder ()
30+ .setError ("Usage: --flit_out=target=server,type=[spring|undertow|jaxrs][,request=[class(es)]]:<PATH>" )
31+ .build ();
2732 }
2833
2934 Map <String , Parameter > params = Parameter .of (request .getParameter ());
@@ -43,21 +48,31 @@ private Generator resolveGenerator(Map<String, Parameter> params) {
4348 if (!params .containsKey (PARAM_TYPE )) {
4449 throw new GeneratorException ("No argument specified for type" );
4550 }
51+ List <String > requestServices = getRequestServices (params );
4652 switch (params .get (PARAM_TARGET ).getValue ()) {
4753 case "server" :
4854 switch (params .get (PARAM_TYPE ).getValue ()) {
4955 case "boot" :
5056 case "spring" :
51- return new SpringGenerator ();
57+ return new SpringGenerator (requestServices );
5258 case "undertow" :
53- return new UndertowGenerator ();
59+ return new UndertowGenerator (requestServices );
5460 case "jaxrs" :
55- return new JaxrsGenerator ();
61+ return new JaxrsGenerator (requestServices );
5662 default :
5763 throw new GeneratorException ("Unknown server type: " + params .get (PARAM_TYPE ).getValue ());
5864 }
5965 default :
6066 throw new GeneratorException ("Unknown target type: " + params .get (PARAM_TARGET ).getValue ());
6167 }
6268 }
69+
70+ private List <String > getRequestServices (Map <String , Parameter > params ) {
71+ Parameter requestServices = params .get (PARAM_REQUEST );
72+ if (requestServices == null ) {
73+ return Collections .emptyList ();
74+ } else {
75+ return Arrays .asList (requestServices .getValue ().split ("," ));
76+ }
77+ }
6378}
0 commit comments