Changed $Yang* generation package and name 05/107705/14
authorOleksandr Panasiuk <oleksandr.panasiuk@pantheon.tech>
Tue, 5 Sep 2023 08:04:23 +0000 (11:04 +0300)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 18 Jan 2024 07:53:02 +0000 (08:53 +0100)
The naming of these classes is rather unfortunate, as it starts with $
due to the requirement not to conflict with other generated classes. So
they were renemed to avoid dollar sign usage.
Also the root package for theese classes was changed from
org.opendaylight.yang.gen.v1 to org.opendaylight.yang.svc.v1.
A lot of test classes are touched in this patch but no logic were
changed there, its just providing a new path for YangModuleInfoImpl.

JIRA: MDSAL-836
Change-Id: If9e43d21063c2fc48d8adbf0ccfc2406fe760054
Signed-off-by: Oleksandr Panasiuk <oleksandr.panasiuk@pantheon.tech>
Signed-off-by: lubos-cicut <lubos.cicut@pantheon.tech>
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
20 files changed:
binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/ForwardedNotificationAdapterTest.java
binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/Mdsal500Test.java
binding/mdsal-binding-generator/src/main/java/org/opendaylight/mdsal/binding/generator/impl/reactor/ModuleGenerator.java
binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/mdsal/binding/java/api/generator/YangModuleInfoTemplate.xtend
binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/mdsal/binding/java/api/generator/AugmentToUsesInAugmentCompilationTest.java
binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/mdsal/binding/java/api/generator/BaseCompilationTest.java
binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/mdsal/binding/java/api/generator/Bug5151Test.java
binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/mdsal/binding/java/api/generator/CascadeUsesCompilationTest.java
binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/mdsal/binding/java/api/generator/CompilationTest.java
binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/mdsal/binding/java/api/generator/CompilationTestUtils.java
binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/mdsal/binding/java/api/generator/NestedGroupingCompilationTest.java
binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/mdsal/binding/java/api/generator/TypedefCompilationTest.java
binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/mdsal/binding/java/api/generator/YangModuleInfoCompilationTest.java
binding/mdsal-binding-runtime-spi/src/main/java/org/opendaylight/mdsal/binding/runtime/spi/BindingRuntimeHelpers.java
binding/mdsal-binding-runtime-spi/src/main/java/org/opendaylight/mdsal/binding/runtime/spi/ModuleInfoSnapshotBuilder.java
binding/mdsal-binding-runtime-spi/src/test/java/org/opendaylight/mdsal/binding/runtime/spi/ModuleInfoSnapshotBuilderTest.java
binding/mdsal-binding-spec-util/src/main/java/org/opendaylight/mdsal/binding/spec/reflect/BindingReflections.java
binding/yang-binding/src/main/java/org/opendaylight/yangtools/yang/binding/contract/Naming.java
dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/Rpcs.java
dom/mdsal-dom-spi/src/test/java/org/opendaylight/mdsal/dom/spi/ContentRoutedRpcContextTest.java

index 8b8b4384af8a512af8b1d9a4f27771411d30619a..ff0f48a9ff18ea310a96d96c5f4719f245041e85 100644 (file)
@@ -21,18 +21,18 @@ import org.junit.Test;
 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
 import org.opendaylight.mdsal.binding.api.NotificationService.Listener;
 import org.opendaylight.mdsal.binding.dom.adapter.test.AbstractNotificationBrokerTest;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.$YangModuleInfoImpl;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.TwoLevelListChanged;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.TwoLevelListChangedBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelListBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelListKey;
