use of org.opendaylight.yangtools.concepts.SemVer in project yangtools by opendaylight.
the class YangModelDependencyInfo method parseImports.
private static ImmutableSet<ModuleImport> parseImports(final IRStatement module, final SourceIdentifier source) {
final Set<ModuleImport> result = new HashSet<>();
for (final IRStatement substatement : module.statements()) {
if (isBuiltin(substatement, IMPORT)) {
final String importedModuleName = safeStringArgument(source, substatement, "imported module name");
final String revisionDateStr = getRevisionDateString(substatement, source);
final Revision revisionDate = Revision.ofNullable(revisionDateStr).orElse(null);
final SemVer importSemVer = findSemanticVersion(substatement, source);
result.add(new ModuleImportImpl(importedModuleName, revisionDate, importSemVer));
}
}
return ImmutableSet.copyOf(result);
}
use of org.opendaylight.yangtools.concepts.SemVer 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.concepts.SemVer 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);
}
use of org.opendaylight.yangtools.concepts.SemVer in project yangtools by opendaylight.
the class SemVerDependencyResolver method isCompatible.
private static boolean isCompatible(final Optional<SemVer> moduleSemVer, final Optional<SemVer> importSemVer) {
if (importSemVer.isEmpty()) {
// Import does not care about the version
return true;
}
if (moduleSemVer.isEmpty()) {
// Modules which do not declare a semantic version are incompatible with imports which do
return false;
}
final SemVer modVer = moduleSemVer.get();
final SemVer impVer = importSemVer.get();
return modVer.getMajor() == impVer.getMajor() && modVer.compareTo(impVer) >= 0;
}
Aggregations