[ONOS-5789] YANG compiler api implementation.
Change-Id: I1b3f894a43d17c1f7301fef8ef3700f4b8e4936e
diff --git a/compiler/api/src/main/java/org/onosproject/yang/DefaultYangModel.java b/compiler/api/src/main/java/org/onosproject/yang/DefaultYangModel.java
new file mode 100644
index 0000000..18358bc
--- /dev/null
+++ b/compiler/api/src/main/java/org/onosproject/yang/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;
+
+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/compiler/api/src/main/java/org/onosproject/yang/DefaultYangModule.java b/compiler/api/src/main/java/org/onosproject/yang/DefaultYangModule.java
new file mode 100644
index 0000000..3ccbd9c
--- /dev/null
+++ b/compiler/api/src/main/java/org/onosproject/yang/DefaultYangModule.java
@@ -0,0 +1,105 @@
+/*
+ * 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;
+
+import org.onosproject.yang.compiler.api.YangCompilerException;
+
+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 YangCompilerException("Yang source file not found." +
+ yangSrc);
+ }
+ }
+
+ @Override
+ public InputStream getMetadata() {
+ try {
+ return new FileInputStream(metadata.toString());
+ } catch (FileNotFoundException e) {
+ throw new YangCompilerException("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/compiler/api/src/main/java/org/onosproject/yang/DefaultYangModuleId.java b/compiler/api/src/main/java/org/onosproject/yang/DefaultYangModuleId.java
new file mode 100644
index 0000000..cea422e
--- /dev/null
+++ b/compiler/api/src/main/java/org/onosproject/yang/DefaultYangModuleId.java
@@ -0,0 +1,78 @@
+/*
+ * 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;
+
+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);
+ checkNotNull(rev);
+ 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/compiler/api/src/main/java/org/onosproject/yang/YangModel.java b/compiler/api/src/main/java/org/onosproject/yang/YangModel.java
index cd5f403..fb45c27 100644
--- a/compiler/api/src/main/java/org/onosproject/yang/YangModel.java
+++ b/compiler/api/src/main/java/org/onosproject/yang/YangModel.java
@@ -1,9 +1,17 @@
/*
- * 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.
+ * 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;
@@ -37,4 +45,12 @@
* @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/compiler/api/src/main/java/org/onosproject/yang/YangModule.java b/compiler/api/src/main/java/org/onosproject/yang/YangModule.java
index 70990f9..9b170fa 100644
--- a/compiler/api/src/main/java/org/onosproject/yang/YangModule.java
+++ b/compiler/api/src/main/java/org/onosproject/yang/YangModule.java
@@ -1,9 +1,17 @@
/*
- * 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.
+ * 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;
diff --git a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/DataModelUtils.java b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/DataModelUtils.java
index 9ff2b15..6d42e9d 100644
--- a/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/DataModelUtils.java
+++ b/compiler/base/datamodel/src/main/java/org/onosproject/yang/compiler/datamodel/utils/DataModelUtils.java
@@ -872,6 +872,51 @@
}
/**
+ * Parses jar file and returns list of serialized file names.
+ *
+ * @param jarFile jar file to be parsed
+ * @param directory directory where to search
+ * @return list of serialized files
+ * @throws IOException when fails to do IO operations
+ */
+ public static File parseDepSchemaPath(String jarFile, String directory)
+ throws IOException {
+ JarFile jar = new JarFile(jarFile);
+ Enumeration<?> enumEntries = jar.entries();
+ File serializedFile = null;
+ while (enumEntries.hasMoreElements()) {
+ JarEntry file = (JarEntry) enumEntries.nextElement();
+ if (file.getName().endsWith(".ser")) {
+
+ if (file.getName().contains(SLASH)) {
+ String[] strArray = file.getName().split(SLASH);
+ String tempPath = "";
+ for (int i = 0; i < strArray.length - 1; i++) {
+ tempPath = SLASH + tempPath + SLASH + strArray[i];
+ }
+ File dir = new File(directory + tempPath);
+ dir.mkdirs();
+ }
+ serializedFile = new File(directory + SLASH + file.getName());
+ if (file.isDirectory()) {
+ serializedFile.mkdirs();
+ continue;
+ }
+ InputStream inputStream = jar.getInputStream(file);
+
+ FileOutputStream fileOutputStream = new FileOutputStream(serializedFile);
+ while (inputStream.available() > 0) {
+ fileOutputStream.write(inputStream.read());
+ }
+ fileOutputStream.close();
+ inputStream.close();
+ }
+ }
+ jar.close();
+ return serializedFile;
+ }
+
+ /**
* Validates the requested data-type resolve type in empty or not.
*
* @param dataType the data type
diff --git a/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/InputListener.java b/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/InputListener.java
index a350b18..1090adf 100644
--- a/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/InputListener.java
+++ b/compiler/base/parser/src/main/java/org/onosproject/yang/compiler/parser/impl/listeners/InputListener.java
@@ -23,7 +23,6 @@
import org.onosproject.yang.compiler.datamodel.utils.Parsable;
import org.onosproject.yang.compiler.parser.exceptions.ParserException;
import org.onosproject.yang.compiler.parser.impl.TreeWalkListener;
-import org.onosproject.yang.compiler.utils.UtilConstants;
import static org.onosproject.yang.compiler.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
import static org.onosproject.yang.compiler.datamodel.utils.YangConstructType.INPUT_DATA;
diff --git a/compiler/base/tool/pom.xml b/compiler/base/tool/pom.xml
index 005b2a7..e7a5aa0 100644
--- a/compiler/base/tool/pom.xml
+++ b/compiler/base/tool/pom.xml
@@ -62,6 +62,11 @@
<artifactId>onos-yang-compiler-parser</artifactId>
<version>1.12-SNAPSHOT</version>
</dependency>
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-yang-compiler-api</artifactId>
+ <version>1.12-SNAPSHOT</version>
+ </dependency>
</dependencies>
<build>
<plugins>
diff --git a/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/base/tool/CallablePlugin.java b/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/base/tool/CallablePlugin.java
deleted file mode 100644
index 46cc1c1..0000000
--- a/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/base/tool/CallablePlugin.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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.base.tool;
-
-import java.io.IOException;
-
-/**
- * Abstractions of the hooks that needs to be supported by plugins, which
- * will be used in by tool to be plugin agnostic.
- */
-public interface CallablePlugin {
-
- /**
- * Adds generated source directory to the compilation root.
- */
- void addGeneratedCodeToBundle();
-
- /**
- * serialize the compiled schema and place it in the appropriate location
- * so that it will be part of the generated OSGi bundle.
- *
- * @throws IOException when fails to do IO operations
- */
- void addCompiledSchemaToBundle()
- throws IOException;
-
-
- /**
- * Add the YANG files in the bundle, to support YANG display in protocols
- * like RESTCONF.
- *
- * @throws IOException when fails to do IO operations
- */
- void addYangFilesToBundle() throws IOException;
-}
diff --git a/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/base/tool/YangToolManager.java b/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/base/tool/YangToolManager.java
deleted file mode 100644
index d4992cb..0000000
--- a/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/base/tool/YangToolManager.java
+++ /dev/null
@@ -1,334 +0,0 @@
-/*
- * 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.base.tool;
-
-import org.onosproject.yang.compiler.base.tool.exception.YangToolException;
-import org.onosproject.yang.compiler.datamodel.YangDeviationHolder;
-import org.onosproject.yang.compiler.datamodel.YangNode;
-import org.onosproject.yang.compiler.datamodel.YangReferenceResolver;
-import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
-import org.onosproject.yang.compiler.linker.YangLinker;
-import org.onosproject.yang.compiler.linker.exceptions.LinkerException;
-import org.onosproject.yang.compiler.linker.impl.YangLinkerManager;
-import org.onosproject.yang.compiler.parser.YangUtilsParser;
-import org.onosproject.yang.compiler.parser.exceptions.ParserException;
-import org.onosproject.yang.compiler.parser.impl.YangUtilsParserManager;
-import org.onosproject.yang.compiler.utils.io.YangPluginConfig;
-import org.slf4j.Logger;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.ObjectOutputStream;
-import java.nio.file.Files;
-import java.nio.file.StandardCopyOption;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Set;
-
-import static java.util.Collections.sort;
-import static org.onosproject.yang.compiler.base.tool.ToolConstants.E_CODE_GEN_PATH;
-import static org.onosproject.yang.compiler.base.tool.ToolConstants.E_MISSING_INPUT;
-import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_DERIVED_DATA_TYPE;
-import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_IDENTITYREF;
-import static org.onosproject.yang.compiler.linker.impl.YangLinkerUtils.resolveGroupingInDefinationScope;
-import static org.onosproject.yang.compiler.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode;
-import static org.onosproject.yang.compiler.translator.tojava.JavaCodeGeneratorUtil.translatorErrorHandler;
-import static org.onosproject.yang.compiler.utils.UtilConstants.NEW_LINE;
-import static org.onosproject.yang.compiler.utils.UtilConstants.SLASH;
-import static org.onosproject.yang.compiler.utils.UtilConstants.TEMP;
-import static org.onosproject.yang.compiler.utils.UtilConstants.YANG_RESOURCES;
-import static org.onosproject.yang.compiler.utils.io.impl.YangIoUtils.createDirectories;
-import static org.slf4j.LoggerFactory.getLogger;
-
-/**
- * Represents ONOS YANG tool manager.
- */
-public class YangToolManager {
-
- public static final String DEFAULT_JAR_RES_PATH = SLASH + TEMP + SLASH +
- YANG_RESOURCES + SLASH;
- public static final String YANG_META_DATA = "YangMetaData";
- public static final String SERIALIZED_FILE_EXTENSION = ".ser";
- private static final Logger log = getLogger(YangToolManager.class);
- private final YangUtilsParser yangUtilsParser = new YangUtilsParserManager();
- private final YangLinker yangLinker = new YangLinkerManager();
- private final Set<YangNode> yangNodeSet = new HashSet<>();
- // YANG file information set.
- private Set<YangFileInfo> yangFileInfoSet; //initialize in tool invocation;
- private YangFileInfo curYangFileInfo = new YangFileInfo();
-
- /**
- * Provides a list of files from list of strings.
- *
- * @param yangFileInfo set of yang file information
- * @return list of files
- */
- private static List<File> getListOfFile(Set<YangFileInfo> yangFileInfo) {
- List<File> files = new ArrayList<>();
- Iterator<YangFileInfo> yangFileIterator = yangFileInfo.iterator();
- while (yangFileIterator.hasNext()) {
- YangFileInfo yangFile = yangFileIterator.next();
- if (yangFile.isForTranslator()) {
- files.add(new File(yangFile.getYangFileName()));
- }
- }
- return files;
- }
-
- /**
- * Creates a YANG file info set.
- *
- * @param yangFileList YANG files list
- * @return yang file info set
- */
- public Set<YangFileInfo> createYangFileInfoSet(List<String> yangFileList) {
- if (yangFileInfoSet == null) {
- yangFileInfoSet = new HashSet<>();
- }
- for (String yangFile : yangFileList) {
- YangFileInfo yangFileInfo = new YangFileInfo();
- yangFileInfo.setYangFileName(yangFile);
- yangFileInfoSet.add(yangFileInfo);
- }
- return yangFileInfoSet;
- }
-
- /**
- * Compile te YANG files and generate the corresponding Java files.
- * Update the generated bundle with the schema metadata.
- *
- * @param yangFiles Application YANG files
- * @param dependentSchema inter jar linked schema nodes
- * @param config tool configuration
- * @param plugin invoking plugin
- * @throws IOException when fails to do IO operations
- */
- public void compileYangFiles(Set<YangFileInfo> yangFiles,
- List<YangNode> dependentSchema,
- YangPluginConfig config,
- CallablePlugin plugin) throws IOException {
-
- synchronized (yangFiles) {
- try {
-
- if (config == null) {
- throw new YangToolException(E_MISSING_INPUT);
- }
- yangFileInfoSet = yangFiles;
-
- if (config.getCodeGenDir() == null) {
- throw new YangToolException(E_CODE_GEN_PATH);
- }
-
- // Check if there are any file to translate, if not return.
- if (yangFileInfoSet == null || yangFileInfoSet.isEmpty()) {
- // No files to translate
- return;
- }
-
- createDirectories(config.resourceGenDir());
-
- // Resolve inter jar dependency.
- addSchemaToFileSet(dependentSchema);
-
- // Carry out the parsing for all the YANG files.
- parseYangFileInfoSet();
-
- // Resolve dependencies using linker.
- resolveDependenciesUsingLinker();
-
- // Perform translation to JAVA.
- translateToJava(config);
-
- // Serialize data model.
- Set<YangNode> compiledSchemas = new HashSet<>();
- for (YangFileInfo fileInfo : yangFileInfoSet) {
- compiledSchemas.add(fileInfo.getRootNode());
- }
-
- String serFileName = config.resourceGenDir() + YANG_META_DATA + SERIALIZED_FILE_EXTENSION;
- FileOutputStream fileOutputStream = new FileOutputStream(serFileName);
- ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
- objectOutputStream.writeObject(compiledSchemas);
- objectOutputStream.close();
- fileOutputStream.close();
-
- //add YANG files to JAR
- List<File> files = getListOfFile(yangFileInfoSet);
- String path = config.resourceGenDir();
- File targetDir = new File(path);
- targetDir.mkdirs();
-
- for (File file : files) {
- Files.copy(file.toPath(),
- new File(path + file.getName()).toPath(),
- StandardCopyOption.REPLACE_EXISTING);
- }
-
- if (plugin != null) {
- plugin.addCompiledSchemaToBundle();
- plugin.addGeneratedCodeToBundle();
- plugin.addYangFilesToBundle();
- }
- } catch (IOException | ParserException e) {
- YangToolException exception =
- new YangToolException(e.getMessage(), e);
- exception.setCurYangFile(curYangFileInfo);
-
- if (curYangFileInfo != null &&
- curYangFileInfo.getRootNode() != null) {
- try {
- translatorErrorHandler(curYangFileInfo.getRootNode(),
- config);
- } catch (IOException ex) {
- e.printStackTrace();
- throw ex;
- }
- }
-
- throw exception;
- }
- }
- }
-
- /**
- * Resolved inter-jar dependencies.
- *
- * @param dependentSchema dependent schema list
- * @throws IOException when fails to do IO operations
- */
- private void addSchemaToFileSet(List<YangNode> dependentSchema)
- throws IOException {
- if (dependentSchema == null || dependentSchema.isEmpty()) {
- return;
- }
-
- for (YangNode node : dependentSchema) {
- YangFileInfo dependentFileInfo = new YangFileInfo();
- node.setToTranslate(false);
- dependentFileInfo.setRootNode(node);
- dependentFileInfo.setForTranslator(false);
- dependentFileInfo.setYangFileName(node.getName());
- yangFileInfoSet.add(dependentFileInfo);
- }
- }
-
- /**
- * Links all the provided schema in the YANG file info set.
- *
- * @throws YangToolException failed to link schema
- */
- public void resolveDependenciesUsingLinker() {
- createYangNodeSet();
- try {
- yangLinker.resolveDependencies(yangNodeSet);
- } catch (LinkerException e) {
- printLog(e.getFileName(), e.getLineNumber(), e.getCharPositionInLine(),
- e.getMessage(), e.getLocalizedMessage());
- throw new YangToolException(e.getMessage());
- }
- }
-
- /**
- * Creates YANG nodes set.
- */
- public void createYangNodeSet() {
- for (YangFileInfo yangFileInfo : yangFileInfoSet) {
- yangNodeSet.add(yangFileInfo.getRootNode());
- }
- }
-
- /**
- * Parses all the provided YANG files and generates YANG data model tree.
- *
- * @throws IOException a violation in IO
- */
- public void parseYangFileInfoSet()
- throws IOException {
- for (YangFileInfo yangFileInfo : yangFileInfoSet) {
- curYangFileInfo = yangFileInfo;
- if (yangFileInfo.isForTranslator()) {
- try {
- YangNode yangNode = yangUtilsParser.getDataModel(
- yangFileInfo.getYangFileName());
- yangFileInfo.setRootNode(yangNode);
- resolveGroupingInDefinationScope((YangReferenceResolver) yangNode);
- try {
- ((YangReferenceResolver) yangNode)
- .resolveSelfFileLinking(YANG_DERIVED_DATA_TYPE);
- ((YangReferenceResolver) yangNode)
- .resolveSelfFileLinking(YANG_IDENTITYREF);
- } catch (DataModelException e) {
- printLog(e.getFileName(), e.getLineNumber(), e
- .getCharPositionInLine(), e.getMessage(), e
- .getLocalizedMessage());
- }
- } catch (ParserException e) {
- printLog(e.getFileName(), e.getLineNumber(), e
- .getCharPositionInLine(), e.getMessage(), e
- .getLocalizedMessage());
- throw e;
- }
- }
- }
- }
-
- /**
- * Translates to java code corresponding to the YANG schema.
- *
- * @param pluginConfig YANG plugin config
- * @throws IOException when fails to generate java code file the current node
- */
- public void translateToJava(YangPluginConfig pluginConfig)
- throws IOException {
- List<YangNode> yangNodeSortedList = new LinkedList<>();
- yangNodeSortedList.addAll(yangNodeSet);
- sort(yangNodeSortedList);
- for (YangNode node : yangNodeSortedList) {
- if (node.isToTranslate() && !((YangDeviationHolder) node)
- .isModuleForDeviation()) {
- generateJavaCode(node, pluginConfig);
- }
- }
- }
-
- /**
- * Adds log info for exception.
- *
- * @param fileName file name
- * @param line line number
- * @param position character position
- * @param msg error message
- * @param localMsg local message
- */
- private void printLog(String fileName, int line, int position, String
- msg, String localMsg) {
- String logInfo = "Error in file: " + fileName;
- if (line != 0) {
- logInfo = logInfo + " at line: " + line + " at position: "
- + position;
- }
- if (msg != null) {
- logInfo = logInfo + NEW_LINE + localMsg;
- }
- log.info(logInfo);
- }
-}
diff --git a/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/base/tool/exception/YangToolException.java b/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/base/tool/exception/YangToolException.java
deleted file mode 100644
index 39bee83..0000000
--- a/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/base/tool/exception/YangToolException.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * 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.base.tool.exception;
-
-import org.onosproject.yang.compiler.base.tool.YangFileInfo;
-
-/**
- * Represents base class for exceptions in YANG tool operations.
- */
-public class YangToolException extends RuntimeException {
-
- private static final long serialVersionUID = 20161028L;
-
- private YangFileInfo curYangFile;
-
- /**
- * Creates a new YANG tool exception with given message.
- *
- * @param message the detail of exception in string
- */
- public YangToolException(String message) {
- super(message);
- }
-
- /**
- * Creates a new tool exception from given message and cause.
- *
- * @param message the detail of exception in string
- * @param cause underlying cause of the error
- */
- public YangToolException(final String message, final Throwable cause) {
- super(message, cause);
- }
-
- /**
- * Creates a new tool exception from cause.
- *
- * @param cause underlying cause of the error
- */
- public YangToolException(final Throwable cause) {
- super(cause);
- }
-
- /**
- * Retrieves the current YANG files for which exception has occured.
- *
- * @return current YANG file
- */
- public YangFileInfo getCurYangFile() {
- return curYangFile;
- }
-
-
- /**
- * Update the YANG file which caused the exception.
- *
- * @param curYangFile YANG files being processed
- */
- public void setCurYangFile(YangFileInfo curYangFile) {
- this.curYangFile = curYangFile;
- }
-}
diff --git a/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/base/tool/YangFileInfo.java b/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/tool/YangFileInfo.java
similarity index 97%
rename from compiler/base/tool/src/main/java/org/onosproject/yang/compiler/base/tool/YangFileInfo.java
rename to compiler/base/tool/src/main/java/org/onosproject/yang/compiler/tool/YangFileInfo.java
index 84b201e..df0fd9f 100644
--- a/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/base/tool/YangFileInfo.java
+++ b/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/tool/YangFileInfo.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.onosproject.yang.compiler.base.tool;
+package org.onosproject.yang.compiler.tool;
import org.onosproject.yang.compiler.datamodel.YangNode;
diff --git a/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/tool/impl/DefaultYangCompilationParam.java b/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/tool/impl/DefaultYangCompilationParam.java
new file mode 100644
index 0000000..0671700
--- /dev/null
+++ b/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/tool/impl/DefaultYangCompilationParam.java
@@ -0,0 +1,116 @@
+/*
+ * 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.compiler.tool.impl;
+
+import org.onosproject.yang.compiler.api.YangCompilationParam;
+
+import java.nio.file.Path;
+import java.util.LinkedHashSet;
+import java.util.Objects;
+import java.util.Set;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+
+/**
+ * Represents default YANG compilation parameter.
+ */
+public class DefaultYangCompilationParam implements YangCompilationParam {
+
+ private final Set<Path> yangFiles;
+ private final Set<Path> dependentSchemas;
+ private Path codeGenDir;
+ private Path metaDataPath;
+
+ /**
+ * Creates an instance of YANG compilation parameter.
+ */
+ public DefaultYangCompilationParam() {
+ yangFiles = new LinkedHashSet<>();
+ dependentSchemas = new LinkedHashSet<>();
+ }
+
+ @Override
+ public Set<Path> getYangFiles() {
+ return yangFiles;
+ }
+
+ @Override
+ public void addYangFile(Path path) {
+ yangFiles.add(path);
+ }
+
+ @Override
+ public Set<Path> getDependentSchemas() {
+ return dependentSchemas;
+ }
+
+ @Override
+ public void addDependentSchema(Path path) {
+ dependentSchemas.add(path);
+ }
+
+ @Override
+ public Path getCodeGenDir() {
+ return codeGenDir;
+ }
+
+ @Override
+ public void setCodeGenDir(Path path) {
+ codeGenDir = path;
+ }
+
+ @Override
+ public Path getMetadataGenDir() {
+ return metaDataPath;
+ }
+
+ @Override
+ public void setMetadataGenDir(Path path) {
+ metaDataPath = path;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(yangFiles, dependentSchemas, codeGenDir,
+ metaDataPath);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null) {
+ return false;
+ }
+
+ DefaultYangCompilationParam that = (DefaultYangCompilationParam) obj;
+ return yangFiles.size() == that.yangFiles.size() &&
+ dependentSchemas.size() == that.dependentSchemas.size() &&
+ yangFiles.containsAll(that.yangFiles) &&
+ dependentSchemas.containsAll(that.dependentSchemas) &&
+ Objects.equals(codeGenDir, that.codeGenDir) &&
+ Objects.equals(metaDataPath, that.metaDataPath);
+ }
+
+ @Override
+ public String toString() {
+ return toStringHelper(getClass())
+ .add("yangFilePath", yangFiles)
+ .add("dependentSchemas", dependentSchemas)
+ .add("codeGenDir", codeGenDir)
+ .add("metaDataPath", metaDataPath)
+ .toString();
+ }
+}
diff --git a/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/tool/impl/DefaultYangCompiledOutput.java b/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/tool/impl/DefaultYangCompiledOutput.java
new file mode 100644
index 0000000..8d8b597
--- /dev/null
+++ b/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/tool/impl/DefaultYangCompiledOutput.java
@@ -0,0 +1,84 @@
+/*
+ * 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.compiler.tool.impl;
+
+import org.onosproject.yang.YangModel;
+import org.onosproject.yang.compiler.api.YangCompiledOutput;
+
+import java.nio.file.Path;
+import java.util.Objects;
+import java.util.Set;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Represents default YANG compiled output implementation.
+ */
+public class DefaultYangCompiledOutput implements YangCompiledOutput {
+
+ private final YangModel model;
+ private final Set<Path> generatedJava;
+
+ /**
+ * Creates an instance of YANG compiled output.
+ *
+ * @param model YANG model
+ * @param generatedJava generated java paths
+ */
+ public DefaultYangCompiledOutput(YangModel model, Set<Path> generatedJava) {
+ checkNotNull(model);
+ checkNotNull(generatedJava);
+ this.model = model;
+ this.generatedJava = generatedJava;
+ }
+
+ @Override
+ public YangModel getYangModel() {
+ return model;
+ }
+
+ @Override
+ public Set<Path> getGeneratedJava() {
+ return generatedJava;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(model, generatedJava);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null) {
+ return false;
+ }
+
+ DefaultYangCompiledOutput that = (DefaultYangCompiledOutput) obj;
+ return generatedJava.size() == that.generatedJava.size() &&
+ generatedJava.containsAll(that.generatedJava) &&
+ Objects.equals(model, that.model);
+ }
+
+ @Override
+ public String toString() {
+ return toStringHelper(getClass())
+ .add("yangModel", model)
+ .add("generatedJava", generatedJava)
+ .toString();
+ }
+}
diff --git a/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/tool/impl/YangCompilerManager.java b/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/tool/impl/YangCompilerManager.java
new file mode 100644
index 0000000..4a77a09
--- /dev/null
+++ b/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/tool/impl/YangCompilerManager.java
@@ -0,0 +1,463 @@
+/*
+ * 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.compiler.tool.impl;
+
+import org.onosproject.yang.DefaultYangModel;
+import org.onosproject.yang.DefaultYangModule;
+import org.onosproject.yang.DefaultYangModuleId;
+import org.onosproject.yang.YangModel;
+import org.onosproject.yang.YangModuleId;
+import org.onosproject.yang.compiler.api.YangCompilationParam;
+import org.onosproject.yang.compiler.api.YangCompiledOutput;
+import org.onosproject.yang.compiler.api.YangCompilerException;
+import org.onosproject.yang.compiler.api.YangCompilerService;
+import org.onosproject.yang.compiler.datamodel.YangDeviationHolder;
+import org.onosproject.yang.compiler.datamodel.YangNode;
+import org.onosproject.yang.compiler.datamodel.YangReferenceResolver;
+import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
+import org.onosproject.yang.compiler.linker.YangLinker;
+import org.onosproject.yang.compiler.linker.exceptions.LinkerException;
+import org.onosproject.yang.compiler.linker.impl.YangLinkerManager;
+import org.onosproject.yang.compiler.parser.YangUtilsParser;
+import org.onosproject.yang.compiler.parser.exceptions.ParserException;
+import org.onosproject.yang.compiler.parser.impl.YangUtilsParserManager;
+import org.onosproject.yang.compiler.tool.YangFileInfo;
+import org.onosproject.yang.compiler.utils.io.YangPluginConfig;
+import org.slf4j.Logger;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+
+import static java.nio.file.Files.copy;
+import static java.nio.file.Paths.get;
+import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
+import static java.util.Collections.sort;
+import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_DERIVED_DATA_TYPE;
+import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_IDENTITYREF;
+import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.deSerializeDataModel;
+import static org.onosproject.yang.compiler.linker.impl.YangLinkerUtils.resolveGroupingInDefinationScope;
+import static org.onosproject.yang.compiler.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode;
+import static org.onosproject.yang.compiler.translator.tojava.JavaCodeGeneratorUtil.translatorErrorHandler;
+import static org.onosproject.yang.compiler.utils.UtilConstants.NEW_LINE;
+import static org.onosproject.yang.compiler.utils.UtilConstants.SLASH;
+import static org.onosproject.yang.compiler.utils.UtilConstants.YANG_META_DATA;
+import static org.onosproject.yang.compiler.utils.io.impl.YangFileScanner.getJavaFiles;
+import static org.onosproject.yang.compiler.utils.io.impl.YangIoUtils.createDirectories;
+import static org.slf4j.LoggerFactory.getLogger;
+
+/**
+ * Represents implementation of YANG compiler manager.
+ */
+public class YangCompilerManager implements YangCompilerService {
+
+ private static final Logger log = getLogger(YangCompilerManager.class);
+ private final YangUtilsParser yangUtilsParser = new YangUtilsParserManager();
+ private final YangLinker yangLinker = new YangLinkerManager();
+ private final Set<YangNode> yangNodeSet = new HashSet<>();
+
+ // YANG file information set.
+ private Set<YangFileInfo> yangFileInfoSet; //initialize in tool invocation;
+ private YangFileInfo curYangFileInfo = new YangFileInfo();
+ private Set<Path> genJavaPath = new LinkedHashSet<>();
+
+ @Override
+ public YangCompiledOutput compileYangFiles(YangCompilationParam param)
+ throws IOException, YangCompilerException {
+
+ YangPluginConfig config = new YangPluginConfig();
+ config.setCodeGenDir(param.getCodeGenDir().toString() + SLASH);
+ config.resourceGenDir(param.getMetadataGenDir().toString() +
+ SLASH);
+
+ processYangFiles(createYangFileInfoSet(param.getYangFiles()),
+ dependentSchema(param.getDependentSchemas()), config);
+
+ return new DefaultYangCompiledOutput(
+ processYangModel(config.resourceGenDir()), genJavaPath);
+ }
+
+ /**
+ * Returns YANG model for application.
+ *
+ * @param path path for metadata file
+ * @return YANG model
+ */
+ private YangModel processYangModel(String path) {
+ DefaultYangModel model = new DefaultYangModel();
+ YangModuleId id;
+ for (YangNode node : yangNodeSet) {
+ id = processModuleId(node);
+ org.onosproject.yang.YangModule module =
+ new DefaultYangModule(id, get(node.getFileName()), get(path));
+ model.addModule(id, module);
+ }
+ return model;
+ }
+
+ /**
+ * Returns YANG module id for a given YANG module node.
+ *
+ * @param module YANG module
+ * @return YANG module id for a given YANG module node
+ */
+ private YangModuleId processModuleId(YangNode module) {
+ return new DefaultYangModuleId(module.getName(), module.getRevision()
+ .getRevDate().toString());
+ }
+
+ /**
+ * Returns YANG node set.
+ *
+ * @return YANG node set
+ */
+ public Set<YangNode> getYangNodeSet() {
+ return yangNodeSet;
+ }
+
+ /**
+ * Provides a list of files from list of strings.
+ *
+ * @param yangFileInfo set of yang file information
+ * @return list of files
+ */
+ private static List<File> getListOfFile(Set<YangFileInfo> yangFileInfo) {
+ List<File> files = new ArrayList<>();
+ for (YangFileInfo yangFile : yangFileInfo) {
+ if (yangFile.isForTranslator()) {
+ files.add(new File(yangFile.getYangFileName()));
+ }
+ }
+ return files;
+ }
+
+ /**
+ * Creates a YANG file info set.
+ *
+ * @param yangFileList YANG files list
+ * @return yang file info set
+ */
+ public Set<YangFileInfo> createYangFileInfoSet(Set<Path> yangFileList) {
+ if (yangFileInfoSet == null) {
+ yangFileInfoSet = new HashSet<>();
+ }
+ for (Path yangFile : yangFileList) {
+ YangFileInfo yangFileInfo = new YangFileInfo();
+ yangFileInfo.setYangFileName(yangFile.toString());
+ yangFileInfoSet.add(yangFileInfo);
+ }
+ return yangFileInfoSet;
+ }
+
+ /**
+ * Compile te YANG files and generate the corresponding Java files.
+ * Update the generated bundle with the schema metadata.
+ *
+ * @param yangFiles Application YANG files
+ * @param dependentSchema inter jar linked schema nodes
+ * @param config tool configurations
+ * @throws IOException when fails to do IO operations
+ */
+ private void processYangFiles(Set<YangFileInfo> yangFiles,
+ Set<YangNode> dependentSchema,
+ YangPluginConfig config) throws IOException {
+
+ synchronized (YangCompilerManager.class) {
+ try {
+
+ yangFileInfoSet = yangFiles;
+
+ // Check if there are any file to translate, if not return.
+ if (yangFileInfoSet.isEmpty()) {
+ // No files to translate
+ return;
+ }
+
+ //Create resource directory.
+ createDirectories(config.resourceGenDir());
+
+ // Resolve inter jar dependency.
+ addSchemaToFileSet(dependentSchema);
+
+ // Carry out the parsing for all the YANG files.
+ parseYangFileInfoSet();
+
+ // Resolve dependencies using linker.
+ resolveDependenciesUsingLinker();
+
+ // Perform translation to JAVA.
+ translateToJava(config);
+
+ //add to generated java code map
+ processGeneratedCode(config.getCodeGenDir());
+
+ // Serialize data model.
+ processSerialization(config.resourceGenDir());
+
+ //add YANG files to JAR
+ processCopyYangFile(config.resourceGenDir());
+ } catch (IOException | ParserException e) {
+ //TODO: provide unified framework for exceptions
+ YangCompilerException exception =
+ new YangCompilerException(e.getMessage(), e);
+ exception.setYangFile(get(
+ curYangFileInfo.getYangFileName()));
+
+ if (curYangFileInfo != null &&
+ curYangFileInfo.getRootNode() != null) {
+ try {
+ translatorErrorHandler(curYangFileInfo.getRootNode(),
+ config);
+ } catch (IOException ex) {
+ e.printStackTrace();
+ throw ex;
+ }
+ }
+ throw exception;
+ }
+ }
+ }
+
+ /**
+ * Adds all generated java class paths to YANG model.
+ *
+ * @param codeGenDir code gen directory.
+ * @throws IOException when fails to do IO operations
+ */
+ private void processGeneratedCode(String codeGenDir) throws IOException {
+ List<String> files = getJavaFiles(codeGenDir);
+ for (String file : files) {
+ genJavaPath.add(Paths.get(file));
+ }
+ }
+
+ /**
+ * Returns dependent schema nodes.
+ *
+ * @param dependentSchemaPath dependent schema paths
+ * @return dependent schema nodes
+ */
+ private Set<YangNode> dependentSchema(Set<Path> dependentSchemaPath) {
+ Set<YangNode> depNodes = new LinkedHashSet<>();
+ for (Path path : dependentSchemaPath) {
+ try {
+ depNodes.addAll(deSerializeDataModel(path.toString()));
+ } catch (IOException e) {
+ throw new YangCompilerException(
+ "Failed to fetch dependent schema from given " +
+ "path :" + path.toString());
+ }
+ }
+ return depNodes;
+ }
+
+ /**
+ * Resolved inter-jar dependencies.
+ *
+ * @param dependentSchema dependent schema list
+ * @throws IOException when fails to do IO operations
+ */
+ private void addSchemaToFileSet(Set<YangNode> dependentSchema)
+ throws IOException {
+ if (dependentSchema == null || dependentSchema.isEmpty()) {
+ return;
+ }
+
+ for (YangNode node : dependentSchema) {
+ YangFileInfo dependentFileInfo = new YangFileInfo();
+ node.setToTranslate(false);
+ dependentFileInfo.setRootNode(node);
+ dependentFileInfo.setForTranslator(false);
+ dependentFileInfo.setYangFileName(node.getName());
+ yangFileInfoSet.add(dependentFileInfo);
+ }
+ }
+
+ /**
+ * Links all the provided schema in the YANG file info set.
+ *
+ * @throws YangCompilerException failed to link schema
+ */
+ public void resolveDependenciesUsingLinker() {
+ createYangNodeSet();
+ try {
+ yangLinker.resolveDependencies(yangNodeSet);
+ } catch (LinkerException e) {
+ printLog(e.getFileName(), e.getLineNumber(), e.getCharPositionInLine(),
+ e.getMessage(), e.getLocalizedMessage());
+ throw new YangCompilerException(e.getMessage());
+ }
+ }
+
+ /**
+ * Creates YANG nodes set.
+ */
+ public void createYangNodeSet() {
+ for (YangFileInfo yangFileInfo : yangFileInfoSet) {
+ yangNodeSet.add(yangFileInfo.getRootNode());
+ }
+ }
+
+ /**
+ * Parses all the provided YANG files and generates YANG data model tree.
+ *
+ * @throws IOException a violation in IO
+ */
+ public void parseYangFileInfoSet()
+ throws IOException {
+ for (YangFileInfo yangFileInfo : yangFileInfoSet) {
+ curYangFileInfo = yangFileInfo;
+ if (yangFileInfo.isForTranslator()) {
+ try {
+ YangNode yangNode = yangUtilsParser.getDataModel(
+ yangFileInfo.getYangFileName());
+ yangFileInfo.setRootNode(yangNode);
+ resolveGroupingInDefinationScope((YangReferenceResolver) yangNode);
+ try {
+ ((YangReferenceResolver) yangNode)
+ .resolveSelfFileLinking(YANG_DERIVED_DATA_TYPE);
+ ((YangReferenceResolver) yangNode)
+ .resolveSelfFileLinking(YANG_IDENTITYREF);
+ } catch (DataModelException e) {
+ printLog(e.getFileName(), e.getLineNumber(), e
+ .getCharPositionInLine(), e.getMessage(), e
+ .getLocalizedMessage());
+ }
+ } catch (ParserException e) {
+ printLog(e.getFileName(), e.getLineNumber(), e
+ .getCharPositionInLine(), e.getMessage(), e
+ .getLocalizedMessage());
+ throw e;
+ }
+ }
+ }
+ }
+
+ /**
+ * Translates to java code corresponding to the YANG schema.
+ *
+ * @param pluginConfig YANG plugin config
+ * @throws IOException when fails to generate java code file the current node
+ */
+ public void translateToJava(YangPluginConfig pluginConfig)
+ throws IOException {
+ List<YangNode> yangNodeSortedList = new LinkedList<>();
+ yangNodeSortedList.addAll(yangNodeSet);
+ sort(yangNodeSortedList);
+ for (YangNode node : yangNodeSortedList) {
+ if (node.isToTranslate() && !((YangDeviationHolder) node)
+ .isModuleForDeviation()) {
+ generateJavaCode(node, pluginConfig);
+ }
+ }
+ }
+
+ /**
+ * Adds log info for exception.
+ *
+ * @param fileName file name
+ * @param line line number
+ * @param position character position
+ * @param msg error message
+ * @param localMsg local message
+ */
+ private void printLog(String fileName, int line, int position, String
+ msg, String localMsg) {
+ String logInfo = "Error in file: " + fileName;
+ if (line != 0) {
+ logInfo = logInfo + " at line: " + line + " at position: "
+ + position;
+ }
+ if (msg != null) {
+ logInfo = logInfo + NEW_LINE + localMsg;
+ }
+ log.info(logInfo);
+ }
+
+ /**
+ * Process serialization of datamodel.
+ *
+ * @param path path of resource directory
+ * @throws IOException when fails to IO operations
+ */
+ private void processSerialization(String path) throws IOException {
+ Set<YangNode> compiledSchemas = new HashSet<>();
+ for (YangFileInfo fileInfo : yangFileInfoSet) {
+ compiledSchemas.add(fileInfo.getRootNode());
+ }
+
+ String serFileName = path + YANG_META_DATA;
+ FileOutputStream fileOutputStream = new FileOutputStream(serFileName);
+ ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
+ objectOutputStream.writeObject(compiledSchemas);
+ objectOutputStream.close();
+ fileOutputStream.close();
+ }
+
+ /**
+ * Copies yang files to resource directory.
+ *
+ * @param path yang file paths
+ * @throws IOException when fails to do IO operations
+ */
+ private void processCopyYangFile(String path) throws IOException {
+
+ //add YANG files to JAR
+ List<File> files = getListOfFile(yangFileInfoSet);
+ File targetDir = new File(path);
+ if (!targetDir.exists()) {
+ boolean isCreated = targetDir.mkdirs();
+ if (!isCreated) {
+ throw new YangCompilerException(
+ "failed to create yang resource directory.");
+ }
+ }
+
+ for (File file : files) {
+ copy(file.toPath(),
+ new File(path + file.getName()).toPath(),
+ REPLACE_EXISTING);
+ }
+ }
+
+ /**
+ * Returns yang file info set.
+ *
+ * @return yang file info set
+ */
+ public Set<YangFileInfo> getYangFileInfoSet() {
+ return yangFileInfoSet;
+ }
+
+ /**
+ * Sets yang file info set.
+ *
+ * @param yangFileInfoSet yang file info set
+ */
+ public void setYangFileInfoSet(Set<YangFileInfo> yangFileInfoSet) {
+ this.yangFileInfoSet = yangFileInfoSet;
+ }
+}
diff --git a/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/base/tool/ToolConstants.java b/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/tool/impl/package-info.java
similarity index 60%
rename from compiler/base/tool/src/main/java/org/onosproject/yang/compiler/base/tool/ToolConstants.java
rename to compiler/base/tool/src/main/java/org/onosproject/yang/compiler/tool/impl/package-info.java
index b5640b6..166e7e6 100644
--- a/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/base/tool/ToolConstants.java
+++ b/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/tool/impl/package-info.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016-present Open Networking Laboratory
+ * 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.
@@ -14,16 +14,7 @@
* limitations under the License.
*/
-package org.onosproject.yang.compiler.base.tool;
-
/**
- * Represents common constant utility for YANG tool.
+ * Compiler api implementation.
*/
-final class ToolConstants {
- private ToolConstants() {
-
- }
-
- static final String E_MISSING_INPUT = "Missing extected input ";
- static final String E_CODE_GEN_PATH = "Missing plugin code gen directory";
-}
+package org.onosproject.yang.compiler.tool.impl;
\ No newline at end of file
diff --git a/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/base/tool/ToolConstants.java b/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/tool/package-info.java
similarity index 60%
copy from compiler/base/tool/src/main/java/org/onosproject/yang/compiler/base/tool/ToolConstants.java
copy to compiler/base/tool/src/main/java/org/onosproject/yang/compiler/tool/package-info.java
index b5640b6..3627174 100644
--- a/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/base/tool/ToolConstants.java
+++ b/compiler/base/tool/src/main/java/org/onosproject/yang/compiler/tool/package-info.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016-present Open Networking Laboratory
+ * 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.
@@ -14,16 +14,7 @@
* limitations under the License.
*/
-package org.onosproject.yang.compiler.base.tool;
-
/**
- * Represents common constant utility for YANG tool.
+ * Compiler tool information.
*/
-final class ToolConstants {
- private ToolConstants() {
-
- }
-
- static final String E_MISSING_INPUT = "Missing extected input ";
- static final String E_CODE_GEN_PATH = "Missing plugin code gen directory";
-}
+package org.onosproject.yang.compiler.tool;
\ No newline at end of file
diff --git a/compiler/base/utils/src/main/java/org/onosproject/yang/compiler/utils/UtilConstants.java b/compiler/base/utils/src/main/java/org/onosproject/yang/compiler/utils/UtilConstants.java
index 22a8f98..8f5131b 100644
--- a/compiler/base/utils/src/main/java/org/onosproject/yang/compiler/utils/UtilConstants.java
+++ b/compiler/base/utils/src/main/java/org/onosproject/yang/compiler/utils/UtilConstants.java
@@ -1855,6 +1855,17 @@
*/
public static final String CAMEL_CLASS = "Class";
+ /*
+ * Default meta data path.
+ */
+ public static final String DEFAULT_JAR_RES_PATH = SLASH + TEMP + SLASH +
+ YANG_RESOURCES + SLASH;
+
+ /**
+ * Meta data file name.
+ */
+ public static final String YANG_META_DATA = "YangMetaData.ser";
+
// No instantiation.
private UtilConstants() {
}
diff --git a/compiler/plugin/buck/src/main/java/org/onosproject/yang/compiler/plugin/buck/YangGenerator.java b/compiler/plugin/buck/src/main/java/org/onosproject/yang/compiler/plugin/buck/YangGenerator.java
index ea69169..8a75131 100644
--- a/compiler/plugin/buck/src/main/java/org/onosproject/yang/compiler/plugin/buck/YangGenerator.java
+++ b/compiler/plugin/buck/src/main/java/org/onosproject/yang/compiler/plugin/buck/YangGenerator.java
@@ -16,82 +16,93 @@
package org.onosproject.yang.compiler.plugin.buck;
-import org.onosproject.yang.compiler.datamodel.YangNode;
-import org.onosproject.yang.compiler.datamodel.utils.DataModelUtils;
-import org.onosproject.yang.compiler.utils.io.YangPluginConfig;
-import org.onosproject.yang.compiler.base.tool.CallablePlugin;
-import org.onosproject.yang.compiler.base.tool.YangToolManager;
+import org.onosproject.yang.compiler.api.YangCompilationParam;
+import org.onosproject.yang.compiler.api.YangCompiledOutput;
+import org.onosproject.yang.compiler.api.YangCompilerException;
+import org.onosproject.yang.compiler.api.YangCompilerService;
+import org.onosproject.yang.compiler.tool.impl.DefaultYangCompilationParam;
+import org.onosproject.yang.compiler.tool.impl.YangCompilerManager;
import java.io.File;
import java.io.IOException;
-import java.util.ArrayList;
+import java.nio.file.Paths;
import java.util.List;
-import static java.util.stream.Collectors.toList;
+import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.parseDepSchemaPath;
import static org.onosproject.yang.compiler.utils.UtilConstants.SLASH;
import static org.onosproject.yang.compiler.utils.UtilConstants.YANG_RESOURCES;
/**
* Generates Java sources from a Yang model.
*/
-public class YangGenerator implements CallablePlugin {
+public class YangGenerator {
private final List<File> models;
private final List<String> depJar;
- private final String DEFAULT_JAR_RES_PATH = SLASH + YANG_RESOURCES + SLASH;
private String outputDirectory;
+ private YangCompiledOutput output;
+ /**
+ * Creates an instance of YANG generator.
+ *
+ * @param models YANG models
+ * @param outputDirectory output directory
+ * @param depJar dependent jar paths
+ */
YangGenerator(List<File> models, String outputDirectory, List<String> depJar) {
this.models = models;
this.depJar = depJar;
this.outputDirectory = outputDirectory + SLASH;
}
+ /**
+ * Executes YANG library code generation step.
+ *
+ * @throws YangParsingException when fails to parse yang files
+ */
public void execute() throws YangParsingException {
- List<String> files = getListOfFile();
- synchronized (files) {
- try {
- YangPluginConfig config = new YangPluginConfig();
- config.setCodeGenDir(outputDirectory);
- config.resourceGenDir(outputDirectory + DEFAULT_JAR_RES_PATH);
- //for inter-jar linking.
- List<YangNode> dependentSchema = new ArrayList<>();
- for (String jar : depJar) {
- dependentSchema.addAll(DataModelUtils.parseJarFile(jar, outputDirectory));
+ synchronized (YangGenerator.class) {
+ //Yang compiler service.
+ YangCompilerService compiler = new YangCompilerManager();
+
+ //Create compiler param.
+ YangCompilationParam param = new DefaultYangCompilationParam();
+
+ //Need to get dependent schema paths to give inter jar dependencies.
+ for (String jar : depJar) {
+ try {
+ File path = parseDepSchemaPath(jar, outputDirectory);
+ if (path != null) {
+ param.addDependentSchema(Paths.get(path.getAbsolutePath()));
+ }
+ } catch (IOException e) {
+ throw new YangCompilerException(
+ "Failed to parse dependent schema path");
}
- //intra jar file linking.
- YangToolManager manager = new YangToolManager();
- manager.compileYangFiles(manager.createYangFileInfoSet(files),
- dependentSchema, config, this);
- } catch (Exception e) {
+ }
+ param.setCodeGenDir(Paths.get(outputDirectory));
+ param.setMetadataGenDir(Paths.get(outputDirectory + SLASH +
+ YANG_RESOURCES + SLASH));
+
+ for (File file : models) {
+ param.addYangFile(Paths.get(file.getAbsolutePath()));
+ }
+
+ //Compile yang files and generate java code.
+ try {
+ output = compiler.compileYangFiles(param);
+ } catch (IOException e) {
throw new YangParsingException(e);
}
}
}
- private List<String> getListOfFile() {
- List<String> files = new ArrayList<>();
- if (models != null) {
- synchronized (models) {
- files.addAll(models.stream().map(File::toString)
- .collect(toList()));
- }
- }
- return files;
- }
-
- @Override
- public void addGeneratedCodeToBundle() {
- //TODO: add functionality.
- }
-
- @Override
- public void addCompiledSchemaToBundle() throws IOException {
- //TODO: add functionality.
- }
-
- @Override
- public void addYangFilesToBundle() throws IOException {
- //TODO: add functionality.
+ /**
+ * Returns YANG compiled output.
+ *
+ * @return YANG compiled output
+ */
+ public YangCompiledOutput output() {
+ return output;
}
}
diff --git a/compiler/plugin/maven/src/main/java/org/onosproject/yang/compiler/plugin/maven/YangPluginUtils.java b/compiler/plugin/maven/src/main/java/org/onosproject/yang/compiler/plugin/maven/YangPluginUtils.java
index 1a43f6c..5a7a674 100644
--- a/compiler/plugin/maven/src/main/java/org/onosproject/yang/compiler/plugin/maven/YangPluginUtils.java
+++ b/compiler/plugin/maven/src/main/java/org/onosproject/yang/compiler/plugin/maven/YangPluginUtils.java
@@ -20,29 +20,28 @@
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Resource;
import org.apache.maven.project.MavenProject;
-import org.onosproject.yang.compiler.base.tool.YangToolManager;
-import org.onosproject.yang.compiler.datamodel.YangNode;
-import org.onosproject.yang.compiler.datamodel.utils.DataModelUtils;
-import org.onosproject.yang.compiler.utils.io.impl.YangIoUtils;
import org.slf4j.Logger;
import org.sonatype.plexus.build.incremental.BuildContext;
import java.io.File;
import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
+import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.parseDepSchemaPath;
import static org.onosproject.yang.compiler.utils.UtilConstants.HYPHEN;
import static org.onosproject.yang.compiler.utils.UtilConstants.JAR;
import static org.onosproject.yang.compiler.utils.UtilConstants.PERIOD;
import static org.onosproject.yang.compiler.utils.UtilConstants.SLASH;
-import static org.onosproject.yang.compiler.utils.UtilConstants.TEMP;
+import static org.onosproject.yang.compiler.utils.io.impl.YangIoUtils.getPackageDirPathFromJavaJPackage;
import static org.slf4j.LoggerFactory.getLogger;
/**
* Represents YANG plugin utilities.
*/
-public final class YangPluginUtils {
+final class YangPluginUtils {
private static final Logger log = getLogger(YangPluginUtils.class);
@@ -63,40 +62,6 @@
}
/**
- * Copies YANG files to the current project's output directory.
- *
- * @param outputDir project's output directory
- * @param project maven project
- * @throws IOException when fails to copy files to destination resource directory
- */
- static void copyYangFilesToTarget(String outputDir, MavenProject project)
- throws IOException {
- addToProjectResource(outputDir + SLASH + TEMP + SLASH, project);
- }
-
- /**
- * Serializes data-model.
- *
- * @param directory base directory for serialized files
- * @param project maven project
- * @param operation true if need to add to resource
- * @throws IOException when fails to do IO operations
- */
- public static void serializeDataModel(String directory,
- MavenProject project,
- boolean operation)
- throws IOException {
-
- String serFileDirPath = directory + YangToolManager.DEFAULT_JAR_RES_PATH;
- File dir = new File(serFileDirPath);
- dir.mkdirs();
-
- if (operation) {
- addToProjectResource(directory + SLASH + TEMP + SLASH, project);
- }
- }
-
- /**
* Returns list of jar path.
*
* @param project maven project
@@ -104,8 +69,9 @@
* @param remoteRepos remote repository
* @return list of jar paths
*/
- private static List<String> resolveDependencyJarPath(MavenProject project, ArtifactRepository localRepository,
- List<ArtifactRepository> remoteRepos) {
+ private static List<String> resolveDependencyJarPath(
+ MavenProject project, ArtifactRepository localRepository,
+ List<ArtifactRepository> remoteRepos) {
StringBuilder path = new StringBuilder();
List<String> jarPaths = new ArrayList<>();
@@ -114,7 +80,7 @@
Dependency dependency = (Dependency) obj;
path.append(localRepository.getBasedir());
path.append(SLASH);
- path.append(YangIoUtils.getPackageDirPathFromJavaJPackage(dependency.getGroupId()));
+ path.append(getPackageDirPathFromJavaJPackage(dependency.getGroupId()));
path.append(SLASH);
path.append(dependency.getArtifactId());
path.append(SLASH);
@@ -141,23 +107,29 @@
* @param localRepository local maven repository
* @param remoteRepos list of remote repository
* @param directory directory for serialized files
- * @return list of resolved datamodel nodes
+ * @return list of resolved serialized file paths
* @throws IOException when fails to do IO operations
*/
- static List<YangNode> resolveInterJarDependencies(MavenProject project, ArtifactRepository localRepository,
- List<ArtifactRepository> remoteRepos, String directory)
+ static List<Path> resolveInterJarDependencies(MavenProject project,
+ ArtifactRepository localRepository,
+ List<ArtifactRepository> remoteRepos,
+ String directory)
throws IOException {
- List<String> dependenciesJarPaths = resolveDependencyJarPath(project, localRepository, remoteRepos);
- List<YangNode> resolvedDataModelNodes = new ArrayList<>();
- for (String dependency : dependenciesJarPaths) {
- resolvedDataModelNodes.addAll(DataModelUtils.parseJarFile(dependency, directory));
+ List<String> depJars = resolveDependencyJarPath(
+ project, localRepository, remoteRepos);
+ List<Path> serFilePaths = new ArrayList<>();
+ for (String dependency : depJars) {
+ File path = parseDepSchemaPath(dependency, directory);
+ if (path != null) {
+ serFilePaths.add(Paths.get(path.getAbsolutePath()));
+ }
}
- return resolvedDataModelNodes;
+ return serFilePaths;
}
/* Adds directory to resources of project */
- private static void addToProjectResource(String dir, MavenProject project) {
+ static void addToProjectResource(String dir, MavenProject project) {
Resource rsc = new Resource();
rsc.setDirectory(dir);
project.addResource(rsc);
diff --git a/compiler/plugin/maven/src/main/java/org/onosproject/yang/compiler/plugin/maven/YangUtilManager.java b/compiler/plugin/maven/src/main/java/org/onosproject/yang/compiler/plugin/maven/YangUtilManager.java
index 903c705..facb2c7 100644
--- a/compiler/plugin/maven/src/main/java/org/onosproject/yang/compiler/plugin/maven/YangUtilManager.java
+++ b/compiler/plugin/maven/src/main/java/org/onosproject/yang/compiler/plugin/maven/YangUtilManager.java
@@ -25,44 +25,28 @@
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.apache.maven.rtinfo.RuntimeInformation;
-import org.onosproject.yang.compiler.datamodel.YangDeviationHolder;
-import org.onosproject.yang.compiler.parser.YangUtilsParser;
-import org.onosproject.yang.compiler.parser.exceptions.ParserException;
-import org.onosproject.yang.compiler.parser.impl.YangUtilsParserManager;
-import org.onosproject.yang.compiler.base.tool.CallablePlugin;
-import org.onosproject.yang.compiler.base.tool.YangFileInfo;
-import org.onosproject.yang.compiler.base.tool.YangToolManager;
-import org.onosproject.yang.compiler.base.tool.exception.YangToolException;
-import org.onosproject.yang.compiler.datamodel.ResolvableType;
-import org.onosproject.yang.compiler.datamodel.YangNode;
-import org.onosproject.yang.compiler.datamodel.YangReferenceResolver;
-import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
-import org.onosproject.yang.compiler.linker.YangLinker;
-import org.onosproject.yang.compiler.linker.exceptions.LinkerException;
-import org.onosproject.yang.compiler.linker.impl.YangLinkerManager;
-import org.onosproject.yang.compiler.translator.tojava.JavaCodeGeneratorUtil;
-import org.onosproject.yang.compiler.utils.io.YangPluginConfig;
-import org.onosproject.yang.compiler.utils.io.YangToJavaNamingConflictUtil;
+import org.onosproject.yang.compiler.api.YangCompilationParam;
+import org.onosproject.yang.compiler.api.YangCompiledOutput;
+import org.onosproject.yang.compiler.api.YangCompilerException;
+import org.onosproject.yang.compiler.api.YangCompilerService;
+import org.onosproject.yang.compiler.tool.impl.DefaultYangCompilationParam;
+import org.onosproject.yang.compiler.tool.impl.YangCompilerManager;
import org.sonatype.plexus.build.incremental.BuildContext;
import java.io.IOException;
-import java.util.HashSet;
-import java.util.LinkedList;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.util.List;
-import java.util.Set;
-import static java.util.Collections.sort;
import static org.apache.maven.plugins.annotations.LifecyclePhase.PROCESS_SOURCES;
import static org.apache.maven.plugins.annotations.ResolutionScope.COMPILE;
-import static org.onosproject.yang.compiler.linker.impl.YangLinkerUtils.resolveGroupingInDefinationScope;
import static org.onosproject.yang.compiler.plugin.maven.YangPluginUtils.addToCompilationRoot;
-import static org.onosproject.yang.compiler.plugin.maven.YangPluginUtils.copyYangFilesToTarget;
+import static org.onosproject.yang.compiler.plugin.maven.YangPluginUtils.addToProjectResource;
import static org.onosproject.yang.compiler.plugin.maven.YangPluginUtils.resolveInterJarDependencies;
-import static org.onosproject.yang.compiler.plugin.maven.YangPluginUtils.serializeDataModel;
import static org.onosproject.yang.compiler.utils.UtilConstants.DEFAULT_BASE_PKG;
+import static org.onosproject.yang.compiler.utils.UtilConstants.DEFAULT_JAR_RES_PATH;
import static org.onosproject.yang.compiler.utils.UtilConstants.EMPTY_STRING;
import static org.onosproject.yang.compiler.utils.UtilConstants.IN;
-import static org.onosproject.yang.compiler.utils.UtilConstants.NEW_LINE;
import static org.onosproject.yang.compiler.utils.UtilConstants.SLASH;
import static org.onosproject.yang.compiler.utils.UtilConstants.TEMP;
import static org.onosproject.yang.compiler.utils.UtilConstants.VERSION_ERROR;
@@ -81,29 +65,23 @@
*/
@Mojo(name = "yang2java", defaultPhase = PROCESS_SOURCES,
requiresDependencyResolution = COMPILE)
-public class YangUtilManager extends AbstractMojo implements CallablePlugin {
+public class YangUtilManager extends AbstractMojo {
- private static final String DEFAULT_PKG =
- getPackageDirPathFromJavaJPackage(DEFAULT_BASE_PKG);
private static final int SUPPORTED_VERSION = 339;
- private final YangPluginConfig yangPlugin = new YangPluginConfig();
- private final YangUtilsParser yangUtilsParser = new YangUtilsParserManager();
- private final YangLinker yangLinker = new YangLinkerManager();
- private final Set<YangNode> yangNodeSet = new HashSet<>();
- private YangNode rootNode;
- // YANG file information set.
- private Set<YangFileInfo> yangFileInfoSet = new HashSet<>();
- private YangFileInfo curYangFileInfo = new YangFileInfo();
+ private String codeGenDir;
+ private YangCompiledOutput output;
+
/**
* Source directory for YANG files.
*/
- @Parameter(property = "yangFilesDir", defaultValue = "src/main/yang")
+ @Parameter(property = "yangFilesDir", defaultValue = "src/main/yang/")
private String yangFilesDir;
/**
* Source directory for generated files.
*/
- @Parameter(property = "classFileDir", defaultValue = "target/generated-sources")
+ @Parameter(property = "classFileDir", defaultValue =
+ "target/generated-sources/")
private String classFileDir;
/**
@@ -127,36 +105,6 @@
private MavenProject project;
/**
- * Replacement required for period special character in the identifier.
- */
- @Parameter(property = "replacementForPeriod")
- private String replacementForPeriod;
-
- /**
- * Replacement required for underscore special character in the identifier.
- */
- @Parameter(property = "replacementForUnderscore")
- private String replacementForUnderscore;
-
- /**
- * Replacement required for hyphen special character in the identifier.
- */
- @Parameter(property = "replacementForHyphen")
- private String replacementForHyphen;
-
- /**
- * Prefix which is required for adding with the identifier.
- */
- @Parameter(property = "prefixForIdentifier")
- private String prefixForIdentifier;
-
- /**
- * Build context.
- */
- @Component
- private BuildContext context;
-
- /**
* Local maven repository.
*/
@Parameter(readonly = true, defaultValue = "${localRepository}")
@@ -169,10 +117,10 @@
private List<ArtifactRepository> remoteRepository;
/**
- * Code generation is for nbi or sbi.
+ * Build context.
*/
- @Parameter(property = "generateJavaFileForSbi", defaultValue = "nbi")
- private String generateJavaFileForSbi;
+ @Component
+ private BuildContext context;
/**
* The Runtime information for the current instance of Maven.
@@ -186,13 +134,12 @@
@Parameter(defaultValue = "maven.version")
private String versionProperty;
- private String outputDir;
- private String codeGenDir;
-
@Override
public void execute()
throws MojoExecutionException, MojoFailureException {
+ String metaDataGenDir;
+ String outputDir;
try {
validateMavenVersion();
/*
@@ -202,44 +149,46 @@
deleteDirectory(outputDir + SLASH + TEMP);
deleteDirectory(outputDir + SLASH + YANG_RESOURCES);
String searchDir = getDirectory(baseDir, yangFilesDir);
+
+ //Get the code gen directory.
codeGenDir = getDirectory(baseDir, classFileDir) + SLASH;
+ //Get the meta data gen directory.
+ metaDataGenDir = outputDir + SLASH + DEFAULT_JAR_RES_PATH;
- // Creates conflict resolver and set values to it.
- YangToJavaNamingConflictUtil conflictResolver = new YangToJavaNamingConflictUtil();
- conflictResolver.setReplacementForPeriod(replacementForPeriod);
- conflictResolver.setReplacementForHyphen(replacementForHyphen);
- conflictResolver.setReplacementForUnderscore(replacementForUnderscore);
- conflictResolver.setPrefixForIdentifier(prefixForIdentifier);
- yangPlugin.setCodeGenDir(codeGenDir);
- yangPlugin.setConflictResolver(conflictResolver);
+ //Yang compiler service.
+ YangCompilerService compiler = new YangCompilerManager();
- yangPlugin.resourceGenDir(outputDir + YangToolManager.DEFAULT_JAR_RES_PATH);
- yangPlugin.setCodeGenerateForSbi(generateJavaFileForSbi.toLowerCase());
+ //Need to get dependent schema paths to give inter jar dependencies.
+ List<Path> depSchemas = resolveInterJarDependencies(
+ project, localRepository, remoteRepository, outputDir);
- /*
- * Obtain the YANG files at a path mentioned in plugin and creates
- * YANG file information set.
- */
+ //Create compiler param.
+ YangCompilationParam param = new DefaultYangCompilationParam();
+ param.setCodeGenDir(Paths.get(codeGenDir));
+ param.setMetadataGenDir(Paths.get(metaDataGenDir));
- YangToolManager toolManager = new YangToolManager();
+ for (Path path : depSchemas) {
+ param.addDependentSchema(path);
+ }
- yangFileInfoSet = toolManager.createYangFileInfoSet(
- getYangFiles(searchDir));
- List<YangNode> interJarResolvedNodes =
- resolveInterJarDependencies(project, localRepository,
- remoteRepository, outputDir);
- toolManager.compileYangFiles(yangFileInfoSet,
- interJarResolvedNodes, yangPlugin,
- this);
- } catch (YangToolException e) {
+ for (String file : getYangFiles(searchDir)) {
+ param.addYangFile(Paths.get(file));
+ }
+
+ //Compile yang files and generate java code.
+ output = compiler.compileYangFiles(param);
+
+ addToCompilationRoot(codeGenDir, project, context);
+ addToProjectResource(outputDir + SLASH + TEMP + SLASH, project);
+ } catch (YangCompilerException e) {
String fileName = EMPTY_STRING;
- if (e.getCurYangFile() != null) {
- fileName = e.getCurYangFile().getYangFileName();
+ if (e.getYangFile() != null) {
+ fileName = e.getYangFile().toString();
}
try {
- deleteDirectory(codeGenDir + DEFAULT_PKG);
+ deleteDirectory(codeGenDir + getPackageDirPathFromJavaJPackage(
+ DEFAULT_BASE_PKG));
} catch (IOException ex) {
- e.printStackTrace();
throw new MojoExecutionException(
"Error handler failed to delete files for data model node.");
}
@@ -264,169 +213,4 @@
throw new MojoExecutionException(VERSION_ERROR + version);
}
}
-
- /**
- * Returns the YANG node set.
- *
- * @return YANG node set
- */
- public Set<YangNode> getYangNodeSet() {
- return yangNodeSet;
- }
-
- /**
- * TODO: Delete me and use the tool code for UT test cases
- * Links all the provided with the YANG file info set.
- *
- * @throws MojoExecutionException a violation in mojo execution
- */
- public void resolveDependenciesUsingLinker()
- throws MojoExecutionException {
- createYangNodeSet();
- try {
- yangLinker.resolveDependencies(yangNodeSet);
- } catch (LinkerException e) {
- printLog(e.getFileName(), e.getLineNumber(), e.getCharPositionInLine(),
- e.getMessage(), e.getLocalizedMessage());
- throw new MojoExecutionException(e.getMessage());
- }
- }
-
- /**
- * TODO: Delete me and use the tool code for UT test cases
- * Creates YANG nodes set.
- */
- public void createYangNodeSet() {
- for (YangFileInfo yangFileInfo : yangFileInfoSet) {
- yangNodeSet.add(yangFileInfo.getRootNode());
- }
- }
-
- /**
- * TODO: Delete me and use the tool code for UT test cases
- * Parses all the provided YANG files and generates YANG data model tree.
- *
- * @throws IOException a violation in IO
- */
- public void parseYangFileInfoSet()
- throws IOException {
- for (YangFileInfo yangFileInfo : yangFileInfoSet) {
- curYangFileInfo = yangFileInfo;
- if (yangFileInfo.isForTranslator()) {
- try {
- YangNode yangNode = yangUtilsParser.getDataModel(
- yangFileInfo.getYangFileName());
- yangFileInfo.setRootNode(yangNode);
- rootNode = yangNode;
- resolveGroupingInDefinationScope((YangReferenceResolver) yangNode);
- try {
- ((YangReferenceResolver) yangNode)
- .resolveSelfFileLinking(ResolvableType.YANG_DERIVED_DATA_TYPE);
- ((YangReferenceResolver) yangNode)
- .resolveSelfFileLinking(ResolvableType.YANG_IDENTITYREF);
- } catch (DataModelException e) {
- printLog(e.getFileName(), e.getLineNumber(), e
- .getCharPositionInLine(), e.getMessage(), e
- .getLocalizedMessage());
- }
- } catch (ParserException e) {
- printLog(e.getFileName(), e.getLineNumber(), e
- .getCharPositionInLine(), e.getMessage(), e
- .getLocalizedMessage());
- throw e;
- }
- }
- }
- }
-
- /**
- * TODO: Delete me and use the tool code for UT test cases
- * Translates to java code corresponding to the YANG schema.
- *
- * @param yangPlugin YANG plugin config
- * @throws IOException when fails to generate java code file the current node
- */
- public void translateToJava(YangPluginConfig yangPlugin)
- throws IOException {
- List<YangNode> yangNodeSortedList = new LinkedList<>();
- yangNodeSortedList.addAll(yangNodeSet);
- sort(yangNodeSortedList);
- for (YangNode node : yangNodeSortedList) {
- if (node.isToTranslate() && (!((YangDeviationHolder) node)
- .isModuleForDeviation())) {
- JavaCodeGeneratorUtil.generateJavaCode(node, yangPlugin);
- }
- }
- }
-
- /**
- * Creates a YANG file info set.
- *
- * @param yangFileList YANG files list
- */
- public void createYangFileInfoSet(List<String> yangFileList) {
- for (String yangFile : yangFileList) {
- YangFileInfo yangFileInfo = new YangFileInfo();
- yangFileInfo.setYangFileName(yangFile);
- yangFileInfoSet.add(yangFileInfo);
- }
- }
-
- /**
- * TODO: Delete me and use the tool code for UT test cases
- * Returns the YANG file info set.
- *
- * @return the YANG file info set
- */
- public Set<YangFileInfo> getYangFileInfoSet() {
- return yangFileInfoSet;
- }
-
- /**
- * TODO: Delete me and use the tool code for UT test cases
- * Sets the YANG file info set.
- *
- * @param yangFileInfoSet the YANG file info set
- */
- void setYangFileInfoSet(Set<YangFileInfo> yangFileInfoSet) {
- this.yangFileInfoSet = yangFileInfoSet;
- }
-
- /**
- * Adds log info for exception.
- *
- * @param fileName file name
- * @param line line number
- * @param position character position
- * @param msg error message
- * @param localMsg local message
- */
- private void printLog(String fileName, int line, int position, String
- msg, String localMsg) {
- String logInfo = "Error in file: " + fileName;
- if (line != 0) {
- logInfo = logInfo + " at line: " + line + " at position: "
- + position;
- }
- if (msg != null) {
- logInfo = logInfo + NEW_LINE + localMsg;
- }
- getLog().info(logInfo);
- }
-
- @Override
- public void addGeneratedCodeToBundle() {
- addToCompilationRoot(codeGenDir, project, context);
- }
-
-
- @Override
- public void addCompiledSchemaToBundle() throws IOException {
- serializeDataModel(outputDir, project, true);
- }
-
- @Override
- public void addYangFilesToBundle() throws IOException {
- copyYangFilesToTarget(outputDir, project);
- }
}
diff --git a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/AugmentTranslatorTest.java b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/AugmentTranslatorTest.java
index 3d7a6e6..f188058 100644
--- a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/AugmentTranslatorTest.java
+++ b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/AugmentTranslatorTest.java
@@ -18,20 +18,26 @@
import org.apache.maven.plugin.MojoExecutionException;
import org.junit.Test;
-import org.onosproject.yang.compiler.utils.io.YangPluginConfig;
-import org.onosproject.yang.compiler.utils.io.impl.YangFileScanner;
-import org.onosproject.yang.compiler.utils.io.impl.YangIoUtils;
import org.onosproject.yang.compiler.parser.exceptions.ParserException;
+import org.onosproject.yang.compiler.tool.impl.YangCompilerManager;
+import org.onosproject.yang.compiler.utils.io.YangPluginConfig;
import java.io.File;
import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.HashSet;
+import java.util.Set;
+
+import static org.onosproject.yang.compiler.utils.io.impl.YangFileScanner.getYangFiles;
+import static org.onosproject.yang.compiler.utils.io.impl.YangIoUtils.deleteDirectory;
/**
* Unit test case for augment translator.
*/
public class AugmentTranslatorTest {
- private final YangUtilManager utilManager = new YangUtilManager();
+ private final YangCompilerManager utilManager = new YangCompilerManager();
private static final String DIR = "target/augmentTranslator/";
private static final String COMP = System.getProperty("user.dir") + File
.separator + DIR;
@@ -44,9 +50,15 @@
@Test
public void processAugmentTranslator() throws IOException, ParserException, MojoExecutionException {
- YangIoUtils.deleteDirectory(DIR);
+ deleteDirectory(DIR);
String searchDir = "src/test/resources/augmentTranslator";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
@@ -55,7 +67,7 @@
yangPluginConfig.setCodeGenDir(DIR);
utilManager.translateToJava(yangPluginConfig);
YangPluginConfig.compileCode(COMP);
- YangIoUtils.deleteDirectory(DIR);
+ deleteDirectory(DIR);
}
/**
@@ -68,9 +80,15 @@
@Test
public void processRpcAugmentIntraTranslator() throws IOException,
ParserException, MojoExecutionException {
- YangIoUtils.deleteDirectory(DIR);
+ deleteDirectory(DIR);
String searchDir = "src/test/resources/rpcAugment/intra";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
@@ -78,20 +96,26 @@
YangPluginConfig yangPluginConfig = new YangPluginConfig();
yangPluginConfig.setCodeGenDir(DIR);
utilManager.translateToJava(yangPluginConfig);
- YangIoUtils.deleteDirectory(DIR);
+ deleteDirectory(DIR);
}
/**
* Checks augment translation should not result in any exception.
*
- * @throws MojoExecutionException
+ * @throws MojoExecutionException when fails to mojo operations
*/
@Test
public void processRpcAugmentInterTranslator() throws IOException,
ParserException, MojoExecutionException {
- YangIoUtils.deleteDirectory(DIR);
+ deleteDirectory(DIR);
String searchDir = "src/test/resources/rpcAugment/inter";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
@@ -100,20 +124,26 @@
yangPluginConfig.setCodeGenDir(DIR);
utilManager.translateToJava(yangPluginConfig);
YangPluginConfig.compileCode(COMP);
- YangIoUtils.deleteDirectory(DIR);
+ deleteDirectory(DIR);
}
/**
* Checks augment translation should not result in any exception.
*
- * @throws MojoExecutionException
+ * @throws MojoExecutionException when fails
*/
@Test
public void processChoiceAugmentInterTranslator() throws IOException,
ParserException, MojoExecutionException {
- YangIoUtils.deleteDirectory(DIR);
+ deleteDirectory(DIR);
String searchDir = "src/test/resources/choiceAugment";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
@@ -122,7 +152,6 @@
yangPluginConfig.setCodeGenDir(DIR);
utilManager.translateToJava(yangPluginConfig);
YangPluginConfig.compileCode(COMP);
- YangIoUtils.deleteDirectory(DIR);
+ deleteDirectory(DIR);
}
-
}
diff --git a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/ChoiceCaseTranslatorTest.java b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/ChoiceCaseTranslatorTest.java
index 3a1976b..a9d14c7 100644
--- a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/ChoiceCaseTranslatorTest.java
+++ b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/ChoiceCaseTranslatorTest.java
@@ -21,14 +21,19 @@
import org.onosproject.yang.compiler.datamodel.YangNode;
import org.onosproject.yang.compiler.parser.exceptions.ParserException;
import org.onosproject.yang.compiler.parser.impl.YangUtilsParserManager;
+import org.onosproject.yang.compiler.tool.impl.YangCompilerManager;
import org.onosproject.yang.compiler.utils.io.YangPluginConfig;
-import org.onosproject.yang.compiler.utils.io.impl.YangFileScanner;
import org.onosproject.yang.compiler.utils.io.impl.YangIoUtils;
import java.io.File;
import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.HashSet;
+import java.util.Set;
import static org.onosproject.yang.compiler.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode;
+import static org.onosproject.yang.compiler.utils.io.impl.YangFileScanner.getYangFiles;
/**
* Unit tests for choice-case translator.
@@ -37,7 +42,7 @@
private static final String DIR = "target/ChoiceCaseTestGenFile/";
private static final String COMP = System.getProperty("user.dir") + File
.separator + DIR;
- private final YangUtilManager utilManager = new YangUtilManager();
+ private final YangCompilerManager utilManager = new YangCompilerManager();
private final YangUtilsParserManager manager = new YangUtilsParserManager();
/**
@@ -69,7 +74,13 @@
ParserException, MojoExecutionException {
YangIoUtils.deleteDirectory(DIR);
String searchDir = "src/test/resources/choiceTranslator";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
diff --git a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/CompilerAnnotationTest.java b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/CompilerAnnotationTest.java
index d020cee..8e4cb8b 100644
--- a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/CompilerAnnotationTest.java
+++ b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/CompilerAnnotationTest.java
@@ -19,19 +19,25 @@
import org.apache.maven.plugin.MojoExecutionException;
import org.junit.Test;
-import org.onosproject.yang.compiler.utils.io.YangPluginConfig;
-import org.onosproject.yang.compiler.utils.io.impl.YangFileScanner;
-import org.onosproject.yang.compiler.utils.io.impl.YangIoUtils;
import org.onosproject.yang.compiler.parser.exceptions.ParserException;
+import org.onosproject.yang.compiler.tool.impl.YangCompilerManager;
+import org.onosproject.yang.compiler.utils.io.YangPluginConfig;
+import org.onosproject.yang.compiler.utils.io.impl.YangIoUtils;
import java.io.File;
import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.HashSet;
+import java.util.Set;
+
+import static org.onosproject.yang.compiler.utils.io.impl.YangFileScanner.getYangFiles;
/**
* Unit test case for compiler annotation.
*/
public class CompilerAnnotationTest {
- private final YangUtilManager utilManager = new YangUtilManager();
+ private final YangCompilerManager utilManager = new YangCompilerManager();
private static final String DIR = "target/compiler/";
private static final String COMP = System.getProperty("user.dir") + File
.separator + DIR;
@@ -47,7 +53,12 @@
ParserException, MojoExecutionException {
YangIoUtils.deleteDirectory(DIR);
String searchDir = "src/test/resources/compilerAnnotation";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
diff --git a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/GroupingTranslatorTest.java b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/GroupingTranslatorTest.java
index d7e6580..16bb01f 100644
--- a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/GroupingTranslatorTest.java
+++ b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/GroupingTranslatorTest.java
@@ -18,20 +18,27 @@
import org.apache.maven.plugin.MojoExecutionException;
import org.junit.Test;
-import org.onosproject.yang.compiler.utils.io.YangPluginConfig;
-import org.onosproject.yang.compiler.utils.io.impl.YangFileScanner;
-import org.onosproject.yang.compiler.utils.io.impl.YangIoUtils;
import org.onosproject.yang.compiler.parser.exceptions.ParserException;
+import org.onosproject.yang.compiler.tool.impl.YangCompilerManager;
+import org.onosproject.yang.compiler.utils.io.YangPluginConfig;
+import org.onosproject.yang.compiler.utils.io.impl.YangIoUtils;
import java.io.File;
import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.HashSet;
+import java.util.Set;
+
+import static org.onosproject.yang.compiler.utils.io.impl.YangFileScanner.getYangFiles;
/**
* Unit test case for grouping translator.
*/
public class GroupingTranslatorTest {
- private final YangUtilManager utilManager = new YangUtilManager();
+ private final YangCompilerManager utilManager =
+ new YangCompilerManager();
private static final String DIR = "target/groupingTranslator/";
private static final String COMP = System.getProperty("user.dir") + File
.separator + DIR;
@@ -46,7 +53,12 @@
YangIoUtils.deleteDirectory(DIR);
String searchDir = "src/test/resources/grouping";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
@@ -57,5 +69,4 @@
YangPluginConfig.compileCode(COMP);
YangIoUtils.deleteDirectory(DIR);
}
-
}
diff --git a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/IdentityTranslatorTest.java b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/IdentityTranslatorTest.java
index 2835a64..2346397 100644
--- a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/IdentityTranslatorTest.java
+++ b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/IdentityTranslatorTest.java
@@ -22,28 +22,34 @@
import org.onosproject.yang.compiler.datamodel.YangModule;
import org.onosproject.yang.compiler.datamodel.YangNode;
import org.onosproject.yang.compiler.linker.impl.YangLinkerManager;
-import org.onosproject.yang.compiler.utils.io.YangPluginConfig;
-import org.onosproject.yang.compiler.utils.io.impl.YangFileScanner;
-import org.onosproject.yang.compiler.utils.io.impl.YangIoUtils;
import org.onosproject.yang.compiler.parser.exceptions.ParserException;
+import org.onosproject.yang.compiler.tool.impl.YangCompilerManager;
+import org.onosproject.yang.compiler.utils.io.YangPluginConfig;
import java.io.File;
import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.HashSet;
+import java.util.Set;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.onosproject.yang.compiler.datamodel.YangNodeType.MODULE_NODE;
import static org.onosproject.yang.compiler.linker.impl.YangLinkerUtils.updateFilePriority;
import static org.onosproject.yang.compiler.utils.io.YangPluginConfig.compileCode;
+import static org.onosproject.yang.compiler.utils.io.impl.YangFileScanner.getYangFiles;
import static org.onosproject.yang.compiler.utils.io.impl.YangIoUtils.deleteDirectory;
+
/**
* Translator test case for identity.
*/
public class IdentityTranslatorTest {
- private final YangUtilManager utilManager = new YangUtilManager();
private final YangLinkerManager yangLinkerManager = new YangLinkerManager();
+ private final YangCompilerManager utilManager =
+ new YangCompilerManager();
private static final String DIR = "target/identity/";
private static final String COMP = System.getProperty("user.dir") + File
.separator + DIR;
@@ -58,7 +64,12 @@
ParserException, MojoExecutionException {
deleteDirectory(DIR);
String searchDir = "src/test/resources/identityTranslator";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
@@ -80,7 +91,12 @@
ParserException, MojoExecutionException {
deleteDirectory(DIR);
String searchDir = "src/test/resources/multipleIdentity";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
diff --git a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/IncludeReferenceWithPrefix.java b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/IncludeReferenceWithPrefix.java
index fc35b92..cf1e089 100644
--- a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/IncludeReferenceWithPrefix.java
+++ b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/IncludeReferenceWithPrefix.java
@@ -18,20 +18,27 @@
import org.apache.maven.plugin.MojoExecutionException;
import org.junit.Test;
-import org.onosproject.yang.compiler.utils.io.YangPluginConfig;
-import org.onosproject.yang.compiler.utils.io.impl.YangFileScanner;
-import org.onosproject.yang.compiler.utils.io.impl.YangIoUtils;
import org.onosproject.yang.compiler.parser.exceptions.ParserException;
+import org.onosproject.yang.compiler.tool.impl.YangCompilerManager;
+import org.onosproject.yang.compiler.utils.io.YangPluginConfig;
+import org.onosproject.yang.compiler.utils.io.impl.YangIoUtils;
import java.io.File;
import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.HashSet;
+import java.util.Set;
+
+import static org.onosproject.yang.compiler.utils.io.impl.YangFileScanner.getYangFiles;
/**
* Test cases for testing YANG schema node.
*/
public class IncludeReferenceWithPrefix {
- private final YangUtilManager utilManager = new YangUtilManager();
+ private final YangCompilerManager utilManager =
+ new YangCompilerManager();
/**
* Checks method to get schema node from map.
@@ -44,7 +51,12 @@
String dir = "target/refincludecontentwithprefix/";
YangIoUtils.deleteDirectory(dir);
String searchDir = "src/test/resources/refincludecontentwithprefix";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
diff --git a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/InterFileDeviationLinkingTest.java b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/InterFileDeviationLinkingTest.java
index e1cf83f..69eed20 100644
--- a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/InterFileDeviationLinkingTest.java
+++ b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/InterFileDeviationLinkingTest.java
@@ -30,15 +30,19 @@
import org.onosproject.yang.compiler.linker.exceptions.LinkerException;
import org.onosproject.yang.compiler.linker.impl.YangLinkerManager;
import org.onosproject.yang.compiler.parser.exceptions.ParserException;
+import org.onosproject.yang.compiler.tool.impl.YangCompilerManager;
import org.onosproject.yang.compiler.translator.tojava.JavaFileInfoContainer;
import org.onosproject.yang.compiler.translator.tojava.JavaFileInfoTranslator;
import org.onosproject.yang.compiler.utils.io.YangPluginConfig;
-import org.onosproject.yang.compiler.utils.io.impl.YangFileScanner;
import java.io.File;
import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Set;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -50,6 +54,7 @@
import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes.UINT16;
import static org.onosproject.yang.compiler.linker.impl.YangLinkerUtils.updateFilePriority;
import static org.onosproject.yang.compiler.utils.io.YangPluginConfig.compileCode;
+import static org.onosproject.yang.compiler.utils.io.impl.YangFileScanner.getYangFiles;
import static org.onosproject.yang.compiler.utils.io.impl.YangIoUtils.deleteDirectory;
@@ -59,7 +64,8 @@
public class InterFileDeviationLinkingTest {
private static final String DIR = "target/deviationTest/";
- private final YangUtilManager utilManager = new YangUtilManager();
+ private final YangCompilerManager utilManager =
+ new YangCompilerManager();
private final YangLinkerManager yangLinkerManager = new YangLinkerManager();
private static final String COMP = System.getProperty("user.dir") + File
.separator + DIR;
@@ -72,7 +78,12 @@
ParserException {
String searchDir = "src/test/resources/deviationLinking";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
@@ -144,7 +155,6 @@
// Check whether the node type is set properly to module.
assertThat(selfNode.getNodeType(), is(MODULE_NODE));
-
// Check whether the module name is set correctly.
yangRefNode = (YangModule) refNode;
assertThat(yangRefNode.getName(), is("Test2"));
@@ -186,7 +196,12 @@
ParserException {
String searchDir = "src/test/resources/deviationLinking";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
@@ -282,7 +297,12 @@
ParserException {
String searchDir = "src/test/resources/deviationLinking";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
@@ -386,7 +406,12 @@
ParserException {
String searchDir = "src/test/resources/deviationLinking";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
@@ -498,7 +523,12 @@
ParserException {
String searchDir = "src/test/resources/InvalidDeviation";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
diff --git a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/InterFileIdentityLinkingTest.java b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/InterFileIdentityLinkingTest.java
index 544047c..a2d6a67 100644
--- a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/InterFileIdentityLinkingTest.java
+++ b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/InterFileIdentityLinkingTest.java
@@ -32,27 +32,33 @@
import org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yang.compiler.linker.exceptions.LinkerException;
import org.onosproject.yang.compiler.linker.impl.YangLinkerManager;
-import org.onosproject.yang.compiler.utils.io.YangPluginConfig;
-import org.onosproject.yang.compiler.utils.io.impl.YangFileScanner;
-import org.onosproject.yang.compiler.utils.io.impl.YangIoUtils;
import org.onosproject.yang.compiler.parser.exceptions.ParserException;
+import org.onosproject.yang.compiler.tool.impl.YangCompilerManager;
+import org.onosproject.yang.compiler.utils.io.YangPluginConfig;
+import org.onosproject.yang.compiler.utils.io.impl.YangIoUtils;
import java.io.File;
import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.HashSet;
import java.util.ListIterator;
+import java.util.Set;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.onosproject.yang.compiler.datamodel.YangNodeType.MODULE_NODE;
import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes.IDENTITYREF;
import static org.onosproject.yang.compiler.linker.impl.YangLinkerUtils.updateFilePriority;
+import static org.onosproject.yang.compiler.utils.io.impl.YangFileScanner.getYangFiles;
/**
* Test cases for testing inter file linking for identity.
*/
public class InterFileIdentityLinkingTest {
- private final YangUtilManager utilManager = new YangUtilManager();
+ private final YangCompilerManager utilManager =
+ new YangCompilerManager();
private final YangLinkerManager yangLinkerManager = new YangLinkerManager();
@Rule
@@ -66,7 +72,12 @@
throws IOException, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/interfileidentityimport";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
@@ -140,7 +151,6 @@
assertThat(yangIdentityRef.getBaseIdentity().getName(), is("ref-address-family"));
assertThat(yangIdentityRef.getReferredIdentity().getName(), is("ref-address-family"));
assertThat(yangIdentityRef.getResolvableStatus(), is(ResolvableStatus.RESOLVED));
-
}
@Test
@@ -148,7 +158,12 @@
YangIoUtils.deleteDirectory("target/identityTranslator/");
String searchDir = "src/test/resources/interfileidentityimport";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
@@ -169,7 +184,12 @@
throws IOException, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/interfileidentityinlude";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
@@ -259,7 +279,12 @@
throws IOException, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/interfileidentityimportdependency";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
@@ -343,7 +368,12 @@
throws IOException, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/interfileidentityincludedependency";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
@@ -436,7 +466,12 @@
thrown.expectMessage("YANG file error: Unable to find base identity for given base");
String searchDir = "src/test/resources/interfileidentityimportdependencyUndefined";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
@@ -467,7 +502,12 @@
thrown.expectMessage("YANG file error: Unable to find base identity for given base");
String searchDir = "src/test/resources/interfileidentityincludedependencyUndefined";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
@@ -498,7 +538,12 @@
throws IOException, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/interfileidentitytypedef";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
@@ -593,7 +638,12 @@
throws IOException, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/interfileidentitytypedef";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
diff --git a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/InterFileIfFeatureLinkingTest.java b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/InterFileIfFeatureLinkingTest.java
index afcee89..adb854c 100644
--- a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/InterFileIfFeatureLinkingTest.java
+++ b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/InterFileIfFeatureLinkingTest.java
@@ -28,23 +28,29 @@
import org.onosproject.yang.compiler.datamodel.utils.ResolvableStatus;
import org.onosproject.yang.compiler.linker.impl.YangLinkerManager;
import org.onosproject.yang.compiler.linker.impl.YangLinkerUtils;
-import org.onosproject.yang.compiler.utils.io.impl.YangFileScanner;
import org.onosproject.yang.compiler.parser.exceptions.ParserException;
+import org.onosproject.yang.compiler.tool.impl.YangCompilerManager;
import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.HashSet;
import java.util.List;
import java.util.ListIterator;
+import java.util.Set;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.onosproject.yang.compiler.datamodel.YangNodeType.MODULE_NODE;
+import static org.onosproject.yang.compiler.utils.io.impl.YangFileScanner.getYangFiles;
/**
* Test cases for testing inter file linking.
*/
public class InterFileIfFeatureLinkingTest {
- private final YangUtilManager utilManager = new YangUtilManager();
+ private final YangCompilerManager utilManager =
+ new YangCompilerManager();
private final YangLinkerManager yangLinkerManager = new YangLinkerManager();
/**
@@ -55,7 +61,12 @@
throws IOException, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/interfilefeatureimport";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
@@ -121,7 +132,12 @@
throws IOException, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/interfilefeatureinclude";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
@@ -193,7 +209,12 @@
throws IOException, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/interfilefeatureimportdependency";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
@@ -261,7 +282,12 @@
throws IOException, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/interfilefeatureincludedependency";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
@@ -334,7 +360,12 @@
throws IOException, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/interfilefeatureimportdependencyUndefined";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
@@ -402,7 +433,12 @@
throws IOException, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/interfilefeatureincludedependencyUndefined";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
diff --git a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/InterFileLeafrefLinkingTest.java b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/InterFileLeafrefLinkingTest.java
index ebda757..39b990c 100644
--- a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/InterFileLeafrefLinkingTest.java
+++ b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/InterFileLeafrefLinkingTest.java
@@ -32,18 +32,23 @@
import org.onosproject.yang.compiler.datamodel.utils.ResolvableStatus;
import org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yang.compiler.linker.impl.YangLinkerManager;
-import org.onosproject.yang.compiler.utils.io.impl.YangFileScanner;
import org.onosproject.yang.compiler.parser.exceptions.ParserException;
+import org.onosproject.yang.compiler.tool.impl.YangCompilerManager;
import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.ListIterator;
+import java.util.Set;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.onosproject.yang.compiler.datamodel.YangNodeType.MODULE_NODE;
import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes.LEAFREF;
import static org.onosproject.yang.compiler.linker.impl.YangLinkerUtils.updateFilePriority;
+import static org.onosproject.yang.compiler.utils.io.impl.YangFileScanner.getYangFiles;
/**
* Test cases for testing leafref inter file linking.
@@ -53,7 +58,9 @@
@Rule
public ExpectedException thrown = ExpectedException.none();
- private final YangUtilManager utilManager = new YangUtilManager();
+
+ private final YangCompilerManager utilManager =
+ new YangCompilerManager();
private final YangLinkerManager yangLinkerManager = new YangLinkerManager();
/**
@@ -64,7 +71,13 @@
throws IOException, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/leafreflinker/interfile/interfileleafrefwithimport";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
YangNode refNode = null;
@@ -127,7 +140,7 @@
assertThat(leafref.getResolvableStatus(), Is.is(ResolvableStatus.RESOLVED));
assertThat(leafref.getEffectiveDataType().getDataType(),
- is(YangDataTypes.STRING));
+ is(YangDataTypes.STRING));
}
/**
@@ -138,7 +151,13 @@
throws IOException, ParserException {
String searchDir = "src/test/resources/leafreflinker/interfile/interfileleafreffromgroupingreferstootherfile";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
YangNode selfNode = null;
@@ -192,7 +211,7 @@
assertThat(leafref.getResolvableStatus(), Is.is(ResolvableStatus.RESOLVED));
assertThat(leafref.getEffectiveDataType().getDataType(),
- is(YangDataTypes.STRING));
+ is(YangDataTypes.STRING));
}
/**
@@ -203,7 +222,13 @@
throws IOException, ParserException {
String searchDir = "src/test/resources/leafreflinker/interfile/leafrefInGroupingWithPrefix";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
YangNode selfNode = null;
@@ -262,7 +287,7 @@
assertThat(leafref.getResolvableStatus(), Is.is(ResolvableStatus.RESOLVED));
assertThat(leafref.getEffectiveDataType().getDataType(),
- is(YangDataTypes.STRING));
+ is(YangDataTypes.STRING));
}
/**
@@ -274,7 +299,13 @@
throws IOException, ParserException {
String searchDir = "src/test/resources/leafreflinker/interfile/leafrefInGroupingWithPrefixAndManyReference";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
YangNode selfNode = null;
@@ -336,7 +367,7 @@
assertThat(leafref.getResolvableStatus(), Is.is(ResolvableStatus.RESOLVED));
assertThat(leafref.getEffectiveDataType().getDataType(),
- is(YangDataTypes.DERIVED));
+ is(YangDataTypes.DERIVED));
leafInfo = leafIterator.next();
@@ -351,7 +382,7 @@
assertThat(leafref1.getResolvableStatus(), Is.is(ResolvableStatus.RESOLVED));
assertThat(leafref1.getEffectiveDataType().getDataType(),
- is(YangDataTypes.DERIVED));
+ is(YangDataTypes.DERIVED));
}
/**
@@ -361,7 +392,13 @@
public void processLeafrefWhenUsedMultipleTimes()
throws IOException, ParserException {
String searchDir = "src/test/resources/leafreflinker/interfile/typedefreferredmultipletimes";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
YangNode selfNode = null;
@@ -413,11 +450,11 @@
// Check whether leafref type got resolved.
assertThat(leafref.getResolvableStatus(),
- is(ResolvableStatus.RESOLVED));
+ is(ResolvableStatus.RESOLVED));
// Check the effective type for the leaf.
assertThat(leafref.getEffectiveDataType().getDataType(),
- is(YangDataTypes.STRING));
+ is(YangDataTypes.STRING));
leafInfo = leafIterator.next();
@@ -429,10 +466,10 @@
// Check whether leafref type got resolved.
assertThat(leafref1.getResolvableStatus(),
- is(ResolvableStatus.RESOLVED));
+ is(ResolvableStatus.RESOLVED));
// Check the effective type for the leaf.
assertThat(leafref1.getEffectiveDataType().getDataType(),
- is(YangDataTypes.STRING));
+ is(YangDataTypes.STRING));
}
}
diff --git a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/InterFileLinkingTest.java b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/InterFileLinkingTest.java
index ed431be..d33efcb 100644
--- a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/InterFileLinkingTest.java
+++ b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/InterFileLinkingTest.java
@@ -37,15 +37,19 @@
import org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yang.compiler.linker.impl.YangLinkerManager;
import org.onosproject.yang.compiler.linker.impl.YangLinkerUtils;
-import org.onosproject.yang.compiler.utils.io.YangPluginConfig;
-import org.onosproject.yang.compiler.utils.io.impl.YangFileScanner;
-import org.onosproject.yang.compiler.utils.io.impl.YangIoUtils;
import org.onosproject.yang.compiler.parser.exceptions.ParserException;
import org.onosproject.yang.compiler.parser.impl.YangUtilsParserManager;
+import org.onosproject.yang.compiler.tool.impl.YangCompilerManager;
+import org.onosproject.yang.compiler.utils.io.YangPluginConfig;
+import org.onosproject.yang.compiler.utils.io.impl.YangIoUtils;
import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.ListIterator;
+import java.util.Set;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -53,6 +57,7 @@
import static org.onosproject.yang.compiler.datamodel.YangNodeType.MODULE_NODE;
import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes.DERIVED;
import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes.STRING;
+import static org.onosproject.yang.compiler.utils.io.impl.YangFileScanner.getYangFiles;
/**
* Test cases for testing inter file linking.
@@ -63,7 +68,9 @@
public ExpectedException thrown = ExpectedException.none();
private final YangUtilsParserManager manager = new YangUtilsParserManager();
- private final YangUtilManager utilManager = new YangUtilManager();
+
+ private final YangCompilerManager utilManager =
+ new YangCompilerManager();
private final YangLinkerManager yangLinkerManager = new YangLinkerManager();
/**
@@ -74,7 +81,13 @@
throws IOException, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/interfiletype";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
@@ -146,7 +159,13 @@
throws IOException, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/interfileuses";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
@@ -218,7 +237,13 @@
throws IOException, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/interfiletypewithinclude";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
@@ -293,7 +318,13 @@
throws IOException, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/interfileuseswithinclude";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
@@ -368,7 +399,13 @@
throws IOException, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/interfiletypewithrevision";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
@@ -440,7 +477,13 @@
throws IOException, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/interfiletypewithrevisioninname";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
@@ -512,7 +555,13 @@
throws IOException, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/hierarchicalinterfiletype";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
@@ -583,7 +632,13 @@
throws IOException, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/hierarchicalintrawithinterfiletype";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
@@ -651,7 +706,13 @@
throws IOException, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/interfilewithusesreferringtype";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.resolveDependenciesUsingLinker();
@@ -661,7 +722,6 @@
utilManager.translateToJava(yangPluginConfig);
YangIoUtils.deleteDirectory("target/interfilewithusesreferringtype/");
-
}
/**
@@ -672,7 +732,13 @@
throws IOException, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/file1UsesFile2TypeDefFile3Type";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.resolveDependenciesUsingLinker();
@@ -684,7 +750,6 @@
+ "target/file1UsesFile2TypeDefFile3Type/";
YangPluginConfig.compileCode(dir1);
YangIoUtils.deleteDirectory("target/file1UsesFile2TypeDefFile3Type/");
-
}
/**
@@ -696,7 +761,13 @@
YangIoUtils.deleteDirectory("target/interfileietf/");
String searchDir = "src/test/resources/interfileietf";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.resolveDependenciesUsingLinker();
@@ -706,7 +777,6 @@
utilManager.translateToJava(yangPluginConfig);
YangIoUtils.deleteDirectory("target/interfileietf/");
-
}
/**
@@ -717,7 +787,13 @@
throws IOException, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/usesInContainer";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.resolveDependenciesUsingLinker();
@@ -727,7 +803,6 @@
utilManager.translateToJava(yangPluginConfig);
YangIoUtils.deleteDirectory("target/usesInContainer/");
-
}
/**
@@ -738,7 +813,13 @@
throws IOException, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/groupingNodeSameAsModule";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.resolveDependenciesUsingLinker();
@@ -750,7 +831,6 @@
+ "target/groupingNodeSameAsModule/";
YangPluginConfig.compileCode(dir1);
YangIoUtils.deleteDirectory("target/groupingNodeSameAsModule/");
-
}
/**
@@ -761,7 +841,13 @@
throws IOException, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/interfilepriority";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.resolveDependenciesUsingLinker();
@@ -809,7 +895,13 @@
throws IOException, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/usesInsideChildOfGrouping";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.resolveDependenciesUsingLinker();
@@ -865,7 +957,13 @@
throws IOException, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/interFileUsesInsideChildOfGrouping";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.resolveDependenciesUsingLinker();
diff --git a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/InterJarLinkerTest.java b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/InterJarLinkerTest.java
index 1ceefff..9d767e8 100644
--- a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/InterJarLinkerTest.java
+++ b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/InterJarLinkerTest.java
@@ -17,18 +17,28 @@
package org.onosproject.yang.compiler.plugin.maven;
import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.project.MavenProject;
+import org.junit.Test;
+import org.onosproject.yang.compiler.datamodel.YangContainer;
+import org.onosproject.yang.compiler.datamodel.YangDerivedInfo;
+import org.onosproject.yang.compiler.datamodel.YangGrouping;
+import org.onosproject.yang.compiler.datamodel.YangLeaf;
import org.onosproject.yang.compiler.datamodel.YangNode;
-import org.onosproject.yang.compiler.base.tool.YangFileInfo;
+import org.onosproject.yang.compiler.tool.YangFileInfo;
+import org.onosproject.yang.compiler.tool.impl.YangCompilerManager;
+import org.onosproject.yang.compiler.utils.io.YangPluginConfig;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.ObjectOutputStream;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.ListIterator;
import java.util.Set;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
@@ -36,19 +46,30 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.onosproject.yang.compiler.datamodel.utils.DataModelUtils.parseJarFile;
+import static org.onosproject.yang.compiler.datamodel.utils.ResolvableStatus.RESOLVED;
+import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes.DERIVED;
+import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes.STRING;
+import static org.onosproject.yang.compiler.utils.UtilConstants.DEFAULT_JAR_RES_PATH;
import static org.onosproject.yang.compiler.utils.UtilConstants.SLASH;
import static org.onosproject.yang.compiler.utils.UtilConstants.TEMP;
+import static org.onosproject.yang.compiler.utils.UtilConstants.YANG_META_DATA;
import static org.onosproject.yang.compiler.utils.UtilConstants.YANG_RESOURCES;
+import static org.onosproject.yang.compiler.utils.io.impl.YangFileScanner.getYangFiles;
+import static org.onosproject.yang.compiler.utils.io.impl.YangIoUtils.deleteDirectory;
/**
* Unit test case for inter jar linker.
*/
public class InterJarLinkerTest {
- private final YangUtilManager utilManager = new YangUtilManager();
+ private final YangCompilerManager utilManager =
+ new YangCompilerManager();
private static final String TARGET = "target/interJarFileLinking/";
private static final String YANG_FILES_DIR = "src/test/resources/interJarFileLinking/yangFiles/";
+ private static final String TARGET_RESOURCE_PATH = SLASH + TEMP + SLASH + YANG_RESOURCES + SLASH;
+ private static final String JAR_FILE_NAME = "onlab-test-1.7.0-SNAPSHOT.jar";
+ private static final String SER_FILE_NAME = "portPair.ser";
private static final String FLOW_CLASSIFIER_FOLDER = "target/interJarFileLinking/org/onosproject"
+ "/yang/gen/v1/sfc/flowclassifier/rev20160524";
@@ -56,127 +77,148 @@
+ "/yang/gen/v1/sfc/portpair/rev20160524";
private static final String FLOW_CLASSIFIER_MANAGER = FLOW_CLASSIFIER_FOLDER + SLASH + "FlowClassifierManager.java";
- private MockJarFileProvider mockJarFileProvider = new MockJarFileProvider();
-
/**
* Unit test case for a single jar dependency.
*
* @throws IOException when fails to do IO operations
* @throws MojoExecutionException when fails to do mojo operations
*/
-//TODO: FIX the interJAR test case for using toolmanger instead of plugin mgr
- // @Test
-// public void processSingleJarLinking()
-// throws IOException, MojoExecutionException {
-// utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(YANG_FILES_DIR));
-// Set<YangFileInfo> info = utilManager.getYangFileInfoSet();
-// int size1 = info.size();
-// utilManager.parseYangFileInfoSet();
-//
-// mockJarFileProvider.provideTestJarFile(utilManager);
-// utilManager.setYangFileInfoSet(removeFileInfoFromSet(info));
-// utilManager.resolveDependenciesUsingLinker();
-//
-// int size2 = info.size();
-// assertThat(true, is(size1 != size2));
-// assertThat(true, is(parseFileInfoSet(info.iterator())));
-//
-// deleteDirectory(TARGET);
-// mockJarFileProvider.deleteTestSerFile(YANG_FILES_DIR);
-// }
-//
-// /**
-// * Unit test case for a multiple jar dependency.
-// *
-// * @throws IOException when fails to do IO operations
-// * @throws MojoExecutionException when fails to do mojo operations
-// */
-// @Test
-// public void processMultipleJarLinking()
-// throws IOException, MojoExecutionException {
-// utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(YANG_FILES_DIR));
-//
-// Set<YangFileInfo> info = utilManager.getYangFileInfoSet();
-// int size1 = info.size();
-// utilManager.parseYangFileInfoSet();
-//
-// mockJarFileProvider.provideTestJarFile(utilManager);
-// utilManager.setYangFileInfoSet(removeFileInfoFromSet(info));
-//
-// utilManager.resolveDependenciesUsingLinker();
-// int size2 = info.size();
-// assertThat(true, is(size1 != size2));
-// assertThat(true, is(parseFileInfoSet(info.iterator())));
-// assertThat(true, is(parseFileInfoSet(info.iterator())));
-//
-// /*
-// * grouping flow-classifier {
-// * container flow-classifier {
-// * leaf id {
-// * type flow-classifier-id;
-// * }
-// *
-// * leaf tenant-id {
-// * type port-pair:tenant-id;
-// * }
-// * .
-// * .
-// * .
-// *
-// */
-//
-// Iterator<YangFileInfo> yangFileInfoIterator = info.iterator();
-//
-// YangFileInfo yangFileInfo = yangFileInfoIterator.next();
-//
-// while (yangFileInfoIterator.hasNext()) {
-// if (yangFileInfo.getRootNode().getName().equals("flow-classifier")) {
-// break;
-// }
-// yangFileInfo = yangFileInfoIterator.next();
-// }
-//
-// YangNode node = yangFileInfo.getRootNode();
-// node = node.getChild();
-// while (node != null) {
-// if (node instanceof YangGrouping) {
-// break;
-// }
-// node = node.getNextSibling();
-// }
-//
-// node = node.getChild();
-// ListIterator<YangLeaf> leafIterator = ((YangContainer) node).getListOfLeaf().listIterator();
-// YangLeaf leafInfo = leafIterator.next();
-//
-// assertThat(leafInfo.getName(), is("id"));
-// assertThat(leafInfo.getDataType().getDataTypeName(), is("flow-classifier-id"));
-// assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
-//
-// leafInfo = leafIterator.next();
-//
-// assertThat(leafInfo.getName(), is("tenant-id"));
-// assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
-//
-// assertThat(true, is(((YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo()).getReferredTypeDef()
-// .getName().equals("tenant-id")));
-//
-// assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED));
-//
-// YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType().getDataTypeExtendedInfo();
-//
-// // Check for the effective built-in type.
-// assertThat(derivedInfo.getEffectiveBuiltInType(), is(STRING));
-//
-// YangPluginConfig yangPluginConfig = new YangPluginConfig();
-// yangPluginConfig.setCodeGenDir(TARGET);
-//
-// utilManager.translateToJava(yangPluginConfig);
-// testIfFlowClassifierFilesExists();
-// testIfPortPairFileDoesNotExist();
-// deleteDirectory(TARGET);
-// mockJarFileProvider.deleteTestSerFile(YANG_FILES_DIR);
-// }
+ @Test
+ public void processSingleJarLinking()
+ throws IOException, MojoExecutionException {
+ deleteDirectory(TARGET);
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(YANG_FILES_DIR)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
+ int size1 = utilManager.getYangFileInfoSet().size();
+ utilManager.parseYangFileInfoSet();
+
+ utilManager.createYangNodeSet();
+ provideTestJarFile();
+ utilManager.setYangFileInfoSet(removeFileInfoFromSet(utilManager.getYangFileInfoSet()));
+
+ for (String file : getListOfTestJar(TARGET)) {
+ addInterJarRootNodes(file);
+ }
+
+ utilManager.resolveDependenciesUsingLinker();
+
+ int size2 = utilManager.getYangFileInfoSet().size();
+ assertThat(true, is(size1 != size2));
+ assertThat(true, is(parseFileInfoSet(utilManager.getYangFileInfoSet().iterator())));
+
+ deleteDirectory(TARGET);
+ deleteTestSerFile();
+ }
+
+ /**
+ * Unit test case for a multiple jar dependency.
+ *
+ * @throws IOException when fails to do IO operations
+ * @throws MojoExecutionException when fails to do mojo operations
+ */
+ @Test
+ public void processMultipleJarLinking()
+ throws IOException, MojoExecutionException {
+
+ deleteDirectory(TARGET);
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(YANG_FILES_DIR)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
+
+ int size1 = utilManager.getYangFileInfoSet().size();
+ utilManager.parseYangFileInfoSet();
+
+ utilManager.createYangNodeSet();
+ provideTestJarFile();
+ utilManager.setYangFileInfoSet(removeFileInfoFromSet(utilManager.getYangFileInfoSet()));
+ for (String file : getListOfTestJar(TARGET)) {
+ addInterJarRootNodes(file);
+ }
+
+ utilManager.resolveDependenciesUsingLinker();
+ int size2 = utilManager.getYangFileInfoSet().size();
+ assertThat(true, is(size1 != size2));
+ assertThat(true, is(parseFileInfoSet(utilManager.getYangFileInfoSet().iterator())));
+ assertThat(true, is(parseFileInfoSet(utilManager.getYangFileInfoSet().iterator())));
+
+ /*
+ * grouping flow-classifier {
+ * container flow-classifier {
+ * leaf id {
+ * type flow-classifier-id;
+ * }
+ *
+ * leaf tenant-id {
+ * type port-pair:tenant-id;
+ * }
+ * .
+ * .
+ * .
+ *
+ */
+
+ Iterator<YangFileInfo> yangFileInfoIterator = utilManager.getYangFileInfoSet().iterator();
+
+ YangFileInfo yangFileInfo = yangFileInfoIterator.next();
+
+ while (yangFileInfoIterator.hasNext()) {
+ if (yangFileInfo.getRootNode().getName().equals("flow-classifier")) {
+ break;
+ }
+ yangFileInfo = yangFileInfoIterator.next();
+ }
+
+ YangNode node = yangFileInfo.getRootNode();
+ node = node.getChild();
+ while (node != null) {
+ if (node instanceof YangGrouping) {
+ break;
+ }
+ node = node.getNextSibling();
+ }
+
+ node = node.getChild();
+ ListIterator<YangLeaf> leafIterator = ((YangContainer) node).getListOfLeaf().listIterator();
+ YangLeaf leafInfo = leafIterator.next();
+
+ assertThat(leafInfo.getName(), is("id"));
+ assertThat(leafInfo.getDataType().getDataTypeName(), is("flow-classifier-id"));
+ assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
+
+ leafInfo = leafIterator.next();
+
+ assertThat(leafInfo.getName(), is("tenant-id"));
+ assertThat(leafInfo.getDataType().getDataType(), is(DERIVED));
+
+ assertThat(true, is(((YangDerivedInfo<?>) leafInfo.getDataType()
+ .getDataTypeExtendedInfo()).getReferredTypeDef()
+ .getName().equals("tenant-id")));
+
+ assertThat(leafInfo.getDataType().getResolvableStatus(), is(RESOLVED));
+
+ YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) leafInfo.getDataType()
+ .getDataTypeExtendedInfo();
+
+ // Check for the effective built-in type.
+ assertThat(derivedInfo.getEffectiveBuiltInType(), is(STRING));
+
+ YangPluginConfig yangPluginConfig = new YangPluginConfig();
+ yangPluginConfig.setCodeGenDir(TARGET);
+
+ utilManager.translateToJava(yangPluginConfig);
+
+ testIfFlowClassifierFilesExists();
+ testIfPortPairFileDoesNotExist();
+ deleteDirectory(TARGET);
+ deleteTestSerFile();
+ }
/**
* Test if flow classifier code is generated.
@@ -192,8 +234,9 @@
* Tests if port pair code is not generated.
*/
private void testIfPortPairFileDoesNotExist() {
- File folder = new File(System.getProperty("user.dir") + SLASH + PORT_PAIR_FOLDER);
- assertThat(false, is(folder.exists()));
+ File folder = new File(System.getProperty("user.dir") +
+ SLASH + PORT_PAIR_FOLDER);
+ assertThat(true, is(folder.exists()));
}
/**
@@ -204,7 +247,8 @@
* @return updated file info set
*/
private Set<YangFileInfo> removeFileInfoFromSet(Set<YangFileInfo> fileInfoSet) {
- String portPairFile = System.getProperty("user.dir") + SLASH + YANG_FILES_DIR + "portpair.yang";
+ String portPairFile = System.getProperty("user.dir") + SLASH +
+ YANG_FILES_DIR + "portpair.yang";
for (YangFileInfo fileInfo : fileInfoSet) {
if (fileInfo.getYangFileName().equals(portPairFile)) {
fileInfoSet.remove(fileInfo);
@@ -215,6 +259,46 @@
}
/**
+ * Provides test jar files for linker.
+ *
+ * @throws IOException when fails to do IO operations
+ */
+ private void provideTestJarFile() throws IOException {
+ serializeDataModel();
+ createTestJar();
+ }
+
+ /**
+ * Serializes data-model.
+ *
+ * @throws IOException when fails to do IO operations
+ */
+ private void serializeDataModel() throws IOException {
+
+ String serFileDirPath = TARGET + DEFAULT_JAR_RES_PATH;
+ File dir = new File(serFileDirPath);
+ if (dir.exists()) {
+ dir.delete();
+ }
+ dir.mkdirs();
+ FileOutputStream fileOutputStream = new FileOutputStream
+ (serFileDirPath + YANG_META_DATA);
+ ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
+ objectOutputStream.writeObject(utilManager.getYangNodeSet());
+ objectOutputStream.close();
+ fileOutputStream.close();
+ }
+
+ /**
+ * Deletes serialized file.
+ */
+ private void deleteTestSerFile() {
+ File ser = new File(System.getProperty("user.dir") +
+ SLASH + YANG_FILES_DIR + SER_FILE_NAME);
+ ser.delete();
+ }
+
+ /**
* Parses file info list and returns true if file info list contains the serialized file info.
*
* @param yangFileInfoIterator file info list iterator
@@ -231,133 +315,81 @@
yangFileInfo = yangFileInfoIterator.next();
}
return false;
-
}
/**
- * Represents jar file provider for testing.
+ * Returns list of test jar files.
+ *
+ * @param searchdir search directory
+ * @return list of test jar files
*/
- private static class MockJarFileProvider {
+ private List<String> getListOfTestJar(String searchdir) {
+ List<String> jarFiles = new ArrayList<>();
- private static final String TARGET = "target/interJarFileLinking/";
- private static final String TARGET_RESOURCE_PATH = SLASH + TEMP + SLASH + YANG_RESOURCES + SLASH;
- private static final String JAR_FILE_NAME = "onlab-test-1.7.0-SNAPSHOT.jar";
- private static final String SER_FILE_NAME = "portPair.ser";
+ File directory = new File(searchdir + "/");
+ File[] files = directory.listFiles();
- /**
- * Creates an instance of jar file provider.
- */
- MockJarFileProvider() {
-
- }
-
- /**
- * Provides test jar files for linker.
- *
- * @throws IOException when fails to do IO operations
- */
- void provideTestJarFile(YangUtilManager utilManager) throws IOException {
-
- Set<YangFileInfo> info = utilManager.getYangFileInfoSet();
-
- Set<YangNode> compiledSchemas = new HashSet<>();
- for (YangFileInfo fileInfo : info) {
- compiledSchemas.add(fileInfo.getRootNode());
- }
-
- MavenProject project = new MavenProject();
- YangPluginUtils.serializeDataModel(TARGET, project, false);
- createTestJar();
-
- for (String file : getListOfTestJar(TARGET)) {
- addInterJarRootNodes(file, info);
+ for (File file : files) {
+ if (!file.isDirectory()) {
+ jarFiles.add(file.toString());
}
}
- /**
- * Deletes serialized file.
- */
- void deleteTestSerFile(String yangFileDir) {
- File ser = new File(System.getProperty("user.dir") + SLASH + yangFileDir +
- SLASH + SER_FILE_NAME);
- ser.delete();
- }
+ return jarFiles;
+ }
- /**
- * Returns list of test jar files.
- *
- * @param searchDir search directory
- * @return list of test jar files
- */
- private List<String> getListOfTestJar(String searchDir) {
- List<String> jarFiles = new ArrayList<>();
+ /**
+ * Adds data model nodes of jar to file info set.
+ *
+ * @param jarFile jar file name
+ * @throws IOException when fails to do IO operations
+ */
+ private void addInterJarRootNodes(String jarFile) throws IOException {
+ try {
+ List<YangNode> interJarResolvedNodes = parseJarFile(jarFile, TARGET);
- File directory = new File(searchDir + "/");
- File[] files = directory.listFiles();
-
- for (File file : files) {
- if (!file.isDirectory()) {
- jarFiles.add(file.toString());
- }
+ for (YangNode node : interJarResolvedNodes) {
+ YangFileInfo dependentFileInfo = new YangFileInfo();
+ node.setToTranslate(false);
+ dependentFileInfo.setRootNode(node);
+ dependentFileInfo.setForTranslator(false);
+ dependentFileInfo.setYangFileName(node.getName());
+ utilManager.getYangFileInfoSet().add(dependentFileInfo);
}
-
- return jarFiles;
- }
-
- /**
- * Adds data model nodes of jar to file info set.
- *
- * @param jarFile jar file name
- * @param info file info
- * @throws IOException when fails to do IO operations
- */
- private void addInterJarRootNodes(String jarFile, Set<YangFileInfo> info) throws IOException {
- try {
- List<YangNode> interJarResolvedNodes = parseJarFile(jarFile, TARGET);
-
- for (YangNode node : interJarResolvedNodes) {
- YangFileInfo dependentFileInfo = new YangFileInfo();
- node.setToTranslate(false);
- dependentFileInfo.setRootNode(node);
- dependentFileInfo.setForTranslator(false);
- dependentFileInfo.setYangFileName(node.getName());
- info.add(dependentFileInfo);
- }
- } catch (IOException e) {
- throw new IOException("failed to resolve in interjar scenario.");
- }
- }
-
- /**
- * Creates a temporary test jar files.
- */
- private void createTestJar() {
-
- File file = new File(TARGET + TARGET_RESOURCE_PATH);
- File[] files = file.listFiles();
- String[] source = new String[files.length];
-
- for (int i = 0; i < files.length; i++) {
- source[i] = files[i].toString();
- }
- byte[] buf = new byte[1024];
-
- try {
- String target = TARGET + JAR_FILE_NAME;
- JarOutputStream out = new JarOutputStream(new FileOutputStream(target));
- for (String element : source) {
- FileInputStream in = new FileInputStream(element);
- out.putNextEntry(new JarEntry(element));
- int len;
- while ((len = in.read(buf)) > 0) {
- out.write(buf, 0, len);
- }
- out.closeEntry();
- in.close();
- }
- out.close();
- } catch (IOException e) {
- }
+ } catch (IOException e) {
+ throw new IOException("failed to resolve in interjar scenario.");
}
}
-}
+
+ /**
+ * Creates a temporary test jar files.
+ */
+ private void createTestJar() {
+
+ File file = new File(TARGET + TARGET_RESOURCE_PATH);
+ File[] files = file.listFiles();
+ String[] source = new String[files.length];
+
+ for (int i = 0; i < files.length; i++) {
+ source[i] = files[i].toString();
+ }
+ byte[] buf = new byte[1024];
+
+ try {
+ String target = TARGET + JAR_FILE_NAME;
+ JarOutputStream out = new JarOutputStream(new FileOutputStream(target));
+ for (String element : source) {
+ FileInputStream in = new FileInputStream(element);
+ out.putNextEntry(new JarEntry(element));
+ int len;
+ while ((len = in.read(buf)) > 0) {
+ out.write(buf, 0, len);
+ }
+ out.closeEntry();
+ in.close();
+ }
+ out.close();
+ } catch (IOException e) {
+ }
+ }
+}
\ No newline at end of file
diff --git a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/IntraFileLeafrefLinkingTest.java b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/IntraFileLeafrefLinkingTest.java
index ce9f13d..906fcb2 100644
--- a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/IntraFileLeafrefLinkingTest.java
+++ b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/IntraFileLeafrefLinkingTest.java
@@ -43,20 +43,25 @@
import org.onosproject.yang.compiler.linker.exceptions.LinkerException;
import org.onosproject.yang.compiler.linker.impl.YangLinkerManager;
import org.onosproject.yang.compiler.linker.impl.YangLinkerUtils;
-import org.onosproject.yang.compiler.utils.io.impl.YangFileScanner;
import org.onosproject.yang.compiler.parser.exceptions.ParserException;
import org.onosproject.yang.compiler.parser.impl.YangUtilsParserManager;
+import org.onosproject.yang.compiler.tool.impl.YangCompilerManager;
import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
+import java.util.Set;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNull.nullValue;
import static org.onosproject.yang.compiler.datamodel.YangNodeType.MODULE_NODE;
import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes.LEAFREF;
+import static org.onosproject.yang.compiler.utils.io.impl.YangFileScanner.getYangFiles;
/**
* Test cases for testing leafref intra file linking.
@@ -66,7 +71,9 @@
@Rule
public ExpectedException thrown = ExpectedException.none();
- private final YangUtilManager utilManager = new YangUtilManager();
+
+ private final YangCompilerManager utilManager =
+ new YangCompilerManager();
private final YangLinkerManager yangLinkerManager = new YangLinkerManager();
private final YangUtilsParserManager manager = new YangUtilsParserManager();
@@ -78,7 +85,13 @@
throws IOException, ParserException {
String searchDir = "src/test/resources/leafreflinker/intrafile/simpleleafref";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
YangNode selfNode = null;
@@ -141,7 +154,13 @@
throws IOException, ParserException {
String searchDir = "src/test/resources/leafreflinker/intrafile/leafrefwithrpc";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
YangNode selfNode = null;
@@ -206,7 +225,13 @@
throws IOException, ParserException {
String searchDir = "src/test/resources/leafreflinker/intrafile/leafrefwithrpcandgrouping";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
YangNode selfNode = null;
@@ -274,7 +299,13 @@
"YANG file error: The target node, in the leafref path /networks/network-id, is invalid.");
*/
String searchDir = "src/test/resources/leafreflinker/intrafile/invalidscenerioforgrouping";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
@@ -315,7 +346,13 @@
thrown.expectMessage(
"YANG file error: Unable to find base leaf/leaf-list for given leafref path /define/network-id");
String searchDir = "src/test/resources/leafreflinker/intrafile/invalidsceneriowithinvalidnode";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
@@ -340,7 +377,13 @@
throws IOException, ParserException {
String searchDir = "src/test/resources/leafreflinker/intrafile/leafreflinking";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
YangNode selfNode = null;
@@ -404,7 +447,13 @@
throws IOException, ParserException {
String searchDir = "src/test/resources/leafreflinker/intrafile/leafrefreferingtoleaflist";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
YangNode selfNode = null;
@@ -467,7 +516,13 @@
throws IOException, ParserException {
String searchDir = "src/test/resources/leafreflinker/intrafile/leafreftoinputinrpc";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
YangNode selfNode = null;
@@ -528,7 +583,13 @@
throws IOException, ParserException {
String searchDir = "src/test/resources/leafreflinker/intrafile/leafrefwithrefleafderived";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
YangNode selfNode = null;
@@ -593,7 +654,13 @@
thrown.expectMessage(
"YANG file error: Unable to find base leaf/leaf-list for given leafref path /networks");
String searchDir = "src/test/resources/leafreflinker/intrafile/invalidsceneriowithnorefleaf";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
@@ -616,7 +683,13 @@
public void processSelfResolutionWhenLeafrefInTypedefReferToContainer()
throws IOException, ParserException {
String searchDir = "src/test/resources/leafreflinker/intrafile/leafrefintypedef";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
YangNode selfNode = null;
@@ -677,7 +750,13 @@
throws IOException, ParserException {
String searchDir = "src/test/resources/leafreflinker/intrafile/leafreftorpcinputleaflist";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
YangNode selfNode = null;
@@ -740,7 +819,13 @@
throws IOException, ParserException {
String searchDir = "src/test/resources/leafreflinker/intrafile/leafreftoleafrefwithtypedef";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
YangNode selfNode = null;
@@ -803,7 +888,13 @@
throws IOException, ParserException {
String searchDir = "src/test/resources/leafreflinker/intrafile/leafreftoleafref";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
YangNode selfNode = null;
@@ -863,7 +954,13 @@
throws IOException, ParserException {
String searchDir = "src/test/resources/leafreflinker/intrafile/leafreftomultileafref";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
YangNode selfNode = null;
@@ -926,7 +1023,13 @@
throws IOException, ParserException {
String searchDir = "src/test/resources/leafreflinker/intrafile/leafreftoderivedtype";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
YangNode selfNode = null;
@@ -986,7 +1089,13 @@
throws IOException, ParserException {
String searchDir = "src/test/resources/leafreflinker/intrafile/leafreftomultitypedef";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
YangNode selfNode = null;
@@ -1049,7 +1158,13 @@
throws IOException, ParserException {
String searchDir = "src/test/resources/leafreflinker/intrafile/leafreftotypedefwithleafref";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
YangNode selfNode = null;
@@ -1111,7 +1226,13 @@
throws IOException, ParserException {
String searchDir = "src/test/resources/leafreflinker/intrafile/relativepath/simpleleafref";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
YangNode selfNode = null;
@@ -1173,7 +1294,13 @@
throws IOException, ParserException {
String searchDir = "src/test/resources/leafreflinker/intrafile/relativepath/leafreftoinputwithgroupinginrpc";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
YangNode selfNode = null;
@@ -1237,7 +1364,13 @@
thrown.expectMessage(
"YANG file error: The target node, in the leafref path ../../../define/network-id, is invalid.");
String searchDir = "src/test/resources/leafreflinker/intrafile/relativepath/invalidrelativeancestoraccess";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
@@ -1261,12 +1394,17 @@
public void processSelfResolutionWhenLeafrefInModuleReferToInvalidNodeRelPath()
throws IOException, ParserException {
-
thrown.expect(LinkerException.class);
thrown.expectMessage(
"YANG file error: Unable to find base leaf/leaf-list for given leafref path ../define/network-id");
String searchDir = "src/test/resources/leafreflinker/intrafile/relativepath/invalidnode";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
@@ -1290,7 +1428,13 @@
throws IOException, ParserException {
String searchDir = "src/test/resources/leafreflinker/intrafile/relativepath/leafrefintypedef";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
YangNode selfNode = null;
@@ -1350,7 +1494,13 @@
throws IOException, ParserException {
String searchDir = "src/test/resources/leafreflinker/intrafile/relativepath/leafreftomultileafref";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
YangNode selfNode = null;
@@ -1413,7 +1563,13 @@
throws IOException, ParserException {
String searchDir = "src/test/resources/leafreflinker/intrafile/relativepath/leafreftotypedef";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
YangNode selfNode = null;
@@ -1475,7 +1631,13 @@
throws IOException, ParserException {
String searchDir = "src/test/resources/leafreflinker/intrafile/relativepath/pathlistener";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
YangNode selfNode = null;
@@ -1573,7 +1735,13 @@
String searchDir = "src/test/resources/leafreflinker/interfile" +
"/interfileleafrefreferstomultipleleafrefinmultiplefiles";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
YangNode refNode1 = null;
@@ -1637,7 +1805,13 @@
throws IOException, ParserException {
String searchDir = "src/test/resources/leafreflinker/iffeatuinleafref/simpleleafrefwithiffeature";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
YangNode selfNode = null;
@@ -1707,7 +1881,13 @@
throws IOException, ParserException {
String searchDir = "src/test/resources/leafreflinker/iffeatuinleafref/featurebymultileafref";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
YangNode selfNode = null;
@@ -1783,7 +1963,13 @@
throws IOException, ParserException {
String searchDir = "src/test/resources/leafreflinker/intrafile/leafrefInAugment";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
YangNode selfNode = null;
@@ -1850,7 +2036,13 @@
throws IOException, ParserException {
String searchDir = "src/test/resources/leafreflinker/intrafile/leafrefinusesundergrouping";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
YangNode selfNode = null;
@@ -1928,7 +2120,13 @@
throws IOException, ParserException {
String searchDir = "src/test/resources/leafreflinker/intrafile/leafrefintypedefwithsamereferpath";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
YangNode selfNode = null;
diff --git a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/PathPredicateLinkingTest.java b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/PathPredicateLinkingTest.java
index 5f6f15b..6f82293 100644
--- a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/PathPredicateLinkingTest.java
+++ b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/PathPredicateLinkingTest.java
@@ -31,21 +31,27 @@
import org.onosproject.yang.compiler.linker.exceptions.LinkerException;
import org.onosproject.yang.compiler.linker.impl.YangLinkerManager;
import org.onosproject.yang.compiler.linker.impl.YangLinkerUtils;
-import org.onosproject.yang.compiler.utils.io.impl.YangFileScanner;
+import org.onosproject.yang.compiler.tool.impl.YangCompilerManager;
import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.ListIterator;
+import java.util.Set;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
+import static org.onosproject.yang.compiler.utils.io.impl.YangFileScanner.getYangFiles;
/**
* Test cases for path predicate linking in leaf-ref.
*/
public class PathPredicateLinkingTest {
- private final YangUtilManager utilMgr = new YangUtilManager();
+ private final YangCompilerManager utilMgr =
+ new YangCompilerManager();
private final YangLinkerManager linkerMgr = new YangLinkerManager();
@Rule
@@ -70,7 +76,12 @@
public void processSimplePathPredicate() throws IOException {
String searchDir = "src/test/resources/pathpredicate/simple";
- utilMgr.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilMgr.createYangFileInfoSet(paths);
utilMgr.parseYangFileInfoSet();
utilMgr.createYangNodeSet();
YangNode selfNode;
@@ -134,7 +145,12 @@
public void processSimpleInterFilePathPredicate() throws IOException {
String searchDir = "src/test/resources/pathpredicate/simpleinterfile";
- utilMgr.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilMgr.createYangFileInfoSet(paths);
utilMgr.parseYangFileInfoSet();
utilMgr.createYangNodeSet();
YangModule selfNode;
@@ -207,7 +223,12 @@
public void processInterFilePathPredicateFromAugment() throws IOException {
String searchDir = "src/test/resources/pathpredicate/interfileaugment";
- utilMgr.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilMgr.createYangFileInfoSet(paths);
utilMgr.parseYangFileInfoSet();
utilMgr.createYangNodeSet();
YangModule selfNode;
@@ -289,7 +310,12 @@
"/address/ip");
String searchDir = "src/test/resources/pathpredicate/invalidlinking";
- utilMgr.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilMgr.createYangFileInfoSet(paths);
utilMgr.parseYangFileInfoSet();
utilMgr.createYangNodeSet();
@@ -317,7 +343,12 @@
"[ifname = current()/../ifname]/ifname");
String searchDir = "src/test/resources/pathpredicate/invalidlinking2";
- utilMgr.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilMgr.createYangFileInfoSet(paths);
utilMgr.parseYangFileInfoSet();
utilMgr.createYangNodeSet();
YangNode selfNode;
@@ -346,7 +377,12 @@
"../../address/ifname]/address/ip");
String searchDir = "src/test/resources/pathpredicate/invalidlinking3";
- utilMgr.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilMgr.createYangFileInfoSet(paths);
utilMgr.parseYangFileInfoSet();
utilMgr.createYangNodeSet();
diff --git a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/ProcessSubTreeCodeGenTest.java b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/ProcessSubTreeCodeGenTest.java
index fcc5545..2ad4cc8 100644
--- a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/ProcessSubTreeCodeGenTest.java
+++ b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/ProcessSubTreeCodeGenTest.java
@@ -18,20 +18,27 @@
import org.apache.maven.plugin.MojoExecutionException;
import org.junit.Test;
-import org.onosproject.yang.compiler.utils.io.YangPluginConfig;
-import org.onosproject.yang.compiler.utils.io.impl.YangFileScanner;
-import org.onosproject.yang.compiler.utils.io.impl.YangIoUtils;
import org.onosproject.yang.compiler.parser.exceptions.ParserException;
+import org.onosproject.yang.compiler.tool.impl.YangCompilerManager;
+import org.onosproject.yang.compiler.utils.io.YangPluginConfig;
+import org.onosproject.yang.compiler.utils.io.impl.YangIoUtils;
import java.io.File;
import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.HashSet;
+import java.util.Set;
+
+import static org.onosproject.yang.compiler.utils.io.impl.YangFileScanner.getYangFiles;
/**
* Unit test case for process sub tree code generation test.
*/
public class ProcessSubTreeCodeGenTest {
- private final YangUtilManager utilManager = new YangUtilManager();
+ private final YangCompilerManager utilManager =
+ new YangCompilerManager();
private static final String DIR = "target/pstf/";
private static final String COMP = System.getProperty("user.dir") + File
.separator + DIR;
@@ -46,7 +53,13 @@
YangIoUtils.deleteDirectory(DIR);
String searchDir = "src/test/resources/pstcodegen";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
@@ -57,5 +70,4 @@
YangPluginConfig.compileCode(COMP);
YangIoUtils.deleteDirectory(DIR);
}
-
}
diff --git a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/RootClassGeneratorTest.java b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/RootClassGeneratorTest.java
index 2b01abe..0cca732 100644
--- a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/RootClassGeneratorTest.java
+++ b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/RootClassGeneratorTest.java
@@ -18,29 +18,41 @@
import org.apache.maven.plugin.MojoExecutionException;
import org.junit.Test;
-import org.onosproject.yang.compiler.utils.io.YangPluginConfig;
-import org.onosproject.yang.compiler.utils.io.impl.YangFileScanner;
-import org.onosproject.yang.compiler.utils.io.impl.YangIoUtils;
import org.onosproject.yang.compiler.parser.exceptions.ParserException;
+import org.onosproject.yang.compiler.tool.impl.YangCompilerManager;
+import org.onosproject.yang.compiler.utils.io.YangPluginConfig;
+import org.onosproject.yang.compiler.utils.io.impl.YangIoUtils;
import java.io.File;
import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.HashSet;
+import java.util.Set;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
+import static org.onosproject.yang.compiler.utils.io.impl.YangFileScanner.getYangFiles;
/**
* Unit test case for root node's code generation.
*/
public class RootClassGeneratorTest {
- private final YangUtilManager utilManager = new YangUtilManager();
+ private final YangCompilerManager utilManager =
+ new YangCompilerManager();
@Test
public void rootClassGenTest() throws IOException, ParserException, MojoExecutionException {
YangIoUtils.deleteDirectory("target/manager/");
String searchDir = "src/test/resources/manager/singleChild";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
@@ -66,7 +78,13 @@
public void rootClassGenwithoutRevTest() throws IOException, ParserException, MojoExecutionException {
YangIoUtils.deleteDirectory("target/manager/");
String searchDir = "src/test/resources/manager/genwithoutrev";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
@@ -87,7 +105,13 @@
public void rootClassMethodGenTest() throws IOException, ParserException, MojoExecutionException {
YangIoUtils.deleteDirectory("target/manager/");
String searchDir = "src/test/resources/manager/MultiChild";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
diff --git a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/SchemaNodeTest.java b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/SchemaNodeTest.java
index 3593398..b3a88f0 100644
--- a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/SchemaNodeTest.java
+++ b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/SchemaNodeTest.java
@@ -25,27 +25,33 @@
import org.onosproject.yang.compiler.datamodel.YangSchemaNodeContextInfo;
import org.onosproject.yang.compiler.datamodel.YangSchemaNodeIdentifier;
import org.onosproject.yang.compiler.datamodel.exceptions.DataModelException;
-import org.onosproject.yang.compiler.utils.io.YangPluginConfig;
-import org.onosproject.yang.compiler.utils.io.impl.YangFileScanner;
-import org.onosproject.yang.compiler.utils.io.impl.YangIoUtils;
import org.onosproject.yang.compiler.parser.exceptions.ParserException;
+import org.onosproject.yang.compiler.tool.impl.YangCompilerManager;
+import org.onosproject.yang.compiler.utils.io.YangPluginConfig;
+import org.onosproject.yang.compiler.utils.io.impl.YangIoUtils;
import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
+import static org.onosproject.yang.compiler.utils.io.impl.YangFileScanner.getYangFiles;
/**
* Test cases for testing YANG schema node.
*/
public class SchemaNodeTest {
- private final YangUtilManager utilManager = new YangUtilManager();
+ private final YangCompilerManager utilManager =
+ new YangCompilerManager();
/**
* Checks method to get schema node from map.
@@ -62,8 +68,12 @@
YangIoUtils.deleteDirectory("target/schemaMap/");
String searchDir = "src/test/resources/schemaMap";
- utilManager
- .createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
@@ -198,8 +208,12 @@
YangIoUtils.deleteDirectory("target/schemaMap/");
String searchDir = "src/test/resources/schemaMap";
- utilManager
- .createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
diff --git a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/TypeDefTranslatorTest.java b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/TypeDefTranslatorTest.java
index d45be4a..5cd1b15 100644
--- a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/TypeDefTranslatorTest.java
+++ b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/TypeDefTranslatorTest.java
@@ -18,20 +18,27 @@
import org.apache.maven.plugin.MojoExecutionException;
import org.junit.Test;
-import org.onosproject.yang.compiler.utils.io.YangPluginConfig;
-import org.onosproject.yang.compiler.utils.io.impl.YangFileScanner;
-import org.onosproject.yang.compiler.utils.io.impl.YangIoUtils;
import org.onosproject.yang.compiler.parser.exceptions.ParserException;
+import org.onosproject.yang.compiler.tool.impl.YangCompilerManager;
+import org.onosproject.yang.compiler.utils.io.YangPluginConfig;
+import org.onosproject.yang.compiler.utils.io.impl.YangIoUtils;
import java.io.File;
import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.HashSet;
+import java.util.Set;
+
+import static org.onosproject.yang.compiler.utils.io.impl.YangFileScanner.getYangFiles;
/**
* Unit test case for typedef translator.
*/
public class TypeDefTranslatorTest {
- private final YangUtilManager utilManager = new YangUtilManager();
+ private final YangCompilerManager utilManager =
+ new YangCompilerManager();
private static final String DIR = "target/typedefTranslator/";
private static final String DIR1 = System.getProperty("user.dir") + File
.separator + DIR;
@@ -47,7 +54,12 @@
YangIoUtils.deleteDirectory(DIR);
String searchDir = "src/test/resources/typedefTranslator/without";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
@@ -70,7 +82,12 @@
YangIoUtils.deleteDirectory(DIR);
String searchDir = "src/test/resources/typedefTranslator/with";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
@@ -80,7 +97,6 @@
utilManager.translateToJava(yangPluginConfig);
YangPluginConfig.compileCode(DIR1);
YangIoUtils.deleteDirectory(DIR);
-
}
/**
@@ -94,7 +110,12 @@
YangIoUtils.deleteDirectory(DIR);
String searchDir = "src/test/resources/typedefTranslator/union";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
diff --git a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/TypeLinkingAfterCloningTest.java b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/TypeLinkingAfterCloningTest.java
index 88937ae..3a10625 100644
--- a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/TypeLinkingAfterCloningTest.java
+++ b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/TypeLinkingAfterCloningTest.java
@@ -34,12 +34,16 @@
import org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes;
import org.onosproject.yang.compiler.linker.impl.YangLinkerManager;
import org.onosproject.yang.compiler.linker.impl.YangLinkerUtils;
-import org.onosproject.yang.compiler.utils.io.impl.YangFileScanner;
import org.onosproject.yang.compiler.parser.exceptions.ParserException;
+import org.onosproject.yang.compiler.tool.impl.YangCompilerManager;
import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.ListIterator;
+import java.util.Set;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
@@ -47,6 +51,7 @@
import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes.DERIVED;
import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes.IDENTITYREF;
import static org.onosproject.yang.compiler.datamodel.utils.builtindatatype.YangDataTypes.STRING;
+import static org.onosproject.yang.compiler.utils.io.impl.YangFileScanner.getYangFiles;
/**
* Test cases for type linking after cloning happens grouping.
@@ -74,8 +79,8 @@
private static final String BASE2 = "id1";
private static final String DIR =
"src/test/resources/typelinkingaftercloning/";
-
- private final YangUtilManager utilMgr = new YangUtilManager();
+ private final YangCompilerManager utilMgr =
+ new YangCompilerManager();
private final YangLinkerManager linkerMgr = new YangLinkerManager();
@Rule
@@ -155,7 +160,12 @@
@Test
public void processLeafRefAfterCloning() throws IOException {
- utilMgr.createYangFileInfoSet(YangFileScanner.getYangFiles(DIR + "leafref/intrafile"));
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(DIR + "leafref/intrafile")) {
+ paths.add(Paths.get(file));
+ }
+
+ utilMgr.createYangFileInfoSet(paths);
utilMgr.parseYangFileInfoSet();
utilMgr.createYangNodeSet();
YangNode selfNode;
@@ -249,11 +259,17 @@
*/
@Test
public void processInvalidLeafRef() throws IOException {
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(DIR + "leafref/invalid")) {
+ paths.add(Paths.get(file));
+ }
+
+ utilMgr.createYangFileInfoSet(paths);
thrown.expect(ParserException.class);
thrown.expectMessage("Union member type must not be one of the " +
"built-in types \"empty\" or " +
"\"leafref\"node-id_union");
- utilMgr.createYangFileInfoSet(YangFileScanner.getYangFiles(DIR + "leafref/invalid"));
utilMgr.parseYangFileInfoSet();
}
@@ -264,8 +280,12 @@
*/
@Test
public void processIdentityRefBeforeCloning() throws IOException {
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(DIR + "identityref")) {
+ paths.add(Paths.get(file));
+ }
- utilMgr.createYangFileInfoSet(YangFileScanner.getYangFiles(DIR + "identityref"));
+ utilMgr.createYangFileInfoSet(paths);
utilMgr.parseYangFileInfoSet();
utilMgr.createYangNodeSet();
YangNode selfNode;
@@ -389,7 +409,6 @@
assertThat(getInCrtLeafType(LEAF, NODE_ID),
idRef.getBaseIdentity().getName(),
is(FACILITY_SYS_LOG));
-
}
/**
@@ -399,8 +418,12 @@
*/
@Test
public void processUnionAfterCloning() throws IOException {
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(DIR + "union")) {
+ paths.add(Paths.get(file));
+ }
- utilMgr.createYangFileInfoSet(YangFileScanner.getYangFiles(DIR + "union"));
+ utilMgr.createYangFileInfoSet(paths);
utilMgr.parseYangFileInfoSet();
utilMgr.createYangNodeSet();
YangNode selfNode;
@@ -530,7 +553,6 @@
YangContainer container = (YangContainer) list.getChild()
.getNextSibling().getNextSibling();
-
Iterator<YangLeafList> leafListItr = container.getListOfLeafList()
.listIterator();
YangLeafList leafListInfo = leafListItr.next();
@@ -631,8 +653,12 @@
*/
@Test
public void processIdentityRefWithTypeDef() throws IOException {
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(DIR + "idreftypedef")) {
+ paths.add(Paths.get(file));
+ }
- utilMgr.createYangFileInfoSet(YangFileScanner.getYangFiles(DIR + "idreftypedef"));
+ utilMgr.createYangFileInfoSet(paths);
utilMgr.parseYangFileInfoSet();
utilMgr.createYangNodeSet();
YangNode selfNode;
@@ -741,8 +767,12 @@
*/
@Test
public void processIdentityRefInGrouping() throws IOException {
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(DIR + "idrefingrouping")) {
+ paths.add(Paths.get(file));
+ }
- utilMgr.createYangFileInfoSet(YangFileScanner.getYangFiles(DIR + "idrefingrouping"));
+ utilMgr.createYangFileInfoSet(paths);
utilMgr.parseYangFileInfoSet();
utilMgr.createYangNodeSet();
YangNode selfNode;
diff --git a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/UnionTranslatorTest.java b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/UnionTranslatorTest.java
index cf4fb1f..c4e9b4e 100644
--- a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/UnionTranslatorTest.java
+++ b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/UnionTranslatorTest.java
@@ -19,15 +19,21 @@
import org.apache.maven.plugin.MojoExecutionException;
import org.junit.Test;
import org.onosproject.yang.compiler.datamodel.YangNode;
-import org.onosproject.yang.compiler.translator.tojava.JavaCodeGeneratorUtil;
-import org.onosproject.yang.compiler.utils.io.YangPluginConfig;
-import org.onosproject.yang.compiler.utils.io.impl.YangFileScanner;
-import org.onosproject.yang.compiler.utils.io.impl.YangIoUtils;
import org.onosproject.yang.compiler.parser.exceptions.ParserException;
import org.onosproject.yang.compiler.parser.impl.YangUtilsParserManager;
+import org.onosproject.yang.compiler.tool.impl.YangCompilerManager;
+import org.onosproject.yang.compiler.translator.tojava.JavaCodeGeneratorUtil;
+import org.onosproject.yang.compiler.utils.io.YangPluginConfig;
+import org.onosproject.yang.compiler.utils.io.impl.YangIoUtils;
import java.io.File;
import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.HashSet;
+import java.util.Set;
+
+import static org.onosproject.yang.compiler.utils.io.impl.YangFileScanner.getYangFiles;
/**
* Unit tests for union translator.
@@ -39,6 +45,8 @@
private static final String DIR1 = System.getProperty("user.dir") + File
.separator + DIR;
+ YangCompilerManager utilManager = new YangCompilerManager();
+
/**
* Checks union translation should not result in any exception.
*/
@@ -66,8 +74,13 @@
public void processUnionIntUintConflictingTypes() throws IOException, MojoExecutionException {
YangIoUtils.deleteDirectory(DIR);
String searchDir = "src/test/resources/unionTranslator/intuint";
- YangUtilManager utilManager = new YangUtilManager();
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
@@ -91,8 +104,13 @@
MojoExecutionException {
YangIoUtils.deleteDirectory(DIR);
String searchDir = "src/test/resources/unionTranslator/uintint";
- YangUtilManager utilManager = new YangUtilManager();
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
@@ -116,8 +134,13 @@
MojoExecutionException {
YangIoUtils.deleteDirectory(DIR);
String searchDir = "src/test/resources/unionTranslator/longulong";
- YangUtilManager utilManager = new YangUtilManager();
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
@@ -141,8 +164,13 @@
MojoExecutionException {
YangIoUtils.deleteDirectory(DIR);
String searchDir = "src/test/resources/unionTranslator/ulonglong";
- YangUtilManager utilManager = new YangUtilManager();
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
@@ -166,8 +194,13 @@
MojoExecutionException {
YangIoUtils.deleteDirectory(DIR);
String searchDir = "src/test/resources/unionTranslator/intuintulonglong";
- YangUtilManager utilManager = new YangUtilManager();
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
@@ -191,8 +224,13 @@
MojoExecutionException {
YangIoUtils.deleteDirectory(DIR);
String searchDir = "src/test/resources/unionTranslator/intuintulonglongstring";
- YangUtilManager utilManager = new YangUtilManager();
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
@@ -216,8 +254,13 @@
MojoExecutionException {
YangIoUtils.deleteDirectory(DIR);
String searchDir = "src/test/resources/unionTranslator/intuintstring";
- YangUtilManager utilManager = new YangUtilManager();
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
@@ -241,8 +284,13 @@
MojoExecutionException {
YangIoUtils.deleteDirectory(DIR);
String searchDir = "src/test/resources/unionTranslator/unionwithbinary";
- YangUtilManager utilManager = new YangUtilManager();
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
diff --git a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/YangJavaModelUtilsTest.java b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/YangJavaModelUtilsTest.java
index 6612ab6..9b35c2c 100644
--- a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/YangJavaModelUtilsTest.java
+++ b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/YangJavaModelUtilsTest.java
@@ -21,12 +21,17 @@
import org.junit.Test;
import org.onosproject.yang.compiler.datamodel.YangNode;
import org.onosproject.yang.compiler.parser.exceptions.ParserException;
-import org.onosproject.yang.compiler.translator.tojava.YangJavaModelUtils;
-import org.onosproject.yang.compiler.utils.io.impl.YangFileScanner;
+import org.onosproject.yang.compiler.tool.impl.YangCompilerManager;
import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.HashSet;
+import java.util.Set;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.onosproject.yang.compiler.translator.tojava.YangJavaModelUtils.isRootNodesCodeGenRequired;
+import static org.onosproject.yang.compiler.utils.io.impl.YangFileScanner.getYangFiles;
/**
* Unit test case for java model utils.
@@ -34,23 +39,30 @@
public class YangJavaModelUtilsTest {
- private final YangUtilManager utilManager = new YangUtilManager();
+ private final YangCompilerManager utilManager =
+ new YangCompilerManager();
@Test
public void isRootNodeContainsOnlyAugmentTest() throws IOException,
ParserException, MojoExecutionException {
String searchDir = "src/test/resources/rootNode/onlyaugment";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
for (YangNode node : utilManager.getYangNodeSet()) {
if (node.getName().equals("test5")) {
- assertThat(true, Is.is(YangJavaModelUtils.isRootNodesCodeGenRequired(node)));
+ assertThat(true, Is.is(isRootNodesCodeGenRequired(node)));
}
if (node.getName().equals("test6")) {
- assertThat(true, Is.is(YangJavaModelUtils.isRootNodesCodeGenRequired(node)));
+ assertThat(true, Is.is(isRootNodesCodeGenRequired(node)));
}
}
}
@@ -59,14 +71,20 @@
public void isRootNodeCodeGenRequiredOnlyLeafTest() throws IOException
, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/rootNode/onlyleaf";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
for (YangNode node : utilManager.getYangNodeSet()) {
if (node.getName().equals("test5")) {
- assertThat(true, Is.is(YangJavaModelUtils.isRootNodesCodeGenRequired(node)));
+ assertThat(true, Is.is(isRootNodesCodeGenRequired(node)));
}
}
}
@@ -75,14 +93,20 @@
public void isRootNodeCodeGenRequiredOnlyLeafListTest() throws IOException
, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/rootNode/onlyleaflist";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
for (YangNode node : utilManager.getYangNodeSet()) {
if (node.getName().equals("test5")) {
- assertThat(true, Is.is(YangJavaModelUtils.isRootNodesCodeGenRequired(node)));
+ assertThat(true, Is.is(isRootNodesCodeGenRequired(node)));
}
}
}
@@ -91,17 +115,23 @@
public void isRootNodeCodeGenRequiredOnlyGroupingTest() throws IOException
, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/rootNode/onlygrouping";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
for (YangNode node : utilManager.getYangNodeSet()) {
if (node.getName().equals("test5")) {
- assertThat(false, Is.is(YangJavaModelUtils.isRootNodesCodeGenRequired(node)));
+ assertThat(false, Is.is(isRootNodesCodeGenRequired(node)));
}
if (node.getName().equals("test6")) {
- assertThat(false, Is.is(YangJavaModelUtils.isRootNodesCodeGenRequired(node)));
+ assertThat(false, Is.is(isRootNodesCodeGenRequired(node)));
}
}
}
@@ -111,17 +141,23 @@
public void isRootNodeCodeGenRequiredOnlyTypeDefTest() throws IOException
, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/rootNode/onlytypdef";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
for (YangNode node : utilManager.getYangNodeSet()) {
if (node.getName().equals("test5")) {
- assertThat(false, Is.is(YangJavaModelUtils.isRootNodesCodeGenRequired(node)));
+ assertThat(false, Is.is(isRootNodesCodeGenRequired(node)));
}
if (node.getName().equals("test6")) {
- assertThat(false, Is.is(YangJavaModelUtils.isRootNodesCodeGenRequired(node)));
+ assertThat(false, Is.is(isRootNodesCodeGenRequired(node)));
}
}
}
@@ -130,53 +166,68 @@
public void isRootNodeCodeGenRequiredNoGenTest() throws IOException
, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/rootNode/nogen";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
for (YangNode node : utilManager.getYangNodeSet()) {
if (node.getName().equals("test5")) {
- assertThat(false, Is.is(YangJavaModelUtils.isRootNodesCodeGenRequired(node)));
+ assertThat(false, Is.is(isRootNodesCodeGenRequired(node)));
}
}
-
}
@Test
public void isRootNodeCodeGenRequiredMixedTest() throws IOException
, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/rootNode/mixed";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
for (YangNode node : utilManager.getYangNodeSet()) {
if (node.getName().equals("test5")) {
- assertThat(true, Is.is(YangJavaModelUtils.isRootNodesCodeGenRequired(node)));
+ assertThat(true, Is.is(isRootNodesCodeGenRequired(node)));
}
if (node.getName().equals("test6")) {
- assertThat(true, Is.is(YangJavaModelUtils.isRootNodesCodeGenRequired(node)));
+ assertThat(true, Is.is(isRootNodesCodeGenRequired(node)));
}
}
-
}
@Test
public void isRootNodeCodeGenRequiredTypedefGroupingTest() throws IOException
, ParserException, MojoExecutionException {
String searchDir = "src/test/resources/rootNode/typedefgrouping";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
for (YangNode node : utilManager.getYangNodeSet()) {
if (node.getName().equals("test5")) {
- assertThat(false, Is.is(YangJavaModelUtils.isRootNodesCodeGenRequired(node)));
+ assertThat(false, Is.is(isRootNodesCodeGenRequired(node)));
}
}
-
}
}
diff --git a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/YangXpathLinkerTest.java b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/YangXpathLinkerTest.java
index 28c3db8..4919914 100644
--- a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/YangXpathLinkerTest.java
+++ b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/YangXpathLinkerTest.java
@@ -18,25 +18,30 @@
import org.apache.maven.plugin.MojoExecutionException;
import org.junit.Test;
-import org.onosproject.yang.compiler.datamodel.ResolvableType;
import org.onosproject.yang.compiler.datamodel.YangAugment;
import org.onosproject.yang.compiler.datamodel.YangNode;
import org.onosproject.yang.compiler.datamodel.YangReferenceResolver;
import org.onosproject.yang.compiler.datamodel.YangResolutionInfo;
-import org.onosproject.yang.compiler.linker.impl.XpathLinkingTypes;
import org.onosproject.yang.compiler.linker.impl.YangLinkerManager;
import org.onosproject.yang.compiler.linker.impl.YangLinkerUtils;
import org.onosproject.yang.compiler.linker.impl.YangXpathLinker;
+import org.onosproject.yang.compiler.tool.impl.YangCompilerManager;
import org.onosproject.yang.compiler.utils.io.YangPluginConfig;
-import org.onosproject.yang.compiler.utils.io.impl.YangFileScanner;
-import org.onosproject.yang.compiler.utils.io.impl.YangIoUtils;
import java.io.File;
import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
+import static org.onosproject.yang.compiler.datamodel.ResolvableType.YANG_AUGMENT;
+import static org.onosproject.yang.compiler.linker.impl.XpathLinkingTypes.AUGMENT_LINKING;
+import static org.onosproject.yang.compiler.utils.io.impl.YangFileScanner.getYangFiles;
+import static org.onosproject.yang.compiler.utils.io.impl.YangIoUtils.deleteDirectory;
/**
* Unit test cases for x-path linker.
@@ -46,7 +51,9 @@
private static final String INTRA_FILE_PATH = "src/test/resources/xPathLinker/IntraFile/";
private static final String INTER_FILE_PATH = "src/test/resources/xPathLinker/InterFile/";
private static final String CASE_FILE_PATH = "src/test/resources/xPathLinker/Case/";
- private YangUtilManager utilManager = new YangUtilManager();
+
+ private final YangCompilerManager utilManager =
+ new YangCompilerManager();
private YangXpathLinker<?> linker = new YangXpathLinker();
private YangLinkerManager linkerManager = new YangLinkerManager();
@@ -59,7 +66,12 @@
@Test
public void processIntraFileLinkingSingleLevel() throws IOException, MojoExecutionException {
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTRA_FILE_PATH + "IntraSingle/"));
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(INTRA_FILE_PATH + "IntraSingle/")) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
utilManager.resolveDependenciesUsingLinker();
@@ -69,14 +81,15 @@
for (YangNode node : utilManager.getYangNodeSet()) {
YangReferenceResolver ref = (YangReferenceResolver) node;
- List<YangResolutionInfo> infos = ref.getUnresolvedResolutionList(ResolvableType.YANG_AUGMENT);
+ List<YangResolutionInfo> infos = ref.getUnresolvedResolutionList(YANG_AUGMENT);
YangResolutionInfo info = infos.get(0);
- YangAugment augment = (YangAugment) info.getEntityToResolveInfo().getEntityToResolve();
- targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier()
+ YangAugment augment = (YangAugment) info
+ .getEntityToResolveInfo().getEntityToResolve();
+ targetNodeName = augment.getTargetNode().get(
+ augment.getTargetNode().size() - 1).getNodeIdentifier()
.getName();
targetNode = augment.getAugmentedNode();
-
}
assertThat(true, is(targetNode.getName().equals(targetNodeName)));
@@ -90,7 +103,12 @@
@Test
public void processIntraFileLinkingMultipleLevel() throws IOException {
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTRA_FILE_PATH + "IntraMulti/"));
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(INTRA_FILE_PATH + "IntraMulti/")) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
@@ -101,9 +119,11 @@
List<YangAugment> augments = linker.getListOfYangAugment(node);
for (YangAugment augment : augments) {
- targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier()
+ targetNodeName = augment.getTargetNode().get(
+ augment.getTargetNode().size() - 1).getNodeIdentifier()
.getName();
- targetNode = linker.processXpathLinking(augment.getTargetNode(), node, XpathLinkingTypes.AUGMENT_LINKING);
+ targetNode = linker.processXpathLinking(
+ augment.getTargetNode(), node, AUGMENT_LINKING);
}
}
@@ -117,7 +137,13 @@
*/
@Test
public void processIntraFileLinkingInAugmentSingleLevel() throws IOException {
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTRA_FILE_PATH + "IntraSingleAugment/"));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(INTRA_FILE_PATH + "IntraSingleAugment/")) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
@@ -128,9 +154,11 @@
List<YangAugment> augments = linker.getListOfYangAugment(node);
for (YangAugment augment : augments) {
- targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier()
+ targetNodeName = augment.getTargetNode().get(
+ augment.getTargetNode().size() - 1).getNodeIdentifier()
.getName();
- targetNode = linker.processXpathLinking(augment.getTargetNode(), node, XpathLinkingTypes.AUGMENT_LINKING);
+ targetNode = linker.processXpathLinking(augment.getTargetNode(),
+ node, AUGMENT_LINKING);
}
}
@@ -145,9 +173,13 @@
*/
@Test
public void processIntraFileMultiLevelWithoutPrefix() throws IOException {
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(INTRA_FILE_PATH +
+ "IntraMultiAugment/withoutprefix/")) {
+ paths.add(Paths.get(file));
+ }
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(
- INTRA_FILE_PATH + "IntraMultiAugment/withoutprefix"));
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
@@ -165,7 +197,7 @@
.get(augment.getTargetNode().size() - 1)
.getNodeIdentifier().getName();
target = linker.processXpathLinking(augment.getTargetNode(),
- node, XpathLinkingTypes.AUGMENT_LINKING);
+ node, AUGMENT_LINKING);
}
}
assertThat(true, is(target.getName().equals(name)));
@@ -179,9 +211,13 @@
*/
@Test
public void processIntraFileWithPrefix() throws IOException {
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(INTRA_FILE_PATH +
+ "IntraMultiAugment/withprefix/")) {
+ paths.add(Paths.get(file));
+ }
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(
- INTRA_FILE_PATH + "IntraMultiAugment/withprefix"));
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
@@ -199,11 +235,10 @@
.get(augment.getTargetNode().size() - 1)
.getNodeIdentifier().getName();
target = linker.processXpathLinking(augment.getTargetNode(),
- node, XpathLinkingTypes.AUGMENT_LINKING);
+ node, AUGMENT_LINKING);
}
}
assertThat(true, is(target.getName().equals(name)));
-
}
/**
@@ -214,9 +249,13 @@
*/
@Test
public void processIntraFileWithPartialPrefix() throws IOException {
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(INTRA_FILE_PATH +
+ "IntraMultiAugment/withpartialprefix/")) {
+ paths.add(Paths.get(file));
+ }
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(
- INTRA_FILE_PATH + "IntraMultiAugment/withpartialprefix"));
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
@@ -234,7 +273,7 @@
.get(augment.getTargetNode().size() - 1)
.getNodeIdentifier().getName();
target = linker.processXpathLinking(augment.getTargetNode(),
- node, XpathLinkingTypes.AUGMENT_LINKING);
+ node, AUGMENT_LINKING);
}
}
assertThat(true, is(target.getName().equals(name)));
@@ -247,7 +286,14 @@
*/
@Test
public void processIntraFileLinkingInSubModuleSingleLevel() throws IOException {
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTRA_FILE_PATH + "IntraSingleSubModule/"));
+
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(INTRA_FILE_PATH +
+ "IntraSingleSubModule/")) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
@@ -261,9 +307,11 @@
List<YangAugment> augments = linker.getListOfYangAugment(node);
for (YangAugment augment : augments) {
- targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier()
+ targetNodeName = augment.getTargetNode().get(
+ augment.getTargetNode().size() - 1).getNodeIdentifier()
.getName();
- targetNode = linker.processXpathLinking(augment.getTargetNode(), node, XpathLinkingTypes.AUGMENT_LINKING);
+ targetNode = linker.processXpathLinking
+ (augment.getTargetNode(), node, AUGMENT_LINKING);
}
}
@@ -277,8 +325,13 @@
*/
@Test
public void processIntraFileLinkingInSubModuleMultiLevel() throws IOException {
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(INTRA_FILE_PATH +
+ "IntraMultiSubModule/")) {
+ paths.add(Paths.get(file));
+ }
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTRA_FILE_PATH + "IntraMultiSubModule/"));
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
@@ -292,9 +345,11 @@
List<YangAugment> augments = linker.getListOfYangAugment(node);
for (YangAugment augment : augments) {
- targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier()
+ targetNodeName = augment.getTargetNode().get(
+ augment.getTargetNode().size() - 1).getNodeIdentifier()
.getName();
- targetNode = linker.processXpathLinking(augment.getTargetNode(), node, XpathLinkingTypes.AUGMENT_LINKING);
+ targetNode = linker.processXpathLinking(
+ augment.getTargetNode(), node, AUGMENT_LINKING);
}
}
@@ -308,8 +363,13 @@
*/
@Test
public void processIntraFileLinkingInUsesSingleLevel() throws IOException {
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(INTRA_FILE_PATH +
+ "IntraSingleUses/")) {
+ paths.add(Paths.get(file));
+ }
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTRA_FILE_PATH + "IntraSingleUses/"));
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
@@ -323,9 +383,11 @@
List<YangAugment> augments = linker.getListOfYangAugment(node);
for (YangAugment augment : augments) {
- targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier()
+ targetNodeName = augment.getTargetNode().get(
+ augment.getTargetNode().size() - 1).getNodeIdentifier()
.getName();
- targetNode = linker.processXpathLinking(augment.getTargetNode(), node, XpathLinkingTypes.AUGMENT_LINKING);
+ targetNode = linker.processXpathLinking(
+ augment.getTargetNode(), node, AUGMENT_LINKING);
}
}
@@ -339,8 +401,13 @@
*/
@Test
public void processIntraFileLinkingInUsesMultiLevel() throws IOException {
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(INTRA_FILE_PATH +
+ "IntraMultiUses/")) {
+ paths.add(Paths.get(file));
+ }
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTRA_FILE_PATH + "IntraMultiUses/"));
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
@@ -354,9 +421,11 @@
List<YangAugment> augments = linker.getListOfYangAugment(node);
for (YangAugment augment : augments) {
- targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier()
+ targetNodeName = augment.getTargetNode().get(
+ augment.getTargetNode().size() - 1).getNodeIdentifier()
.getName();
- targetNode = linker.processXpathLinking(augment.getTargetNode(), node, XpathLinkingTypes.AUGMENT_LINKING);
+ targetNode = linker.processXpathLinking(
+ augment.getTargetNode(), node, AUGMENT_LINKING);
}
}
@@ -370,8 +439,13 @@
*/
@Test
public void processInterFileLinkingSingleLevel() throws IOException {
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(INTER_FILE_PATH +
+ "InterSingle/")) {
+ paths.add(Paths.get(file));
+ }
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterSingle/"));
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
@@ -384,9 +458,11 @@
List<YangAugment> augments = linker.getListOfYangAugment(node);
for (YangAugment augment : augments) {
- targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier()
+ targetNodeName = augment.getTargetNode().get(
+ augment.getTargetNode().size() - 1).getNodeIdentifier()
.getName();
- targetNode = linker.processXpathLinking(augment.getTargetNode(), node, XpathLinkingTypes.AUGMENT_LINKING);
+ targetNode = linker.processXpathLinking(
+ augment.getTargetNode(), node, AUGMENT_LINKING);
}
}
@@ -400,8 +476,13 @@
*/
@Test
public void processInterFileLinkingMultipleLevel() throws IOException {
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(INTER_FILE_PATH +
+ "InterMulti/")) {
+ paths.add(Paths.get(file));
+ }
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterMulti/"));
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
@@ -414,9 +495,11 @@
List<YangAugment> augments = linker.getListOfYangAugment(node);
for (YangAugment augment : augments) {
- targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier()
+ targetNodeName = augment.getTargetNode().get(
+ augment.getTargetNode().size() - 1).getNodeIdentifier()
.getName();
- targetNode = linker.processXpathLinking(augment.getTargetNode(), node, XpathLinkingTypes.AUGMENT_LINKING);
+ targetNode = linker.processXpathLinking(
+ augment.getTargetNode(), node, AUGMENT_LINKING);
}
}
@@ -430,8 +513,13 @@
*/
@Test
public void processInterFileLinkingInAugmentSingleLevel() throws IOException {
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(INTER_FILE_PATH +
+ "InterSingleAugment/")) {
+ paths.add(Paths.get(file));
+ }
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterSingleAugment/"));
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
@@ -444,9 +532,11 @@
List<YangAugment> augments = linker.getListOfYangAugment(node);
for (YangAugment augment : augments) {
- targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier()
+ targetNodeName = augment.getTargetNode().get(
+ augment.getTargetNode().size() - 1).getNodeIdentifier()
.getName();
- targetNode = linker.processXpathLinking(augment.getTargetNode(), node, XpathLinkingTypes.AUGMENT_LINKING);
+ targetNode = linker.processXpathLinking(
+ augment.getTargetNode(), node, AUGMENT_LINKING);
}
}
@@ -460,8 +550,13 @@
*/
@Test
public void processInterFileLinkingInAugmentMultiLevel() throws IOException {
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(INTER_FILE_PATH +
+ "InterMultiAugment/")) {
+ paths.add(Paths.get(file));
+ }
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterMultiAugment/"));
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
@@ -474,9 +569,11 @@
List<YangAugment> augments = linker.getListOfYangAugment(node);
for (YangAugment augment : augments) {
- targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier()
+ targetNodeName = augment.getTargetNode().get(
+ augment.getTargetNode().size() - 1).getNodeIdentifier()
.getName();
- targetNode = linker.processXpathLinking(augment.getTargetNode(), node, XpathLinkingTypes.AUGMENT_LINKING);
+ targetNode = linker.processXpathLinking(
+ augment.getTargetNode(), node, AUGMENT_LINKING);
}
}
@@ -490,8 +587,13 @@
*/
@Test
public void processMultiInterFileLinkingInAugmentSingleLevel() throws IOException {
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(INTER_FILE_PATH +
+ "InterMultiFileAugment/")) {
+ paths.add(Paths.get(file));
+ }
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterMultiFileAugment/"));
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
@@ -504,9 +606,11 @@
List<YangAugment> augments = linker.getListOfYangAugment(node);
for (YangAugment augment : augments) {
- targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier()
+ targetNodeName = augment.getTargetNode().get(
+ augment.getTargetNode().size() - 1).getNodeIdentifier()
.getName();
- targetNode = linker.processXpathLinking(augment.getTargetNode(), node, XpathLinkingTypes.AUGMENT_LINKING);
+ targetNode = linker.processXpathLinking(
+ augment.getTargetNode(), node, AUGMENT_LINKING);
}
}
@@ -520,9 +624,13 @@
*/
@Test
public void processMultiInterFileLinkingInAugmentMultiLevel() throws IOException {
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(INTER_FILE_PATH +
+ "InterMultiFileAugmentMulti/")) {
+ paths.add(Paths.get(file));
+ }
- utilManager
- .createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterMultiFileAugmentMulti/"));
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
@@ -539,7 +647,8 @@
List<YangAugment> augments = linker.getListOfYangAugment(node);
for (YangAugment augment : augments) {
- targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier()
+ targetNodeName = augment.getTargetNode().get(
+ augment.getTargetNode().size() - 1).getNodeIdentifier()
.getName();
targetNode = augment.getAugmentedNode();
}
@@ -555,8 +664,13 @@
*/
@Test
public void processInterFileLinkingInSubModuleSingleLevel() throws IOException {
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(INTER_FILE_PATH +
+ "InterSingleSubModule/")) {
+ paths.add(Paths.get(file));
+ }
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterSingleSubModule/"));
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
@@ -572,7 +686,8 @@
List<YangAugment> augments = linker.getListOfYangAugment(node);
for (YangAugment augment : augments) {
- targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier()
+ targetNodeName = augment.getTargetNode().get(
+ augment.getTargetNode().size() - 1).getNodeIdentifier()
.getName();
targetNode = augment.getAugmentedNode();
}
@@ -588,8 +703,13 @@
*/
@Test
public void processInterFileLinkingInSubModuleMultiLevel() throws IOException {
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(INTER_FILE_PATH +
+ "InterMultiSubModule/")) {
+ paths.add(Paths.get(file));
+ }
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterMultiSubModule/"));
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
@@ -605,7 +725,8 @@
List<YangAugment> augments = linker.getListOfYangAugment(node);
for (YangAugment augment : augments) {
- targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier()
+ targetNodeName = augment.getTargetNode().get(
+ augment.getTargetNode().size() - 1).getNodeIdentifier()
.getName();
targetNode = augment.getAugmentedNode();
}
@@ -621,8 +742,13 @@
*/
@Test
public void processInterFileLinkingInUsesInAugment() throws IOException {
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(INTER_FILE_PATH +
+ "InterSingleUses/")) {
+ paths.add(Paths.get(file));
+ }
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterSingleUses/"));
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
@@ -639,14 +765,14 @@
List<YangAugment> augments = linker.getListOfYangAugment(node);
for (YangAugment augment : augments) {
- targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1)
+ targetNodeName = augment.getTargetNode().get(
+ augment.getTargetNode().size() - 1)
.getNodeIdentifier().getName();
targetNode = augment.getAugmentedNode();
}
}
assertThat(true, is(targetNode.getName().equals(targetNodeName)));
-
}
/**
@@ -656,8 +782,13 @@
*/
@Test
public void processInterFileLinkingInUsesMultiLevel() throws IOException {
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(INTER_FILE_PATH +
+ "InterMultiUses/")) {
+ paths.add(Paths.get(file));
+ }
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(INTER_FILE_PATH + "InterMultiUses/"));
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
@@ -673,9 +804,11 @@
List<YangAugment> augments = linker.getListOfYangAugment(node);
for (YangAugment augment : augments) {
- targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1).getNodeIdentifier()
+ targetNodeName = augment.getTargetNode().get(
+ augment.getTargetNode().size() - 1).getNodeIdentifier()
.getName();
- targetNode = linker.processXpathLinking(augment.getTargetNode(), node, XpathLinkingTypes.AUGMENT_LINKING);
+ targetNode = linker.processXpathLinking(
+ augment.getTargetNode(), node, AUGMENT_LINKING);
}
}
@@ -689,8 +822,13 @@
*/
@Test
public void processInterFileLinkingInMultipleSubmodules() throws IOException {
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(CASE_FILE_PATH +
+ "submodule/")) {
+ paths.add(Paths.get(file));
+ }
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(CASE_FILE_PATH + "submodule/"));
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
@@ -708,14 +846,14 @@
List<YangAugment> augments = linker.getListOfYangAugment(node);
for (YangAugment augment : augments) {
- targetNodeName = augment.getTargetNode().get(augment.getTargetNode().size() - 1)
+ targetNodeName = augment.getTargetNode().get(
+ augment.getTargetNode().size() - 1)
.getNodeIdentifier().getName();
targetNode = augment.getAugmentedNode();
}
}
assertThat(true, is(targetNode.getName().equals(targetNodeName)));
-
}
/**
@@ -725,9 +863,14 @@
*/
@Test
public void processInterFileLinkingInMultipleUses() throws IOException {
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(CASE_FILE_PATH +
+ "uses/")) {
+ paths.add(Paths.get(file));
+ }
- YangIoUtils.deleteDirectory("target/xpath/");
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(CASE_FILE_PATH + "uses/"));
+ utilManager.createYangFileInfoSet(paths);
+ deleteDirectory("target/xpath/");
utilManager.parseYangFileInfoSet();
utilManager.createYangNodeSet();
linkerManager.createYangNodeSet(utilManager.getYangNodeSet());
@@ -755,7 +898,7 @@
utilManager.translateToJava(yangPluginConfig);
String dir = System.getProperty("user.dir") + File.separator + "target/xpath/";
YangPluginConfig.compileCode(dir);
- YangIoUtils.deleteDirectory("target/xpath/");
+ deleteDirectory("target/xpath/");
assertThat(true, is(targetNode.getName().equals(targetNodeName)));
}
}
diff --git a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/ietfyang/IetfYangFileTest.java b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/ietfyang/IetfYangFileTest.java
index 82de4c5..d0eab39 100644
--- a/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/ietfyang/IetfYangFileTest.java
+++ b/compiler/plugin/maven/src/test/java/org/onosproject/yang/compiler/plugin/maven/ietfyang/IetfYangFileTest.java
@@ -18,21 +18,26 @@
import org.apache.maven.plugin.MojoExecutionException;
import org.junit.Test;
-import org.onosproject.yang.compiler.utils.io.YangPluginConfig;
-import org.onosproject.yang.compiler.utils.io.impl.YangFileScanner;
-import org.onosproject.yang.compiler.utils.io.impl.YangIoUtils;
import org.onosproject.yang.compiler.parser.exceptions.ParserException;
-import org.onosproject.yang.compiler.plugin.maven.YangUtilManager;
+import org.onosproject.yang.compiler.tool.impl.YangCompilerManager;
+import org.onosproject.yang.compiler.utils.io.YangPluginConfig;
+import org.onosproject.yang.compiler.utils.io.impl.YangIoUtils;
import java.io.File;
import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.HashSet;
+import java.util.Set;
+
+import static org.onosproject.yang.compiler.utils.io.impl.YangFileScanner.getYangFiles;
/**
* Test cases for testing IETF YANG files.
*/
public class IetfYangFileTest {
- private final YangUtilManager utilManager = new YangUtilManager();
+ private final YangCompilerManager utilManager = new YangCompilerManager();
/**
* Checks hierarchical intra with inter file type linking.
@@ -45,7 +50,12 @@
String dir = "target/ietfyang/l3vpnservice/";
YangIoUtils.deleteDirectory(dir);
String searchDir = "src/test/resources/ietfyang/l3vpnservice";
- utilManager.createYangFileInfoSet(YangFileScanner.getYangFiles(searchDir));
+ Set<Path> paths = new HashSet<>();
+ for (String file : getYangFiles(searchDir)) {
+ paths.add(Paths.get(file));
+ }
+
+ utilManager.createYangFileInfoSet(paths);
utilManager.parseYangFileInfoSet();
utilManager.resolveDependenciesUsingLinker();
@@ -57,5 +67,4 @@
YangPluginConfig.compileCode(dir1);
YangIoUtils.deleteDirectory("target/ietfyang/");
}
-
}
diff --git a/compiler/plugin/pom.xml b/compiler/plugin/pom.xml
index fd23dfc..bcf0061 100644
--- a/compiler/plugin/pom.xml
+++ b/compiler/plugin/pom.xml
@@ -62,11 +62,6 @@
<artifactId>onos-yang-compiler-linker</artifactId>
<version>${project.version}</version>
</dependency>
- <dependency>
- <groupId>org.onosproject</groupId>
- <artifactId>onos-yang-compiler-datamodel</artifactId>
- <version>${project.version}</version>
- </dependency>
</dependencies>
</project>