X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=yang%2Fyang-maven-plugin%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang2sources%2Fplugin%2FYangToSourcesMojo.java;h=8ecc6f230a75b337456239cd356753a0137627b4;hb=01d91de2265e55fab1b1e67171bd668146398017;hp=49d9ef62d37aa868526c9785317661d53347c921;hpb=5c1f875f69e35248aa4115c429bd962160beeef4;p=yangtools.git
diff --git a/yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangToSourcesMojo.java b/yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangToSourcesMojo.java
index 49d9ef62d3..8ecc6f230a 100644
--- a/yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangToSourcesMojo.java
+++ b/yang/yang-maven-plugin/src/main/java/org/opendaylight/yangtools/yang2sources/plugin/YangToSourcesMojo.java
@@ -7,45 +7,55 @@
*/
package org.opendaylight.yangtools.yang2sources.plugin;
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.ImmutableList;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.io.File;
import java.util.Arrays;
+import java.util.Collection;
import java.util.Collections;
import java.util.List;
-
+import java.util.Set;
+import java.util.function.Function;
+import org.apache.maven.artifact.repository.ArtifactRepository;
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.apache.maven.repository.RepositorySystem;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang2sources.plugin.ConfigArg.CodeGeneratorArg;
-
-import com.google.common.annotations.VisibleForTesting;
+import org.opendaylight.yangtools.yang2sources.spi.BasicCodeGenerator;
+import org.sonatype.plexus.build.incremental.BuildContext;
/**
* Generate sources from yang files using user provided set of
- * {@link CodeGenerator}s. Steps of this process:
+ * {@link BasicCodeGenerator}s. Steps of this process:
*
* - List yang files from {@link #yangFilesRootDir}
- * - Process yang files using {@link YangModelParserImpl}
- * - For each {@link CodeGenerator} from {@link #codeGenerators}:
+ * - Process yang files using Yang Parser
+ * - For each {@link BasicCodeGenerator} from {@link #codeGenerators}:
*
* - Instantiate using default constructor
- * - Call {@link CodeGenerator#generateSources(SchemaContext, File)}
- *
+ * - Call {@link BasicCodeGenerator#generateSources(SchemaContext, File, Set, Function)}
+ *
*
*/
-@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 {
+ public static final String PLUGIN_NAME = "org.opendaylight.yangtools:yang-maven-plugin";
/**
- * Classes implementing {@link CodeGenerator} interface. An instance will be
+ * Classes implementing {@link BasicCodeGenerator} interface. An instance will be
* created out of every class using default constructor. Method {@link
- * CodeGenerator#generateSources(SchemaContext, File, Set
- * yangModulesNames)} will be called on every instance.
+ * BasicCodeGenerator#generateSources(SchemaContext, File, Set)} will be called on every instance.
*/
@Parameter(required = false)
private CodeGeneratorArg[] codeGenerators;
@@ -55,43 +65,68 @@ public final class YangToSourcesMojo extends AbstractMojo {
* 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)
+ @Parameter(property = "inspectDependencies")
private boolean inspectDependencies;
+ @Component
+ private BuildContext buildContext;
+
private YangToSourcesProcessor yangToSourcesProcessor;
+ @Component
+ private RepositorySystem repoSystem;
+
+ @Parameter(readonly = true, defaultValue = "${localRepository}")
+ private ArtifactRepository localRepository;
+
+ @Parameter(readonly = true, defaultValue = "${project.remoteArtifactRepositories}")
+ private List remoteRepos;
+
+ // When set to "true", then the execution of the plugin is disabled
+ @Parameter(property = "yang.skip")
+ private String yangSkip;
+
public YangToSourcesMojo() {
}
@VisibleForTesting
- YangToSourcesMojo(YangToSourcesProcessor processor) {
+ YangToSourcesMojo(final YangToSourcesProcessor processor) {
this.yangToSourcesProcessor = processor;
}
+ public void setProject(final MavenProject project) {
+ this.project = project;
+ }
+
@Override
+ @SuppressFBWarnings(value = "UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR", justification = "yangFilesRootDir")
public void execute() throws MojoExecutionException, MojoFailureException {
+ Util.checkClasspath(project, repoSystem, localRepository, remoteRepos);
+
if (yangToSourcesProcessor == null) {
List codeGeneratorArgs = processCodeGenerators(codeGenerators);
// defaults to ${basedir}/src/main/yang
- File yangFilesRootFile = processYangFilesRootDir(yangFilesRootDir,
- project.getBasedir());
+ File yangFilesRootFile = processYangFilesRootDir(yangFilesRootDir, project.getBasedir());
+ Collection excludedFiles = processExcludeFiles(excludeFiles, yangFilesRootFile);
- yangToSourcesProcessor = new YangToSourcesProcessor(getLog(),
- yangFilesRootFile, codeGeneratorArgs, project,
- inspectDependencies);
+ yangToSourcesProcessor = new YangToSourcesProcessor(buildContext, yangFilesRootFile,
+ excludedFiles, codeGeneratorArgs, project, inspectDependencies);
}
- yangToSourcesProcessor.execute();
+ yangToSourcesProcessor.conditionalExecute("true".equals(yangSkip));
}
- private static List processCodeGenerators(
- CodeGeneratorArg[] codeGenerators) {
+ private static List processCodeGenerators(final CodeGeneratorArg[] codeGenerators) {
List codeGeneratorArgs;
if (codeGenerators == null) {
codeGeneratorArgs = Collections.emptyList();
@@ -101,12 +136,10 @@ public final class YangToSourcesMojo extends AbstractMojo {
return codeGeneratorArgs;
}
- private static File processYangFilesRootDir(String yangFilesRootDir,
- File baseDir) {
+ private static File processYangFilesRootDir(final String yangFilesRootDir, final 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()) {
@@ -117,4 +150,13 @@ public final class YangToSourcesMojo extends AbstractMojo {
}
return yangFilesRootFile;
}
+
+ private static Collection processExcludeFiles(final String[] excludeFiles, final File baseDir) {
+ if (excludeFiles == null) {
+ return ImmutableList.of();
+ }
+
+ return Collections2.transform(Arrays.asList(excludeFiles), f -> new File(baseDir, f));
+ }
+
}