Allow module to be represented in different formats
[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.Set;
15 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
16 import org.opendaylight.yangtools.yang.model.api.Module;
17
18 /**
19  * Maven 3.1.x and newer uses SLF4J internally, which means we do not need to pass a logger instance around.
20  */
21 public interface BasicCodeGenerator {
22     enum ImportResolutionMode {
23         /**
24          * Standard, RFC6020 and RFC7950 compliant mode. Imports are satisfied by exact revision match (if specified),
25          * or by latest available revision.
26          */
27         REVISION_EXACT_OR_LATEST,
28         /**
29          * Semantic version based mode. Imports which specify a semantic version (via the OpenConfig extension) will
30          * be satisfied by module which exports the latest compatible revision. Imports which do not specify semantic
31          * version will be resolved just as they would be via {@link #REVISION_EXACT_OR_LATEST}.
32          */
33         SEMVER_LATEST,
34     }
35
36     /**
37      * Generate sources from provided {@link EffectiveModelContext}.
38      *
39      * @param context
40      *            parsed from YANG files
41      * @param outputBaseDir
42      *            expected output directory for generated sources configured by
43      *            user
44      * @param currentModules
45      *            YANG modules parsed from yangFilesRootDir
46      * @param moduleResourcePathResolver
47      *            Function converting a local module to the packaged resource path
48      * @return collection of files that were generated from schema context
49      */
50     Collection<File> generateSources(EffectiveModelContext context, File outputBaseDir, Set<Module> currentModules,
51             ModuleResourceResolver moduleResourcePathResolver) throws IOException;
52
53     /**
54      * Provided map contains all configuration that was set in pom for code
55      * generator in additionalConfiguration tag.
56      */
57     void setAdditionalConfig(Map<String, String> additionalConfiguration);
58
59     /**
60      * Provided folder is marked as resources and its content will be packaged
61      * in resulting jar. Feel free to add necessary resources.
62      */
63     void setResourceBaseDir(File resourceBaseDir);
64
65     /**
66      * Indicate import resolution mode this code generator requires. Default implementation indicates
67      * {@link ImportResolutionMode#REVISION_EXACT_OR_LATEST}.
68      *
69      * @return Required import resolution mode, null if the code generator does not care.
70      */
71     // FIXME: This is not really extensible, we should be returning a collection of acceptable modes, or have some sort
72     //        of two-step negotiation protocol:
73     //        - Optional<ImportResolutionMode> suggestImportResolutionMode();
74     //        - boolean isImportResolutionModeAcceptable(ImportResolutionMode);
75     //        Let's go with something hacky until we figure out exact requirements.
76     default ImportResolutionMode getImportResolutionMode() {
77         return ImportResolutionMode.REVISION_EXACT_OR_LATEST;
78     }
79 }