X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=yang%2Fyang-parser-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fparser%2Frepo%2FSharedSchemaContextFactory.java;h=7b40342003c575eca5692f0f88d4ca6ad827a441;hb=e403e34bcb508c48aa606a1cd81a386fb73c5db6;hp=1594fd4212704836a7207008bfb619f9cafd67b6;hpb=8b74f965b8a7cb7d592c84e87bda32bcefd06162;p=yangtools.git diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/repo/SharedSchemaContextFactory.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/repo/SharedSchemaContextFactory.java index 1594fd4212..7b40342003 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/repo/SharedSchemaContextFactory.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/repo/SharedSchemaContextFactory.java @@ -39,6 +39,7 @@ import org.opendaylight.yangtools.yang.model.repo.api.SchemaContextFactory; import org.opendaylight.yangtools.yang.model.repo.api.SchemaResolutionException; import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceFilter; import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier; +import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode; import org.opendaylight.yangtools.yang.parser.impl.util.YangModelDependencyInfo; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; @@ -60,6 +61,7 @@ final class SharedSchemaContextFactory implements SchemaContextFactory { } }; private final Cache, SchemaContext> cache = CacheBuilder.newBuilder().weakValues().build(); + private final Cache, SchemaContext> semVerCache = CacheBuilder.newBuilder().weakValues().build(); private final SharedSchemaRepository repository; // FIXME: ignored right now private final SchemaSourceFilter filter; @@ -72,7 +74,14 @@ final class SharedSchemaContextFactory implements SchemaContextFactory { @Override public CheckedFuture createSchemaContext( - final Collection requiredSources, java.util.function.Predicate isFeatureSupported) { + final Collection requiredSources, final StatementParserMode statementParserMode, + final java.util.function.Predicate isFeatureSupported) { + return createSchemaContext(requiredSources, + statementParserMode == StatementParserMode.SEMVER_MODE ? this.semVerCache : this.cache, + new AssembleSources(isFeatureSupported, statementParserMode)); + } + + private CheckedFuture createSchemaContext(final Collection requiredSources, final Cache, SchemaContext> cache, final AsyncFunction, SchemaContext> assembleSources) { // Make sources unique final List uniqueSourceIdentifiers = deDuplicateSources(requiredSources); @@ -91,7 +100,6 @@ final class SharedSchemaContextFactory implements SchemaContextFactory { sf = Futures.transform(sf, new SourceIdMismatchDetector(uniqueSourceIdentifiers)); // Assemble sources into a schema context - final AssembleSources assembleSources = new AssembleSources(isFeatureSupported); final ListenableFuture cf = Futures.transform(sf, assembleSources); // Populate cache when successful @@ -166,22 +174,33 @@ final class SharedSchemaContextFactory implements SchemaContextFactory { private static final class AssembleSources implements AsyncFunction, SchemaContext> { private final java.util.function.Predicate isFeatureSupported; + private final StatementParserMode statementParserMode; + private final Function getIdentifier; - private AssembleSources(final java.util.function.Predicate isFeatureSupported) { + private AssembleSources(final java.util.function.Predicate isFeatureSupported, + final StatementParserMode statementParserMode) { this.isFeatureSupported = Preconditions.checkNotNull(isFeatureSupported); + this.statementParserMode = Preconditions.checkNotNull(statementParserMode); + switch (statementParserMode) { + case SEMVER_MODE: + this.getIdentifier = ASTSchemaSource.GET_SEMVER_IDENTIFIER; + break; + default: + this.getIdentifier = ASTSchemaSource.GET_IDENTIFIER; + } } @Override - public ListenableFuture apply(List sources) throws SchemaResolutionException, + public ListenableFuture apply(final List sources) throws SchemaResolutionException, SourceException, ReactorException { - final Map srcs = - Maps.uniqueIndex(sources, ASTSchemaSource.GET_IDENTIFIER); + final Map srcs = Maps.uniqueIndex(sources, getIdentifier); final Map deps = Maps.transformValues(srcs, ASTSchemaSource.GET_DEPINFO); LOG.debug("Resolving dependency reactor {}", deps); - final DependencyResolver res = DependencyResolver.create(deps); + final DependencyResolver res = this.statementParserMode == StatementParserMode.SEMVER_MODE ? SemVerDependencyResolver + .create(deps) : RevisionDependencyResolver.create(deps); if (!res.getUnresolvedSources().isEmpty()) { LOG.debug("Omitting models {} due to unsatisfied imports {}", res.getUnresolvedSources(), res.getUnsatisfiedImports()); throw new SchemaResolutionException("Failed to resolve required models", @@ -190,7 +209,7 @@ final class SharedSchemaContextFactory implements SchemaContextFactory { final Map asts = Maps.transformValues(srcs, ASTSchemaSource.GET_AST); final CrossSourceStatementReactor.BuildAction reactor = - YangInferencePipeline.RFC6020_REACTOR.newBuild(isFeatureSupported); + YangInferencePipeline.RFC6020_REACTOR.newBuild(statementParserMode, isFeatureSupported); for (final Entry e : asts.entrySet()) { final ParserRuleContext parserRuleCtx = e.getValue(); @@ -200,7 +219,7 @@ final class SharedSchemaContextFactory implements SchemaContextFactory { reactor.addSource(new YangStatementSourceImpl(e.getKey(), (StatementContext) parserRuleCtx)); } - SchemaContext schemaContext = reactor.buildEffective(); + final SchemaContext schemaContext = reactor.buildEffective(); return Futures.immediateCheckedFuture(schemaContext); }