-@Mojo(name = "generate-sources", defaultPhase = LifecyclePhase.GENERATE_SOURCES,requiresDependencyResolution=ResolutionScope.COMPILE,requiresProject=true)
+@Mojo(name = "generate-sources", defaultPhase = LifecyclePhase.GENERATE_SOURCES, requiresDependencyResolution = ResolutionScope.COMPILE, requiresProject = true)
public final class YangToSourcesMojo extends AbstractMojo {
private static final String LOG_PREFIX = "yang-to-sources:";
public final class YangToSourcesMojo extends AbstractMojo {
private static final String LOG_PREFIX = "yang-to-sources:";
@Parameter(property = "project", required = true, readonly = true)
protected MavenProject project;
@Parameter(property = "project", required = true, readonly = true)
protected MavenProject project;
private SchemaContext processYang() throws MojoExecutionException {
try {
Collection<File> yangFiles = Util.listFiles(yangFilesRootDir);
private SchemaContext processYang() throws MojoExecutionException {
try {
Collection<File> yangFiles = Util.listFiles(yangFilesRootDir);
if (yangFiles.isEmpty()) {
getLog().warn(
Util.message("No %s file found in %s", LOG_PREFIX,
Util.YANG_SUFFIX, yangFilesRootDir));
return null;
if (yangFiles.isEmpty()) {
getLog().warn(
Util.message("No %s file found in %s", LOG_PREFIX,
Util.YANG_SUFFIX, yangFilesRootDir));
return null;
- project.addCompileSourceRoot(outputDir.getPath());
- Collection<File> generated = g.generateSources(context,
- outputDir);
+ if (project != null && outputDir != null) {
+ project.addCompileSourceRoot(outputDir.getPath());
+ }
+ Collection<File> generated = g.generateSources(context, outputDir);
getLog().info(
Util.message("Sources generated by %s: %s", LOG_PREFIX,
codeGeneratorCfg.getCodeGeneratorClass(), generated));
getLog().info(
Util.message("Sources generated by %s: %s", LOG_PREFIX,
codeGeneratorCfg.getCodeGeneratorClass(), generated));