Going to a JPMS module means our resources are subject to encapsulation
-- which means things like YangTextSchemaSource.forResource() actually
depend on where the resource if located.
If its location ends up being in a valid package, that request will fail,
as JRE will consider the resource encapsulated and will reject external
module's attempt to meddle with it (such as yang.model.api).
As it turns out some of models are matching this check and we load them
through such facilities. In some cases we can re-route in a way which
makes things less verbose -- and we do that in this patch.
JIRA: YANGTOOLS-1151
Change-Id: Ib55cadd9eba840980eeba3b9004d8f9c4101e33d
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
package org.opendaylight.yangtools.yang.stmt;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.io.IOException;
package org.opendaylight.yangtools.yang.stmt;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.io.IOException;
+import java.net.URISyntaxException;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.repo.api.YinTextSchemaSource;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.xml.sax.SAXException;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.xml.sax.SAXException;
* Use input stream to load Yin module.
*/
@Before
* Use input stream to load Yin module.
*/
@Before
- public void initTest() throws ReactorException, SAXException, IOException {
- foo = TestUtils.loadYinModule(YinTextSchemaSource.forResource(getClass(), "/bugs/bug5693/foo.yin"));
+ public void initTest() throws ReactorException, SAXException, IOException, URISyntaxException {
+ foo = StmtTestUtils.parseYinSources("/bugs/bug5693").getModules().iterator().next();
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
+import java.io.IOException;
+import java.net.URISyntaxException;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
+import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
public class ChoiceStmtTest {
public class ChoiceStmtTest {
-
- private static final StatementStreamSource CHOICE_MODULE = sourceForResource("/model/foo.yang");
- private static final StatementStreamSource IMPORTED_MODULE1 = sourceForResource("/model/bar.yang");
- private static final StatementStreamSource IMPORTED_MODULE2 = sourceForResource("/model/baz.yang");
- private static final StatementStreamSource INCLUDED_MODULE = sourceForResource("/model/subfoo.yang");
-
- public void choiceAndCaseTest() throws ReactorException {
- final SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
- .addSources(CHOICE_MODULE, IMPORTED_MODULE1, IMPORTED_MODULE2, INCLUDED_MODULE)
- .buildEffective();
+ public void choiceAndCaseTest() throws ReactorException, YangSyntaxErrorException, URISyntaxException, IOException {
+ final SchemaContext result = StmtTestUtils.parseYangSources("/model");
assertNotNull(result);
final Module testModule = result.findModules("foo").iterator().next();
assertNotNull(result);
final Module testModule = result.findModules("foo").iterator().next();
return reactor.buildEffective();
}
return reactor.buildEffective();
}
+ public static EffectiveModelContext parseYinSources(final String yinSourcesDirectoryPath)
+ throws URISyntaxException, SAXException, IOException, ReactorException {
+ return parseYinSources(yinSourcesDirectoryPath, StatementParserMode.DEFAULT_MODE);
+ }
+
public static EffectiveModelContext parseYinSources(final String yinSourcesDirectoryPath,
final StatementParserMode statementParserMode) throws URISyntaxException, SAXException, IOException,
ReactorException {
public static EffectiveModelContext parseYinSources(final String yinSourcesDirectoryPath,
final StatementParserMode statementParserMode) throws URISyntaxException, SAXException, IOException,
ReactorException {