final Set<SourceSpecificContext> requiredLibs = new HashSet<>();
for (final SourceSpecificContext source : sources) {
collectRequiredSourcesFromLib(libSourcesTable, requiredLibs, source);
+ removeConflictingLibSources(source, requiredLibs);
}
return requiredLibs;
}
return sourceMap != null && !sourceMap.isEmpty() ? sourceMap.get(sourceMap.lastKey()) : null;
}
+ // removes required library sources which would cause namespace/name conflict with one of the main sources
+ // later in the parsing process. this can happen if we add a parent module or a submodule as a main source
+ // and the same parent module or submodule is added as one of the library sources.
+ // such situation may occur when using the yang-system-test artifact - if a parent module/submodule is specified
+ // as its argument and the same dir is specified as one of the library dirs through -p option).
+ private static void removeConflictingLibSources(final SourceSpecificContext source,
+ final Set<SourceSpecificContext> requiredLibs) {
+ final Iterator<SourceSpecificContext> requiredLibsIter = requiredLibs.iterator();
+ while (requiredLibsIter.hasNext()) {
+ final SourceSpecificContext currentReqSource = requiredLibsIter.next();
+ if (source.getRootIdentifier().equals(currentReqSource.getRootIdentifier())) {
+ requiredLibsIter.remove();
+ }
+ }
+ }
+
private void endPhase(final ModelProcessingPhase phase) {
Preconditions.checkState(currentPhase == phase);
finishedPhase = currentPhase;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
+import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
public class Bug7480Test {
@Test
assertTrue(message.startsWith("Imported module [missing-lib] was not found."));
}
}
+
+ @Test
+ public void testHandlingOfMainSourceConflictingWithLibSource() throws Exception {
+ // parent module as main source and as lib source at the same time
+ // parser should remove it from the required lib sources and thus avoid module namespace collision
+ final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ reactor.addSource(StmtTestUtils.sourceForResource(
+ "/bugs/bug7480/main-source-lib-source-conflict-test/parent-module.yang"));
+ reactor.addLibSources(StmtTestUtils.sourceForResource(
+ "/bugs/bug7480/main-source-lib-source-conflict-test/child-module.yang"),
+ StmtTestUtils.sourceForResource(
+ "/bugs/bug7480/main-source-lib-source-conflict-test/parent-module.yang"));
+ final SchemaContext schemaContext = reactor.buildEffective();
+ assertNotNull(schemaContext);
+ }
+
+ @Test
+ public void testHandlingOfMainSourceConflictingWithLibSource2() throws Exception {
+ // submodule as main source and as lib source at the same time
+ // parser should remove it from the required lib sources and thus avoid submodule name collision
+ final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
+ reactor.addSource(StmtTestUtils.sourceForResource(
+ "/bugs/bug7480/main-source-lib-source-conflict-test/child-module.yang"));
+ reactor.addLibSources(StmtTestUtils.sourceForResource(
+ "/bugs/bug7480/main-source-lib-source-conflict-test/parent-module.yang"),
+ StmtTestUtils.sourceForResource(
+ "/bugs/bug7480/main-source-lib-source-conflict-test/child-module.yang"));
+ final SchemaContext schemaContext = reactor.buildEffective();
+ assertNotNull(schemaContext);
+ }
}