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;
import java.io.File;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
}
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) {
*/
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;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.nio.charset.StandardCharsets;
/**
* Reads process output and writes to logs
@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) {
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;
import java.io.File;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import java.security.Key;
import java.security.SecureRandom;
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) {
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);
}
}
*/
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;
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;
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);
*/
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;
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;
/**
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);
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 {
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;
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;
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);
}
*/
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;
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
*
} else {
result = shortBytes;
}
- return new String(result, UTF_8);
+ return new String(result, StandardCharsets.UTF_8);
}
private final System2 system;
*/
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;
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 {
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;
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;
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
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;
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;
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
}
@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) {
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;
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;
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");
*/
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;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
+import java.nio.charset.StandardCharsets;
import java.util.Date;
/**
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);
*/
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;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
+import java.nio.charset.StandardCharsets;
@ServerSide
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);
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);
*/
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;
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;
}
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) {
*/
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;
import org.sonar.server.qualityprofile.QProfileFactory;
import java.io.OutputStreamWriter;
+import java.nio.charset.StandardCharsets;
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);
*/
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;
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 {
.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());
}
}
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 {
*/
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;
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";
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 {
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;
import org.sonar.server.rule.RuleService;
import java.io.OutputStreamWriter;
+import java.nio.charset.StandardCharsets;
/**
* @since 4.4
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();
}
*/
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;
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;
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);
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;
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;
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);
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;
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;
}
@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")
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);
}
*/
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;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
+import java.nio.charset.StandardCharsets;
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());
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;
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;
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);
*/
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;
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";
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()));
}
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);
}
*/
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;
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
+import java.nio.charset.StandardCharsets;
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() {
@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
*/
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;
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
*/
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();
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;
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;
"(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 " +
.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);
.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);
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;
}
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);
}
}
*/
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;
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;
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));
}
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 +
" </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);
}
}
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;
private String getFileContent(String file) throws Exception {
return Resources.toString(Resources.getResource(getClass(), "DebtRulesXMLImporterTest/" + file),
- Charsets.UTF_8);
+ StandardCharsets.UTF_8);
}
}
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;
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;
}
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) {
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;
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;
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);
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);
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);
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);
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();
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;
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;
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);
}
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);
}
*/
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;
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 {
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);
}
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);
}
*/
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;
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;
@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();
}
@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);
}
}
*/
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;
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;
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();
}
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");
// 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);
// 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));
// 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));
// 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));
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");
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>.");
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");
@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));
@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();
*/
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;
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;
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
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;
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;
@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
}
public String outputAsString() {
- return new String(output.toByteArray(), Charsets.UTF_8);
+ return new String(output.toByteArray(), StandardCharsets.UTF_8);
}
}
}
public String outputAsString() {
- return new String(response.output.toByteArray(), Charsets.UTF_8);
+ return new String(response.output.toByteArray(), StandardCharsets.UTF_8);
}
public byte[] output() {
*/
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;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URISyntaxException;
+import java.nio.charset.StandardCharsets;
import java.util.Properties;
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 {
*/
package org.sonar.application;
-import org.apache.commons.io.Charsets;
import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Rule;
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;
@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");
}
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
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);
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;
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;
* 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)));
}
/**
* 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);
}
/**
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 {
@CheckForNull
public String getData() {
if (dataValue != null) {
- return new String(dataValue, Charsets.UTF_8);
+ return new String(dataValue, StandardCharsets.UTF_8);
}
return textValue;
}
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;
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;
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;
// 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);
*/
package org.sonar.core.util;
-import com.google.common.base.Charsets;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.junit.AfterClass;
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;
@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);
}
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
@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");
}
*/
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;
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;
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);
*/
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;
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;
@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)));
}
/**
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);
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:
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);
}
*/
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;
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;
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);