2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang2sources.spi;
11 import java.io.IOException;
12 import java.util.Collection;
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;
21 * Maven 3.1.x and newer uses SLF4J internally, which means we do not need to pass a logger instance around.
23 * @deprecated Use {@link FileGenerator} instead.
26 public interface BasicCodeGenerator {
27 enum ImportResolutionMode {
29 * Standard, RFC6020 and RFC7950 compliant mode. Imports are satisfied by exact revision match (if specified),
30 * or by latest available revision.
32 REVISION_EXACT_OR_LATEST(FileGenerator.ImportResolutionMode.REVISION_EXACT_OR_LATEST),
34 * Semantic version based mode. Imports which specify a semantic version (via the OpenConfig extension) will
35 * be satisfied by module which exports the latest compatible revision. Imports which do not specify semantic
36 * version will be resolved just as they would be via {@link #REVISION_EXACT_OR_LATEST}.
38 * @deprecated This mode has no users and is deprecated for removal.
40 @Deprecated(forRemoval = true, since = "8.0.4")
41 SEMVER_LATEST(FileGenerator.ImportResolutionMode.SEMVER_LATEST);
43 private final FileGenerator.@NonNull ImportResolutionMode fileGeneratorMode;
45 ImportResolutionMode(final FileGenerator.@NonNull ImportResolutionMode fileGeneratorMode) {
46 this.fileGeneratorMode = fileGeneratorMode;
50 * Return {@link FileGenerator.ImportResolutionMode} equivalent of this mode.
52 * @return {@link FileGenerator.ImportResolutionMode} equivalent of this mode
54 public final FileGenerator.@NonNull ImportResolutionMode toFileGeneratorMode() {
55 return fileGeneratorMode;
60 * Generate sources from provided {@link EffectiveModelContext}.
63 * parsed from YANG files
64 * @param outputBaseDir
65 * expected output directory for generated sources configured by
67 * @param currentModules
68 * YANG modules parsed from yangFilesRootDir
69 * @param moduleResourcePathResolver
70 * Function converting a local module to the packaged resource path
71 * @return collection of files that were generated from schema context
73 Collection<File> generateSources(EffectiveModelContext context, File outputBaseDir, Set<Module> currentModules,
74 ModuleResourceResolver moduleResourcePathResolver) throws IOException;
77 * Provided map contains all configuration that was set in pom for code
78 * generator in additionalConfiguration tag.
80 void setAdditionalConfig(Map<String, String> additionalConfiguration);
83 * Provided folder is marked as resources and its content will be packaged
84 * in resulting jar. Feel free to add necessary resources.
86 void setResourceBaseDir(File resourceBaseDir);
89 * Indicate import resolution mode this code generator requires. Default implementation indicates
90 * {@link ImportResolutionMode#REVISION_EXACT_OR_LATEST}.
92 * @return Required import resolution mode, null if the code generator does not care.
94 // FIXME: This is not really extensible, we should be returning a collection of acceptable modes, or have some sort
95 // of two-step negotiation protocol:
96 // - Optional<ImportResolutionMode> suggestImportResolutionMode();
97 // - boolean isImportResolutionModeAcceptable(ImportResolutionMode);
98 // Let's go with something hacky until we figure out exact requirements.
99 default ImportResolutionMode getImportResolutionMode() {
100 return ImportResolutionMode.REVISION_EXACT_OR_LATEST;