ProtostuffCompiler { public void compile(ModuleConfiguration configuration) { LOGGER.debug("Compiling module {}", configuration); FileReaderFactory fileReaderFactory = injector.getInstance(FileReaderFactory.class); Importer importer = injector.getInstance(Importer.class); CompilerRegistry registry = injector.getInstance(CompilerRegistry.class); ProtoCompiler compiler = registry.findCompiler(configuration.getGenerator()); if (compiler == null) { throw new GeneratorException("Unknown template: %s | %s", configuration.getGenerator(), registry.availableCompilers()); } FileReader fileReader = fileReaderFactory.create(configuration.getIncludePaths()); Map<String, Proto> importedFiles = new HashMap<>(); for (String path : configuration.getProtoFiles()) { LOGGER.info("Parse {}", path); ProtoContext context = importer.importFile(fileReader, path); Proto proto = context.getProto(); importedFiles.put(path, proto); } ImmutableModule.Builder builder = ImmutableModule.builder(); builder.name(configuration.getName()); builder.output(configuration.getOutput()); builder.options(configuration.getOptions()); for (Proto proto : importedFiles.values()) { builder.addProtos(proto); } UsageIndex index = UsageIndex.build(importedFiles.values()); builder.usageIndex(index); ImmutableModule module = builder.build(); for (Proto proto : importedFiles.values()) { proto.setModule(module); } compiler.compile(module); } ProtostuffCompiler(); void compile(ModuleConfiguration configuration);  }
@Test void compile() { ProtostuffCompiler compiler = new ProtostuffCompiler(); compiler.compile(ImmutableModuleConfiguration.builder() .name("none") .addProtoFiles("protostuff_unittest/messages_sample.proto") .generator(CompilerModule.DUMMY_COMPILER) .output("none") .build()); Injector injector = compiler.injector; CompilerRegistry registry = injector.getInstance(CompilerRegistry.class); DummyGenerator generator = (DummyGenerator) registry.findCompiler(CompilerModule.DUMMY_COMPILER); Assertions.assertNotNull(generator); Module compiledModule = generator.getLastCompiledModule(); Assertions.assertNotNull(compiledModule); Proto proto = compiledModule.getProtos().get(0); Message a = proto.getMessage("A"); Assertions.assertEquals("A", a.getName()); Assertions.assertFalse(a.isNested()); }