Fix checkstyle in maven-sal-api-gen-plugin 12/64412/4
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 17 Oct 2017 16:03:40 +0000 (18:03 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 17 Oct 2017 17:00:03 +0000 (19:00 +0200)
Fix violations and enable enforcement.

Change-Id: Ibc88fbe40b09a0aeff977bd1aaeed408954c201a
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/maven-sal-api-gen-plugin/pom.xml
binding/maven-sal-api-gen-plugin/src/main/java/org/opendaylight/mdsal/binding/maven/api/gen/plugin/CodeGeneratorImpl.java
binding/maven-sal-api-gen-plugin/src/main/java/org/opendaylight/mdsal/binding/yang/unified/doc/generator/GeneratorImpl.xtend
binding/maven-sal-api-gen-plugin/src/main/java/org/opendaylight/mdsal/binding/yang/unified/doc/generator/maven/DocumentationGeneratorImpl.java
binding/maven-sal-api-gen-plugin/src/main/java/org/opendaylight/mdsal/binding/yang/wadl/generator/WadlRestconfGenerator.xtend
binding/maven-sal-api-gen-plugin/src/main/java/org/opendaylight/mdsal/binding/yang/wadl/generator/maven/WadlGenerator.java
binding/maven-sal-api-gen-plugin/src/test/java/org/opendaylight/mdsal/binding/yang/unified/doc/generator/maven/DocGenTest.java
binding/maven-sal-api-gen-plugin/src/test/java/org/opendaylight/mdsal/binding/yang/unified/doc/generator/maven/YangModuleInfoCompilationTest.java
binding/maven-sal-api-gen-plugin/src/test/java/org/opendaylight/mdsal/binding/yang/wadl/generator/maven/WadlGenTest.java

index 31c9572cec71ffeb0f85c61e33742e50c402735f..4dc01327239627437a5192bba9b6478273f7dee6 100644 (file)
                 <groupId>org.eclipse.xtend</groupId>
                 <artifactId>xtend-maven-plugin</artifactId>
             </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-checkstyle-plugin</artifactId>
+                <configuration>
+                    <propertyExpansion>checkstyle.violationSeverity=error</propertyExpansion>
+                </configuration>
+            </plugin>
         </plugins>
     </build>
 
-  <!--
-      Maven Site Configuration
+    <!--
+        Maven Site Configuration
 
-      The following configuration is necessary for maven-site-plugin to
-      correctly identify the correct deployment path for OpenDaylight Maven
-      sites.
-  -->
-  <url>${odl.site.url}/${project.groupId}/${stream}/${project.artifactId}/</url>
+        The following configuration is necessary for maven-site-plugin to
+        correctly identify the correct deployment path for OpenDaylight Maven
+        sites.
+    -->
+    <url>${odl.site.url}/${project.groupId}/${stream}/${project.artifactId}/</url>
 
-  <distributionManagement>
-    <site>
-      <id>opendaylight-site</id>
-      <url>${nexus.site.url}/${project.artifactId}/</url>
-    </site>
-  </distributionManagement>
+    <distributionManagement>
+        <site>
+            <id>opendaylight-site</id>
+            <url>${nexus.site.url}/${project.artifactId}/</url>
+        </site>
+    </distributionManagement>
 
 </project>
index 26d935d46882a49893a0ff63d0c7091b6e79ce8e..84f94eca6c10facadabfea3deef23fa040812f47 100644 (file)
@@ -51,6 +51,13 @@ public final class CodeGeneratorImpl implements BasicCodeGenerator, BuildContext
     private MavenProject mavenProject;
     private File resourceBaseDir;
 
+    @Override
+    public Collection<File> generateSources(final SchemaContext context, final File outputBaseDir,
+            final Set<Module> currentModules) throws IOException {
+        return generateSources(context, outputBaseDir, currentModules,
+            module -> Optional.of("/" + module.getModuleSourcePath().replace(File.separator, "/")));
+    }
+
     @Override
     public Collection<File> generateSources(final SchemaContext context, final File outputDir,
             final Set<Module> yangModules, final Function<Module, Optional<String>> moduleResourcePathResolver)
@@ -150,7 +157,7 @@ public final class CodeGeneratorImpl implements BasicCodeGenerator, BuildContext
     private Set<File> generateYangModuleInfo(final File outputBaseDir, final Module module, final SchemaContext ctx,
             final Function<Module, Optional<String>> moduleResourcePathResolver,
             final Builder<String> providerSourceSet) {
-        Builder<File> generatedFiles = ImmutableSet.<File> builder();
+        Builder<File> generatedFiles = ImmutableSet.builder();
 
         final YangModuleInfoTemplate template = new YangModuleInfoTemplate(module, ctx, moduleResourcePathResolver);
         String moduleInfoSource = template.generate();
@@ -180,10 +187,11 @@ public final class CodeGeneratorImpl implements BasicCodeGenerator, BuildContext
         return file;
     }
 
+    @SuppressWarnings("checkstyle:illegalCatch")
     private File writeFile(final File file, final String source) {
-        try (final OutputStream stream = buildContext.newFileOutputStream(file)) {
-            try (final Writer fw = new OutputStreamWriter(stream, StandardCharsets.UTF_8)) {
-                try (final BufferedWriter bw = new BufferedWriter(fw)) {
+        try (OutputStream stream = buildContext.newFileOutputStream(file)) {
+            try (Writer fw = new OutputStreamWriter(stream, StandardCharsets.UTF_8)) {
+                try (BufferedWriter bw = new BufferedWriter(fw)) {
                     bw.write(source);
                 }
             } catch (Exception e) {
@@ -194,12 +202,4 @@ public final class CodeGeneratorImpl implements BasicCodeGenerator, BuildContext
         }
         return file;
     }
-
-    @Override
-    public Collection<File> generateSources(final SchemaContext context, final File outputBaseDir, final Set<Module> currentModules)
-            throws IOException {
-        return generateSources(context, outputBaseDir, currentModules,
-            m -> Optional.of("/" + m.getModuleSourcePath().replace(File.separator, "/")));
-    }
-
 }
index 31f615247bbc059f06a8b187c1bc0330605593ad..04b7f1e80e3a7d437abbfa23ba5d3d7885b33e41 100644 (file)
@@ -66,9 +66,9 @@ class GeneratorImpl {
     var Module currentModule;
     val Map<String, String> imports = new HashMap();
     var SchemaContext ctx;
-    
+
     StringBuilder augmentChildNodesAsString
-    
+
     DataSchemaNode lastNodeInTargetPath = null
 
     def generate(SchemaContext context, File targetPath, Set<Module> modulesToGen) throws IOException {
@@ -305,7 +305,7 @@ class GeneratorImpl {
         }
         return '''
             <h2>Augmentations</h2>
-            
+
             <ul>
             «FOR augment : module.augmentations»
                 <li>
@@ -322,7 +322,7 @@ class GeneratorImpl {
                     «FOR childNode : augment.childNodes»
                         «childNode.printSchemaNodeInfo»
                     «ENDFOR»
-                    
+
                     <h3>Example</h3>
                     «createAugmentChildNodesAsString(new ArrayList(augment.childNodes))»
                     «printNodeChildren(parseTargetPath(augment.targetPath))»
@@ -331,13 +331,13 @@ class GeneratorImpl {
             </ul>
         '''
     }
-    
+
     private def createAugmentChildNodesAsString(List<DataSchemaNode> childNodes) {
         augmentChildNodesAsString = new StringBuilder();
         augmentChildNodesAsString.append(printNodeChildren(childNodes))
         return ''
     }
-    
+
     private def parseTargetPath(SchemaPath path) {
         val List<DataSchemaNode> nodes = new ArrayList<DataSchemaNode>();
         for (QName pathElement : path.pathFromRoot) {
@@ -359,13 +359,13 @@ class GeneratorImpl {
         if(! nodes.empty) {
             lastNodeInTargetPath = nodes.get(nodes.size() - 1)
         }
-        
+
         val List<DataSchemaNode> targetPathNodes = new ArrayList<DataSchemaNode>();
         targetPathNodes.add(lastNodeInTargetPath)
-        
+
         return targetPathNodes
     }
-    
+
     private def DataSchemaNode findNodeInChildNodes(QName findingNode, Iterable<DataSchemaNode> childNodes) {
         for(child : childNodes) {
             if (child.QName.equals(findingNode))
@@ -384,25 +384,25 @@ class GeneratorImpl {
             }
         }
     }
-    
+
     private def printNodeChildren(List<DataSchemaNode> childNodes) {
         if (childNodes.empty) {
             return ''
         }
-        
-        return 
+
+        return
         '''
         <pre>
         «printAugmentedNode(childNodes.get(0))»
         </pre>
         '''
     }
-    
+
     private def CharSequence printAugmentedNode(DataSchemaNode child) {
-        
+
         if(child instanceof ChoiceCaseNode)
             return ''
-            
+
         return
         '''
         «IF child instanceof ContainerSchemaNode»
@@ -425,7 +425,7 @@ class GeneratorImpl {
         «ENDIF»
         '''
     }
-    
+
     private def printChoiceNode(ChoiceSchemaNode child) {
         val List<ChoiceCaseNode> cases = new ArrayList(child.cases);
         if(!cases.empty) {
@@ -434,7 +434,7 @@ class GeneratorImpl {
                 printAugmentedNode(caseChildNode)
         }
     }
-    
+
     private def printListNode(ListSchemaNode listNode) {
         return
         '''
@@ -445,7 +445,7 @@ class GeneratorImpl {
             &lt;/«listNode.QName.localName»&gt;
         '''
     }
-    
+
     private def printContainerNode(ContainerSchemaNode containerNode) {
         return
         '''
@@ -456,7 +456,7 @@ class GeneratorImpl {
             &lt;/«containerNode.QName.localName»&gt;
         '''
     }
-    
+
     private def printLeafListNode(LeafListSchemaNode leafListNode) {
         return
         '''
@@ -465,16 +465,16 @@ class GeneratorImpl {
             &lt;«leafListNode.QName.localName»&gt;. . .&lt;/«leafListNode.QName.localName»&gt;
         '''
     }
-    
+
     private def printAnyXmlNode(AnyXmlSchemaNode anyXmlNode) {
-        return 
+        return
         '''
             &lt;«anyXmlNode.QName.localName»&gt;. . .&lt;/«anyXmlNode.QName.localName»&gt;
         '''
     }
-    
+
     private def printLeafNode(LeafSchemaNode leafNode) {
-        return 
+        return
         '''
             &lt;«leafNode.QName.localName»&gt;. . .&lt;/«leafNode.QName.localName»&gt;
         '''
index 0452b0774c52dc09f706c9ba76024b8e1ee3d1e3..b528c6d3d83d79bc981e2b1655a7560dd976b7a9 100644 (file)
@@ -20,8 +20,9 @@ import org.opendaylight.yangtools.yang2sources.spi.BasicCodeGenerator;
 public class DocumentationGeneratorImpl extends GeneratorImpl implements BasicCodeGenerator {
 
     @Override
-    public Collection<File> generateSources(final SchemaContext arg0, final File arg1, final Set<Module> arg2) throws IOException {
-         return generate(arg0, arg1, arg2);
+    public Collection<File> generateSources(final SchemaContext arg0, final File arg1, final Set<Module> arg2)
+            throws IOException {
+        return generate(arg0, arg1, arg2);
     }
 
     @Override
index 8b1a4885ee1d0d8e15bf0ffd29dfc5f6f4d19ac3..5045a08df70f003bfd3a6e15b1a5eca522bfb5e2 100644 (file)
@@ -27,228 +27,228 @@ import org.sonatype.plexus.build.incremental.BuildContext
 import org.sonatype.plexus.build.incremental.DefaultBuildContext
 
 class WadlRestconfGenerator {
-       
-       File path
-       static val BuildContext CTX = new DefaultBuildContext();
-       static val PATH_DELIMETER = '/'
-       var SchemaContext context;
-       var List<DataSchemaNode> configData;
-       var List<DataSchemaNode> operationalData;
-       var Module module;
-       var List<LeafSchemaNode> pathListParams;
-
-       new(File targetPath) {
-               if (!targetPath.exists) targetPath.mkdirs
-               path = targetPath
-       }
-
-       def generate(SchemaContext context, Set<Module> modules) {
+
+    File path
+    static val BuildContext CTX = new DefaultBuildContext();
+    static val PATH_DELIMETER = '/'
+    var SchemaContext context;
+    var List<DataSchemaNode> configData;
+    var List<DataSchemaNode> operationalData;
+    var Module module;
+    var List<LeafSchemaNode> pathListParams;
+
+    new(File targetPath) {
+        if (!targetPath.exists) targetPath.mkdirs
+        path = targetPath
+    }
+
+    def generate(SchemaContext context, Set<Module> modules) {
         val result = new HashSet;
-               this.context = context
-               for (module : modules) {
-                       val dataContainers = module.childNodes.filter[it|it.listOrContainer]
-                       if (!dataContainers.empty || !module.rpcs.nullOrEmpty) {
-                               configData = new ArrayList
-                               operationalData = new ArrayList
-                               
-                               for (data : dataContainers) {
-                                       if (data.configuration) {
-                                               configData.add(data)    
-                                       } else {
-                                               operationalData.add(data)
-                                       }
-                               }
-                               
-                               this.module = module
-                               val destination = new File(path, '''«module.name».wadl''')
-                   val fw = new OutputStreamWriter(CTX.newFileOutputStream(destination), StandardCharsets.UTF_8)
-                   val bw = new BufferedWriter(fw)
-                   bw.append(application);
-                   bw.close();
-                   fw.close();
-                       result.add(destination)
-                       }
-               }
-               return result
-       }
-       
-       private def application() '''
-               <?xml version="1.0"?>
-               <application xmlns="http://wadl.dev.java.net/2009/02" «module.importsAsNamespaces» xmlns:«module.prefix»="«module.namespace»">
-               
-                       «grammars»
-                       
-                       «resources»
-               </application>
-       '''
-       
-       private def importsAsNamespaces(Module module) '''
-               «FOR imprt : module.imports»
-                       xmlns:«imprt.prefix»="«context.findModuleByName(imprt.moduleName, imprt.revision).namespace»"
-               «ENDFOR»
-       '''
-       
-       private def grammars() '''
-               <grammars>
-                       <include href="«module.name».yang"/>
-                       «FOR imprt : module.imports»
-                               <include href="«imprt.moduleName».yang"/>
-                       «ENDFOR»
-               </grammars>
-       '''
-       
-       private def resources() '''
-               <resources base="http://localhost:9998/restconf">
-                       «resourceOperational»
-                       «resourceConfig»
-                       «resourceOperations»
-               </resources>
-       '''
-       
-       private def resourceOperational() '''
-               «IF !operationalData.nullOrEmpty»
-                       <resource path="operational">
-                               «FOR schemaNode : operationalData»
-                                       «schemaNode.firstResource(false)»
-                               «ENDFOR»
-                       </resource>
-               «ENDIF»
-       '''
-       
-       private def resourceConfig() '''
-               «IF !configData.nullOrEmpty»
-                       <resource path="config">
-                               «FOR schemaNode : configData»
-                                       «schemaNode.mehodPost»
-                               «ENDFOR»
-                               «FOR schemaNode : configData»
-                                       «schemaNode.firstResource(true)»
-                               «ENDFOR»
-                       </resource>
-               «ENDIF»
-       '''
-       
-       private def resourceOperations() '''
-               «IF !module.rpcs.nullOrEmpty»
-                       <resource path="operations">
-                               «FOR rpc : module.rpcs»
-                                       <resource path="«module.name»:«rpc.QName.localName»">
-                                               «methodPostRpc(rpc.input !== null, rpc.output !== null)»
-                                       </resource>
-                               «ENDFOR»
-                       </resource>
-               «ENDIF»
-       '''
-       
-       private def String firstResource(DataSchemaNode schemaNode, boolean config) '''
-               <resource path="«module.name»:«schemaNode.createPath»">
-                       «resourceBody(schemaNode, config)»
-               </resource>
-       '''
-               
-       private def String resource(DataSchemaNode schemaNode, boolean config) '''
-               <resource path="«schemaNode.createPath»">
-                       «resourceBody(schemaNode, config)»
-               </resource>
-       '''
-       
-       private def String createPath(DataSchemaNode schemaNode) {
-               pathListParams = new ArrayList
-               var StringBuilder path = new StringBuilder
-               path.append(schemaNode.QName.localName)
-               if (schemaNode instanceof ListSchemaNode) {
-                       for (listKey : schemaNode.keyDefinition) {
-                               pathListParams.add((schemaNode as DataNodeContainer).getDataChildByName(listKey) as LeafSchemaNode)
-                               path.append(PATH_DELIMETER)
-                               path.append('{')
-                               path.append(listKey.localName)
-                               path.append('}')
-                       }
-               }
-               return path.toString
-       }
-       
-       private def String resourceBody(DataSchemaNode schemaNode, boolean config) '''
-               «IF !pathListParams.nullOrEmpty»
-                       «resourceParams»
-               «ENDIF»
-               «schemaNode.methodGet»
-               «val children = (schemaNode as DataNodeContainer).childNodes.filter[it|it.listOrContainer]»
-               «IF config»
-                       «schemaNode.methodDelete»
-                       «schemaNode.mehodPut»
-                       «FOR child : children»
-                               «child.mehodPost»
-                       «ENDFOR»
-               «ENDIF»
-               «FOR child : children»
-                       «child.resource(config)»
-               «ENDFOR»
-       '''
-       
-       private def resourceParams() '''
-               «FOR pathParam : pathListParams»
-                   «IF pathParam !== null»
-                       «val type = pathParam.type.QName.localName»
-                       <param required="true" style="template" name="«pathParam.QName.localName»" type="«type»"/>
-                       «ENDIF»
-               «ENDFOR»
-       '''
-       
-       private def methodGet(DataSchemaNode schemaNode) '''
-               <method name="GET">
-                       <response>
-                               «representation(schemaNode.QName.namespace, schemaNode.QName.localName)»
-                       </response>
-               </method>
-       '''
-       
-       private def mehodPut(DataSchemaNode schemaNode) '''
-               <method name="PUT">
-                       <request>
-                               «representation(schemaNode.QName.namespace, schemaNode.QName.localName)»
-                       </request>
-               </method>
-       '''
-       
-       private def mehodPost(DataSchemaNode schemaNode) '''
-               <method name="POST">
-                       <request>
-                               «representation(schemaNode.QName.namespace, schemaNode.QName.localName)»
-                       </request>
-               </method>
-       '''
-       
-       private def methodPostRpc(boolean input, boolean output) '''
-               <method name="POST">
-                       «IF input»
-                       <request>
-                               «representation(null, "input")»
-                       </request>
-                       «ENDIF»
-                       «IF output»
-                       <response>
-                               «representation(null, "output")»
-                       </response>
-                       «ENDIF»
-               </method>
-       '''
-
-       private def methodDelete(DataSchemaNode schemaNode) '''
-               <method name="DELETE" />
-       '''
-
-       private def representation(URI prefix, String name) '''
-               «val elementData = name»
-               <representation mediaType="application/xml" element="«elementData»"/>
-               <representation mediaType="text/xml" element="«elementData»"/>
-               <representation mediaType="application/json" element="«elementData»"/>
-               <representation mediaType="application/yang.data+xml" element="«elementData»"/>
-               <representation mediaType="application/yang.data+json" element="«elementData»"/>
-       '''
-       
-       private def boolean isListOrContainer(DataSchemaNode schemaNode) {
-               return (schemaNode instanceof ListSchemaNode || schemaNode instanceof ContainerSchemaNode)
-       }
+        this.context = context
+        for (module : modules) {
+            val dataContainers = module.childNodes.filter[it|it.listOrContainer]
+            if (!dataContainers.empty || !module.rpcs.nullOrEmpty) {
+                configData = new ArrayList
+                operationalData = new ArrayList
+
+                for (data : dataContainers) {
+                    if (data.configuration) {
+                        configData.add(data)
+                    } else {
+                        operationalData.add(data)
+                    }
+                }
+
+                this.module = module
+                val destination = new File(path, '''«module.name».wadl''')
+                val fw = new OutputStreamWriter(CTX.newFileOutputStream(destination), StandardCharsets.UTF_8)
+                val bw = new BufferedWriter(fw)
+                bw.append(application);
+                bw.close();
+                fw.close();
+                result.add(destination)
+            }
+        }
+        return result
+    }
+
+    private def application() '''
+        <?xml version="1.0"?>
+        <application xmlns="http://wadl.dev.java.net/2009/02" «module.importsAsNamespaces» xmlns:«module.prefix»="«module.namespace»">
+
+            «grammars»
+
+            «resources»
+        </application>
+    '''
+
+    private def importsAsNamespaces(Module module) '''
+        «FOR imprt : module.imports»
+            xmlns:«imprt.prefix»="«context.findModuleByName(imprt.moduleName, imprt.revision).namespace»"
+        «ENDFOR»
+    '''
+
+    private def grammars() '''
+        <grammars>
+            <include href="«module.name».yang"/>
+            «FOR imprt : module.imports»
+                <include href="«imprt.moduleName».yang"/>
+            «ENDFOR»
+        </grammars>
+    '''
+
+    private def resources() '''
+        <resources base="http://localhost:9998/restconf">
+            «resourceOperational»
+            «resourceConfig»
+            «resourceOperations»
+        </resources>
+    '''
+
+    private def resourceOperational() '''
+        «IF !operationalData.nullOrEmpty»
+            <resource path="operational">
+                «FOR schemaNode : operationalData»
+                    «schemaNode.firstResource(false)»
+                «ENDFOR»
+            </resource>
+        «ENDIF»
+    '''
+
+    private def resourceConfig() '''
+        «IF !configData.nullOrEmpty»
+            <resource path="config">
+                «FOR schemaNode : configData»
+                    «schemaNode.mehodPost»
+                «ENDFOR»
+                «FOR schemaNode : configData»
+                    «schemaNode.firstResource(true)»
+                «ENDFOR»
+            </resource>
+        «ENDIF»
+    '''
+
+    private def resourceOperations() '''
+        «IF !module.rpcs.nullOrEmpty»
+            <resource path="operations">
+                «FOR rpc : module.rpcs»
+                    <resource path="«module.name»:«rpc.QName.localName»">
+                        «methodPostRpc(rpc.input !== null, rpc.output !== null)»
+                    </resource>
+                «ENDFOR»
+            </resource>
+        «ENDIF»
+    '''
+
+    private def String firstResource(DataSchemaNode schemaNode, boolean config) '''
+        <resource path="«module.name»:«schemaNode.createPath»">
+            «resourceBody(schemaNode, config)»
+        </resource>
+    '''
+
+    private def String resource(DataSchemaNode schemaNode, boolean config) '''
+        <resource path="«schemaNode.createPath»">
+            «resourceBody(schemaNode, config)»
+        </resource>
+    '''
+
+    private def String createPath(DataSchemaNode schemaNode) {
+        pathListParams = new ArrayList
+        var StringBuilder path = new StringBuilder
+        path.append(schemaNode.QName.localName)
+        if (schemaNode instanceof ListSchemaNode) {
+            for (listKey : schemaNode.keyDefinition) {
+                pathListParams.add((schemaNode as DataNodeContainer).getDataChildByName(listKey) as LeafSchemaNode)
+                path.append(PATH_DELIMETER)
+                path.append('{')
+                path.append(listKey.localName)
+                path.append('}')
+            }
+        }
+        return path.toString
+    }
+
+    private def String resourceBody(DataSchemaNode schemaNode, boolean config) '''
+        «IF !pathListParams.nullOrEmpty»
+            «resourceParams»
+        «ENDIF»
+        «schemaNode.methodGet»
+        «val children = (schemaNode as DataNodeContainer).childNodes.filter[it|it.listOrContainer]»
+        «IF config»
+            «schemaNode.methodDelete»
+            «schemaNode.mehodPut»
+            «FOR child : children»
+                «child.mehodPost»
+            «ENDFOR»
+        «ENDIF»
+        «FOR child : children»
+            «child.resource(config)»
+        «ENDFOR»
+    '''
+
+    private def resourceParams() '''
+        «FOR pathParam : pathListParams»
+            «IF pathParam !== null»
+            «val type = pathParam.type.QName.localName»
+            <param required="true" style="template" name="«pathParam.QName.localName»" type="«type»"/>
+            «ENDIF»
+        «ENDFOR»
+    '''
+
+    private def methodGet(DataSchemaNode schemaNode) '''
+        <method name="GET">
+            <response>
+                «representation(schemaNode.QName.namespace, schemaNode.QName.localName)»
+            </response>
+        </method>
+    '''
+
+    private def mehodPut(DataSchemaNode schemaNode) '''
+        <method name="PUT">
+            <request>
+                «representation(schemaNode.QName.namespace, schemaNode.QName.localName)»
+            </request>
+        </method>
+    '''
+
+    private def mehodPost(DataSchemaNode schemaNode) '''
+        <method name="POST">
+            <request>
+                «representation(schemaNode.QName.namespace, schemaNode.QName.localName)»
+            </request>
+        </method>
+    '''
+
+    private def methodPostRpc(boolean input, boolean output) '''
+        <method name="POST">
+            «IF input»
+            <request>
+                «representation(null, "input")»
+            </request>
+            «ENDIF»
+            «IF output»
+            <response>
+                «representation(null, "output")»
+            </response>
+            «ENDIF»
+        </method>
+    '''
+
+    private def methodDelete(DataSchemaNode schemaNode) '''
+        <method name="DELETE" />
+    '''
+
+    private def representation(URI prefix, String name) '''
+        «val elementData = name»
+        <representation mediaType="application/xml" element="«elementData»"/>
+        <representation mediaType="text/xml" element="«elementData»"/>
+        <representation mediaType="application/json" element="«elementData»"/>
+        <representation mediaType="application/yang.data+xml" element="«elementData»"/>
+        <representation mediaType="application/yang.data+json" element="«elementData»"/>
+    '''
+
+    private def boolean isListOrContainer(DataSchemaNode schemaNode) {
+        return (schemaNode instanceof ListSchemaNode || schemaNode instanceof ContainerSchemaNode)
+    }
 
 }
index 69fc52d7c73eee3a91b86198190a4bcd155f4d17..8f0fc163a7ad4561ab6a94b603b7cef967330988 100644 (file)
@@ -20,8 +20,8 @@ import org.opendaylight.yangtools.yang2sources.spi.BasicCodeGenerator;
 public class WadlGenerator implements BasicCodeGenerator {
 
     @Override
-    public Collection<File> generateSources(final SchemaContext context, final File outputDir, final Set<Module> currentModules)
-            throws IOException {
+    public Collection<File> generateSources(final SchemaContext context, final File outputDir,
+            final Set<Module> currentModules) throws IOException {
 
         final File outputBaseDir;
         if (outputDir == null) {
index 0a38e9320e330a754caebd7bee58ea18bc2f4bd0..4d004c1bc353979fffb183bdd85990d4e4264bd8 100644 (file)
@@ -21,7 +21,6 @@ import java.util.Set;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
-import org.opendaylight.mdsal.binding.yang.unified.doc.generator.maven.DocumentationGeneratorImpl;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
index 1a0731851a2725f25a02adc87a05575d3e532056..c63824a1b1df5c150f79eeff9242a98444e3101a 100644 (file)
@@ -113,17 +113,20 @@ public class YangModuleInfoCompilationTest {
             String name = ymi.getName();
 
             switch (name) {
-            case "import-module":
-                infoImport = ymi;
-                break;
-            case "submodule1":
-                infoSub1 = ymi;
-                break;
-            case "submodule2":
-                infoSub2 = ymi;
-                break;
-            case "submodule3":
-                infoSub3 = ymi;
+                case "import-module":
+                    infoImport = ymi;
+                    break;
+                case "submodule1":
+                    infoSub1 = ymi;
+                    break;
+                case "submodule2":
+                    infoSub2 = ymi;
+                    break;
+                case "submodule3":
+                    infoSub3 = ymi;
+                    break;
+                default:
+                    // no-op
             }
         }
         assertNotNull(infoImport);
@@ -134,7 +137,8 @@ public class YangModuleInfoCompilationTest {
         cleanUp(sourcesOutputDir, compiledOutputDir);
     }
 
-    private static void generateTestSources(final String resourceDirPath, final File sourcesOutputDir) throws Exception {
+    private static void generateTestSources(final String resourceDirPath, final File sourcesOutputDir)
+            throws Exception {
         final List<File> sourceFiles = getSourceFiles(resourceDirPath);
         final SchemaContext context = YangParserTestUtils.parseYangSources(sourceFiles);
         CodeGeneratorImpl codegen = new CodeGeneratorImpl();
@@ -153,10 +157,10 @@ public class YangModuleInfoCompilationTest {
         codegen.setAdditionalConfig(ImmutableMap.of("test", "test"));
         Collection<File> files = codegen.generateSources(context, null, context.getModules());
         assertFalse(files.isEmpty());
-        files.forEach((file -> {
+        files.forEach(file -> {
             deleteTestDir(file);
             assertFalse(file.exists());
-        }));
+        });
     }
 
     private static void testCompilation(final File sourcesOutputDir, final File compiledOutputDir) {
@@ -210,8 +214,8 @@ public class YangModuleInfoCompilationTest {
         if (file.isDirectory()) {
             File[] filesToDelete = file.listFiles();
             if (filesToDelete != null) {
-                for (File f : filesToDelete) {
-                    deleteTestDir(f);
+                for (File ftd : filesToDelete) {
+                    deleteTestDir(ftd);
                 }
             }
         }
@@ -220,11 +224,12 @@ public class YangModuleInfoCompilationTest {
         }
     }
 
-    private static Method assertContainsMethod(final Class<?> clazz, final Class<?> returnType, final String name, final Class<?>... args) {
+    private static Method assertContainsMethod(final Class<?> clazz, final Class<?> returnType, final String name,
+            final Class<?>... args) {
         try {
-            Method m = clazz.getDeclaredMethod(name, args);
-            assertEquals(returnType, m.getReturnType());
-            return m;
+            Method method = clazz.getDeclaredMethod(name, args);
+            assertEquals(returnType, method.getReturnType());
+            return method;
         } catch (NoSuchMethodException e) {
             throw new AssertionError("Method " + name + " with args " + Arrays.toString(args)
                     + " does not exists in class " + clazz.getSimpleName());
index c94f8f40d086dbe40968a0ee4805012590d7245d..e6210901ac1c65219280d87df8728a107914a49c 100644 (file)
@@ -22,7 +22,6 @@ import java.util.Set;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
-import org.opendaylight.mdsal.binding.yang.wadl.generator.maven.WadlGenerator;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
@@ -103,4 +102,4 @@ public class WadlGenTest {
             throw new RuntimeException("Failed to clean up after test");
         }
     }
-}
\ No newline at end of file
+}