From: Peter Kajsa Date: Wed, 30 Mar 2016 11:27:34 +0000 (+0200) Subject: Bug 4662: Introduce a SemanticVersion concept - import processing X-Git-Tag: release/boron~123 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=4968d735af48cd6b0ea91b37fbd238316c7cb46c;hp=82af449e4ef07d80490e79484d0402b81009541e;p=yangtools.git Bug 4662: Introduce a SemanticVersion concept - import processing Added new semantic version processing mode to yang statement parser. If the mode is enabled, each module import is processed based on the specified semantic version and revision date of import statement is ignored. - fix of SemVer's compareTo method - fix of Yin statements argument parsing - added Yang unit tests - added Yin unit tests - fix of module imports resolving and module dependency sort for cases when semantic versioning is enabled - added StatementParserMode - unit test fix Change-Id: Ibf0519c3ec8fec85763e0a13059c1b8af91276ba Signed-off-by: Peter Kajsa --- diff --git a/common/concepts/src/main/java/org/opendaylight/yangtools/concepts/SemVer.java b/common/concepts/src/main/java/org/opendaylight/yangtools/concepts/SemVer.java index 65d55f2776..d7520d47c9 100644 --- a/common/concepts/src/main/java/org/opendaylight/yangtools/concepts/SemVer.java +++ b/common/concepts/src/main/java/org/opendaylight/yangtools/concepts/SemVer.java @@ -89,7 +89,7 @@ public final class SemVer implements Comparable, Serializable { if (i == 0) { i = Integer.compare(minor, o.minor); if (i == 0) { - return Integer.compare(patch, patch); + return Integer.compare(patch, o.patch); } } diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/Module.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/Module.java index 8af290e522..9e0311a5ff 100644 --- a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/Module.java +++ b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/Module.java @@ -11,6 +11,7 @@ import java.util.List; import java.util.Set; import javax.annotation.Nullable; import javax.annotation.concurrent.Immutable; +import org.opendaylight.yangtools.concepts.SemVer; /** * This interface contains the methods for getting the data from the YANG @@ -58,6 +59,11 @@ import javax.annotation.concurrent.Immutable; */ @Immutable public interface Module extends DataNodeContainer, SourceStreamAware, ModuleIdentifier { + /** + * Default semantic version of Module. + */ + SemVer DEFAULT_SEMANTIC_VERSION = SemVer.create(0, 0, 0); + /** * Returns the prefix of the module * diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/ModuleIdentifier.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/ModuleIdentifier.java index 8858b51d61..0ca6e4d25c 100644 --- a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/ModuleIdentifier.java +++ b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/ModuleIdentifier.java @@ -10,7 +10,7 @@ package org.opendaylight.yangtools.yang.model.api; import java.net.URI; import java.util.Date; - +import org.opendaylight.yangtools.concepts.SemVer; import org.opendaylight.yangtools.yang.common.QNameModule; @@ -50,4 +50,19 @@ public interface ModuleIdentifier { * keyword */ Date getRevision(); + + /** + * Returns the semantic version of yang module. + * + * If the semantic version is not specified, default semantic version of + * module is returned. + * + * @return SemVer semantic version of yang module which is specified as + * argument of + * (urn:opendaylight:yang:extension:semantic-version?revision + * =2016-02-02)semantic-version statement + */ + default SemVer getSemanticVersion() { + return Module.DEFAULT_SEMANTIC_VERSION; + } } diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/ModuleImport.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/ModuleImport.java index 28d934fc07..0ef81046e3 100644 --- a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/ModuleImport.java +++ b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/ModuleImport.java @@ -8,6 +8,7 @@ package org.opendaylight.yangtools.yang.model.api; import java.util.Date; +import org.opendaylight.yangtools.concepts.SemVer; /** * Interface describing YANG 'import' statement. @@ -28,6 +29,13 @@ public interface ModuleImport { */ Date getRevision(); + /** + * @return Semantic version of module to import + */ + default SemVer getSemanticVersion() { + return Module.DEFAULT_SEMANTIC_VERSION; + } + /** * @return Prefix used to point to imported module */ diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/Rfc6020Mapping.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/Rfc6020Mapping.java index d791ab960e..7371fbae2f 100644 --- a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/Rfc6020Mapping.java +++ b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/Rfc6020Mapping.java @@ -11,7 +11,6 @@ import com.google.common.annotations.Beta; import com.google.common.base.Preconditions; import javax.annotation.Nonnull; import javax.annotation.Nullable; - import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.common.YangConstants; import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement; @@ -210,6 +209,7 @@ public enum Rfc6020Mapping implements StatementDefinition { return effectiveType; } + @Override public boolean isArgumentYinElement() { return yinElement; } diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/meta/StatementDefinition.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/meta/StatementDefinition.java index cfb8488848..ac2293d165 100644 --- a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/meta/StatementDefinition.java +++ b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/meta/StatementDefinition.java @@ -13,13 +13,12 @@ import org.opendaylight.yangtools.concepts.Immutable; import org.opendaylight.yangtools.yang.common.QName; /** - * Definition / model of YANG {@link DeclaredStatement} and {@link EffectiveStatement}. + * Definition / model of YANG {@link DeclaredStatement} and + * {@link EffectiveStatement}. * - * Statement concept is defined in RFC6020 section 6.3: - *
A YANG + * Statement concept is defined in RFC6020 section 6.3:
A YANG * module contains a sequence of statements. Each statement starts with a - * keyword, followed by zero or one argument - *
+ * keyword, followed by zero or one argument
* * Source: */ @@ -64,5 +63,16 @@ public interface StatementDefinition extends Immutable { * with this definition */ @Nonnull - Class> getEffectiveRepresentationClass(); + Class> getEffectiveRepresentationClass(); + + /** + * Returns true, if argument of statement is represented as value of yin + * element. If argument of statement is represented as argument of yin + * element, returns false. + * + * + * @return returns true, if statement argument is represented as value of + * yin element, otherwise returns false. + */ + boolean isArgumentYinElement(); } diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/StatementParserMode.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/StatementParserMode.java new file mode 100644 index 0000000000..e2e71a278d --- /dev/null +++ b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/repo/api/StatementParserMode.java @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2016 Cisco Systems, Inc. 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.model.repo.api; + +import com.google.common.annotations.Beta; + +@Beta +public enum StatementParserMode { + /** + * Default mode of statement parser. + */ + DEFAULT_MODE, + /** + * Semantic version mode of statement parser. If it is enabled, module + * imports are processed on the basis of semantic versions. + */ + SEMVER_MODE +} \ No newline at end of file diff --git a/yang/yang-model-export/src/main/java/org/opendaylight/yangtools/yang/model/export/ExtensionStatement.java b/yang/yang-model-export/src/main/java/org/opendaylight/yangtools/yang/model/export/ExtensionStatement.java index eeb6137e25..291c56bf09 100644 --- a/yang/yang-model-export/src/main/java/org/opendaylight/yangtools/yang/model/export/ExtensionStatement.java +++ b/yang/yang-model-export/src/main/java/org/opendaylight/yangtools/yang/model/export/ExtensionStatement.java @@ -51,6 +51,7 @@ final class ExtensionStatement implements StatementDefinition { return statementName; } + @Override public boolean isArgumentYinElement() { return yinElement; } diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/ModuleImportImpl.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/ModuleImportImpl.java index 376511663e..f6ec3488bb 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/ModuleImportImpl.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/ModuleImportImpl.java @@ -7,19 +7,28 @@ */ package org.opendaylight.yangtools.yang.model.util; +import com.google.common.base.Preconditions; import java.util.Date; import java.util.Objects; +import org.opendaylight.yangtools.concepts.SemVer; +import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.ModuleImport; public final class ModuleImportImpl implements ModuleImport { private final String moduleName; private final Date revision; + private final SemVer semVer; private final String prefix; public ModuleImportImpl(final String moduleName, final Date revision, final String prefix) { - this.moduleName = moduleName; + this(moduleName, revision, prefix, Module.DEFAULT_SEMANTIC_VERSION); + } + + public ModuleImportImpl(final String moduleName, final Date revision, final String prefix, final SemVer semVer) { + this.moduleName = Preconditions.checkNotNull(moduleName, "Module name must not be null."); this.revision = revision; - this.prefix = prefix; + this.prefix = Preconditions.checkNotNull(prefix, "Import prefix must not be null."); + this.semVer = Preconditions.checkNotNull(semVer, "Semantic version of module must not be null."); } @Override @@ -32,6 +41,11 @@ public final class ModuleImportImpl implements ModuleImport { return revision; } + @Override + public SemVer getSemanticVersion() { + return semVer; + } + @Override public String getPrefix() { return prefix; @@ -44,6 +58,7 @@ public final class ModuleImportImpl implements ModuleImport { result = prime * result + Objects.hashCode(moduleName); result = prime * result + Objects.hashCode(revision); result = prime * result + Objects.hashCode(prefix); + result = prime * result + Objects.hashCode(semVer); return result; } @@ -68,6 +83,9 @@ public final class ModuleImportImpl implements ModuleImport { if (!Objects.equals(getPrefix(), other.getPrefix())) { return false; } + if (!Objects.equals(getSemanticVersion(), other.getSemanticVersion())) { + return false; + } return true; } diff --git a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/ModuleImportImplTest.java b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/ModuleImportImplTest.java index 62f127ef5f..21a6cd0a9e 100644 --- a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/ModuleImportImplTest.java +++ b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/ModuleImportImplTest.java @@ -7,13 +7,14 @@ */ package org.opendaylight.yangtools.yang.model.util; -import static org.junit.Assert.*; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import java.util.Date; - -import org.opendaylight.yangtools.yang.model.api.ModuleImport; import org.junit.Before; import org.junit.Test; +import org.opendaylight.yangtools.yang.model.api.ModuleImport; public class ModuleImportImplTest { @@ -25,9 +26,9 @@ public class ModuleImportImplTest { public void setup() { now = new Date(); module1 = new ModuleImportImpl("myModule", now, "myPrefix"); - module2 = new ModuleImportImpl(null, null, null); + module2 = new ModuleImportImpl("foo", null, "prefix-foo"); module3 = new ModuleImportImpl("myModule", null, "customPrefix"); - module4 = new ModuleImportImpl("myModule", now, null); + module4 = new ModuleImportImpl("myModule", now, "prefix"); module5 = new ModuleImportImpl("myModule", now, "myPrefix"); hash1 = module1.hashCode(); hash2 = module2.hashCode(); diff --git a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/SchemaContextProxyTest.java b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/SchemaContextProxyTest.java index c4f7f1acb4..59bbfd93c6 100644 --- a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/SchemaContextProxyTest.java +++ b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/SchemaContextProxyTest.java @@ -12,6 +12,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; + import com.google.common.collect.Sets; import java.net.URI; import java.net.URISyntaxException; @@ -22,6 +23,7 @@ import java.util.HashSet; import java.util.Set; import org.junit.BeforeClass; import org.junit.Test; +import org.opendaylight.yangtools.concepts.SemVer; import org.opendaylight.yangtools.yang.common.QNameModule; import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil; import org.opendaylight.yangtools.yang.model.api.Module; @@ -498,6 +500,11 @@ public class SchemaContextProxyTest { return module.getName(); } + @Override + public SemVer getSemanticVersion() { + return module.getSemanticVersion(); + } + @Override public String toString() { diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/ModuleIdentifierImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/ModuleIdentifierImpl.java index 63608b3e7a..dd42fec14e 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/ModuleIdentifierImpl.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/ModuleIdentifierImpl.java @@ -8,10 +8,14 @@ package org.opendaylight.yangtools.yang.parser.builder.impl; import static com.google.common.base.Preconditions.checkNotNull; + import com.google.common.base.Optional; import java.net.URI; import java.util.Date; +import java.util.Objects; +import org.opendaylight.yangtools.concepts.SemVer; import org.opendaylight.yangtools.yang.common.QNameModule; +import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier; /** @@ -19,16 +23,23 @@ import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier; * Name is only non-null attribute. * Equality check on namespace and revision is only triggered if they are non-null * - * @deprecated Pre-Beryllium implementation, scheduled for removal. */ -@Deprecated + +// FIXME: This class is used widely by yang statement parser. This class should be moved to one of yang statement +// parser packages after removal of deprecated pre-beryllium implementation. public class ModuleIdentifierImpl implements ModuleIdentifier { private final QNameModule qnameModule; private final String name; + private final SemVer semVer; public ModuleIdentifierImpl(final String name, final Optional namespace, final Optional revision) { + this(name, namespace, revision, Module.DEFAULT_SEMANTIC_VERSION); + } + + public ModuleIdentifierImpl(final String name, final Optional namespace, final Optional revision, final SemVer semVer) { this.name = checkNotNull(name); this.qnameModule = QNameModule.create(namespace.orNull(), revision.orNull()); + this.semVer = (semVer == null ? Module.DEFAULT_SEMANTIC_VERSION : semVer); } @Override @@ -41,6 +52,11 @@ public class ModuleIdentifierImpl implements ModuleIdentifier { return qnameModule.getRevision(); } + @Override + public SemVer getSemanticVersion() { + return semVer; + } + @Override public String getName() { return name; @@ -57,6 +73,7 @@ public class ModuleIdentifierImpl implements ModuleIdentifier { "name='" + name + '\'' + ", namespace=" + getNamespace() + ", revision=" + qnameModule.getFormattedRevision() + + ", semantic version=" + semVer + '}'; } @@ -69,18 +86,22 @@ public class ModuleIdentifierImpl implements ModuleIdentifier { return false; } - ModuleIdentifier that = (ModuleIdentifier) o; + ModuleIdentifier other = (ModuleIdentifier) o; - if (!name.equals(that.getName())) { + if (!name.equals(other.getName())) { return false; } // only fail if this namespace is non-null - if (getNamespace() != null && !getNamespace().equals(that.getNamespace())) { + if (getNamespace() != null && !getNamespace().equals(other.getNamespace())) { return false; } // only fail if this revision is non-null - if (getRevision() != null && !getRevision().equals(that.getRevision())) { + if (getRevision() != null && !getRevision().equals(other.getRevision())) { + return false; + } + + if (!Objects.equals(getSemanticVersion(), other.getSemanticVersion())) { return false; } diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/ModuleImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/ModuleImpl.java index e6abb121b3..7b5255d2bb 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/ModuleImpl.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/ModuleImpl.java @@ -9,6 +9,7 @@ package org.opendaylight.yangtools.yang.parser.builder.impl; import static com.google.common.base.Preconditions.checkNotNull; + import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import java.net.URI; @@ -20,6 +21,7 @@ import java.util.Objects; import java.util.Set; import java.util.TreeSet; import org.opendaylight.yangtools.concepts.Immutable; +import org.opendaylight.yangtools.concepts.SemVer; import org.opendaylight.yangtools.yang.common.QNameModule; import org.opendaylight.yangtools.yang.model.api.AugmentationSchema; import org.opendaylight.yangtools.yang.model.api.Deviation; @@ -253,4 +255,9 @@ public final class ModuleImpl extends AbstractDocumentedDataNodeContainer implem public QNameModule getQNameModule() { return qnameModule; } + + @Override + public SemVer getSemanticVersion() { + return DEFAULT_SEMANTIC_VERSION; + } } diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/YinStatementParserImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/YinStatementParserImpl.java index 5128185a22..d2631f6474 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/YinStatementParserImpl.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/YinStatementParserImpl.java @@ -53,7 +53,7 @@ public class YinStatementParserImpl { /** * - * This method is supposed to be called in linkage phase, when YinStatementParserImpl instance has already been + * This method is supposed to be called in pre-linkage phase, when YinStatementParserImpl instance has already been * created. * When done, start walking through YIN source * @@ -67,7 +67,7 @@ public class YinStatementParserImpl { } /** - * This method is supposed to be called in any phase but linkage, when YinStatementParserImpl instance has already + * This method is supposed to be called in any phase but pre-linkage, when YinStatementParserImpl instance has already * been created. * When done, start walking through YIN source * @@ -226,28 +226,34 @@ public class YinStatementParserImpl { } } - private static boolean isStatementWithArgument(final QName identifier, final QNameToStatementDefinition stmtDef) { - if (stmtDef != null && stmtDef.get(Utils.trimPrefix(identifier)) == null) { + private boolean isStatementWithArgument(final QName identifier, final QNameToStatementDefinition stmtDef) { + StatementDefinition statementDefinition = getStatementDefinition(identifier, stmtDef); + if (statementDefinition == null) { return false; - } else if (((StatementSupport) stmtDef.get(Utils.trimPrefix(identifier))).getPublicView().getArgumentName() == null) { + } else if (((StatementSupport) statementDefinition).getPublicView().getArgumentName() == null) { return false; } return true; } - private static boolean isStatementWithYinElement(final QName identifier, final QNameToStatementDefinition stmtDef) { - final StatementDefinition statementDefinition = stmtDef.get(Utils.trimPrefix(identifier)); + private boolean isStatementWithYinElement(final QName identifier, final QNameToStatementDefinition stmtDef) { + StatementDefinition statementDefinition = getStatementDefinition(identifier, stmtDef); if (statementDefinition == null) { return false; } - - return ((Rfc6020Mapping) ((StatementSupport) statementDefinition).getPublicView()).isArgumentYinElement(); + return statementDefinition.isArgumentYinElement(); } - private static String getAttributeValue(final XMLStreamReader inputReader, final QName identifier, final QNameToStatementDefinition + private String getAttributeValue(final XMLStreamReader inputReader, final QName identifier, final QNameToStatementDefinition stmtDef) { String namespace = null; - return inputReader.getAttributeValue(namespace, (((StatementSupport) stmtDef.get(Utils.trimPrefix(identifier))) + return inputReader.getAttributeValue(namespace, (((StatementSupport) getStatementDefinition(identifier, stmtDef)) .getPublicView()).getArgumentName().getLocalName()); } + + private StatementDefinition getStatementDefinition(final QName identifier, final QNameToStatementDefinition stmtDef) { + final QName trimPrefixIdentifier = Utils.trimPrefix(identifier); + return stmtDef.getByNamespaceAndLocalName(trimPrefixIdentifier.getNamespace(), + trimPrefixIdentifier.getLocalName()); + } } \ No newline at end of file diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/util/YangModelDependencyInfo.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/util/YangModelDependencyInfo.java index cbe259f1fd..e7125bf4ad 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/util/YangModelDependencyInfo.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/util/YangModelDependencyInfo.java @@ -9,21 +9,15 @@ package org.opendaylight.yangtools.yang.parser.impl.util; import static org.opendaylight.yangtools.yang.parser.impl.ParserListenerUtils.getArgumentString; -import org.opendaylight.yangtools.yang.parser.impl.ParserListenerUtils; - import com.google.common.base.Optional; -import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils; -import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl; -import java.util.HashSet; -import java.util.Set; -import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping; -import org.opendaylight.yangtools.antlrv4.code.gen.YangStatementParser.StatementContext; -import org.opendaylight.yangtools.antlrv4.code.gen.YangStatementParser; +import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableSet; import java.io.InputStream; import java.util.Date; +import java.util.HashSet; import java.util.List; import java.util.Objects; +import java.util.Set; import org.antlr.v4.runtime.ParserRuleContext; import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Belongs_to_stmtContext; import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Import_stmtContext; @@ -33,9 +27,17 @@ import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Revision_date_stmt import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Revision_stmtContext; import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Revision_stmtsContext; import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Submodule_stmtContext; +import org.opendaylight.yangtools.antlrv4.code.gen.YangStatementParser; +import org.opendaylight.yangtools.antlrv4.code.gen.YangStatementParser.StatementContext; +import org.opendaylight.yangtools.concepts.SemVer; import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.ModuleImport; +import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping; import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException; +import org.opendaylight.yangtools.yang.parser.impl.ParserListenerUtils; +import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.Utils; +import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl; /** * Helper transfer object which holds basic and dependency information for YANG @@ -484,11 +486,17 @@ public abstract class YangModelDependencyInfo { private static final class ModuleImportImpl implements ModuleImport { private final Date revision; + private final SemVer semVer; private final String name; public ModuleImportImpl(final String moduleName, final Date revision) { - this.name = moduleName; + this(moduleName, revision, Module.DEFAULT_SEMANTIC_VERSION); + } + + public ModuleImportImpl(final String moduleName, final Date revision, final SemVer semVer) { + this.name = Preconditions.checkNotNull(moduleName, "Module name must not be null."); this.revision = revision; + this.semVer = Preconditions.checkNotNull(semVer, "Semantic version of module must not be null."); } @Override @@ -501,6 +509,11 @@ public abstract class YangModelDependencyInfo { return this.revision; } + @Override + public SemVer getSemanticVersion() { + return this.semVer; + } + @Override public String getPrefix() { return null; @@ -512,6 +525,7 @@ public abstract class YangModelDependencyInfo { int result = 1; result = prime * result + Objects.hashCode(name); result = prime * result + Objects.hashCode(revision); + result = prime * result + Objects.hashCode(semVer); return result; } @@ -541,6 +555,10 @@ public abstract class YangModelDependencyInfo { } else if (!revision.equals(other.revision)) { return false; } + + if (!Objects.equals(getSemanticVersion(), other.getSemanticVersion())) { + return false; + } return true; } diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/repo/DependencyResolver.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/repo/DependencyResolver.java index f2180a3b2e..d24e8ae116 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/repo/DependencyResolver.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/repo/DependencyResolver.java @@ -22,6 +22,7 @@ import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import org.opendaylight.yangtools.concepts.SemVer; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.model.api.ModuleImport; import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier; @@ -208,6 +209,11 @@ final class DependencyResolver { return null; } + @Override + public SemVer getSemanticVersion() { + return null; + } + @Override public String toString() { return MoreObjects.toStringHelper(this) diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/AbstractStatementSupport.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/AbstractStatementSupport.java index ffc1249a75..ab974ea255 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/AbstractStatementSupport.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/AbstractStatementSupport.java @@ -127,4 +127,8 @@ public abstract class AbstractStatementSupport // NOOP for most implementations } + @Override + public boolean isArgumentYinElement() { + return getPublicView().isArgumentYinElement(); + } } diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/SemanticVersionModuleNamespace.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/SemanticVersionModuleNamespace.java new file mode 100644 index 0000000000..4f5f83eef9 --- /dev/null +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/SemanticVersionModuleNamespace.java @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2016 Cisco Systems, Inc. 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.spi.meta; + +import com.google.common.annotations.Beta; +import java.util.NavigableMap; +import org.opendaylight.yangtools.concepts.SemVer; +import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace; + +/** + * Namespace class for storing Maps of all modules with the same name. This namespace is + * used only in case the semantic versioning is enabled, otherwise it is empty. + */ +@Beta +public interface SemanticVersionModuleNamespace extends IdentifierNamespace>> { +} diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/SemanticVersionNamespace.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/SemanticVersionNamespace.java new file mode 100644 index 0000000000..40a7dbba5b --- /dev/null +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/SemanticVersionNamespace.java @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2016 Cisco Systems, Inc. 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.spi.meta; + +import com.google.common.annotations.Beta; +import org.opendaylight.yangtools.concepts.SemVer; +import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace; + +/** + * namespace class for storing semantic version of yang modules + */ +@Beta +public interface SemanticVersionNamespace extends IdentifierNamespace, SemVer> { +} diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContext.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContext.java index 78d1ef4420..de95986d47 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContext.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContext.java @@ -54,6 +54,8 @@ public interface StmtContext, E extends Effect boolean isConfiguration(); + boolean isEnabledSemanticVersioning(); + @Nonnull > V getFromNamespace( Class type, KT key) throws NamespaceNotAvailableException; diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/ImpPrefixToModuleIdentifier.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/ImpPrefixToModuleIdentifier.java index a60e7dfb94..843ed6adc5 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/ImpPrefixToModuleIdentifier.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/ImpPrefixToModuleIdentifier.java @@ -8,15 +8,12 @@ package org.opendaylight.yangtools.yang.parser.spi.source; import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier; - import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace; /** * - * Source-specific mapping of prefixes to namespaces + * Source-specific mapping of prefixes to module identifiers * */ public interface ImpPrefixToModuleIdentifier extends IdentifierNamespace { - - } diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/ImpPrefixToSemVerModuleIdentifier.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/ImpPrefixToSemVerModuleIdentifier.java new file mode 100644 index 0000000000..d167832ea8 --- /dev/null +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/ImpPrefixToSemVerModuleIdentifier.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2016 Cisco Systems, Inc. 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.spi.source; + +import com.google.common.annotations.Beta; +import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier; +import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace; + +/** + * + * Source-specific mapping of prefixes to module identifier with specified semantic version + */ +@Beta +public interface ImpPrefixToSemVerModuleIdentifier extends IdentifierNamespace { +} diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/ModuleCtxToModuleIdentifier.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/ModuleCtxToModuleIdentifier.java new file mode 100644 index 0000000000..29e2d9a210 --- /dev/null +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/ModuleCtxToModuleIdentifier.java @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. 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.spi.source; + +import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier; +import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace; +import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext; + +/** + * + * Global mapping of modules to module identifier + * + */ +public interface ModuleCtxToModuleIdentifier extends IdentifierNamespace, ModuleIdentifier> { + +} diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/ModuleCtxToModuleQName.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/ModuleCtxToModuleQName.java index 2487afd3cb..5e118b3de4 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/ModuleCtxToModuleQName.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/ModuleCtxToModuleQName.java @@ -7,14 +7,13 @@ */ package org.opendaylight.yangtools.yang.parser.spi.source; -import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext; - import org.opendaylight.yangtools.yang.common.QNameModule; import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace; +import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext; /** * - * Source-specific mapping of prefixes to namespaces + * Global mapping of modules to QNameModules * */ public interface ModuleCtxToModuleQName extends IdentifierNamespace, QNameModule> { diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/BuildGlobalContext.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/BuildGlobalContext.java index a4c0b4446b..9752834623 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/BuildGlobalContext.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/BuildGlobalContext.java @@ -28,6 +28,7 @@ import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement; import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement; import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace; +import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode; import org.opendaylight.yangtools.yang.parser.spi.meta.DerivedNamespaceBehaviour; import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase; import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour; @@ -52,42 +53,51 @@ import org.slf4j.LoggerFactory; class BuildGlobalContext extends NamespaceStorageSupport implements NamespaceBehaviour.Registry { private static final Logger LOG = LoggerFactory.getLogger(BuildGlobalContext.class); - private static final List PHASE_EXECUTION_ORDER = ImmutableList.builder() - .add(ModelProcessingPhase.SOURCE_PRE_LINKAGE) - .add(ModelProcessingPhase.SOURCE_LINKAGE) - .add(ModelProcessingPhase.STATEMENT_DEFINITION) - .add(ModelProcessingPhase.FULL_DECLARATION) - .add(ModelProcessingPhase.EFFECTIVE_MODEL) - .build(); + private static final List PHASE_EXECUTION_ORDER = ImmutableList + . builder().add(ModelProcessingPhase.SOURCE_PRE_LINKAGE) + .add(ModelProcessingPhase.SOURCE_LINKAGE).add(ModelProcessingPhase.STATEMENT_DEFINITION) + .add(ModelProcessingPhase.FULL_DECLARATION).add(ModelProcessingPhase.EFFECTIVE_MODEL).build(); - private final Map> definitions = new HashMap<>(); - private final Map,NamespaceBehaviourWithListeners> supportedNamespaces = new HashMap<>(); + private final Map> definitions = new HashMap<>(); + private final Map, NamespaceBehaviourWithListeners> supportedNamespaces = new HashMap<>(); - private final Map supports; + private final Map supports; private final Set sources = new HashSet<>(); private ModelProcessingPhase currentPhase = ModelProcessingPhase.INIT; private ModelProcessingPhase finishedPhase = ModelProcessingPhase.INIT; + private final boolean enabledSemanticVersions; + public BuildGlobalContext(final Map supports, - final Predicate isFeatureSupported) { + StatementParserMode statementParserMode, final Predicate isFeatureSupported) { super(); this.supports = Preconditions.checkNotNull(supports, "BuildGlobalContext#supports cannot be null"); + Preconditions.checkNotNull(statementParserMode, "Statement parser mode must not be null."); + this.enabledSemanticVersions = statementParserMode == StatementParserMode.SEMVER_MODE; - addToNs(SupportedFeaturesNamespace.class, SupportedFeatures.SUPPORTED_FEATURES, isFeatureSupported); + addToNs(SupportedFeaturesNamespace.class, SupportedFeatures.SUPPORTED_FEATURES, + Preconditions.checkNotNull(isFeatureSupported, "Supported feature predicate must not be null.")); } public BuildGlobalContext(final Map supports, - final Map> supportedValidation, - final Predicate isFeatureSupported) { + final Map> supportedValidation, + StatementParserMode statementParserMode, final Predicate isFeatureSupported) { super(); this.supports = Preconditions.checkNotNull(supports, "BuildGlobalContext#supports cannot be null"); + Preconditions.checkNotNull(statementParserMode, "Statement parser mode must not be null."); + this.enabledSemanticVersions = statementParserMode == StatementParserMode.SEMVER_MODE; for (Entry> validationBundle : supportedValidation.entrySet()) { addToNs(ValidationBundlesNamespace.class, validationBundle.getKey(), validationBundle.getValue()); } - addToNs(SupportedFeaturesNamespace.class, SupportedFeatures.SUPPORTED_FEATURES, isFeatureSupported); + addToNs(SupportedFeaturesNamespace.class, SupportedFeatures.SUPPORTED_FEATURES, + Preconditions.checkNotNull(isFeatureSupported, "Supported feature predicate must not be null.")); + } + + public boolean isEnabledSemanticVersioning() { + return enabledSemanticVersions; } public StatementSupportBundle getSupportsForPhase(final ModelProcessingPhase currentPhase) { @@ -95,7 +105,7 @@ class BuildGlobalContext extends NamespaceStorageSupport implements NamespaceBeh } public void addSource(@Nonnull final StatementStreamSource source) { - sources.add(new SourceSpecificContext(this,source)); + sources.add(new SourceSpecificContext(this, source)); } @Override @@ -114,7 +124,8 @@ class BuildGlobalContext extends NamespaceStorageSupport implements NamespaceBeh } @Override - public > NamespaceBehaviourWithListeners getNamespaceBehaviour(final Class type) { + public > NamespaceBehaviourWithListeners getNamespaceBehaviour( + final Class type) { NamespaceBehaviourWithListeners potential = supportedNamespaces.get(type); if (potential == null) { NamespaceBehaviour potentialRaw = supports.get(currentPhase).getNamespaceBehaviour(type); @@ -122,27 +133,27 @@ class BuildGlobalContext extends NamespaceStorageSupport implements NamespaceBeh potential = createNamespaceContext(potentialRaw); supportedNamespaces.put(type, potential); } else { - throw new NamespaceNotAvailableException( - "Namespace " + type + " is not available in phase " + currentPhase); + throw new NamespaceNotAvailableException("Namespace " + type + " is not available in phase " + + currentPhase); } } Verify.verify(type.equals(potential.getIdentifier())); /* - * Safe cast, previous checkState checks equivalence of key from which type argument are - * derived + * Safe cast, previous checkState checks equivalence of key from which + * type argument are derived */ return (NamespaceBehaviourWithListeners) potential; } - @SuppressWarnings({"unchecked", "rawtypes"}) + @SuppressWarnings({ "unchecked", "rawtypes" }) private > NamespaceBehaviourWithListeners createNamespaceContext( final NamespaceBehaviour potentialRaw) { if (potentialRaw instanceof DerivedNamespaceBehaviour) { - VirtualNamespaceContext derivedContext = - new VirtualNamespaceContext((DerivedNamespaceBehaviour) potentialRaw); - getNamespaceBehaviour(((DerivedNamespaceBehaviour) potentialRaw).getDerivedFrom()) - .addDerivedNamespace(derivedContext); + VirtualNamespaceContext derivedContext = new VirtualNamespaceContext( + (DerivedNamespaceBehaviour) potentialRaw); + getNamespaceBehaviour(((DerivedNamespaceBehaviour) potentialRaw).getDerivedFrom()).addDerivedNamespace( + derivedContext); return derivedContext; } return new SimpleNamespaceContext<>(potentialRaw); @@ -192,7 +203,7 @@ class BuildGlobalContext extends NamespaceStorageSupport implements NamespaceBeh private EffectiveSchemaContext transformEffective() { Preconditions.checkState(finishedPhase == ModelProcessingPhase.EFFECTIVE_MODEL); List> rootStatements = new ArrayList<>(sources.size()); - List> rootEffectiveStatements = new ArrayList<>(sources.size()); + List> rootEffectiveStatements = new ArrayList<>(sources.size()); for (SourceSpecificContext source : sources) { final RootStatementContext root = source.getRoot(); @@ -211,7 +222,7 @@ class BuildGlobalContext extends NamespaceStorageSupport implements NamespaceBeh currentPhase = phase; } - private void loadPhaseStatements() throws SourceException { + private void loadPhaseStatements() throws SourceException { Preconditions.checkState(currentPhase != null); for (SourceSpecificContext source : sources) { source.loadStatements(); @@ -224,7 +235,8 @@ class BuildGlobalContext extends NamespaceStorageSupport implements NamespaceBeh for (SourceSpecificContext failedSource : sourcesToProgress) { final SourceException sourceEx = failedSource.failModifiers(currentPhase); - // Workaround for broken logging implementations which ignore suppressed exceptions + // Workaround for broken logging implementations which ignore + // suppressed exceptions Throwable cause = sourceEx.getCause() != null ? sourceEx.getCause() : sourceEx; if (LOG.isDebugEnabled()) { LOG.error("Failed to parse YANG from source {}", failedSource, sourceEx); @@ -259,7 +271,7 @@ class BuildGlobalContext extends NamespaceStorageSupport implements NamespaceBeh return buildFailure; } - private void completePhaseActions() throws ReactorException { + private void completePhaseActions() throws ReactorException { Preconditions.checkState(currentPhase != null); List sourcesToProgress = Lists.newArrayList(sources); try { @@ -272,17 +284,18 @@ class BuildGlobalContext extends NamespaceStorageSupport implements NamespaceBeh SourceSpecificContext nextSourceCtx = currentSource.next(); PhaseCompletionProgress sourceProgress = nextSourceCtx.tryToCompletePhase(currentPhase); switch (sourceProgress) { - case FINISHED: - currentSource.remove(); - // Fallback to progress, since we were able to make progress in computation - case PROGRESS: - progressing = true; - break; - case NO_PROGRESS: - // Noop - break; - default: - throw new IllegalStateException("Unsupported phase progress " + sourceProgress); + case FINISHED: + currentSource.remove(); + // Fallback to progress, since we were able to make + // progress in computation + case PROGRESS: + progressing = true; + break; + case NO_PROGRESS: + // Noop + break; + default: + throw new IllegalStateException("Unsupported phase progress " + sourceProgress); } } } @@ -296,7 +309,7 @@ class BuildGlobalContext extends NamespaceStorageSupport implements NamespaceBeh } } - private void endPhase(final ModelProcessingPhase phase) { + private void endPhase(final ModelProcessingPhase phase) { Preconditions.checkState(currentPhase == phase); finishedPhase = currentPhase; } diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/CrossSourceStatementReactor.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/CrossSourceStatementReactor.java index 9873466b30..fac33f5e1d 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/CrossSourceStatementReactor.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/CrossSourceStatementReactor.java @@ -7,7 +7,6 @@ */ package org.opendaylight.yangtools.yang.parser.stmt.reactor; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableMap; import com.google.common.io.ByteSource; import java.io.File; @@ -25,6 +24,7 @@ import java.util.function.Predicate; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode; import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupportBundle; @@ -36,15 +36,16 @@ import org.opendaylight.yangtools.yang.parser.util.NamedFileInputStream; public class CrossSourceStatementReactor { - private final Map supportedTerminology; - private final Map> supportedValidation; + private final Map supportedTerminology; + private final Map> supportedValidation; CrossSourceStatementReactor(final Map supportedTerminology) { this.supportedTerminology = ImmutableMap.copyOf(supportedTerminology); this.supportedValidation = ImmutableMap.of(); } - CrossSourceStatementReactor(final Map supportedTerminology, final Map> supportedValidation) { + CrossSourceStatementReactor(final Map supportedTerminology, + final Map> supportedValidation) { this.supportedTerminology = ImmutableMap.copyOf(supportedTerminology); this.supportedValidation = ImmutableMap.copyOf(supportedValidation); } @@ -54,26 +55,34 @@ public class CrossSourceStatementReactor { } public final BuildAction newBuild() { - return newBuild(t -> true); + return newBuild(StatementParserMode.DEFAULT_MODE, t -> true); } public final BuildAction newBuild(final Predicate isFeatureSupported) { - return new BuildAction(isFeatureSupported); + return new BuildAction(StatementParserMode.DEFAULT_MODE, isFeatureSupported); } - public static class Builder implements org.opendaylight.yangtools.concepts.Builder{ + public final BuildAction newBuild(final StatementParserMode statementParserMode) { + return new BuildAction(statementParserMode, t -> true); + } + + public final BuildAction newBuild(final StatementParserMode statementParserMode, + final Predicate isFeatureSupported) { + return new BuildAction(statementParserMode, isFeatureSupported); + } - final Map bundles = new EnumMap<>(ModelProcessingPhase.class); - final Map> validationBundles = new EnumMap<>(ValidationBundleType.class); + public static class Builder implements org.opendaylight.yangtools.concepts.Builder { - public Builder setBundle(final ModelProcessingPhase phase,final StatementSupportBundle bundle) { + final Map bundles = new EnumMap<>(ModelProcessingPhase.class); + final Map> validationBundles = new EnumMap<>(ValidationBundleType.class); + + public Builder setBundle(final ModelProcessingPhase phase, final StatementSupportBundle bundle) { bundles.put(phase, bundle); return this; } - public Builder setValidationBundle(final ValidationBundleType type, final Collection validationBundle) { - validationBundles.put(type,validationBundle); + validationBundles.put(type, validationBundle); return this; } @@ -87,12 +96,20 @@ public class CrossSourceStatementReactor { private final BuildGlobalContext context; public BuildAction() { - this(t -> true); + this(StatementParserMode.DEFAULT_MODE, t -> true); + } + + public BuildAction(StatementParserMode statementParserMode) { + this(statementParserMode, t -> true); } public BuildAction(Predicate isFeatureSupported) { - Preconditions.checkNotNull(isFeatureSupported); - this.context = new BuildGlobalContext(supportedTerminology, supportedValidation, isFeatureSupported); + this(StatementParserMode.DEFAULT_MODE, isFeatureSupported); + } + + public BuildAction(StatementParserMode statementParserMode, Predicate isFeatureSupported) { + this.context = new BuildGlobalContext(supportedTerminology, supportedValidation, statementParserMode, + isFeatureSupported); } public void addSource(final StatementStreamSource source) { @@ -117,8 +134,8 @@ public class CrossSourceStatementReactor { return context.buildEffective(); } - public SchemaContext buildEffective(final Collection yangByteSources) throws - ReactorException, IOException { + public SchemaContext buildEffective(final Collection yangByteSources) throws ReactorException, + IOException { for (ByteSource yangByteSource : yangByteSources) { addSource(new YangStatementSourceImpl(yangByteSource.openStream())); } @@ -126,8 +143,7 @@ public class CrossSourceStatementReactor { return buildEffective(); } - public SchemaContext buildEffective(final List yangInputStreams) throws - ReactorException { + public SchemaContext buildEffective(final List yangInputStreams) throws ReactorException { for (InputStream yangInputStream : yangInputStreams) { addSource(new YangStatementSourceImpl(yangInputStream)); } @@ -136,11 +152,12 @@ public class CrossSourceStatementReactor { } /** - * @deprecated This method was never used and relies on deprecated module methods. + * @deprecated This method was never used and relies on deprecated + * module methods. */ @Deprecated - public Map buildEffectiveMappedToSource(final List yangFiles) throws - ReactorException, FileNotFoundException { + public Map buildEffectiveMappedToSource(final List yangFiles) throws ReactorException, + FileNotFoundException { if (yangFiles == null || yangFiles.isEmpty()) { return Collections.emptyMap(); } @@ -162,4 +179,4 @@ public class CrossSourceStatementReactor { return sourceFileToModule; } } -} +} \ No newline at end of file diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/ModelDefinedStatementDefinition.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/ModelDefinedStatementDefinition.java index 26f4a3e57e..a6df713883 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/ModelDefinedStatementDefinition.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/ModelDefinedStatementDefinition.java @@ -20,9 +20,15 @@ import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.UnknownEffe // FIXME: Provide real argument name final class ModelDefinedStatementDefinition implements StatementDefinition { private final QName qName; + private final boolean yinElement; ModelDefinedStatementDefinition(QName qName) { + this(qName, false); + } + + ModelDefinedStatementDefinition(QName qName, final boolean yinElement) { this.qName = qName; + this.yinElement = yinElement; } @Nonnull @@ -48,4 +54,9 @@ final class ModelDefinedStatementDefinition implements StatementDefinition { public Class> getEffectiveRepresentationClass() { return UnknownEffectiveStatementImpl.class; } + + @Override + public boolean isArgumentYinElement() { + return yinElement; + } } \ No newline at end of file diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/RootStatementContext.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/RootStatementContext.java index b24f6e3e04..4fc299a573 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/RootStatementContext.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/RootStatementContext.java @@ -171,4 +171,9 @@ public class RootStatementContext, E extends E public boolean isConfiguration() { return true; } + + @Override + public boolean isEnabledSemanticVersioning() { + return sourceContext.isEnabledSemanticVersioning(); + } } diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/SourceSpecificContext.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/SourceSpecificContext.java index ead4acb8aa..c2d06d6035 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/SourceSpecificContext.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/SourceSpecificContext.java @@ -88,6 +88,10 @@ public class SourceSpecificContext implements NamespaceStorageNode, NamespaceBeh this.currentContext = currentContext; } + public boolean isEnabledSemanticVersioning(){ + return currentContext.isEnabledSemanticVersioning(); + } + ModelProcessingPhase getInProgressPhase() { return inProgressPhase; } @@ -382,7 +386,7 @@ public class SourceSpecificContext implements NamespaceStorageNode, NamespaceBeh } private QNameToStatementDefinition stmtDef() { - // regular YANG statements added + // regular YANG statements and extension supports added ImmutableMap> definitions = currentContext.getSupportsForPhase( inProgressPhase).getDefinitions(); for (Entry> entry : definitions.entrySet()) { @@ -396,12 +400,15 @@ public class SourceSpecificContext implements NamespaceStorageNode, NamespaceBeh if (extensions != null) { for (Entry>> extension : extensions.entrySet()) { - qNameToStmtDefMap.put((extension.getKey()), + if(qNameToStmtDefMap.get(extension.getKey()) == null) { + qNameToStmtDefMap.put((extension.getKey()), (StatementDefinition) ((StatementContextBase) extension.getValue()).definition() .getFactory()); + } } } } + return qNameToStmtDefMap; } } diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/SubstatementContext.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/SubstatementContext.java index c7e1c1a8de..5f47b015ad 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/SubstatementContext.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/SubstatementContext.java @@ -257,4 +257,9 @@ final class SubstatementContext, E extends Eff "Parent node has config statement set to false, therefore no node underneath it can have config set to true", getStatementSourceReference()); } + + @Override + public boolean isEnabledSemanticVersioning() { + return parent.isEnabledSemanticVersioning(); + } } diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/ImportStatementDefinition.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/ImportStatementDefinition.java index 6fc637b59d..336b85cb1a 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/ImportStatementDefinition.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/ImportStatementDefinition.java @@ -18,7 +18,10 @@ import java.util.Collection; import java.util.Date; import java.util.Map; import java.util.Map.Entry; +import java.util.NavigableMap; +import org.opendaylight.yangtools.concepts.SemVer; import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil; +import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier; import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping; import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement; @@ -36,18 +39,22 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException; import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder; import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder.InferenceAction; import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder.Prerequisite; +import org.opendaylight.yangtools.yang.parser.spi.meta.SemanticVersionModuleNamespace; +import org.opendaylight.yangtools.yang.parser.spi.meta.SemanticVersionNamespace; import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext; import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable; import org.opendaylight.yangtools.yang.parser.spi.source.ImpPrefixToModuleIdentifier; import org.opendaylight.yangtools.yang.parser.spi.source.ImpPrefixToNamespace; +import org.opendaylight.yangtools.yang.parser.spi.source.ImpPrefixToSemVerModuleIdentifier; +import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleIdentifier; import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToNamespace; import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.ImportEffectiveStatementImpl; -public class ImportStatementDefinition - extends AbstractStatementSupport> { - private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = - SubstatementValidator.builder(Rfc6020Mapping.IMPORT) - .add(Rfc6020Mapping.PREFIX, 1, 1).add(Rfc6020Mapping.REVISION_DATE, 0, 1).build(); +public class ImportStatementDefinition extends + AbstractStatementSupport> { + private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator + .builder(Rfc6020Mapping.IMPORT).add(Rfc6020Mapping.PREFIX, 1, 1).add(Rfc6020Mapping.REVISION_DATE, 0, 1) + .add(SupportedExtensionsMapping.SEMANTIC_VERSION, 0, 1).build(); public ImportStatementDefinition() { super(Rfc6020Mapping.IMPORT); @@ -109,79 +116,186 @@ public class ImportStatementDefinition @Override public void onLinkageDeclared( final Mutable> stmt) { - final ModuleIdentifier impIdentifier = getImportedModuleIdentifier(stmt); - final ModelActionBuilder importAction = stmt.newInferenceAction(SOURCE_LINKAGE); - final Prerequisite> imported = importAction.requiresCtx(stmt, ModuleNamespace.class, - impIdentifier, SOURCE_LINKAGE); - final Prerequisite> linkageTarget = importAction.mutatesCtx(stmt.getRoot(), SOURCE_LINKAGE); + if (stmt.isEnabledSemanticVersioning()) { + SemanticVersionImport.onLinkageDeclared(stmt); + } else { + RevisionImport.onLinkageDeclared(stmt); + } + } - importAction.apply(new InferenceAction() { - @Override - public void apply() { - StmtContext importedModule = null; - ModuleIdentifier importedModuleIdentifier = null; - if (impIdentifier.getRevision() == SimpleDateFormatUtil.DEFAULT_DATE_IMP) { - Entry>> recentModuleEntry = - findRecentModule(impIdentifier, stmt.getAllFromNamespace(ModuleNamespace.class)); - if (recentModuleEntry != null) { - importedModuleIdentifier = recentModuleEntry.getKey(); - importedModule = recentModuleEntry.getValue(); + private static class RevisionImport { + + private RevisionImport() { + throw new UnsupportedOperationException("Utility class"); + } + + private static void onLinkageDeclared( + final Mutable> stmt) { + final ModuleIdentifier impIdentifier = getImportedModuleIdentifier(stmt); + final ModelActionBuilder importAction = stmt.newInferenceAction(SOURCE_LINKAGE); + final Prerequisite> imported = importAction.requiresCtx(stmt, ModuleNamespace.class, + impIdentifier, SOURCE_LINKAGE); + final Prerequisite> linkageTarget = importAction + .mutatesCtx(stmt.getRoot(), SOURCE_LINKAGE); + + importAction.apply(new InferenceAction() { + @Override + public void apply() { + StmtContext importedModule = null; + ModuleIdentifier importedModuleIdentifier = null; + if (impIdentifier.getRevision() == SimpleDateFormatUtil.DEFAULT_DATE_IMP) { + Entry>> recentModuleEntry = findRecentModule( + impIdentifier, stmt.getAllFromNamespace(ModuleNamespace.class)); + if (recentModuleEntry != null) { + importedModuleIdentifier = recentModuleEntry.getKey(); + importedModule = recentModuleEntry.getValue(); + } + } + + if (importedModule == null || importedModuleIdentifier == null) { + importedModule = imported.get(); + importedModuleIdentifier = impIdentifier; + } + + linkageTarget.get().addToNs(ImportedModuleContext.class, importedModuleIdentifier, importedModule); + String impPrefix = firstAttributeOf(stmt.declaredSubstatements(), PrefixStatement.class); + stmt.addToNs(ImpPrefixToModuleIdentifier.class, impPrefix, importedModuleIdentifier); + + final URI modNs = firstAttributeOf(importedModule.declaredSubstatements(), NamespaceStatement.class); + stmt.addToNs(URIStringToImpPrefix.class, modNs.toString(), impPrefix); + } + + @Override + public void prerequisiteFailed(final Collection> failed) { + if (failed.contains(imported)) { + throw new InferenceException(stmt.getStatementSourceReference(), + "Imported module [%s] was not found.", impIdentifier); } } + }); + + } + + private static Entry>> findRecentModule( + final ModuleIdentifier impIdentifier, + final Map>> allModules) { + + ModuleIdentifier recentModuleIdentifier = impIdentifier; + Entry>> recentModuleEntry = null; + + for (Entry>> moduleEntry : allModules + .entrySet()) { + final ModuleIdentifier id = moduleEntry.getKey(); - if (importedModule == null || importedModuleIdentifier == null) { - importedModule = imported.get(); - importedModuleIdentifier = impIdentifier; + if (id.getName().equals(impIdentifier.getName()) + && id.getRevision().compareTo(recentModuleIdentifier.getRevision()) > 0) { + recentModuleIdentifier = id; + recentModuleEntry = moduleEntry; } + } - linkageTarget.get().addToNs(ImportedModuleContext.class, importedModuleIdentifier, importedModule); - String impPrefix = firstAttributeOf(stmt.declaredSubstatements(), PrefixStatement.class); - stmt.addToNs(ImpPrefixToModuleIdentifier.class, impPrefix, importedModuleIdentifier); + return recentModuleEntry; + } - final URI modNs = firstAttributeOf(importedModule.declaredSubstatements(), NamespaceStatement.class); - stmt.addToNs(URIStringToImpPrefix.class, modNs.toString(), impPrefix); + private static ModuleIdentifier getImportedModuleIdentifier(final Mutable stmt) { + Date revision = firstAttributeOf(stmt.declaredSubstatements(), RevisionDateStatement.class); + if (revision == null) { + revision = SimpleDateFormatUtil.DEFAULT_DATE_IMP; } - private Entry>> findRecentModule( - final ModuleIdentifier impIdentifier, - final Map>> allModules) { + return new ModuleIdentifierImpl(stmt.getStatementArgument(), Optional.absent(), + Optional.of(revision)); + } + } + + private static class SemanticVersionImport { + private SemanticVersionImport() { + throw new UnsupportedOperationException("Utility class"); + } - ModuleIdentifier recentModuleIdentifier = impIdentifier; - Entry>> recentModuleEntry = null; + private static void onLinkageDeclared( + final Mutable> stmt) { + final ModuleIdentifier impIdentifier = getImportedModuleIdentifier(stmt); + final ModelActionBuilder importAction = stmt.newInferenceAction(SOURCE_LINKAGE); + final Prerequisite> imported = importAction.requiresCtx(stmt, ModuleNamespace.class, + impIdentifier, SOURCE_LINKAGE); + final Prerequisite> linkageTarget = importAction + .mutatesCtx(stmt.getRoot(), SOURCE_LINKAGE); - for (Entry>> moduleEntry : allModules.entrySet()) { - final ModuleIdentifier id = moduleEntry.getKey(); + importAction.apply(new InferenceAction() { + @Override + public void apply() { + Entry> importedModuleEntry= findRecentCompatibleModuleEntry( + impIdentifier.getName(), stmt); - if (id.getName().equals(impIdentifier.getName()) - && id.getRevision().compareTo(recentModuleIdentifier.getRevision()) > 0) { - recentModuleIdentifier = id; - recentModuleEntry = moduleEntry; + StmtContext importedModule = null; + ModuleIdentifier importedModuleIdentifier = null; + ModuleIdentifier semVerModuleIdentifier = null; + if (importedModuleEntry != null) { + importedModule = importedModuleEntry.getValue(); + importedModuleIdentifier = importedModule.getFromNamespace(ModuleCtxToModuleIdentifier.class, importedModule); + semVerModuleIdentifier = createSemVerModuleIdentifier(importedModuleIdentifier, importedModuleEntry.getKey()); + } else { + throw new InferenceException(stmt.getStatementSourceReference(), + "Unable to find module compatible with requested import [%s(%s)].", impIdentifier + .getName(), getRequestedImportVersion(stmt)); } + + linkageTarget.get().addToNs(ImportedModuleContext.class, importedModuleIdentifier, importedModule); + String impPrefix = firstAttributeOf(stmt.declaredSubstatements(), PrefixStatement.class); + stmt.addToNs(ImpPrefixToModuleIdentifier.class, impPrefix, importedModuleIdentifier); + stmt.addToNs(ImpPrefixToSemVerModuleIdentifier.class, impPrefix, semVerModuleIdentifier); + + final URI modNs = firstAttributeOf(importedModule.declaredSubstatements(), NamespaceStatement.class); + stmt.addToNs(URIStringToImpPrefix.class, modNs.toString(), impPrefix); } - return recentModuleEntry; + @Override + public void prerequisiteFailed(final Collection> failed) { + if (failed.contains(imported)) { + throw new InferenceException(stmt.getStatementSourceReference(), + "Unable to find module compatible with requested import [%s(%s)].", impIdentifier + .getName(), getRequestedImportVersion(stmt)); + } + } + }); + } + + private static SemVer getRequestedImportVersion(Mutable impStmt) { + SemVer requestedImportVersion = impStmt.getFromNamespace(SemanticVersionNamespace.class, impStmt); + if (requestedImportVersion == null) { + requestedImportVersion = Module.DEFAULT_SEMANTIC_VERSION; } + return requestedImportVersion; + } - @Override - public void prerequisiteFailed(final Collection> failed) { - if (failed.contains(imported)) { - throw new InferenceException(stmt.getStatementSourceReference(), - "Imported module [%s] was not found.", impIdentifier); - } + private static Entry> findRecentCompatibleModuleEntry(final String moduleName, + final Mutable> impStmt) { + NavigableMap> allRelevantModulesMap = impStmt.getFromNamespace( + SemanticVersionModuleNamespace.class, moduleName); + if (allRelevantModulesMap == null) { + return null; } - }); + final SemVer requestedImportVersion = getRequestedImportVersion(impStmt); + allRelevantModulesMap = allRelevantModulesMap.subMap(requestedImportVersion, true, + SemVer.create(requestedImportVersion.getMajor() + 1), false); + if (!allRelevantModulesMap.isEmpty()) { + return allRelevantModulesMap.lastEntry(); + } - } + return null; + } - private static ModuleIdentifier getImportedModuleIdentifier(final Mutable stmt) { - Date revision = firstAttributeOf(stmt.declaredSubstatements(), RevisionDateStatement.class); - if (revision == null) { - revision = SimpleDateFormatUtil.DEFAULT_DATE_IMP; + private static ModuleIdentifier getImportedModuleIdentifier(final Mutable impStmt) { + return new ModuleIdentifierImpl(impStmt.getStatementArgument(), Optional.absent(), + Optional.of(SimpleDateFormatUtil.DEFAULT_DATE_IMP)); } - return new ModuleIdentifierImpl(stmt.getStatementArgument(), Optional.absent(), - Optional.of(revision)); + private static ModuleIdentifier createSemVerModuleIdentifier(final ModuleIdentifier importedModuleIdentifier, + final SemVer semVer) { + return new ModuleIdentifierImpl(importedModuleIdentifier.getName(), Optional.fromNullable(importedModuleIdentifier + .getNamespace()), Optional.of(importedModuleIdentifier.getRevision()), semVer); + } } - -} \ No newline at end of file +} diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/ModuleStatementSupport.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/ModuleStatementSupport.java index 44c4194cf2..2f0e06ba1d 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/ModuleStatementSupport.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/ModuleStatementSupport.java @@ -13,8 +13,12 @@ import static org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils.f import com.google.common.base.Optional; import java.net.URI; import java.util.Date; +import java.util.NavigableMap; +import java.util.TreeMap; +import org.opendaylight.yangtools.concepts.SemVer; import org.opendaylight.yangtools.yang.common.QNameModule; import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil; +import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier; import org.opendaylight.yangtools.yang.model.api.Rfc6020Mapping; import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement; @@ -27,10 +31,13 @@ import org.opendaylight.yangtools.yang.parser.spi.NamespaceToModule; import org.opendaylight.yangtools.yang.parser.spi.PreLinkageModuleNamespace; import org.opendaylight.yangtools.yang.parser.spi.SubstatementValidator; import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport; +import org.opendaylight.yangtools.yang.parser.spi.meta.SemanticVersionModuleNamespace; +import org.opendaylight.yangtools.yang.parser.spi.meta.SemanticVersionNamespace; import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext; import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable; import org.opendaylight.yangtools.yang.parser.spi.source.ImpPrefixToModuleIdentifier; import org.opendaylight.yangtools.yang.parser.spi.source.ImpPrefixToNamespace; +import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleIdentifier; import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName; import org.opendaylight.yangtools.yang.parser.spi.source.ModuleIdentifierToModuleQName; import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToModuleQName; @@ -71,6 +78,7 @@ public class ModuleStatementSupport extends .add(Rfc6020Mapping.TYPEDEF, 0, MAX) .add(Rfc6020Mapping.USES, 0, MAX) .add(Rfc6020Mapping.YANG_VERSION, 0, 1) + .add(SupportedExtensionsMapping.SEMANTIC_VERSION, 0, 1) .build(); public ModuleStatementSupport() { @@ -139,9 +147,30 @@ public class ModuleStatementSupport extends stmt.addToNs(PrefixToModule.class, modulePrefix, qNameModule); stmt.addToNs(ModuleNameToModuleQName.class, stmt.getStatementArgument(), qNameModule); stmt.addToNs(ModuleCtxToModuleQName.class, stmt, qNameModule); + stmt.addToNs(ModuleCtxToModuleIdentifier.class, stmt, moduleIdentifier); stmt.addToNs(ModuleQNameToModuleName.class, qNameModule, stmt.getStatementArgument()); stmt.addToNs(ModuleIdentifierToModuleQName.class, moduleIdentifier, qNameModule); stmt.addToNs(ImpPrefixToModuleIdentifier.class, modulePrefix, moduleIdentifier); + + if (stmt.isEnabledSemanticVersioning()) { + addToSemVerModuleNamespace(stmt); + } + } + + private void addToSemVerModuleNamespace( + final Mutable> stmt) { + final String moduleName = stmt.getStatementArgument(); + NavigableMap> modulesMap = stmt.getFromNamespace( + SemanticVersionModuleNamespace.class, moduleName); + if (modulesMap == null) { + modulesMap = new TreeMap>(); + } + SemVer moduleSemVer = stmt.getFromNamespace(SemanticVersionNamespace.class, stmt); + if(moduleSemVer == null) { + moduleSemVer = Module.DEFAULT_SEMANTIC_VERSION; + } + modulesMap.put(moduleSemVer, stmt); + stmt.addToNs(SemanticVersionModuleNamespace.class, moduleName, modulesMap); } @Override diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/SemanticVersionStatementImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/SemanticVersionStatementImpl.java new file mode 100644 index 0000000000..aea5d7ee66 --- /dev/null +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/SemanticVersionStatementImpl.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2016 Cisco Systems, Inc. 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.stmt.rfc6020; + +import com.google.common.annotations.Beta; +import org.opendaylight.yangtools.concepts.SemVer; +import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement; +import org.opendaylight.yangtools.yang.model.api.stmt.UnknownStatement; +import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement; +import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport; +import org.opendaylight.yangtools.yang.parser.spi.meta.SemanticVersionNamespace; +import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext; +import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.SemanticVersionEffectiveStatementImpl; + +@Beta +public final class SemanticVersionStatementImpl extends AbstractDeclaredStatement implements + UnknownStatement { + + SemanticVersionStatementImpl( + StmtContext, ?> context) { + super(context); + } + + public static class SemanticVersionSupport + extends + AbstractStatementSupport, EffectiveStatement>> { + + public SemanticVersionSupport() { + super(SupportedExtensionsMapping.SEMANTIC_VERSION); + } + + @Override + public SemVer parseArgumentValue(StmtContext ctx, String value) { + return SemVer.valueOf(value) ; + } + + @Override + public void onLinkageDeclared(StmtContext.Mutable,EffectiveStatement>> stmt) { + stmt.addToNs(SemanticVersionNamespace.class, stmt.getParentContext(), stmt.getStatementArgument()); + } + + @Override + public UnknownStatement createDeclared( + StmtContext, ?> ctx) { + return new SemanticVersionStatementImpl(ctx); + } + + @Override + public EffectiveStatement> createEffective( + final StmtContext, EffectiveStatement>> ctx) { + return new SemanticVersionEffectiveStatementImpl(ctx); + } + } + + @Override + public SemVer getArgument() { + return argument(); + } +} diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/SupportedExtensionsMapping.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/SupportedExtensionsMapping.java index a62e0b7c5e..55390c8d2f 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/SupportedExtensionsMapping.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/SupportedExtensionsMapping.java @@ -16,26 +16,46 @@ import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement; import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement; import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition; import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.AnyxmlSchemaLocationEffectiveStatementImpl; +import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.SemanticVersionEffectiveStatementImpl; @Beta public enum SupportedExtensionsMapping implements StatementDefinition { ANYXML_SCHEMA_LOCATION("urn:opendaylight:yang:extension:yang-ext", "2013-07-09", - AnyxmlSchemaLocationStatementImpl.class, AnyxmlSchemaLocationEffectiveStatementImpl.class, - "anyxml-schema-location", "target-node"); + AnyxmlSchemaLocationStatementImpl.class, AnyxmlSchemaLocationEffectiveStatementImpl.class, + "anyxml-schema-location", "target-node", false), SEMANTIC_VERSION( + "urn:opendaylight:yang:extension:semantic-version", "2016-02-02", SemanticVersionStatementImpl.class, + SemanticVersionEffectiveStatementImpl.class, "semantic-version", "semantic-version", false); private final Class> type; private final Class> effectiveType; private final QName name; private final QName argument; + private final boolean yinElement; SupportedExtensionsMapping(final String namespace, final String revision, final Class> declared, - final Class> effective, final String nameStr, - final String argumentStr) { + final Class> effective, final String nameStr, final String argumentStr, + final boolean yinElement) { type = Preconditions.checkNotNull(declared); effectiveType = Preconditions.checkNotNull(effective); name = createQName(namespace, revision, nameStr); argument = createQName(namespace, revision, argumentStr); + this.yinElement = yinElement; + } + + private SupportedExtensionsMapping(final String namespace, final Class> declared, + final Class> effective, final String nameStr, final String argumentStr, + final boolean yinElement) { + type = Preconditions.checkNotNull(declared); + effectiveType = Preconditions.checkNotNull(effective); + name = createQName(namespace, nameStr); + argument = createQName(namespace, argumentStr); + this.yinElement = yinElement; + } + + @Nonnull + private static QName createQName(final String namespace, final String localName) { + return QName.create(namespace, localName).intern(); } @Nonnull @@ -64,4 +84,9 @@ public enum SupportedExtensionsMapping implements StatementDefinition { public Class> getEffectiveRepresentationClass() { return effectiveType; } + + @Override + public boolean isArgumentYinElement() { + return yinElement; + } } diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/YangInferencePipeline.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/YangInferencePipeline.java index bbb52f6e9a..907c22e585 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/YangInferencePipeline.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/YangInferencePipeline.java @@ -24,6 +24,8 @@ import org.opendaylight.yangtools.yang.parser.spi.TypeNamespace; import org.opendaylight.yangtools.yang.parser.spi.meta.DerivedIdentitiesNamespace; import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase; import org.opendaylight.yangtools.yang.parser.spi.meta.QNameCacheNamespace; +import org.opendaylight.yangtools.yang.parser.spi.meta.SemanticVersionModuleNamespace; +import org.opendaylight.yangtools.yang.parser.spi.meta.SemanticVersionNamespace; import org.opendaylight.yangtools.yang.parser.spi.meta.StatementSupportBundle; import org.opendaylight.yangtools.yang.parser.spi.source.AnyxmlSchemaLocationNamespace; import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToModuleContext; @@ -31,7 +33,9 @@ import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToPrefixToModule import org.opendaylight.yangtools.yang.parser.spi.source.BelongsToPrefixToModuleName; import org.opendaylight.yangtools.yang.parser.spi.source.ImpPrefixToModuleIdentifier; import org.opendaylight.yangtools.yang.parser.spi.source.ImpPrefixToNamespace; +import org.opendaylight.yangtools.yang.parser.spi.source.ImpPrefixToSemVerModuleIdentifier; import org.opendaylight.yangtools.yang.parser.spi.source.IncludedSubmoduleNameToIdentifier; +import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleIdentifier; import org.opendaylight.yangtools.yang.parser.spi.source.ModuleCtxToModuleQName; import org.opendaylight.yangtools.yang.parser.spi.source.ModuleIdentifierToModuleQName; import org.opendaylight.yangtools.yang.parser.spi.source.ModuleNameToModuleQName; @@ -82,6 +86,7 @@ public final class YangInferencePipeline { .addSupport(global(NamespaceToModule.class)) .addSupport(global(ModuleNameToModuleQName.class)) .addSupport(global(ModuleCtxToModuleQName.class)) + .addSupport(global(ModuleCtxToModuleIdentifier.class)) .addSupport(global(ModuleQNameToModuleName.class)) .addSupport(global(PrefixToModule.class)) .addSupport(global(ModuleIdentifierToModuleQName.class)) @@ -95,6 +100,10 @@ public final class YangInferencePipeline { .addSupport(sourceLocal(BelongsToModuleContext.class)) .addSupport(sourceLocal(QNameToStatementDefinition.class)) .addSupport(sourceLocal(BelongsToPrefixToModuleName.class)) + .addSupport(new SemanticVersionStatementImpl.SemanticVersionSupport()) + .addSupport(global(SemanticVersionNamespace.class)) + .addSupport(global(SemanticVersionModuleNamespace.class)) + .addSupport(sourceLocal(ImpPrefixToSemVerModuleIdentifier.class)) .build(); private static final StatementSupportBundle STMT_DEF_BUNDLE = StatementSupportBundle diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/YinStatementSourceImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/YinStatementSourceImpl.java index c86b84f422..7a4fcdc60a 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/YinStatementSourceImpl.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/YinStatementSourceImpl.java @@ -45,6 +45,7 @@ public class YinStatementSourceImpl implements StatementStreamSource { private String fileName; private boolean isAbsolute; + // FIXME IO exception: input stream closed when called from StmtTestUtils parserseYinSources method public YinStatementSourceImpl(final InputStream inputStream) { yinStatementModelParser = new YinStatementParserImpl(inputStream.toString()); this.inputStream = new BufferedInputStream(inputStream); diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/AbstractEffectiveModule.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/AbstractEffectiveModule.java index f73b455b4d..2367db331a 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/AbstractEffectiveModule.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/AbstractEffectiveModule.java @@ -21,6 +21,7 @@ import java.util.List; import java.util.Map; import java.util.Set; import org.opendaylight.yangtools.concepts.Immutable; +import org.opendaylight.yangtools.concepts.SemVer; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.common.QNameModule; import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil; @@ -74,6 +75,7 @@ abstract class AbstractEffectiveModule> exte private final Set uses; private final Set> typeDefinitions; private final Set publicChildNodes; + private final SemVer semanticVersion; AbstractEffectiveModule(final StmtContext> ctx) { super(ctx); @@ -86,6 +88,9 @@ abstract class AbstractEffectiveModule> exte YangVersionEffectiveStatementImpl yangVersionStmt = firstEffective(YangVersionEffectiveStatementImpl.class); this.yangVersion = (yangVersionStmt == null) ? "1" : yangVersionStmt.argument(); + SemanticVersionEffectiveStatementImpl semanticVersionStmt = firstEffective(SemanticVersionEffectiveStatementImpl.class); + this.semanticVersion = (semanticVersionStmt == null) ? DEFAULT_SEMANTIC_VERSION : semanticVersionStmt.argument(); + OrganizationEffectiveStatementImpl organizationStmt = firstEffective(OrganizationEffectiveStatementImpl.class); this.organization = (organizationStmt == null) ? null : organizationStmt.argument(); @@ -215,7 +220,11 @@ abstract class AbstractEffectiveModule> exte this.unknownNodes = ImmutableList.copyOf(unknownNodesInit); this.augmentations = ImmutableSet.copyOf(augmentationsInit); - this.imports = ImmutableSet.copyOf(resolveModuleImports(importsInit, ctx)); + if (ctx.isEnabledSemanticVersioning()) { + this.imports = ImmutableSet.copyOf(importsInit); + } else { + this.imports = ImmutableSet.copyOf(resolveModuleImports(importsInit, ctx)); + } this.notifications = ImmutableSet.copyOf(notificationsInit); this.rpcs = ImmutableSet.copyOf(rpcsInit); this.deviations = ImmutableSet.copyOf(deviationsInit); @@ -381,6 +390,11 @@ abstract class AbstractEffectiveModule> exte return uses; } + @Override + public SemVer getSemanticVersion() { + return semanticVersion; + } + @Override public String toString() { return this.getClass().getSimpleName() + "[" + diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/ImportEffectiveStatementImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/ImportEffectiveStatementImpl.java index d9f6fb6b2c..12b8eb6cd9 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/ImportEffectiveStatementImpl.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/ImportEffectiveStatementImpl.java @@ -9,27 +9,28 @@ package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective; import java.util.Date; import java.util.Objects; +import org.opendaylight.yangtools.concepts.SemVer; import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil; +import org.opendaylight.yangtools.yang.model.api.Module; +import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier; import org.opendaylight.yangtools.yang.model.api.ModuleImport; import org.opendaylight.yangtools.yang.model.api.stmt.ImportStatement; import org.opendaylight.yangtools.yang.parser.spi.meta.MissingSubstatementException; import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext; +import org.opendaylight.yangtools.yang.parser.spi.source.ImpPrefixToSemVerModuleIdentifier; public class ImportEffectiveStatementImpl extends DeclaredEffectiveStatementBase implements ModuleImport { private final String moduleName; private final Date revision; + private final SemVer semVer; private final String prefix; public ImportEffectiveStatementImpl(final StmtContext ctx) { super(ctx); moduleName = ctx.getStatementArgument(); - - RevisionDateEffectiveStatementImpl revisionDateStmt = firstEffective(RevisionDateEffectiveStatementImpl.class); - this.revision = (revisionDateStmt == null) ? SimpleDateFormatUtil.DEFAULT_DATE_IMP : revisionDateStmt.argument(); - PrefixEffectiveStatementImpl prefixStmt = firstEffective(PrefixEffectiveStatementImpl.class); if (prefixStmt != null) { this.prefix = prefixStmt.argument(); @@ -37,6 +38,17 @@ public class ImportEffectiveStatementImpl extends DeclaredEffectiveStatementBase throw new MissingSubstatementException("Prefix is mandatory substatement of import statement", ctx.getStatementSourceReference()); } + + if (!ctx.isEnabledSemanticVersioning()) { + RevisionDateEffectiveStatementImpl revisionDateStmt = firstEffective(RevisionDateEffectiveStatementImpl.class); + this.revision = (revisionDateStmt == null) ? SimpleDateFormatUtil.DEFAULT_DATE_IMP : revisionDateStmt + .argument(); + this.semVer = Module.DEFAULT_SEMANTIC_VERSION; + } else { + ModuleIdentifier importedModuleIdentifier = ctx.getFromNamespace(ImpPrefixToSemVerModuleIdentifier.class, prefix); + revision = importedModuleIdentifier.getRevision(); + semVer = importedModuleIdentifier.getSemanticVersion(); + } } @Override @@ -49,6 +61,11 @@ public class ImportEffectiveStatementImpl extends DeclaredEffectiveStatementBase return revision; } + @Override + public SemVer getSemanticVersion() { + return semVer; + } + @Override public String getPrefix() { return prefix; @@ -61,6 +78,7 @@ public class ImportEffectiveStatementImpl extends DeclaredEffectiveStatementBase result = prime * result + Objects.hashCode(moduleName); result = prime * result + Objects.hashCode(revision); result = prime * result + Objects.hashCode(prefix); + result = prime * result + Objects.hashCode(semVer); return result; } @@ -85,12 +103,15 @@ public class ImportEffectiveStatementImpl extends DeclaredEffectiveStatementBase if (!Objects.equals(getPrefix(), other.getPrefix())) { return false; } + if (!Objects.equals(getSemanticVersion(), other.getSemanticVersion())) { + return false; + } return true; } @Override public String toString() { return ImportEffectiveStatementImpl.class.getSimpleName() + "[moduleName=" + moduleName + ", revision=" - + revision + ", prefix=" + prefix + "]"; + + revision + ", semantic version=" + semVer + ", prefix=" + prefix + "]"; } } diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/SemanticVersionEffectiveStatementImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/SemanticVersionEffectiveStatementImpl.java new file mode 100644 index 0000000000..eaf7dccaeb --- /dev/null +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/SemanticVersionEffectiveStatementImpl.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2016 Cisco Systems, Inc. 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.stmt.rfc6020.effective; + +import com.google.common.annotations.Beta; +import java.util.Objects; +import org.opendaylight.yangtools.concepts.SemVer; +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.model.api.SchemaPath; +import org.opendaylight.yangtools.yang.model.api.stmt.UnknownStatement; +import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext; + +@Beta +public final class SemanticVersionEffectiveStatementImpl extends + UnknownEffectiveStatementBase { + + private final SchemaPath path; + + public SemanticVersionEffectiveStatementImpl( + final StmtContext, ?> ctx) { + super(ctx); + path = ctx.getParentContext().getSchemaPath().get().createChild(getNodeType()); + } + + @Override + public QName getQName() { + return getNodeType(); + } + + @Override + public SchemaPath getPath() { + return path; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + Objects.hashCode(path); + result = prime * result + Objects.hashCode(getNodeType()); + result = prime * result + Objects.hashCode(getNodeParameter()); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + SemanticVersionEffectiveStatementImpl other = (SemanticVersionEffectiveStatementImpl) obj; + if (!Objects.equals(path, other.path)) { + return false; + } + if (!Objects.equals(getNodeType(), other.getNodeType())) { + return false; + } + if (!Objects.equals(getNodeParameter(), other.getNodeParameter())) { + return false; + } + return true; + } +} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/StmtTestUtils.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/StmtTestUtils.java index 6855026127..87b6176750 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/StmtTestUtils.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/StmtTestUtils.java @@ -8,29 +8,31 @@ package org.opendaylight.yangtools.yang.stmt; +import java.io.File; import java.io.FileFilter; - -import org.opendaylight.yangtools.yang.parser.util.NamedFileInputStream; +import java.io.FileNotFoundException; import java.net.URISyntaxException; import java.net.URL; -import java.io.File; -import java.io.FileNotFoundException; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; -import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; -import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource; -import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline; import java.util.ArrayList; -import java.util.List; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.util.Collection; +import java.util.List; import java.util.Set; import org.opendaylight.yangtools.yang.model.api.DataNodeContainer; import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; import org.opendaylight.yangtools.yang.model.api.Module; +import org.opendaylight.yangtools.yang.model.api.ModuleImport; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; +import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; +import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource; import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor; +import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline; import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl; +import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YinStatementSourceImpl; +import org.opendaylight.yangtools.yang.parser.util.NamedFileInputStream; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class StmtTestUtils { @@ -42,8 +44,15 @@ public class StmtTestUtils { } }; - private static final Logger LOG = LoggerFactory - .getLogger(StmtTestUtils.class); + final public static FileFilter YIN_FILE_FILTER = new FileFilter() { + @Override + public boolean accept(File file) { + String name = file.getName().toLowerCase(); + return name.endsWith(".xml") && file.isFile(); + } + }; + + private static final Logger LOG = LoggerFactory.getLogger(StmtTestUtils.class); private StmtTestUtils() { @@ -58,8 +67,7 @@ public class StmtTestUtils { } } - public static List findModules(final Set modules, - final String moduleName) { + public static List findModules(final Set modules, final String moduleName) { List result = new ArrayList<>(); for (Module module : modules) { if (module.getName().equals(moduleName)) { @@ -69,18 +77,14 @@ public class StmtTestUtils { return result; } - public static void addSources( - CrossSourceStatementReactor.BuildAction reactor, - YangStatementSourceImpl... sources) { + public static void addSources(CrossSourceStatementReactor.BuildAction reactor, YangStatementSourceImpl... sources) { for (YangStatementSourceImpl source : sources) { reactor.addSource(source); } } - public static void printReferences(Module module, boolean isSubmodule, - String indent) { - LOG.debug(indent + (isSubmodule ? "Submodule " : "Module ") - + module.getName()); + public static void printReferences(Module module, boolean isSubmodule, String indent) { + LOG.debug(indent + (isSubmodule ? "Submodule " : "Module ") + module.getName()); Set submodules = module.getSubmodules(); for (Module submodule : submodules) { printReferences(submodule, true, indent + " "); @@ -88,31 +92,37 @@ public class StmtTestUtils { } } - public static void printChilds(Collection childNodes, - String indent) { + public static void printChilds(Collection childNodes, String indent) { for (DataSchemaNode child : childNodes) { LOG.debug(indent + "Child " + child.getQName().getLocalName()); if (child instanceof DataNodeContainer) { - printChilds(((DataNodeContainer) child).getChildNodes(), indent - + " "); + printChilds(((DataNodeContainer) child).getChildNodes(), indent + " "); } } } - public static SchemaContext parseYangSources( - StatementStreamSource... sources) throws SourceException, + public static SchemaContext parseYangSources(StatementStreamSource... sources) throws SourceException, ReactorException { + return parseYangSources(StatementParserMode.DEFAULT_MODE, sources); + } - CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR - .newBuild(); + public static SchemaContext parseYangSources(StatementParserMode statementParserMode, StatementStreamSource... sources) + throws SourceException, ReactorException { + + CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(statementParserMode); reactor.addSources(sources); return reactor.buildEffective(); } - public static SchemaContext parseYangSources(File... files) - throws SourceException, ReactorException, FileNotFoundException { + public static SchemaContext parseYangSources(File... files) throws SourceException, ReactorException, + FileNotFoundException { + return parseYangSources(StatementParserMode.DEFAULT_MODE, files); + } + + public static SchemaContext parseYangSources(StatementParserMode statementParserMode, File... files) throws SourceException, + ReactorException, FileNotFoundException { StatementStreamSource[] sources = new StatementStreamSource[files.length]; @@ -120,20 +130,75 @@ public class StmtTestUtils { sources[i] = new YangStatementSourceImpl(new NamedFileInputStream(files[i], files[i].getPath())); } - return parseYangSources(sources); + return parseYangSources(statementParserMode, sources); + } + + public static SchemaContext parseYangSources(Collection files) throws SourceException, ReactorException, + FileNotFoundException { + return parseYangSources(files, StatementParserMode.DEFAULT_MODE); } - public static SchemaContext parseYangSources(Collection files) + public static SchemaContext parseYangSources(Collection files, StatementParserMode statementParserMode) throws SourceException, ReactorException, FileNotFoundException { - return parseYangSources(files.toArray(new File[files.size()])); + return parseYangSources(statementParserMode, files.toArray(new File[files.size()])); } - public static SchemaContext parseYangSources(String yangSourcesDirectoryPath) + public static SchemaContext parseYangSources(String yangSourcesDirectoryPath) throws SourceException, + ReactorException, FileNotFoundException, URISyntaxException { + return parseYangSources(yangSourcesDirectoryPath, StatementParserMode.DEFAULT_MODE); + } + + public static SchemaContext parseYangSources(String yangSourcesDirectoryPath, StatementParserMode statementParserMode) throws SourceException, ReactorException, FileNotFoundException, URISyntaxException { URL resourceDir = StmtTestUtils.class.getResource(yangSourcesDirectoryPath); File testSourcesDir = new File(resourceDir.toURI()); - return parseYangSources(testSourcesDir.listFiles(YANG_FILE_FILTER)); + return parseYangSources(statementParserMode, testSourcesDir.listFiles(YANG_FILE_FILTER)); + } + + public static SchemaContext parseYinSources(String yinSourcesDirectoryPath, StatementParserMode statementParserMode) + throws SourceException, ReactorException, FileNotFoundException, URISyntaxException { + + URL resourceDir = StmtTestUtils.class.getResource(yinSourcesDirectoryPath); + File testSourcesDir = new File(resourceDir.toURI()); + + return parseYinSources(statementParserMode, testSourcesDir.listFiles(YIN_FILE_FILTER)); + } + + public static SchemaContext parseYinSources(StatementParserMode statementParserMode, File... files) throws SourceException, + ReactorException, FileNotFoundException { + + StatementStreamSource[] sources = new StatementStreamSource[files.length]; + + for (int i = 0; i < files.length; i++) { + sources[i] = new YinStatementSourceImpl(new NamedFileInputStream(files[i], files[i].getPath())); + } + + return parseYinSources(statementParserMode, sources); + } + + public static SchemaContext parseYinSources(StatementParserMode statementParserMode, StatementStreamSource... sources) + throws SourceException, ReactorException { + + CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(statementParserMode); + reactor.addSources(sources); + + return reactor.buildEffective(); + } + + public static Module findImportedModule(SchemaContext context, Module rootModule, String importedModuleName) { + ModuleImport requestedModuleImport = null; + Set rootImports = rootModule.getImports(); + for (ModuleImport moduleImport : rootImports) { + if (moduleImport.getModuleName().equals(importedModuleName)) { + requestedModuleImport = moduleImport; + break; + } + } + + Module importedModule = context.findModuleByName(requestedModuleImport.getModuleName(), + requestedModuleImport.getRevision()); + return importedModule; } } diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/semver/SemanticVersionBorderCaseTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/semver/SemanticVersionBorderCaseTest.java new file mode 100644 index 0000000000..028989ce9b --- /dev/null +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/semver/SemanticVersionBorderCaseTest.java @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2016 Cisco Systems, Inc. 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.stmt.semver; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode; + +import java.io.FileNotFoundException; +import java.net.URI; +import java.net.URISyntaxException; +import org.junit.Test; +import org.opendaylight.yangtools.concepts.SemVer; +import org.opendaylight.yangtools.yang.model.api.Module; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; +import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; +import org.opendaylight.yangtools.yang.stmt.StmtTestUtils; + +public class SemanticVersionBorderCaseTest { + + @Test + public void borderCaseValidMajorTest() throws SourceException, FileNotFoundException, ReactorException, + URISyntaxException { + SchemaContext context = StmtTestUtils.parseYangSources("/semantic-version/border-case/border-case-valid-major", + StatementParserMode.SEMVER_MODE); + assertNotNull(context); + + Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next(); + Module semVer = context.findModuleByNamespace(new URI("urn:opendaylight:yang:extension:semantic-version")) + .iterator().next(); + + assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion()); + assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion()); + Module bar = StmtTestUtils.findImportedModule(context, foo, "bar"); + assertEquals(SemVer.valueOf("5.5.5"), bar.getSemanticVersion()); + } + + @Test + public void borderCaseValidMinorTest() throws SourceException, FileNotFoundException, ReactorException, + URISyntaxException { + SchemaContext context = StmtTestUtils.parseYangSources("/semantic-version/border-case/border-case-valid-minor", + StatementParserMode.SEMVER_MODE); + assertNotNull(context); + + Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next(); + Module semVer = context.findModuleByNamespace(new URI("urn:opendaylight:yang:extension:semantic-version")) + .iterator().next(); + + assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion()); + assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion()); + Module bar = StmtTestUtils.findImportedModule(context, foo, "bar"); + assertEquals(SemVer.valueOf("5.6.5"), bar.getSemanticVersion()); + } + + @Test + public void borderCaseValidPatchTest() throws SourceException, FileNotFoundException, ReactorException, + URISyntaxException { + SchemaContext context = StmtTestUtils.parseYangSources("/semantic-version/border-case/border-case-valid-patch", + StatementParserMode.SEMVER_MODE); + assertNotNull(context); + + Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next(); + Module semVer = context.findModuleByNamespace(new URI("urn:opendaylight:yang:extension:semantic-version")) + .iterator().next(); + + assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion()); + assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion()); + Module bar = StmtTestUtils.findImportedModule(context, foo, "bar"); + assertEquals(SemVer.valueOf("5.5.6"), bar.getSemanticVersion()); + } + + @Test + public void borderCaseInvalidMajorTest() throws SourceException, FileNotFoundException, ReactorException, + URISyntaxException { + try { + StmtTestUtils.parseYangSources("/semantic-version/border-case/border-case-invalid-major", + StatementParserMode.SEMVER_MODE); + fail("Test should fail due to invalid semantic version"); + } catch (InferenceException e) { + assertTrue(e.getMessage() + .startsWith("Unable to find module compatible with requested import [bar(5.5.5)].")); + } + } + + @Test + public void borderCaseInvalidMinorTest() throws SourceException, FileNotFoundException, ReactorException, + URISyntaxException { + try { + StmtTestUtils.parseYangSources("/semantic-version/border-case/border-case-invalid-minor", + StatementParserMode.SEMVER_MODE); + fail("Test should fail due to invalid semantic version"); + } catch (InferenceException e) { + assertTrue(e.getMessage() + .startsWith("Unable to find module compatible with requested import [bar(5.5.5)].")); + } + } + + @Test + public void borderCaseInvalidPatchTest() throws SourceException, FileNotFoundException, ReactorException, + URISyntaxException { + try { + StmtTestUtils.parseYangSources("/semantic-version/border-case/border-case-invalid-patch", + StatementParserMode.SEMVER_MODE); + fail("Test should fail due to invalid semantic version"); + } catch (InferenceException e) { + assertTrue(e.getMessage() + .startsWith("Unable to find module compatible with requested import [bar(5.5.5)].")); + } + } +} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/semver/SemanticVersionComplexTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/semver/SemanticVersionComplexTest.java new file mode 100644 index 0000000000..44205743c6 --- /dev/null +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/semver/SemanticVersionComplexTest.java @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2016 Cisco Systems, Inc. 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.stmt.semver; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode; + +import java.io.FileNotFoundException; +import java.net.URI; +import java.net.URISyntaxException; +import java.text.ParseException; +import org.junit.Test; +import org.opendaylight.yangtools.concepts.SemVer; +import org.opendaylight.yangtools.yang.model.api.Module; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.model.util.RevisionAwareXPathImpl; +import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; +import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; +import org.opendaylight.yangtools.yang.stmt.StmtTestUtils; + +public class SemanticVersionComplexTest { + + @Test + public void complexTest1() throws SourceException, FileNotFoundException, ReactorException, URISyntaxException, + ParseException { + SchemaContext context = StmtTestUtils.parseYangSources("/semantic-version/complex/complex-1", + StatementParserMode.SEMVER_MODE); + assertNotNull(context); + + Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next(); + Module semVer = context.findModuleByNamespace(new URI("urn:opendaylight:yang:extension:semantic-version")) + .iterator().next(); + + // check module versions + assertEquals(SemVer.valueOf("1.3.95"), semVer.getSemanticVersion()); + assertEquals(SemVer.valueOf("1.50.2"), foo.getSemanticVersion()); + + Module bar = StmtTestUtils.findImportedModule(context, foo, "bar"); + assertEquals(SemVer.valueOf("1.2.6"), bar.getSemanticVersion()); + + Module foobar = StmtTestUtils.findImportedModule(context, bar, "foobar"); + assertEquals(SemVer.valueOf("2.26.465"), foobar.getSemanticVersion()); + + // check imported components + assertNotNull("This component should be present", SchemaContextUtil.findDataSchemaNode(context, foo, + new RevisionAwareXPathImpl("/bar:root/bar:test-container/bar:number", true))); + + assertNotNull("This component should be present", SchemaContextUtil.findDataSchemaNode(context, foo, + new RevisionAwareXPathImpl("/bar:should-present", true))); + + // check not imported components + assertNull("This component should not be present", SchemaContextUtil.findDataSchemaNode(context, foo, + new RevisionAwareXPathImpl("/bar:root/bar:test-container/bar:oldnumber", true))); + + assertNull("This component should not be present", SchemaContextUtil.findDataSchemaNode(context, foo, + new RevisionAwareXPathImpl("/bar:should-not-be-present", true))); + } + + @Test + public void complexTest2() throws SourceException, FileNotFoundException, ReactorException, URISyntaxException, + ParseException { + SchemaContext context = StmtTestUtils.parseYangSources("/semantic-version/complex/complex-2", + StatementParserMode.SEMVER_MODE); + assertNotNull(context); + + Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next(); + Module semVer = context.findModuleByNamespace(new URI("urn:opendaylight:yang:extension:semantic-version")) + .iterator().next(); + + // check module versions + assertEquals(SemVer.valueOf("2.5.50"), semVer.getSemanticVersion()); + assertEquals(SemVer.valueOf("2.32.2"), foo.getSemanticVersion()); + + Module bar = StmtTestUtils.findImportedModule(context, foo, "bar"); + assertEquals(SemVer.valueOf("4.9.8"), bar.getSemanticVersion()); + + Module foobar = StmtTestUtils.findImportedModule(context, bar, "foobar"); + assertEquals(SemVer.valueOf("7.13.99"), foobar.getSemanticVersion()); + + // check used augmentations + assertNotNull("This component should be present", SchemaContextUtil.findDataSchemaNode(context, bar, + new RevisionAwareXPathImpl("/foobar:root/foobar:test-container/bar:should-present-leaf-1", true))); + + assertNotNull("This component should be present", SchemaContextUtil.findDataSchemaNode(context, bar, + new RevisionAwareXPathImpl("/foobar:root/foobar:test-container/bar:should-present-leaf-2", true))); + + // check not used augmentations + assertNull("This component should not be present", + SchemaContextUtil.findDataSchemaNode(context, bar, new RevisionAwareXPathImpl( + "/foobar:root/foobar:test-container/bar:should-not-be-present-leaf-1", true))); + + assertNull("This component should not be present", + SchemaContextUtil.findDataSchemaNode(context, bar, new RevisionAwareXPathImpl( + "/foobar:root/foobar:test-container/bar:should-not-be-present-leaf-2", true))); + + // check if correct foobar module was included + assertNotNull("This component should be present", SchemaContextUtil.findDataSchemaNode(context, bar, + new RevisionAwareXPathImpl("/foobar:root/foobar:included-correct-mark", true))); + + assertNull("This component should not be present", SchemaContextUtil.findDataSchemaNode(context, bar, + new RevisionAwareXPathImpl("/foobar:root/foobar:included-not-correct-mark", true))); + } +} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/semver/SemanticVersionDefaultsTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/semver/SemanticVersionDefaultsTest.java new file mode 100644 index 0000000000..33cc244a35 --- /dev/null +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/semver/SemanticVersionDefaultsTest.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2016 Cisco Systems, Inc. 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.stmt.semver; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode; + +import java.io.FileNotFoundException; +import java.net.URI; +import java.net.URISyntaxException; +import org.junit.Test; +import org.opendaylight.yangtools.concepts.SemVer; +import org.opendaylight.yangtools.yang.model.api.Module; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; +import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; +import org.opendaylight.yangtools.yang.stmt.StmtTestUtils; + +public class SemanticVersionDefaultsTest { + + @Test + public void defaultsTest() throws SourceException, FileNotFoundException, ReactorException, URISyntaxException { + SchemaContext context = StmtTestUtils.parseYangSources("/semantic-version/defaults/defaults", + StatementParserMode.SEMVER_MODE); + assertNotNull(context); + + Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next(); + Module bar = context.findModuleByNamespace(new URI("bar")).iterator().next(); + + assertEquals(SemVer.valueOf("0.0.0"), foo.getSemanticVersion()); + assertEquals(SemVer.valueOf("0.0.0"), bar.getSemanticVersion()); + } + + @Test + public void defaultMajorValidTest() throws SourceException, FileNotFoundException, ReactorException, + URISyntaxException { + SchemaContext context = StmtTestUtils.parseYangSources("/semantic-version/defaults/default-major-valid", + StatementParserMode.SEMVER_MODE); + assertNotNull(context); + + Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next(); + Module bar = context.findModuleByNamespace(new URI("bar")).iterator().next(); + + assertEquals(SemVer.valueOf("0.0.0"), foo.getSemanticVersion()); + assertEquals(SemVer.valueOf("0.99.99"), bar.getSemanticVersion()); + } + + @Test + public void defaultMajorInvalidTest() throws SourceException, FileNotFoundException, ReactorException, + URISyntaxException { + try { + StmtTestUtils.parseYangSources("/semantic-version/defaults/default-major-invalid", StatementParserMode.SEMVER_MODE); + fail("Test should fail due to invalid semantic version"); + } catch (InferenceException e) { + assertTrue(e.getMessage() + .startsWith("Unable to find module compatible with requested import [bar(0.0.0)].")); + } + } +} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/semver/SemanticVersionIgnoringRevisionTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/semver/SemanticVersionIgnoringRevisionTest.java new file mode 100644 index 0000000000..6d09201825 --- /dev/null +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/semver/SemanticVersionIgnoringRevisionTest.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2016 Cisco Systems, Inc. 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.stmt.semver; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode; + +import java.io.FileNotFoundException; +import java.net.URI; +import java.net.URISyntaxException; +import org.junit.Test; +import org.opendaylight.yangtools.concepts.SemVer; +import org.opendaylight.yangtools.yang.model.api.Module; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; +import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; +import org.opendaylight.yangtools.yang.stmt.StmtTestUtils; + +public class SemanticVersionIgnoringRevisionTest { + + @Test + public void ignoringRevisionTest() throws SourceException, FileNotFoundException, ReactorException, + URISyntaxException { + SchemaContext context = StmtTestUtils.parseYangSources("/semantic-version/ignoring-revision", + StatementParserMode.SEMVER_MODE); + assertNotNull(context); + + Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next(); + Module bar = context.findModuleByNamespace(new URI("bar")).iterator().next(); + Module semVer = context.findModuleByNamespace(new URI("urn:opendaylight:yang:extension:semantic-version")) + .iterator().next(); + + assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion()); + assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion()); + assertEquals(SemVer.valueOf("0.1.2"), bar.getSemanticVersion()); + } + + @Test + public void ignoringRevision2Test() throws SourceException, FileNotFoundException, ReactorException, + URISyntaxException { + SchemaContext context = StmtTestUtils.parseYangSources("/semantic-version/ignoring-revision-2", + StatementParserMode.SEMVER_MODE); + assertNotNull(context); + + Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next(); + Module semVer = context.findModuleByNamespace(new URI("urn:opendaylight:yang:extension:semantic-version")) + .iterator().next(); + Module bar = StmtTestUtils.findImportedModule(context, foo, "bar"); + + assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion()); + assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion()); + assertEquals(SemVer.valueOf("0.1.2"), bar.getSemanticVersion()); + } +} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/semver/SemanticVersionImportTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/semver/SemanticVersionImportTest.java new file mode 100644 index 0000000000..114fbfea18 --- /dev/null +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/semver/SemanticVersionImportTest.java @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2016 Cisco Systems, Inc. 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.stmt.semver; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode; + +import java.io.FileNotFoundException; +import java.net.URI; +import java.net.URISyntaxException; +import org.junit.Test; +import org.opendaylight.yangtools.concepts.SemVer; +import org.opendaylight.yangtools.yang.model.api.Module; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; +import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; +import org.opendaylight.yangtools.yang.stmt.StmtTestUtils; + +public class SemanticVersionImportTest { + + @Test + public void importValidTest() throws SourceException, FileNotFoundException, ReactorException, URISyntaxException { + SchemaContext context = StmtTestUtils.parseYangSources("/semantic-version/import/import-valid", + StatementParserMode.SEMVER_MODE); + assertNotNull(context); + + Module semVer = context.findModuleByNamespace(new URI("urn:opendaylight:yang:extension:semantic-version")) + .iterator().next(); + + assertEquals(SemVer.valueOf("1.0.0"), semVer.getSemanticVersion()); + } + + @Test + public void importInvalidDeprecatedTest1() throws SourceException, FileNotFoundException, ReactorException, + URISyntaxException { + try { + StmtTestUtils.parseYangSources("/semantic-version/import/import-invalid-deprecated-1", + StatementParserMode.SEMVER_MODE); + fail("Test should fail due to invalid import of semantic-version module"); + } catch (InferenceException e) { + assertTrue(e.getMessage().startsWith( + "Unable to find module compatible with requested import " + "[semantic-version(1.0.0)].")); + } + } + + @Test + public void importInvalidDeprecatedTest2() throws SourceException, FileNotFoundException, ReactorException, + URISyntaxException { + try { + StmtTestUtils.parseYangSources("/semantic-version/import/import-invalid-deprecated-2", + StatementParserMode.SEMVER_MODE); + fail("Test should fail due to invalid import of semantic-version module"); + } catch (InferenceException e) { + assertTrue(e.getMessage().startsWith( + "Unable to find module compatible with requested import " + "[semantic-version(0.9.9)].")); + } + } + + @Test + public void importInvalidNotsufficientTest1() throws SourceException, FileNotFoundException, ReactorException, + URISyntaxException { + try { + StmtTestUtils.parseYangSources("/semantic-version/import/import-invalid-notsufficient-1", + StatementParserMode.SEMVER_MODE); + fail("Test should fail due to invalid import of semantic-version module"); + } catch (InferenceException e) { + assertTrue(e.getMessage().startsWith( + "Unable to find module compatible with requested import " + "[semantic-version(2.0.0)].")); + } + } + + @Test + public void importInvalidNotsufficientTest2() throws SourceException, FileNotFoundException, ReactorException, + URISyntaxException { + try { + StmtTestUtils.parseYangSources("/semantic-version/import/import-invalid-notsufficient-2", + StatementParserMode.SEMVER_MODE); + fail("Test should fail due to invalid import of semantic-version module"); + } catch (InferenceException e) { + assertTrue(e.getMessage().startsWith( + "Unable to find module compatible with requested import " + "[semantic-version(2.0.5)].")); + } + } +} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/semver/SemanticVersionMultipleImportTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/semver/SemanticVersionMultipleImportTest.java new file mode 100644 index 0000000000..7b85f55afa --- /dev/null +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/semver/SemanticVersionMultipleImportTest.java @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2016 Cisco Systems, Inc. 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.stmt.semver; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode; + +import java.io.FileNotFoundException; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.Set; +import org.junit.Test; +import org.opendaylight.yangtools.concepts.SemVer; +import org.opendaylight.yangtools.yang.model.api.Module; +import org.opendaylight.yangtools.yang.model.api.ModuleImport; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; +import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; +import org.opendaylight.yangtools.yang.stmt.StmtTestUtils; + +public class SemanticVersionMultipleImportTest { + + @Test + public void multipleInvalidDeprecatedTest() throws SourceException, FileNotFoundException, ReactorException, + URISyntaxException { + try { + StmtTestUtils.parseYangSources("/semantic-version/multiple/multiple-invalid-deprecated", + StatementParserMode.SEMVER_MODE); + fail("Test should fail due to invalid semantic version"); + } catch (InferenceException e) { + assertTrue(e.getMessage() + .startsWith("Unable to find module compatible with requested import [bar(1.0.0)].")); + } + } + + @Test + public void multipleInvalidNosufficientTest() throws SourceException, FileNotFoundException, ReactorException, + URISyntaxException { + try { + StmtTestUtils.parseYangSources("/semantic-version/multiple/multiple-invalid-nosufficient", + StatementParserMode.SEMVER_MODE); + fail("Test should fail due to invalid semantic version"); + } catch (InferenceException e) { + assertTrue(e.getMessage() + .startsWith("Unable to find module compatible with requested import [bar(2.5.5)].")); + } + } + + @Test + public void multipleValidDefaultsTest() throws SourceException, FileNotFoundException, ReactorException, + URISyntaxException { + SchemaContext context = StmtTestUtils.parseYangSources("/semantic-version/multiple/multiple-valid-defaults", + StatementParserMode.SEMVER_MODE); + assertNotNull(context); + + Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next(); + Module semVer = context.findModuleByNamespace(new URI("urn:opendaylight:yang:extension:semantic-version")) + .iterator().next(); + + assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion()); + assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion()); + Module bar = findImportedModule(context, foo, "bar"); + assertEquals(SemVer.valueOf("0.9.5"), bar.getSemanticVersion()); + } + + @Test + public void multipleValidSpecifiedTest() throws SourceException, FileNotFoundException, ReactorException, + URISyntaxException { + SchemaContext context = StmtTestUtils.parseYangSources("/semantic-version/multiple/multiple-valid-specified", + StatementParserMode.SEMVER_MODE); + assertNotNull(context); + + Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next(); + Module semVer = context.findModuleByNamespace(new URI("urn:opendaylight:yang:extension:semantic-version")) + .iterator().next(); + + assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion()); + assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion()); + Module bar = findImportedModule(context, foo, "bar"); + assertEquals(SemVer.valueOf("5.5.6"), bar.getSemanticVersion()); + } + + private static Module findImportedModule(SchemaContext context, Module rootModule, String importedModuleName) { + ModuleImport requestedModuleImport = null; + Set rootImports = rootModule.getImports(); + for (ModuleImport moduleImport : rootImports) { + if (moduleImport.getModuleName().equals(importedModuleName)) { + requestedModuleImport = moduleImport; + break; + } + } + + Module importedModule = context.findModuleByName(requestedModuleImport.getModuleName(), + requestedModuleImport.getRevision()); + return importedModule; + } +} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/semver/SemanticVersionPositionTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/semver/SemanticVersionPositionTest.java new file mode 100644 index 0000000000..a869ba50ad --- /dev/null +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/semver/SemanticVersionPositionTest.java @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2016 Cisco Systems, Inc. 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.stmt.semver; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode; + +import java.io.FileNotFoundException; +import java.net.URI; +import java.net.URISyntaxException; +import org.junit.Test; +import org.opendaylight.yangtools.concepts.SemVer; +import org.opendaylight.yangtools.yang.model.api.Module; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; +import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; +import org.opendaylight.yangtools.yang.stmt.StmtTestUtils; + +public class SemanticVersionPositionTest { + + @Test + public void positionHeadTest() throws SourceException, FileNotFoundException, ReactorException, URISyntaxException { + SchemaContext context = StmtTestUtils.parseYangSources("/semantic-version/position/position-head", + StatementParserMode.SEMVER_MODE); + assertNotNull(context); + + Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next(); + Module bar = context.findModuleByNamespace(new URI("bar")).iterator().next(); + Module semVer = context.findModuleByNamespace(new URI("urn:opendaylight:yang:extension:semantic-version")) + .iterator().next(); + + assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion()); + assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion()); + assertEquals(SemVer.valueOf("0.1.2"), bar.getSemanticVersion()); + } + + @Test + public void positionMiddleTest() throws SourceException, FileNotFoundException, ReactorException, + URISyntaxException { + SchemaContext context = StmtTestUtils.parseYangSources("/semantic-version/position/position-middle", + StatementParserMode.SEMVER_MODE); + assertNotNull(context); + + Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next(); + Module bar = context.findModuleByNamespace(new URI("bar")).iterator().next(); + Module semVer = context.findModuleByNamespace(new URI("urn:opendaylight:yang:extension:semantic-version")) + .iterator().next(); + + assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion()); + assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion()); + assertEquals(SemVer.valueOf("0.1.2"), bar.getSemanticVersion()); + } + + @Test + public void positiontailTest() throws SourceException, FileNotFoundException, ReactorException, URISyntaxException { + SchemaContext context = StmtTestUtils.parseYangSources("/semantic-version/position/position-tail", + StatementParserMode.SEMVER_MODE); + assertNotNull(context); + + Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next(); + Module bar = context.findModuleByNamespace(new URI("bar")).iterator().next(); + Module semVer = context.findModuleByNamespace(new URI("urn:opendaylight:yang:extension:semantic-version")) + .iterator().next(); + + assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion()); + assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion()); + assertEquals(SemVer.valueOf("0.1.2"), bar.getSemanticVersion()); + } +} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/semver/SemanticVersionTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/semver/SemanticVersionTest.java new file mode 100644 index 0000000000..e0bb3d004c --- /dev/null +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/semver/SemanticVersionTest.java @@ -0,0 +1,171 @@ +/* + * Copyright (c) 2016 Cisco Systems, Inc. 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.stmt.semver; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode; + +import java.io.FileNotFoundException; +import java.net.URI; +import java.net.URISyntaxException; +import org.junit.Test; +import org.opendaylight.yangtools.concepts.SemVer; +import org.opendaylight.yangtools.yang.common.QName; +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.SchemaNode; +import org.opendaylight.yangtools.yang.model.api.SchemaPath; +import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil; +import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; +import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; +import org.opendaylight.yangtools.yang.stmt.StmtTestUtils; + +public class SemanticVersionTest { + @Test + public void basicTest() throws SourceException, FileNotFoundException, ReactorException, URISyntaxException { + SchemaContext context = StmtTestUtils.parseYangSources("/semantic-version/basic", StatementParserMode.SEMVER_MODE); + assertNotNull(context); + + Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next(); + Module bar = context.findModuleByNamespace(new URI("bar")).iterator().next(); + Module semVer = context.findModuleByNamespace(new URI("urn:opendaylight:yang:extension:semantic-version")) + .iterator().next(); + + assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion()); + assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion()); + assertEquals(SemVer.valueOf("0.1.2"), bar.getSemanticVersion()); + } + + @Test + public void basicTest2() throws SourceException, FileNotFoundException, ReactorException, URISyntaxException { + SchemaContext context = StmtTestUtils.parseYangSources("/semantic-version/basic-2", StatementParserMode.SEMVER_MODE); + assertNotNull(context); + + Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next(); + Module bar = context.findModuleByNamespace(new URI("bar")).iterator().next(); + Module semVer = context.findModuleByNamespace(new URI("urn:opendaylight:yang:extension:semantic-version")) + .iterator().next(); + + assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion()); + assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion()); + assertEquals(SemVer.valueOf("0.1.2"), bar.getSemanticVersion()); + } + + @Test + public void basicTest3() throws SourceException, FileNotFoundException, ReactorException, URISyntaxException { + SchemaContext context = StmtTestUtils.parseYangSources("/semantic-version/basic-3", StatementParserMode.SEMVER_MODE); + assertNotNull(context); + + Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next(); + Module semVer = context.findModuleByNamespace(new URI("urn:opendaylight:yang:extension:semantic-version")) + .iterator().next(); + + assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion()); + assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion()); + } + + @Test + public void basicImportTest1() throws SourceException, FileNotFoundException, ReactorException, URISyntaxException { + SchemaContext context = StmtTestUtils.parseYangSources("/semantic-version/basic-import-1", + StatementParserMode.SEMVER_MODE); + assertNotNull(context); + + Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next(); + Module semVer = context.findModuleByNamespace(new URI("urn:opendaylight:yang:extension:semantic-version")) + .iterator().next(); + + assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion()); + assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion()); + Module bar = StmtTestUtils.findImportedModule(context, foo, "bar"); + assertEquals(SemVer.valueOf("0.1.2"), bar.getSemanticVersion()); + } + + @Test + public void multipleModulesTest() throws SourceException, FileNotFoundException, ReactorException, + URISyntaxException { + SchemaContext context = StmtTestUtils.parseYangSources("/semantic-version/multiple-modules", + StatementParserMode.SEMVER_MODE); + assertNotNull(context); + + Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next(); + Module semVer = context.findModuleByNamespace(new URI("urn:opendaylight:yang:extension:semantic-version")) + .iterator().next(); + + assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion()); + assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion()); + Module bar = StmtTestUtils.findImportedModule(context, foo, "bar"); + assertEquals(SemVer.valueOf("0.10.4"), bar.getSemanticVersion()); + } + + @Test + public void basicImportErrTest1() throws SourceException, FileNotFoundException, ReactorException, + URISyntaxException { + try { + StmtTestUtils.parseYangSources("/semantic-version/basic-import-invalid-1", StatementParserMode.SEMVER_MODE); + fail("Test should fail due to invalid semantic version"); + } catch (InferenceException e) { + assertTrue(e.getMessage() + .startsWith("Unable to find module compatible with requested import [bar(0.1.2)].")); + } + } + + @Test + public void basicImportErrTest2() throws SourceException, FileNotFoundException, ReactorException, + URISyntaxException { + try { + StmtTestUtils.parseYangSources("/semantic-version/basic-import-invalid-2", StatementParserMode.SEMVER_MODE); + fail("Test should fail due to invalid semantic version"); + } catch (InferenceException e) { + assertTrue(e.getMessage() + .startsWith("Unable to find module compatible with requested import [bar(0.1.2)].")); + } + } + + @Test + public void nodeTest() throws Exception { + SchemaContext context = StmtTestUtils.parseYangSources("/semantic-version/node-test", StatementParserMode.SEMVER_MODE); + assertNotNull(context); + + Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next(); + Module semVer = context.findModuleByNamespace(new URI("urn:opendaylight:yang:extension:semantic-version")) + .iterator().next(); + + assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion()); + assertEquals(SemVer.valueOf("2016.1.1"), foo.getSemanticVersion()); + Module bar = StmtTestUtils.findImportedModule(context, foo, "bar"); + assertEquals(SemVer.valueOf("2016.4.6"), bar.getSemanticVersion()); + + QName root = QName.create("foo", "2016-01-01", "foo-root"); + QName container20160404 = QName.create("foo", "2016-01-01", "con20160404"); + SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context, + SchemaPath.create(true, root, container20160404)); + assertTrue(findDataSchemaNode instanceof ContainerSchemaNode); + + QName container20160405 = QName.create("foo", "2016-01-01", "con20160405"); + findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context, + SchemaPath.create(true, root, container20160405)); + assertTrue(findDataSchemaNode instanceof ContainerSchemaNode); + + QName container20160406 = QName.create("foo", "2016-01-01", "con20160406"); + findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context, + SchemaPath.create(true, root, container20160406)); + assertTrue(findDataSchemaNode instanceof ContainerSchemaNode); + + QName container20170406 = QName.create("foo", "2016-01-01", "con20170406"); + findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context, + SchemaPath.create(true, root, container20170406)); + assertNull(findDataSchemaNode); + } +} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/semver/yin/YinSemanticVersionTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/semver/yin/YinSemanticVersionTest.java new file mode 100644 index 0000000000..d27ebf88cc --- /dev/null +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/semver/yin/YinSemanticVersionTest.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2016 Cisco Systems, Inc. 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.stmt.semver.yin; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode; + +import java.io.FileNotFoundException; +import java.net.URI; +import java.net.URISyntaxException; +import org.junit.Test; +import org.opendaylight.yangtools.concepts.SemVer; +import org.opendaylight.yangtools.yang.model.api.Module; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; +import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; +import org.opendaylight.yangtools.yang.stmt.StmtTestUtils; + +public class YinSemanticVersionTest { + + @Test + public void basicTest() throws SourceException, FileNotFoundException, ReactorException, URISyntaxException { + SchemaContext context = StmtTestUtils.parseYinSources("/semantic-version/yin-input/basic", + StatementParserMode.SEMVER_MODE); + assertNotNull(context); + + Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next(); + Module bar = context.findModuleByNamespace(new URI("bar")).iterator().next(); + Module semVer = context.findModuleByNamespace(new URI("urn:opendaylight:yang:extension:semantic-version")) + .iterator().next(); + + assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion()); + assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion()); + assertEquals(SemVer.valueOf("0.1.2"), bar.getSemanticVersion()); + } + + @Test + public void basicImportTest1() throws SourceException, FileNotFoundException, ReactorException, URISyntaxException { + SchemaContext context = StmtTestUtils.parseYinSources("/semantic-version/yin-input/basic-import", + StatementParserMode.SEMVER_MODE); + assertNotNull(context); + + Module foo = context.findModuleByNamespace(new URI("foo")).iterator().next(); + Module semVer = context.findModuleByNamespace(new URI("urn:opendaylight:yang:extension:semantic-version")) + .iterator().next(); + + assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion()); + assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion()); + Module bar = StmtTestUtils.findImportedModule(context, foo, "bar"); + assertEquals(SemVer.valueOf("0.1.2"), bar.getSemanticVersion()); + } + + @Test + public void basicImportErrTest1() throws SourceException, FileNotFoundException, ReactorException, + URISyntaxException { + try { + StmtTestUtils.parseYinSources("/semantic-version/yin-input/basic-import-invalid", StatementParserMode.SEMVER_MODE); + fail("Test should fail due to invalid semantic version"); + } catch (InferenceException e) { + assertTrue(e.getMessage() + .startsWith("Unable to find module compatible with requested import [bar(0.1.2)].")); + } + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/basic-2/bar.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/basic-2/bar.yang new file mode 100644 index 0000000000..5664e68ba9 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/basic-2/bar.yang @@ -0,0 +1,15 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02;} + + revision "2016-01-31" { + description "Initial version"; + } + sv:semantic-version "0.1.2"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/basic-2/foo.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/basic-2/foo.yang new file mode 100644 index 0000000000..01fe8e8905 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/basic-2/foo.yang @@ -0,0 +1,16 @@ +module foo { + namespace "foo"; + prefix foo; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02;} + import bar { prefix bar; revision-date 2016-01-31;} + + revision "2016-02-01" { + description "Initial version"; + } + sv:semantic-version "0.1.1"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/basic-2/semantic-version.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/basic-2/semantic-version.yang new file mode 100644 index 0000000000..dd92de6883 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/basic-2/semantic-version.yang @@ -0,0 +1,47 @@ +module semantic-version { + namespace "urn:opendaylight:yang:extension:semantic-version"; + prefix sv; + yang-version 1; + + revision 2016-02-02 { + description "Initial verison"; + } + sv:semantic-version "0.0.1"; + + extension semantic-version { + argument "semantic-version" { + yin-element false; + } + description + "The OpenConfig version number for the module. This is + expressed as a semantic version number of the form: + x.y.z + where: + * x corresponds to the major version, + * y corresponds to a minor version, + * z corresponds to a patch version. + This version corresponds to the model file within which it is + defined, and does not cover the whole set of OpenConfig models. + Where several modules are used to build up a single block of + functionality, the same module version is specified across each + file that makes up the module. + + A major version number of 0 indicates that this model is still + in development (whether within OpenConfig or with industry + partners), and is potentially subject to change. + + Following a release of major version 1, all modules will + increment major revision number where backwards incompatible + changes to the model are made. + + The minor version is changed when features are added to the + model that do not impact current clients use of the model. + + The patch-level version is incremented when non-feature changes + (such as bugfixes or clarifications to human-readable + descriptions that do not impact model functionality) are made + that maintain backwards compatibility. + + The version number is stored in the module meta-data."; + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/basic-3/foo.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/basic-3/foo.yang new file mode 100644 index 0000000000..537f5d7ac6 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/basic-3/foo.yang @@ -0,0 +1,15 @@ +module foo { + namespace "foo"; + prefix foo; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-02-01" { + description "Initial version"; + } + sv:semantic-version "0.1.1"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/basic-3/semantic-version.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/basic-3/semantic-version.yang new file mode 100644 index 0000000000..dd92de6883 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/basic-3/semantic-version.yang @@ -0,0 +1,47 @@ +module semantic-version { + namespace "urn:opendaylight:yang:extension:semantic-version"; + prefix sv; + yang-version 1; + + revision 2016-02-02 { + description "Initial verison"; + } + sv:semantic-version "0.0.1"; + + extension semantic-version { + argument "semantic-version" { + yin-element false; + } + description + "The OpenConfig version number for the module. This is + expressed as a semantic version number of the form: + x.y.z + where: + * x corresponds to the major version, + * y corresponds to a minor version, + * z corresponds to a patch version. + This version corresponds to the model file within which it is + defined, and does not cover the whole set of OpenConfig models. + Where several modules are used to build up a single block of + functionality, the same module version is specified across each + file that makes up the module. + + A major version number of 0 indicates that this model is still + in development (whether within OpenConfig or with industry + partners), and is potentially subject to change. + + Following a release of major version 1, all modules will + increment major revision number where backwards incompatible + changes to the model are made. + + The minor version is changed when features are added to the + model that do not impact current clients use of the model. + + The patch-level version is incremented when non-feature changes + (such as bugfixes or clarifications to human-readable + descriptions that do not impact model functionality) are made + that maintain backwards compatibility. + + The version number is stored in the module meta-data."; + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/basic-import-1/bar@2016-01-01.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/basic-import-1/bar@2016-01-01.yang new file mode 100644 index 0000000000..54da0db564 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/basic-import-1/bar@2016-01-01.yang @@ -0,0 +1,15 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-01-01" { + description "Initial version"; + } + sv:semantic-version "0.1.2"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/basic-import-1/bar@2016-01-31.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/basic-import-1/bar@2016-01-31.yang new file mode 100644 index 0000000000..e61a340d48 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/basic-import-1/bar@2016-01-31.yang @@ -0,0 +1,15 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-01-31" { + description "Initial version"; + } + sv:semantic-version "1.1.2"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/basic-import-1/foo.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/basic-import-1/foo.yang new file mode 100644 index 0000000000..220c9cc582 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/basic-import-1/foo.yang @@ -0,0 +1,16 @@ +module foo { + namespace "foo"; + prefix foo; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + import bar { prefix bar; sv:semantic-version "0.1.2";} + + revision "2016-02-01" { + description "Initial version"; + } + sv:semantic-version "0.1.1"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/basic-import-1/semantic-version.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/basic-import-1/semantic-version.yang new file mode 100644 index 0000000000..dd92de6883 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/basic-import-1/semantic-version.yang @@ -0,0 +1,47 @@ +module semantic-version { + namespace "urn:opendaylight:yang:extension:semantic-version"; + prefix sv; + yang-version 1; + + revision 2016-02-02 { + description "Initial verison"; + } + sv:semantic-version "0.0.1"; + + extension semantic-version { + argument "semantic-version" { + yin-element false; + } + description + "The OpenConfig version number for the module. This is + expressed as a semantic version number of the form: + x.y.z + where: + * x corresponds to the major version, + * y corresponds to a minor version, + * z corresponds to a patch version. + This version corresponds to the model file within which it is + defined, and does not cover the whole set of OpenConfig models. + Where several modules are used to build up a single block of + functionality, the same module version is specified across each + file that makes up the module. + + A major version number of 0 indicates that this model is still + in development (whether within OpenConfig or with industry + partners), and is potentially subject to change. + + Following a release of major version 1, all modules will + increment major revision number where backwards incompatible + changes to the model are made. + + The minor version is changed when features are added to the + model that do not impact current clients use of the model. + + The patch-level version is incremented when non-feature changes + (such as bugfixes or clarifications to human-readable + descriptions that do not impact model functionality) are made + that maintain backwards compatibility. + + The version number is stored in the module meta-data."; + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/basic-import-invalid-1/bar@2016-01-01.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/basic-import-invalid-1/bar@2016-01-01.yang new file mode 100644 index 0000000000..2e94728149 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/basic-import-invalid-1/bar@2016-01-01.yang @@ -0,0 +1,15 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-01-01" { + description "Initial version"; + } + sv:semantic-version "1.1.2"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/basic-import-invalid-1/bar@2016-01-31.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/basic-import-invalid-1/bar@2016-01-31.yang new file mode 100644 index 0000000000..d3d101b61b --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/basic-import-invalid-1/bar@2016-01-31.yang @@ -0,0 +1,15 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-01-31" { + description "Initial version"; + } + sv:semantic-version "1.1.3"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/basic-import-invalid-1/foo.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/basic-import-invalid-1/foo.yang new file mode 100644 index 0000000000..220c9cc582 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/basic-import-invalid-1/foo.yang @@ -0,0 +1,16 @@ +module foo { + namespace "foo"; + prefix foo; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + import bar { prefix bar; sv:semantic-version "0.1.2";} + + revision "2016-02-01" { + description "Initial version"; + } + sv:semantic-version "0.1.1"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/basic-import-invalid-1/semantic-version.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/basic-import-invalid-1/semantic-version.yang new file mode 100644 index 0000000000..dd92de6883 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/basic-import-invalid-1/semantic-version.yang @@ -0,0 +1,47 @@ +module semantic-version { + namespace "urn:opendaylight:yang:extension:semantic-version"; + prefix sv; + yang-version 1; + + revision 2016-02-02 { + description "Initial verison"; + } + sv:semantic-version "0.0.1"; + + extension semantic-version { + argument "semantic-version" { + yin-element false; + } + description + "The OpenConfig version number for the module. This is + expressed as a semantic version number of the form: + x.y.z + where: + * x corresponds to the major version, + * y corresponds to a minor version, + * z corresponds to a patch version. + This version corresponds to the model file within which it is + defined, and does not cover the whole set of OpenConfig models. + Where several modules are used to build up a single block of + functionality, the same module version is specified across each + file that makes up the module. + + A major version number of 0 indicates that this model is still + in development (whether within OpenConfig or with industry + partners), and is potentially subject to change. + + Following a release of major version 1, all modules will + increment major revision number where backwards incompatible + changes to the model are made. + + The minor version is changed when features are added to the + model that do not impact current clients use of the model. + + The patch-level version is incremented when non-feature changes + (such as bugfixes or clarifications to human-readable + descriptions that do not impact model functionality) are made + that maintain backwards compatibility. + + The version number is stored in the module meta-data."; + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/basic-import-invalid-2/bar.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/basic-import-invalid-2/bar.yang new file mode 100644 index 0000000000..e61a340d48 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/basic-import-invalid-2/bar.yang @@ -0,0 +1,15 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-01-31" { + description "Initial version"; + } + sv:semantic-version "1.1.2"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/basic-import-invalid-2/foo.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/basic-import-invalid-2/foo.yang new file mode 100644 index 0000000000..dda1144dff --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/basic-import-invalid-2/foo.yang @@ -0,0 +1,16 @@ +module foo { + namespace "foo"; + prefix foo; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + import bar { prefix bar; revision-date 2016-01-31; sv:semantic-version "0.1.2";} + + revision "2016-02-01" { + description "Initial version"; + } + sv:semantic-version "0.1.1"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/basic-import-invalid-2/semantic-version.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/basic-import-invalid-2/semantic-version.yang new file mode 100644 index 0000000000..dd92de6883 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/basic-import-invalid-2/semantic-version.yang @@ -0,0 +1,47 @@ +module semantic-version { + namespace "urn:opendaylight:yang:extension:semantic-version"; + prefix sv; + yang-version 1; + + revision 2016-02-02 { + description "Initial verison"; + } + sv:semantic-version "0.0.1"; + + extension semantic-version { + argument "semantic-version" { + yin-element false; + } + description + "The OpenConfig version number for the module. This is + expressed as a semantic version number of the form: + x.y.z + where: + * x corresponds to the major version, + * y corresponds to a minor version, + * z corresponds to a patch version. + This version corresponds to the model file within which it is + defined, and does not cover the whole set of OpenConfig models. + Where several modules are used to build up a single block of + functionality, the same module version is specified across each + file that makes up the module. + + A major version number of 0 indicates that this model is still + in development (whether within OpenConfig or with industry + partners), and is potentially subject to change. + + Following a release of major version 1, all modules will + increment major revision number where backwards incompatible + changes to the model are made. + + The minor version is changed when features are added to the + model that do not impact current clients use of the model. + + The patch-level version is incremented when non-feature changes + (such as bugfixes or clarifications to human-readable + descriptions that do not impact model functionality) are made + that maintain backwards compatibility. + + The version number is stored in the module meta-data."; + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/basic/bar.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/basic/bar.yang new file mode 100644 index 0000000000..2adc1363ba --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/basic/bar.yang @@ -0,0 +1,15 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-01-31" { + description "Initial version"; + } + sv:semantic-version "0.1.2"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/basic/foo.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/basic/foo.yang new file mode 100644 index 0000000000..dda1144dff --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/basic/foo.yang @@ -0,0 +1,16 @@ +module foo { + namespace "foo"; + prefix foo; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + import bar { prefix bar; revision-date 2016-01-31; sv:semantic-version "0.1.2";} + + revision "2016-02-01" { + description "Initial version"; + } + sv:semantic-version "0.1.1"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/basic/semantic-version.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/basic/semantic-version.yang new file mode 100644 index 0000000000..dd92de6883 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/basic/semantic-version.yang @@ -0,0 +1,47 @@ +module semantic-version { + namespace "urn:opendaylight:yang:extension:semantic-version"; + prefix sv; + yang-version 1; + + revision 2016-02-02 { + description "Initial verison"; + } + sv:semantic-version "0.0.1"; + + extension semantic-version { + argument "semantic-version" { + yin-element false; + } + description + "The OpenConfig version number for the module. This is + expressed as a semantic version number of the form: + x.y.z + where: + * x corresponds to the major version, + * y corresponds to a minor version, + * z corresponds to a patch version. + This version corresponds to the model file within which it is + defined, and does not cover the whole set of OpenConfig models. + Where several modules are used to build up a single block of + functionality, the same module version is specified across each + file that makes up the module. + + A major version number of 0 indicates that this model is still + in development (whether within OpenConfig or with industry + partners), and is potentially subject to change. + + Following a release of major version 1, all modules will + increment major revision number where backwards incompatible + changes to the model are made. + + The minor version is changed when features are added to the + model that do not impact current clients use of the model. + + The patch-level version is incremented when non-feature changes + (such as bugfixes or clarifications to human-readable + descriptions that do not impact model functionality) are made + that maintain backwards compatibility. + + The version number is stored in the module meta-data."; + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-invalid-major/bar@2016-01-01.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-invalid-major/bar@2016-01-01.yang new file mode 100644 index 0000000000..e016dde777 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-invalid-major/bar@2016-01-01.yang @@ -0,0 +1,15 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-01-01" { + description "Initial version"; + } + sv:semantic-version "2.5.5"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-invalid-major/bar@2016-01-02.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-invalid-major/bar@2016-01-02.yang new file mode 100644 index 0000000000..fa2cc103a5 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-invalid-major/bar@2016-01-02.yang @@ -0,0 +1,15 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-01-02" { + description "Initial version"; + } + sv:semantic-version "3.5.5"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-invalid-major/bar@2016-01-03.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-invalid-major/bar@2016-01-03.yang new file mode 100644 index 0000000000..8bbaa12721 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-invalid-major/bar@2016-01-03.yang @@ -0,0 +1,15 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-01-03" { + description "Initial version"; + } + sv:semantic-version "4.5.5"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-invalid-major/foo.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-invalid-major/foo.yang new file mode 100644 index 0000000000..c89c60d0df --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-invalid-major/foo.yang @@ -0,0 +1,16 @@ +module foo { + namespace "foo"; + prefix foo; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + import bar { prefix bar; sv:semantic-version "5.5.5"; } + + revision "2016-02-01" { + description "Initial version"; + } + sv:semantic-version "0.1.1"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-invalid-major/semantic-version.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-invalid-major/semantic-version.yang new file mode 100644 index 0000000000..dd92de6883 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-invalid-major/semantic-version.yang @@ -0,0 +1,47 @@ +module semantic-version { + namespace "urn:opendaylight:yang:extension:semantic-version"; + prefix sv; + yang-version 1; + + revision 2016-02-02 { + description "Initial verison"; + } + sv:semantic-version "0.0.1"; + + extension semantic-version { + argument "semantic-version" { + yin-element false; + } + description + "The OpenConfig version number for the module. This is + expressed as a semantic version number of the form: + x.y.z + where: + * x corresponds to the major version, + * y corresponds to a minor version, + * z corresponds to a patch version. + This version corresponds to the model file within which it is + defined, and does not cover the whole set of OpenConfig models. + Where several modules are used to build up a single block of + functionality, the same module version is specified across each + file that makes up the module. + + A major version number of 0 indicates that this model is still + in development (whether within OpenConfig or with industry + partners), and is potentially subject to change. + + Following a release of major version 1, all modules will + increment major revision number where backwards incompatible + changes to the model are made. + + The minor version is changed when features are added to the + model that do not impact current clients use of the model. + + The patch-level version is incremented when non-feature changes + (such as bugfixes or clarifications to human-readable + descriptions that do not impact model functionality) are made + that maintain backwards compatibility. + + The version number is stored in the module meta-data."; + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-invalid-minor/bar@2016-01-01.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-invalid-minor/bar@2016-01-01.yang new file mode 100644 index 0000000000..06c3e48f38 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-invalid-minor/bar@2016-01-01.yang @@ -0,0 +1,15 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-01-01" { + description "Initial version"; + } + sv:semantic-version "5.2.5"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-invalid-minor/bar@2016-01-02.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-invalid-minor/bar@2016-01-02.yang new file mode 100644 index 0000000000..0b59caee3a --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-invalid-minor/bar@2016-01-02.yang @@ -0,0 +1,15 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-01-02" { + description "Initial version"; + } + sv:semantic-version "5.3.5"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-invalid-minor/bar@2016-01-03.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-invalid-minor/bar@2016-01-03.yang new file mode 100644 index 0000000000..4826af89a6 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-invalid-minor/bar@2016-01-03.yang @@ -0,0 +1,15 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-01-03" { + description "Initial version"; + } + sv:semantic-version "5.4.5"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-invalid-minor/foo.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-invalid-minor/foo.yang new file mode 100644 index 0000000000..c89c60d0df --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-invalid-minor/foo.yang @@ -0,0 +1,16 @@ +module foo { + namespace "foo"; + prefix foo; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + import bar { prefix bar; sv:semantic-version "5.5.5"; } + + revision "2016-02-01" { + description "Initial version"; + } + sv:semantic-version "0.1.1"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-invalid-minor/semantic-version.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-invalid-minor/semantic-version.yang new file mode 100644 index 0000000000..dd92de6883 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-invalid-minor/semantic-version.yang @@ -0,0 +1,47 @@ +module semantic-version { + namespace "urn:opendaylight:yang:extension:semantic-version"; + prefix sv; + yang-version 1; + + revision 2016-02-02 { + description "Initial verison"; + } + sv:semantic-version "0.0.1"; + + extension semantic-version { + argument "semantic-version" { + yin-element false; + } + description + "The OpenConfig version number for the module. This is + expressed as a semantic version number of the form: + x.y.z + where: + * x corresponds to the major version, + * y corresponds to a minor version, + * z corresponds to a patch version. + This version corresponds to the model file within which it is + defined, and does not cover the whole set of OpenConfig models. + Where several modules are used to build up a single block of + functionality, the same module version is specified across each + file that makes up the module. + + A major version number of 0 indicates that this model is still + in development (whether within OpenConfig or with industry + partners), and is potentially subject to change. + + Following a release of major version 1, all modules will + increment major revision number where backwards incompatible + changes to the model are made. + + The minor version is changed when features are added to the + model that do not impact current clients use of the model. + + The patch-level version is incremented when non-feature changes + (such as bugfixes or clarifications to human-readable + descriptions that do not impact model functionality) are made + that maintain backwards compatibility. + + The version number is stored in the module meta-data."; + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-invalid-patch/bar@2016-01-01.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-invalid-patch/bar@2016-01-01.yang new file mode 100644 index 0000000000..f6dd765b7f --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-invalid-patch/bar@2016-01-01.yang @@ -0,0 +1,15 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-01-01" { + description "Initial version"; + } + sv:semantic-version "5.5.2"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-invalid-patch/bar@2016-01-02.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-invalid-patch/bar@2016-01-02.yang new file mode 100644 index 0000000000..1398079f2c --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-invalid-patch/bar@2016-01-02.yang @@ -0,0 +1,15 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-01-02" { + description "Initial version"; + } + sv:semantic-version "5.5.3"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-invalid-patch/bar@2016-01-03.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-invalid-patch/bar@2016-01-03.yang new file mode 100644 index 0000000000..714f1de10b --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-invalid-patch/bar@2016-01-03.yang @@ -0,0 +1,15 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-01-03" { + description "Initial version"; + } + sv:semantic-version "5.5.4"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-invalid-patch/foo.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-invalid-patch/foo.yang new file mode 100644 index 0000000000..c89c60d0df --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-invalid-patch/foo.yang @@ -0,0 +1,16 @@ +module foo { + namespace "foo"; + prefix foo; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + import bar { prefix bar; sv:semantic-version "5.5.5"; } + + revision "2016-02-01" { + description "Initial version"; + } + sv:semantic-version "0.1.1"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-invalid-patch/semantic-version.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-invalid-patch/semantic-version.yang new file mode 100644 index 0000000000..dd92de6883 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-invalid-patch/semantic-version.yang @@ -0,0 +1,47 @@ +module semantic-version { + namespace "urn:opendaylight:yang:extension:semantic-version"; + prefix sv; + yang-version 1; + + revision 2016-02-02 { + description "Initial verison"; + } + sv:semantic-version "0.0.1"; + + extension semantic-version { + argument "semantic-version" { + yin-element false; + } + description + "The OpenConfig version number for the module. This is + expressed as a semantic version number of the form: + x.y.z + where: + * x corresponds to the major version, + * y corresponds to a minor version, + * z corresponds to a patch version. + This version corresponds to the model file within which it is + defined, and does not cover the whole set of OpenConfig models. + Where several modules are used to build up a single block of + functionality, the same module version is specified across each + file that makes up the module. + + A major version number of 0 indicates that this model is still + in development (whether within OpenConfig or with industry + partners), and is potentially subject to change. + + Following a release of major version 1, all modules will + increment major revision number where backwards incompatible + changes to the model are made. + + The minor version is changed when features are added to the + model that do not impact current clients use of the model. + + The patch-level version is incremented when non-feature changes + (such as bugfixes or clarifications to human-readable + descriptions that do not impact model functionality) are made + that maintain backwards compatibility. + + The version number is stored in the module meta-data."; + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-valid-major/bar@2016-01-01.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-valid-major/bar@2016-01-01.yang new file mode 100644 index 0000000000..c331b9ec67 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-valid-major/bar@2016-01-01.yang @@ -0,0 +1,15 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-01-01" { + description "Initial version"; + } + sv:semantic-version "4.5.5"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-valid-major/bar@2016-01-02.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-valid-major/bar@2016-01-02.yang new file mode 100644 index 0000000000..920c18af50 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-valid-major/bar@2016-01-02.yang @@ -0,0 +1,15 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-01-02" { + description "Initial version"; + } + sv:semantic-version "5.5.5"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-valid-major/bar@2016-01-03.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-valid-major/bar@2016-01-03.yang new file mode 100644 index 0000000000..f04a98e343 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-valid-major/bar@2016-01-03.yang @@ -0,0 +1,15 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-01-03" { + description "Initial version"; + } + sv:semantic-version "6.5.5"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-valid-major/foo.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-valid-major/foo.yang new file mode 100644 index 0000000000..c89c60d0df --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-valid-major/foo.yang @@ -0,0 +1,16 @@ +module foo { + namespace "foo"; + prefix foo; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + import bar { prefix bar; sv:semantic-version "5.5.5"; } + + revision "2016-02-01" { + description "Initial version"; + } + sv:semantic-version "0.1.1"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-valid-major/semantic-version.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-valid-major/semantic-version.yang new file mode 100644 index 0000000000..dd92de6883 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-valid-major/semantic-version.yang @@ -0,0 +1,47 @@ +module semantic-version { + namespace "urn:opendaylight:yang:extension:semantic-version"; + prefix sv; + yang-version 1; + + revision 2016-02-02 { + description "Initial verison"; + } + sv:semantic-version "0.0.1"; + + extension semantic-version { + argument "semantic-version" { + yin-element false; + } + description + "The OpenConfig version number for the module. This is + expressed as a semantic version number of the form: + x.y.z + where: + * x corresponds to the major version, + * y corresponds to a minor version, + * z corresponds to a patch version. + This version corresponds to the model file within which it is + defined, and does not cover the whole set of OpenConfig models. + Where several modules are used to build up a single block of + functionality, the same module version is specified across each + file that makes up the module. + + A major version number of 0 indicates that this model is still + in development (whether within OpenConfig or with industry + partners), and is potentially subject to change. + + Following a release of major version 1, all modules will + increment major revision number where backwards incompatible + changes to the model are made. + + The minor version is changed when features are added to the + model that do not impact current clients use of the model. + + The patch-level version is incremented when non-feature changes + (such as bugfixes or clarifications to human-readable + descriptions that do not impact model functionality) are made + that maintain backwards compatibility. + + The version number is stored in the module meta-data."; + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-valid-minor/bar@2016-01-01.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-valid-minor/bar@2016-01-01.yang new file mode 100644 index 0000000000..c129995474 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-valid-minor/bar@2016-01-01.yang @@ -0,0 +1,15 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-01-01" { + description "Initial version"; + } + sv:semantic-version "5.4.5"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-valid-minor/bar@2016-01-02.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-valid-minor/bar@2016-01-02.yang new file mode 100644 index 0000000000..920c18af50 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-valid-minor/bar@2016-01-02.yang @@ -0,0 +1,15 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-01-02" { + description "Initial version"; + } + sv:semantic-version "5.5.5"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-valid-minor/bar@2016-01-03.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-valid-minor/bar@2016-01-03.yang new file mode 100644 index 0000000000..da8327c89d --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-valid-minor/bar@2016-01-03.yang @@ -0,0 +1,15 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-01-03" { + description "Initial version"; + } + sv:semantic-version "5.6.5"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-valid-minor/foo.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-valid-minor/foo.yang new file mode 100644 index 0000000000..c89c60d0df --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-valid-minor/foo.yang @@ -0,0 +1,16 @@ +module foo { + namespace "foo"; + prefix foo; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + import bar { prefix bar; sv:semantic-version "5.5.5"; } + + revision "2016-02-01" { + description "Initial version"; + } + sv:semantic-version "0.1.1"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-valid-minor/semantic-version.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-valid-minor/semantic-version.yang new file mode 100644 index 0000000000..dd92de6883 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-valid-minor/semantic-version.yang @@ -0,0 +1,47 @@ +module semantic-version { + namespace "urn:opendaylight:yang:extension:semantic-version"; + prefix sv; + yang-version 1; + + revision 2016-02-02 { + description "Initial verison"; + } + sv:semantic-version "0.0.1"; + + extension semantic-version { + argument "semantic-version" { + yin-element false; + } + description + "The OpenConfig version number for the module. This is + expressed as a semantic version number of the form: + x.y.z + where: + * x corresponds to the major version, + * y corresponds to a minor version, + * z corresponds to a patch version. + This version corresponds to the model file within which it is + defined, and does not cover the whole set of OpenConfig models. + Where several modules are used to build up a single block of + functionality, the same module version is specified across each + file that makes up the module. + + A major version number of 0 indicates that this model is still + in development (whether within OpenConfig or with industry + partners), and is potentially subject to change. + + Following a release of major version 1, all modules will + increment major revision number where backwards incompatible + changes to the model are made. + + The minor version is changed when features are added to the + model that do not impact current clients use of the model. + + The patch-level version is incremented when non-feature changes + (such as bugfixes or clarifications to human-readable + descriptions that do not impact model functionality) are made + that maintain backwards compatibility. + + The version number is stored in the module meta-data."; + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-valid-patch/bar@2016-01-01.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-valid-patch/bar@2016-01-01.yang new file mode 100644 index 0000000000..939c7e81fd --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-valid-patch/bar@2016-01-01.yang @@ -0,0 +1,15 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-01-01" { + description "Initial version"; + } + sv:semantic-version "5.5.4"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-valid-patch/bar@2016-01-02.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-valid-patch/bar@2016-01-02.yang new file mode 100644 index 0000000000..920c18af50 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-valid-patch/bar@2016-01-02.yang @@ -0,0 +1,15 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-01-02" { + description "Initial version"; + } + sv:semantic-version "5.5.5"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-valid-patch/bar@2016-01-03.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-valid-patch/bar@2016-01-03.yang new file mode 100644 index 0000000000..5d3f96d0ff --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-valid-patch/bar@2016-01-03.yang @@ -0,0 +1,15 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-01-03" { + description "Initial version"; + } + sv:semantic-version "5.5.6"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-valid-patch/foo.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-valid-patch/foo.yang new file mode 100644 index 0000000000..c89c60d0df --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-valid-patch/foo.yang @@ -0,0 +1,16 @@ +module foo { + namespace "foo"; + prefix foo; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + import bar { prefix bar; sv:semantic-version "5.5.5"; } + + revision "2016-02-01" { + description "Initial version"; + } + sv:semantic-version "0.1.1"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-valid-patch/semantic-version.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-valid-patch/semantic-version.yang new file mode 100644 index 0000000000..dd92de6883 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/border-case/border-case-valid-patch/semantic-version.yang @@ -0,0 +1,47 @@ +module semantic-version { + namespace "urn:opendaylight:yang:extension:semantic-version"; + prefix sv; + yang-version 1; + + revision 2016-02-02 { + description "Initial verison"; + } + sv:semantic-version "0.0.1"; + + extension semantic-version { + argument "semantic-version" { + yin-element false; + } + description + "The OpenConfig version number for the module. This is + expressed as a semantic version number of the form: + x.y.z + where: + * x corresponds to the major version, + * y corresponds to a minor version, + * z corresponds to a patch version. + This version corresponds to the model file within which it is + defined, and does not cover the whole set of OpenConfig models. + Where several modules are used to build up a single block of + functionality, the same module version is specified across each + file that makes up the module. + + A major version number of 0 indicates that this model is still + in development (whether within OpenConfig or with industry + partners), and is potentially subject to change. + + Following a release of major version 1, all modules will + increment major revision number where backwards incompatible + changes to the model are made. + + The minor version is changed when features are added to the + model that do not impact current clients use of the model. + + The patch-level version is incremented when non-feature changes + (such as bugfixes or clarifications to human-readable + descriptions that do not impact model functionality) are made + that maintain backwards compatibility. + + The version number is stored in the module meta-data."; + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/complex/complex-1/bar@2016-01-03.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/complex/complex-1/bar@2016-01-03.yang new file mode 100644 index 0000000000..a7b14f1dfe --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/complex/complex-1/bar@2016-01-03.yang @@ -0,0 +1,24 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; sv:semantic-version "1.2.012"; } + import foobar { prefix foobar; sv:semantic-version "2.25.3"; } + + revision "2016-01-03" { + description "Imported version"; + } + sv:semantic-version "1.2.6"; + + container root { + container test-container { + uses foobar:test-grouping; + } + } + + leaf-list should-present { + type string; + description "List of strings"; + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/complex/complex-1/bar@2016-01-04.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/complex/complex-1/bar@2016-01-04.yang new file mode 100644 index 0000000000..eaff86f9c6 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/complex/complex-1/bar@2016-01-04.yang @@ -0,0 +1,24 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; sv:semantic-version "1.2.210"; } + import foobar { prefix foobar; sv:semantic-version "2.25.3"; } + + revision "2016-01-04" { + description "Not-imported version"; + } + sv:semantic-version "2.200.200"; + + container root { + container test-container { + uses foobar:test-grouping; + } + } + + leaf-list should-not-be-present { + type uint32; + description "List of integers"; + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/complex/complex-1/foo.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/complex/complex-1/foo.yang new file mode 100644 index 0000000000..bce4b87d0b --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/complex/complex-1/foo.yang @@ -0,0 +1,13 @@ +module foo { + namespace "foo"; + prefix foo; + yang-version 1; + + import semantic-version { prefix sv; sv:semantic-version "1.0.0"; } + import bar { prefix bar; sv:semantic-version "1.2.5"; } + + revision "2016-02-01" { + description "Initial version"; + } + sv:semantic-version "1.50.02"; +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/complex/complex-1/foobar@2016-01-31.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/complex/complex-1/foobar@2016-01-31.yang new file mode 100644 index 0000000000..6efe81dfc9 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/complex/complex-1/foobar@2016-01-31.yang @@ -0,0 +1,23 @@ +module foobar { + namespace "foobar"; + prefix foobar; + yang-version 1; + + import semantic-version { prefix sv; sv:semantic-version "1.2.95"; } + + revision "2016-01-31" { + description "Not-imported version"; + } + sv:semantic-version "2.25.2"; + + grouping test-grouping { + leaf name { + type string; + description "Name"; + } + leaf oldnumber { + type uint8; + description "Old number"; + } + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/complex/complex-1/foobar@2016-02-28.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/complex/complex-1/foobar@2016-02-28.yang new file mode 100644 index 0000000000..867d25eb0b --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/complex/complex-1/foobar@2016-02-28.yang @@ -0,0 +1,23 @@ +module foobar { + namespace "foobar"; + prefix foobar; + yang-version 1; + + import semantic-version { prefix sv; sv:semantic-version "1.3.95"; } + + revision "2016-02-28" { + description "Imported version"; + } + sv:semantic-version "2.26.465"; + + grouping test-grouping { + leaf name { + type string; + description "Name"; + } + leaf number { + type uint32; + description "Number"; + } + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/complex/complex-1/semantic-version.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/complex/complex-1/semantic-version.yang new file mode 100644 index 0000000000..a8de91cac2 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/complex/complex-1/semantic-version.yang @@ -0,0 +1,47 @@ +module semantic-version { + namespace "urn:opendaylight:yang:extension:semantic-version"; + prefix sv; + yang-version 1; + + revision 2016-02-02 { + description "Initial verison"; + } + sv:semantic-version "1.3.95"; + + extension semantic-version { + argument "semantic-version" { + yin-element false; + } + description + "The OpenConfig version number for the module. This is + expressed as a semantic version number of the form: + x.y.z + where: + * x corresponds to the major version, + * y corresponds to a minor version, + * z corresponds to a patch version. + This version corresponds to the model file within which it is + defined, and does not cover the whole set of OpenConfig models. + Where several modules are used to build up a single block of + functionality, the same module version is specified across each + file that makes up the module. + + A major version number of 0 indicates that this model is still + in development (whether within OpenConfig or with industry + partners), and is potentially subject to change. + + Following a release of major version 1, all modules will + increment major revision number where backwards incompatible + changes to the model are made. + + The minor version is changed when features are added to the + model that do not impact current clients use of the model. + + The patch-level version is incremented when non-feature changes + (such as bugfixes or clarifications to human-readable + descriptions that do not impact model functionality) are made + that maintain backwards compatibility. + + The version number is stored in the module meta-data."; + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/complex/complex-2/bar@2016-01-03.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/complex/complex-2/bar@2016-01-03.yang new file mode 100644 index 0000000000..f11bdb0943 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/complex/complex-2/bar@2016-01-03.yang @@ -0,0 +1,23 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; sv:semantic-version "2.0.40"; } + import foobar { prefix foobar; sv:semantic-version "7.12.54"; } + + revision "2016-01-03" { + description "Imported version"; + } + sv:semantic-version "4.9.8"; + + augment "/foobar:root/foobar:test-container" { + leaf should-present-leaf-1 { + type string; + } + leaf should-present-leaf-2 { + type uint8; + default 0; + } + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/complex/complex-2/bar@2016-01-04.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/complex/complex-2/bar@2016-01-04.yang new file mode 100644 index 0000000000..1066b8a9b6 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/complex/complex-2/bar@2016-01-04.yang @@ -0,0 +1,23 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; sv:semantic-version "2.0.50"; } + import foobar { prefix foobar; sv:semantic-version "7.12.54"; } + + revision "2016-01-04" { + description "Not-imported version"; + } + sv:semantic-version "3.0.5"; + + augment "/foobar:root/foobar:test-container" { + leaf should-not-be-present-leaf-1 { + type string; + } + leaf should-not-be-present-leaf-2 { + type uint8; + default 0; + } + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/complex/complex-2/foo.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/complex/complex-2/foo.yang new file mode 100644 index 0000000000..5be60d8920 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/complex/complex-2/foo.yang @@ -0,0 +1,13 @@ +module foo { + namespace "foo"; + prefix foo; + yang-version 1; + + import semantic-version { prefix sv; sv:semantic-version "2.5.40"; } + import bar { prefix bar; sv:semantic-version "4.1.1"; } + + revision "2016-02-01" { + description "Initial version"; + } + sv:semantic-version "2.32.2"; +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/complex/complex-2/foobar@2016-01-31.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/complex/complex-2/foobar@2016-01-31.yang new file mode 100644 index 0000000000..435bea628d --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/complex/complex-2/foobar@2016-01-31.yang @@ -0,0 +1,20 @@ +module foobar { + namespace "foobar"; + prefix foobar; + yang-version 1; + + import semantic-version { prefix sv; sv:semantic-version "2.1.950"; } + + revision "2016-01-31" { + description "Not-imported version"; + } + sv:semantic-version "8.0.0"; + + container root { + leaf included-not-correct-mark { + type empty; + } + container test-container { + } + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/complex/complex-2/foobar@2016-02-27.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/complex/complex-2/foobar@2016-02-27.yang new file mode 100644 index 0000000000..8b8f48e1a7 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/complex/complex-2/foobar@2016-02-27.yang @@ -0,0 +1,20 @@ +module foobar { + namespace "foobar"; + prefix foobar; + yang-version 1; + + import semantic-version { prefix sv; sv:semantic-version "2.5.50"; } + + revision "2016-02-27" { + description "Not-imported version"; + } + sv:semantic-version "7.13.0"; + + container root { + leaf included-not-correct-mark { + type empty; + } + container test-container { + } + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/complex/complex-2/foobar@2016-02-28.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/complex/complex-2/foobar@2016-02-28.yang new file mode 100644 index 0000000000..c45a020a52 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/complex/complex-2/foobar@2016-02-28.yang @@ -0,0 +1,20 @@ +module foobar { + namespace "foobar"; + prefix foobar; + yang-version 1; + + import semantic-version { prefix sv; sv:semantic-version "2.5.50"; } + + revision "2016-02-28" { + description "Imported version"; + } + sv:semantic-version "7.13.99"; + + container root { + leaf included-correct-mark { + type empty; + } + container test-container { + } + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/complex/complex-2/semantic-version.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/complex/complex-2/semantic-version.yang new file mode 100644 index 0000000000..a7e5ba2a62 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/complex/complex-2/semantic-version.yang @@ -0,0 +1,47 @@ +module semantic-version { + namespace "urn:opendaylight:yang:extension:semantic-version"; + prefix sv; + yang-version 1; + + revision 2016-02-02 { + description "Initial verison"; + } + sv:semantic-version "2.5.50"; + + extension semantic-version { + argument "semantic-version" { + yin-element false; + } + description + "The OpenConfig version number for the module. This is + expressed as a semantic version number of the form: + x.y.z + where: + * x corresponds to the major version, + * y corresponds to a minor version, + * z corresponds to a patch version. + This version corresponds to the model file within which it is + defined, and does not cover the whole set of OpenConfig models. + Where several modules are used to build up a single block of + functionality, the same module version is specified across each + file that makes up the module. + + A major version number of 0 indicates that this model is still + in development (whether within OpenConfig or with industry + partners), and is potentially subject to change. + + Following a release of major version 1, all modules will + increment major revision number where backwards incompatible + changes to the model are made. + + The minor version is changed when features are added to the + model that do not impact current clients use of the model. + + The patch-level version is incremented when non-feature changes + (such as bugfixes or clarifications to human-readable + descriptions that do not impact model functionality) are made + that maintain backwards compatibility. + + The version number is stored in the module meta-data."; + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/defaults/default-major-invalid/bar.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/defaults/default-major-invalid/bar.yang new file mode 100644 index 0000000000..e7fe6096d5 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/defaults/default-major-invalid/bar.yang @@ -0,0 +1,15 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-01-31" { + description "Initial version"; + } + sv:semantic-version "1.0.0"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/defaults/default-major-invalid/foo.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/defaults/default-major-invalid/foo.yang new file mode 100644 index 0000000000..e81c79130b --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/defaults/default-major-invalid/foo.yang @@ -0,0 +1,15 @@ +module foo { + namespace "foo"; + prefix foo; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + import bar { prefix bar; revision-date 2016-01-31; } + + revision "2016-02-01" { + description "Initial version"; + } + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/defaults/default-major-invalid/semantic-version.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/defaults/default-major-invalid/semantic-version.yang new file mode 100644 index 0000000000..dd92de6883 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/defaults/default-major-invalid/semantic-version.yang @@ -0,0 +1,47 @@ +module semantic-version { + namespace "urn:opendaylight:yang:extension:semantic-version"; + prefix sv; + yang-version 1; + + revision 2016-02-02 { + description "Initial verison"; + } + sv:semantic-version "0.0.1"; + + extension semantic-version { + argument "semantic-version" { + yin-element false; + } + description + "The OpenConfig version number for the module. This is + expressed as a semantic version number of the form: + x.y.z + where: + * x corresponds to the major version, + * y corresponds to a minor version, + * z corresponds to a patch version. + This version corresponds to the model file within which it is + defined, and does not cover the whole set of OpenConfig models. + Where several modules are used to build up a single block of + functionality, the same module version is specified across each + file that makes up the module. + + A major version number of 0 indicates that this model is still + in development (whether within OpenConfig or with industry + partners), and is potentially subject to change. + + Following a release of major version 1, all modules will + increment major revision number where backwards incompatible + changes to the model are made. + + The minor version is changed when features are added to the + model that do not impact current clients use of the model. + + The patch-level version is incremented when non-feature changes + (such as bugfixes or clarifications to human-readable + descriptions that do not impact model functionality) are made + that maintain backwards compatibility. + + The version number is stored in the module meta-data."; + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/defaults/default-major-valid/bar.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/defaults/default-major-valid/bar.yang new file mode 100644 index 0000000000..678f4f60e9 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/defaults/default-major-valid/bar.yang @@ -0,0 +1,15 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-01-31" { + description "Initial version"; + } + sv:semantic-version "0.99.99"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/defaults/default-major-valid/foo.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/defaults/default-major-valid/foo.yang new file mode 100644 index 0000000000..e81c79130b --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/defaults/default-major-valid/foo.yang @@ -0,0 +1,15 @@ +module foo { + namespace "foo"; + prefix foo; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + import bar { prefix bar; revision-date 2016-01-31; } + + revision "2016-02-01" { + description "Initial version"; + } + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/defaults/default-major-valid/semantic-version.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/defaults/default-major-valid/semantic-version.yang new file mode 100644 index 0000000000..dd92de6883 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/defaults/default-major-valid/semantic-version.yang @@ -0,0 +1,47 @@ +module semantic-version { + namespace "urn:opendaylight:yang:extension:semantic-version"; + prefix sv; + yang-version 1; + + revision 2016-02-02 { + description "Initial verison"; + } + sv:semantic-version "0.0.1"; + + extension semantic-version { + argument "semantic-version" { + yin-element false; + } + description + "The OpenConfig version number for the module. This is + expressed as a semantic version number of the form: + x.y.z + where: + * x corresponds to the major version, + * y corresponds to a minor version, + * z corresponds to a patch version. + This version corresponds to the model file within which it is + defined, and does not cover the whole set of OpenConfig models. + Where several modules are used to build up a single block of + functionality, the same module version is specified across each + file that makes up the module. + + A major version number of 0 indicates that this model is still + in development (whether within OpenConfig or with industry + partners), and is potentially subject to change. + + Following a release of major version 1, all modules will + increment major revision number where backwards incompatible + changes to the model are made. + + The minor version is changed when features are added to the + model that do not impact current clients use of the model. + + The patch-level version is incremented when non-feature changes + (such as bugfixes or clarifications to human-readable + descriptions that do not impact model functionality) are made + that maintain backwards compatibility. + + The version number is stored in the module meta-data."; + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/defaults/defaults/bar.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/defaults/defaults/bar.yang new file mode 100644 index 0000000000..7dedebe1c3 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/defaults/defaults/bar.yang @@ -0,0 +1,12 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + revision "2016-01-31" { + description "Initial version"; + } + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/defaults/defaults/foo.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/defaults/defaults/foo.yang new file mode 100644 index 0000000000..005e06a8a9 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/defaults/defaults/foo.yang @@ -0,0 +1,14 @@ +module foo { + namespace "foo"; + prefix foo; + yang-version 1; + + import bar { prefix bar; revision-date 2016-01-31; } + + revision "2016-02-01" { + description "Initial version"; + } + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/ignoring-revision-2/bar@2016-01-01.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/ignoring-revision-2/bar@2016-01-01.yang new file mode 100644 index 0000000000..54da0db564 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/ignoring-revision-2/bar@2016-01-01.yang @@ -0,0 +1,15 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-01-01" { + description "Initial version"; + } + sv:semantic-version "0.1.2"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/ignoring-revision-2/bar@2016-01-31.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/ignoring-revision-2/bar@2016-01-31.yang new file mode 100644 index 0000000000..e61a340d48 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/ignoring-revision-2/bar@2016-01-31.yang @@ -0,0 +1,15 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-01-31" { + description "Initial version"; + } + sv:semantic-version "1.1.2"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/ignoring-revision-2/foo.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/ignoring-revision-2/foo.yang new file mode 100644 index 0000000000..dda1144dff --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/ignoring-revision-2/foo.yang @@ -0,0 +1,16 @@ +module foo { + namespace "foo"; + prefix foo; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + import bar { prefix bar; revision-date 2016-01-31; sv:semantic-version "0.1.2";} + + revision "2016-02-01" { + description "Initial version"; + } + sv:semantic-version "0.1.1"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/ignoring-revision-2/semantic-version.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/ignoring-revision-2/semantic-version.yang new file mode 100644 index 0000000000..dd92de6883 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/ignoring-revision-2/semantic-version.yang @@ -0,0 +1,47 @@ +module semantic-version { + namespace "urn:opendaylight:yang:extension:semantic-version"; + prefix sv; + yang-version 1; + + revision 2016-02-02 { + description "Initial verison"; + } + sv:semantic-version "0.0.1"; + + extension semantic-version { + argument "semantic-version" { + yin-element false; + } + description + "The OpenConfig version number for the module. This is + expressed as a semantic version number of the form: + x.y.z + where: + * x corresponds to the major version, + * y corresponds to a minor version, + * z corresponds to a patch version. + This version corresponds to the model file within which it is + defined, and does not cover the whole set of OpenConfig models. + Where several modules are used to build up a single block of + functionality, the same module version is specified across each + file that makes up the module. + + A major version number of 0 indicates that this model is still + in development (whether within OpenConfig or with industry + partners), and is potentially subject to change. + + Following a release of major version 1, all modules will + increment major revision number where backwards incompatible + changes to the model are made. + + The minor version is changed when features are added to the + model that do not impact current clients use of the model. + + The patch-level version is incremented when non-feature changes + (such as bugfixes or clarifications to human-readable + descriptions that do not impact model functionality) are made + that maintain backwards compatibility. + + The version number is stored in the module meta-data."; + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/ignoring-revision/bar@2016-01-01.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/ignoring-revision/bar@2016-01-01.yang new file mode 100644 index 0000000000..54da0db564 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/ignoring-revision/bar@2016-01-01.yang @@ -0,0 +1,15 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-01-01" { + description "Initial version"; + } + sv:semantic-version "0.1.2"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/ignoring-revision/foo.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/ignoring-revision/foo.yang new file mode 100644 index 0000000000..dda1144dff --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/ignoring-revision/foo.yang @@ -0,0 +1,16 @@ +module foo { + namespace "foo"; + prefix foo; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + import bar { prefix bar; revision-date 2016-01-31; sv:semantic-version "0.1.2";} + + revision "2016-02-01" { + description "Initial version"; + } + sv:semantic-version "0.1.1"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/ignoring-revision/semantic-version.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/ignoring-revision/semantic-version.yang new file mode 100644 index 0000000000..dd92de6883 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/ignoring-revision/semantic-version.yang @@ -0,0 +1,47 @@ +module semantic-version { + namespace "urn:opendaylight:yang:extension:semantic-version"; + prefix sv; + yang-version 1; + + revision 2016-02-02 { + description "Initial verison"; + } + sv:semantic-version "0.0.1"; + + extension semantic-version { + argument "semantic-version" { + yin-element false; + } + description + "The OpenConfig version number for the module. This is + expressed as a semantic version number of the form: + x.y.z + where: + * x corresponds to the major version, + * y corresponds to a minor version, + * z corresponds to a patch version. + This version corresponds to the model file within which it is + defined, and does not cover the whole set of OpenConfig models. + Where several modules are used to build up a single block of + functionality, the same module version is specified across each + file that makes up the module. + + A major version number of 0 indicates that this model is still + in development (whether within OpenConfig or with industry + partners), and is potentially subject to change. + + Following a release of major version 1, all modules will + increment major revision number where backwards incompatible + changes to the model are made. + + The minor version is changed when features are added to the + model that do not impact current clients use of the model. + + The patch-level version is incremented when non-feature changes + (such as bugfixes or clarifications to human-readable + descriptions that do not impact model functionality) are made + that maintain backwards compatibility. + + The version number is stored in the module meta-data."; + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/import/import-invalid-deprecated-1/foo.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/import/import-invalid-deprecated-1/foo.yang new file mode 100644 index 0000000000..a6c665bd3e --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/import/import-invalid-deprecated-1/foo.yang @@ -0,0 +1,14 @@ +module foo { + namespace "foo"; + prefix foo; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "1.0.0"; } + + revision "2016-02-01" { + description "Initial version"; + } + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/import/import-invalid-deprecated-1/semantic-version.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/import/import-invalid-deprecated-1/semantic-version.yang new file mode 100644 index 0000000000..ca9b177b6a --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/import/import-invalid-deprecated-1/semantic-version.yang @@ -0,0 +1,47 @@ +module semantic-version { + namespace "urn:opendaylight:yang:extension:semantic-version"; + prefix sv; + yang-version 1; + + revision 2016-02-02 { + description "Initial verison"; + } + sv:semantic-version "2.0.0"; + + extension semantic-version { + argument "semantic-version" { + yin-element false; + } + description + "The OpenConfig version number for the module. This is + expressed as a semantic version number of the form: + x.y.z + where: + * x corresponds to the major version, + * y corresponds to a minor version, + * z corresponds to a patch version. + This version corresponds to the model file within which it is + defined, and does not cover the whole set of OpenConfig models. + Where several modules are used to build up a single block of + functionality, the same module version is specified across each + file that makes up the module. + + A major version number of 0 indicates that this model is still + in development (whether within OpenConfig or with industry + partners), and is potentially subject to change. + + Following a release of major version 1, all modules will + increment major revision number where backwards incompatible + changes to the model are made. + + The minor version is changed when features are added to the + model that do not impact current clients use of the model. + + The patch-level version is incremented when non-feature changes + (such as bugfixes or clarifications to human-readable + descriptions that do not impact model functionality) are made + that maintain backwards compatibility. + + The version number is stored in the module meta-data."; + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/import/import-invalid-deprecated-2/foo.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/import/import-invalid-deprecated-2/foo.yang new file mode 100644 index 0000000000..eacb99e2bf --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/import/import-invalid-deprecated-2/foo.yang @@ -0,0 +1,14 @@ +module foo { + namespace "foo"; + prefix foo; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.9.9"; } + + revision "2016-02-01" { + description "Initial version"; + } + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/import/import-invalid-deprecated-2/semantic-version.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/import/import-invalid-deprecated-2/semantic-version.yang new file mode 100644 index 0000000000..5b1f6163d5 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/import/import-invalid-deprecated-2/semantic-version.yang @@ -0,0 +1,47 @@ +module semantic-version { + namespace "urn:opendaylight:yang:extension:semantic-version"; + prefix sv; + yang-version 1; + + revision 2016-02-02 { + description "Initial verison"; + } + sv:semantic-version "1.0.0"; + + extension semantic-version { + argument "semantic-version" { + yin-element false; + } + description + "The OpenConfig version number for the module. This is + expressed as a semantic version number of the form: + x.y.z + where: + * x corresponds to the major version, + * y corresponds to a minor version, + * z corresponds to a patch version. + This version corresponds to the model file within which it is + defined, and does not cover the whole set of OpenConfig models. + Where several modules are used to build up a single block of + functionality, the same module version is specified across each + file that makes up the module. + + A major version number of 0 indicates that this model is still + in development (whether within OpenConfig or with industry + partners), and is potentially subject to change. + + Following a release of major version 1, all modules will + increment major revision number where backwards incompatible + changes to the model are made. + + The minor version is changed when features are added to the + model that do not impact current clients use of the model. + + The patch-level version is incremented when non-feature changes + (such as bugfixes or clarifications to human-readable + descriptions that do not impact model functionality) are made + that maintain backwards compatibility. + + The version number is stored in the module meta-data."; + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/import/import-invalid-notsufficient-1/foo.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/import/import-invalid-notsufficient-1/foo.yang new file mode 100644 index 0000000000..74446cc940 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/import/import-invalid-notsufficient-1/foo.yang @@ -0,0 +1,14 @@ +module foo { + namespace "foo"; + prefix foo; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "2.0.0"; } + + revision "2016-02-01" { + description "Initial version"; + } + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/import/import-invalid-notsufficient-1/semantic-version.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/import/import-invalid-notsufficient-1/semantic-version.yang new file mode 100644 index 0000000000..5b1f6163d5 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/import/import-invalid-notsufficient-1/semantic-version.yang @@ -0,0 +1,47 @@ +module semantic-version { + namespace "urn:opendaylight:yang:extension:semantic-version"; + prefix sv; + yang-version 1; + + revision 2016-02-02 { + description "Initial verison"; + } + sv:semantic-version "1.0.0"; + + extension semantic-version { + argument "semantic-version" { + yin-element false; + } + description + "The OpenConfig version number for the module. This is + expressed as a semantic version number of the form: + x.y.z + where: + * x corresponds to the major version, + * y corresponds to a minor version, + * z corresponds to a patch version. + This version corresponds to the model file within which it is + defined, and does not cover the whole set of OpenConfig models. + Where several modules are used to build up a single block of + functionality, the same module version is specified across each + file that makes up the module. + + A major version number of 0 indicates that this model is still + in development (whether within OpenConfig or with industry + partners), and is potentially subject to change. + + Following a release of major version 1, all modules will + increment major revision number where backwards incompatible + changes to the model are made. + + The minor version is changed when features are added to the + model that do not impact current clients use of the model. + + The patch-level version is incremented when non-feature changes + (such as bugfixes or clarifications to human-readable + descriptions that do not impact model functionality) are made + that maintain backwards compatibility. + + The version number is stored in the module meta-data."; + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/import/import-invalid-notsufficient-2/foo.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/import/import-invalid-notsufficient-2/foo.yang new file mode 100644 index 0000000000..d069eef1cb --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/import/import-invalid-notsufficient-2/foo.yang @@ -0,0 +1,14 @@ +module foo { + namespace "foo"; + prefix foo; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "2.0.5"; } + + revision "2016-02-01" { + description "Initial version"; + } + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/import/import-invalid-notsufficient-2/semantic-version.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/import/import-invalid-notsufficient-2/semantic-version.yang new file mode 100644 index 0000000000..ca9b177b6a --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/import/import-invalid-notsufficient-2/semantic-version.yang @@ -0,0 +1,47 @@ +module semantic-version { + namespace "urn:opendaylight:yang:extension:semantic-version"; + prefix sv; + yang-version 1; + + revision 2016-02-02 { + description "Initial verison"; + } + sv:semantic-version "2.0.0"; + + extension semantic-version { + argument "semantic-version" { + yin-element false; + } + description + "The OpenConfig version number for the module. This is + expressed as a semantic version number of the form: + x.y.z + where: + * x corresponds to the major version, + * y corresponds to a minor version, + * z corresponds to a patch version. + This version corresponds to the model file within which it is + defined, and does not cover the whole set of OpenConfig models. + Where several modules are used to build up a single block of + functionality, the same module version is specified across each + file that makes up the module. + + A major version number of 0 indicates that this model is still + in development (whether within OpenConfig or with industry + partners), and is potentially subject to change. + + Following a release of major version 1, all modules will + increment major revision number where backwards incompatible + changes to the model are made. + + The minor version is changed when features are added to the + model that do not impact current clients use of the model. + + The patch-level version is incremented when non-feature changes + (such as bugfixes or clarifications to human-readable + descriptions that do not impact model functionality) are made + that maintain backwards compatibility. + + The version number is stored in the module meta-data."; + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/import/import-valid/foo.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/import/import-valid/foo.yang new file mode 100644 index 0000000000..a6c665bd3e --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/import/import-valid/foo.yang @@ -0,0 +1,14 @@ +module foo { + namespace "foo"; + prefix foo; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "1.0.0"; } + + revision "2016-02-01" { + description "Initial version"; + } + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/import/import-valid/semantic-version.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/import/import-valid/semantic-version.yang new file mode 100644 index 0000000000..5b1f6163d5 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/import/import-valid/semantic-version.yang @@ -0,0 +1,47 @@ +module semantic-version { + namespace "urn:opendaylight:yang:extension:semantic-version"; + prefix sv; + yang-version 1; + + revision 2016-02-02 { + description "Initial verison"; + } + sv:semantic-version "1.0.0"; + + extension semantic-version { + argument "semantic-version" { + yin-element false; + } + description + "The OpenConfig version number for the module. This is + expressed as a semantic version number of the form: + x.y.z + where: + * x corresponds to the major version, + * y corresponds to a minor version, + * z corresponds to a patch version. + This version corresponds to the model file within which it is + defined, and does not cover the whole set of OpenConfig models. + Where several modules are used to build up a single block of + functionality, the same module version is specified across each + file that makes up the module. + + A major version number of 0 indicates that this model is still + in development (whether within OpenConfig or with industry + partners), and is potentially subject to change. + + Following a release of major version 1, all modules will + increment major revision number where backwards incompatible + changes to the model are made. + + The minor version is changed when features are added to the + model that do not impact current clients use of the model. + + The patch-level version is incremented when non-feature changes + (such as bugfixes or clarifications to human-readable + descriptions that do not impact model functionality) are made + that maintain backwards compatibility. + + The version number is stored in the module meta-data."; + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/multiple-modules/bar@2016-01-01.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple-modules/bar@2016-01-01.yang new file mode 100644 index 0000000000..fdab507214 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple-modules/bar@2016-01-01.yang @@ -0,0 +1,15 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-01-01" { + description "Initial version"; + } + sv:semantic-version "0.1.1"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/multiple-modules/bar@2016-01-02.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple-modules/bar@2016-01-02.yang new file mode 100644 index 0000000000..388f7f15a3 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple-modules/bar@2016-01-02.yang @@ -0,0 +1,15 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-01-02" { + description "Initial version"; + } + sv:semantic-version "0.1.2"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/multiple-modules/bar@2016-01-03.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple-modules/bar@2016-01-03.yang new file mode 100644 index 0000000000..1b7d0e319f --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple-modules/bar@2016-01-03.yang @@ -0,0 +1,15 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-01-03" { + description "Initial version"; + } + sv:semantic-version "0.1.3"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/multiple-modules/bar@2016-01-04.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple-modules/bar@2016-01-04.yang new file mode 100644 index 0000000000..adb243687a --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple-modules/bar@2016-01-04.yang @@ -0,0 +1,15 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-01-04" { + description "Initial version"; + } + sv:semantic-version "0.10.4"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/multiple-modules/bar@2016-01-31.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple-modules/bar@2016-01-31.yang new file mode 100644 index 0000000000..e61a340d48 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple-modules/bar@2016-01-31.yang @@ -0,0 +1,15 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-01-31" { + description "Initial version"; + } + sv:semantic-version "1.1.2"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/multiple-modules/bar@2016-02-28.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple-modules/bar@2016-02-28.yang new file mode 100644 index 0000000000..b4a6511ef4 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple-modules/bar@2016-02-28.yang @@ -0,0 +1,15 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-02-28" { + description "Initial version"; + } + sv:semantic-version "1.2.28"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/multiple-modules/foo.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple-modules/foo.yang new file mode 100644 index 0000000000..220c9cc582 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple-modules/foo.yang @@ -0,0 +1,16 @@ +module foo { + namespace "foo"; + prefix foo; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + import bar { prefix bar; sv:semantic-version "0.1.2";} + + revision "2016-02-01" { + description "Initial version"; + } + sv:semantic-version "0.1.1"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/multiple-modules/semantic-version.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple-modules/semantic-version.yang new file mode 100644 index 0000000000..dd92de6883 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple-modules/semantic-version.yang @@ -0,0 +1,47 @@ +module semantic-version { + namespace "urn:opendaylight:yang:extension:semantic-version"; + prefix sv; + yang-version 1; + + revision 2016-02-02 { + description "Initial verison"; + } + sv:semantic-version "0.0.1"; + + extension semantic-version { + argument "semantic-version" { + yin-element false; + } + description + "The OpenConfig version number for the module. This is + expressed as a semantic version number of the form: + x.y.z + where: + * x corresponds to the major version, + * y corresponds to a minor version, + * z corresponds to a patch version. + This version corresponds to the model file within which it is + defined, and does not cover the whole set of OpenConfig models. + Where several modules are used to build up a single block of + functionality, the same module version is specified across each + file that makes up the module. + + A major version number of 0 indicates that this model is still + in development (whether within OpenConfig or with industry + partners), and is potentially subject to change. + + Following a release of major version 1, all modules will + increment major revision number where backwards incompatible + changes to the model are made. + + The minor version is changed when features are added to the + model that do not impact current clients use of the model. + + The patch-level version is incremented when non-feature changes + (such as bugfixes or clarifications to human-readable + descriptions that do not impact model functionality) are made + that maintain backwards compatibility. + + The version number is stored in the module meta-data."; + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-invalid-deprecated/bar@2016-01-01.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-invalid-deprecated/bar@2016-01-01.yang new file mode 100644 index 0000000000..6352253fb4 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-invalid-deprecated/bar@2016-01-01.yang @@ -0,0 +1,15 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-01-01" { + description "Initial version"; + } + sv:semantic-version "2.1.1"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-invalid-deprecated/bar@2016-01-02.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-invalid-deprecated/bar@2016-01-02.yang new file mode 100644 index 0000000000..db806e8d6d --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-invalid-deprecated/bar@2016-01-02.yang @@ -0,0 +1,15 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-01-02" { + description "Initial version"; + } + sv:semantic-version "2.1.2"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-invalid-deprecated/bar@2016-02-01.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-invalid-deprecated/bar@2016-02-01.yang new file mode 100644 index 0000000000..69e3d6cca8 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-invalid-deprecated/bar@2016-02-01.yang @@ -0,0 +1,15 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-02-01" { + description "Initial version"; + } + sv:semantic-version "4.1.1"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-invalid-deprecated/bar@2016-02-02.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-invalid-deprecated/bar@2016-02-02.yang new file mode 100644 index 0000000000..13c579cceb --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-invalid-deprecated/bar@2016-02-02.yang @@ -0,0 +1,15 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-02-02" { + description "Initial version"; + } + sv:semantic-version "5.0.0"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-invalid-deprecated/foo.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-invalid-deprecated/foo.yang new file mode 100644 index 0000000000..3a2ab942c2 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-invalid-deprecated/foo.yang @@ -0,0 +1,16 @@ +module foo { + namespace "foo"; + prefix foo; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + import bar { prefix bar; revision-date 2016-01-31; sv:semantic-version "1.0.0"; } + + revision "2016-02-01" { + description "Initial version"; + } + sv:semantic-version "0.1.1"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-invalid-deprecated/semantic-version.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-invalid-deprecated/semantic-version.yang new file mode 100644 index 0000000000..dd92de6883 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-invalid-deprecated/semantic-version.yang @@ -0,0 +1,47 @@ +module semantic-version { + namespace "urn:opendaylight:yang:extension:semantic-version"; + prefix sv; + yang-version 1; + + revision 2016-02-02 { + description "Initial verison"; + } + sv:semantic-version "0.0.1"; + + extension semantic-version { + argument "semantic-version" { + yin-element false; + } + description + "The OpenConfig version number for the module. This is + expressed as a semantic version number of the form: + x.y.z + where: + * x corresponds to the major version, + * y corresponds to a minor version, + * z corresponds to a patch version. + This version corresponds to the model file within which it is + defined, and does not cover the whole set of OpenConfig models. + Where several modules are used to build up a single block of + functionality, the same module version is specified across each + file that makes up the module. + + A major version number of 0 indicates that this model is still + in development (whether within OpenConfig or with industry + partners), and is potentially subject to change. + + Following a release of major version 1, all modules will + increment major revision number where backwards incompatible + changes to the model are made. + + The minor version is changed when features are added to the + model that do not impact current clients use of the model. + + The patch-level version is incremented when non-feature changes + (such as bugfixes or clarifications to human-readable + descriptions that do not impact model functionality) are made + that maintain backwards compatibility. + + The version number is stored in the module meta-data."; + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-invalid-nosufficient/bar@2016-01-01.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-invalid-nosufficient/bar@2016-01-01.yang new file mode 100644 index 0000000000..4422f6d2d9 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-invalid-nosufficient/bar@2016-01-01.yang @@ -0,0 +1,15 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-01-01" { + description "Initial version"; + } + sv:semantic-version "2.0.0"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-invalid-nosufficient/bar@2016-01-02.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-invalid-nosufficient/bar@2016-01-02.yang new file mode 100644 index 0000000000..9d916f6b27 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-invalid-nosufficient/bar@2016-01-02.yang @@ -0,0 +1,15 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-01-02" { + description "Initial version"; + } + sv:semantic-version "2.1.0"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-invalid-nosufficient/bar@2016-02-01.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-invalid-nosufficient/bar@2016-02-01.yang new file mode 100644 index 0000000000..30367614c7 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-invalid-nosufficient/bar@2016-02-01.yang @@ -0,0 +1,15 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-02-01" { + description "Initial version"; + } + sv:semantic-version "2.5.0"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-invalid-nosufficient/bar@2016-02-02.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-invalid-nosufficient/bar@2016-02-02.yang new file mode 100644 index 0000000000..f27a9efd35 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-invalid-nosufficient/bar@2016-02-02.yang @@ -0,0 +1,15 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-02-02" { + description "Initial version"; + } + sv:semantic-version "2.5.4"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-invalid-nosufficient/foo.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-invalid-nosufficient/foo.yang new file mode 100644 index 0000000000..ec773ae546 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-invalid-nosufficient/foo.yang @@ -0,0 +1,16 @@ +module foo { + namespace "foo"; + prefix foo; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + import bar { prefix bar; sv:semantic-version "2.5.5"; } + + revision "2016-02-01" { + description "Initial version"; + } + sv:semantic-version "0.1.1"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-invalid-nosufficient/semantic-version.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-invalid-nosufficient/semantic-version.yang new file mode 100644 index 0000000000..dd92de6883 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-invalid-nosufficient/semantic-version.yang @@ -0,0 +1,47 @@ +module semantic-version { + namespace "urn:opendaylight:yang:extension:semantic-version"; + prefix sv; + yang-version 1; + + revision 2016-02-02 { + description "Initial verison"; + } + sv:semantic-version "0.0.1"; + + extension semantic-version { + argument "semantic-version" { + yin-element false; + } + description + "The OpenConfig version number for the module. This is + expressed as a semantic version number of the form: + x.y.z + where: + * x corresponds to the major version, + * y corresponds to a minor version, + * z corresponds to a patch version. + This version corresponds to the model file within which it is + defined, and does not cover the whole set of OpenConfig models. + Where several modules are used to build up a single block of + functionality, the same module version is specified across each + file that makes up the module. + + A major version number of 0 indicates that this model is still + in development (whether within OpenConfig or with industry + partners), and is potentially subject to change. + + Following a release of major version 1, all modules will + increment major revision number where backwards incompatible + changes to the model are made. + + The minor version is changed when features are added to the + model that do not impact current clients use of the model. + + The patch-level version is incremented when non-feature changes + (such as bugfixes or clarifications to human-readable + descriptions that do not impact model functionality) are made + that maintain backwards compatibility. + + The version number is stored in the module meta-data."; + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-valid-defaults/bar@2016-01-01.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-valid-defaults/bar@2016-01-01.yang new file mode 100644 index 0000000000..5c6572cd05 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-valid-defaults/bar@2016-01-01.yang @@ -0,0 +1,15 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-01-01" { + description "Initial version"; + } + sv:semantic-version "0.0.1"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-valid-defaults/bar@2016-01-02.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-valid-defaults/bar@2016-01-02.yang new file mode 100644 index 0000000000..b819db324a --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-valid-defaults/bar@2016-01-02.yang @@ -0,0 +1,15 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-01-02" { + description "Initial version"; + } + sv:semantic-version "0.1.0"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-valid-defaults/bar@2016-02-01.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-valid-defaults/bar@2016-02-01.yang new file mode 100644 index 0000000000..4405fa975b --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-valid-defaults/bar@2016-02-01.yang @@ -0,0 +1,15 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-02-01" { + description "Initial version"; + } + sv:semantic-version "0.9.5"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-valid-defaults/bar@2016-02-02.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-valid-defaults/bar@2016-02-02.yang new file mode 100644 index 0000000000..54506080ba --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-valid-defaults/bar@2016-02-02.yang @@ -0,0 +1,15 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-02-02" { + description "Initial version"; + } + sv:semantic-version "1.0.0"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-valid-defaults/foo.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-valid-defaults/foo.yang new file mode 100644 index 0000000000..3da8de0a25 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-valid-defaults/foo.yang @@ -0,0 +1,16 @@ +module foo { + namespace "foo"; + prefix foo; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + import bar { prefix bar; } + + revision "2016-02-01" { + description "Initial version"; + } + sv:semantic-version "0.1.1"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-valid-defaults/semantic-version.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-valid-defaults/semantic-version.yang new file mode 100644 index 0000000000..dd92de6883 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-valid-defaults/semantic-version.yang @@ -0,0 +1,47 @@ +module semantic-version { + namespace "urn:opendaylight:yang:extension:semantic-version"; + prefix sv; + yang-version 1; + + revision 2016-02-02 { + description "Initial verison"; + } + sv:semantic-version "0.0.1"; + + extension semantic-version { + argument "semantic-version" { + yin-element false; + } + description + "The OpenConfig version number for the module. This is + expressed as a semantic version number of the form: + x.y.z + where: + * x corresponds to the major version, + * y corresponds to a minor version, + * z corresponds to a patch version. + This version corresponds to the model file within which it is + defined, and does not cover the whole set of OpenConfig models. + Where several modules are used to build up a single block of + functionality, the same module version is specified across each + file that makes up the module. + + A major version number of 0 indicates that this model is still + in development (whether within OpenConfig or with industry + partners), and is potentially subject to change. + + Following a release of major version 1, all modules will + increment major revision number where backwards incompatible + changes to the model are made. + + The minor version is changed when features are added to the + model that do not impact current clients use of the model. + + The patch-level version is incremented when non-feature changes + (such as bugfixes or clarifications to human-readable + descriptions that do not impact model functionality) are made + that maintain backwards compatibility. + + The version number is stored in the module meta-data."; + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-valid-specified/bar@2016-01-01.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-valid-specified/bar@2016-01-01.yang new file mode 100644 index 0000000000..732609a657 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-valid-specified/bar@2016-01-01.yang @@ -0,0 +1,15 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-01-01" { + description "Initial version"; + } + sv:semantic-version "4.4.0"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-valid-specified/bar@2016-01-02.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-valid-specified/bar@2016-01-02.yang new file mode 100644 index 0000000000..82dd7efcba --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-valid-specified/bar@2016-01-02.yang @@ -0,0 +1,15 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-01-02" { + description "Initial version"; + } + sv:semantic-version "5.5.0"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-valid-specified/bar@2016-02-01.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-valid-specified/bar@2016-02-01.yang new file mode 100644 index 0000000000..32edae48fb --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-valid-specified/bar@2016-02-01.yang @@ -0,0 +1,15 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-02-01" { + description "Initial version"; + } + sv:semantic-version "5.5.5"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-valid-specified/bar@2016-02-02.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-valid-specified/bar@2016-02-02.yang new file mode 100644 index 0000000000..a4d94b5af8 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-valid-specified/bar@2016-02-02.yang @@ -0,0 +1,15 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-02-02" { + description "Initial version"; + } + sv:semantic-version "5.5.6"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-valid-specified/foo.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-valid-specified/foo.yang new file mode 100644 index 0000000000..c89c60d0df --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-valid-specified/foo.yang @@ -0,0 +1,16 @@ +module foo { + namespace "foo"; + prefix foo; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + import bar { prefix bar; sv:semantic-version "5.5.5"; } + + revision "2016-02-01" { + description "Initial version"; + } + sv:semantic-version "0.1.1"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-valid-specified/semantic-version.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-valid-specified/semantic-version.yang new file mode 100644 index 0000000000..dd92de6883 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/multiple/multiple-valid-specified/semantic-version.yang @@ -0,0 +1,47 @@ +module semantic-version { + namespace "urn:opendaylight:yang:extension:semantic-version"; + prefix sv; + yang-version 1; + + revision 2016-02-02 { + description "Initial verison"; + } + sv:semantic-version "0.0.1"; + + extension semantic-version { + argument "semantic-version" { + yin-element false; + } + description + "The OpenConfig version number for the module. This is + expressed as a semantic version number of the form: + x.y.z + where: + * x corresponds to the major version, + * y corresponds to a minor version, + * z corresponds to a patch version. + This version corresponds to the model file within which it is + defined, and does not cover the whole set of OpenConfig models. + Where several modules are used to build up a single block of + functionality, the same module version is specified across each + file that makes up the module. + + A major version number of 0 indicates that this model is still + in development (whether within OpenConfig or with industry + partners), and is potentially subject to change. + + Following a release of major version 1, all modules will + increment major revision number where backwards incompatible + changes to the model are made. + + The minor version is changed when features are added to the + model that do not impact current clients use of the model. + + The patch-level version is incremented when non-feature changes + (such as bugfixes or clarifications to human-readable + descriptions that do not impact model functionality) are made + that maintain backwards compatibility. + + The version number is stored in the module meta-data."; + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/node-test/bar@20160404.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/node-test/bar@20160404.yang new file mode 100644 index 0000000000..69270ae685 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/node-test/bar@20160404.yang @@ -0,0 +1,18 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision 2016-04-04 { + description "test"; + } + + sv:semantic-version "2016.4.4"; + + grouping grp { + container con20160404 { + } + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/node-test/bar@20160405.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/node-test/bar@20160405.yang new file mode 100644 index 0000000000..f2bc4bee73 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/node-test/bar@20160405.yang @@ -0,0 +1,20 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision 2016-04-05 { + description "test"; + } + + sv:semantic-version "2016.4.5"; + + grouping grp { + container con20160404 { + } + container con20160405 { + } + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/node-test/bar@20160406.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/node-test/bar@20160406.yang new file mode 100644 index 0000000000..46d63f0751 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/node-test/bar@20160406.yang @@ -0,0 +1,22 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision 2016-04-06 { + description "test"; + } + + sv:semantic-version "2016.4.6"; + + grouping grp { + container con20160404 { + } + container con20160405 { + } + container con20160406 { + } + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/node-test/bar@20170406.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/node-test/bar@20170406.yang new file mode 100644 index 0000000000..21066d44e6 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/node-test/bar@20170406.yang @@ -0,0 +1,24 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision 2017-04-06 { + description "test"; + } + + sv:semantic-version "2017.4.6"; + + grouping grp { + container con20160404 { + } + container con20160405 { + } + container con20160406 { + } + container con20170406 { + } + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/node-test/foo.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/node-test/foo.yang new file mode 100644 index 0000000000..b4af34672c --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/node-test/foo.yang @@ -0,0 +1,18 @@ +module foo { + namespace "foo"; + prefix foo; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + import bar { prefix bar; revision-date 2017-04-06; sv:semantic-version "2016.4.5"; } + + revision 2016-01-01 { + description "test"; + } + + sv:semantic-version "2016.1.1"; + + container foo-root { + uses bar:grp; + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/node-test/semantic-version.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/node-test/semantic-version.yang new file mode 100644 index 0000000000..dd92de6883 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/node-test/semantic-version.yang @@ -0,0 +1,47 @@ +module semantic-version { + namespace "urn:opendaylight:yang:extension:semantic-version"; + prefix sv; + yang-version 1; + + revision 2016-02-02 { + description "Initial verison"; + } + sv:semantic-version "0.0.1"; + + extension semantic-version { + argument "semantic-version" { + yin-element false; + } + description + "The OpenConfig version number for the module. This is + expressed as a semantic version number of the form: + x.y.z + where: + * x corresponds to the major version, + * y corresponds to a minor version, + * z corresponds to a patch version. + This version corresponds to the model file within which it is + defined, and does not cover the whole set of OpenConfig models. + Where several modules are used to build up a single block of + functionality, the same module version is specified across each + file that makes up the module. + + A major version number of 0 indicates that this model is still + in development (whether within OpenConfig or with industry + partners), and is potentially subject to change. + + Following a release of major version 1, all modules will + increment major revision number where backwards incompatible + changes to the model are made. + + The minor version is changed when features are added to the + model that do not impact current clients use of the model. + + The patch-level version is incremented when non-feature changes + (such as bugfixes or clarifications to human-readable + descriptions that do not impact model functionality) are made + that maintain backwards compatibility. + + The version number is stored in the module meta-data."; + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/position/position-head/bar.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/position/position-head/bar.yang new file mode 100644 index 0000000000..868ce014a0 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/position/position-head/bar.yang @@ -0,0 +1,16 @@ +module bar { + sv:semantic-version "0.1.2"; + + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-01-31" { + description "Initial version"; + } + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/position/position-head/foo.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/position/position-head/foo.yang new file mode 100644 index 0000000000..4aee60f5bb --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/position/position-head/foo.yang @@ -0,0 +1,17 @@ +module foo { + sv:semantic-version "0.1.1"; + import bar { prefix bar; revision-date 2016-01-31; sv:semantic-version "0.1.2";} + + namespace "foo"; + prefix foo; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-02-01" { + description "Initial version"; + } + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/position/position-head/semantic-version.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/position/position-head/semantic-version.yang new file mode 100644 index 0000000000..3879c0670b --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/position/position-head/semantic-version.yang @@ -0,0 +1,48 @@ +module semantic-version { + sv:semantic-version "0.0.1"; + + namespace "urn:opendaylight:yang:extension:semantic-version"; + prefix sv; + yang-version 1; + + revision 2016-02-02 { + description "Initial verison"; + } + + extension semantic-version { + argument "semantic-version" { + yin-element false; + } + description + "The OpenConfig version number for the module. This is + expressed as a semantic version number of the form: + x.y.z + where: + * x corresponds to the major version, + * y corresponds to a minor version, + * z corresponds to a patch version. + This version corresponds to the model file within which it is + defined, and does not cover the whole set of OpenConfig models. + Where several modules are used to build up a single block of + functionality, the same module version is specified across each + file that makes up the module. + + A major version number of 0 indicates that this model is still + in development (whether within OpenConfig or with industry + partners), and is potentially subject to change. + + Following a release of major version 1, all modules will + increment major revision number where backwards incompatible + changes to the model are made. + + The minor version is changed when features are added to the + model that do not impact current clients use of the model. + + The patch-level version is incremented when non-feature changes + (such as bugfixes or clarifications to human-readable + descriptions that do not impact model functionality) are made + that maintain backwards compatibility. + + The version number is stored in the module meta-data."; + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/position/position-middle/bar.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/position/position-middle/bar.yang new file mode 100644 index 0000000000..2adc1363ba --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/position/position-middle/bar.yang @@ -0,0 +1,15 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-01-31" { + description "Initial version"; + } + sv:semantic-version "0.1.2"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/position/position-middle/foo.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/position/position-middle/foo.yang new file mode 100644 index 0000000000..dda1144dff --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/position/position-middle/foo.yang @@ -0,0 +1,16 @@ +module foo { + namespace "foo"; + prefix foo; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + import bar { prefix bar; revision-date 2016-01-31; sv:semantic-version "0.1.2";} + + revision "2016-02-01" { + description "Initial version"; + } + sv:semantic-version "0.1.1"; + + container root { + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/position/position-middle/semantic-version.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/position/position-middle/semantic-version.yang new file mode 100644 index 0000000000..dd92de6883 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/position/position-middle/semantic-version.yang @@ -0,0 +1,47 @@ +module semantic-version { + namespace "urn:opendaylight:yang:extension:semantic-version"; + prefix sv; + yang-version 1; + + revision 2016-02-02 { + description "Initial verison"; + } + sv:semantic-version "0.0.1"; + + extension semantic-version { + argument "semantic-version" { + yin-element false; + } + description + "The OpenConfig version number for the module. This is + expressed as a semantic version number of the form: + x.y.z + where: + * x corresponds to the major version, + * y corresponds to a minor version, + * z corresponds to a patch version. + This version corresponds to the model file within which it is + defined, and does not cover the whole set of OpenConfig models. + Where several modules are used to build up a single block of + functionality, the same module version is specified across each + file that makes up the module. + + A major version number of 0 indicates that this model is still + in development (whether within OpenConfig or with industry + partners), and is potentially subject to change. + + Following a release of major version 1, all modules will + increment major revision number where backwards incompatible + changes to the model are made. + + The minor version is changed when features are added to the + model that do not impact current clients use of the model. + + The patch-level version is incremented when non-feature changes + (such as bugfixes or clarifications to human-readable + descriptions that do not impact model functionality) are made + that maintain backwards compatibility. + + The version number is stored in the module meta-data."; + } +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/position/position-tail/bar.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/position/position-tail/bar.yang new file mode 100644 index 0000000000..8ce6838c35 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/position/position-tail/bar.yang @@ -0,0 +1,16 @@ +module bar { + namespace "bar"; + prefix bar; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-01-31" { + description "Initial version"; + } + + container root { + } + + sv:semantic-version "0.1.2"; +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/position/position-tail/foo.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/position/position-tail/foo.yang new file mode 100644 index 0000000000..67e9025fc4 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/position/position-tail/foo.yang @@ -0,0 +1,17 @@ +module foo { + namespace "foo"; + prefix foo; + yang-version 1; + + import semantic-version { prefix sv; revision-date 2016-02-02; sv:semantic-version "0.0.1"; } + + revision "2016-02-01" { + description "Initial version"; + } + + container root { + } + + sv:semantic-version "0.1.1"; + import bar { prefix bar; revision-date 2016-01-31; sv:semantic-version "0.1.2";} +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/position/position-tail/semantic-version.yang b/yang/yang-parser-impl/src/test/resources/semantic-version/position/position-tail/semantic-version.yang new file mode 100644 index 0000000000..ca84e112e2 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/position/position-tail/semantic-version.yang @@ -0,0 +1,48 @@ +module semantic-version { + namespace "urn:opendaylight:yang:extension:semantic-version"; + prefix sv; + yang-version 1; + + revision 2016-02-02 { + description "Initial verison"; + } + + extension semantic-version { + argument "semantic-version" { + yin-element false; + } + description + "The OpenConfig version number for the module. This is + expressed as a semantic version number of the form: + x.y.z + where: + * x corresponds to the major version, + * y corresponds to a minor version, + * z corresponds to a patch version. + This version corresponds to the model file within which it is + defined, and does not cover the whole set of OpenConfig models. + Where several modules are used to build up a single block of + functionality, the same module version is specified across each + file that makes up the module. + + A major version number of 0 indicates that this model is still + in development (whether within OpenConfig or with industry + partners), and is potentially subject to change. + + Following a release of major version 1, all modules will + increment major revision number where backwards incompatible + changes to the model are made. + + The minor version is changed when features are added to the + model that do not impact current clients use of the model. + + The patch-level version is incremented when non-feature changes + (such as bugfixes or clarifications to human-readable + descriptions that do not impact model functionality) are made + that maintain backwards compatibility. + + The version number is stored in the module meta-data."; + } + + sv:semantic-version "0.0.1"; +} diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/yin-input/basic-import-invalid/bar@2016-01-01.xml b/yang/yang-parser-impl/src/test/resources/semantic-version/yin-input/basic-import-invalid/bar@2016-01-01.xml new file mode 100644 index 0000000000..6b4cfb5247 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/yin-input/basic-import-invalid/bar@2016-01-01.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/yin-input/basic-import-invalid/bar@2016-01-31.xml b/yang/yang-parser-impl/src/test/resources/semantic-version/yin-input/basic-import-invalid/bar@2016-01-31.xml new file mode 100644 index 0000000000..97d3dea508 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/yin-input/basic-import-invalid/bar@2016-01-31.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/yin-input/basic-import-invalid/foo@2016-02-01.xml b/yang/yang-parser-impl/src/test/resources/semantic-version/yin-input/basic-import-invalid/foo@2016-02-01.xml new file mode 100644 index 0000000000..19c5ea64d9 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/yin-input/basic-import-invalid/foo@2016-02-01.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/yin-input/basic-import-invalid/semantic-version@2016-02-02.xml b/yang/yang-parser-impl/src/test/resources/semantic-version/yin-input/basic-import-invalid/semantic-version@2016-02-02.xml new file mode 100644 index 0000000000..fe7aeb9346 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/yin-input/basic-import-invalid/semantic-version@2016-02-02.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + The OpenConfig version number for the module. This is + expressed as a semantic version number of the form: + x.y.z + where: + * x corresponds to the major version, + * y corresponds to a minor version, + * z corresponds to a patch version. + This version corresponds to the model file within which it is + defined, and does not cover the whole set of OpenConfig models. + Where several modules are used to build up a single block of + functionality, the same module version is specified across each + file that makes up the module. + + A major version number of 0 indicates that this model is still + in development (whether within OpenConfig or with industry + partners), and is potentially subject to change. + + Following a release of major version 1, all modules will + increment major revision number where backwards incompatible + changes to the model are made. + + The minor version is changed when features are added to the + model that do not impact current clients use of the model. + + The patch-level version is incremented when non-feature changes + (such as bugfixes or clarifications to human-readable + descriptions that do not impact model functionality) are made + that maintain backwards compatibility. + + The version number is stored in the module meta-data. + + + + \ No newline at end of file diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/yin-input/basic-import/bar@2016-01-01.xml b/yang/yang-parser-impl/src/test/resources/semantic-version/yin-input/basic-import/bar@2016-01-01.xml new file mode 100644 index 0000000000..ab75b3a61e --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/yin-input/basic-import/bar@2016-01-01.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/yin-input/basic-import/bar@2016-01-31.xml b/yang/yang-parser-impl/src/test/resources/semantic-version/yin-input/basic-import/bar@2016-01-31.xml new file mode 100644 index 0000000000..224c76744d --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/yin-input/basic-import/bar@2016-01-31.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/yin-input/basic-import/foo@2016-02-01.xml b/yang/yang-parser-impl/src/test/resources/semantic-version/yin-input/basic-import/foo@2016-02-01.xml new file mode 100644 index 0000000000..19c5ea64d9 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/yin-input/basic-import/foo@2016-02-01.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/yin-input/basic-import/semantic-version@2016-02-02.xml b/yang/yang-parser-impl/src/test/resources/semantic-version/yin-input/basic-import/semantic-version@2016-02-02.xml new file mode 100644 index 0000000000..fe7aeb9346 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/yin-input/basic-import/semantic-version@2016-02-02.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + The OpenConfig version number for the module. This is + expressed as a semantic version number of the form: + x.y.z + where: + * x corresponds to the major version, + * y corresponds to a minor version, + * z corresponds to a patch version. + This version corresponds to the model file within which it is + defined, and does not cover the whole set of OpenConfig models. + Where several modules are used to build up a single block of + functionality, the same module version is specified across each + file that makes up the module. + + A major version number of 0 indicates that this model is still + in development (whether within OpenConfig or with industry + partners), and is potentially subject to change. + + Following a release of major version 1, all modules will + increment major revision number where backwards incompatible + changes to the model are made. + + The minor version is changed when features are added to the + model that do not impact current clients use of the model. + + The patch-level version is incremented when non-feature changes + (such as bugfixes or clarifications to human-readable + descriptions that do not impact model functionality) are made + that maintain backwards compatibility. + + The version number is stored in the module meta-data. + + + + \ No newline at end of file diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/yin-input/basic/bar@2016-01-31.xml b/yang/yang-parser-impl/src/test/resources/semantic-version/yin-input/basic/bar@2016-01-31.xml new file mode 100644 index 0000000000..b3fe6a230a --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/yin-input/basic/bar@2016-01-31.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/yin-input/basic/foo@2016-02-01.xml b/yang/yang-parser-impl/src/test/resources/semantic-version/yin-input/basic/foo@2016-02-01.xml new file mode 100644 index 0000000000..19c5ea64d9 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/yin-input/basic/foo@2016-02-01.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/yang/yang-parser-impl/src/test/resources/semantic-version/yin-input/basic/semantic-version@2016-02-02.xml b/yang/yang-parser-impl/src/test/resources/semantic-version/yin-input/basic/semantic-version@2016-02-02.xml new file mode 100644 index 0000000000..fe7aeb9346 --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/semantic-version/yin-input/basic/semantic-version@2016-02-02.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + The OpenConfig version number for the module. This is + expressed as a semantic version number of the form: + x.y.z + where: + * x corresponds to the major version, + * y corresponds to a minor version, + * z corresponds to a patch version. + This version corresponds to the model file within which it is + defined, and does not cover the whole set of OpenConfig models. + Where several modules are used to build up a single block of + functionality, the same module version is specified across each + file that makes up the module. + + A major version number of 0 indicates that this model is still + in development (whether within OpenConfig or with industry + partners), and is potentially subject to change. + + Following a release of major version 1, all modules will + increment major revision number where backwards incompatible + changes to the model are made. + + The minor version is changed when features are added to the + model that do not impact current clients use of the model. + + The patch-level version is incremented when non-feature changes + (such as bugfixes or clarifications to human-readable + descriptions that do not impact model functionality) are made + that maintain backwards compatibility. + + The version number is stored in the module meta-data. + + + + \ No newline at end of file