Search in sources :

Example 6 with GeneratedFile

use of org.opendaylight.yangtools.plugin.generator.api.GeneratedFile in project mdsal by opendaylight.

the class YangModuleInfoCompilationTest method generateTestSourcesWithAdditionalConfig.

@Test
public void generateTestSourcesWithAdditionalConfig() throws Exception {
    final List<File> sourceFiles = getSourceFiles("/yang-module-info");
    final EffectiveModelContext context = YangParserTestUtils.parseYangFiles(sourceFiles);
    JavaFileGenerator codegen = new JavaFileGenerator(Map.of("test", "test"));
    Table<GeneratedFileType, GeneratedFilePath, GeneratedFile> files = codegen.generateFiles(context, Set.copyOf(context.getModules()), (module, representation) -> Optional.of(module.getName()));
    assertEquals(15, files.size());
    assertEquals(14, files.row(GeneratedFileType.SOURCE).size());
    assertEquals(1, files.row(GeneratedFileType.RESOURCE).size());
}
Also used : GeneratedFilePath(org.opendaylight.yangtools.plugin.generator.api.GeneratedFilePath) GeneratedFileType(org.opendaylight.yangtools.plugin.generator.api.GeneratedFileType) File(java.io.File) GeneratedFile(org.opendaylight.yangtools.plugin.generator.api.GeneratedFile) GeneratedFile(org.opendaylight.yangtools.plugin.generator.api.GeneratedFile) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) Test(org.junit.Test)

Example 7 with GeneratedFile

use of org.opendaylight.yangtools.plugin.generator.api.GeneratedFile in project mdsal by opendaylight.

the class BaseCompilationTest method generateTestSources.

protected static final void generateTestSources(final List<GeneratedType> types, final File sourcesOutputDir) throws IOException {
    types.sort((o1, o2) -> o2.getName().compareTo(o1.getName()));
    final Table<?, GeneratedFilePath, GeneratedFile> generatedFiles = JavaFileGenerator.generateFiles(types, true);
    for (Cell<?, GeneratedFilePath, GeneratedFile> cell : generatedFiles.cellSet()) {
        final File target = new File(sourcesOutputDir, cell.getColumnKey().getPath());
        Files.createParentDirs(target);
        try (OutputStream os = newOutputStream(target.toPath())) {
            cell.getValue().writeBody(os);
        }
    }
}
Also used : GeneratedFilePath(org.opendaylight.yangtools.plugin.generator.api.GeneratedFilePath) OutputStream(java.io.OutputStream) Files.newOutputStream(java.nio.file.Files.newOutputStream) File(java.io.File) GeneratedFile(org.opendaylight.yangtools.plugin.generator.api.GeneratedFile) GeneratedFile(org.opendaylight.yangtools.plugin.generator.api.GeneratedFile)

Aggregations

GeneratedFile (org.opendaylight.yangtools.plugin.generator.api.GeneratedFile)7 GeneratedFilePath (org.opendaylight.yangtools.plugin.generator.api.GeneratedFilePath)7 GeneratedFileType (org.opendaylight.yangtools.plugin.generator.api.GeneratedFileType)6 File (java.io.File)4 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)3 OutputStream (java.io.OutputStream)2 Test (org.junit.Test)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Stopwatch (com.google.common.base.Stopwatch)1 IOException (java.io.IOException)1 Files.newOutputStream (java.nio.file.Files.newOutputStream)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 CodeGenerator (org.opendaylight.mdsal.binding.model.api.CodeGenerator)1 GeneratedTransferObject (org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject)1 GeneratedType (org.opendaylight.mdsal.binding.model.api.GeneratedType)1 Type (org.opendaylight.mdsal.binding.model.api.Type)1 FileGenerator (org.opendaylight.yangtools.plugin.generator.api.FileGenerator)1 GeneratedFileLifecycle (org.opendaylight.yangtools.plugin.generator.api.GeneratedFileLifecycle)1 Module (org.opendaylight.yangtools.yang.model.api.Module)1