+import org.opendaylight.yang.svc.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.YangModuleInfoImpl;
 import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
 import org.opendaylight.yangtools.yang.binding.util.BindingMap;
 
 public class ForwardedNotificationAdapterTest extends AbstractNotificationBrokerTest {
     @Override
     protected Set<YangModuleInfo> getModuleInfos() throws Exception {
-        return Set.of($YangModuleInfoImpl.getInstance());
+        return Set.of(YangModuleInfoImpl.getInstance());
     }
 
     @Test
index 0ac7ad6a1cb9562b9b71bc595568e6a00b453601..804a5e77c91eb6af442c27add2bd3ce4dd19a406 100644 (file)
@@ -33,12 +33,12 @@ import org.opendaylight.mdsal.dom.api.DOMRpcProviderService;
 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
 import org.opendaylight.mdsal.dom.api.DOMRpcService;
 import org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult;
-import org.opendaylight.yang.gen.v1.rpc.norev.$YangModuleInfoImpl;
 import org.opendaylight.yang.gen.v1.rpc.norev.Switch;
 import org.opendaylight.yang.gen.v1.rpc.norev.SwitchInput;
 import org.opendaylight.yang.gen.v1.rpc.norev.SwitchInputBuilder;
 import org.opendaylight.yang.gen.v1.rpc.norev.SwitchOutput;
 import org.opendaylight.yang.gen.v1.rpc.norev.SwitchOutputBuilder;
+import org.opendaylight.yang.svc.v1.rpc.norev.YangModuleInfoImpl;
 import org.opendaylight.yangtools.util.concurrent.FluentFutures;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.RpcResult;
@@ -63,7 +63,7 @@ public class Mdsal500Test {
         testFactory.setExecutor(MoreExecutors.newDirectExecutorService());
         testContext = testFactory.getTestContext();
 
-        testContext.setSchemaModuleInfos(Set.of($YangModuleInfoImpl.getInstance()));
+        testContext.setSchemaModuleInfos(Set.of(YangModuleInfoImpl.getInstance()));
         testContext.start();
         baRpcProviderService = testContext.getBindingRpcProviderRegistry();
         baRpcConsumerService = testContext.getBindingRpcService();
index 2634d538c86bd47a0d6c176c199bc134afe151ad..1aa230aa23535a6b17f6d9d74ab07bb8474d695e 100644 (file)
@@ -50,7 +50,8 @@ public final class ModuleGenerator extends AbstractCompositeGenerator<ModuleEffe
 
     ModuleGenerator(final ModuleEffectiveStatement statement) {
         super(statement);
-        yangModuleInfo = JavaTypeName.create(javaPackage(), Naming.MODULE_INFO_CLASS_NAME);
+        yangModuleInfo = JavaTypeName.create(Naming.getServicePackageName(statement.localQNameModule()),
+            Naming.MODULE_INFO_CLASS_NAME);
         prefixMember = domain().addPrefix(this, new ModuleNamingStrategy(statement.argument()));
     }
 
index 8b42d43d8aaf63024c89ebd8266e5858ec41fc55..2c940685fc368154e39c1953e55fae86a1589ec1 100644 (file)
@@ -8,7 +8,7 @@
 package org.opendaylight.mdsal.binding.java.api.generator
 
 import static extension org.opendaylight.yangtools.yang.binding.contract.Naming.getClassName
-import static extension org.opendaylight.yangtools.yang.binding.contract.Naming.getRootPackageName
+import static extension org.opendaylight.yangtools.yang.binding.contract.Naming.getServicePackageName
 import static org.opendaylight.yangtools.yang.binding.contract.Naming.MODEL_BINDING_PROVIDER_CLASS_NAME
 import static org.opendaylight.yangtools.yang.binding.contract.Naming.MODULE_INFO_CLASS_NAME
 import static org.opendaylight.yangtools.yang.binding.contract.Naming.MODULE_INFO_QNAMEOF_METHOD_NAME
@@ -81,7 +81,7 @@ final class YangModuleInfoTemplate {
         this.module = module
         this.ctx = ctx
         this.moduleFilePathResolver = moduleFilePathResolver
-        packageName = module.QNameModule.rootPackageName;
+        packageName = module.QNameModule.getServicePackageName;
         modelBindingProviderName = '''«packageName».«MODEL_BINDING_PROVIDER_CLASS_NAME»'''
         hasYangData = module.unknownSchemaNodes.stream.anyMatch([s | s instanceof YangDataSchemaNode])
     }
@@ -207,9 +207,9 @@ final class YangModuleInfoTemplate {
                                 «sorted.put(module.revision, module)»
                             «ENDIF»
                         «ENDFOR»
-                        set.add(«sorted.lastEntry().value.QNameModule.rootPackageName».«MODULE_INFO_CLASS_NAME».getInstance());
+                        set.add(«sorted.lastEntry().value.QNameModule.getServicePackageName».«MODULE_INFO_CLASS_NAME».getInstance());
                     «ELSE»
-                        set.add(«(ctx.findModule(name, rev).orElseThrow.QNameModule).rootPackageName».«MODULE_INFO_CLASS_NAME».getInstance());
+                        set.add(«(ctx.findModule(name, rev).orElseThrow.QNameModule).getServicePackageName».«MODULE_INFO_CLASS_NAME».getInstance());
                     «ENDIF»
                 «ENDFOR»
             «ENDIF»
index 16b9cc226161ac4f349850e98e641ff826957cf1..bac49f5892b074d5f6312bb0c541b61f51de742a 100644 (file)
@@ -25,43 +25,49 @@ public class AugmentToUsesInAugmentCompilationTest extends BaseCompilationTest {
         generateTestSources("/compilation/augment-uses-to-augment", sourcesOutputDir);
 
         // Test if all sources are generated from 'module foo'
-        File fooParent = new File(sourcesOutputDir, CompilationTestUtils.NS_FOO);
+        final File fooParent = new File(sourcesOutputDir, CompilationTestUtils.NS_FOO);
         assertTrue(new File(fooParent, "FooData.java").exists());
         assertTrue(new File(fooParent, "IgpLinkAttributes.java").exists());
         assertTrue(new File(fooParent, "Link1.java").exists());
         assertTrue(new File(fooParent, "Link1Builder.java").exists());
-        CompilationTestUtils.assertFilesCount(fooParent, 6);
+        CompilationTestUtils.assertFilesCount(fooParent, 5);
+        final File fooSvcParent = new File(sourcesOutputDir, CompilationTestUtils.NS_SVC_FOO);
+        CompilationTestUtils.assertFilesCount(fooSvcParent, 1);
 
         // Test if all sources are generated from 'module bar'
-        File barParent = new File(sourcesOutputDir, CompilationTestUtils.NS_BAR);
+        final File barParent = new File(sourcesOutputDir, CompilationTestUtils.NS_BAR);
         assertTrue(new File(barParent, "BarData.java").exists());
         assertTrue(new File(barParent, "NetworkTopology.java").exists());
         assertTrue(new File(barParent, "NetworkTopologyBuilder.java").exists());
         assertTrue(new File(barParent, "Link.java").exists());
         assertTrue(new File(barParent, "LinkAttributes.java").exists());
-        CompilationTestUtils.assertFilesCount(barParent, 8);
+        CompilationTestUtils.assertFilesCount(barParent, 7);
+        final File barSvcParent = new File(sourcesOutputDir, CompilationTestUtils.NS_SVC_BAR);
+        CompilationTestUtils.assertFilesCount(barSvcParent, 1);
 
-        File networkParent = new File(barParent, "network");
+        final File networkParent = new File(barParent, "network");
         CompilationTestUtils.assertFilesCount(networkParent, 1);
-        File topologyParent = new File(networkParent, "topology");
+        final File topologyParent = new File(networkParent, "topology");
         assertTrue(new File(topologyParent, "Topology.java").exists());
         assertTrue(new File(topologyParent, "TopologyBuilder.java").exists());
         assertTrue(new File(topologyParent, "TopologyKey.java").exists());
         CompilationTestUtils.assertFilesCount(topologyParent, 3);
 
-        File linkParent = new File(barParent, "link");
+        final File linkParent = new File(barParent, "link");
         assertTrue(new File(linkParent, "Link.java").exists());
         assertTrue(new File(linkParent, "LinkBuilder.java").exists());
         assertTrue(new File(linkParent, "LinkKey.java").exists());
         CompilationTestUtils.assertFilesCount(linkParent, 3);
 
         // Test if all sources are generated from 'module baz'
-        File bazParent = new File(sourcesOutputDir, CompilationTestUtils.NS_BAZ);
+        final File bazParent = new File(sourcesOutputDir, CompilationTestUtils.NS_BAZ);
         assertTrue(new File(bazParent, "BazData.java").exists());
         assertTrue(new File(bazParent, "IgpLinkAttributes1.java").exists());
         assertTrue(new File(bazParent, "IgpLinkAttributes1Builder.java").exists());
         assertTrue(new File(bazParent, "LinkAttributes.java").exists());
-        CompilationTestUtils.assertFilesCount(bazParent, 6);
+        CompilationTestUtils.assertFilesCount(bazParent, 5);
+        final File bazSvcParent = new File(sourcesOutputDir, CompilationTestUtils.NS_SVC_BAZ);
+        CompilationTestUtils.assertFilesCount(bazSvcParent, 1);
 
         // Test if sources are compilable
         CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);
index 368bec84e9ea312913e8d9e208d2289f249821fd..6ba90a62e949f7d4014b2884fe4f6529835934cc 100644 (file)
@@ -69,7 +69,7 @@ public abstract class BaseCompilationTest {
                 mod -> Optional.of("fake/" + mod.getName()));
 
             final File file = new File(new File(sourcesOutputDir,
-                Naming.getRootPackageName(module.getQNameModule()).replace('.', File.separatorChar)),
+                Naming.getServicePackageName(module.getQNameModule()).replace('.', File.separatorChar)),
                 Naming.MODULE_INFO_CLASS_NAME + ".java");
             Files.createParentDirs(file);
             Files.asCharSink(file, StandardCharsets.UTF_8).write(template.generate());
index 910d366c0edd9c1e4b3a2d1f50a2b1f8f2835e00..26b0e6c47a309f2163f95cc86c6af509ae69f0b4 100644 (file)
@@ -10,6 +10,8 @@ package org.opendaylight.mdsal.binding.java.api.generator;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assume.assumeFalse;
+import static org.opendaylight.mdsal.binding.java.api.generator.CompilationTestUtils.BASE_SVC_PATH;
+import static org.opendaylight.mdsal.binding.java.api.generator.CompilationTestUtils.FS;
 
 import java.io.File;
 import java.util.Map;
@@ -21,6 +23,7 @@ import org.junit.Test;
 public class Bug5151Test extends BaseCompilationTest {
 
     private static final String BUG_ID = "bug5151";
+    private static final String SVC_PATH = BASE_SVC_PATH + FS + "urn" + FS + "test" + FS + "foo" + FS + "rev160706";
 
     @Test
     public void test() throws Exception {
@@ -29,14 +32,14 @@ public class Bug5151Test extends BaseCompilationTest {
         assumeFalse(System.getProperty("os.name").toLowerCase().startsWith("win"));
         final File sourcesOutputDir = CompilationTestUtils.generatorOutput(BUG_ID);
         final File compiledOutputDir = CompilationTestUtils.compilerOutput(BUG_ID);
-        generateTestSources(CompilationTestUtils.FS + "compilation" + CompilationTestUtils.FS + BUG_ID,
+        generateTestSources(FS + "compilation" + FS + BUG_ID,
             sourcesOutputDir);
 
         // Test if sources are compilable
         CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);
 
         final Map<String, File> generatedFiles = FileSearchUtil.getFiles(sourcesOutputDir);
-        assertEquals(13, generatedFiles.size());
+        assertEquals(14, generatedFiles.size());
 
         final File fooContainerFile = generatedFiles.get("FooContainer.java");
         assertNotNull(fooContainerFile);
@@ -48,6 +51,9 @@ public class Bug5151Test extends BaseCompilationTest {
         FileSearchUtil.assertFileContains(fooDataFile,
             "FooContainer} fooContainer, or {@code null} if it is not present");
 
+        final File svcParent = new File(sourcesOutputDir, SVC_PATH);
+        CompilationTestUtils.assertFilesCount(svcParent, 1);
+
         CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
     }
 }
index 9c8cfaa588ff3633f64f953328c8a7d39ae4da02..a55cd55461d657e8319d1432c2620d292e1b3ad8 100644 (file)
@@ -15,6 +15,9 @@ import static org.opendaylight.mdsal.binding.java.api.generator.CompilationTestU
 import static org.opendaylight.mdsal.binding.java.api.generator.CompilationTestUtils.NS_BAR;
 import static org.opendaylight.mdsal.binding.java.api.generator.CompilationTestUtils.NS_BAZ;
 import static org.opendaylight.mdsal.binding.java.api.generator.CompilationTestUtils.NS_FOO;
+import static org.opendaylight.mdsal.binding.java.api.generator.CompilationTestUtils.NS_SVC_BAR;
+import static org.opendaylight.mdsal.binding.java.api.generator.CompilationTestUtils.NS_SVC_BAZ;
+import static org.opendaylight.mdsal.binding.java.api.generator.CompilationTestUtils.NS_SVC_FOO;
 import static org.opendaylight.mdsal.binding.java.api.generator.CompilationTestUtils.assertFilesCount;
 import static org.opendaylight.mdsal.binding.java.api.generator.CompilationTestUtils.assertImplementsIfc;
 import static org.opendaylight.mdsal.binding.java.api.generator.CompilationTestUtils.cleanUp;
@@ -41,20 +44,26 @@ public class CascadeUsesCompilationTest extends BaseCompilationTest {
         assertTrue(new File(parent, "FooGr1.java").exists());
         assertTrue(new File(parent, "Nodes.java").exists());
         assertTrue(new File(parent, "NodesBuilder.java").exists());
-        assertFilesCount(parent, 6);
+        assertFilesCount(parent, 5);
+        File svcParent = new File(sourcesOutputDir, NS_SVC_FOO);
+        assertFilesCount(svcParent, 1);
 
         // Test if all sources are generated from module bar
         parent = new File(sourcesOutputDir, NS_BAR);
         assertTrue(new File(parent, "BarData.java").exists());
         assertTrue(new File(parent, "BarGr1.java").exists());
         assertTrue(new File(parent, "BarGr2.java").exists());
-        assertFilesCount(parent, 4);
+        assertFilesCount(parent, 3);
+        svcParent = new File(sourcesOutputDir, NS_SVC_BAR);
+        assertFilesCount(svcParent, 1);
 
         // Test if all sources are generated from module baz
         parent = new File(sourcesOutputDir, NS_BAZ);
         assertTrue(new File(parent, "BazData.java").exists());
         assertTrue(new File(parent, "BazGr1.java").exists());
-        assertFilesCount(parent, 3);
+        assertFilesCount(parent, 2);
+        svcParent = new File(sourcesOutputDir, NS_SVC_BAZ);
+        assertFilesCount(svcParent, 1);
 
         // Test if sources are compilable
         testCompilation(sourcesOutputDir, compiledOutputDir);
index 0e5f744a2016079dd4839d99d3983c7d7191d080..b1716b0b889128438d4f94d58c15a44c88239611 100644 (file)
@@ -82,7 +82,9 @@ public class CompilationTest extends BaseCompilationTest {
         assertTrue(linksBuilder.exists());
         assertTrue(linksKey.exists());
         assertTrue(testData.exists());
-        CompilationTestUtils.assertFilesCount(parent, 7);
+        CompilationTestUtils.assertFilesCount(parent, 6);
+        final File svcParent = new File(sourcesOutputDir, CompilationTestUtils.NS_SVC_TEST);
+        CompilationTestUtils.assertFilesCount(svcParent, 1);
 
         parent = new File(sourcesOutputDir, CompilationTestUtils.NS_TEST + CompilationTestUtils.FS + "links");
         final File level = new File(parent, "Level.java");
@@ -153,7 +155,9 @@ public class CompilationTest extends BaseCompilationTest {
         assertTrue(new File(parent, "RootContainer.java").exists());
         assertTrue(new File(parent, "rootcontainer/PresenceContainer.java").exists());
         assertTrue(new File(parent, "rootcontainer/NonPresenceContainer.java").exists());
-        CompilationTestUtils.assertFilesCount(parent, 5);
+        CompilationTestUtils.assertFilesCount(parent, 4);
+        File svcParent = new File(sourcesOutputDir, CompilationTestUtils.NS_SVC_TEST);
+        CompilationTestUtils.assertFilesCount(svcParent, 1);
 
         // Test if sources are compilable
         CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);
@@ -201,7 +205,9 @@ public class CompilationTest extends BaseCompilationTest {
         assertTrue(new File(parent, "ExplicitRouteObject.java").exists());
         assertTrue(new File(parent, "PathKeySubobject.java").exists());
         assertTrue(new File(parent, "FooData.java").exists());
-        CompilationTestUtils.assertFilesCount(parent, 11);
+        CompilationTestUtils.assertFilesCount(parent, 10);
+        File svcParent = new File(sourcesOutputDir, CompilationTestUtils.NS_SVC_FOO);
+        CompilationTestUtils.assertFilesCount(svcParent, 1);
 
         parent = new File(parent, "object");
         assertTrue(new File(parent, "Nodes.java").exists());
@@ -260,7 +266,9 @@ public class CompilationTest extends BaseCompilationTest {
         assertTrue(new File(parent, "BasicExplicitRouteSubobjects.java").exists());
         assertTrue(new File(parent, "ExplicitRouteSubobjects.java").exists());
         assertTrue(new File(parent, "RouteSubobjects.java").exists());
-        CompilationTestUtils.assertFilesCount(parent, 7);
+        CompilationTestUtils.assertFilesCount(parent, 6);
+        svcParent = new File(sourcesOutputDir, CompilationTestUtils.NS_SVC_BAR);
+        CompilationTestUtils.assertFilesCount(svcParent, 1);
 
         parent = new File(parent, "route");
         CompilationTestUtils.assertFilesCount(parent, 1);
@@ -303,7 +311,9 @@ public class CompilationTest extends BaseCompilationTest {
         assertTrue(new File(parent, "PathAttributes.java").exists());
         assertTrue(new File(parent, "Update.java").exists());
         assertTrue(new File(parent, "UpdateBuilder.java").exists());
-        CompilationTestUtils.assertFilesCount(parent, 7);
+        CompilationTestUtils.assertFilesCount(parent, 6);
+        File svcParent = new File(sourcesOutputDir, CompilationTestUtils.NS_SVC_FOO);
+        CompilationTestUtils.assertFilesCount(svcParent, 1);
 
         parent = new File(sourcesOutputDir, CompilationTestUtils.NS_FOO + CompilationTestUtils.FS + "path");
         CompilationTestUtils.assertFilesCount(parent, 1);
@@ -325,7 +335,9 @@ public class CompilationTest extends BaseCompilationTest {
         assertTrue(new File(parent, "Destination.java").exists());
         assertTrue(new File(parent, "PathAttributes1.java").exists());
         assertTrue(new File(parent, "PathAttributes1Builder.java").exists());
-        CompilationTestUtils.assertFilesCount(parent, 7);
+        CompilationTestUtils.assertFilesCount(parent, 6);
+        svcParent = new File(sourcesOutputDir, CompilationTestUtils.NS_SVC_BAR);
+        CompilationTestUtils.assertFilesCount(svcParent, 1);
 
         parent = new File(sourcesOutputDir, CompilationTestUtils.NS_BAR + CompilationTestUtils.FS + "destination");
         CompilationTestUtils.assertFilesCount(parent, 2);
@@ -365,7 +377,9 @@ public class CompilationTest extends BaseCompilationTest {
         parent = new File(sourcesOutputDir, CompilationTestUtils.NS_BAZ);
         assertTrue(new File(parent, "BazData.java").exists());
         assertTrue(new File(parent, "LinkstateDestination.java").exists());
-        CompilationTestUtils.assertFilesCount(parent, 4);
+        CompilationTestUtils.assertFilesCount(parent, 3);
+        svcParent = new File(sourcesOutputDir, CompilationTestUtils.NS_SVC_BAZ);
+        CompilationTestUtils.assertFilesCount(svcParent, 1);
 
         parent = new File(sourcesOutputDir, CompilationTestUtils.NS_BAZ + CompilationTestUtils.FS + "update");
         CompilationTestUtils.assertFilesCount(parent, 1);
@@ -429,7 +443,9 @@ public class CompilationTest extends BaseCompilationTest {
         assertTrue(new File(parent, "Nodes.java").exists());
         assertTrue(new File(parent, "NodesBuilder.java").exists());
         assertTrue(new File(parent, "Alg.java").exists());
-        CompilationTestUtils.assertFilesCount(parent, 5);
+        CompilationTestUtils.assertFilesCount(parent, 4);
+        final File svcParent = new File(sourcesOutputDir, CompilationTestUtils.NS_SVC_TEST);
+        CompilationTestUtils.assertFilesCount(svcParent, 1);
 
         // Test if sources are compilable
         CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);
@@ -492,13 +508,17 @@ public class CompilationTest extends BaseCompilationTest {
 
         // Test if all sources are generated
         final File fooParent = new File(sourcesOutputDir, CompilationTestUtils.NS_FOO);
-        CompilationTestUtils.assertFilesCount(fooParent, 4);
+        CompilationTestUtils.assertFilesCount(fooParent, 3);
+        final File fooSvcParent = new File(sourcesOutputDir, CompilationTestUtils.NS_SVC_FOO);
+        CompilationTestUtils.assertFilesCount(fooSvcParent, 1);
         assertTrue(new File(fooParent, "FooData.java").exists());
         assertTrue(new File(fooParent, "Nodes.java").exists());
         assertTrue(new File(fooParent, "NodesBuilder.java").exists());
 
         final File barParent = new File(sourcesOutputDir, CompilationTestUtils.NS_BAR);
-        CompilationTestUtils.assertFilesCount(barParent, 3);
+        CompilationTestUtils.assertFilesCount(barParent, 2);
+        final File barSvcParent = new File(sourcesOutputDir, CompilationTestUtils.NS_SVC_BAR);
+        CompilationTestUtils.assertFilesCount(barSvcParent, 1);
         assertTrue(new File(barParent, "BarData.java").exists());
         assertTrue(new File(barParent, "IdentityClass.java").exists());
 
@@ -806,12 +826,11 @@ public class CompilationTest extends BaseCompilationTest {
         final File compiledOutputDir = CompilationTestUtils.compilerOutput("yang-data-gen");
 
         generateTestSources("/compilation/yang-data-gen", sourcesOutputDir);
-        CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);
 
         final ClassLoader loader = new URLClassLoader(new URL[]{compiledOutputDir.toURI().toURL()});
         final List<String> artifactNames = List.of(
                 // module with top level container
-                "$YangModuleInfoImpl", "YangDataDemoData", "RootContainer", "RootContainerBuilder",
+                "YangDataDemoData", "RootContainer", "RootContainerBuilder",
 
                 // yang-data artifacts
                 "YangDataWithContainer", "YangDataWithContainerBuilder",
@@ -854,8 +873,6 @@ public class CompilationTest extends BaseCompilationTest {
             // ensure class source is generated
             final String srcPath = className.replace('.', File.separatorChar) + ".java";
             assertTrue(srcPath + " exists", new File(sourcesOutputDir, srcPath).exists());
-            // ensure class is loadable
-            Class.forName(className, true, loader);
         }
 
         CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
index 42d976ef0b9044bfcf1ea1096bc06ca98557bacd..ffc7e14467865c1c762eb36a71e7059b86e44cb9 100644 (file)
@@ -50,10 +50,15 @@ public final class CompilationTestUtils {
 
     static final String AUGMENTATION = "interface org.opendaylight.yangtools.yang.binding.Augmentation";
     static final String BASE_PATH = "org" + FS + "opendaylight" + FS + "yang" + FS + "gen" + FS + "v1";
+    static final String BASE_SVC_PATH = "org" + FS + "opendaylight" + FS + "yang" + FS + "svc" + FS + "v1";
     static final String NS_TEST = BASE_PATH + FS + "urn" + FS + "opendaylight" + FS + "test" + FS + "rev131008";
+    static final String NS_SVC_TEST = BASE_SVC_PATH + FS + "urn" + FS + "opendaylight" + FS + "test" + FS + "rev131008";
     static final String NS_FOO = BASE_PATH + FS + "urn" + FS + "opendaylight" + FS + "foo" + FS + "rev131008";
+    static final String NS_SVC_FOO = BASE_SVC_PATH + FS + "urn" + FS + "opendaylight" + FS + "foo" + FS + "rev131008";
     static final String NS_BAR = BASE_PATH + FS + "urn" + FS + "opendaylight" + FS + "bar" + FS + "rev131008";
+    static final String NS_SVC_BAR = BASE_SVC_PATH + FS + "urn" + FS + "opendaylight" + FS + "bar" + FS + "rev131008";
     static final String NS_BAZ = BASE_PATH + FS + "urn" + FS + "opendaylight" + FS + "baz" + FS + "rev131008";
+    static final String NS_SVC_BAZ = BASE_SVC_PATH + FS + "urn" + FS + "opendaylight" + FS + "baz" + FS + "rev131008";
     static final String NS_BUG5882 = BASE_PATH + FS + "urn" + FS + "yang" + FS + "foo" + FS + "rev160102";
 
     private CompilationTestUtils() {
index 9245830e13ae5b97b33bab000a7e4c9973c28e9a..427cf0578869630c626312b974e0da3fc0d58861 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.mdsal.binding.java.api.generator;
 
 import static org.junit.Assert.assertTrue;
 import static org.opendaylight.mdsal.binding.java.api.generator.CompilationTestUtils.BASE_PKG;
+import static org.opendaylight.mdsal.binding.java.api.generator.CompilationTestUtils.NS_SVC_TEST;
 import static org.opendaylight.mdsal.binding.java.api.generator.CompilationTestUtils.NS_TEST;
 import static org.opendaylight.mdsal.binding.java.api.generator.CompilationTestUtils.assertFilesCount;
 import static org.opendaylight.mdsal.binding.java.api.generator.CompilationTestUtils.assertImplementsIfc;
@@ -42,10 +43,12 @@ public class NestedGroupingCompilationTest extends BaseCompilationTest {
         assertTrue(fooBuilder.exists());
         assertTrue(testData.exists());
         assertTrue(fooDir.exists());
-        assertFilesCount(parent, 5);
+        assertFilesCount(parent, 4);
+        final File svcParent = new File(sourcesOutputDir, NS_SVC_TEST);
+        assertFilesCount(svcParent, 1);
 
         parent = new File(parent, "foo");
-        File bar = new File(parent, "Bar.java");
+        final File bar = new File(parent, "Bar.java");
         assertTrue(bar.exists());
         assertFilesCount(parent, 1);
 
index 91c1d40630ea9694b73747e4a9f6f8f7796f1760..5507b50d3f32009ac5abac2129ed0d4cc0e7497d 100644 (file)
@@ -51,7 +51,9 @@ public class TypedefCompilationTest extends BaseCompilationTest {
         assertTrue(new File(parent, "UnionExt2.java").exists());
         assertTrue(new File(parent, "UnionExt3.java").exists());
         assertTrue(new File(parent, "UnionExt4.java").exists());
-        CompilationTestUtils.assertFilesCount(parent, 31);
+        CompilationTestUtils.assertFilesCount(parent, 30);
+        final File svcParent = new File(sourcesOutputDir, CompilationTestUtils.NS_SVC_FOO);
+        CompilationTestUtils.assertFilesCount(svcParent, 1);
 
         // Test if sources are compilable
         CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);
index f17beba5d1602df78045b5c7ede1e307e170b441..bc51aea342470a35016ce4be5095597f4281a86a 100644 (file)
@@ -56,7 +56,7 @@ import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 // binding-java-api-generator project - reorganize compilation tests
 public class YangModuleInfoCompilationTest {
     public static final String FS = File.separator;
-    private static final String BASE_PKG = "org.opendaylight.yang.gen.v1";
+    private static final String BASE_PKG = "org.opendaylight.yang.svc.v1";
 
     private static final String TEST_PATH = "target" + FS + "test";
     private static final File TEST_DIR = new File(TEST_PATH);
@@ -85,10 +85,10 @@ public class YangModuleInfoCompilationTest {
         generateTestSources("/yang-module-info", sourcesOutputDir);
 
         // Test if $YangModuleInfoImpl.java file is generated
-        final String BASE_PATH = "org" + FS + "opendaylight" + FS + "yang" + FS + "gen" + FS + "v1";
+        final String BASE_PATH = "org" + FS + "opendaylight" + FS + "yang" + FS + "svc" + FS + "v1";
         final String NS_TEST = BASE_PATH + FS + "yang" + FS + "test" + FS + "main" + FS + "rev140630";
         File parent = new File(sourcesOutputDir, NS_TEST);
-        File keyArgs = new File(parent, "$YangModuleInfoImpl.java");
+        File keyArgs = new File(parent, "YangModuleInfoImpl.java");
         assertTrue(keyArgs.exists());
 
         // Test if sources are compilable
@@ -101,8 +101,8 @@ public class YangModuleInfoCompilationTest {
         ClassLoader loader = new URLClassLoader(urls);
 
         // Load class
-        Class<?> yangModuleInfoClass = Class.forName(BASE_PKG + ".yang.test.main.rev140630.$YangModuleInfoImpl", true,
-                loader);
+        Class<?> yangModuleInfoClass =
+            Class.forName(BASE_PKG + ".yang.test.main.rev140630.YangModuleInfoImpl", true, loader);
 
         // Test generated $YangModuleInfoImpl class
         assertFalse(yangModuleInfoClass.isInterface());
index e4db5c3d441f88462926c9c125ba3c2ee8056275..523c7e6718e95d85c2e08a4de482a5d7c0c0805f 100644 (file)
@@ -106,8 +106,7 @@ public final class BindingRuntimeHelpers {
     }
 
     public static @NonNull YangModuleInfo getYangModuleInfo(final Class<?> clazz) {
-        // Module info resides in the root package we will use that to ascertain identity
-        final var modelPackage = Naming.getModelRootPackageName(clazz.getPackage().getName());
+        final var modelPackage = Naming.rootToServicePackageName(clazz.getPackage().getName());
 
         for (var bindingProvider : ServiceLoader.load(YangModelBindingProvider.class, clazz.getClassLoader())) {
             var moduleInfo = bindingProvider.getModuleInfo();
index 363cdab4a37cfc42144e32c027c95ed7c6fa55d4..3aacf9929a472a0ff68a7a82f8c76d46e34f7314 100644 (file)
@@ -110,7 +110,8 @@ public final class ModuleInfoSnapshotBuilder {
             mappedInfos.put(source.sourceId(), info);
 
             final Class<?> infoClass = info.getClass();
-            final String infoRoot = Naming.getModelRootPackageName(infoClass.getPackage().getName());
+            final String infoRoot = Naming.getModelRootPackageName(infoClass.getPackage().getName())
+                .replace(Naming.SVC_PACKAGE_PREFIX, Naming.PACKAGE_PREFIX);
             classLoaders.put(infoRoot, infoClass.getClassLoader());
             namespaces.put(infoRoot, info.getName().getModule());
 
index babc6783d94784d5940e0fefd9c582a7d424506b..618007f635bb54e25469dfda069e7d01b6129fd1 100644 (file)
@@ -11,9 +11,9 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
 
 import java.util.Set;
 import org.junit.jupiter.api.Test;
-import org.opendaylight.yang.gen.v1.mdsal767.norev.$YangModuleInfoImpl;
 import org.opendaylight.yang.gen.v1.mdsal767.norev.Mdsal767Data;
 import org.opendaylight.yang.gen.v1.mdsal767.norev.One$F;
+import org.opendaylight.yang.svc.v1.mdsal767.norev.YangModuleInfoImpl;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.common.XMLNamespace;
@@ -23,7 +23,7 @@ class ModuleInfoSnapshotBuilderTest {
     @Test
     void testModuleRegistration() throws Exception {
         final var snapshotBuilder = new ModuleInfoSnapshotBuilder(new DefaultYangParserFactory());
-        snapshotBuilder.add($YangModuleInfoImpl.getInstance());
+        snapshotBuilder.add(YangModuleInfoImpl.getInstance());
         snapshotBuilder.addModuleFeatures(Mdsal767Data.class, Set.of(One$F.VALUE));
 
         final var snapshot = snapshotBuilder.build();
index 23918c022f62c022b1e5418c21000e5175c0d796..05bd99809e8c5b96b150f03e91ba9f81c3fe7bdf 100644 (file)
@@ -73,8 +73,8 @@ public final class BindingReflections {
      * @return Instance of {@link YangModuleInfo} associated with model, from which this class was derived.
      */
     private static @NonNull YangModuleInfo getModuleInfo(final Class<?> cls) {
-        final String potentialClassName = Naming.getModelRootPackageName(cls.getPackage().getName()) + "."
-            + Naming.MODULE_INFO_CLASS_NAME;
+        final String potentialClassName = Naming.rootToServicePackageName(cls.getPackage().getName())
+            + '.' + Naming.MODULE_INFO_CLASS_NAME;
         final Class<?> moduleInfoClass;
         try {
             moduleInfoClass = cls.getClassLoader().loadClass(potentialClassName);
index e5ddfa28c8e74db372073bc597c9ab05a1d173e7..536e69db7d6eae0ea45badc3daa855bf5af4b7a7 100644 (file)
@@ -74,6 +74,7 @@ public final class Naming {
     // concrete extensible contracts, for example 'feature', 'identity' and similar
     public static final @NonNull String VALUE_STATIC_FIELD_NAME = "VALUE";
     public static final @NonNull String PACKAGE_PREFIX = "org.opendaylight.yang.gen.v1";
+    public static final @NonNull String SVC_PACKAGE_PREFIX = "org.opendaylight.yang.svc.v1";
     public static final @NonNull String AUGMENTATION_FIELD = "augmentation";
 
     private static final Splitter CAMEL_SPLITTER = Splitter.on(CharMatcher.anyOf(" _.-/").precomputed())
@@ -82,10 +83,10 @@ public final class Naming {
     private static final String QUOTED_DOT = Matcher.quoteReplacement(".");
     private static final Splitter DOT_SPLITTER = Splitter.on('.');
 
-    public static final @NonNull String MODULE_INFO_CLASS_NAME = "$YangModuleInfoImpl";
+    public static final @NonNull String MODULE_INFO_CLASS_NAME = "YangModuleInfoImpl";
     public static final @NonNull String MODULE_INFO_QNAMEOF_METHOD_NAME = "qnameOf";
     public static final @NonNull String MODULE_INFO_YANGDATANAMEOF_METHOD_NAME = "yangDataNameOf";
-    public static final @NonNull String MODEL_BINDING_PROVIDER_CLASS_NAME = "$YangModelBindingProvider";
+    public static final @NonNull String MODEL_BINDING_PROVIDER_CLASS_NAME = "YangModelBindingProviderImpl";
 
     /**
      * Name of {@link Augmentable#augmentation(Class)}.
@@ -156,20 +157,35 @@ public final class Naming {
     private static final Interner<String> PACKAGE_INTERNER = Interners.newWeakInterner();
     @Regex
     private static final String ROOT_PACKAGE_PATTERN_STRING =
-            "(org.opendaylight.yang.gen.v1.[a-z0-9_\\.]*?\\.(?:rev[0-9][0-9][0-1][0-9][0-3][0-9]|norev))";
+            "(org.opendaylight.yang.(gen|svc).v1.[a-z0-9_\\.]*?\\.(?:rev[0-9][0-9][0-1][0-9][0-3][0-9]|norev))";
     private static final Pattern ROOT_PACKAGE_PATTERN = Pattern.compile(ROOT_PACKAGE_PATTERN_STRING);
 
     private Naming() {
         // Hidden on purpose
     }
 
+    /**
+     * Return the package name for placing generated ServiceLoader entities, like {@link #MODULE_INFO_CLASS_NAME} and
+     * {@link #MODEL_BINDING_PROVIDER_CLASS_NAME}.
+     *
+     * @param module module namespace
+     * @return the package name for placing generated ServiceLoader entities
+     */
+    public static @NonNull String getServicePackageName(final QNameModule module) {
+        final StringBuilder packageNameBuilder = new StringBuilder().append(SVC_PACKAGE_PREFIX).append('.');
+        return getRootPackageName(packageNameBuilder, module);
+    }
+
     public static @NonNull String getRootPackageName(final QName module) {
         return getRootPackageName(module.getModule());
     }
 
     public static @NonNull String getRootPackageName(final QNameModule module) {
         final StringBuilder packageNameBuilder = new StringBuilder().append(PACKAGE_PREFIX).append('.');
+        return getRootPackageName(packageNameBuilder, module);
+    }
 
+    private static @NonNull String getRootPackageName(final StringBuilder builder, final QNameModule module) {
         String namespace = module.getNamespace().toString();
         namespace = COLON_SLASH_SLASH.matcher(namespace).replaceAll(QUOTED_DOT);
 
@@ -183,9 +199,9 @@ public final class Naming {
             }
         }
 
-        packageNameBuilder.append(chars);
+        builder.append(chars);
         if (chars[chars.length - 1] != '.') {
-            packageNameBuilder.append('.');
+            builder.append('.');
         }
 
         final Optional<Revision> optRev = module.getRevision();
@@ -194,13 +210,27 @@ public final class Naming {
             // right characters.
             final String rev = optRev.orElseThrow().toString();
             checkArgument(rev.length() == 10, "Unsupported revision %s", rev);
-            packageNameBuilder.append("rev").append(rev, 2, 4).append(rev, 5, 7).append(rev.substring(8));
+            builder.append("rev").append(rev, 2, 4).append(rev, 5, 7).append(rev.substring(8));
         } else {
             // No-revision packages are special
-            packageNameBuilder.append("norev");
+            builder.append("norev");
         }
 
-        return normalizePackageName(packageNameBuilder.toString());
+        return normalizePackageName(builder.toString());
+    }
+
+    /**
+     * Convert the result of {@link #getRootPackageName(QNameModule)} to the corresponding result of
+     * {@link #getServicePackageName(QNameModule)}.
+     *
+     * @param rootPackageName root package name
+     * @return Service root package name
+     */
+    public static @NonNull String rootToServicePackageName(final String rootPackageName) {
+        final var match = ROOT_PACKAGE_PATTERN.matcher(rootPackageName);
+        checkArgument(match.find(), "Package name '%s' does not match required pattern '%s'", rootPackageName,
+            ROOT_PACKAGE_PATTERN_STRING);
+        return getModelRootPackageName(rootPackageName.replace(Naming.PACKAGE_PREFIX, Naming.SVC_PACKAGE_PREFIX));
     }
 
     public static @NonNull String normalizePackageName(final String packageName) {
@@ -364,8 +394,8 @@ public final class Naming {
      *                                  not match package name formatting rules
      */
     public static @NonNull String getModelRootPackageName(final String packageName) {
-        checkArgument(packageName.startsWith(PACKAGE_PREFIX), "Package name not starting with %s, is: %s",
-            PACKAGE_PREFIX, packageName);
+        checkArgument(packageName.startsWith(PACKAGE_PREFIX) || packageName.startsWith(SVC_PACKAGE_PREFIX),
+            "Package name not starting with %s, is: %s", PACKAGE_PREFIX, packageName);
         final var match = ROOT_PACKAGE_PATTERN.matcher(packageName);
         checkArgument(match.find(), "Package name '%s' does not match required pattern '%s'", packageName,
             ROOT_PACKAGE_PATTERN_STRING);
index 6182099b024ca9e8b5b85dc694e0ce45a5733324..1c41bee2b5272c0e1f3afc909fba68003c3ed813 100644 (file)
@@ -8,7 +8,7 @@
 package org.opendaylight.mdsal.dom.broker;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.yang.extension.yang.ext.rev130709.$YangModuleInfoImpl;
+import org.opendaylight.yang.svc.v1.urn.opendaylight.yang.extension.yang.ext.rev130709.YangModuleInfoImpl;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
@@ -22,7 +22,7 @@ final class Rpcs {
     static final EffectiveModelContext CONTEXT = YangParserTestUtils.parseYangSources(YangParserConfiguration.DEFAULT,
         null,
         new DelegatedYangTextSource(new SourceIdentifier("yang-ext.yang"),
-            $YangModuleInfoImpl.getInstance().getYangTextCharSource()),
+            YangModuleInfoImpl.getInstance().getYangTextCharSource()),
         new URLYangTextSource(Rpcs.class.getResource("/rpcs.yang")));
 
     static final QName FOO = QName.create("rpcs", "foo");
index 0fd28da92a026b310361a32f024b8414cbb82d3f..19f72f15bcf11a20aec12889f83e35a8a526c166 100644 (file)
@@ -16,7 +16,7 @@ import java.util.stream.Collectors;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.yang.extension.yang.ext.rev130709.$YangModuleInfoImpl;
+import org.opendaylight.yang.svc.v1.urn.opendaylight.yang.extension.yang.ext.rev130709.YangModuleInfoImpl;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
 import org.opendaylight.yangtools.yang.model.api.stmt.RpcEffectiveStatement;
@@ -32,7 +32,7 @@ public class ContentRoutedRpcContextTest {
     public static void beforeClass() {
         final var ctx = YangParserTestUtils.parseYangSources(YangParserConfiguration.DEFAULT, null,
             new DelegatedYangTextSource(new SourceIdentifier("yang-ext.yang"),
-                $YangModuleInfoImpl.getInstance().getYangTextCharSource()),
+                YangModuleInfoImpl.getInstance().getYangTextCharSource()),
             new URLYangTextSource(ContentRoutedRpcContext.class.getResource("/rpc-routing-strategy.yang")));
 
         RPCS = ctx.findModuleStatements("foo").iterator().next()