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