import java.util.Arrays;
import java.util.Collections;
import java.util.List;
+import java.util.Set;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.project.MavenProject;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
import org.opendaylight.yangtools.yang2sources.plugin.ConfigArg.CodeGeneratorArg;
+import org.opendaylight.yangtools.yang2sources.spi.CodeGenerator;
import org.slf4j.impl.StaticLoggerBinder;
+import org.sonatype.plexus.build.incremental.BuildContext;
import com.google.common.annotations.VisibleForTesting;
* {@link CodeGenerator}s. Steps of this process:
* <ol>
* <li>List yang files from {@link #yangFilesRootDir}</li>
- * <li>Process yang files using {@link YangModelParserImpl}</li>
+ * <li>Process yang files using {@link YangParserImpl}</li>
* <li>For each {@link CodeGenerator} from {@link #codeGenerators}:</li>
* <ol>
* <li>Instantiate using default constructor</li>
- * <li>Call {@link CodeGenerator#generateSources(SchemaContext, File)}</li>
+ * <li>Call {@link CodeGenerator#generateSources(SchemaContext, File, Set)}</li>
* </ol>
* </ol>
*/
* with .yang suffix).
*/
@Parameter(required = false)
- private String yangFilesRootDir; // defaults to ${basedir}/src/main/yang
+ // defaults to ${basedir}/src/main/yang
+ private String yangFilesRootDir;
+
+ @Parameter(required = false)
+ private String[] excludeFiles;
@Parameter(property = "project", required = true, readonly = true)
- protected MavenProject project;
+ private MavenProject project;
@Parameter(property = "inspectDependencies", required = true, readonly = true)
private boolean inspectDependencies;
+ @Component
+ private BuildContext buildContext;
+
private YangToSourcesProcessor yangToSourcesProcessor;
public YangToSourcesMojo() {
}
+ public void setProject(MavenProject project) {
+ this.project = project;
+ }
+
@VisibleForTesting
YangToSourcesMojo(YangToSourcesProcessor processor) {
this.yangToSourcesProcessor = processor;
List<CodeGeneratorArg> codeGeneratorArgs = processCodeGenerators(codeGenerators);
// defaults to ${basedir}/src/main/yang
- File yangFilesRootFile = processYangFilesRootDir(yangFilesRootDir,
- project.getBasedir());
+ File yangFilesRootFile = processYangFilesRootDir(yangFilesRootDir, project.getBasedir());
+ File[] excludedFiles = processExcludeFiles(excludeFiles, yangFilesRootFile);
- yangToSourcesProcessor = new YangToSourcesProcessor(getLog(),
- yangFilesRootFile, codeGeneratorArgs, project,
- inspectDependencies);
+ yangToSourcesProcessor = new YangToSourcesProcessor(buildContext, getLog(), yangFilesRootFile, excludedFiles,
+ codeGeneratorArgs, project, inspectDependencies);
}
yangToSourcesProcessor.execute();
}
- private static List<CodeGeneratorArg> processCodeGenerators(
- CodeGeneratorArg[] codeGenerators) {
+ private static List<CodeGeneratorArg> processCodeGenerators(CodeGeneratorArg[] codeGenerators) {
List<CodeGeneratorArg> codeGeneratorArgs;
if (codeGenerators == null) {
codeGeneratorArgs = Collections.emptyList();
return codeGeneratorArgs;
}
- private static File processYangFilesRootDir(String yangFilesRootDir,
- File baseDir) {
+ private static File processYangFilesRootDir(String yangFilesRootDir, File baseDir) {
File yangFilesRootFile;
if (yangFilesRootDir == null) {
- yangFilesRootFile = new File(baseDir, "src" + File.separator
- + "main" + File.separator + "yang");
+ yangFilesRootFile = new File(baseDir, "src" + File.separator + "main" + File.separator + "yang");
} else {
File file = new File(yangFilesRootDir);
if (file.isAbsolute()) {
}
return yangFilesRootFile;
}
+
+ private static File[] processExcludeFiles(String[] excludeFiles, File baseDir) {
+ if (excludeFiles == null) {
+ return new File[] {};
+ }
+ File[] result = new File[excludeFiles.length];
+ for (int i = 0; i < excludeFiles.length; i++) {
+ result[i] = new File(baseDir, excludeFiles[i]);
+ }
+
+ return result;
+ }
+
}