aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2020-03-19 16:23:03 +0100
committersonartech <sonartech@sonarsource.com>2020-03-23 20:03:41 +0000
commitd393e4175c28965f5ab40a6dc6cf95e1f24249c7 (patch)
treee0519c018668b2b2d7f22c332a72888126ff723f /sonar-plugin-api
parenta5e56c8d403ba0bfdb36e94acb8def5ceb065524 (diff)
downloadsonarqube-d393e4175c28965f5ab40a6dc6cf95e1f24249c7.tar.gz
sonarqube-d393e4175c28965f5ab40a6dc6cf95e1f24249c7.zip
Decrease coupling with commons-io
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileParser.java10
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/rules/XMLRuleParser.java4
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/utils/ZipUtils.java5
3 files changed, 9 insertions, 10 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileParser.java b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileParser.java
index a9d8999e4f9..7092a79eba9 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileParser.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileParser.java
@@ -19,6 +19,7 @@
*/
package org.sonar.api.profiles;
+import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.StandardCharsets;
@@ -26,7 +27,6 @@ import java.util.HashMap;
import java.util.Map;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
-import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.codehaus.staxmate.SMInputFactory;
import org.codehaus.staxmate.in.SMHierarchicCursor;
@@ -63,12 +63,10 @@ public class XMLProfileParser {
}
public RulesProfile parseResource(ClassLoader classloader, String xmlClassPath, ValidationMessages messages) {
- Reader reader = new InputStreamReader(classloader.getResourceAsStream(xmlClassPath), StandardCharsets.UTF_8);
- try {
+ try (Reader reader = new InputStreamReader(classloader.getResourceAsStream(xmlClassPath), StandardCharsets.UTF_8)) {
return parse(reader, messages);
-
- } finally {
- IOUtils.closeQuietly(reader);
+ } catch (IOException e) {
+ throw new IllegalStateException("Unable to close stream", e);
}
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/rules/XMLRuleParser.java b/sonar-plugin-api/src/main/java/org/sonar/api/rules/XMLRuleParser.java
index 2e916538334..a74c83529b8 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/rules/XMLRuleParser.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/rules/XMLRuleParser.java
@@ -24,13 +24,13 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
+import java.nio.file.Files;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
-import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.codehaus.staxmate.SMInputFactory;
import org.codehaus.staxmate.in.SMHierarchicCursor;
@@ -54,7 +54,7 @@ public final class XMLRuleParser {
private static final Map<String, String> TYPE_MAP = typeMapWithDeprecatedValues();
public List<Rule> parse(File file) {
- try (Reader reader = new InputStreamReader(FileUtils.openInputStream(file), UTF_8)) {
+ try (Reader reader = new InputStreamReader(Files.newInputStream(file.toPath()), UTF_8)) {
return parse(reader);
} catch (IOException e) {
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/ZipUtils.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/ZipUtils.java
index 46d4c4288a9..10323340055 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/ZipUtils.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/ZipUtils.java
@@ -26,6 +26,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Enumeration;
import java.util.function.Predicate;
@@ -175,8 +176,8 @@ public final class ZipUtils {
}
public static void zipDir(File dir, File zip) throws IOException {
- try (OutputStream out = FileUtils.openOutputStream(zip);
- ZipOutputStream zout = new ZipOutputStream(out)) {
+ try (OutputStream out = Files.newOutputStream(zip.toPath());
+ ZipOutputStream zout = new ZipOutputStream(out)) {
doZipDir(dir, zout);
}
}