diff options
52 files changed, 233 insertions, 209 deletions
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/scm/XooBlameCommand.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/scm/XooBlameCommand.java index 0d1c978e0de..dcf5258413b 100644 --- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/scm/XooBlameCommand.java +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/scm/XooBlameCommand.java @@ -20,7 +20,6 @@ package org.sonar.xoo.scm; import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Charsets; import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; import org.sonar.api.batch.fs.InputFile; @@ -30,6 +29,7 @@ import org.sonar.api.utils.DateUtils; import java.io.File; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; @@ -53,7 +53,7 @@ public class XooBlameCommand extends BlameCommand { } try { - List<String> lines = FileUtils.readLines(scmDataFile, Charsets.UTF_8.name()); + List<String> lines = FileUtils.readLines(scmDataFile, StandardCharsets.UTF_8); List<BlameLine> blame = new ArrayList<>(lines.size()); int lineNumber = 0; for (String line : lines) { diff --git a/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/StreamGobbler.java b/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/StreamGobbler.java index 35c03564abf..73181e148a3 100644 --- a/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/StreamGobbler.java +++ b/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/StreamGobbler.java @@ -19,7 +19,6 @@ */ package org.sonar.process.monitor; -import org.apache.commons.io.Charsets; import org.apache.commons.io.IOUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -29,6 +28,7 @@ import javax.annotation.Nullable; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; /** * Reads process output and writes to logs @@ -50,7 +50,7 @@ class StreamGobbler extends Thread { @Override public void run() { - BufferedReader br = new BufferedReader(new InputStreamReader(is, Charsets.UTF_8)); + BufferedReader br = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8)); try { String line; while ((line = br.readLine()) != null) { diff --git a/server/sonar-process/src/main/java/org/sonar/process/AesCipher.java b/server/sonar-process/src/main/java/org/sonar/process/AesCipher.java index f98f1fe65dd..7759e1ab2fa 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/AesCipher.java +++ b/server/sonar-process/src/main/java/org/sonar/process/AesCipher.java @@ -20,7 +20,6 @@ package org.sonar.process; -import org.apache.commons.io.Charsets; import org.apache.commons.codec.binary.Base64; import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; @@ -32,6 +31,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; @@ -74,7 +74,7 @@ final class AesCipher implements 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 (RuntimeException e) { throw e; } catch (Exception e) { diff --git a/server/sonar-process/src/main/java/org/sonar/process/Base64Cipher.java b/server/sonar-process/src/main/java/org/sonar/process/Base64Cipher.java index ca9044850e9..209588e2d90 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/Base64Cipher.java +++ b/server/sonar-process/src/main/java/org/sonar/process/Base64Cipher.java @@ -21,16 +21,17 @@ package org.sonar.process; import org.apache.commons.codec.binary.Base64; -import org.apache.commons.io.Charsets; + +import java.nio.charset.StandardCharsets; final class Base64Cipher implements Cipher { @Override public String encrypt(String clearText) { - return Base64.encodeBase64String(clearText.getBytes(Charsets.UTF_8)); + return Base64.encodeBase64String(clearText.getBytes(StandardCharsets.UTF_8)); } @Override public String decrypt(String encryptedText) { - return new String(Base64.decodeBase64(encryptedText), Charsets.UTF_8); + return new String(Base64.decodeBase64(encryptedText), StandardCharsets.UTF_8); } } diff --git a/server/sonar-process/src/main/java/org/sonar/process/ConfigurationUtils.java b/server/sonar-process/src/main/java/org/sonar/process/ConfigurationUtils.java index 458cf031722..a9e27300f1f 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/ConfigurationUtils.java +++ b/server/sonar-process/src/main/java/org/sonar/process/ConfigurationUtils.java @@ -19,7 +19,6 @@ */ package org.sonar.process; -import org.apache.commons.io.Charsets; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang.text.StrSubstitutor; @@ -28,6 +27,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.Enumeration; import java.util.Map; import java.util.Properties; @@ -60,7 +60,7 @@ public final class ConfigurationUtils { Properties properties = new Properties(); Reader reader = null; try { - reader = new InputStreamReader(new FileInputStream(propertyFile), Charsets.UTF_8); + reader = new InputStreamReader(new FileInputStream(propertyFile), StandardCharsets.UTF_8); properties.load(reader); } catch (Exception e) { throw new IllegalStateException("Could not read properties from file: " + args[0], e); diff --git a/server/sonar-server/src/main/java/org/sonar/server/activity/index/ActivityResultSetIterator.java b/server/sonar-server/src/main/java/org/sonar/server/activity/index/ActivityResultSetIterator.java index 430db67a0c5..df6fbf59c8a 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/activity/index/ActivityResultSetIterator.java +++ b/server/sonar-server/src/main/java/org/sonar/server/activity/index/ActivityResultSetIterator.java @@ -19,7 +19,6 @@ */ package org.sonar.server.activity.index; -import org.apache.commons.io.Charsets; import org.apache.commons.lang.StringUtils; import org.elasticsearch.action.update.UpdateRequest; import org.sonar.api.utils.KeyValueFormat; @@ -31,7 +30,12 @@ import org.sonar.server.util.DateCollector; import java.io.ByteArrayOutputStream; import java.io.OutputStreamWriter; -import java.sql.*; +import java.nio.charset.StandardCharsets; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Timestamp; import java.util.Date; /** @@ -77,7 +81,7 @@ class ActivityResultSetIterator extends ResultSetIterator<UpdateRequest> { protected UpdateRequest read(ResultSet rs) throws SQLException { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); // all the fields must be present, even if value is null - JsonWriter writer = JsonWriter.of(new OutputStreamWriter(bytes, Charsets.UTF_8)).setSerializeNulls(true); + JsonWriter writer = JsonWriter.of(new OutputStreamWriter(bytes, StandardCharsets.UTF_8)).setSerializeNulls(true); writer.beginObject(); String key = rs.getString(1); writer.prop(ActivityIndexDefinition.FIELD_KEY, key); diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/source/ComputeFileSourceData.java b/server/sonar-server/src/main/java/org/sonar/server/computation/source/ComputeFileSourceData.java index 88cddc7dca4..fd983c42789 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/source/ComputeFileSourceData.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/source/ComputeFileSourceData.java @@ -29,7 +29,7 @@ import java.security.MessageDigest; import java.util.Iterator; import java.util.List; -import static com.google.common.base.Charsets.UTF_8; +import static java.nio.charset.StandardCharsets.UTF_8; public class ComputeFileSourceData { diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistFileSourcesStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistFileSourcesStep.java index d416bb75345..78df32a46aa 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistFileSourcesStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistFileSourcesStep.java @@ -22,7 +22,6 @@ package org.sonar.server.computation.step; import com.google.common.collect.ImmutableMap; import org.apache.commons.codec.digest.DigestUtils; -import org.apache.commons.io.Charsets; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.io.LineIterator; @@ -51,6 +50,7 @@ import org.sonar.server.source.db.FileSourceDb; import java.io.File; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -118,7 +118,7 @@ public class PersistFileSourcesStep implements ComputationStep { private static LineIterator sourceLinesIterator(File file) { try { - return IOUtils.lineIterator(FileUtils.openInputStream(file), Charsets.UTF_8); + return IOUtils.lineIterator(FileUtils.openInputStream(file), StandardCharsets.UTF_8); } catch (IOException e) { throw new IllegalStateException("Fail to traverse file: " + file, e); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FeedFileSources.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FeedFileSources.java index be975171650..d37850b3394 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FeedFileSources.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FeedFileSources.java @@ -19,13 +19,6 @@ */ package org.sonar.server.db.migrations.v50; -import static com.google.common.base.Charsets.UTF_8; - -import java.sql.SQLException; -import java.util.Date; - -import javax.annotation.Nullable; - import org.apache.commons.lang.StringUtils; import org.sonar.api.utils.System2; import org.sonar.core.persistence.Database; @@ -35,6 +28,12 @@ import org.sonar.server.db.migrations.Select.Row; import org.sonar.server.db.migrations.Select.RowReader; import org.sonar.server.db.migrations.SqlStatement; +import javax.annotation.Nullable; + +import java.nio.charset.StandardCharsets; +import java.sql.SQLException; +import java.util.Date; + /** * Used in the Active Record Migration 714 * @@ -220,7 +219,7 @@ public class FeedFileSources extends BaseDataChange { } else { result = shortBytes; } - return new String(result, UTF_8); + return new String(result, StandardCharsets.UTF_8); } private final System2 system; diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FileSourceDto.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FileSourceDto.java index 1219afd4d92..f3ca467ee98 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FileSourceDto.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FileSourceDto.java @@ -19,20 +19,8 @@ */ package org.sonar.server.db.migrations.v50; -import static com.google.common.base.Charsets.UTF_8; - -import java.io.ByteArrayOutputStream; -import java.io.OutputStreamWriter; -import java.io.StringReader; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLStreamException; - +import com.google.common.base.Splitter; +import com.google.common.collect.ImmutableList; import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.lang.StringUtils; import org.codehaus.stax2.XMLInputFactory2; @@ -43,8 +31,19 @@ import org.sonar.api.measures.CoreMetrics; import org.sonar.api.utils.KeyValueFormat; import org.sonar.api.utils.text.CsvWriter; -import com.google.common.base.Splitter; -import com.google.common.collect.ImmutableList; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; + +import java.io.ByteArrayOutputStream; +import java.io.OutputStreamWriter; +import java.io.StringReader; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import static java.nio.charset.StandardCharsets.UTF_8; class FileSourceDto { diff --git a/server/sonar-server/src/main/java/org/sonar/server/debt/DebtModelPluginRepository.java b/server/sonar-server/src/main/java/org/sonar/server/debt/DebtModelPluginRepository.java index 8ca78f7c3f6..67b016de536 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/debt/DebtModelPluginRepository.java +++ b/server/sonar-server/src/main/java/org/sonar/server/debt/DebtModelPluginRepository.java @@ -22,7 +22,6 @@ package org.sonar.server.debt; import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.Maps; -import org.apache.commons.io.Charsets; import org.picocontainer.Startable; import org.sonar.api.Plugin; import org.sonar.api.ServerSide; @@ -31,6 +30,7 @@ import org.sonar.core.platform.PluginRepository; import java.io.InputStreamReader; import java.io.Reader; +import java.nio.charset.StandardCharsets; import java.util.Collection; import java.util.Collections; import java.util.Map; @@ -123,7 +123,7 @@ public class DebtModelPluginRepository implements Startable { public Reader createReaderForXMLFile(String pluginKey) { ClassLoader classLoader = contributingPluginKeyToClassLoader.get(pluginKey); String xmlFilePath = getXMLFilePath(pluginKey); - return new InputStreamReader(classLoader.getResourceAsStream(xmlFilePath), Charsets.UTF_8); + return new InputStreamReader(classLoader.getResourceAsStream(xmlFilePath), StandardCharsets.UTF_8); } @VisibleForTesting diff --git a/server/sonar-server/src/main/java/org/sonar/server/debt/DebtModelXMLExporter.java b/server/sonar-server/src/main/java/org/sonar/server/debt/DebtModelXMLExporter.java index 8dfae1f9e4d..fc14e492886 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/debt/DebtModelXMLExporter.java +++ b/server/sonar-server/src/main/java/org/sonar/server/debt/DebtModelXMLExporter.java @@ -24,7 +24,6 @@ import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Iterables; import com.google.common.collect.Multimap; import com.google.common.collect.Ordering; -import org.apache.commons.io.Charsets; import org.apache.commons.lang.StringEscapeUtils; import org.apache.commons.lang.StringUtils; import org.sonar.api.ServerSide; @@ -45,6 +44,7 @@ import javax.xml.transform.stream.StreamResult; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; +import java.nio.charset.StandardCharsets; import java.util.Collections; import java.util.List; import java.util.regex.Matcher; @@ -170,10 +170,10 @@ public class DebtModelXMLExporter { serializer.setOutputProperty(OutputKeys.INDENT, "yes"); serializer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); serializer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", DEFAULT_INDENT); - Source xmlSource = new SAXSource(new InputSource(new ByteArrayInputStream(xml.getBytes(Charsets.UTF_8)))); + Source xmlSource = new SAXSource(new InputSource(new ByteArrayInputStream(xml.getBytes(StandardCharsets.UTF_8)))); StreamResult res = new StreamResult(new ByteArrayOutputStream()); serializer.transform(xmlSource, res); - return new String(((ByteArrayOutputStream) res.getOutputStream()).toByteArray(), Charsets.UTF_8); + return new String(((ByteArrayOutputStream) res.getOutputStream()).toByteArray(), StandardCharsets.UTF_8); } catch (TransformerException ignored) { // Ignore, raw XML will be returned } diff --git a/server/sonar-server/src/main/java/org/sonar/server/measure/MeasureFilter.java b/server/sonar-server/src/main/java/org/sonar/server/measure/MeasureFilter.java index 68c07974484..0dd3f518206 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/measure/MeasureFilter.java +++ b/server/sonar-server/src/main/java/org/sonar/server/measure/MeasureFilter.java @@ -185,7 +185,7 @@ public class MeasureFilter { @VisibleForTesting static List<String> sanitize(@Nullable List<String> list) { - return isEmptyList(list) ? Collections.<String> emptyList() : Lists.newArrayList(list); + return isEmptyList(list) ? Collections.<String>emptyList() : Lists.newArrayList(list); } private static boolean isEmptyList(@Nullable List<String> list) { diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/ServerImpl.java b/server/sonar-server/src/main/java/org/sonar/server/platform/ServerImpl.java index bae47f5e2fc..435e3e8b21b 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/platform/ServerImpl.java +++ b/server/sonar-server/src/main/java/org/sonar/server/platform/ServerImpl.java @@ -20,7 +20,6 @@ package org.sonar.server.platform; import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Charsets; import com.google.common.base.Joiner; import com.google.common.io.Resources; import org.apache.commons.io.IOUtils; @@ -39,6 +38,7 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.net.URL; +import java.nio.charset.StandardCharsets; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Properties; @@ -142,9 +142,9 @@ public final class ServerImpl extends Server implements Startable { private static String readVersion(String filename) throws IOException { URL url = ServerImpl.class.getResource(filename); if (url != null) { - String version = Resources.toString(url, Charsets.UTF_8); + String version = Resources.toString(url, StandardCharsets.UTF_8); if (!StringUtils.isBlank(version)) { - return StringUtils.deleteWhitespace(version); + return StringUtils.deleteWhitespace(version); } } throw new IllegalStateException("Unknown SonarQube version"); diff --git a/server/sonar-server/src/main/java/org/sonar/server/plugins/UpdateCenterClient.java b/server/sonar-server/src/main/java/org/sonar/server/plugins/UpdateCenterClient.java index 0f774f15e03..d4b3d164890 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/plugins/UpdateCenterClient.java +++ b/server/sonar-server/src/main/java/org/sonar/server/plugins/UpdateCenterClient.java @@ -19,7 +19,6 @@ */ package org.sonar.server.plugins; -import com.google.common.base.Charsets; import org.apache.commons.io.IOUtils; import org.sonar.api.Properties; import org.sonar.api.Property; @@ -34,6 +33,7 @@ import org.sonar.updatecenter.common.UpdateCenterDeserializer.Mode; import java.io.InputStream; import java.net.URI; import java.net.URISyntaxException; +import java.nio.charset.StandardCharsets; import java.util.Date; /** @@ -100,9 +100,9 @@ public class UpdateCenterClient { private UpdateCenter init() { InputStream input = null; try { - String content = uriReader.readString(uri, Charsets.UTF_8); + String content = uriReader.readString(uri, StandardCharsets.UTF_8); java.util.Properties properties = new java.util.Properties(); - input = IOUtils.toInputStream(content, Charsets.UTF_8.name()); + input = IOUtils.toInputStream(content, StandardCharsets.UTF_8); properties.load(input); return new UpdateCenterDeserializer(Mode.PROD, true).fromProperties(properties); diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileCopier.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileCopier.java index 1c8b14cfdce..af91f724f54 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileCopier.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileCopier.java @@ -19,7 +19,6 @@ */ package org.sonar.server.qualityprofile; -import org.apache.commons.io.Charsets; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; @@ -35,6 +34,7 @@ import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.Reader; import java.io.Writer; +import java.nio.charset.StandardCharsets; @ServerSide public class QProfileCopier { @@ -100,7 +100,7 @@ public class QProfileCopier { private void backup(String profileKey, File backupFile) { Writer writer = null; try { - writer = new OutputStreamWriter(FileUtils.openOutputStream(backupFile), Charsets.UTF_8); + writer = new OutputStreamWriter(FileUtils.openOutputStream(backupFile), StandardCharsets.UTF_8); backuper.backup(profileKey, writer); } catch (IOException e) { throw new IllegalStateException("Fail to open temporary backup file: " + backupFile, e); @@ -112,7 +112,7 @@ public class QProfileCopier { private void restore(File backupFile, QProfileName profileName) { Reader reader = null; try { - reader = new InputStreamReader(FileUtils.openInputStream(backupFile), Charsets.UTF_8); + reader = new InputStreamReader(FileUtils.openInputStream(backupFile), StandardCharsets.UTF_8); backuper.restore(reader, profileName); } catch (IOException e) { throw new IllegalStateException("Fail to create temporary backup file: " + backupFile, e); diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileExporters.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileExporters.java index 4d3f4ffa201..13d9d364ac7 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileExporters.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileExporters.java @@ -19,7 +19,6 @@ */ package org.sonar.server.qualityprofile; -import com.google.common.base.Charsets; import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.StringUtils; import org.sonar.api.ServerSide; @@ -42,6 +41,7 @@ import java.io.Reader; import java.io.StringReader; import java.io.StringWriter; import java.io.Writer; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -141,7 +141,7 @@ public class QProfileExporters { } public QProfileResult importXml(QualityProfileDto profileDto, String importerKey, InputStream xml, DbSession dbSession) { - return importXml(profileDto, importerKey, new InputStreamReader(xml, Charsets.UTF_8), dbSession); + return importXml(profileDto, importerKey, new InputStreamReader(xml, StandardCharsets.UTF_8), dbSession); } public QProfileResult importXml(QualityProfileDto profileDto, String importerKey, Reader xml, DbSession dbSession) { diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfileBackupAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfileBackupAction.java index f87f637f956..0bca14c941d 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfileBackupAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfileBackupAction.java @@ -19,7 +19,6 @@ */ package org.sonar.server.qualityprofile.ws; -import com.google.common.base.Charsets; import org.apache.commons.io.IOUtils; import org.sonar.api.resources.Languages; import org.sonar.api.server.ws.Request; @@ -34,6 +33,7 @@ import org.sonar.server.qualityprofile.QProfileBackuper; import org.sonar.server.qualityprofile.QProfileFactory; import java.io.OutputStreamWriter; +import java.nio.charset.StandardCharsets; public class QProfileBackupAction implements QProfileWsAction { @@ -62,12 +62,11 @@ public class QProfileBackupAction implements QProfileWsAction { QProfileIdentificationParamUtils.defineProfileParams(backup, languages); } - @Override public void handle(Request request, Response response) throws Exception { Stream stream = response.stream(); stream.setMediaType(MimeTypes.XML); - OutputStreamWriter writer = new OutputStreamWriter(stream.output(), Charsets.UTF_8); + OutputStreamWriter writer = new OutputStreamWriter(stream.output(), StandardCharsets.UTF_8); DbSession session = dbClient.openSession(false); try { String profileKey = QProfileIdentificationParamUtils.getProfileKeyFromParameters(request, profileFactory, session); diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfileExportAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfileExportAction.java index 9efca568911..1750393c147 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfileExportAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfileExportAction.java @@ -19,7 +19,6 @@ */ package org.sonar.server.qualityprofile.ws; -import com.google.common.base.Charsets; import com.google.common.collect.Lists; import org.apache.commons.io.IOUtils; import org.sonar.api.profiles.ProfileExporter; @@ -42,6 +41,7 @@ import org.sonar.server.qualityprofile.QProfileFactory; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.Writer; +import java.nio.charset.StandardCharsets; import java.util.List; public class QProfileExportAction implements QProfileWsAction { @@ -86,8 +86,8 @@ public class QProfileExportAction implements QProfileWsAction { .setRequired(true); List<String> exporterKeys = Lists.newArrayList(); - for (Language lang: languages.all()) { - for(ProfileExporter exporter: exporters.exportersForLanguage(lang.getKey())) { + for (Language lang : languages.all()) { + for (ProfileExporter exporter : exporters.exportersForLanguage(lang.getKey())) { exporterKeys.add(exporter.getKey()); } } @@ -111,10 +111,10 @@ public class QProfileExportAction implements QProfileWsAction { DbSession dbSession = dbClient.openSession(false); Stream stream = response.stream(); OutputStream output = stream.output(); - Writer writer = new OutputStreamWriter(output, Charsets.UTF_8); + Writer writer = new OutputStreamWriter(output, StandardCharsets.UTF_8); try { - QualityProfileDto profile = null; + QualityProfileDto profile; if (name == null) { profile = profileFactory.getDefault(dbSession, language); } else { diff --git a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfileRestoreAction.java b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfileRestoreAction.java index 0daf91ff217..621bf9473f0 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfileRestoreAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/QProfileRestoreAction.java @@ -19,10 +19,7 @@ */ package org.sonar.server.qualityprofile.ws; -import com.google.common.base.Charsets; import com.google.common.base.Preconditions; -import java.io.InputStream; -import java.io.InputStreamReader; import org.apache.commons.io.IOUtils; import org.sonar.api.resources.Languages; import org.sonar.api.server.ws.Request; @@ -35,6 +32,10 @@ import org.sonar.server.qualityprofile.BulkChangeResult; import org.sonar.server.qualityprofile.QProfileBackuper; import org.sonar.server.user.UserSession; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; + public class QProfileRestoreAction implements QProfileWsAction { private static final String PARAM_BACKUP = "backup"; @@ -70,7 +71,7 @@ public class QProfileRestoreAction implements QProfileWsAction { try { Preconditions.checkArgument(backup != null, "A backup file must be provided"); - reader = new InputStreamReader(backup, Charsets.UTF_8); + reader = new InputStreamReader(backup, StandardCharsets.UTF_8); BulkChangeResult result = backuper.restore(reader, null); writeResponse(response.newJsonWriter(), result); } finally { diff --git a/server/sonar-server/src/main/java/org/sonar/server/rule/ws/CreateAction.java b/server/sonar-server/src/main/java/org/sonar/server/rule/ws/CreateAction.java index 43e95d449a1..c97c0e06cfb 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/rule/ws/CreateAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/rule/ws/CreateAction.java @@ -20,7 +20,6 @@ package org.sonar.server.rule.ws; import com.google.common.base.Strings; -import org.apache.commons.io.Charsets; import org.sonar.api.rule.RuleKey; import org.sonar.api.rule.RuleStatus; import org.sonar.api.rule.Severity; @@ -37,6 +36,7 @@ import org.sonar.server.rule.Rule; import org.sonar.server.rule.RuleService; import java.io.OutputStreamWriter; +import java.nio.charset.StandardCharsets; /** * @since 4.4 @@ -168,7 +168,7 @@ public class CreateAction implements RulesWsAction { Response.Stream stream = response.stream(); stream.setStatus(409); stream.setMediaType(MimeTypes.JSON); - JsonWriter json = JsonWriter.of(new OutputStreamWriter(stream.output(), Charsets.UTF_8)).beginObject().name("rule"); + JsonWriter json = JsonWriter.of(new OutputStreamWriter(stream.output(), StandardCharsets.UTF_8)).beginObject().name("rule"); mapping.write(rule, json, null /* TODO replace by SearchOptions immutable constant */); json.endObject().close(); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/source/index/SourceLineResultSetIterator.java b/server/sonar-server/src/main/java/org/sonar/server/source/index/SourceLineResultSetIterator.java index 95561fd4c6b..d23082d857d 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/source/index/SourceLineResultSetIterator.java +++ b/server/sonar-server/src/main/java/org/sonar/server/source/index/SourceLineResultSetIterator.java @@ -19,7 +19,6 @@ */ package org.sonar.server.source.index; -import org.apache.commons.io.Charsets; import org.elasticsearch.action.update.UpdateRequest; import org.sonar.api.utils.text.JsonWriter; import org.sonar.core.source.db.FileSourceDto; @@ -32,6 +31,7 @@ import javax.annotation.Nullable; import java.io.ByteArrayOutputStream; import java.io.OutputStreamWriter; +import java.nio.charset.StandardCharsets; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -77,7 +77,7 @@ public class SourceLineResultSetIterator extends ResultSetIterator<FileSourcesUp ByteArrayOutputStream bytes = new ByteArrayOutputStream(); // all the fields must be present, even if value is null - JsonWriter writer = JsonWriter.of(new OutputStreamWriter(bytes, Charsets.UTF_8)).setSerializeNulls(true); + JsonWriter writer = JsonWriter.of(new OutputStreamWriter(bytes, StandardCharsets.UTF_8)).setSerializeNulls(true); writer.beginObject(); writer.prop(SourceLineIndexDefinition.FIELD_PROJECT_UUID, projectUuid); writer.prop(SourceLineIndexDefinition.FIELD_FILE_UUID, fileUuid); diff --git a/server/sonar-server/src/main/java/org/sonar/server/source/ws/HashAction.java b/server/sonar-server/src/main/java/org/sonar/server/source/ws/HashAction.java index 35751b53abd..69cbfada5c4 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/source/ws/HashAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/source/ws/HashAction.java @@ -22,10 +22,6 @@ package org.sonar.server.source.ws; import com.google.common.base.Function; import com.google.common.io.CharStreams; import com.google.common.io.Resources; -import java.io.IOException; -import java.io.OutputStreamWriter; -import java.io.Reader; -import org.apache.commons.io.Charsets; import org.sonar.api.server.ws.Request; import org.sonar.api.server.ws.Response; import org.sonar.api.server.ws.WebService; @@ -35,6 +31,11 @@ import org.sonar.core.persistence.DbSession; import org.sonar.server.db.DbClient; import org.sonar.server.user.UserSession; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.Reader; +import java.nio.charset.StandardCharsets; + public class HashAction implements SourcesWsAction { private final DbClient dbClient; @@ -69,7 +70,7 @@ public class HashAction implements SourcesWsAction { userSession.checkProjectUuidPermission(UserRole.USER, component.projectUuid()); response.stream().setMediaType("text/plain"); - OutputStreamWriter writer = new OutputStreamWriter(response.stream().output(), Charsets.UTF_8); + OutputStreamWriter writer = new OutputStreamWriter(response.stream().output(), StandardCharsets.UTF_8); try { HashFunction hashFunction = new HashFunction(writer, componentKey); dbClient.fileSourceDao().readLineHashesStream(session, component.uuid(), hashFunction); diff --git a/server/sonar-server/src/main/java/org/sonar/server/source/ws/RawAction.java b/server/sonar-server/src/main/java/org/sonar/server/source/ws/RawAction.java index 81cc9c90547..d94c6175671 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/source/ws/RawAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/source/ws/RawAction.java @@ -21,9 +21,6 @@ package org.sonar.server.source.ws; import com.google.common.io.Resources; -import java.io.IOException; -import java.util.List; -import org.apache.commons.io.Charsets; import org.apache.commons.io.IOUtils; import org.sonar.api.server.ws.Request; import org.sonar.api.server.ws.Response; @@ -35,6 +32,10 @@ import org.sonar.server.db.DbClient; import org.sonar.server.source.SourceService; import org.sonar.server.user.UserSession; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.List; + public class RawAction implements SourcesWsAction { private final DbClient dbClient; @@ -48,7 +49,7 @@ public class RawAction implements SourcesWsAction { } @Override - public void define(WebService.NewController controller) { + public void define(WebService.NewController controller) { WebService.NewAction action = controller.createAction("raw") .setDescription("Get source code as plain text. Require See Source Code permission on file") .setSince("5.0") @@ -70,7 +71,7 @@ public class RawAction implements SourcesWsAction { ComponentDto componentDto = dbClient.componentDao().getByKey(session, fileKey); List<String> lines = sourceService.getLinesAsTxt(componentDto.uuid(), null, null); response.stream().setMediaType("text/plain"); - IOUtils.writeLines(lines, "\n", response.stream().output(), Charsets.UTF_8); + IOUtils.writeLines(lines, "\n", response.stream().output(), StandardCharsets.UTF_8); } catch (IOException e) { throw new IllegalStateException("Fail to write raw source of file " + fileKey, e); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/startup/GeneratePluginIndex.java b/server/sonar-server/src/main/java/org/sonar/server/startup/GeneratePluginIndex.java index eb50d9a0732..163ad22b6d3 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/startup/GeneratePluginIndex.java +++ b/server/sonar-server/src/main/java/org/sonar/server/startup/GeneratePluginIndex.java @@ -19,7 +19,6 @@ */ package org.sonar.server.startup; -import org.apache.commons.io.Charsets; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang.CharUtils; @@ -34,6 +33,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.Writer; +import java.nio.charset.StandardCharsets; public final class GeneratePluginIndex implements ServerComponent { @@ -51,7 +51,7 @@ public final class GeneratePluginIndex implements ServerComponent { void writeIndex(File indexFile) throws IOException { FileUtils.forceMkdir(indexFile.getParentFile()); - Writer writer = new OutputStreamWriter(new FileOutputStream(indexFile), Charsets.UTF_8); + Writer writer = new OutputStreamWriter(new FileOutputStream(indexFile), StandardCharsets.UTF_8); try { for (PluginInfo pluginInfo : repository.getPluginInfos()) { writer.append(RemotePlugin.create(pluginInfo).marshal()); diff --git a/server/sonar-server/src/main/java/org/sonar/server/test/index/TestResultSetIterator.java b/server/sonar-server/src/main/java/org/sonar/server/test/index/TestResultSetIterator.java index 482b867635a..d810a316b95 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/test/index/TestResultSetIterator.java +++ b/server/sonar-server/src/main/java/org/sonar/server/test/index/TestResultSetIterator.java @@ -20,7 +20,6 @@ package org.sonar.server.test.index; -import org.apache.commons.io.Charsets; import org.elasticsearch.action.update.UpdateRequest; import org.sonar.api.utils.text.JsonWriter; import org.sonar.core.source.db.FileSourceDto; @@ -34,6 +33,7 @@ import javax.annotation.Nullable; import java.io.ByteArrayOutputStream; import java.io.OutputStreamWriter; +import java.nio.charset.StandardCharsets; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -91,7 +91,7 @@ public class TestResultSetIterator extends ResultSetIterator<Row> { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); // all the fields must be present, even if value is null - JsonWriter writer = JsonWriter.of(new OutputStreamWriter(bytes, Charsets.UTF_8)).setSerializeNulls(true); + JsonWriter writer = JsonWriter.of(new OutputStreamWriter(bytes, StandardCharsets.UTF_8)).setSerializeNulls(true); writer.beginObject(); writer.prop(FIELD_PROJECT_UUID, projectUuid); writer.prop(FIELD_FILE_UUID, fileUuid); diff --git a/server/sonar-server/src/main/java/org/sonar/server/ui/ws/ComponentNavigationAction.java b/server/sonar-server/src/main/java/org/sonar/server/ui/ws/ComponentNavigationAction.java index 4d4fdef44d9..cc6c4737360 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/ui/ws/ComponentNavigationAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/ui/ws/ComponentNavigationAction.java @@ -19,14 +19,7 @@ */ package org.sonar.server.ui.ws; -import com.google.common.base.Charsets; import com.google.common.collect.Lists; -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; -import java.util.Date; -import java.util.List; -import java.util.Locale; -import javax.annotation.Nullable; import org.sonar.api.i18n.I18n; import org.sonar.api.resources.Qualifiers; import org.sonar.api.resources.ResourceType; @@ -53,6 +46,15 @@ import org.sonar.server.ui.ViewProxy; import org.sonar.server.ui.Views; import org.sonar.server.user.UserSession; +import javax.annotation.Nullable; + +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.util.Date; +import java.util.List; +import java.util.Locale; + public class ComponentNavigationAction implements NavigationWsAction { private static final String PARAM_COMPONENT_KEY = "componentKey"; @@ -163,7 +165,7 @@ public class ComponentNavigationAction implements NavigationWsAction { private void writeExtensions(JsonWriter json, ComponentDto component, List<ViewProxy<Page>> pages, Locale locale) { json.name("extensions").beginArray(); - for (ViewProxy<Page> page: pages) { + for (ViewProxy<Page> page : pages) { if (page.isUserAuthorized(component)) { writePage(json, getPageUrl(page, component), i18n.message(locale, page.getId() + ".page", page.getTitle())); } @@ -185,7 +187,7 @@ public class ComponentNavigationAction implements NavigationWsAction { private static String encodeComponentKey(ComponentDto component) { String componentKey = component.getKey(); try { - componentKey = URLEncoder.encode(componentKey, Charsets.UTF_8.name()); + componentKey = URLEncoder.encode(componentKey, StandardCharsets.UTF_8.name()); } catch (UnsupportedEncodingException unknownEncoding) { throw new IllegalStateException(unknownEncoding); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/ws/ServletResponse.java b/server/sonar-server/src/main/java/org/sonar/server/ws/ServletResponse.java index 98676d441fa..3fe0b5b9614 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/ws/ServletResponse.java +++ b/server/sonar-server/src/main/java/org/sonar/server/ws/ServletResponse.java @@ -19,7 +19,6 @@ */ package org.sonar.server.ws; -import com.google.common.base.Charsets; import org.sonar.api.server.ws.Response; import org.sonar.api.utils.text.JsonWriter; import org.sonar.api.utils.text.XmlWriter; @@ -30,6 +29,7 @@ import javax.annotation.CheckForNull; import java.io.ByteArrayOutputStream; import java.io.OutputStream; import java.io.OutputStreamWriter; +import java.nio.charset.StandardCharsets; public class ServletResponse implements Response { @@ -65,7 +65,7 @@ public class ServletResponse implements Response { } public String outputAsString() { - return new String(output.toByteArray(), Charsets.UTF_8); + return new String(output.toByteArray(), StandardCharsets.UTF_8); } public ServletStream reset() { @@ -79,13 +79,13 @@ public class ServletResponse implements Response { @Override public JsonWriter newJsonWriter() { stream.setMediaType(MimeTypes.JSON); - return JsonWriter.of(new OutputStreamWriter(stream.output(), Charsets.UTF_8)); + return JsonWriter.of(new OutputStreamWriter(stream.output(), StandardCharsets.UTF_8)); } @Override public XmlWriter newXmlWriter() { stream.setMediaType(MimeTypes.XML); - return XmlWriter.of(new OutputStreamWriter(stream.output(), Charsets.UTF_8)); + return XmlWriter.of(new OutputStreamWriter(stream.output(), StandardCharsets.UTF_8)); } @Override diff --git a/server/sonar-server/src/main/java/org/sonar/server/ws/WebServiceEngine.java b/server/sonar-server/src/main/java/org/sonar/server/ws/WebServiceEngine.java index 6df77bae14d..2b43b9c9f30 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/ws/WebServiceEngine.java +++ b/server/sonar-server/src/main/java/org/sonar/server/ws/WebServiceEngine.java @@ -19,10 +19,6 @@ */ package org.sonar.server.ws; -import com.google.common.base.Charsets; -import java.io.OutputStreamWriter; -import java.util.List; -import javax.servlet.http.HttpServletResponse; import org.picocontainer.Startable; import org.sonar.api.ServerSide; import org.sonar.api.i18n.I18n; @@ -38,6 +34,12 @@ import org.sonar.server.exceptions.ServerException; import org.sonar.server.plugins.MimeTypes; import org.sonar.server.user.UserSession; +import javax.servlet.http.HttpServletResponse; + +import java.io.OutputStreamWriter; +import java.nio.charset.StandardCharsets; +import java.util.List; + /** * @since 4.2 */ @@ -120,7 +122,7 @@ public class WebServiceEngine implements Startable { stream.reset(); stream.setStatus(status); stream.setMediaType(MimeTypes.JSON); - JsonWriter json = JsonWriter.of(new OutputStreamWriter(stream.output(), Charsets.UTF_8)); + JsonWriter json = JsonWriter.of(new OutputStreamWriter(stream.output(), StandardCharsets.UTF_8)); try { json.beginObject(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/FeedFileSourcesTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/FeedFileSourcesTest.java index d45cfc7a4ec..33f94cf7010 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/FeedFileSourcesTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/FeedFileSourcesTest.java @@ -21,7 +21,6 @@ package org.sonar.server.db.migrations.v50; import org.apache.commons.dbutils.DbUtils; -import org.apache.commons.io.Charsets; import org.junit.Before; import org.junit.ClassRule; import org.junit.Test; @@ -29,6 +28,7 @@ import org.sonar.api.utils.DateUtils; import org.sonar.api.utils.System2; import org.sonar.core.persistence.DbTester; +import java.nio.charset.StandardCharsets; import java.sql.Connection; import java.sql.PreparedStatement; import java.util.List; @@ -137,84 +137,84 @@ public class FeedFileSourcesTest { "(metric_id, snapshot_id, " + columnName + ") " + "values " + "(1, 6, ?)"); - revisionStmt.setBytes(1, "1=aef12a;2=abe465;3=afb789;4=afb789".getBytes(Charsets.UTF_8)); + revisionStmt.setBytes(1, "1=aef12a;2=abe465;3=afb789;4=afb789".getBytes(StandardCharsets.UTF_8)); revisionStmt.executeUpdate(); PreparedStatement authorStmt = connection.prepareStatement("insert into project_measures " + "(metric_id, snapshot_id, " + columnName + ") " + "values " + "(2, 6, ?)"); - authorStmt.setBytes(1, "1=alice;2=bob;3=carol;4=carol".getBytes(Charsets.UTF_8)); + authorStmt.setBytes(1, "1=alice;2=bob;3=carol;4=carol".getBytes(StandardCharsets.UTF_8)); authorStmt.executeUpdate(); PreparedStatement dateStmt = connection.prepareStatement("insert into project_measures " + "(metric_id, snapshot_id, " + columnName + ") " + "values " + "(3, 6, ?)"); - dateStmt.setBytes(1, "1=2014-04-25T12:34:56+0100;2=2014-07-25T12:34:56+0100;3=2014-03-23T12:34:56+0100;4=2014-03-23T12:34:56+0100".getBytes(Charsets.UTF_8)); + dateStmt.setBytes(1, "1=2014-04-25T12:34:56+0100;2=2014-07-25T12:34:56+0100;3=2014-03-23T12:34:56+0100;4=2014-03-23T12:34:56+0100".getBytes(StandardCharsets.UTF_8)); dateStmt.executeUpdate(); PreparedStatement utHitsStmt = connection.prepareStatement("insert into project_measures " + "(metric_id, snapshot_id, " + columnName + ") " + "values " + "(4, 6, ?)"); - utHitsStmt.setBytes(1, "1=1;3=0".getBytes(Charsets.UTF_8)); + utHitsStmt.setBytes(1, "1=1;3=0".getBytes(StandardCharsets.UTF_8)); utHitsStmt.executeUpdate(); PreparedStatement utCondStmt = connection.prepareStatement("insert into project_measures " + "(metric_id, snapshot_id, " + columnName + ") " + "values " + "(5, 6, ?)"); - utCondStmt.setBytes(1, "1=4".getBytes(Charsets.UTF_8)); + utCondStmt.setBytes(1, "1=4".getBytes(StandardCharsets.UTF_8)); utCondStmt.executeUpdate(); PreparedStatement utCoveredCondStmt = connection.prepareStatement("insert into project_measures " + "(metric_id, snapshot_id, " + columnName + ") " + "values " + "(6, 6, ?)"); - utCoveredCondStmt.setBytes(1, "1=2".getBytes(Charsets.UTF_8)); + utCoveredCondStmt.setBytes(1, "1=2".getBytes(StandardCharsets.UTF_8)); utCoveredCondStmt.executeUpdate(); PreparedStatement itHitsStmt = connection.prepareStatement("insert into project_measures " + "(metric_id, snapshot_id, " + columnName + ") " + "values " + "(7, 6, ?)"); - itHitsStmt.setBytes(1, "1=2;3=0".getBytes(Charsets.UTF_8)); + itHitsStmt.setBytes(1, "1=2;3=0".getBytes(StandardCharsets.UTF_8)); itHitsStmt.executeUpdate(); PreparedStatement itCondStmt = connection.prepareStatement("insert into project_measures " + "(metric_id, snapshot_id, " + columnName + ") " + "values " + "(8, 6, ?)"); - itCondStmt.setBytes(1, "1=5".getBytes(Charsets.UTF_8)); + itCondStmt.setBytes(1, "1=5".getBytes(StandardCharsets.UTF_8)); itCondStmt.executeUpdate(); PreparedStatement itCoveredCondStmt = connection.prepareStatement("insert into project_measures " + "(metric_id, snapshot_id, " + columnName + ") " + "values " + "(9, 6, ?)"); - itCoveredCondStmt.setBytes(1, "1=3".getBytes(Charsets.UTF_8)); + itCoveredCondStmt.setBytes(1, "1=3".getBytes(StandardCharsets.UTF_8)); itCoveredCondStmt.executeUpdate(); PreparedStatement overallHitsStmt = connection.prepareStatement("insert into project_measures " + "(metric_id, snapshot_id, " + columnName + ") " + "values " + "(10, 6, ?)"); - overallHitsStmt.setBytes(1, "1=3;3=0".getBytes(Charsets.UTF_8)); + overallHitsStmt.setBytes(1, "1=3;3=0".getBytes(StandardCharsets.UTF_8)); overallHitsStmt.executeUpdate(); PreparedStatement overallCondStmt = connection.prepareStatement("insert into project_measures " + "(metric_id, snapshot_id, " + columnName + ") " + "values " + "(11, 6, ?)"); - overallCondStmt.setBytes(1, "1=6".getBytes(Charsets.UTF_8)); + overallCondStmt.setBytes(1, "1=6".getBytes(StandardCharsets.UTF_8)); overallCondStmt.executeUpdate(); PreparedStatement overallCoveredCondStmt = connection.prepareStatement("insert into project_measures " + "(metric_id, snapshot_id, " + columnName + ") " + "values " + "(12, 6, ?)"); - overallCoveredCondStmt.setBytes(1, "1=4".getBytes(Charsets.UTF_8)); + overallCoveredCondStmt.setBytes(1, "1=4".getBytes(StandardCharsets.UTF_8)); overallCoveredCondStmt.executeUpdate(); PreparedStatement duplicationDataStmt = connection.prepareStatement("insert into project_measures " + @@ -225,7 +225,7 @@ public class FeedFileSourcesTest { .setBytes( 1, "<duplications><g><b s=\"1\" l=\"1\" r=\"MyProject:src/main/xoo/prj/MyFile.xoo\"/><b s=\"2\" l=\"1\" r=\"MyProject:src/main/xoo/prj/MyFile.xoo\"/><b s=\"3\" l=\"1\" r=\"MyProject:src/main/xoo/prj/AnotherFile.xoo\"/></g></duplications>" - .getBytes(Charsets.UTF_8)); + .getBytes(StandardCharsets.UTF_8)); duplicationDataStmt.executeUpdate(); } finally { DbUtils.commitAndCloseQuietly(connection); @@ -283,7 +283,7 @@ public class FeedFileSourcesTest { .setBytes( 1, "<duplications><g><b s=\"1\" l=\"1\" r=\"MyProject:src/main/xoo/prj/MyFile.xoo\"/><b s=\"2\" l=\"1\" r=\"MyProject:src/main/xoo/prj/MyFile.xoo\"/><b s=\"3\" l=\"1\" r=\"MyProject:src/main/xoo/prj/AnotherFile.xoo\"/" - .getBytes(Charsets.UTF_8)); + .getBytes(StandardCharsets.UTF_8)); duplicationDataStmt.executeUpdate(); } finally { DbUtils.commitAndCloseQuietly(connection); diff --git a/server/sonar-server/src/test/java/org/sonar/server/debt/DebtCharacteristicsXMLImporterTest.java b/server/sonar-server/src/test/java/org/sonar/server/debt/DebtCharacteristicsXMLImporterTest.java index 9d04d96d86c..baf7ad8a5ea 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/debt/DebtCharacteristicsXMLImporterTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/debt/DebtCharacteristicsXMLImporterTest.java @@ -20,11 +20,11 @@ package org.sonar.server.debt; -import com.google.common.base.Charsets; import com.google.common.io.Resources; import org.junit.Test; import org.sonar.api.server.debt.DebtCharacteristic; +import java.nio.charset.StandardCharsets; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; @@ -108,7 +108,7 @@ public class DebtCharacteristicsXMLImporterTest { } private String getFileContent(String file) throws Exception { - return Resources.toString(Resources.getResource(getClass(), "DebtCharacteristicsXMLImporterTest/" + file), Charsets.UTF_8); + return Resources.toString(Resources.getResource(getClass(), "DebtCharacteristicsXMLImporterTest/" + file), StandardCharsets.UTF_8); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/debt/DebtModelXMLExporterTest.java b/server/sonar-server/src/test/java/org/sonar/server/debt/DebtModelXMLExporterTest.java index 071a390ded6..f463fce9693 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/debt/DebtModelXMLExporterTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/debt/DebtModelXMLExporterTest.java @@ -19,7 +19,6 @@ */ package org.sonar.server.debt; -import com.google.common.base.Charsets; import com.google.common.io.Resources; import org.apache.commons.lang.CharUtils; import org.apache.commons.lang.SystemUtils; @@ -31,6 +30,7 @@ import org.sonar.api.rule.RuleKey; import org.sonar.api.server.debt.DebtRemediationFunction; import org.sonar.api.server.debt.internal.DefaultDebtCharacteristic; +import java.nio.charset.StandardCharsets; import java.util.Collections; import java.util.List; import java.util.regex.Pattern; @@ -65,7 +65,7 @@ public class DebtModelXMLExporterTest { List<RuleDebt> rules = newArrayList( new RuleDebt().setRuleKey(RuleKey.of("checkstyle", "Regexp")) .setSubCharacteristicKey("MEMORY_USE").setFunction(DebtRemediationFunction.Type.LINEAR_OFFSET.name()).setCoefficient("3d").setOffset("15min") - ); + ); assertSimilarXml(getFileContent("export_xml.xml"), xmlExporter.export(debtModel, rules)); } @@ -109,7 +109,7 @@ public class DebtModelXMLExporterTest { List<RuleDebt> rules = newArrayList( new RuleDebt().setRuleKey(RuleKey.of("checkstyle", "Regexp")) .setSubCharacteristicKey("MEMORY_USE").setFunction(DebtRemediationFunction.Type.LINEAR.name()).setCoefficient("3d") - ); + ); assertThat(xmlExporter.export(debtModel, rules)).isEqualTo( "<sqale>" + SystemUtils.LINE_SEPARATOR + " <chc>" + SystemUtils.LINE_SEPARATOR + @@ -138,10 +138,10 @@ public class DebtModelXMLExporterTest { " </chc>" + SystemUtils.LINE_SEPARATOR + " </chc>" + SystemUtils.LINE_SEPARATOR + "</sqale>" + SystemUtils.LINE_SEPARATOR - ); + ); } private String getFileContent(String file) throws Exception { - return Resources.toString(Resources.getResource(getClass(), "DebtModelXMLExporterTest/" + file), Charsets.UTF_8); + return Resources.toString(Resources.getResource(getClass(), "DebtModelXMLExporterTest/" + file), StandardCharsets.UTF_8); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/debt/DebtRulesXMLImporterTest.java b/server/sonar-server/src/test/java/org/sonar/server/debt/DebtRulesXMLImporterTest.java index 087e96116d9..233d486c2b0 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/debt/DebtRulesXMLImporterTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/debt/DebtRulesXMLImporterTest.java @@ -20,13 +20,13 @@ package org.sonar.server.debt; -import com.google.common.base.Charsets; import com.google.common.io.Resources; import org.junit.Test; import org.sonar.api.rule.RuleKey; import org.sonar.api.server.debt.DebtRemediationFunction; import org.sonar.api.utils.ValidationMessages; +import java.nio.charset.StandardCharsets; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; @@ -253,6 +253,6 @@ public class DebtRulesXMLImporterTest { private String getFileContent(String file) throws Exception { return Resources.toString(Resources.getResource(getClass(), "DebtRulesXMLImporterTest/" + file), - Charsets.UTF_8); + StandardCharsets.UTF_8); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/duplication/ws/DuplicationsParserTest.java b/server/sonar-server/src/test/java/org/sonar/server/duplication/ws/DuplicationsParserTest.java index a4f43944929..0bbef9a73dd 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/duplication/ws/DuplicationsParserTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/duplication/ws/DuplicationsParserTest.java @@ -20,7 +20,6 @@ package org.sonar.server.duplication.ws; -import com.google.common.base.Charsets; import com.google.common.base.Predicate; import com.google.common.collect.Iterables; import com.google.common.io.Files; @@ -39,6 +38,7 @@ import javax.annotation.Nullable; import java.io.File; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; @@ -229,10 +229,10 @@ public class DuplicationsParserTest { } private String getData(String file) throws IOException { - return Files.toString(new File(Resources.getResource(this.getClass(), "DuplicationsParserTest/" + file).getFile()), Charsets.UTF_8); + return Files.toString(new File(Resources.getResource(this.getClass(), "DuplicationsParserTest/" + file).getFile()), StandardCharsets.UTF_8); } - private static DuplicationsParser.Duplication duplication(List<DuplicationsParser.Duplication> duplications, @Nullable final String componentKey){ + private static DuplicationsParser.Duplication duplication(List<DuplicationsParser.Duplication> duplications, @Nullable final String componentKey) { return Iterables.find(duplications, new Predicate<DuplicationsParser.Duplication>() { @Override public boolean apply(@Nullable DuplicationsParser.Duplication input) { diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/IssueChangesEmailTemplateTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/IssueChangesEmailTemplateTest.java index 3c82fb374dc..0c0d3ede87f 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/IssueChangesEmailTemplateTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/IssueChangesEmailTemplateTest.java @@ -20,7 +20,6 @@ package org.sonar.server.issue.notification; import com.google.common.io.Resources; -import org.apache.commons.codec.Charsets; import org.apache.commons.lang.StringUtils; import org.junit.Before; import org.junit.Test; @@ -34,6 +33,8 @@ import org.sonar.api.user.UserFinder; import org.sonar.core.component.ComponentDto; import org.sonar.plugins.emailnotifications.api.EmailMessage; +import java.nio.charset.StandardCharsets; + import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -73,7 +74,7 @@ public class IssueChangesEmailTemplateTest { String message = email.getMessage(); String expected = Resources.toString(Resources.getResource( "org/sonar/server/issue/notification/IssueChangesEmailTemplateTest/email_with_assignee_change.txt"), - Charsets.UTF_8 + StandardCharsets.UTF_8 ); expected = StringUtils.remove(expected, '\r'); assertThat(message).isEqualTo(expected); @@ -93,7 +94,7 @@ public class IssueChangesEmailTemplateTest { String message = email.getMessage(); String expected = Resources.toString(Resources.getResource( "org/sonar/server/issue/notification/IssueChangesEmailTemplateTest/email_with_action_plan_change.txt"), - Charsets.UTF_8 + StandardCharsets.UTF_8 ); expected = StringUtils.remove(expected, '\r'); assertThat(message).isEqualTo(expected); @@ -113,7 +114,7 @@ public class IssueChangesEmailTemplateTest { String message = email.getMessage(); String expected = Resources.toString(Resources.getResource( "org/sonar/server/issue/notification/IssueChangesEmailTemplateTest/email_should_display_resolution_change.txt"), - Charsets.UTF_8 + StandardCharsets.UTF_8 ); expected = StringUtils.remove(expected, '\r'); assertThat(message).isEqualTo(expected); @@ -132,7 +133,7 @@ public class IssueChangesEmailTemplateTest { String message = email.getMessage(); String expected = Resources.toString(Resources.getResource( "org/sonar/server/issue/notification/IssueChangesEmailTemplateTest/display_component_key_if_no_component_name.txt"), - Charsets.UTF_8 + StandardCharsets.UTF_8 ); expected = StringUtils.remove(expected, '\r'); assertThat(message).isEqualTo(expected); @@ -154,7 +155,7 @@ public class IssueChangesEmailTemplateTest { String message = email.getMessage(); String expected = Resources.toString(Resources.getResource( - "org/sonar/server/issue/notification/IssueChangesEmailTemplateTest/email_with_multiple_changes.txt"), Charsets.UTF_8); + "org/sonar/server/issue/notification/IssueChangesEmailTemplateTest/email_with_multiple_changes.txt"), StandardCharsets.UTF_8); expected = StringUtils.remove(expected, '\r'); assertThat(message).isEqualTo(expected); assertThat(email.getFrom()).isNull(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/MyNewIssuesEmailTemplateTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/MyNewIssuesEmailTemplateTest.java index e30e67d1f37..750de90cdd0 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/MyNewIssuesEmailTemplateTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/MyNewIssuesEmailTemplateTest.java @@ -20,7 +20,6 @@ package org.sonar.server.issue.notification; -import com.google.common.base.Charsets; import org.apache.commons.io.IOUtils; import org.junit.Before; import org.junit.Test; @@ -33,6 +32,7 @@ import org.sonar.plugins.emailnotifications.api.EmailMessage; import org.sonar.server.user.index.UserDoc; import org.sonar.server.user.index.UserIndex; +import java.nio.charset.StandardCharsets; import java.util.Date; import java.util.Locale; @@ -95,7 +95,7 @@ public class MyNewIssuesEmailTemplateTest { EmailMessage message = sut.format(notification); // TODO datetime to be completed when test is isolated from JVM timezone - String file = IOUtils.toString(getClass().getResource("MyNewIssuesEmailTemplateTest/email_with_all_details.txt"), Charsets.UTF_8); + String file = IOUtils.toString(getClass().getResource("MyNewIssuesEmailTemplateTest/email_with_all_details.txt"), StandardCharsets.UTF_8); assertThat(message.getMessage()).startsWith(file); } @@ -124,7 +124,7 @@ public class MyNewIssuesEmailTemplateTest { EmailMessage message = sut.format(notification); // TODO datetime to be completed when test is isolated from JVM timezone - String file = IOUtils.toString(getClass().getResource("MyNewIssuesEmailTemplateTest/email_with_no_assignee_tags_components.txt"), Charsets.UTF_8); + String file = IOUtils.toString(getClass().getResource("MyNewIssuesEmailTemplateTest/email_with_no_assignee_tags_components.txt"), StandardCharsets.UTF_8); assertThat(message.getMessage()).startsWith(file); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/NewIssuesEmailTemplateTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/NewIssuesEmailTemplateTest.java index abd0556bc3c..5e58492a861 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/NewIssuesEmailTemplateTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/NewIssuesEmailTemplateTest.java @@ -19,7 +19,6 @@ */ package org.sonar.server.issue.notification; -import com.google.common.base.Charsets; import org.apache.commons.io.IOUtils; import org.junit.Before; import org.junit.Test; @@ -32,13 +31,21 @@ import org.sonar.plugins.emailnotifications.api.EmailMessage; import org.sonar.server.user.index.UserDoc; import org.sonar.server.user.index.UserIndex; +import java.nio.charset.StandardCharsets; import java.util.Locale; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Matchers.*; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyString; +import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static org.sonar.server.issue.notification.NewIssuesStatistics.Metric.*; +import static org.sonar.server.issue.notification.NewIssuesStatistics.Metric.ASSIGNEE; +import static org.sonar.server.issue.notification.NewIssuesStatistics.Metric.COMPONENT; +import static org.sonar.server.issue.notification.NewIssuesStatistics.Metric.DEBT; +import static org.sonar.server.issue.notification.NewIssuesStatistics.Metric.RULE; +import static org.sonar.server.issue.notification.NewIssuesStatistics.Metric.SEVERITY; +import static org.sonar.server.issue.notification.NewIssuesStatistics.Metric.TAG; public class NewIssuesEmailTemplateTest { @@ -104,7 +111,7 @@ public class NewIssuesEmailTemplateTest { EmailMessage message = template.format(notification); // TODO datetime to be completed when test is isolated from JVM timezone - String expectedContent = IOUtils.toString(getClass().getResource("NewIssuesEmailTemplateTest/email_with_all_details.txt"), Charsets.UTF_8); + String expectedContent = IOUtils.toString(getClass().getResource("NewIssuesEmailTemplateTest/email_with_all_details.txt"), StandardCharsets.UTF_8); assertThat(message.getMessage()).startsWith(expectedContent); } @@ -115,7 +122,7 @@ public class NewIssuesEmailTemplateTest { EmailMessage message = template.format(notification); // TODO datetime to be completed when test is isolated from JVM timezone - String expectedContent = IOUtils.toString(getClass().getResource("NewIssuesEmailTemplateTest/email_with_partial_details.txt"), Charsets.UTF_8); + String expectedContent = IOUtils.toString(getClass().getResource("NewIssuesEmailTemplateTest/email_with_partial_details.txt"), StandardCharsets.UTF_8); assertThat(message.getMessage()).startsWith(expectedContent); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/plugins/UpdateCenterClientTest.java b/server/sonar-server/src/test/java/org/sonar/server/plugins/UpdateCenterClientTest.java index 9c9e5a5bf6a..9d6581bb583 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/plugins/UpdateCenterClientTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/plugins/UpdateCenterClientTest.java @@ -19,7 +19,6 @@ */ package org.sonar.server.plugins; -import com.google.common.base.Charsets; import org.junit.Before; import org.junit.Test; import org.sonar.api.config.Settings; @@ -30,6 +29,7 @@ import org.sonar.updatecenter.common.Version; 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.Matchers.any; @@ -54,9 +54,9 @@ public class UpdateCenterClientTest { @Test public void downloadUpdateCenter() throws URISyntaxException { - when(reader.readString(new URI(BASE_URL), Charsets.UTF_8)).thenReturn("publicVersions=2.2,2.3"); + when(reader.readString(new URI(BASE_URL), StandardCharsets.UTF_8)).thenReturn("publicVersions=2.2,2.3"); UpdateCenter plugins = client.getUpdateCenter(); - verify(reader, times(1)).readString(new URI(BASE_URL), Charsets.UTF_8); + verify(reader, times(1)).readString(new URI(BASE_URL), StandardCharsets.UTF_8); assertThat(plugins.getSonar().getVersions()).containsOnly(Version.create("2.2"), Version.create("2.3")); assertThat(client.getLastRefreshDate()).isNotNull(); } @@ -68,27 +68,27 @@ public class UpdateCenterClientTest { @Test public void ignore_connection_errors() { - when(reader.readString(any(URI.class), eq(Charsets.UTF_8))).thenThrow(new SonarException()); + when(reader.readString(any(URI.class), eq(StandardCharsets.UTF_8))).thenThrow(new SonarException()); assertThat(client.getUpdateCenter()).isNull(); } @Test public void cache_data() throws Exception { - when(reader.readString(new URI(BASE_URL), Charsets.UTF_8)).thenReturn("sonar.versions=2.2,2.3"); + when(reader.readString(new URI(BASE_URL), StandardCharsets.UTF_8)).thenReturn("sonar.versions=2.2,2.3"); client.getUpdateCenter(); client.getUpdateCenter(); - verify(reader, times(1)).readString(new URI(BASE_URL), Charsets.UTF_8); + verify(reader, times(1)).readString(new URI(BASE_URL), StandardCharsets.UTF_8); } @Test public void forceRefresh() throws Exception { - when(reader.readString(new URI(BASE_URL), Charsets.UTF_8)).thenReturn("sonar.versions=2.2,2.3"); + when(reader.readString(new URI(BASE_URL), StandardCharsets.UTF_8)).thenReturn("sonar.versions=2.2,2.3"); client.getUpdateCenter(); client.getUpdateCenter(true); - verify(reader, times(2)).readString(new URI(BASE_URL), Charsets.UTF_8); + verify(reader, times(2)).readString(new URI(BASE_URL), StandardCharsets.UTF_8); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperMediumTest.java index 6417ff3686d..6c017b07ad7 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/QProfileBackuperMediumTest.java @@ -19,7 +19,6 @@ */ package org.sonar.server.qualityprofile; -import com.google.common.base.Charsets; import com.google.common.collect.Lists; import com.google.common.io.Resources; import org.custommonkey.xmlunit.Diff; @@ -39,13 +38,14 @@ import org.sonar.core.rule.RuleParamDto; import org.sonar.server.db.DbClient; import org.sonar.server.rule.RuleTesting; import org.sonar.server.tester.ServerTester; +import org.sonar.server.tester.UserSessionRule; import javax.xml.stream.XMLStreamException; import java.io.StringReader; import java.io.StringWriter; +import java.nio.charset.StandardCharsets; import java.util.List; -import org.sonar.server.tester.UserSessionRule; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.fail; @@ -108,7 +108,7 @@ public class QProfileBackuperMediumTest { XMLUnit.setIgnoreWhitespace(true); XMLUnit.setIgnoreComments(true); Diff diff = XMLUnit.compareXML(output.toString(), - Resources.toString(getClass().getResource("QProfileBackuperMediumTest/expected-backup.xml"), Charsets.UTF_8)); + Resources.toString(getClass().getResource("QProfileBackuperMediumTest/expected-backup.xml"), StandardCharsets.UTF_8)); assertThat(diff.identical()).as(diff.toString()).isTrue(); } @@ -127,7 +127,7 @@ public class QProfileBackuperMediumTest { public void restore_and_create_profile() throws Exception { // Backup file declares profile P1 on xoo tester.get(QProfileBackuper.class).restore(new StringReader( - Resources.toString(getClass().getResource("QProfileBackuperMediumTest/restore.xml"), Charsets.UTF_8)), + Resources.toString(getClass().getResource("QProfileBackuperMediumTest/restore.xml"), StandardCharsets.UTF_8)), null); QualityProfileDto profile = db.qualityProfileDao().getByNameAndLanguage("P1", "xoo"); @@ -158,7 +158,7 @@ public class QProfileBackuperMediumTest { // restore backup, which activates only x1 // -> update x1 and deactivate x2 tester.get(QProfileBackuper.class).restore(new StringReader( - Resources.toString(getClass().getResource("QProfileBackuperMediumTest/restore.xml"), Charsets.UTF_8)), null); + Resources.toString(getClass().getResource("QProfileBackuperMediumTest/restore.xml"), StandardCharsets.UTF_8)), null); List<ActiveRule> activeRules = Lists.newArrayList(tester.get(QProfileLoader.class).findActiveRulesByProfile(QProfileTesting.XOO_P1_KEY)); assertThat(activeRules).hasSize(1); @@ -185,7 +185,7 @@ public class QProfileBackuperMediumTest { // restore backup of child profile -> overrides x1 tester.get(QProfileBackuper.class).restore(new StringReader( - Resources.toString(getClass().getResource("QProfileBackuperMediumTest/restore-child.xml"), Charsets.UTF_8)), null); + Resources.toString(getClass().getResource("QProfileBackuperMediumTest/restore-child.xml"), StandardCharsets.UTF_8)), null); // parent profile is unchanged List<ActiveRule> activeRules = Lists.newArrayList(tester.get(QProfileLoader.class).findActiveRulesByProfile(QProfileTesting.XOO_P1_KEY)); @@ -220,7 +220,7 @@ public class QProfileBackuperMediumTest { // restore backup of parent profile -> update x1 and propagates to child tester.get(QProfileBackuper.class).restore(new StringReader( - Resources.toString(getClass().getResource("QProfileBackuperMediumTest/restore-parent.xml"), Charsets.UTF_8)), null); + Resources.toString(getClass().getResource("QProfileBackuperMediumTest/restore-parent.xml"), StandardCharsets.UTF_8)), null); // parent profile is updated List<ActiveRule> activeRules = Lists.newArrayList(tester.get(QProfileLoader.class).findActiveRulesByProfile(QProfileTesting.XOO_P1_KEY)); @@ -255,7 +255,7 @@ public class QProfileBackuperMediumTest { // backup of child profile contains x2 but not x1 tester.get(QProfileBackuper.class).restore(new StringReader( - Resources.toString(getClass().getResource("QProfileBackuperMediumTest/keep_other_inherited_rules.xml"), Charsets.UTF_8)), QProfileTesting.XOO_P2_NAME); + Resources.toString(getClass().getResource("QProfileBackuperMediumTest/keep_other_inherited_rules.xml"), StandardCharsets.UTF_8)), QProfileTesting.XOO_P2_NAME); // x1 and x2 List<ActiveRule> activeRules = Lists.newArrayList(tester.get(QProfileLoader.class).findActiveRulesByProfile(QProfileTesting.XOO_P2_KEY)); @@ -266,7 +266,7 @@ public class QProfileBackuperMediumTest { public void fail_to_restore_if_not_xml_backup() throws Exception { try { tester.get(QProfileBackuper.class).restore(new StringReader( - Resources.toString(getClass().getResource("QProfileBackuperMediumTest/not-xml-backup.txt"), Charsets.UTF_8)), null); + Resources.toString(getClass().getResource("QProfileBackuperMediumTest/not-xml-backup.txt"), StandardCharsets.UTF_8)), null); fail(); } catch (IllegalStateException e) { assertThat(e).hasMessage("Fail to restore Quality profile backup"); @@ -278,7 +278,7 @@ public class QProfileBackuperMediumTest { public void fail_to_restore_if_bad_xml_format() throws Exception { try { tester.get(QProfileBackuper.class).restore(new StringReader( - Resources.toString(getClass().getResource("QProfileBackuperMediumTest/bad-xml-backup.xml"), Charsets.UTF_8)), null); + Resources.toString(getClass().getResource("QProfileBackuperMediumTest/bad-xml-backup.xml"), StandardCharsets.UTF_8)), null); fail(); } catch (IllegalArgumentException e) { assertThat(e).hasMessage("Backup XML is not valid. Root element must be <profile>."); @@ -289,7 +289,7 @@ public class QProfileBackuperMediumTest { public void fail_to_restore_if_duplicate_rule() throws Exception { try { tester.get(QProfileBackuper.class).restore(new StringReader( - Resources.toString(getClass().getResource("QProfileBackuperMediumTest/duplicates-xml-backup.xml"), Charsets.UTF_8)), null); + Resources.toString(getClass().getResource("QProfileBackuperMediumTest/duplicates-xml-backup.xml"), StandardCharsets.UTF_8)), null); fail(); } catch (IllegalArgumentException e) { assertThat(e).hasMessage("The quality profile cannot be restored as it contains duplicates for the following rules: xoo:x1, xoo:x2"); @@ -299,7 +299,7 @@ public class QProfileBackuperMediumTest { @Test public void restore_and_override_profile_name() throws Exception { tester.get(QProfileBackuper.class).restore(new StringReader( - Resources.toString(getClass().getResource("QProfileBackuperMediumTest/restore.xml"), Charsets.UTF_8)), + Resources.toString(getClass().getResource("QProfileBackuperMediumTest/restore.xml"), StandardCharsets.UTF_8)), QProfileTesting.XOO_P3_NAME); List<ActiveRule> activeRules = Lists.newArrayList(tester.get(QProfileLoader.class).findActiveRulesByProfile(QProfileTesting.XOO_P1_KEY)); @@ -314,7 +314,7 @@ public class QProfileBackuperMediumTest { @Test public void restore_profile_with_zero_rules() throws Exception { tester.get(QProfileBackuper.class).restore(new StringReader( - Resources.toString(getClass().getResource("QProfileBackuperMediumTest/empty.xml"), Charsets.UTF_8)), + Resources.toString(getClass().getResource("QProfileBackuperMediumTest/empty.xml"), StandardCharsets.UTF_8)), null); dbSession.clearCache(); diff --git a/server/sonar-server/src/test/java/org/sonar/server/startup/JdbcDriverDeployerTest.java b/server/sonar-server/src/test/java/org/sonar/server/startup/JdbcDriverDeployerTest.java index 56d686142a5..cd6e4e121ef 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/startup/JdbcDriverDeployerTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/startup/JdbcDriverDeployerTest.java @@ -19,7 +19,6 @@ */ package org.sonar.server.startup; -import com.google.common.base.Charsets; import com.google.common.io.Files; import com.google.common.io.Resources; import org.junit.Rule; @@ -29,6 +28,7 @@ import org.sonar.api.config.Settings; import org.sonar.server.platform.DefaultServerFileSystem; import java.io.File; +import java.nio.charset.StandardCharsets; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -60,7 +60,7 @@ public class JdbcDriverDeployerTest { assertThat(deployedFile).exists(); assertThat(deployedFile).hasContentEqualTo(driver); - assertThat(Files.toString(deployedIndex, Charsets.UTF_8)).isEqualTo("my-driver.jar|02b97f7bc37b2b68fc847fcc3fc1c156"); + assertThat(Files.toString(deployedIndex, StandardCharsets.UTF_8)).isEqualTo("my-driver.jar|02b97f7bc37b2b68fc847fcc3fc1c156"); } @Test diff --git a/server/sonar-server/src/test/java/org/sonar/server/ws/WsTester.java b/server/sonar-server/src/test/java/org/sonar/server/ws/WsTester.java index 1be9064a188..6608f18be0f 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/ws/WsTester.java +++ b/server/sonar-server/src/test/java/org/sonar/server/ws/WsTester.java @@ -20,7 +20,6 @@ package org.sonar.server.ws; import com.google.common.collect.Maps; -import org.apache.commons.io.Charsets; import org.apache.commons.io.IOUtils; import org.sonar.api.server.ws.Response; import org.sonar.api.server.ws.WebService; @@ -39,6 +38,7 @@ import java.io.OutputStream; import java.io.OutputStreamWriter; import java.net.HttpURLConnection; import java.net.URL; +import java.nio.charset.StandardCharsets; import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; @@ -137,12 +137,12 @@ public class WsTester { @Override public JsonWriter newJsonWriter() { - return JsonWriter.of(new OutputStreamWriter(output, Charsets.UTF_8)); + return JsonWriter.of(new OutputStreamWriter(output, StandardCharsets.UTF_8)); } @Override public XmlWriter newXmlWriter() { - return XmlWriter.of(new OutputStreamWriter(output, Charsets.UTF_8)); + return XmlWriter.of(new OutputStreamWriter(output, StandardCharsets.UTF_8)); } @Override @@ -161,7 +161,7 @@ public class WsTester { } public String outputAsString() { - return new String(output.toByteArray(), Charsets.UTF_8); + return new String(output.toByteArray(), StandardCharsets.UTF_8); } } @@ -177,7 +177,7 @@ public class WsTester { } public String outputAsString() { - return new String(response.output.toByteArray(), Charsets.UTF_8); + return new String(response.output.toByteArray(), StandardCharsets.UTF_8); } public byte[] output() { diff --git a/sonar-application/src/main/java/org/sonar/application/PropsBuilder.java b/sonar-application/src/main/java/org/sonar/application/PropsBuilder.java index 167b8a3e0c7..c6c3404d0b3 100644 --- a/sonar-application/src/main/java/org/sonar/application/PropsBuilder.java +++ b/sonar-application/src/main/java/org/sonar/application/PropsBuilder.java @@ -19,7 +19,6 @@ */ package org.sonar.application; -import org.apache.commons.io.Charsets; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.sonar.process.ConfigurationUtils; @@ -32,6 +31,7 @@ import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; import java.net.URISyntaxException; +import java.nio.charset.StandardCharsets; import java.util.Properties; class PropsBuilder { @@ -87,7 +87,7 @@ class PropsBuilder { Properties p = new Properties(); File propsFile = new File(homeDir, "conf/sonar.properties"); if (propsFile.exists()) { - Reader reader = new InputStreamReader(new FileInputStream(propsFile), Charsets.UTF_8); + Reader reader = new InputStreamReader(new FileInputStream(propsFile), StandardCharsets.UTF_8); try { p.load(reader); } finally { diff --git a/sonar-application/src/test/java/org/sonar/application/PropsBuilderTest.java b/sonar-application/src/test/java/org/sonar/application/PropsBuilderTest.java index 9dd5c240dab..429a776ba3e 100644 --- a/sonar-application/src/test/java/org/sonar/application/PropsBuilderTest.java +++ b/sonar-application/src/test/java/org/sonar/application/PropsBuilderTest.java @@ -19,7 +19,6 @@ */ package org.sonar.application; -import org.apache.commons.io.Charsets; import org.apache.commons.io.FileUtils; import org.junit.Before; import org.junit.Rule; @@ -29,6 +28,7 @@ import org.sonar.process.Props; import java.io.File; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.Properties; import static org.assertj.core.api.Assertions.assertThat; @@ -122,7 +122,7 @@ public class PropsBuilderTest { @Test public void utf8_file_encoding() throws Exception { - FileUtils.write(new File(homeDir, "conf/sonar.properties"), "utf8prop=Thônes", Charsets.UTF_8); + FileUtils.write(new File(homeDir, "conf/sonar.properties"), "utf8prop=Thônes", StandardCharsets.UTF_8); Props props = new PropsBuilder(new Properties(), jdbcSettings, homeDir).build(); assertThat(props.value("utf8prop")).isEqualTo("Thônes"); } diff --git a/sonar-colorizer/src/main/java/org/sonar/colorizer/HtmlDecorator.java b/sonar-colorizer/src/main/java/org/sonar/colorizer/HtmlDecorator.java index 35f1d896d34..48b65acaaf9 100644 --- a/sonar-colorizer/src/main/java/org/sonar/colorizer/HtmlDecorator.java +++ b/sonar-colorizer/src/main/java/org/sonar/colorizer/HtmlDecorator.java @@ -21,11 +21,11 @@ package org.sonar.colorizer; import com.google.common.io.ByteStreams; import com.google.common.io.Closeables; -import org.apache.commons.io.Charsets; import org.sonar.channel.CodeReader; import java.io.IOException; import java.io.InputStream; +import java.nio.charset.StandardCharsets; /** * @deprecated since 4.5.2 replace by highlighting mechanism @@ -99,7 +99,7 @@ public class HtmlDecorator extends Tokenizer { InputStream input = null; try { input = HtmlRenderer.class.getResourceAsStream(CSS_PATH); - return new String(ByteStreams.toByteArray(input), Charsets.UTF_8); + return new String(ByteStreams.toByteArray(input), StandardCharsets.UTF_8); } catch (IOException e) { throw new SynhtaxHighlightingException("SonarQube Colorizer CSS file not found: " + CSS_PATH, e); diff --git a/sonar-core/src/main/java/org/sonar/core/graph/graphson/GraphsonUtil.java b/sonar-core/src/main/java/org/sonar/core/graph/graphson/GraphsonUtil.java index 241d2645140..a837bbf9ac0 100644 --- a/sonar-core/src/main/java/org/sonar/core/graph/graphson/GraphsonUtil.java +++ b/sonar-core/src/main/java/org/sonar/core/graph/graphson/GraphsonUtil.java @@ -23,7 +23,6 @@ import com.tinkerpop.blueprints.Direction; import com.tinkerpop.blueprints.Edge; import com.tinkerpop.blueprints.Element; import com.tinkerpop.blueprints.Vertex; -import org.apache.commons.io.Charsets; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; @@ -34,7 +33,14 @@ import javax.annotation.Nullable; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; -import java.util.*; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; import static org.sonar.core.graph.graphson.ElementPropertyConfig.ElementPropertiesRule; @@ -549,7 +555,7 @@ class GraphsonUtil { * Creates a vertex from GraphSON using settings supplied in the constructor. */ Vertex vertexFromJson(InputStream json) throws ParseException, IOException { - return this.vertexFromJson((JSONObject) parser.parse(new InputStreamReader(json, Charsets.UTF_8))); + return this.vertexFromJson((JSONObject) parser.parse(new InputStreamReader(json, StandardCharsets.UTF_8))); } /** @@ -563,7 +569,7 @@ class GraphsonUtil { * Creates an edge from GraphSON using settings supplied in the constructor. */ Edge edgeFromJson(InputStream json, Vertex out, Vertex in) throws IOException, ParseException { - return this.edgeFromJson((JSONObject) parser.parse(new InputStreamReader(json, Charsets.UTF_8)), out, in); + return this.edgeFromJson((JSONObject) parser.parse(new InputStreamReader(json, StandardCharsets.UTF_8)), out, in); } /** diff --git a/sonar-core/src/main/java/org/sonar/core/measure/db/MeasureDto.java b/sonar-core/src/main/java/org/sonar/core/measure/db/MeasureDto.java index 990e8dfd512..7b4e45e2cdc 100644 --- a/sonar-core/src/main/java/org/sonar/core/measure/db/MeasureDto.java +++ b/sonar-core/src/main/java/org/sonar/core/measure/db/MeasureDto.java @@ -20,12 +20,13 @@ package org.sonar.core.measure.db; -import com.google.common.base.Charsets; import org.sonar.api.rule.Severity; import javax.annotation.CheckForNull; import javax.annotation.Nullable; +import java.nio.charset.StandardCharsets; + import static com.google.common.base.Preconditions.checkArgument; public class MeasureDto { @@ -75,7 +76,7 @@ public class MeasureDto { @CheckForNull public String getData() { if (dataValue != null) { - return new String(dataValue, Charsets.UTF_8); + return new String(dataValue, StandardCharsets.UTF_8); } return textValue; } @@ -86,7 +87,7 @@ public class MeasureDto { this.dataValue = null; } else if (data.length() > MAX_TEXT_VALUE_LENGTH) { this.textValue = null; - this.dataValue = data.getBytes(Charsets.UTF_8); + this.dataValue = data.getBytes(StandardCharsets.UTF_8); } else { this.textValue = data; this.dataValue = null; diff --git a/sonar-core/src/main/java/org/sonar/core/util/DefaultHttpDownloader.java b/sonar-core/src/main/java/org/sonar/core/util/DefaultHttpDownloader.java index 64a4a43942e..ad63f77f220 100644 --- a/sonar-core/src/main/java/org/sonar/core/util/DefaultHttpDownloader.java +++ b/sonar-core/src/main/java/org/sonar/core/util/DefaultHttpDownloader.java @@ -29,7 +29,6 @@ import com.google.common.io.CharStreams; import com.google.common.io.Files; import com.google.common.io.InputSupplier; import org.apache.commons.codec.binary.Base64; -import org.apache.commons.io.Charsets; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.sonar.api.config.Settings; @@ -50,6 +49,7 @@ import java.net.Proxy; import java.net.ProxySelector; import java.net.URI; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.List; import java.util.Map; import java.util.zip.GZIPInputStream; @@ -282,7 +282,7 @@ public class DefaultHttpDownloader extends HttpDownloader { // allow both GZip and Deflate (ZLib) encodings connection.setRequestProperty("Accept-Encoding", "gzip"); if (!Strings.isNullOrEmpty(login)) { - String encoded = Base64.encodeBase64String((login + ":" + password).getBytes(Charsets.UTF_8)); + String encoded = Base64.encodeBase64String((login + ":" + password).getBytes(StandardCharsets.UTF_8)); connection.setRequestProperty("Authorization", "Basic " + encoded); } connection.setConnectTimeout(TIMEOUT_MILLISECONDS); diff --git a/sonar-core/src/test/java/org/sonar/core/util/DefaultHttpDownloaderTest.java b/sonar-core/src/test/java/org/sonar/core/util/DefaultHttpDownloaderTest.java index 06dcdedf7c1..75dc1732b0a 100644 --- a/sonar-core/src/test/java/org/sonar/core/util/DefaultHttpDownloaderTest.java +++ b/sonar-core/src/test/java/org/sonar/core/util/DefaultHttpDownloaderTest.java @@ -19,7 +19,6 @@ */ package org.sonar.core.util; -import com.google.common.base.Charsets; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; import org.junit.AfterClass; @@ -49,6 +48,7 @@ import java.net.SocketAddress; import java.net.SocketTimeoutException; import java.net.URI; import java.net.URISyntaxException; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Properties; import java.util.zip.GZIPOutputStream; @@ -132,19 +132,19 @@ public class DefaultHttpDownloaderTest { @Test public void readString() throws URISyntaxException { - String text = new DefaultHttpDownloader(new Settings()).readString(new URI(baseUrl), Charsets.UTF_8); + String text = new DefaultHttpDownloader(new Settings()).readString(new URI(baseUrl), StandardCharsets.UTF_8); assertThat(text.length()).isGreaterThan(10); } @Test public void readGzipString() throws URISyntaxException { - String text = new DefaultHttpDownloader(new Settings()).readString(new URI(baseUrl + "/gzip/"), Charsets.UTF_8); + String text = new DefaultHttpDownloader(new Settings()).readString(new URI(baseUrl + "/gzip/"), StandardCharsets.UTF_8); assertThat(text).isEqualTo("GZIP response"); } @Test public void readStringWithDefaultTimeout() throws URISyntaxException { - String text = new DefaultHttpDownloader(new Settings()).readString(new URI(baseUrl + "/timeout/"), Charsets.UTF_8); + String text = new DefaultHttpDownloader(new Settings()).readString(new URI(baseUrl + "/timeout/"), StandardCharsets.UTF_8); assertThat(text.length()).isGreaterThan(10); } @@ -160,7 +160,7 @@ public class DefaultHttpDownloaderTest { public void describeTo(Description arg0) { } }); - new DefaultHttpDownloader(new Settings(), 50).readString(new URI(baseUrl + "/timeout/"), Charsets.UTF_8); + new DefaultHttpDownloader(new Settings(), 50).readString(new URI(baseUrl + "/timeout/"), StandardCharsets.UTF_8); } @Test @@ -201,7 +201,7 @@ public class DefaultHttpDownloaderTest { @Test public void followRedirect() throws URISyntaxException { - String content = new DefaultHttpDownloader(new Settings()).readString(new URI(baseUrl + "/redirect/"), Charsets.UTF_8); + String content = new DefaultHttpDownloader(new Settings()).readString(new URI(baseUrl + "/redirect/"), StandardCharsets.UTF_8); assertThat(content).contains("agent"); } diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/java/JavaStatementBuilderTest.java b/sonar-duplications/src/test/java/org/sonar/duplications/java/JavaStatementBuilderTest.java index a60c04e86d3..904820856d8 100644 --- a/sonar-duplications/src/test/java/org/sonar/duplications/java/JavaStatementBuilderTest.java +++ b/sonar-duplications/src/test/java/org/sonar/duplications/java/JavaStatementBuilderTest.java @@ -19,7 +19,6 @@ */ package org.sonar.duplications.java; -import com.google.common.base.Charsets; import org.apache.commons.io.IOUtils; import org.junit.Test; import org.sonar.duplications.DuplicationsTestUtil; @@ -32,6 +31,7 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStreamReader; import java.io.Reader; +import java.nio.charset.StandardCharsets; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; @@ -327,7 +327,7 @@ public class JavaStatementBuilderTest { private List<Statement> chunk(File file) { Reader reader = null; try { - reader = new InputStreamReader(new FileInputStream(file), Charsets.UTF_8); + reader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8); return statementChunker.chunk(tokenChunker.chunk(reader)); } catch (FileNotFoundException e) { throw new RuntimeException(e); diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/java/JavaTokenProducerTest.java b/sonar-duplications/src/test/java/org/sonar/duplications/java/JavaTokenProducerTest.java index 3a190a5e3be..1afeb632b9c 100644 --- a/sonar-duplications/src/test/java/org/sonar/duplications/java/JavaTokenProducerTest.java +++ b/sonar-duplications/src/test/java/org/sonar/duplications/java/JavaTokenProducerTest.java @@ -19,7 +19,6 @@ */ package org.sonar.duplications.java; -import com.google.common.base.Charsets; import com.google.common.collect.Lists; import org.apache.commons.io.IOUtils; import org.hamcrest.Matcher; @@ -35,6 +34,7 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStreamReader; import java.io.Reader; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.List; @@ -284,11 +284,11 @@ public class JavaTokenProducerTest { @Test public void shouldPreserveSeparators() { assertThat(chunk("(){}[];,."), isTokens( - new Token("(", 1, 0), new Token(")", 1, 1), - new Token("{", 1, 2), new Token("}", 1, 3), - new Token("[", 1, 4), new Token("]", 1, 5), - new Token(";", 1, 6), new Token(",", 1, 7), - new Token(".", 1, 8))); + new Token("(", 1, 0), new Token(")", 1, 1), + new Token("{", 1, 2), new Token("}", 1, 3), + new Token("[", 1, 4), new Token("]", 1, 5), + new Token(";", 1, 6), new Token(",", 1, 7), + new Token(".", 1, 8))); } /** @@ -312,7 +312,7 @@ public class JavaTokenProducerTest { private TokenQueue chunk(File file) { Reader reader = null; try { - reader = new InputStreamReader(new FileInputStream(file), Charsets.UTF_8); + reader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8); return chunker.chunk(reader); } catch (FileNotFoundException e) { throw new RuntimeException(e); diff --git a/sonar-testing-harness/src/main/java/org/sonar/test/JsonAssert.java b/sonar-testing-harness/src/main/java/org/sonar/test/JsonAssert.java index 2632d9e2504..9e6cc013149 100644 --- a/sonar-testing-harness/src/main/java/org/sonar/test/JsonAssert.java +++ b/sonar-testing-harness/src/main/java/org/sonar/test/JsonAssert.java @@ -22,12 +22,12 @@ package org.sonar.test; import com.google.gson.GsonBuilder; import com.google.gson.JsonElement; import com.google.gson.JsonParser; -import org.apache.commons.io.Charsets; import org.apache.commons.io.IOUtils; import org.junit.ComparisonFailure; import java.io.IOException; import java.net.URL; +import java.nio.charset.StandardCharsets; /** * Assertion to compare JSON documents. Comparison is not strict: @@ -100,7 +100,7 @@ public class JsonAssert { private static String urlToString(URL url) { try { - return IOUtils.toString(url, Charsets.UTF_8); + return IOUtils.toString(url, StandardCharsets.UTF_8); } catch (IOException e) { throw new IllegalStateException("Fail to load JSON from " + url, e); } diff --git a/sonar-testing-harness/src/main/java/org/sonar/test/i18n/BundleSynchronizedMatcher.java b/sonar-testing-harness/src/main/java/org/sonar/test/i18n/BundleSynchronizedMatcher.java index 00b333144ad..2eb2430efcd 100644 --- a/sonar-testing-harness/src/main/java/org/sonar/test/i18n/BundleSynchronizedMatcher.java +++ b/sonar-testing-harness/src/main/java/org/sonar/test/i18n/BundleSynchronizedMatcher.java @@ -19,7 +19,6 @@ */ package org.sonar.test.i18n; -import org.apache.commons.io.Charsets; import org.apache.commons.io.IOUtils; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; @@ -30,6 +29,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStreamWriter; import java.io.Writer; +import java.nio.charset.StandardCharsets; import java.util.Map; import java.util.Properties; import java.util.SortedMap; @@ -121,7 +121,7 @@ public class BundleSynchronizedMatcher extends BaseMatcher<String> { dumpFile.delete(); } dumpFile.getParentFile().mkdirs(); - try (Writer writer = new OutputStreamWriter(new FileOutputStream(dumpFile), Charsets.UTF_8)) { + try (Writer writer = new OutputStreamWriter(new FileOutputStream(dumpFile), StandardCharsets.UTF_8)) { writer.write(details); } catch (IOException e) { throw new IllegalStateException("Unable to write the report to 'target/l10n/" + bundleName + ".report.txt'", e); |