[ONOS-5766] Define YANG compiler API
Change-Id: I93ce8dd4340f51282dcfc2be30838eff6c2f8f81
diff --git a/compiler/api/pom.xml b/compiler/api/pom.xml
index fd80dc2..e2398a6 100644
--- a/compiler/api/pom.xml
+++ b/compiler/api/pom.xml
@@ -25,10 +25,7 @@
</parent>
<artifactId>onos-yang-compiler-api</artifactId>
- <packaging>pom</packaging>
- <!--
- Change packaging to jar
- -->
+ <packaging>jar</packaging>
<build>
<plugins>
<plugin>
diff --git a/compiler/api/src/main/java/org/onosproject/yang/YangModel.java b/compiler/api/src/main/java/org/onosproject/yang/YangModel.java
new file mode 100644
index 0000000..cd5f403
--- /dev/null
+++ b/compiler/api/src/main/java/org/onosproject/yang/YangModel.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2017. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
+ * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
+ * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
+ * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
+ * Vestibulum commodo. Ut rhoncus gravida arcu.
+ */
+
+package org.onosproject.yang;
+
+import java.util.Set;
+
+/**
+ * Representation of a compiled YANG model.
+ */
+public interface YangModel {
+
+ /**
+ * Returns set of YANG module with information.
+ *
+ * @return YANG module info
+ */
+ Set<YangModule> getYangModules();
+
+ /**
+ * Returns set of YANG modules identifier.
+ *
+ * @return YANG module identifier
+ */
+ Set<YangModuleId> getYangModulesId();
+
+ /**
+ * Returns YANG module information corresponding to a given module
+ * identifier.
+ *
+ * @param id module identifier
+ * @return YANG module information
+ */
+ YangModule getYangModule(YangModuleId id);
+}
diff --git a/compiler/api/src/main/java/org/onosproject/yang/YangModule.java b/compiler/api/src/main/java/org/onosproject/yang/YangModule.java
new file mode 100644
index 0000000..70990f9
--- /dev/null
+++ b/compiler/api/src/main/java/org/onosproject/yang/YangModule.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2017. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
+ * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
+ * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
+ * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
+ * Vestibulum commodo. Ut rhoncus gravida arcu.
+ */
+
+package org.onosproject.yang;
+
+import java.io.InputStream;
+
+/**
+ * Representation of YANG module information.
+ */
+public interface YangModule {
+
+ /**
+ * Returns YANG module identifier.
+ *
+ * @return module identifier
+ */
+ YangModuleId getYangModuleId();
+
+ /**
+ * Returns input stream corresponding to a given YANG file path.
+ *
+ * @return stream
+ */
+ InputStream getYangSource();
+
+ /**
+ * Returns metadata stream.
+ *
+ * @return stream
+ */
+ InputStream getMetadata();
+}
diff --git a/compiler/api/src/main/java/org/onosproject/yang/YangModuleId.java b/compiler/api/src/main/java/org/onosproject/yang/YangModuleId.java
new file mode 100644
index 0000000..44872df
--- /dev/null
+++ b/compiler/api/src/main/java/org/onosproject/yang/YangModuleId.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang;
+
+/**
+ * Representation of an entity which provides YANG module identifiers.
+ * Reference RFC 7895.
+ */
+public interface YangModuleId {
+
+ /**
+ * Returns the name of the YANG module.
+ *
+ * @return name of the YANG module
+ */
+ String moduleName();
+
+ /**
+ * Returns revision of the YANG module.
+ * <p>
+ * Reference RFC 7895
+ * Each YANG module and submodule within the library has a
+ * revision. This is derived from the most recent revision statement
+ * within the module or submodule. If no such revision statement
+ * exists, the module's or submodule's revision is the zero-length
+ * string.
+ *
+ * @return revision of the YANG module
+ */
+ String revision();
+}
diff --git a/compiler/api/src/main/java/org/onosproject/yang/compiler/api/YangCompilationParam.java b/compiler/api/src/main/java/org/onosproject/yang/compiler/api/YangCompilationParam.java
new file mode 100644
index 0000000..b44814f
--- /dev/null
+++ b/compiler/api/src/main/java/org/onosproject/yang/compiler/api/YangCompilationParam.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.api;
+
+import java.nio.file.Path;
+import java.util.Set;
+
+/**
+ * Representation of parameters required for YANG compilation.
+ */
+public interface YangCompilationParam {
+
+ /**
+ * Returns set of YANG files path. This could be a directory in which
+ * YANG files resides, all files under that directory will be taken.
+ *
+ * @return set of YANG file path
+ */
+ Set<Path> getYangFiles();
+
+ /**
+ * Adds YANG file path. This could be a directory in which YANG files are
+ * available.
+ *
+ * @param path YANG file path
+ */
+ void addYangFile(Path path);
+
+ /**
+ * Returns set of dependent metadata paths.
+ *
+ * @return set of dependent metadata path
+ */
+ Set<Path> getDependentSchemas();
+
+ /**
+ * Adds dependent metadata path.
+ *
+ * @param path metadata path
+ */
+ void addDependentSchema(Path path);
+
+ /**
+ * Returns the desired path of generated code. If its not specified default
+ * path will be taken.
+ *
+ * @return path to generated code destination directory
+ */
+ Path getCodeGenDir();
+
+ /**
+ * Sets code generation directory.
+ *
+ * @param path expected code generation directory
+ */
+ void setCodeGenDir(Path path);
+
+ /**
+ * Returns the desired path of metadata. If its not specified default
+ * path will be taken.
+ *
+ * @return path to generated metadata destination directory.
+ */
+ Path getMetadataGenDir();
+
+ /**
+ * Sets metadata generation directory.
+ *
+ * @param path expected metadata generation directory
+ */
+ void setMetadataGenDir(Path path);
+}
diff --git a/compiler/api/src/main/java/org/onosproject/yang/compiler/api/YangCompiledOutput.java b/compiler/api/src/main/java/org/onosproject/yang/compiler/api/YangCompiledOutput.java
new file mode 100644
index 0000000..4caedb8
--- /dev/null
+++ b/compiler/api/src/main/java/org/onosproject/yang/compiler/api/YangCompiledOutput.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.api;
+
+import org.onosproject.yang.YangModel;
+
+import java.nio.file.Path;
+import java.util.Set;
+
+/**
+ * Representation of an entity that provides YANG compiled output.
+ */
+public interface YangCompiledOutput {
+
+ /**
+ * Returns compiled YANG model.
+ *
+ * @return YANG model
+ */
+ YangModel getYangModel();
+
+ /**
+ * Returns generated JAVA files.
+ *
+ * @return generated JAVA files.
+ */
+ Set<Path> getGeneratedJava();
+}
\ No newline at end of file
diff --git a/compiler/api/src/main/java/org/onosproject/yang/compiler/api/YangCompilerException.java b/compiler/api/src/main/java/org/onosproject/yang/compiler/api/YangCompilerException.java
new file mode 100644
index 0000000..6857a31
--- /dev/null
+++ b/compiler/api/src/main/java/org/onosproject/yang/compiler/api/YangCompilerException.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.api;
+
+import java.nio.file.Path;
+
+/**
+ * Represents base class for exceptions in YANG tool operations.
+ */
+public class YangCompilerException extends RuntimeException {
+
+ private static final long serialVersionUID = 20161028L;
+
+ private Path yangFile;
+
+ /**
+ * Creates a new YANG tool exception with given message. It's expected
+ * that caller of YANG compiler display's exception message to communicate
+ * error information with user.
+ *
+ * @param message the detail of exception in string
+ */
+ public YangCompilerException(String message) {
+ super(message);
+ }
+
+ /**
+ * Creates a new tool exception from given message and cause. It's expected
+ * that caller of YANG compiler display's exception cause and message to
+ * communicate error information with user.
+ *
+ * @param message the detail of exception in string
+ * @param cause underlying cause of the error
+ */
+ public YangCompilerException(final String message, final Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * Creates a new tool exception from cause. It's expected
+ * that caller of YANG compiler display's exception cause to communicate
+ * error information with user.
+ *
+ * @param cause underlying cause of the error
+ */
+ public YangCompilerException(final Throwable cause) {
+ super(cause);
+ }
+
+ /**
+ * Retrieves the current YANG files for which exception has occured.
+ *
+ * @return current YANG file
+ */
+ public Path getYangFile() {
+ return yangFile;
+ }
+
+
+ /**
+ * Updates the YANG file which caused the exception.
+ *
+ * @param yangFile YANG files being processed
+ */
+ public void setYangFile(Path yangFile) {
+ this.yangFile = yangFile;
+ }
+}
diff --git a/compiler/api/src/main/java/org/onosproject/yang/compiler/api/YangCompilerService.java b/compiler/api/src/main/java/org/onosproject/yang/compiler/api/YangCompilerService.java
new file mode 100644
index 0000000..6fb9643
--- /dev/null
+++ b/compiler/api/src/main/java/org/onosproject/yang/compiler/api/YangCompilerService.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yang.compiler.api;
+
+import java.io.IOException;
+
+/**
+ * Representation of an entity that provides YANG compilation service.
+ */
+public interface YangCompilerService {
+
+ /**
+ * Compiles YANG files and generates the required code with serialized
+ * metadata.
+ *
+ * @param param YANG compilation parameters
+ * @return compiled output
+ * @throws IOException a violation in IO rule
+ * @throws YangCompilerException a violation in YANG compilation rule
+ */
+ YangCompiledOutput compileYangFiles(YangCompilationParam param)
+ throws IOException, YangCompilerException;
+}
diff --git a/compiler/api/src/main/java/org/onosproject/yang/package-info.java b/compiler/api/src/main/java/org/onosproject/yang/package-info.java
new file mode 100644
index 0000000..d720de4
--- /dev/null
+++ b/compiler/api/src/main/java/org/onosproject/yang/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Representation of a compiled YANG model.
+ */
+package org.onosproject.yang;
\ No newline at end of file