abbccdda commented on a change in pull request #9002: URL: https://github.com/apache/kafka/pull/9002#discussion_r452542243
########## File path: generator/src/main/java/org/apache/kafka/message/TypeClassGenerator.java ########## @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.kafka.message; + +import java.io.BufferedWriter; +import java.io.IOException; + +public interface TypeClassGenerator { + /** + * The short name of the type class file we are generating. For example, + * ApiMessageType.java. + */ + String outputName(); + + /** + * Registers a message spec with the generator. + * + * @param spec The spec to register. + */ + void registerMessageType(MessageSpec spec); + + /** + * Write out the internal state. Review comment: Generate the type and write it out to the internal state. ########## File path: generator/src/main/java/org/apache/kafka/message/MessageGenerator.java ########## @@ -267,10 +283,10 @@ public static void main(String[] args) throws Exception { if (args.length == 0) { System.out.println(USAGE); System.exit(0); - } else if (args.length != 3) { + } else if (args.length != 4) { Review comment: Why we need separate exit code for mis-used arguments? ########## File path: generator/src/main/java/org/apache/kafka/message/MessageGenerator.java ########## @@ -169,20 +185,20 @@ public static void processDirectories(String packageName, String outputDir, Stri generator.write(writer); } numProcessed++; - messageTypeGenerator.registerMessageType(spec); + if (typeClassGenerator != null) { + typeClassGenerator.registerMessageType(spec); + } } catch (Exception e) { throw new RuntimeException("Exception while processing " + inputPath.toString(), e); } } } - if (messageTypeGenerator.hasRegisteredTypes()) { - Path factoryOutputPath = Paths.get(outputDir, API_MESSAGE_TYPE_JAVA); - outputFileNames.add(API_MESSAGE_TYPE_JAVA); + if (typeClassGenerator != null) { Review comment: Instead of using null ptr, maybe we could get a `NoOpTypeClassGenerator` which will do nothing for `generateAndWrite`, and remove the `outputName()` to make one single API. Something like ``` String outputFileName = typeClassGenerator.generateAndWrite(outputDir, writer); ``` I don't feel strong about this change, ideally it should look better, but up to you. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org