+ protected static final void generateTestSources(final List<Type> types, final File sourcesOutputDir)
+ throws IOException {
+ types.sort((o1, o2) -> o2.getName().compareTo(o1.getName()));
+
+ final GeneratorJavaFile generator = new GeneratorJavaFile(ImmutableSet.copyOf(types));
+ final Table<?, String, Supplier<String>> generatedFiles = generator.generateFileContent(true);
+ for (Cell<?, String, Supplier<String>> cell : generatedFiles.cellSet()) {
+ final File target = new File(sourcesOutputDir, cell.getColumnKey());
+ Files.createParentDirs(target);
+ Files.asCharSink(target, StandardCharsets.UTF_8).write(cell.getValue().get());
+ }
+ }
+
+ protected final List<Type> generateTestSources(final String resourceDirPath, final File sourcesOutputDir)
+ throws IOException, URISyntaxException {
+ final List<File> sourceFiles = CompilationTestUtils.getSourceFiles(resourceDirPath);
+ final SchemaContext context = YangParserTestUtils.parseYangFiles(sourceFiles);
+ final List<Type> types = bindingGenerator.generateTypes(context);
+ generateTestSources(types, sourcesOutputDir);
+
+ // Also generate YangModuleInfo
+ for (Module module : context.getModules()) {
+ final YangModuleInfoTemplate template = new YangModuleInfoTemplate(module, context,
+ mod -> Optional.of("fake/" + mod.getName()));
+
+ final File file = new File(GeneratorJavaFile.packageToDirectory(sourcesOutputDir,
+ BindingMapping.getRootPackageName(module.getQNameModule())),
+ BindingMapping.MODULE_INFO_CLASS_NAME + ".java");
+ Files.createParentDirs(file);
+ Files.asCharSink(file, StandardCharsets.UTF_8).write(template.generate());
+ }
+
+ return types;
+ }