]> source.dussan.org Git - sonarqube.git/commitdiff
Use StandardCharsets instead of guava/commons-io
authorJulien HENRY <julien.henry@sonarsource.com>
Tue, 12 May 2015 14:42:56 +0000 (16:42 +0200)
committerJulien HENRY <julien.henry@sonarsource.com>
Tue, 12 May 2015 14:43:36 +0000 (16:43 +0200)
29 files changed:
sonar-batch/src/main/java/org/sonar/batch/mediumtest/BatchMediumTester.java
sonar-batch/src/main/java/org/sonar/batch/report/SourcePublisher.java
sonar-batch/src/main/java/org/sonar/batch/scan/report/JSONReport.java
sonar-batch/src/test/java/org/sonar/batch/bootstrap/ServerClientTest.java
sonar-batch/src/test/java/org/sonar/batch/issue/ignore/scanner/IssueExclusionsLoaderTest.java
sonar-batch/src/test/java/org/sonar/batch/issue/ignore/scanner/IssueExclusionsRegexpScannerTest.java
sonar-batch/src/test/java/org/sonar/batch/issue/tracking/IssueTrackingDecoratorTest.java
sonar-batch/src/test/java/org/sonar/batch/issue/tracking/IssueTrackingTest.java
sonar-batch/src/test/java/org/sonar/batch/issue/tracking/SourceHashHolderTest.java
sonar-batch/src/test/java/org/sonar/batch/mediumtest/dependency/DependencyMediumTest.java
sonar-batch/src/test/java/org/sonar/batch/mediumtest/fs/RandomFsAccessMediumTest.java
sonar-batch/src/test/java/org/sonar/batch/report/SourcePublisherTest.java
sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputFileBuilderTest.java
sonar-batch/src/test/java/org/sonar/batch/scan/filesystem/InputPathCacheTest.java
sonar-batch/src/test/java/org/sonar/batch/source/CodeColorizersTest.java
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/FileMetadata.java
sonar-plugin-api/src/main/java/org/sonar/api/config/AesCipher.java
sonar-plugin-api/src/main/java/org/sonar/api/config/Base64Cipher.java
sonar-plugin-api/src/main/java/org/sonar/api/config/License.java
sonar-plugin-api/src/main/java/org/sonar/api/database/model/MeasureModel.java
sonar-plugin-api/src/main/java/org/sonar/api/profiles/XMLProfileParser.java
sonar-plugin-api/src/main/java/org/sonar/api/server/ws/WebService.java
sonar-plugin-api/src/main/java/org/sonar/api/utils/XpathParser.java
sonar-plugin-api/src/main/java/org/sonar/api/utils/command/CommandExecutor.java
sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/FileMetadataTest.java
sonar-plugin-api/src/test/java/org/sonar/api/batch/maven/MavenUtilsTest.java
sonar-plugin-api/src/test/java/org/sonar/api/resources/InputFileUtilsTest.java
sonar-plugin-api/src/test/java/org/sonar/api/server/rule/RulesDefinitionXmlLoaderTest.java
sonar-plugin-api/src/test/java/org/sonar/api/utils/UriReaderTest.java

index 35765f96fb902935643e42e350985cf3fd3e62e5..8e38c2031fe1768e18a64a4982c651b4d757975f 100644 (file)
@@ -21,7 +21,6 @@ package org.sonar.batch.mediumtest;
 
 import com.google.common.base.Function;
 import com.google.common.io.Files;
-import org.apache.commons.io.Charsets;
 import org.sonar.api.CoreProperties;
 import org.sonar.api.SonarPlugin;
 import org.sonar.api.batch.bootstrap.ProjectReactor;
@@ -47,6 +46,7 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.InputStreamReader;
 import java.io.Reader;
