aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2015-05-12 16:42:56 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2015-05-12 16:43:36 +0200
commit3cc93206c68a2c8fd37dec04698724bf5f845331 (patch)
tree4f4f222abadd85ba5748238393ec7be81a23363a /sonar-plugin-api
parent52f34d90b5c307c1cb73cc75b9f6ff18f0568405 (diff)
downloadsonarqube-3cc93206c68a2c8fd37dec04698724bf5f845331.tar.gz
sonarqube-3cc93206c68a2c8fd37dec04698724bf5f845331.zip
Use StandardCharsets instead of guava/commons-io
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/FileMetadata.java15
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/config/AesCipher.java4
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/config/Base64Cipher.java7
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/config/License.java4
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/database/model/MeasureModel.java14
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileParser.java4
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java4
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/utils/XpathParser.java8
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/utils/command/CommandExecutor.java4
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/FileMetadataTest.java70
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/batch/maven/MavenUtilsTest.java4
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/resources/InputFileUtilsTest.java15
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RulesDefinitionXmlLoaderTest.java16
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/utils/UriReaderTest.java10
14 files changed, 91 insertions, 88 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/FileMetadata.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/FileMetadata.java
index 19b101720a4..5badc62f7bf 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/FileMetadata.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/FileMetadata.java
@@ -19,14 +19,12 @@
*/
package org.sonar.api.batch.fs.internal;
-import org.sonar.api.BatchSide;
-
-import com.google.common.base.Charsets;
import com.google.common.primitives.Ints;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.io.ByteOrderMark;
import org.apache.commons.io.input.BOMInputStream;
+import org.sonar.api.BatchSide;
import org.sonar.api.CoreProperties;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
@@ -41,6 +39,7 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.List;
@@ -139,14 +138,14 @@ public class FileMetadata {
@Override
protected void newLine() {
sb.append(LINE_FEED);
- globalMd5Digest.update(sb.toString().getBytes(Charsets.UTF_8));
+ globalMd5Digest.update(sb.toString().getBytes(StandardCharsets.UTF_8));
sb.setLength(0);
}
@Override
protected void eof() {
if (sb.length() > 0) {
- globalMd5Digest.update(sb.toString().getBytes(Charsets.UTF_8));
+ globalMd5Digest.update(sb.toString().getBytes(StandardCharsets.UTF_8));
}
}
@@ -175,7 +174,7 @@ public class FileMetadata {
@Override
protected void newLine() {
- consumer.consume(line, sb.length() > 0 ? lineMd5Digest.digest(sb.toString().getBytes(Charsets.UTF_8)) : null);
+ consumer.consume(line, sb.length() > 0 ? lineMd5Digest.digest(sb.toString().getBytes(StandardCharsets.UTF_8)) : null);
sb.setLength(0);
line++;
}
@@ -183,7 +182,7 @@ public class FileMetadata {
@Override
protected void eof() {
if (this.line > 0) {
- consumer.consume(line, sb.length() > 0 ? lineMd5Digest.digest(sb.toString().getBytes(Charsets.UTF_8)) : null);
+ consumer.consume(line, sb.length() > 0 ? lineMd5Digest.digest(sb.toString().getBytes(StandardCharsets.UTF_8)) : null);
}
}
@@ -240,7 +239,7 @@ public class FileMetadata {
* For testing purpose
*/
public Metadata readMetadata(Reader reader) {
- LineCounter lineCounter = new LineCounter(new File("fromString"), Charsets.UTF_16);
+ LineCounter lineCounter = new LineCounter(new File("fromString"), StandardCharsets.UTF_16);
FileHashComputer fileHashComputer = new FileHashComputer();
LineOffsetCounter lineOffsetCounter = new LineOffsetCounter();
try {
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/AesCipher.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/AesCipher.java
index 27c747ced27..769f416fbd6 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/config/AesCipher.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/config/AesCipher.java
@@ -22,7 +22,6 @@ package org.sonar.api.config;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Throwables;
import org.apache.commons.codec.binary.Base64;
-import org.apache.commons.io.Charsets;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.CoreProperties;
@@ -34,6 +33,7 @@ import javax.crypto.spec.SecretKeySpec;
import java.io.File;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import java.security.Key;
import java.security.SecureRandom;
@@ -69,7 +69,7 @@ final class AesCipher extends Cipher {
javax.crypto.Cipher cipher = javax.crypto.Cipher.getInstance(CRYPTO_KEY);
cipher.init(javax.crypto.Cipher.DECRYPT_MODE, loadSecretFile());
byte[] cipherData = cipher.doFinal(Base64.decodeBase64(StringUtils.trim(encryptedText)));
- return new String(cipherData, Charsets.UTF_8);
+ return new String(cipherData, StandardCharsets.UTF_8);
} catch (Exception e) {
throw Throwables.propagate(e);
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/Base64Cipher.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/Base64Cipher.java
index 26f9212dc8c..ef3afd73a4a 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/config/Base64Cipher.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/config/Base64Cipher.java
@@ -19,17 +19,18 @@
*/
package org.sonar.api.config;
-import com.google.common.base.Charsets;
import org.apache.commons.codec.binary.Base64;
+import java.nio.charset.StandardCharsets;
+
final class Base64Cipher extends Cipher {
@Override
String encrypt(String clearText) {
- return Base64.encodeBase64String(clearText.getBytes(Charsets.UTF_8));
+ return Base64.encodeBase64String(clearText.getBytes(StandardCharsets.UTF_8));
}
@Override
String decrypt(String encryptedText) {
- return new String(Base64.decodeBase64(encryptedText), Charsets.UTF_8);
+ return new String(Base64.decodeBase64(encryptedText), StandardCharsets.UTF_8);
}
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/License.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/License.java
index 8760b8f8d2e..6f4a0e4779c 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/config/License.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/config/License.java
@@ -22,7 +22,6 @@ package org.sonar.api.config;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Maps;
import org.apache.commons.codec.binary.Base64;
-import org.apache.commons.io.Charsets;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.utils.DateUtils;
@@ -31,6 +30,7 @@ import javax.annotation.Nullable;
import java.io.IOException;
import java.io.StringReader;
+import java.nio.charset.StandardCharsets;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
@@ -125,7 +125,7 @@ public final class License {
}
public static License readBase64(String base64) {
- return readPlainText(new String(Base64.decodeBase64(base64.getBytes(Charsets.UTF_8)), Charsets.UTF_8));
+ return readPlainText(new String(Base64.decodeBase64(base64.getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8));
}
@VisibleForTesting
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/database/model/MeasureModel.java b/sonar-plugin-api/src/main/java/org/sonar/api/database/model/MeasureModel.java
index 8346966c5e4..4d9a29db93f 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/database/model/MeasureModel.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/database/model/MeasureModel.java
@@ -19,7 +19,6 @@
*/
package org.sonar.api.database.model;
-import com.google.common.base.Charsets;
import com.google.common.base.Throwables;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
@@ -28,9 +27,16 @@ import org.sonar.api.measures.Metric;
import org.sonar.api.rules.RulePriority;
import javax.annotation.CheckForNull;
-import javax.persistence.*;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Table;
import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
/**
* This class is the Hibernate model to store a measure in the DB
@@ -332,7 +338,7 @@ public class MeasureModel implements Cloneable {
}
if (metric.isDataType() && data != null) {
try {
- return new String(data, Charsets.UTF_8.name());
+ return new String(data, StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException e) {
// how is it possible to not support UTF-8 ?
Throwables.propagate(e);
@@ -352,7 +358,7 @@ public class MeasureModel implements Cloneable {
} else {
if (data.length() > TEXT_VALUE_LENGTH) {
this.textValue = null;
- this.data = data.getBytes(Charsets.UTF_8);
+ this.data = data.getBytes(StandardCharsets.UTF_8);
} else {
this.textValue = data;
this.data = null;
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 6ac3287dd6e..b900c25f69e 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,7 +19,6 @@
*/
package org.sonar.api.profiles;
-import com.google.common.base.Charsets;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.codehaus.staxmate.SMInputFactory;
@@ -37,6 +36,7 @@ import javax.xml.stream.XMLStreamException;
import java.io.InputStreamReader;
import java.io.Reader;
+import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
@@ -60,7 +60,7 @@ public class XMLProfileParser {
}
public RulesProfile parseResource(ClassLoader classloader, String xmlClassPath, ValidationMessages messages) {
- Reader reader = new InputStreamReader(classloader.getResourceAsStream(xmlClassPath), Charsets.UTF_8);
+ Reader reader = new InputStreamReader(classloader.getResourceAsStream(xmlClassPath), StandardCharsets.UTF_8);
try {
return parse(reader, messages);
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java
index 2535dcd72b9..4a22a4da474 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java
@@ -19,7 +19,6 @@
*/
package org.sonar.api.server.ws;
-import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
@@ -36,6 +35,7 @@ import javax.annotation.concurrent.Immutable;
import java.io.IOException;
import java.net.URL;
+import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
@@ -455,7 +455,7 @@ public interface WebService extends Definable<WebService.Context> {
public String responseExampleAsString() {
try {
if (responseExample != null) {
- return StringUtils.trim(IOUtils.toString(responseExample, Charsets.UTF_8));
+ return StringUtils.trim(IOUtils.toString(responseExample, StandardCharsets.UTF_8));
}
return null;
} catch (IOException e) {
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/XpathParser.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/XpathParser.java
index ea3ef78527a..d962fd2db03 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/XpathParser.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/XpathParser.java
@@ -19,7 +19,6 @@
*/
package org.sonar.api.utils;
-import org.apache.commons.io.Charsets;
import org.apache.commons.io.IOUtils;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
@@ -47,6 +46,7 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -97,7 +97,7 @@ public class XpathParser {
BufferedReader buffer = null;
try {
- buffer = new BufferedReader(new InputStreamReader(new FileInputStream(file), Charsets.UTF_8));
+ buffer = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8));
parse(buffer);
} catch (IOException e) {
@@ -111,7 +111,7 @@ public class XpathParser {
public void parse(InputStream stream) {
BufferedReader buffer = null;
try {
- buffer = new BufferedReader(new InputStreamReader(stream, Charsets.UTF_8));
+ buffer = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8));
parse(buffer);
} catch (IOException e) {
@@ -129,7 +129,7 @@ public class XpathParser {
public void parse(String xml) {
try {
String fixedXml = fixUnicodeChar(xml);
- doc = builder.parse(new ByteArrayInputStream(fixedXml.getBytes(Charsets.UTF_8)));
+ doc = builder.parse(new ByteArrayInputStream(fixedXml.getBytes(StandardCharsets.UTF_8)));
XPathFactory factory = XPathFactory.newInstance();
xpath = factory.newXPath();
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/command/CommandExecutor.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/command/CommandExecutor.java
index 0a094de7052..4c540b207a2 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/command/CommandExecutor.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/command/CommandExecutor.java
@@ -19,7 +19,6 @@
*/
package org.sonar.api.utils.command;
-import com.google.common.base.Charsets;
import com.google.common.io.Closeables;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
@@ -30,6 +29,7 @@ import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.nio.charset.StandardCharsets;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@@ -173,7 +173,7 @@ public class CommandExecutor {
@Override
public void run() {
- try (BufferedReader br = new BufferedReader(new InputStreamReader(is, Charsets.UTF_8))) {
+ try (BufferedReader br = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) {
String line;
while ((line = br.readLine()) != null) {
consumeLine(line);
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/FileMetadataTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/FileMetadataTest.java
index e26451cf82d..0d00ba28793 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/FileMetadataTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/FileMetadataTest.java
@@ -19,7 +19,6 @@
*/
package org.sonar.api.batch.fs.internal;
-import com.google.common.base.Charsets;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.io.FileUtils;
import org.junit.Rule;
@@ -34,6 +33,7 @@ import javax.annotation.Nullable;
import java.io.File;
import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import static org.apache.commons.codec.digest.DigestUtils.md5Hex;
import static org.assertj.core.api.Assertions.assertThat;
@@ -55,7 +55,7 @@ public class FileMetadataTest {
File tempFile = temp.newFile();
FileUtils.touch(tempFile);
- FileMetadata.Metadata metadata = new FileMetadata().readMetadata(tempFile, Charsets.UTF_8);
+ FileMetadata.Metadata metadata = new FileMetadata().readMetadata(tempFile, StandardCharsets.UTF_8);
assertThat(metadata.lines).isEqualTo(1);
assertThat(metadata.nonBlankLines).isEqualTo(0);
assertThat(metadata.hash).isNotEmpty();
@@ -66,9 +66,9 @@ public class FileMetadataTest {
@Test
public void windows_without_latest_eol() throws Exception {
File tempFile = temp.newFile();
- FileUtils.write(tempFile, "foo\r\nbar\r\nbaz", Charsets.UTF_8, true);
+ FileUtils.write(tempFile, "foo\r\nbar\r\nbaz", StandardCharsets.UTF_8, true);
- FileMetadata.Metadata metadata = new FileMetadata().readMetadata(tempFile, Charsets.UTF_8);
+ FileMetadata.Metadata metadata = new FileMetadata().readMetadata(tempFile, StandardCharsets.UTF_8);
assertThat(metadata.lines).isEqualTo(3);
assertThat(metadata.nonBlankLines).isEqualTo(3);
assertThat(metadata.hash).isEqualTo(md5Hex("foo\nbar\nbaz"));
@@ -81,7 +81,7 @@ public class FileMetadataTest {
File tempFile = temp.newFile();
FileUtils.write(tempFile, "marker´s\n", Charset.forName("cp1252"));
- FileMetadata.Metadata metadata = new FileMetadata().readMetadata(tempFile, Charsets.UTF_8);
+ FileMetadata.Metadata metadata = new FileMetadata().readMetadata(tempFile, StandardCharsets.UTF_8);
assertThat(metadata.lines).isEqualTo(2);
assertThat(metadata.hash).isEqualTo(md5Hex("marker\ufffds\n"));
assertThat(metadata.originalLineOffsets).containsOnly(0, 9);
@@ -90,9 +90,9 @@ public class FileMetadataTest {
@Test
public void non_ascii_utf_8() throws Exception {
File tempFile = temp.newFile();
- FileUtils.write(tempFile, "föo\r\nbàr\r\n\u1D11Ebaßz\r\n", Charsets.UTF_8, true);
+ FileUtils.write(tempFile, "föo\r\nbàr\r\n\u1D11Ebaßz\r\n", StandardCharsets.UTF_8, true);
- FileMetadata.Metadata metadata = new FileMetadata().readMetadata(tempFile, Charsets.UTF_8);
+ FileMetadata.Metadata metadata = new FileMetadata().readMetadata(tempFile, StandardCharsets.UTF_8);
assertThat(metadata.lines).isEqualTo(4);
assertThat(metadata.nonBlankLines).isEqualTo(3);
assertThat(metadata.hash).isEqualTo(md5Hex("föo\nbàr\n\u1D11Ebaßz\n"));
@@ -102,9 +102,9 @@ public class FileMetadataTest {
@Test
public void non_ascii_utf_16() throws Exception {
File tempFile = temp.newFile();
- FileUtils.write(tempFile, "föo\r\nbàr\r\n\u1D11Ebaßz\r\n", Charsets.UTF_16, true);
+ FileUtils.write(tempFile, "föo\r\nbàr\r\n\u1D11Ebaßz\r\n", StandardCharsets.UTF_16, true);
- FileMetadata.Metadata metadata = new FileMetadata().readMetadata(tempFile, Charsets.UTF_16);
+ FileMetadata.Metadata metadata = new FileMetadata().readMetadata(tempFile, StandardCharsets.UTF_16);
assertThat(metadata.lines).isEqualTo(4);
assertThat(metadata.nonBlankLines).isEqualTo(3);
assertThat(metadata.hash).isEqualTo(md5Hex("föo\nbàr\n\u1D11Ebaßz\n"));
@@ -114,9 +114,9 @@ public class FileMetadataTest {
@Test
public void unix_without_latest_eol() throws Exception {
File tempFile = temp.newFile();
- FileUtils.write(tempFile, "foo\nbar\nbaz", Charsets.UTF_8, true);
+ FileUtils.write(tempFile, "foo\nbar\nbaz", StandardCharsets.UTF_8, true);
- FileMetadata.Metadata metadata = new FileMetadata().readMetadata(tempFile, Charsets.UTF_8);
+ FileMetadata.Metadata metadata = new FileMetadata().readMetadata(tempFile, StandardCharsets.UTF_8);
assertThat(metadata.lines).isEqualTo(3);
assertThat(metadata.nonBlankLines).isEqualTo(3);
assertThat(metadata.hash).isEqualTo(md5Hex("foo\nbar\nbaz"));
@@ -127,9 +127,9 @@ public class FileMetadataTest {
@Test
public void unix_with_latest_eol() throws Exception {
File tempFile = temp.newFile();
- FileUtils.write(tempFile, "foo\nbar\nbaz\n", Charsets.UTF_8, true);
+ FileUtils.write(tempFile, "foo\nbar\nbaz\n", StandardCharsets.UTF_8, true);
- FileMetadata.Metadata metadata = new FileMetadata().readMetadata(tempFile, Charsets.UTF_8);
+ FileMetadata.Metadata metadata = new FileMetadata().readMetadata(tempFile, StandardCharsets.UTF_8);
assertThat(metadata.lines).isEqualTo(4);
assertThat(metadata.nonBlankLines).isEqualTo(3);
assertThat(metadata.hash).isEqualTo(md5Hex("foo\nbar\nbaz\n"));
@@ -140,9 +140,9 @@ public class FileMetadataTest {
@Test
public void mix_of_newlines_with_latest_eol() throws Exception {
File tempFile = temp.newFile();
- FileUtils.write(tempFile, "foo\nbar\r\nbaz\n", Charsets.UTF_8, true);
+ FileUtils.write(tempFile, "foo\nbar\r\nbaz\n", StandardCharsets.UTF_8, true);
- FileMetadata.Metadata metadata = new FileMetadata().readMetadata(tempFile, Charsets.UTF_8);
+ FileMetadata.Metadata metadata = new FileMetadata().readMetadata(tempFile, StandardCharsets.UTF_8);
assertThat(metadata.lines).isEqualTo(4);
assertThat(metadata.nonBlankLines).isEqualTo(3);
assertThat(metadata.hash).isEqualTo(md5Hex("foo\nbar\nbaz\n"));
@@ -152,9 +152,9 @@ public class FileMetadataTest {
@Test
public void several_new_lines() throws Exception {
File tempFile = temp.newFile();
- FileUtils.write(tempFile, "foo\n\n\nbar", Charsets.UTF_8, true);
+ FileUtils.write(tempFile, "foo\n\n\nbar", StandardCharsets.UTF_8, true);
- FileMetadata.Metadata metadata = new FileMetadata().readMetadata(tempFile, Charsets.UTF_8);
+ FileMetadata.Metadata metadata = new FileMetadata().readMetadata(tempFile, StandardCharsets.UTF_8);
assertThat(metadata.lines).isEqualTo(4);
assertThat(metadata.nonBlankLines).isEqualTo(2);
assertThat(metadata.hash).isEqualTo(md5Hex("foo\n\n\nbar"));
@@ -164,9 +164,9 @@ public class FileMetadataTest {
@Test
public void mix_of_newlines_without_latest_eol() throws Exception {
File tempFile = temp.newFile();
- FileUtils.write(tempFile, "foo\nbar\r\nbaz", Charsets.UTF_8, true);
+ FileUtils.write(tempFile, "foo\nbar\r\nbaz", StandardCharsets.UTF_8, true);
- FileMetadata.Metadata metadata = new FileMetadata().readMetadata(tempFile, Charsets.UTF_8);
+ FileMetadata.Metadata metadata = new FileMetadata().readMetadata(tempFile, StandardCharsets.UTF_8);
assertThat(metadata.lines).isEqualTo(3);
assertThat(metadata.nonBlankLines).isEqualTo(3);
assertThat(metadata.hash).isEqualTo(md5Hex("foo\nbar\nbaz"));
@@ -176,9 +176,9 @@ public class FileMetadataTest {
@Test
public void start_with_newline() throws Exception {
File tempFile = temp.newFile();
- FileUtils.write(tempFile, "\nfoo\nbar\r\nbaz", Charsets.UTF_8, true);
+ FileUtils.write(tempFile, "\nfoo\nbar\r\nbaz", StandardCharsets.UTF_8, true);
- FileMetadata.Metadata metadata = new FileMetadata().readMetadata(tempFile, Charsets.UTF_8);
+ FileMetadata.Metadata metadata = new FileMetadata().readMetadata(tempFile, StandardCharsets.UTF_8);
assertThat(metadata.lines).isEqualTo(4);
assertThat(metadata.nonBlankLines).isEqualTo(3);
assertThat(metadata.hash).isEqualTo(md5Hex("\nfoo\nbar\nbaz"));
@@ -188,9 +188,9 @@ public class FileMetadataTest {
@Test
public void start_with_bom() throws Exception {
File tempFile = temp.newFile();
- FileUtils.write(tempFile, "\uFEFFfoo\nbar\r\nbaz", Charsets.UTF_8, true);
+ FileUtils.write(tempFile, "\uFEFFfoo\nbar\r\nbaz", StandardCharsets.UTF_8, true);
- FileMetadata.Metadata metadata = new FileMetadata().readMetadata(tempFile, Charsets.UTF_8);
+ FileMetadata.Metadata metadata = new FileMetadata().readMetadata(tempFile, StandardCharsets.UTF_8);
assertThat(metadata.lines).isEqualTo(3);
assertThat(metadata.nonBlankLines).isEqualTo(3);
assertThat(metadata.hash).isEqualTo(md5Hex("foo\nbar\nbaz"));
@@ -200,11 +200,11 @@ public class FileMetadataTest {
@Test
public void ignore_whitespace_when_computing_line_hashes() throws Exception {
File tempFile = temp.newFile();
- FileUtils.write(tempFile, " foo\nb ar\r\nbaz \t", Charsets.UTF_8, true);
+ FileUtils.write(tempFile, " foo\nb ar\r\nbaz \t", StandardCharsets.UTF_8, true);
DefaultInputFile f = new DefaultInputFile("foo", tempFile.getName());
f.setModuleBaseDir(tempFile.getParentFile().toPath());
- f.setCharset(Charsets.UTF_8);
+ f.setCharset(StandardCharsets.UTF_8);
FileMetadata.computeLineHashesForIssueTracking(f, new LineHashConsumer() {
@Override
@@ -229,11 +229,11 @@ public class FileMetadataTest {
@Test
public void dont_fail_on_empty_file() throws Exception {
File tempFile = temp.newFile();
- FileUtils.write(tempFile, "", Charsets.UTF_8, true);
+ FileUtils.write(tempFile, "", StandardCharsets.UTF_8, true);
DefaultInputFile f = new DefaultInputFile("foo", tempFile.getName());
f.setModuleBaseDir(tempFile.getParentFile().toPath());
- f.setCharset(Charsets.UTF_8);
+ f.setCharset(StandardCharsets.UTF_8);
FileMetadata.computeLineHashesForIssueTracking(f, new LineHashConsumer() {
@Override
@@ -257,24 +257,24 @@ public class FileMetadataTest {
thrown.expect(IllegalStateException.class);
thrown.expectMessage("Fail to read file '" + file.getAbsolutePath() + "' with encoding 'UTF-8'");
- new FileMetadata().readMetadata(file, Charsets.UTF_8);
+ new FileMetadata().readMetadata(file, StandardCharsets.UTF_8);
}
@Test
public void line_feed_is_included_into_hash() throws Exception {
File file1 = temp.newFile();
- FileUtils.write(file1, "foo\nbar\n", Charsets.UTF_8, true);
+ FileUtils.write(file1, "foo\nbar\n", StandardCharsets.UTF_8, true);
// same as file1, except an additional return carriage
File file1a = temp.newFile();
- FileUtils.write(file1a, "foo\r\nbar\n", Charsets.UTF_8, true);
+ FileUtils.write(file1a, "foo\r\nbar\n", StandardCharsets.UTF_8, true);
File file2 = temp.newFile();
- FileUtils.write(file2, "foo\nbar", Charsets.UTF_8, true);
+ FileUtils.write(file2, "foo\nbar", StandardCharsets.UTF_8, true);
- String hash1 = new FileMetadata().readMetadata(file1, Charsets.UTF_8).hash;
- String hash1a = new FileMetadata().readMetadata(file1a, Charsets.UTF_8).hash;
- String hash2 = new FileMetadata().readMetadata(file2, Charsets.UTF_8).hash;
+ String hash1 = new FileMetadata().readMetadata(file1, StandardCharsets.UTF_8).hash;
+ String hash1a = new FileMetadata().readMetadata(file1a, StandardCharsets.UTF_8).hash;
+ String hash2 = new FileMetadata().readMetadata(file2, StandardCharsets.UTF_8).hash;
assertThat(hash1).isEqualTo(hash1a);
assertThat(hash1).isNotEqualTo(hash2);
}
@@ -283,7 +283,7 @@ public class FileMetadataTest {
public void binary_file_with_unmappable_character() throws Exception {
File woff = new File(this.getClass().getResource("glyphicons-halflings-regular.woff").toURI());
- FileMetadata.Metadata metadata = new FileMetadata().readMetadata(woff, Charsets.UTF_8);
+ FileMetadata.Metadata metadata = new FileMetadata().readMetadata(woff, StandardCharsets.UTF_8);
assertThat(metadata.lines).isEqualTo(135);
assertThat(metadata.nonBlankLines).isEqualTo(134);
assertThat(metadata.hash).isNotEmpty();
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/maven/MavenUtilsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/maven/MavenUtilsTest.java
index 1eb9b637281..5f2f465bc2b 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/maven/MavenUtilsTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/maven/MavenUtilsTest.java
@@ -19,13 +19,13 @@
*/
package org.sonar.api.batch.maven;
-import com.google.common.base.Charsets;
import org.apache.maven.project.MavenProject;
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.test.MavenTestUtils;
import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
@@ -59,6 +59,6 @@ public class MavenUtilsTest {
@Test
public void testSourceEncoding() {
MavenProject pom = MavenTestUtils.loadPom("/org/sonar/api/batch/maven/MavenPomWithSourceEncoding.xml");
- assertEquals(MavenUtils.getSourceCharset(pom), Charsets.UTF_16);
+ assertEquals(MavenUtils.getSourceCharset(pom), StandardCharsets.UTF_16);
}
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/resources/InputFileUtilsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/resources/InputFileUtilsTest.java
index 630b9e6007c..13c9a18602e 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/resources/InputFileUtilsTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/resources/InputFileUtilsTest.java
@@ -19,22 +19,19 @@
*/
package org.sonar.api.resources;
-import com.google.common.io.Closeables;
-
-import org.junit.rules.ExpectedException;
-
-import org.junit.Rule;
-
-import com.google.common.base.Charsets;
import com.google.common.io.ByteStreams;
+import com.google.common.io.Closeables;
import com.google.common.io.Files;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;
@@ -168,12 +165,12 @@ public class InputFileUtilsTest {
static void write(String content, File file) throws IOException {
file.getParentFile().mkdirs();
- Files.write(content, file, Charsets.UTF_8);
+ Files.write(content, file, StandardCharsets.UTF_8);
}
static String read(InputStream input) throws IOException {
try {
- return new String(ByteStreams.toByteArray(input), Charsets.UTF_8.displayName());
+ return new String(ByteStreams.toByteArray(input), StandardCharsets.UTF_8.displayName());
} finally {
Closeables.closeQuietly(input);
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RulesDefinitionXmlLoaderTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RulesDefinitionXmlLoaderTest.java
index 3c372bd19fd..a7c96cd4206 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RulesDefinitionXmlLoaderTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RulesDefinitionXmlLoaderTest.java
@@ -19,7 +19,6 @@
*/
package org.sonar.api.server.rule;
-import com.google.common.base.Charsets;
import org.apache.commons.io.IOUtils;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -28,6 +27,7 @@ import org.sonar.api.rule.Severity;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
import static org.assertj.core.api.Assertions.assertThat;
@@ -47,7 +47,7 @@ public class RulesDefinitionXmlLoaderTest {
@Test
public void parse_xml() {
InputStream input = getClass().getResourceAsStream("/org/sonar/api/server/rule/RulesDefinitionXmlLoaderTest/rules.xml");
- RulesDefinition.Repository repository = load(input, Charsets.UTF_8.name());
+ RulesDefinition.Repository repository = load(input, StandardCharsets.UTF_8.name());
assertThat(repository.rules()).hasSize(2);
RulesDefinition.Rule rule = repository.rule("complete");
@@ -78,19 +78,19 @@ public class RulesDefinitionXmlLoaderTest {
@Test
public void fail_if_missing_rule_key() {
thrown.expect(IllegalStateException.class);
- load(IOUtils.toInputStream("<rules><rule><name>Foo</name></rule></rules>"), Charsets.UTF_8.name());
+ load(IOUtils.toInputStream("<rules><rule><name>Foo</name></rule></rules>"), StandardCharsets.UTF_8.name());
}
@Test
public void fail_if_missing_property_key() {
thrown.expect(IllegalStateException.class);
- load(IOUtils.toInputStream("<rules><rule><key>foo</key><name>Foo</name><param></param></rule></rules>"), Charsets.UTF_8.name());
+ load(IOUtils.toInputStream("<rules><rule><key>foo</key><name>Foo</name><param></param></rule></rules>"), StandardCharsets.UTF_8.name());
}
@Test
public void fail_on_invalid_rule_parameter_type() {
thrown.expect(IllegalStateException.class);
- load(IOUtils.toInputStream("<rules><rule><key>foo</key><name>Foo</name><param><key>key</key><type>INVALID</type></param></rule></rules>"), Charsets.UTF_8.name());
+ load(IOUtils.toInputStream("<rules><rule><key>foo</key><name>Foo</name><param><key>key</key><type>INVALID</type></param></rule></rules>"), StandardCharsets.UTF_8.name());
}
@Test
@@ -99,13 +99,13 @@ public class RulesDefinitionXmlLoaderTest {
thrown.expectMessage("XML is not valid");
InputStream input = getClass().getResourceAsStream("/org/sonar/api/server/rule/RulesDefinitionXmlLoaderTest/invalid.xml");
- load(input, Charsets.UTF_8.name());
+ load(input, StandardCharsets.UTF_8.name());
}
@Test
public void test_utf8_encoding() throws UnsupportedEncodingException {
InputStream input = getClass().getResourceAsStream("/org/sonar/api/server/rule/RulesDefinitionXmlLoaderTest/utf8.xml");
- RulesDefinition.Repository repository = load(input, Charsets.UTF_8.name());
+ RulesDefinition.Repository repository = load(input, StandardCharsets.UTF_8.name());
assertThat(repository.rules()).hasSize(1);
RulesDefinition.Rule rule = repository.rules().get(0);
@@ -120,7 +120,7 @@ public class RulesDefinitionXmlLoaderTest {
public void support_deprecated_format() {
// the deprecated format uses some attributes instead of nodes
InputStream input = getClass().getResourceAsStream("/org/sonar/api/server/rule/RulesDefinitionXmlLoaderTest/deprecated.xml");
- RulesDefinition.Repository repository = load(input, Charsets.UTF_8.name());
+ RulesDefinition.Repository repository = load(input, StandardCharsets.UTF_8.name());
assertThat(repository.rules()).hasSize(1);
RulesDefinition.Rule rule = repository.rules().get(0);
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/UriReaderTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/UriReaderTest.java
index c7f21de758f..e89e1c6399f 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/UriReaderTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/UriReaderTest.java
@@ -19,7 +19,6 @@
*/
package org.sonar.api.utils;
-import com.google.common.base.Charsets;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -27,6 +26,7 @@ import org.junit.rules.ExpectedException;
import java.net.URI;
import java.net.URISyntaxException;
+import java.nio.charset.StandardCharsets;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
@@ -54,7 +54,7 @@ public class UriReaderTest {
@Test
public void file_readString() {
UriReader uriReader = new UriReader(new UriReader.SchemeProcessor[0]);
- assertThat(uriReader.readString(testFile, Charsets.UTF_8)).isEqualTo("in foo");
+ assertThat(uriReader.readString(testFile, StandardCharsets.UTF_8)).isEqualTo("in foo");
}
@Test
@@ -67,7 +67,7 @@ public class UriReaderTest {
public void file_readString_fails_if_file_not_found() throws Exception {
thrown.expect(RuntimeException.class);
UriReader uriReader = new UriReader(new UriReader.SchemeProcessor[0]);
- uriReader.readString(new URI("file:/notfound"), Charsets.UTF_8);
+ uriReader.readString(new URI("file:/notfound"), StandardCharsets.UTF_8);
}
@Test
@@ -96,8 +96,8 @@ public class UriReaderTest {
@Test
public void register_processors() throws Exception {
UriReader.SchemeProcessor processor = mock(UriReader.SchemeProcessor.class);
- when(processor.getSupportedSchemes()).thenReturn(new String[]{"ftp"});
- UriReader uriReader = new UriReader(new UriReader.SchemeProcessor[]{processor});
+ when(processor.getSupportedSchemes()).thenReturn(new String[] {"ftp"});
+ UriReader uriReader = new UriReader(new UriReader.SchemeProcessor[] {processor});
assertThat(uriReader.searchForSupportedProcessor(new URI("ftp://sonarsource.org"))).isNotNull();
}