From 18ac80f3b2ff56bc734d236ba38d9cd14c5f06d7 Mon Sep 17 00:00:00 2001 From: Ivan Hrasko Date: Thu, 20 May 2021 12:25:37 +0200 Subject: [PATCH] Fix submodule resource resolution Initial integration with yangtools-6.0.0 has changed the resource resolution logic. Unfortunately the lambda instroduced in Ifa9780fbdfb411b4613df0ee18407d85e81bd517 incorrectly passed 'module' and not the requested entity to the resolver -- leading to all submodules to open their module's resource instead. Fix the lambda and also add proper asserts to check resources are being open correctly. JIRA: MDSAL-663 Change-Id: I293f20c15426490a97bb70b4303f0c7b23114c82 Signed-off-by: Ivan Hrasko Signed-off-by: Robert Varga --- .../binding/maven/api/gen/plugin/CodeGeneratorImpl.java | 2 +- .../doc/generator/maven/YangModuleInfoCompilationTest.java | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/binding/maven-sal-api-gen-plugin/src/main/java/org/opendaylight/mdsal/binding/maven/api/gen/plugin/CodeGeneratorImpl.java b/binding/maven-sal-api-gen-plugin/src/main/java/org/opendaylight/mdsal/binding/maven/api/gen/plugin/CodeGeneratorImpl.java index 5506cc26d3..d3459d1a98 100644 --- a/binding/maven-sal-api-gen-plugin/src/main/java/org/opendaylight/mdsal/binding/maven/api/gen/plugin/CodeGeneratorImpl.java +++ b/binding/maven-sal-api-gen-plugin/src/main/java/org/opendaylight/mdsal/binding/maven/api/gen/plugin/CodeGeneratorImpl.java @@ -220,7 +220,7 @@ public final class CodeGeneratorImpl implements BasicCodeGenerator, BuildContext Builder generatedFiles = ImmutableSet.builder(); final YangModuleInfoTemplate template = new YangModuleInfoTemplate(module, ctx, - mod -> moduleResourcePathResolver.findModuleResourcePath(module, YangTextSchemaSource.class)); + mod -> moduleResourcePathResolver.findModuleResourcePath(mod, YangTextSchemaSource.class)); String moduleInfoSource = template.generate(); if (moduleInfoSource.isEmpty()) { throw new IllegalStateException("Generated code should not be empty!"); diff --git a/binding/maven-sal-api-gen-plugin/src/test/java/org/opendaylight/mdsal/binding/yang/unified/doc/generator/maven/YangModuleInfoCompilationTest.java b/binding/maven-sal-api-gen-plugin/src/test/java/org/opendaylight/mdsal/binding/yang/unified/doc/generator/maven/YangModuleInfoCompilationTest.java index fbb4da4211..0b7c682553 100644 --- a/binding/maven-sal-api-gen-plugin/src/test/java/org/opendaylight/mdsal/binding/yang/unified/doc/generator/maven/YangModuleInfoCompilationTest.java +++ b/binding/maven-sal-api-gen-plugin/src/test/java/org/opendaylight/mdsal/binding/yang/unified/doc/generator/maven/YangModuleInfoCompilationTest.java @@ -7,6 +7,8 @@ */ package org.opendaylight.mdsal.binding.yang.unified.doc.generator.maven; +import static org.hamcrest.CoreMatchers.startsWith; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -135,9 +137,13 @@ public class YangModuleInfoCompilationTest { } } assertNotNull(infoImport); + assertThat(infoImport.getYangTextCharSource().readFirstLine(), startsWith("module import-module")); assertNotNull(infoSub1); + assertThat(infoSub1.getYangTextCharSource().readFirstLine(), startsWith("submodule submodule1")); assertNotNull(infoSub2); + assertThat(infoSub2.getYangTextCharSource().readFirstLine(), startsWith("submodule submodule2")); assertNotNull(infoSub3); + assertThat(infoSub3.getYangTextCharSource().readFirstLine(), startsWith("submodule submodule3")); cleanUp(sourcesOutputDir, compiledOutputDir); } -- 2.36.6