From b62535fa9751a3c80ebd8892df7f3db914b535eb Mon Sep 17 00:00:00 2001 From: Illia Date: Thu, 1 Oct 2020 13:28:47 +0300 Subject: [PATCH] Fix WadlRestconfGenerator checkstyle Move resources closing to finally block. Suppress uncalled private method warning(called from anonymous class). Signed-off-by: Illia Change-Id: I86aba7b831c90cf8a927d3468b7b5eba30031e05 --- .../generator/WadlRestconfGenerator.xtend | 35 +++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/binding/maven-sal-api-gen-plugin/src/main/java/org/opendaylight/mdsal/binding/yang/wadl/generator/WadlRestconfGenerator.xtend b/binding/maven-sal-api-gen-plugin/src/main/java/org/opendaylight/mdsal/binding/yang/wadl/generator/WadlRestconfGenerator.xtend index b9237e0bab..6cb0f3bd42 100644 --- a/binding/maven-sal-api-gen-plugin/src/main/java/org/opendaylight/mdsal/binding/yang/wadl/generator/WadlRestconfGenerator.xtend +++ b/binding/maven-sal-api-gen-plugin/src/main/java/org/opendaylight/mdsal/binding/yang/wadl/generator/WadlRestconfGenerator.xtend @@ -7,8 +7,12 @@ */ package org.opendaylight.mdsal.binding.yang.wadl.generator +import static com.google.common.base.Preconditions.checkState; + +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.io.BufferedWriter import java.io.File +import java.io.IOException import java.io.OutputStreamWriter import java.net.URI import java.nio.charset.StandardCharsets @@ -23,10 +27,14 @@ import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode import org.opendaylight.yangtools.yang.model.api.ListSchemaNode import org.opendaylight.yangtools.yang.model.api.Module +import org.slf4j.Logger +import org.slf4j.LoggerFactory import org.sonatype.plexus.build.incremental.BuildContext class WadlRestconfGenerator { + static val Logger LOG = LoggerFactory.getLogger(WadlRestconfGenerator) + static val PATH_DELIMETER = '/' val BuildContext buildContext; val File path @@ -37,7 +45,9 @@ class WadlRestconfGenerator { var List pathListParams; new(BuildContext buildContext, File targetPath) { - if (!targetPath.exists) targetPath.mkdirs + if (!targetPath.exists) { + checkState(targetPath.mkdirs, "Unable to create directory: %s", targetPath); + } path = targetPath this.buildContext = buildContext } @@ -61,11 +71,22 @@ class WadlRestconfGenerator { this.module = module val destination = new File(path, '''«module.name».wadl''') - val fw = new OutputStreamWriter(buildContext.newFileOutputStream(destination), StandardCharsets.UTF_8) - val bw = new BufferedWriter(fw) - bw.append(application); - bw.close(); - fw.close(); + var OutputStreamWriter fw + var BufferedWriter bw + try { + fw = new OutputStreamWriter(buildContext.newFileOutputStream(destination), StandardCharsets.UTF_8) + bw = new BufferedWriter(fw) + bw.append(application); + } catch (IOException e) { + LOG.error("Failed to emit file {}", destination, e); + } finally { + if (bw !== null) { + bw.close(); + } + if (fw !== null) { + fw.close(); + } + } result.add(destination) } } @@ -247,6 +268,8 @@ class WadlRestconfGenerator { ''' + @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD", + justification = "https://github.com/spotbugs/spotbugs/issues/811") private def boolean isListOrContainer(DataSchemaNode schemaNode) { return (schemaNode instanceof ListSchemaNode || schemaNode instanceof ContainerSchemaNode) } -- 2.36.6