try {
schemaContext = parser.buildEffectiveModel();
} catch (final YangParserException e) {
+ final Throwable cause = e.getCause();
+ if (cause instanceof ReactorException) {
+ throw new SchemaResolutionException("Failed to resolve required models",
+ ((ReactorException) cause).getSourceIdentifier(), e);
+ }
throw new SchemaResolutionException("Failed to resolve required models", e);
}
return SemVerSourceIdentifier.create(identifier.getName(), identifier.getRevision(), semver);
}
-}
\ No newline at end of file
+}
--- /dev/null
+/*
+ * Copyright (c) 2022 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * 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.parser.repo;
+
+import com.google.common.collect.SetMultimap;
+import com.google.common.util.concurrent.ListenableFuture;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.stream.Collectors;
+import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
+import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactoryConfiguration;
+import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.parser.api.YangSyntaxErrorException;
+import org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRSchemaSource;
+import org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToIRTransformer;
+
+public abstract class AbstractSchemaRepositoryTest {
+ static ListenableFuture<EffectiveModelContext> createSchemaContext(
+ final SetMultimap<QNameModule, QNameModule> modulesWithSupportedDeviations, final String... resources) {
+ final var sharedSchemaRepository = new SharedSchemaRepository();
+ final var requiredSources = Arrays.stream(resources)
+ .map(resource -> {
+ final var yangSource = assertYangTextResource(resource);
+ yangSource.register(sharedSchemaRepository);
+ yangSource.setResult();
+ return yangSource.getId();
+ })
+ .collect(Collectors.toUnmodifiableList());
+
+ return sharedSchemaRepository
+ .createEffectiveModelContextFactory(SchemaContextFactoryConfiguration.builder()
+ .setModulesDeviatedByModules(modulesWithSupportedDeviations)
+ .build())
+ .createEffectiveModelContext(requiredSources);
+ }
+
+ private static SettableSchemaProvider<IRSchemaSource> assertYangTextResource(final String resourceName) {
+ final IRSchemaSource yangSource;
+ try {
+ yangSource = TextToIRTransformer.transformText(YangTextSchemaSource.forResource(resourceName));
+ } catch (YangSyntaxErrorException | IOException e) {
+ throw new AssertionError("Failed to parse " + resourceName, e);
+ }
+ return SettableSchemaProvider.createImmediate(yangSource, IRSchemaSource.class);
+ }
+}
import com.google.common.collect.ImmutableSetMultimap;
import com.google.common.collect.SetMultimap;
import com.google.common.util.concurrent.ListenableFuture;
-import java.util.ArrayList;
-import java.util.Collection;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.common.XMLNamespace;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
-import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactoryConfiguration;
-import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
-import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
-import org.opendaylight.yangtools.yang.parser.rfc7950.ir.IRSchemaSource;
-import org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToIRTransformer;
import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
-public class SchemaContextFactoryDeviationsTest {
+public class SchemaContextFactoryDeviationsTest extends AbstractSchemaRepositoryTest {
private static final String FOO = "/bug9195/foo.yang";
private static final String BAR = "/bug9195/bar.yang";
private static final String BAZ = "/bug9195/baz.yang";
private static void assertPresent(final EffectiveModelContext schemaContext, final QName qname) {
assertNotEquals(Optional.empty(), schemaContext.findDataTreeChild(qname));
}
-
- private static SettableSchemaProvider<IRSchemaSource> getImmediateYangSourceProviderFromResource(
- final String resourceName) throws Exception {
- final YangTextSchemaSource yangSource = YangTextSchemaSource.forResource(resourceName);
- return SettableSchemaProvider.createImmediate(TextToIRTransformer.transformText(yangSource),
- IRSchemaSource.class);
- }
-
- private static ListenableFuture<EffectiveModelContext> createSchemaContext(
- final SetMultimap<QNameModule, QNameModule> modulesWithSupportedDeviations, final String... resources)
- throws Exception {
- final SharedSchemaRepository sharedSchemaRepository = new SharedSchemaRepository(
- "shared-schema-repo-with-deviations-test");
-
- final Collection<SourceIdentifier> requiredSources = new ArrayList<>();
- for (final String resource : resources) {
- final SettableSchemaProvider<IRSchemaSource> yangSource = getImmediateYangSourceProviderFromResource(
- resource);
- yangSource.register(sharedSchemaRepository);
- yangSource.setResult();
- requiredSources.add(yangSource.getId());
- }
-
- final SchemaContextFactoryConfiguration config = SchemaContextFactoryConfiguration.builder()
- .setModulesDeviatedByModules(modulesWithSupportedDeviations).build();
- return sharedSchemaRepository.createEffectiveModelContextFactory(config).createEffectiveModelContext(
- requiredSources);
- }
}
--- /dev/null
+/*
+ * Copyright (c) 2022 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * 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.parser.repo;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThrows;
+
+import com.google.common.util.concurrent.Futures;
+import java.util.concurrent.ExecutionException;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
+import org.opendaylight.yangtools.yang.model.repo.api.SchemaResolutionException;
+
+public class YT1428Test extends AbstractSchemaRepositoryTest {
+ @Test
+ public void testDeviateSourceReported() throws Exception {
+ final var future = createSchemaContext(null, "/yt1428/orig.yang", "/yt1428/deviate.yang");
+ final var cause = assertThrows(ExecutionException.class, () -> Futures.getDone(future)).getCause();
+ assertThat(cause, instanceOf(SchemaResolutionException.class));
+ assertEquals(RevisionSourceIdentifier.create("deviate"), ((SchemaResolutionException) cause).getFailedSource());
+ }
+}
--- /dev/null
+module deviate {
+ namespace "urn:deviate";
+ prefix dev;
+
+ import orig {
+ prefix orig;
+ }
+
+ deviation "/orig:foo/orig:bar/orig:baz" {
+ deviate not-supported;
+ }
+}
--- /dev/null
+module orig {
+ namespace "urn:orig";
+ prefix orig;
+
+ container foo {
+ leaf bar {
+ type string;
+ }
+ }
+}