Fixed Yin view for Yang file with imported modules. 80/37680/1
authorDavid M. Karr <davidmichaelkarr@gmail.com>
Fri, 15 Apr 2016 18:55:00 +0000 (11:55 -0700)
committerDavid M. Karr <davidmichaelkarr@gmail.com>
Fri, 15 Apr 2016 18:55:00 +0000 (11:55 -0700)
Change-Id: I5f4be3f14567c5616b6de28f89e0f9c847d77d57
Signed-off-by: David M. Karr <davidmichaelkarr@gmail.com>
plugins/com.cisco.yangide.ext.model.editor/pom.xml
plugins/com.cisco.yangide.ext.model.editor/src/main/java/com/cisco/yangide/ext/model/editor/YinBuilder.java
plugins/com.cisco.yangide.yangparser/.classpath
plugins/com.cisco.yangide.yangparser/META-INF/MANIFEST.MF
plugins/com.cisco.yangide.yangparser/build.properties
plugins/com.cisco.yangide.yangparser/pom.xml

index ddd129b42179a3be854d4036e15dcb562e43c1bc..75f3bdc64f8d6f878ff8b7f60e69231000a17041 100644 (file)
             <version>3.4.0</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>com.google.guava</groupId>
+            <artifactId>guava</artifactId>
+            <version>18.0</version>
+            <scope>test</scope>
+        </dependency>
        </dependencies>
 </project>
index 90589a163aa7bafb4d60ed5642b4e716220cdb8d..ab6306cb4e7336312a0f27f8775a66533bc726c0 100644 (file)
@@ -7,6 +7,8 @@
  *******************************************************************************/
 package com.cisco.yangide.ext.model.editor;
 
+//import static com.cisco.yangide.core.model.YangModelManager.search;
+
 import java.io.IOException;
 import java.io.OutputStream;
 import java.util.ArrayList;
@@ -15,6 +17,7 @@ import java.util.List;
 import javax.xml.stream.XMLStreamException;
 
 import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.Path;
 import org.eclipse.ui.IFileEditorInput;
 import org.opendaylight.yangtools.yang.model.export.YinExportUtils;
 import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
@@ -23,8 +26,15 @@ import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
 import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
 import org.opendaylight.yangtools.yang.parser.repo.YangTextSchemaContextResolver;
 
+import com.cisco.yangide.core.YangCorePlugin;
+import com.cisco.yangide.core.YangModelException;
 import com.cisco.yangide.core.dom.ModuleImport;
 import com.cisco.yangide.core.dom.SubModuleInclude;
+import com.cisco.yangide.core.indexing.ElementIndexInfo;
+import com.cisco.yangide.core.indexing.ElementIndexType;
+import com.cisco.yangide.core.model.YangFile;
+import com.cisco.yangide.core.model.YangJarEntry;
+import com.cisco.yangide.core.model.YangModelManager;
 import com.cisco.yangide.core.parser.IYangValidationListener;
 import com.cisco.yangide.core.parser.YangParserUtil;
 import com.cisco.yangide.editor.editors.YangEditor;
