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
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;
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();
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()));
}
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
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])
}
«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»
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);
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());
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;
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 {
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);
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);
}
}
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;
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);
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");
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);
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());
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);
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);
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);
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);
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);
// 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());
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",
// 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);
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() {
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;
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);
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);
// 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);
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
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());
}
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();
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());
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;
@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();
* @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);
// 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())
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)}.
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);
}
}
- packageNameBuilder.append(chars);
+ builder.append(chars);
if (chars[chars.length - 1] != '.') {
- packageNameBuilder.append('.');
+ builder.append('.');
}
final Optional<Revision> optRev = module.getRevision();
// 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) {
* 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);
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;
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");
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;
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()