mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-10-17 02:11:38 +02:00
[ONOS-3875] Implementation of maven plugin.
Change-Id: Id2930fec97037dc238a35fea0b118e6a00300f8e
This commit is contained in:
parent
bcad55b9e6
commit
ec4ef7cb4b
@ -17,6 +17,9 @@
|
||||
package org.onosproject.yangutils.parser;
|
||||
|
||||
import org.onosproject.yangutils.datamodel.YangNode;
|
||||
import org.onosproject.yangutils.parser.exceptions.ParserException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Abstraction of entity which provides parser service of YANG files for yangutils-maven-plugin.
|
||||
@ -28,6 +31,7 @@ public interface YangUtilsParser {
|
||||
*
|
||||
* @param file input YANG file
|
||||
* @return YangNode root node of the data model tree
|
||||
* @throws ParserException when fails to get the data model
|
||||
*/
|
||||
YangNode getDataModel(String file);
|
||||
YangNode getDataModel(String file) throws IOException, ParserException;
|
||||
}
|
||||
|
@ -16,25 +16,94 @@
|
||||
|
||||
package org.onosproject.yangutils.plugin.manager;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.maven.plugin.AbstractMojo;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
import org.apache.maven.plugins.annotations.LifecyclePhase;
|
||||
import org.apache.maven.plugins.annotations.Mojo;
|
||||
import org.apache.maven.plugins.annotations.ResolutionScope;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.plugins.annotations.Parameter;
|
||||
import org.apache.maven.plugins.annotations.Component;
|
||||
import org.sonatype.plexus.build.incremental.BuildContext;
|
||||
|
||||
import org.onosproject.yangutils.datamodel.YangNode;
|
||||
import org.onosproject.yangutils.parser.YangUtilsParser;
|
||||
import org.onosproject.yangutils.parser.exceptions.ParserException;
|
||||
import org.onosproject.yangutils.utils.io.impl.YangFileScanner;
|
||||
|
||||
/**
|
||||
* ONOS YANG utility maven plugin.
|
||||
* Goal of plugin is yang2java
|
||||
* Execution phase in generate-sources
|
||||
* requiresDependencyResolution at compile time
|
||||
*/
|
||||
* ONOS YANG utility maven plugin.
|
||||
* Goal of plugin is yang2java
|
||||
* Execution phase in generate-sources
|
||||
* requiresDependencyResolution at compile time
|
||||
*/
|
||||
@Mojo(name = "yang2java", defaultPhase = LifecyclePhase.GENERATE_SOURCES,
|
||||
requiresDependencyResolution = ResolutionScope.COMPILE, requiresProject = true)
|
||||
requiresDependencyResolution = ResolutionScope.COMPILE, requiresProject = true)
|
||||
public class YangUtilManager extends AbstractMojo {
|
||||
|
||||
/**
|
||||
* Source directory for YANG files.
|
||||
*/
|
||||
@Parameter(property = "yangFilesDir", defaultValue = "src/main/yang")
|
||||
private String yangFilesDir;
|
||||
|
||||
/**
|
||||
* Output directory.
|
||||
*/
|
||||
@Parameter(property = "project.build.outputDirectory", required = true, defaultValue = "target/classes")
|
||||
private File outputDirectory;
|
||||
|
||||
/**
|
||||
* Current maven project.
|
||||
*/
|
||||
@Parameter(property = "project", required = true, readonly = true, defaultValue = "${project}")
|
||||
private MavenProject project;
|
||||
|
||||
/**
|
||||
* Build context.
|
||||
*/
|
||||
@Component
|
||||
private BuildContext context;
|
||||
|
||||
private YangUtilsParser yangUtilsParser;
|
||||
private String baseDir;
|
||||
private String searchDir;
|
||||
|
||||
/**
|
||||
* Set current project.
|
||||
*
|
||||
* @param project maven project.
|
||||
*/
|
||||
public void setCurrentProject(final MavenProject project) {
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() throws MojoExecutionException, MojoFailureException {
|
||||
//TODO: implement the MOJO plugin
|
||||
|
||||
try {
|
||||
baseDir = project.getBasedir().toString();
|
||||
searchDir = baseDir + File.separator + yangFilesDir;
|
||||
|
||||
List<String> yangFiles = YangFileScanner.getYangFiles(searchDir);
|
||||
Iterator<String> yangFileIterator = yangFiles.iterator();
|
||||
while (yangFileIterator.hasNext()) {
|
||||
String yangFile = yangFileIterator.next();
|
||||
try {
|
||||
YangNode yangNode = yangUtilsParser.getDataModel(yangFile);
|
||||
//TODO: send this data model to translator and create the corresponding java files.
|
||||
} catch (ParserException e) {
|
||||
getLog().info("Invalid yang file.");
|
||||
}
|
||||
}
|
||||
} catch (final IOException e) {
|
||||
getLog().info("Exception occured");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user