<!-- 
RSS generated by JIRA (8.20.10#820010-sha1:ace47f9899e9ee25d7157d59aa17ab06aee30d3d) at Wed Feb 07 20:52:04 UTC 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>OpenDaylight JIRA</title>
    <link>https://jira.opendaylight.org</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>8.20.10</version>
        <build-number>820010</build-number>
        <build-date>22-06-2022</build-date>
    </build-info>


<item>
            <title>[YANGTOOLS-28] New parser builder imports all yang files in directory</title>
                <link>https://jira.opendaylight.org/browse/YANGTOOLS-28</link>
                <project id="10188" key="YANGTOOLS">yangtools</project>
                    <description>&lt;p&gt;The new builder &lt;br/&gt;
public Set&amp;lt;org.opendaylight.yangtools.yang.model.api.Module&amp;gt; parseYangModels(File yangFile,File directory)&lt;br/&gt;
loads all yang files in the directory, not just those needed to parse the file.&lt;br/&gt;
This will not scale when we have large numbers of files.&lt;/p&gt;

&lt;p&gt;Below shows the key code I used to build the list (I have omitted the antlr related code, but happy to attach that if it helps).&lt;/p&gt;

&lt;p&gt;===============================================================&lt;br/&gt;
I&apos;m not saying my code is any good, just showing it can be done.&lt;br/&gt;
===============================================================&lt;/p&gt;

&lt;p&gt;&amp;gt;&amp;gt;&amp;gt; So my call in main was.&lt;br/&gt;
Set&amp;lt;Module&amp;gt; modules = parser.parseYangModels(getAllYangFiles(yangFileStr, dirStr));&lt;/p&gt;

&lt;p&gt;&amp;gt;&amp;gt;&amp;gt;and here are the methods&lt;/p&gt;

&lt;p&gt;// parse the imports in the main file&lt;br/&gt;
    public List&amp;lt;File&amp;gt; getAllYangFiles(final String fileName, final String dirStr) throws IOException {&lt;br/&gt;
        assert fileName != null;&lt;br/&gt;
        assert dirStr != null;        &lt;/p&gt;

&lt;p&gt;        imports = new HashSet&amp;lt;String&amp;gt;(127);&lt;br/&gt;
        List&amp;lt;File&amp;gt; files = new ArrayList&amp;lt;File&amp;gt;();&lt;br/&gt;
        files.add(new File(dirStr + File.separator + fileName + YANG_FILE_EXTENSION)); // add the main file&lt;/p&gt;

&lt;p&gt;        getYangImports(fileName, dirStr); // recursively get the file imports&lt;/p&gt;

&lt;p&gt;        Iterator&amp;lt;String&amp;gt; i = imports.iterator();&lt;/p&gt;

&lt;p&gt;        while (i.hasNext()) &lt;/p&gt;
{
            files.add(new File(dirStr + File.separator + i.next()+ YANG_FILE_EXTENSION));
        }

&lt;p&gt;        return files;&lt;br/&gt;
    }&lt;/p&gt;

&lt;p&gt;// recursively parse the imported yang files&lt;br/&gt;
    public void getYangImports(final String fileName, final String dirStr) throws IOException {&lt;br/&gt;
        assert fileName != null;&lt;br/&gt;
        assert dirStr != null;           &lt;/p&gt;

&lt;p&gt;        Set&amp;lt;String&amp;gt; fileImports = getYangFileImports(fileName, dirStr);&lt;/p&gt;

&lt;p&gt;        if (!fileImports.isEmpty()) { // have some imports !&lt;br/&gt;
            Iterator&amp;lt;String&amp;gt; i = fileImports.iterator();&lt;br/&gt;
            String importStr;&lt;/p&gt;

&lt;p&gt;            while (i.hasNext()) {&lt;br/&gt;
                importStr = i.next();&lt;br/&gt;
                if (!imports.contains(importStr)) &lt;/p&gt;
{ // a new file to add to the list
                    imports.add(importStr);
                    getYangImports(importStr, dirStr); // recursive goodness
                }
&lt;p&gt;            }&lt;br/&gt;
        }&lt;br/&gt;
    }&lt;/p&gt;

&lt;p&gt;// get the import statements in each file&lt;br/&gt;
    public Set&amp;lt;String&amp;gt; getYangFileImports(final String fileName, final String dirStr) throws IOException &lt;/p&gt;
{
        assert fileName != null;
        assert dirStr != null;   
        
        //lexer splits input into tokens
        YangLexer lexer = new YangLexer(new ANTLRFileStream(dirStr + File.separator + fileName + YANG_FILE_EXTENSION)); // need to use subclass here (not Lexer)

        //parser generates abstract syntax tree
        YangParser parser = new YangParser(new CommonTokenStream(lexer)); // need to use subclass here (not Parser)
        parser.setBuildParseTree(true);

        ParseTree tree = parser.module_stmt();
        YangListener listener = new YangListener();
        ParseTreeWalker.DEFAULT.walk(listener, tree);

        return listener.getImports();
    }</description>
                <environment>&lt;p&gt;Operating System: Windows&lt;br/&gt;
Platform: PC&lt;/p&gt;</environment>
        <key id="22448">YANGTOOLS-28</key>
            <summary>New parser builder imports all yang files in directory</summary>
                <type id="10104" iconUrl="https://jira.opendaylight.org/secure/viewavatar?size=xsmall&amp;avatarId=10303&amp;avatarType=issuetype">Bug</type>
                                                <status id="5" iconUrl="https://jira.opendaylight.org/images/icons/statuses/resolved.png" description="A resolution has been taken, and it is awaiting verification by reporter. From here issues are either reopened, or are closed.">Resolved</status>
                    <statusCategory id="3" key="done" colorName="green"/>
                                    <resolution id="10000">Done</resolution>
                                        <assignee username="-1">Unassigned</assignee>
                                    <reporter username="chrhartl@cisco.com">Christopher Hartley</reporter>
                        <labels>
                    </labels>
                <created>Mon, 30 Sep 2013 08:31:46 +0000</created>
                <updated>Sun, 10 Apr 2022 18:34:52 +0000</updated>
                            <resolved>Tue, 1 Oct 2013 14:26:29 +0000</resolved>
                                                                        <due></due>
                            <votes>0</votes>
                                    <watches>1</watches>
                                                                                                                <comments>
                            <comment id="42543" author="mvitez@cisco.com" created="Tue, 1 Oct 2013 14:26:29 +0000"  >&lt;p&gt;Fixed in yang-parser-impl version 0.5.9-SNAPSHOT.&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                            <customfield id="customfield_11400" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                        <customfield id="customfield_10208" key="com.atlassian.jira.plugin.system.customfieldtypes:textfield">
                        <customfieldname>External issue ID</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>91</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10201" key="com.atlassian.jira.plugin.system.customfieldtypes:url">
                        <customfieldname>External issue URL</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue><![CDATA[https://bugs.opendaylight.org/show_bug.cgi?id=91]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                <customfield id="customfield_10000" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>0|i024p3:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                </customfields>
    </item>
</channel>
</rss>