YANGTOOLS-825: extend plugin SPI with import resolution mode 94/65094/7
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 3 Nov 2017 13:00:56 +0000 (14:00 +0100)
committerRobert Varga <nite@hq.sk>
Tue, 7 Nov 2017 20:36:38 +0000 (20:36 +0000)
This patch adds the basic API needed for codegen plugins to express
their desired import resolution mode. The default implementation
results in RFC6020/7950 compliant mode.

Change-Id: I60936171b984dab503e1933b21dbcb5bd68278c8
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-maven-plugin-spi/src/main/java/org/opendaylight/yangtools/yang2sources/spi/BasicCodeGenerator.java

index 9c07db36be5069be61006f619ee3f72137bd71bb..364aed252df1a3de8feeb406ba5f2ccb1a73c162 100644 (file)
@@ -22,6 +22,20 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext;
  * a logger instance around.
  */
 public interface BasicCodeGenerator {
+    enum ImportResolutionMode {
+        /**
+         * Standard, RFC6020 and RFC7950 compliant mode. Imports are satisfied by exact revision match (if specified),
+         * or by latest available revision.
+         */
+        REVISION_EXACT_OR_LATEST,
+        /**
+         * Semantic version based mode. Imports which specify a semantic version (via the OpenConfig extension) will
+         * be satisfied by module which exports the latest compatible revision. Imports which do not specify semantic
+         * version will be resolved just as they would be via {@link #REVISION_EXACT_OR_LATEST}.
+         */
+        SEMVER_LATEST,
+    }
+
     /**
      * Generate sources from provided {@link SchemaContext}.
      *
@@ -50,4 +64,14 @@ public interface BasicCodeGenerator {
      * in resulting jar. Feel free to add necessary resources.
      */
     void setResourceBaseDir(File resourceBaseDir);
+
+    /**
+     * Indicate import resolution mode this code generator requires. Default implementation indicates
+     * {@link ImportResolutionMode#REVISION_EXACT_OR_LATEST}.
+     *
+     * @return Import resolution mode.
+     */
+    default ImportResolutionMode getImportResolutionMode() {
+        return ImportResolutionMode.REVISION_EXACT_OR_LATEST;
+    }
 }