@@ -63,20 +73,48 @@ public class YinBuilder {
         // YMPE doesn't run this job if the synchronizer says the source is invalid.
         if (module == null || (errorCountHolder.value > 0))
             return;
+
+        // Now have to register the source contents for all the referenced files.  The
+        // easy one is the contents of the current file.  Getting the contents of the
+        // imported files requires a little more work.  The files will be indexed in the
+        // IndexManager, but access to that is encapsulated in the YangModelManager.
         
         List<SourceIdentifier>  sourceIdentifiers   = collectSourceIds(module);
-        if (sourceIdentifiers.size() == 1) {
-            resolver.registerSource(YangTextSchemaSource.delegateForByteSource(sourceIdentifiers.get(0),
-                    ByteSource.wrap(yangSourceEditor.getDocument().get().getBytes())));
-        }
-        else {
-            for (SourceIdentifier id : sourceIdentifiers) {
-                //System.out.println("id[" + id + "]");
-                // delegate will be a ByteArrayByteSource.
-                //                YangTextSchemaSource    source  = YangTextSchemaSource.delegateForByteSource(id, delegate);
-                //                resolver.registerSource(source);
+        
+        resolver.registerSource(YangTextSchemaSource.delegateForByteSource(sourceIdentifiers.get(0),
+                ByteSource.wrap(yangSourceEditor.getDocument().get().getBytes())));
+        
+        for (int ctr = 1; ctr < sourceIdentifiers.size(); ++ ctr) {
+            String  name        = sourceIdentifiers.get(ctr).getName();
+            String  revision    =  sourceIdentifiers.get(ctr).getRevision();
+            ElementIndexInfo[]  infos   =
+                    YangModelManager.search(null, revision, name, ElementIndexType.MODULE,
+                                            file.getProject(), null);
+            try {
+                // Just use the first element of the array and quit.
+                for (ElementIndexInfo info : infos) {
+                    // Pretty much only two choices.  It's either an entry in a jar file, or
+                    // a raw file.
+                    if (info.getEntry() != null && info.getEntry().length() > 0) {
+                        YangJarEntry    jarEntry    =
+                                YangCorePlugin.createJarEntry(new Path(info.getPath()), info.getEntry());
+                        resolver.registerSource(YangTextSchemaSource.delegateForByteSource(sourceIdentifiers.get(0),
+                                ByteSource.wrap(new String(jarEntry.getContent()).getBytes())));
+                    }
+                    else {
+                        YangFile    yangFile    =
+                                YangCorePlugin.createYangFile(info.getPath());
+                        resolver.registerSource(YangTextSchemaSource.delegateForByteSource(sourceIdentifiers.get(0),
+                                ByteSource.wrap(new String(yangFile.getContents()).getBytes())));
+                    }
+                    break;
+                }
+            }
+            catch (YangModelException ex) {
+                YangCorePlugin.log(ex);
             }
         }
+
         YinExportUtils.writeModuleToOutputStream(resolver.getSchemaContext().get(), new ModuleApiProxy(module), outputStream);
     }
 
index b671265f9e156802972c05adb85a5edeefe17b4f..589198f32bdf4c2dd70eb1145739c6a0185902db 100644 (file)
@@ -1,9 +1,9 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
+       <classpathentry exported="true" kind="lib" path="libs/guava-18.0.jar"/>
        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
        <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
        <classpathentry kind="src" path="src/"/>
-       <classpathentry exported="true" kind="lib" path="libs/guava-18.0.jar"/>
        <classpathentry exported="true" kind="lib" path="libs/antlr4-runtime-4.5.1.jar"/>
        <classpathentry exported="true" kind="lib" path="libs/jsr305-3.0.0.jar"/>
        <classpathentry exported="true" kind="lib" path="libs/junit-4.12.jar"/>
index 43087c65ce961f54df9899e0ed4c4e6ad337adcb..1c88ab806d97cd7afef769273f165e9c9c2a49c9 100644 (file)
@@ -13,7 +13,6 @@ Require-Bundle: org.eclipse.core.runtime,
  com.google.guava;bundle-version="15.0.0",
  org.slf4j.api;bundle-version="1.7.2"
 Bundle-ClassPath: .,
- libs/guava-18.0.jar,
  libs/antlr4-runtime-4.5.1.jar,
  libs/jsr305-3.0.0.jar,
  libs/junit-4.12.jar,
@@ -27,10 +26,12 @@ Bundle-ClassPath: .,
  libs/yang-model-export-1.0.0-SNAPSHOT.jar,
  libs/yang-model-util-1.0.0-SNAPSHOT.jar,
  libs/yang-parser-api-1.0.0-SNAPSHOT.jar,
- libs/yang-parser-impl-1.0.0-SNAPSHOT.jar
+ libs/yang-parser-impl-1.0.0-SNAPSHOT.jar,
+ libs/guava-18.0.jar
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
 Bundle-ActivationPolicy: lazy
-Export-Package: org.antlr.v4.runtime,
+Export-Package: com.google.common.base,
+ org.antlr.v4.runtime,
  org.antlr.v4.runtime.atn,
  org.antlr.v4.runtime.dfa,
  org.antlr.v4.runtime.misc,
index 2baaaa29ce22542717b0aaa811bd2f5642e531aa..4742401aa55ae45bfef8c45aa8f568ea300cc6d3 100644 (file)
@@ -11,7 +11,6 @@ output.. = target/classes
 bin.includes = META-INF/,\
                .,\
                plugin.xml,\
-               libs/guava-18.0.jar,\
                libs/antlr4-runtime-4.5.1.jar,\
                libs/jsr305-3.0.0.jar,\
                libs/junit-4.12.jar,\
@@ -25,4 +24,5 @@ bin.includes = META-INF/,\
                libs/yang-model-export-1.0.0-SNAPSHOT.jar,\
                libs/yang-model-util-1.0.0-SNAPSHOT.jar,\
                libs/yang-parser-api-1.0.0-SNAPSHOT.jar,\
-               libs/yang-parser-impl-1.0.0-SNAPSHOT.jar
+               libs/yang-parser-impl-1.0.0-SNAPSHOT.jar,\
+               libs/guava-18.0.jar
index 97a14e9daadf684de20038864aa9f074ac69fed9..0ee0e1c2d236ae096f98dd1caf601097f841f716 100644 (file)
@@ -26,7 +26,6 @@
   <packaging>eclipse-plugin</packaging>
   <version>1.1.1-SNAPSHOT</version>
   <properties>
-    <!-- <odl-version>0.8.0-Beryllium</odl-version> -->
     <odl-version>1.0.0-SNAPSHOT</odl-version>
   </properties>
   <dependencies>