// 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);
}
}
}
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);
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;
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;
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;
// 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);
}
}
}
public String apply(@Nonnull RulesDefinition.Repository input) {
return input.key();
}
- }
- ));
+ }));
List<ActiveRuleChange> changes = new ArrayList<>();
for (RuleDto rule : removedRules) {
return to != null && to < currentLine;
}
-
private char[] normalize(char currentChar) {
char[] normalizedChars;
if (currentChar == HTML_OPENING) {
} else if (currentChar == AMPERSAND) {
normalizedChars = ENCODED_AMPERSAND.toCharArray();
} else {
- normalizedChars = new char[]{currentChar};
+ normalizedChars = new char[] {currentChar};
}
return normalizedChars;
}
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) {
}
private void closeCompletedTags(CharactersReader charactersReader, int numberOfTagsToClose,
- StringBuilder decoratedText) {
+ StringBuilder decoratedText) {
for (int i = 0; i < numberOfTagsToClose; i++) {
injectClosingHtml(decoratedText);
charactersReader.removeLastOpenTag();
}
private void openNewTags(CharactersReader charactersReader, Collection<String> tagsToOpen,
- StringBuilder decoratedText) {
+ StringBuilder decoratedText) {
for (String tagToOpen : tagsToOpen) {
injectOpeningHtmlForRule(tagToOpen, decoratedText);
charactersReader.registerOpenTag(tagToOpen);
*/
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;
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 {
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)));
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
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;
}
}
- 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));
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) {
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
*/
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;
}