Bladeren bron

Fix quality flaws

tags/6.0-RC1
Julien Lancelot 8 jaren geleden
bovenliggende
commit
3f785d1134

+ 6
- 6
server/sonar-server/src/main/java/org/sonar/server/computation/issue/TrackerRawInputFactory.java Bestand weergeven

@@ -98,13 +98,13 @@ public class TrackerRawInputFactory {
// as late as possible
while (reportIssues.hasNext()) {
ScannerReport.Issue reportIssue = reportIssues.next();
if (isIssueOnUnsupportedCommonRule(reportIssue)) {
DefaultIssue issue = toIssue(getLineHashSequence(), reportIssue);
if (issueFilter.accept(issue, component)) {
result.add(issue);
}
} else {
if (!isIssueOnUnsupportedCommonRule(reportIssue)) {
Loggers.get(getClass()).debug("Ignored issue from analysis report on rule {}:{}", reportIssue.getRuleRepository(), reportIssue.getRuleKey());
continue;
}
DefaultIssue issue = toIssue(getLineHashSequence(), reportIssue);
if (issueFilter.accept(issue, component)) {
result.add(issue);
}
}
}

+ 6
- 5
server/sonar-server/src/main/java/org/sonar/server/debt/DebtModelBackup.java Bestand weergeven

@@ -89,11 +89,12 @@ public class DebtModelBackup {
try {
List<RuleDebt> rules = newArrayList();
for (RuleDto rule : dbClient.ruleDao().selectEnabled(session)) {
if (languageKey == null || languageKey.equals(rule.getLanguage())) {
RuleDebt ruleDebt = toRuleDebt(rule);
if (ruleDebt != null) {
rules.add(ruleDebt);
}
if (languageKey != null && !languageKey.equals(rule.getLanguage())) {
continue;
}
RuleDebt ruleDebt = toRuleDebt(rule);
if (ruleDebt != null) {
rules.add(ruleDebt);
}
}
return debtModelXMLExporter.export(rules);

+ 21
- 20
server/sonar-server/src/main/java/org/sonar/server/issue/IssueBulkChangeService.java Bestand weergeven

@@ -72,7 +72,7 @@ public class IssueBulkChangeService {
private final UserSession userSession;

public IssueBulkChangeService(DbClient dbClient, IssueIndex issueIndex, IssueStorage issueStorage, DefaultRuleFinder ruleFinder,
NotificationManager notificationService, List<Action> actions, UserSession userSession) {
NotificationManager notificationService, List<Action> actions, UserSession userSession) {
this.dbClient = dbClient;
this.issueIndex = issueIndex;
this.issueStorage = issueStorage;
@@ -100,26 +100,27 @@ public class IssueBulkChangeService {
for (Action action : bulkActions) {
applyAction(action, actionContext, issueBulkChangeQuery, result);
}
if (result.issuesChanged().contains(issue)) {
// Apply comment action only on changed issues
if (issueBulkChangeQuery.hasComment()) {
applyAction(getAction(CommentAction.COMMENT_KEY), actionContext, issueBulkChangeQuery, result);
}
issueStorage.save((DefaultIssue) issue);
if (issueBulkChangeQuery.sendNotifications()) {
String projectKey = issue.projectKey();
if (projectKey != null) {
Rule rule = repository.rule(issue.ruleKey());
notificationService.scheduleForSending(new IssueChangeNotification()
.setIssue((DefaultIssue) issue)
.setChangeAuthorLogin(issueChangeContext.login())
.setRuleName(rule != null ? rule.getName() : null)
.setProject(projectKey, repository.project(projectKey).name())
.setComponent(repository.component(issue.componentKey())));
}
}
concernedProjects.add(issue.projectKey());
if (!result.issuesChanged().contains(issue)) {
continue;
}
if (issueBulkChangeQuery.hasComment()) {
applyAction(getAction(CommentAction.COMMENT_KEY), actionContext, issueBulkChangeQuery, result);
}
issueStorage.save((DefaultIssue) issue);
if (!issueBulkChangeQuery.sendNotifications()) {
continue;
}
String projectKey = issue.projectKey();
if (projectKey != null) {
Rule rule = repository.rule(issue.ruleKey());
notificationService.scheduleForSending(new IssueChangeNotification()
.setIssue((DefaultIssue) issue)
.setChangeAuthorLogin(issueChangeContext.login())
.setRuleName(rule != null ? rule.getName() : null)
.setProject(projectKey, repository.project(projectKey).name())
.setComponent(repository.component(issue.componentKey())));
}
concernedProjects.add(issue.projectKey());
}
LOG.debug("BulkChange execution time : {} ms", System.currentTimeMillis() - start);
return result;

+ 13
- 12
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/index/ActiveRuleIndex.java Bestand weergeven

@@ -126,20 +126,21 @@ public class ActiveRuleIndex extends BaseIndex {
return stats;
}

private Multimap<String, FacetValue> processAggregations(@Nullable Aggregations aggregations) {
private static Multimap<String, FacetValue> processAggregations(@Nullable Aggregations aggregations) {
Multimap<String, FacetValue> stats = ArrayListMultimap.create();
if (aggregations != null) {
for (Aggregation aggregation : aggregations.asList()) {
if (aggregation instanceof StringTerms) {
for (Terms.Bucket value : ((Terms) aggregation).getBuckets()) {
FacetValue facetValue = new FacetValue(value.getKeyAsString(), value.getDocCount());
stats.put(aggregation.getName(), facetValue);
}
} else if (aggregation instanceof InternalValueCount) {
InternalValueCount count = (InternalValueCount) aggregation;
FacetValue facetValue = new FacetValue(count.getName(), count.getValue());
stats.put(count.getName(), facetValue);
if (aggregations == null) {
return stats;
}
for (Aggregation aggregation : aggregations.asList()) {
if (aggregation instanceof StringTerms) {
for (Terms.Bucket value : ((Terms) aggregation).getBuckets()) {
FacetValue facetValue = new FacetValue(value.getKeyAsString(), value.getDocCount());
stats.put(aggregation.getName(), facetValue);
}
} else if (aggregation instanceof InternalValueCount) {
InternalValueCount count = (InternalValueCount) aggregation;
FacetValue facetValue = new FacetValue(count.getName(), count.getValue());
stats.put(count.getName(), facetValue);
}
}
return stats;

+ 17
- 16
server/sonar-server/src/main/java/org/sonar/server/rule/RegisterRules.java Bestand weergeven

@@ -303,20 +303,22 @@ public class RegisterRules implements Startable {
// Create newly parameters
for (RulesDefinition.Param param : ruleDef.params()) {
RuleParamDto paramDto = existingParamsByName.get(param.key());
if (paramDto == null) {
paramDto = RuleParamDto.createFor(rule)
.setName(param.key())
.setDescription(param.description())
.setDefaultValue(param.defaultValue())
.setType(param.type().toString());
dbClient.ruleDao().insertRuleParam(session, rule, paramDto);
if (!StringUtils.isEmpty(param.defaultValue())) {
// Propagate the default value to existing active rule parameters
for (ActiveRuleDto activeRule : dbClient.activeRuleDao().selectByRuleId(session, rule.getId())) {
ActiveRuleParamDto activeParam = ActiveRuleParamDto.createFor(paramDto).setValue(param.defaultValue());
dbClient.activeRuleDao().insertParam(session, activeRule, activeParam);
}
}
if (paramDto != null) {
continue;
}
paramDto = RuleParamDto.createFor(rule)
.setName(param.key())
.setDescription(param.description())
.setDefaultValue(param.defaultValue())
.setType(param.type().toString());
dbClient.ruleDao().insertRuleParam(session, rule, paramDto);
if (StringUtils.isEmpty(param.defaultValue())) {
continue;
}
// Propagate the default value to existing active rule parameters
for (ActiveRuleDto activeRule : dbClient.activeRuleDao().selectByRuleId(session, rule.getId())) {
ActiveRuleParamDto activeParam = ActiveRuleParamDto.createFor(paramDto).setValue(param.defaultValue());
dbClient.activeRuleDao().insertParam(session, activeRule, activeParam);
}
}
}
@@ -451,8 +453,7 @@ public class RegisterRules implements Startable {
public String apply(@Nonnull RulesDefinition.Repository input) {
return input.key();
}
}
));
}));

List<ActiveRuleChange> changes = new ArrayList<>();
for (RuleDto rule : removedRules) {

+ 4
- 5
server/sonar-server/src/main/java/org/sonar/server/source/HtmlTextDecorator.java Bestand weergeven

@@ -129,7 +129,6 @@ class HtmlTextDecorator {
return to != null && to < currentLine;
}


private char[] normalize(char currentChar) {
char[] normalizedChars;
if (currentChar == HTML_OPENING) {
@@ -139,7 +138,7 @@ class HtmlTextDecorator {
} else if (currentChar == AMPERSAND) {
normalizedChars = ENCODED_AMPERSAND.toCharArray();
} else {
normalizedChars = new char[]{currentChar};
normalizedChars = new char[] {currentChar};
}
return normalizedChars;
}
@@ -176,7 +175,7 @@ class HtmlTextDecorator {
private boolean shouldReopenPendingTags(CharactersReader charactersReader) {
return (charactersReader.getPreviousValue() == LF_END_OF_LINE && charactersReader.getCurrentValue() != LF_END_OF_LINE)
|| (charactersReader.getPreviousValue() == CR_END_OF_LINE && charactersReader.getCurrentValue() != CR_END_OF_LINE
&& charactersReader.getCurrentValue() != LF_END_OF_LINE);
&& charactersReader.getCurrentValue() != LF_END_OF_LINE);
}

private boolean shouldStartNewLine(CharactersReader charactersReader) {
@@ -185,7 +184,7 @@ class HtmlTextDecorator {
}

private void closeCompletedTags(CharactersReader charactersReader, int numberOfTagsToClose,
StringBuilder decoratedText) {
StringBuilder decoratedText) {
for (int i = 0; i < numberOfTagsToClose; i++) {
injectClosingHtml(decoratedText);
charactersReader.removeLastOpenTag();
@@ -193,7 +192,7 @@ class HtmlTextDecorator {
}

private void openNewTags(CharactersReader charactersReader, Collection<String> tagsToOpen,
StringBuilder decoratedText) {
StringBuilder decoratedText) {
for (String tagToOpen : tagsToOpen) {
injectOpeningHtmlForRule(tagToOpen, decoratedText);
charactersReader.registerOpenTag(tagToOpen);

+ 7
- 6
server/sonar-server/src/main/java/org/sonar/server/user/UserUpdater.java Bestand weergeven

@@ -19,10 +19,6 @@
*/
package org.sonar.server.user;

import static com.google.common.base.Strings.isNullOrEmpty;
import static com.google.common.collect.Lists.newArrayList;
import static org.sonar.db.user.UserDto.encryptPassword;

import com.google.common.base.Joiner;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
@@ -51,6 +47,10 @@ import org.sonar.server.exceptions.ServerException;
import org.sonar.server.user.index.UserIndexer;
import org.sonar.server.util.Validation;

import static com.google.common.base.Strings.isNullOrEmpty;
import static com.google.common.collect.Lists.newArrayList;
import static org.sonar.db.user.UserDto.encryptPassword;

@ServerSide
public class UserUpdater {

@@ -336,9 +336,10 @@ public class UserUpdater {
List<UserDto> matchingUsers = dbClient.userDao().selectByScmAccountOrLoginOrEmail(dbSession, scmAccount);
List<String> matchingUsersWithoutExistingUser = newArrayList();
for (UserDto matchingUser : matchingUsers) {
if (existingUser == null || !matchingUser.getId().equals(existingUser.getId())) {
matchingUsersWithoutExistingUser.add(matchingUser.getName() + " (" + matchingUser.getLogin() + ")");
if (existingUser != null && matchingUser.getId().equals(existingUser.getId())) {
continue;
}
matchingUsersWithoutExistingUser.add(matchingUser.getName() + " (" + matchingUser.getLogin() + ")");
}
if (!matchingUsersWithoutExistingUser.isEmpty()) {
messages.add(Message.of("user.scm_account_already_used", scmAccount, Joiner.on(", ").join(matchingUsersWithoutExistingUser)));

+ 9
- 10
server/sonar-server/src/main/java/org/sonar/server/user/index/UserResultSetIterator.java Bestand weergeven

@@ -20,15 +20,14 @@
package org.sonar.server.user.index;

import com.google.common.collect.Maps;
import org.apache.commons.lang.StringUtils;
import org.sonar.db.DbSession;
import org.sonar.db.user.UserDto;
import org.sonar.db.DbClient;
import org.sonar.db.ResultSetIterator;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.apache.commons.lang.StringUtils;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.ResultSetIterator;
import org.sonar.db.user.UserDto;

/**
* Scrolls over table USERS and reads documents to populate the user index
@@ -50,6 +49,10 @@ class UserResultSetIterator extends ResultSetIterator<UserDoc> {

private static final String SQL_AFTER_DATE = SQL_ALL + " where u.updated_at>?";

private UserResultSetIterator(PreparedStatement stmt) throws SQLException {
super(stmt);
}

static UserResultSetIterator create(DbClient dbClient, DbSession session, long afterDate) {
try {
String sql = afterDate > 0L ? SQL_AFTER_DATE : SQL_ALL;
@@ -63,10 +66,6 @@ class UserResultSetIterator extends ResultSetIterator<UserDoc> {
}
}

private UserResultSetIterator(PreparedStatement stmt) throws SQLException {
super(stmt);
}

@Override
protected UserDoc read(ResultSet rs) throws SQLException {
UserDoc doc = new UserDoc(Maps.<String, Object>newHashMapWithExpectedSize(7));

+ 18
- 18
sonar-db/src/main/java/org/sonar/db/version/v51/CopyScmAccountsFromAuthorsToUsers.java Bestand weergeven

@@ -59,29 +59,29 @@ public class CopyScmAccountsFromAuthorsToUsers extends BaseDataChange {
final Multimap<Long, String> authorsByPersonId = ArrayListMultimap.create();
context.prepareSelect("SELECT a.person_id, a.login FROM authors a," +
" (SELECT person_id, COUNT(*) AS nb FROM authors GROUP BY person_id HAVING COUNT(*) > 1) group_by_person" +
" WHERE a.person_id = group_by_person.person_id "
).scroll(new AuthorsByPersonIdHandler(authorsByPersonId));
" WHERE a.person_id = group_by_person.person_id ").scroll(new AuthorsByPersonIdHandler(authorsByPersonId));

Upsert update = context.prepareUpsert("UPDATE users SET scm_accounts = ?, updated_at = ? WHERE id = ?");
for (Long personId : authorsByPersonId.keySet()) {
List<String> authors = newArrayList(authorsByPersonId.get(personId));
List<User> users = selectUsersFromLoginOrEmail(context, authors);
if (users.size() == 1) {
User user = users.get(0);
if (authors.contains(user.login)) {
authors.remove(user.login);
}
if (authors.contains(user.email)) {
authors.remove(user.email);
}
if (!authors.isEmpty()) {
update
.setString(1, encodeScmAccounts(authors))
.setLong(2, now)
.setLong(3, user.id)
.addBatch();
counter.getAndIncrement();
}
if (users.size() != 1) {
continue;
}
User user = users.get(0);
if (authors.contains(user.login)) {
authors.remove(user.login);
}
if (authors.contains(user.email)) {
authors.remove(user.email);
}
if (!authors.isEmpty()) {
update
.setString(1, encodeScmAccounts(authors))
.setLong(2, now)
.setLong(3, user.id)
.addBatch();
counter.getAndIncrement();
}
}
if (((UpsertImpl) update).getBatchCount() > 0L) {

+ 12
- 12
sonar-plugin-api/src/main/java/org/sonar/api/rules/ActiveRuleParam.java Bestand weergeven

@@ -27,18 +27,6 @@ public class ActiveRuleParam implements Cloneable {
private String paramKey;
private String value;

public Integer getId() {
return id;
}

/**
* @deprecated visibility should be decreased to protected or package
*/
@Deprecated
void setId(Integer id) {
this.id = id;
}

/**
* @deprecated visibility should be decreased to protected or package
*/
@@ -57,6 +45,18 @@ public class ActiveRuleParam implements Cloneable {
this.paramKey = ruleParam.getKey();
}

public Integer getId() {
return id;
}

/**
* @deprecated visibility should be decreased to protected or package
*/
@Deprecated
void setId(Integer id) {
this.id = id;
}

public ActiveRule getActiveRule() {
return activeRule;
}

Laden…
Annuleren
Opslaan