final class Base64Cipher implements Cipher {
@Override
public String encrypt(String clearText) {
- return Base64.encodeBase64String(clearText.getBytes());
+ return Base64.encodeBase64String(clearText.getBytes(Charsets.UTF_8));
}
@Override
public class ComputationComponents {
+ private ComputationComponents() {
+ // only static stuff
+ }
+
/**
* List of all objects to be injected in the picocontainer dedicated to computation stack.
* Does not contain the steps declared in {@link org.sonar.server.computation.step.ComputationSteps#orderedStepClasses()}.
private void guessAuthor(DefaultIssue issue) {
// issue.authorLogin() can be not-null when old developer cockpit plugin (or other plugin)
// is still installed and executed during analysis
- if (issue.authorLogin() == null && issue.line() != null) {
- issue.setAuthorLogin(linesCache.lineAuthor(issue.line()));
+ Integer line = issue.line();
+ if (issue.authorLogin() == null && line != null) {
+ issue.setAuthorLogin(linesCache.lineAuthor(line));
}
}
@Override
public void execute(Context context) throws SQLException {
- final Date now = new Date(system.now());
MassUpdate massUpdate = context.prepareMassUpdate();
massUpdate.select("select id,data from issue_filters where data like '%" + SORT_KEY + "%' or data like '%" + ASC_KEY +"%'");
massUpdate.update("update issue_filters set data=?, updated_at=? where id=?");
massUpdate.rowPluralName("issue filters");
- massUpdate.execute(new MassUpdate.Handler() {
- @Override
- public boolean handle(Select.Row row, SqlStatement update) throws SQLException {
- String data = row.getString(2);
- String[] fields = StringUtils.split(data, FIELD_SEPARATOR);
+ massUpdate.execute(new FilterHandler(new Date(system.now())));
+ }
- boolean found = false;
- List<String> fieldsToKeep = Lists.newArrayList();
- for (String field : fields) {
- if (field.startsWith(SORT_KEY) || field.startsWith(ASC_KEY)) {
- found = true;
- } else {
- fieldsToKeep.add(field);
- }
- }
- if (found) {
- // data without 'sort' field
- update.setString(1, StringUtils.join(fieldsToKeep, FIELD_SEPARATOR));
- update.setDate(2, now);
- update.setLong(3, row.getLong(1));
+ private static class FilterHandler implements MassUpdate.Handler {
+ private final Date now;
+
+ private FilterHandler(Date now) {
+ this.now = now;
+ }
+
+ @Override
+ public boolean handle(Select.Row row, SqlStatement update) throws SQLException {
+ String data = row.getString(2);
+ String[] fields = StringUtils.split(data, FIELD_SEPARATOR);
+
+ boolean found = false;
+ List<String> fieldsToKeep = Lists.newArrayList();
+ for (String field : fields) {
+ if (field.startsWith(SORT_KEY) || field.startsWith(ASC_KEY)) {
+ found = true;
+ } else {
+ fieldsToKeep.add(field);
}
- return found;
}
- });
+ if (found) {
+ // data without 'sort' field
+ update.setString(1, StringUtils.join(fieldsToKeep, FIELD_SEPARATOR));
+ update.setDate(2, now);
+ update.setLong(3, row.getLong(1));
+ }
+ return found;
+ }
}
}
import org.sonar.server.issue.index.IssueIndexDefinition;
import org.sonar.server.search.IndexDefinition;
import org.sonar.server.search.SearchClient;
-import org.sonar.server.source.index.SourceLineIndex;
import org.sonar.server.source.index.SourceLineIndexDefinition;
import java.sql.Connection;
public class SwitchLogbackAppender extends AppenderBase<ILoggingEvent> implements AppenderAttachable<ILoggingEvent> {
- private transient AppenderAttachableImpl<ILoggingEvent> attachedAppenders = new AppenderAttachableImpl<ILoggingEvent>();
- private transient Appender<ILoggingEvent> console = null;
- private transient Appender<ILoggingEvent> analysisReports = null;
+ private AppenderAttachableImpl<ILoggingEvent> attachedAppenders = new AppenderAttachableImpl<>();
+ private Appender<ILoggingEvent> console = null;
+ private Appender<ILoggingEvent> analysisReports = null;
@Override
protected void append(ILoggingEvent event) {
package org.sonar.server.computation;
import org.junit.Test;
+import org.sonar.test.TestUtils;
import static org.assertj.core.api.Assertions.assertThat;
public void nonStepComponents() throws Exception {
assertThat(ComputationComponents.nonStepComponents()).isNotEmpty();
}
+
+ @Test
+ public void util_class() throws Exception {
+ assertThat(TestUtils.hasOnlyPrivateConstructors(ComputationComponents.class)).isTrue();
+ }
}
// <home>/data is missing
FileUtils.forceMkdir(webDir);
FileUtils.forceMkdir(logsDir);
-
try {
FileUtils.touch(dataDir);
new PropsBuilder(new Properties(), jdbcSettings, homeDir).build();
assertThat(props.value("sonar.origin")).isEqualTo("raw");
}
+ @Test
+ public void do_not_load_properties_file_if_not_exists() throws Exception {
+ FileUtils.forceMkdir(dataDir);
+ FileUtils.forceMkdir(webDir);
+ FileUtils.forceMkdir(logsDir);
+
+ Properties rawProperties = new Properties();
+ rawProperties.setProperty("sonar.origin", "raw");
+ Props props = new PropsBuilder(rawProperties, jdbcSettings, homeDir).build();
+
+ assertThat(props.value("sonar.origin")).isEqualTo("raw");
+ }
+
@Test
public void detectHomeDir() throws Exception {
assertThat(PropsBuilder.detectHomeDir()).isDirectory().exists();
private String tags;
private String systemTags;
- private transient RuleKey key;
+ private RuleKey key;
@Override
public RuleKey getKey() {
final class Base64Cipher extends Cipher {
@Override
String encrypt(String clearText) {
- return Base64.encodeBase64String(clearText.getBytes());
+ return Base64.encodeBase64String(clearText.getBytes(Charsets.UTF_8));
}
@Override