+import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;
@@ -176,7 +176,7 @@ public class BatchMediumTester {
 
   public TaskBuilder newScanTask(File sonarProps) {
     Properties prop = new Properties();
-    try (Reader reader = new InputStreamReader(new FileInputStream(sonarProps), Charsets.UTF_8)) {
+    try (Reader reader = new InputStreamReader(new FileInputStream(sonarProps), StandardCharsets.UTF_8)) {
       prop.load(reader);
     } catch (Exception e) {
       throw new IllegalStateException("Unable to read configuration file", e);
index 8f6b7f3ffb57e254cdd19c0b7ed08c9e92f32302..bd89b7dfe2fe1a96055e07e7953290961f0981d1 100644 (file)
@@ -19,7 +19,6 @@
  */
 package org.sonar.batch.report;
 
-import com.google.common.base.Charsets;
 import org.apache.commons.io.ByteOrderMark;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.io.input.BOMInputStream;
@@ -28,7 +27,13 @@ import org.sonar.batch.index.BatchResource;
 import org.sonar.batch.index.ResourceCache;
 import org.sonar.batch.protocol.output.BatchReportWriter;
 
-import java.io.*;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.nio.charset.StandardCharsets;
 
 public class SourcePublisher implements ReportPublisherStep {
 
@@ -53,10 +58,10 @@ public class SourcePublisher implements ReportPublisherStep {
         BufferedReader reader = new BufferedReader(new InputStreamReader(bomIn, inputFile.charset()))) {
         String lineStr = reader.readLine();
         while (lineStr != null) {
-          IOUtils.write(lineStr, output, Charsets.UTF_8);
+          IOUtils.write(lineStr, output, StandardCharsets.UTF_8);
           line++;
           if (line < inputFile.lines()) {
-            IOUtils.write("\n", output, Charsets.UTF_8);
+            IOUtils.write("\n", output, StandardCharsets.UTF_8);
           }
           lineStr = reader.readLine();
         }
index 11b8be7a45696dc0183695cd67dba1b2e45b96d9..e2959d9352d3e36963da372cc0bf06a5a6b1772c 100644 (file)
@@ -20,7 +20,6 @@
 package org.sonar.batch.scan.report;
 
 import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Charsets;
 import org.apache.commons.lang.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -52,6 +51,7 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStreamWriter;
 import java.io.Writer;
+import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Set;
@@ -102,7 +102,7 @@ public class JSONReport implements Reporter {
     File exportFile = new File(fileSystem.workDir(), exportPath);
 
     LOG.info("Export issues to " + exportFile.getAbsolutePath());
-    try (Writer output = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(exportFile), Charsets.UTF_8))) {
+    try (Writer output = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(exportFile), StandardCharsets.UTF_8))) {
       writeJson(output);
 
     } catch (IOException e) {
index 2e13a5a9481f4c69ffe33d2b2f5fa9bd7cf055c6..b50d3643887dbc95ac0a3c554a764740d61fe867 100644 (file)
@@ -19,7 +19,6 @@
  */
 package org.sonar.batch.bootstrap;
 
-import com.google.common.base.Charsets;
 import com.google.common.io.Files;
 import org.apache.commons.io.IOUtils;
 import org.eclipse.jetty.server.Handler;
@@ -39,6 +38,7 @@ import javax.servlet.http.HttpServletResponse;
 
 import java.io.File;
 import java.io.IOException;
+import java.nio.charset.StandardCharsets;
 
 import static javax.servlet.http.HttpServletResponse.SC_OK;
 import static org.apache.commons.io.IOUtils.write;
@@ -99,7 +99,7 @@ public class ServerClientTest {
 
     File file = temp.newFile();
     newServerClient().download("/foo", file);
-    assertThat(Files.toString(file, Charsets.UTF_8)).isEqualTo("this is the content");
+    assertThat(Files.toString(file, StandardCharsets.UTF_8)).isEqualTo("this is the content");
   }
 
   @Test
index 5bd352f2e623e24e52e3af0441bd9bfb3ce4628c..b213103a1b5c7b7c7608561d020a52aa236e01a8 100644 (file)
@@ -38,7 +38,7 @@ import org.sonar.batch.issue.ignore.pattern.PatternMatcher;
 import java.io.File;
 import java.io.IOException;
 
-import static com.google.common.base.Charsets.UTF_8;
+import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.verify;
index 10d5241c5a32c74af25671548caf8672e7945a03..58bdb434ca857c9b73d1064ebd2fa56994aa7c23 100644 (file)
@@ -35,7 +35,7 @@ import java.io.File;
 import java.util.Arrays;
 import java.util.Set;
 
-import static com.google.common.base.Charsets.UTF_8;
+import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.verifyNoMoreInteractions;
index bcbb361f976cd76757fb42e3110b7142bba907b7..d09c7908d20735684abcafda0d3eae60136ee78a 100644 (file)
@@ -19,7 +19,6 @@
  */
 package org.sonar.batch.issue.tracking;
 
-import com.google.common.base.Charsets;
 import org.apache.commons.codec.digest.DigestUtils;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang.StringUtils;
@@ -52,6 +51,7 @@ import org.sonar.core.issue.workflow.IssueWorkflow;
 import org.sonar.java.api.JavaClass;
 
 import java.io.IOException;
+import java.nio.charset.StandardCharsets;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
@@ -59,7 +59,19 @@ import java.util.List;
 
 import static com.google.common.collect.Lists.newArrayList;
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.*;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyCollection;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.argThat;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Matchers.isA;
+import static org.mockito.Mockito.RETURNS_MOCKS;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.mockito.Mockito.when;
 
 public class IssueTrackingDecoratorTest {
 
@@ -210,9 +222,9 @@ public class IssueTrackingDecoratorTest {
     java.io.File f = temp.newFile();
     when(inputFile.path()).thenReturn(f.toPath());
     when(inputFile.file()).thenReturn(f);
-    when(inputFile.charset()).thenReturn(Charsets.UTF_8);
+    when(inputFile.charset()).thenReturn(StandardCharsets.UTF_8);
     when(inputFile.lines()).thenReturn(StringUtils.countMatches(newSource, "\n") + 1);
-    FileUtils.write(f, newSource, Charsets.UTF_8);
+    FileUtils.write(f, newSource, StandardCharsets.UTF_8);
     when(inputFile.key()).thenReturn("foo:Action.java");
     when(inputPathCache.getFile("foo", "Action.java")).thenReturn(inputFile);
     when(lastSnapshots.getLineHashes("foo:Action.java")).thenReturn(computeHexHashes(originalSource));
index b716ce907d5c8b006c94a9b18170f55152c9859b..062c539b457bda487aa8b008d4f281e900ebcd43 100644 (file)
@@ -20,7 +20,6 @@
 
 package org.sonar.batch.issue.tracking;
 
-import com.google.common.base.Charsets;
 import com.google.common.collect.Lists;
 import com.google.common.io.Resources;
 import org.apache.commons.codec.digest.DigestUtils;
@@ -41,6 +40,7 @@ import org.sonar.core.issue.db.IssueDto;
 
 import java.io.File;
 import java.io.IOException;
+import java.nio.charset.StandardCharsets;
 import java.util.Arrays;
 import java.util.Collections;
 
@@ -345,7 +345,7 @@ public class IssueTrackingTest {
   }
 
   private static String load(String name) throws IOException {
-    return Resources.toString(IssueTrackingTest.class.getResource("IssueTrackingTest/" + name + ".txt"), Charsets.UTF_8);
+    return Resources.toString(IssueTrackingTest.class.getResource("IssueTrackingTest/" + name + ".txt"), StandardCharsets.UTF_8);
   }
 
   private DefaultIssue newDefaultIssue(String message, Integer line, RuleKey ruleKey, String checksum) {
@@ -371,10 +371,10 @@ public class IssueTrackingTest {
     File f = temp.newFile();
     when(inputFile.path()).thenReturn(f.toPath());
     when(inputFile.file()).thenReturn(f);
-    when(inputFile.charset()).thenReturn(Charsets.UTF_8);
+    when(inputFile.charset()).thenReturn(StandardCharsets.UTF_8);
     String data = load(newSource);
     when(inputFile.lines()).thenReturn(StringUtils.countMatches(data, "\n") + 1);
-    FileUtils.write(f, data, Charsets.UTF_8);
+    FileUtils.write(f, data, StandardCharsets.UTF_8);
     when(inputFile.key()).thenReturn("foo:Action.java");
     when(lastSnapshots.getLineHashes("foo:Action.java")).thenReturn(computeHexHashes(load(reference)));
     sourceHashHolder = new SourceHashHolder(inputFile, lastSnapshots);
index 3488e9d25e44666669f940f53fc7f7d0df1471a9..cdb7324ae2aa9bac868646bec1442a9cfa15d926 100644 (file)
@@ -19,7 +19,6 @@
  */
 package org.sonar.batch.issue.tracking;
 
-import com.google.common.base.Charsets;
 import org.apache.commons.io.FileUtils;
 import org.junit.Before;
 import org.junit.Rule;
@@ -30,6 +29,7 @@ import org.sonar.api.batch.fs.InputFile;
 import org.sonar.api.batch.fs.internal.DefaultInputFile;
 
 import java.io.File;
+import java.nio.charset.StandardCharsets;
 
 import static org.apache.commons.codec.digest.DigestUtils.md5Hex;
 import static org.assertj.core.api.Assertions.assertThat;
@@ -57,7 +57,7 @@ public class SourceHashHolderTest {
     when(file.file()).thenReturn(ioFile);
     when(file.path()).thenReturn(ioFile.toPath());
     when(file.lines()).thenReturn(1);
-    when(file.charset()).thenReturn(Charsets.UTF_8);
+    when(file.charset()).thenReturn(StandardCharsets.UTF_8);
 
     sourceHashHolder = new SourceHashHolder(file, lastSnapshots);
   }
@@ -65,7 +65,7 @@ public class SourceHashHolderTest {
   @Test
   public void should_lazy_load_line_hashes() throws Exception {
     final String source = "source";
-    FileUtils.write(ioFile, source + "\n", Charsets.UTF_8);
+    FileUtils.write(ioFile, source + "\n", StandardCharsets.UTF_8);
     when(file.lines()).thenReturn(2);
 
     assertThat(sourceHashHolder.getHashedSource().getHash(1)).isEqualTo(md5Hex(source));
@@ -80,7 +80,7 @@ public class SourceHashHolderTest {
   public void should_lazy_load_reference_hashes_when_status_changed() throws Exception {
     final String source = "source";
     String key = "foo:src/Foo.java";
-    FileUtils.write(ioFile, source, Charsets.UTF_8);
+    FileUtils.write(ioFile, source, StandardCharsets.UTF_8);
     when(file.key()).thenReturn(key);
     when(file.status()).thenReturn(InputFile.Status.CHANGED);
     when(lastSnapshots.getLineHashes(key)).thenReturn(new String[] {md5Hex(source)});
@@ -96,7 +96,7 @@ public class SourceHashHolderTest {
   public void should_not_load_reference_hashes_when_status_same() throws Exception {
     final String source = "source";
     String key = "foo:src/Foo.java";
-    FileUtils.write(ioFile, source, Charsets.UTF_8);
+    FileUtils.write(ioFile, source, StandardCharsets.UTF_8);
     when(file.key()).thenReturn(key);
     when(file.status()).thenReturn(InputFile.Status.SAME);
 
@@ -108,7 +108,7 @@ public class SourceHashHolderTest {
   public void no_reference_hashes_when_status_added() throws Exception {
     final String source = "source";
     String key = "foo:src/Foo.java";
-    FileUtils.write(ioFile, source, Charsets.UTF_8);
+    FileUtils.write(ioFile, source, StandardCharsets.UTF_8);
     when(file.key()).thenReturn(key);
     when(file.status()).thenReturn(InputFile.Status.ADDED);
 
index b09883aef7c4a50b77349d79df6cdbbe5d36ee28..e6e7e6165552766a113c4105c84125dedfa57775 100644 (file)
@@ -19,7 +19,6 @@
  */
 package org.sonar.batch.mediumtest.dependency;
 
-import com.google.common.base.Charsets;
 import com.google.common.collect.ImmutableMap;
 import org.apache.commons.io.FileUtils;
 import org.junit.After;
@@ -34,6 +33,7 @@ import org.sonar.xoo.XooPlugin;
 
 import java.io.File;
 import java.io.IOException;
+import java.nio.charset.StandardCharsets;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
@@ -107,7 +107,7 @@ public class DependencyMediumTest {
       FileUtils.write(xooFile2, "foo");
       File xooDepFile = new File(srcDir, "dir1/sample" + nb + ".xoo.deps");
       for (int otherId = 1; otherId <= nbFiles; otherId++) {
-        FileUtils.write(xooDepFile, "src/dir2/sample" + otherId + ".xoo:1\n", Charsets.UTF_8, true);
+        FileUtils.write(xooDepFile, "src/dir2/sample" + otherId + ".xoo:1\n", StandardCharsets.UTF_8, true);
       }
     }
 
index 7579314569a1ac1e7af20519bf3f858fdc10dcff..4e75ffc5474b159e9800d3f1ec106de9262b8c07 100644 (file)
@@ -19,7 +19,6 @@
  */
 package org.sonar.batch.mediumtest.fs;
 
-import com.google.common.base.Charsets;
 import com.google.common.collect.ImmutableMap;
 import org.apache.commons.io.FileUtils;
 import org.junit.After;
@@ -35,6 +34,7 @@ import org.sonar.xoo.XooPlugin;
 
 import java.io.File;
 import java.io.IOException;
+import java.nio.charset.StandardCharsets;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
@@ -72,7 +72,7 @@ public class RandomFsAccessMediumTest {
     int ISSUE_COUNT = 10000;
     for (int i = 0; i < ISSUE_COUNT; i++) {
       File xooFile = new File(srcDir, "sample" + (i / 10 + 1) + ".xoo");
-      FileUtils.write(paths, xooFile.getAbsolutePath() + "\n", Charsets.UTF_8, true);
+      FileUtils.write(paths, xooFile.getAbsolutePath() + "\n", StandardCharsets.UTF_8, true);
     }
 
     long start = System.currentTimeMillis();
@@ -102,7 +102,7 @@ public class RandomFsAccessMediumTest {
     File paths = new File(baseDir, "paths.txt");
     int ISSUE_COUNT = 10000;
     for (int i = 0; i < ISSUE_COUNT; i++) {
-      FileUtils.write(paths, "src/sample" + (i / 10 + 1) + ".xoo\n", Charsets.UTF_8, true);
+      FileUtils.write(paths, "src/sample" + (i / 10 + 1) + ".xoo\n", StandardCharsets.UTF_8, true);
     }
 
     TaskResult result = tester.newTask()
index 42108b08d86f140dc7ff69f20488358b7869554b..bfe6067b6923832d9cc941b7535a6c74ebc5e635 100644 (file)
@@ -19,7 +19,6 @@
  */
 package org.sonar.batch.report;
 
-import com.google.common.base.Charsets;
 import org.apache.commons.io.FileUtils;
 import org.junit.Before;
 import org.junit.Rule;
@@ -34,6 +33,7 @@ import org.sonar.batch.protocol.output.BatchReportWriter;
 
 import java.io.File;
 import java.io.IOException;
+import java.nio.charset.StandardCharsets;
 import java.util.Date;
 
 import static org.assertj.core.api.Assertions.assertThat;
@@ -60,7 +60,8 @@ public class SourcePublisherTest {
     resourceCache.add(p, null).setSnapshot(new Snapshot().setId(2));
     File baseDir = temp.newFolder();
     sourceFile = new File(baseDir, "src/Foo.php");
-    resourceCache.add(sampleFile, null).setInputPath(new DefaultInputFile("foo", "src/Foo.php").setLines(5).setModuleBaseDir(baseDir.toPath()).setCharset(Charsets.ISO_8859_1));
+    resourceCache.add(sampleFile, null).setInputPath(
+      new DefaultInputFile("foo", "src/Foo.php").setLines(5).setModuleBaseDir(baseDir.toPath()).setCharset(StandardCharsets.ISO_8859_1));
     publisher = new SourcePublisher(resourceCache);
     File outputDir = temp.newFolder();
     writer = new BatchReportWriter(outputDir);
@@ -68,52 +69,52 @@ public class SourcePublisherTest {
 
   @Test
   public void publishEmptySource() throws Exception {
-    FileUtils.write(sourceFile, "", Charsets.ISO_8859_1);
+    FileUtils.write(sourceFile, "", StandardCharsets.ISO_8859_1);
 
     publisher.publish(writer);
 
     File out = writer.getSourceFile(2);
-    assertThat(FileUtils.readFileToString(out, Charsets.UTF_8)).isEqualTo("");
+    assertThat(FileUtils.readFileToString(out, StandardCharsets.UTF_8)).isEqualTo("");
   }
 
   @Test
   public void publishSourceWithLastEmptyLine() throws Exception {
-    FileUtils.write(sourceFile, "1\n2\n3\n4\n", Charsets.ISO_8859_1);
+    FileUtils.write(sourceFile, "1\n2\n3\n4\n", StandardCharsets.ISO_8859_1);
 
     publisher.publish(writer);
 
     File out = writer.getSourceFile(2);
-    assertThat(FileUtils.readFileToString(out, Charsets.UTF_8)).isEqualTo("1\n2\n3\n4\n");
+    assertThat(FileUtils.readFileToString(out, StandardCharsets.UTF_8)).isEqualTo("1\n2\n3\n4\n");
   }
 
   @Test
   public void publishTestSource() throws Exception {
-    FileUtils.write(sourceFile, "1\n2\n3\n4\n", Charsets.ISO_8859_1);
+    FileUtils.write(sourceFile, "1\n2\n3\n4\n", StandardCharsets.ISO_8859_1);
     sampleFile.setQualifier(Qualifiers.UNIT_TEST_FILE);
 
     publisher.publish(writer);
 
     File out = writer.getSourceFile(2);
-    assertThat(FileUtils.readFileToString(out, Charsets.UTF_8)).isEqualTo("1\n2\n3\n4\n");
+    assertThat(FileUtils.readFileToString(out, StandardCharsets.UTF_8)).isEqualTo("1\n2\n3\n4\n");
   }
 
   @Test
   public void publishSourceWithLastLineNotEmpty() throws Exception {
-    FileUtils.write(sourceFile, "1\n2\n3\n4\n5", Charsets.ISO_8859_1);
+    FileUtils.write(sourceFile, "1\n2\n3\n4\n5", StandardCharsets.ISO_8859_1);
 
     publisher.publish(writer);
 
     File out = writer.getSourceFile(2);
-    assertThat(FileUtils.readFileToString(out, Charsets.UTF_8)).isEqualTo("1\n2\n3\n4\n5");
+    assertThat(FileUtils.readFileToString(out, StandardCharsets.UTF_8)).isEqualTo("1\n2\n3\n4\n5");
   }
 
   @Test
   public void cleanLineEnds() throws Exception {
-    FileUtils.write(sourceFile, "\n2\r\n3\n4\r5", Charsets.ISO_8859_1);
+    FileUtils.write(sourceFile, "\n2\r\n3\n4\r5", StandardCharsets.ISO_8859_1);
 
     publisher.publish(writer);
 
     File out = writer.getSourceFile(2);
-    assertThat(FileUtils.readFileToString(out, Charsets.UTF_8)).isEqualTo("\n2\n3\n4\n5");
+    assertThat(FileUtils.readFileToString(out, StandardCharsets.UTF_8)).isEqualTo("\n2\n3\n4\n5");
   }
 }
index 2438c3de381b3ff84d0ab013b6f09ea5efd5222a..805749c2d3a7888e57cea34fb841f4e8a42a94d7 100644 (file)
@@ -19,7 +19,6 @@
  */
 package org.sonar.batch.scan.filesystem;
 
-import org.apache.commons.io.Charsets;
 import org.apache.commons.io.FileUtils;
 import org.junit.Rule;
 import org.junit.Test;
@@ -33,6 +32,7 @@ import org.sonar.api.utils.PathUtils;
 import org.sonar.batch.bootstrap.DefaultAnalysisMode;
 
 import java.io.File;
+import java.nio.charset.StandardCharsets;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Matchers.any;
@@ -57,7 +57,7 @@ public class InputFileBuilderTest {
     FileUtils.touch(srcFile);
     FileUtils.write(srcFile, "single line");
     when(fs.baseDir()).thenReturn(basedir);
-    when(fs.encoding()).thenReturn(Charsets.UTF_8);
+    when(fs.encoding()).thenReturn(StandardCharsets.UTF_8);
 
     // lang
     when(langDetection.language(any(InputFile.class))).thenReturn("java");
@@ -104,7 +104,7 @@ public class InputFileBuilderTest {
     FileUtils.touch(srcFile);
     FileUtils.write(srcFile, "single line");
     when(fs.baseDir()).thenReturn(basedir);
-    when(fs.encoding()).thenReturn(Charsets.UTF_8);
+    when(fs.encoding()).thenReturn(StandardCharsets.UTF_8);
 
     // lang
     when(langDetection.language(any(InputFile.class))).thenReturn(null);
index 84b24fa9355b14bc383ceeabe40d4560145a4e0f..67caca6a48a3dd177c48682e04deac7a47afec43 100644 (file)
@@ -19,7 +19,6 @@
  */
 package org.sonar.batch.scan.filesystem;
 
-import com.google.common.base.Charsets;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
@@ -31,6 +30,8 @@ import org.sonar.api.batch.fs.InputPath;
 import org.sonar.api.batch.fs.internal.DefaultInputFile;
 import org.sonar.api.batch.fs.internal.DeprecatedDefaultInputFile;
 
+import java.nio.charset.StandardCharsets;
+
 import static org.assertj.core.api.Assertions.assertThat;
 
 public class InputPathCacheTest {
@@ -56,12 +57,12 @@ public class InputPathCacheTest {
       .setType(Type.MAIN)
       .setStatus(Status.ADDED)
       .setLines(2)
-      .setCharset(Charsets.UTF_8)
+      .setCharset(StandardCharsets.UTF_8)
       .setModuleBaseDir(temp.newFolder().toPath()));
 
     DefaultInputFile loadedFile = (DefaultInputFile) cache.getFile("struts-core", "src/main/java/Bar.java");
     assertThat(loadedFile.relativePath()).isEqualTo("src/main/java/Bar.java");
-    assertThat(loadedFile.charset()).isEqualTo(Charsets.UTF_8);
+    assertThat(loadedFile.charset()).isEqualTo(StandardCharsets.UTF_8);
 
     assertThat(cache.filesByModule("struts")).hasSize(1);
     assertThat(cache.filesByModule("struts-core")).hasSize(1);
index a656866163310aa547ac13348f996ef10a116d5f..7b56b2afb04a0474d20321b2d49aa1d4ec90b01f 100644 (file)
@@ -19,7 +19,6 @@
  */
 package org.sonar.batch.source;
 
-import com.google.common.base.Charsets;
 import com.google.common.collect.ImmutableList;
 import org.apache.commons.io.FileUtils;
 import org.junit.Rule;
@@ -28,9 +27,15 @@ import org.junit.rules.TemporaryFolder;
 import org.sonar.api.batch.sensor.highlighting.NewHighlighting;
 import org.sonar.api.batch.sensor.highlighting.TypeOfText;
 import org.sonar.api.web.CodeColorizerFormat;
-import org.sonar.colorizer.*;
+import org.sonar.colorizer.CDocTokenizer;
+import org.sonar.colorizer.CppDocTokenizer;
+import org.sonar.colorizer.JavadocTokenizer;
+import org.sonar.colorizer.KeywordsTokenizer;
+import org.sonar.colorizer.StringTokenizer;
+import org.sonar.colorizer.Tokenizer;
 
 import java.io.File;
+import java.nio.charset.StandardCharsets;
 import java.util.Arrays;
 import java.util.List;
 
@@ -48,7 +53,7 @@ public class CodeColorizersTest {
     File jsFile = new File(this.getClass().getResource("CodeColorizersTest/Person.js").toURI());
     NewHighlighting highlighting = mock(NewHighlighting.class);
 
-    codeColorizers.toSyntaxHighlighting(jsFile, Charsets.UTF_8, "js", highlighting);
+    codeColorizers.toSyntaxHighlighting(jsFile, StandardCharsets.UTF_8, "js", highlighting);
 
     verifyForJs(highlighting);
   }
@@ -76,7 +81,7 @@ public class CodeColorizersTest {
     FileUtils.write(fileWithBom, FileUtils.readFileToString(jsFile), "UTF-8", true);
 
     NewHighlighting highlighting = mock(NewHighlighting.class);
-    codeColorizers.toSyntaxHighlighting(fileWithBom, Charsets.UTF_8, "js", highlighting);
+    codeColorizers.toSyntaxHighlighting(fileWithBom, StandardCharsets.UTF_8, "js", highlighting);
 
     verifyForJs(highlighting);
   }
@@ -88,7 +93,7 @@ public class CodeColorizersTest {
     File javaFile = new File(this.getClass().getResource("CodeColorizersTest/Person.java").toURI());
 
     NewHighlighting highlighting = mock(NewHighlighting.class);
-    codeColorizers.toSyntaxHighlighting(javaFile, Charsets.UTF_8, "java", highlighting);
+    codeColorizers.toSyntaxHighlighting(javaFile, StandardCharsets.UTF_8, "java", highlighting);
 
     verify(highlighting).highlight(0, 4, TypeOfText.STRUCTURED_COMMENT);
     verify(highlighting).highlight(5, 11, TypeOfText.STRUCTURED_COMMENT);
index 19b101720a4ce8e30fa4bcf92580d859ff90550b..5badc62f7bffc699beee2d8896189447457a2330 100644 (file)
  */
 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 {
index 27c747ced27c9007f1d32ae4762d450ca0889da7..769f416fbd66fb5363cc13e1550a3068b8805598 100644 (file)
@@ -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);
     }
index 26f9212dc8c4f3c60c498917f2441e1c8eb7fe23..ef3afd73a4ab6bbe783edf2822d29b5feef2d0f4 100644 (file)
  */
 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);
   }
 }
index 8760b8f8d2e6e7a11a4703cf460dafb723bcdca0..6f4a0e4779cd30e9f6fa08229d482a4ae543ca5d 100644 (file)
@@ -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
index 8346966c5e46af10c834716a5c4a12880c7d0ccb..4d9a29db93f14a1d9ee93d816ec4fbdc5ce864f8 100644 (file)
@@ -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;
index 6ac3287dd6ed7b7ecbbf32cf05de1ea012d57825..b900c25f69ec9a72cf2cd31635e0f82a351edc85 100644 (file)
@@ -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);
 
index 2535dcd72b92b6597af389346349654f148f48bd..4a22a4da47418beb28be38f805f26d492a73b23d 100644 (file)
@@ -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) {
index ea3ef78527ab8f39739cbfe7307ecda116147470..d962fd2db03a0eacad89eafa9edead7cb2775522 100644 (file)
@@ -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();
 
index 0a094de7052d5baee31ef51404e47ff5f2dfe843..4c540b207a279e06f150c49d55ad03fc182833e1 100644 (file)
@@ -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);
index e26451cf82d0c1da03faf9d1066186e56a4a8631..0d00ba287932a871cdbe9f010ee97108d3663d60 100644 (file)
@@ -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();
index 1eb9b6372817ae28b38d3a180f881990b07e97a2..5f2f465bc2b49772c57f91230488f5247dcc7b1b 100644 (file)
  */
 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);
   }
 }
index 630b9e6007cfd364426ddb88796f19ea61fee70d..13c9a18602ebd477aac4944f42e7646c5cba8f21 100644 (file)
  */
 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);
     }
index 3c372bd19fdc28a713217c4f161eeb76926101b4..a7c96cd4206df3e26d0c5d1fe5919d74aaf1b083 100644 (file)
@@ -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);
index c7f21de758fb7ecfd9f970fa6295137c1f7ede42..e89e1c6399f686c61bd8848b66f983ca2530b98c 100644 (file)
@@ -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();
   }