YANGTOOLS-825: extend plugin SPI with import resolution mode
[yangtools.git] / yang / yang-maven-plugin-spi / src / main / java / org / opendaylight / yangtools / yang2sources / spi / BasicCodeGenerator.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.yangtools.yang2sources.spi;
9
10 import java.io.File;
11 import java.io.IOException;
12 import java.util.Collection;
13 import java.util.Map;
14 import java.util.Optional;
15 import java.util.Set;
16 import java.util.function.Function;
17 import org.opendaylight.yangtools.yang.model.api.Module;
18 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
19
20 /**
21  * Maven 3.1.x and newer uses SLF4J internally, which means we do not need to pass
22  * a logger instance around.
23  */
24 public interface BasicCodeGenerator {
25     enum ImportResolutionMode {
26         /**
27          * Standard, RFC6020 and RFC7950 compliant mode. Imports are satisfied by exact revision match (if specified),
28          * or by latest available revision.
29          */
30         REVISION_EXACT_OR_LATEST,
31         /**
32          * Semantic version based mode. Imports which specify a semantic version (via the OpenConfig extension) will
33          * be satisfied by module which exports the latest compatible revision. Imports which do not specify semantic
34          * version will be resolved just as they would be via {@link #REVISION_EXACT_OR_LATEST}.
35          */
36         SEMVER_LATEST,
37     }
38
39     /**
40      * Generate sources from provided {@link SchemaContext}.
41      *
42      * @param context
43      *            parsed from YANG files
44      * @param outputBaseDir
45      *            expected output directory for generated sources configured by
46      *            user
47      * @param currentModules
48      *            YANG modules parsed from yangFilesRootDir
49      * @param moduleResourcePathResolver
50      *            Function converting a local module to the packaged resource path
51      * @return collection of files that were generated from schema context
52      */
53     Collection<File> generateSources(SchemaContext context, File outputBaseDir, Set<Module> currentModules,
54             Function<Module, Optional<String>> moduleResourcePathResolver) throws IOException;
55
56     /**
57      * Provided map contains all configuration that was set in pom for code
58      * generator in additionalConfiguration tag.
59      */
60     void setAdditionalConfig(Map<String, String> additionalConfiguration);
61
62     /**
63      * Provided folder is marked as resources and its content will be packaged
64      * in resulting jar. Feel free to add necessary resources.
65      */
66     void setResourceBaseDir(File resourceBaseDir);
67
68     /**
69      * Indicate import resolution mode this code generator requires. Default implementation indicates
70      * {@link ImportResolutionMode#REVISION_EXACT_OR_LATEST}.
71      *
72      * @return Import resolution mode.
73      */
74     default ImportResolutionMode getImportResolutionMode() {
75         return ImportResolutionMode.REVISION_EXACT_OR_LATEST;
76     }
77 }