pom.xml changes for bundle packaging
Change-Id: I7d4c85b24f79ec526db0cb74bcdf7f0659746163
diff --git a/model/pom.xml b/model/pom.xml
index 36c2f69..522e686 100644
--- a/model/pom.xml
+++ b/model/pom.xml
@@ -26,7 +26,7 @@
</parent>
<artifactId>onos-yang-model</artifactId>
- <packaging>jar</packaging>
+ <packaging>bundle</packaging>
<dependencies>
<dependency>
@@ -50,20 +50,10 @@
<build>
<plugins>
<plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- <version>3.0.2</version>
- <configuration>
- <skipIfEmpty>true</skipIfEmpty>
- </configuration>
- <executions>
- <execution>
- <id>default</id>
- <goals>
- <goal>test-jar</goal>
- </goals>
- </execution>
- </executions>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>3.2.0</version>
+ <extensions>true</extensions>
</plugin>
</plugins>
</build>
diff --git a/model/src/main/java/org/onosproject/yang/model/DefaultYangModel.java b/model/src/main/java/org/onosproject/yang/model/DefaultYangModel.java
new file mode 100644
index 0000000..b1bb8f6
--- /dev/null
+++ b/model/src/main/java/org/onosproject/yang/model/DefaultYangModel.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2017-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.model;
+
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+
+/**
+ * Represents default YANG model implementation.
+ */
+public class DefaultYangModel implements YangModel {
+
+ private final Map<YangModuleId, YangModule> moduleMap;
+
+ /**
+ * Creates an instance of YANG model.
+ */
+ public DefaultYangModel() {
+ moduleMap = new LinkedHashMap<>();
+ }
+
+ @Override
+ public Set<YangModule> getYangModules() {
+ Set<YangModule> modules = new LinkedHashSet<>();
+ for (Map.Entry<YangModuleId, YangModule> entry : moduleMap.entrySet()) {
+ modules.add(entry.getValue());
+ }
+ return modules;
+ }
+
+ @Override
+ public Set<YangModuleId> getYangModulesId() {
+ Set<YangModuleId> ids = new LinkedHashSet<>();
+ for (Map.Entry<YangModuleId, YangModule> entry : moduleMap.entrySet()) {
+ ids.add(entry.getKey());
+ }
+ return ids;
+ }
+
+ @Override
+ public YangModule getYangModule(YangModuleId id) {
+ return moduleMap.get(id);
+ }
+
+ @Override
+ public void addModule(YangModuleId id, YangModule module) {
+ moduleMap.put(id, module);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(moduleMap);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null) {
+ return false;
+ }
+ DefaultYangModel that = (DefaultYangModel) obj;
+
+ if (moduleMap.size() == that.moduleMap.size()) {
+ for (Map.Entry<YangModuleId, YangModule> entry : moduleMap.entrySet()) {
+ if (!that.moduleMap.containsKey(entry.getKey()) ||
+ !that.moduleMap.containsValue(entry.getValue())) {
+ return false;
+ }
+ }
+ } else {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return toStringHelper(getClass())
+ .add("model", moduleMap)
+ .toString();
+ }
+}
diff --git a/model/src/main/java/org/onosproject/yang/model/DefaultYangModule.java b/model/src/main/java/org/onosproject/yang/model/DefaultYangModule.java
new file mode 100644
index 0000000..d209144
--- /dev/null
+++ b/model/src/main/java/org/onosproject/yang/model/DefaultYangModule.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright 2017-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.model;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.nio.file.Path;
+import java.util.Objects;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Represents default YANG module.
+ */
+public class DefaultYangModule implements YangModule {
+
+ private YangModuleId id;
+ private Path yangSrc;
+ private Path metadata;
+
+ /**
+ * Creates an instance of default YANG module.
+ *
+ * @param id YANG module id
+ * @param yangSrc YANG source file path
+ * @param metadata YANG metadata source file path
+ */
+ public DefaultYangModule(YangModuleId id, Path yangSrc, Path metadata) {
+ checkNotNull(yangSrc);
+ checkNotNull(metadata);
+ checkNotNull(id);
+ this.id = id;
+ this.yangSrc = yangSrc;
+ this.metadata = metadata;
+ }
+
+ @Override
+ public YangModuleId getYangModuleId() {
+ return id;
+ }
+
+ @Override
+ public InputStream getYangSource() {
+ try {
+ return new FileInputStream(yangSrc.toString());
+ } catch (FileNotFoundException e) {
+ throw new ModelException("Yang source file not found." +
+ yangSrc);
+ }
+ }
+
+ @Override
+ public InputStream getMetadata() {
+ try {
+ return new FileInputStream(metadata.toString());
+ } catch (FileNotFoundException e) {
+ throw new ModelException("metadata source file not found." +
+ metadata);
+ }
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(id, yangSrc, metadata);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null) {
+ return false;
+ }
+
+ DefaultYangModule that = (DefaultYangModule) obj;
+ return Objects.equals(id, that.id) &&
+ Objects.equals(yangSrc, that.yangSrc) &&
+ Objects.equals(metadata, that.metadata);
+ }
+
+ @Override
+ public String toString() {
+ return toStringHelper(getClass())
+ .add("moduleId", id)
+ .add("yangSource", yangSrc)
+ .add("yangMetadata", metadata)
+ .toString();
+ }
+}
diff --git a/model/src/main/java/org/onosproject/yang/model/DefaultYangModuleId.java b/model/src/main/java/org/onosproject/yang/model/DefaultYangModuleId.java
new file mode 100644
index 0000000..284d605
--- /dev/null
+++ b/model/src/main/java/org/onosproject/yang/model/DefaultYangModuleId.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2017-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.model;
+
+import java.util.Objects;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Represents default YANG module identifier.
+ */
+public class DefaultYangModuleId implements YangModuleId {
+
+ private String moduleName;
+ private String revision;
+
+ /**
+ * Creates an instance of default YANG module id.
+ *
+ * @param name name of module
+ * @param rev revision of module
+ */
+ public DefaultYangModuleId(String name, String rev) {
+ checkNotNull(name);
+ moduleName = name;
+ revision = rev;
+ }
+
+ @Override
+ public String moduleName() {
+ return moduleName;
+ }
+
+ @Override
+ public String revision() {
+ return revision;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(moduleName, revision);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null) {
+ return false;
+ }
+
+ DefaultYangModuleId that = (DefaultYangModuleId) obj;
+ return Objects.equals(moduleName, that.moduleName) &&
+ Objects.equals(revision, that.revision);
+ }
+
+ @Override
+ public String toString() {
+ return toStringHelper(getClass())
+ .add("moduleName", moduleName)
+ .add("revision", revision)
+ .toString();
+ }
+}
diff --git a/model/src/main/java/org/onosproject/yang/model/YangModel.java b/model/src/main/java/org/onosproject/yang/model/YangModel.java
new file mode 100644
index 0000000..74dd0cb
--- /dev/null
+++ b/model/src/main/java/org/onosproject/yang/model/YangModel.java
@@ -0,0 +1,56 @@
+/*
+ * 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.model;
+
+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);
+
+ /**
+ * Adds YANG module information for a given module identifier.
+ *
+ * @param id module identifier
+ * @param module YANG module information
+ */
+ void addModule(YangModuleId id, YangModule module);
+}
diff --git a/model/src/main/java/org/onosproject/yang/model/YangModule.java b/model/src/main/java/org/onosproject/yang/model/YangModule.java
new file mode 100644
index 0000000..8aed5ef
--- /dev/null
+++ b/model/src/main/java/org/onosproject/yang/model/YangModule.java
@@ -0,0 +1,46 @@
+/*
+ * 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.model;
+
+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/model/src/main/java/org/onosproject/yang/model/YangModuleId.java b/model/src/main/java/org/onosproject/yang/model/YangModuleId.java
new file mode 100644
index 0000000..484660e
--- /dev/null
+++ b/model/src/main/java/org/onosproject/yang/model/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.model;
+
+/**
+ * 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();
+}