import org.opendaylight.yangtools.plugin.generator.api.ModuleResourceResolver;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.sonatype.plexus.build.incremental.BuildContext;
/**
public final class YangToSourcesMojo extends AbstractMojo {
public static final String PLUGIN_NAME = "org.opendaylight.yangtools:yang-maven-plugin";
+ private static final Logger LOG = LoggerFactory.getLogger(YangToSourcesMojo.class);
+
/**
* {@link FileGenerator} instances resolved via ServiceLoader can hold additional configuration, which details
* how they are executed.
private List<ArtifactRepository> remoteRepos;
// When set to "true", then the execution of the plugin is disabled
- @Parameter(property = "yang.skip")
- private String yangSkip;
+ @Parameter(property = "yang.skip", defaultValue = "false")
+ private boolean yangSkip;
@Parameter(defaultValue = "DEFAULT_MODE")
@Deprecated(forRemoval = true)
@Override
@SuppressFBWarnings(value = "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", justification = "yangFilesRootDir")
public void execute() throws MojoExecutionException, MojoFailureException {
- Util.checkClasspath(project, repoSystem, localRepository, remoteRepos);
+ if (yangSkip) {
+ LOG.info("{} Skipping YANG code generation because property yang.skip is true",
+ YangToSourcesProcessor.LOG_PREFIX);
+ return;
+ }
+ Util.checkClasspath(project, repoSystem, localRepository, remoteRepos);
if (yangToSourcesProcessor == null) {
// defaults to ${basedir}/src/main/yang
File yangFilesRootFile = processYangFilesRootDir(yangFilesRootDir, project.getBasedir());
Collection<File> excludedFiles = processExcludeFiles(excludeFiles, yangFilesRootFile);
yangToSourcesProcessor = new YangToSourcesProcessor(buildContext, yangFilesRootFile,
- excludedFiles, arrayToList(fileGenerators), project, inspectDependencies);
+ excludedFiles, arrayToList(fileGenerators), project, inspectDependencies);
}
- yangToSourcesProcessor.conditionalExecute("true".equals(yangSkip));
+ yangToSourcesProcessor.execute();
}
private static <T> List<T> arrayToList(final T[] array) {
YangProvider.getInstance());
}
- public void execute() throws MojoExecutionException, MojoFailureException {
- conditionalExecute(false);
- }
-
- void conditionalExecute(final boolean skip) throws MojoExecutionException, MojoFailureException {
+ void execute() throws MojoExecutionException, MojoFailureException {
var prevState = buildContext.getValue(BUILD_CONTEXT_STATE_NAME);
if (prevState == null) {
LOG.debug("{} BuildContext did not provide state", LOG_PREFIX);
if (optReactor.isPresent()) {
final ProcessorModuleReactor reactor = optReactor.orElseThrow();
- if (!skip) {
- final Stopwatch sw = Stopwatch.createStarted();
- final ContextHolder holder;
+ final Stopwatch sw = Stopwatch.createStarted();
+ final ContextHolder holder;
+
+ try {
+ holder = reactor.toContext();
+ } catch (YangParserException e) {
+ throw new MojoFailureException("Failed to process reactor " + reactor, e);
+ } catch (IOException e) {
+ throw new MojoExecutionException("Failed to read reactor " + reactor, e);
+ }
+
+ LOG.info("{} {} YANG models processed in {}", LOG_PREFIX, holder.getContext().getModules().size(), sw);
+ outputFiles.addAll(generateSources(holder, codeGenerators, parserConfig));
+ if (!sourcesPersisted) {
+ // add META_INF/yang once
+ final var models = reactor.getModelsInProject();
+ final Collection<FileState> sourceFileStates;
try {
- holder = reactor.toContext();
- } catch (YangParserException e) {
- throw new MojoFailureException("Failed to process reactor " + reactor, e);
+ sourceFileStates = yangProvider.addYangsToMetaInf(project, models);
} catch (IOException e) {
- throw new MojoExecutionException("Failed to read reactor " + reactor, e);
+ throw new MojoExecutionException("Failed write model files for " + models, e);
}
- LOG.info("{} {} YANG models processed in {}", LOG_PREFIX, holder.getContext().getModules().size(),
- sw);
- outputFiles.addAll(generateSources(holder, codeGenerators, parserConfig));
-
- if (!sourcesPersisted) {
- // add META_INF/yang once
- final var models = reactor.getModelsInProject();
- final Collection<FileState> sourceFileStates;
- try {
- sourceFileStates = yangProvider.addYangsToMetaInf(project, models);
- } catch (IOException e) {
- throw new MojoExecutionException("Failed write model files for " + models, e);
- }
-
- sourcesPersisted = true;
- outputFiles.addAll(sourceFileStates);
- }
- } else {
- LOG.info("{} Skipping YANG code generation because property yang.skip is true", LOG_PREFIX);
+ sourcesPersisted = true;
+ outputFiles.addAll(sourceFileStates);
}
}
}