@@ -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); |
@@ -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(); | |||
} |
@@ -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) { |
@@ -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 |
@@ -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; |
@@ -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; |
@@ -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)); |
@@ -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); |
@@ -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); | |||
@@ -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); | |||
} | |||
} | |||
@@ -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() |
@@ -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"); | |||
} | |||
} |
@@ -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); |
@@ -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); |
@@ -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); |
@@ -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 { |
@@ -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); | |||
} |
@@ -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); | |||
} | |||
} |
@@ -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 |
@@ -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; |
@@ -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); | |||
@@ -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) { |
@@ -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(); | |||
@@ -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); |
@@ -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(); |
@@ -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); | |||
} | |||
} |
@@ -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); | |||
} |
@@ -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); |
@@ -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(); | |||
} |