From 8c522f2a8f59bfe96112e1cf5f8da5e75f156c63 Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Wed, 4 Mar 2015 17:56:31 +0100 Subject: [PATCH] Fix Javadoc and add useful method using Charset for RulesDefinitionXmlLoader --- .../server/rule/RulesDefinitionXmlLoader.java | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinitionXmlLoader.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinitionXmlLoader.java index 72e2b545f06..55612d860aa 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinitionXmlLoader.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinitionXmlLoader.java @@ -19,7 +19,6 @@ */ package org.sonar.api.server.rule; -import com.google.common.io.Closeables; import org.apache.commons.lang.StringUtils; import org.codehaus.staxmate.SMInputFactory; import org.codehaus.staxmate.in.SMHierarchicCursor; @@ -31,10 +30,12 @@ import org.sonar.check.Cardinality; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamException; + import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; +import java.nio.charset.Charset; import java.util.ArrayList; import java.util.List; @@ -57,10 +58,10 @@ import java.util.List; * <severity>BLOCKER</severity> * <cardinality>MULTIPLE</cardinality> * <status>BETA</status> + * <tag>style</tag> + * <tag>security</tag> * <param> * <key>the-param-key</key> - * <tag>style</tag> - * <tag>security</tag> * <description> * <![CDATA[the param-description]]> * </description> @@ -83,16 +84,17 @@ import java.util.List; public class RulesDefinitionXmlLoader implements ServerComponent { public void load(RulesDefinition.NewRepository repo, InputStream input, String encoding) { - Reader reader = null; - try { - reader = new InputStreamReader(input, encoding); - load(repo, reader); + load(repo, input, Charset.forName(encoding)); + } + /** + * @since 5.1 + */ + public void load(RulesDefinition.NewRepository repo, InputStream input, Charset charset) { + try (Reader reader = new InputStreamReader(input, charset)) { + load(repo, reader); } catch (IOException e) { - throw new IllegalStateException("Fail to load XML file", e); - - } finally { - Closeables.closeQuietly(reader); + throw new IllegalStateException("Error while reading XML rules definition for repository " + repo.key(), e); } } -- 2.39.5