use of org.opendaylight.yangtools.yang.model.repo.api.SemVerSourceIdentifier in project yangtools by opendaylight.
the class SemanticVersionImport method onLinkageDeclared.
static void onLinkageDeclared(final Mutable<String, ImportStatement, ImportEffectiveStatement> stmt) {
final ModelActionBuilder importAction = stmt.newInferenceAction(SOURCE_LINKAGE);
final String moduleName = stmt.getArgument();
final SemVer semanticVersion = stmt.getFromNamespace(SemanticVersionNamespace.class, stmt);
final SemanticVersionImport.CompatibleCriterion criterion = semanticVersion == null ? new NoVerCompatibleCriterion(moduleName) : new SemVerCompatibleCriterion(moduleName, semanticVersion);
final Prerequisite<StmtContext<?, ?, ?>> imported = importAction.requiresCtx(stmt, SemanticVersionModuleNamespace.class, criterion, SOURCE_LINKAGE);
final Prerequisite<Mutable<?, ?, ?>> linkageTarget = importAction.mutatesCtx(stmt.getRoot(), SOURCE_LINKAGE);
importAction.apply(new InferenceAction() {
@Override
public void apply(final InferenceContext ctx) {
final StmtContext<?, ?, ?> importedModule = imported.resolve(ctx);
final SemVer importedVersion = stmt.getFromNamespace(SemanticVersionNamespace.class, stmt);
final SourceIdentifier importedModuleIdentifier = importedModule.getFromNamespace(ModuleCtxToSourceIdentifier.class, importedModule);
final SemVerSourceIdentifier semVerModuleIdentifier = createSemVerModuleIdentifier(importedModuleIdentifier, importedVersion);
stmt.addToNs(ImportedVersionNamespace.class, Empty.value(), semVerModuleIdentifier);
linkageTarget.resolve(ctx).addToNs(ImportedModuleContext.class, importedModuleIdentifier, importedModule);
final String impPrefix = firstAttributeOf(stmt.declaredSubstatements(), PrefixStatement.class);
stmt.addToNs(ImportPrefixToModuleCtx.class, impPrefix, importedModule);
stmt.addToNs(ImportPrefixToSemVerSourceIdentifier.class, impPrefix, semVerModuleIdentifier);
final QNameModule mod = InferenceException.throwIfNull(stmt.getFromNamespace(ModuleCtxToModuleQName.class, importedModule), stmt, "Failed to find module of %s", importedModule);
stmt.addToNs(ModuleQNameToPrefix.class, mod, impPrefix);
}
@Override
public void prerequisiteFailed(final Collection<? extends Prerequisite<?>> failed) {
if (failed.contains(imported)) {
throw new InferenceException(stmt, "Unable to find module compatible with requested import [%s(%s)].", moduleName, getRequestedImportVersionString(stmt));
}
}
});
}
use of org.opendaylight.yangtools.yang.model.repo.api.SemVerSourceIdentifier in project yangtools by opendaylight.
the class ModuleStatementSupport method addToSemVerModuleNamespace.
private static void addToSemVerModuleNamespace(final Mutable<Unqualified, ModuleStatement, ModuleEffectiveStatement> stmt, final SourceIdentifier moduleIdentifier) {
final SemVerSourceIdentifier id = SemVerSourceIdentifier.create(stmt.getRawArgument(), stmt.getFromNamespace(SemanticVersionNamespace.class, stmt));
stmt.addToNs(SemanticVersionModuleNamespace.class, id, stmt);
}
use of org.opendaylight.yangtools.yang.model.repo.api.SemVerSourceIdentifier in project yangtools by opendaylight.
the class AssembleSources method getSemVerIdentifier.
private static SemVerSourceIdentifier getSemVerIdentifier(final IRSchemaSource source) {
final SourceIdentifier identifier = source.getIdentifier();
final SemVer semver = YangModelDependencyInfo.findSemanticVersion(source.getRootStatement(), identifier);
if (identifier instanceof SemVerSourceIdentifier && semver == null) {
return (SemVerSourceIdentifier) identifier;
}
return SemVerSourceIdentifier.create(identifier.getName(), identifier.getRevision(), semver);
}
Aggregations