private final IssueCache issueCache;
private final IssueLifecycle issueLifecycle;
- public CloseIssuesOnRemovedComponentsVisitor(BaseIssuesLoader baseIssuesLoader, ComponentsWithUnprocessedIssues componentsWithUnprocessedIssues, IssueCache issueCache, IssueLifecycle issueLifecycle) {
+ public CloseIssuesOnRemovedComponentsVisitor(BaseIssuesLoader baseIssuesLoader, ComponentsWithUnprocessedIssues componentsWithUnprocessedIssues, IssueCache issueCache,
+ IssueLifecycle issueLifecycle) {
super(CrawlerDepthLimit.PROJECT, POST_ORDER);
this.baseIssuesLoader = baseIssuesLoader;
this.componentsWithUnprocessedIssues = componentsWithUnprocessedIssues;
private static Iterable<MeasureComputer> sortComputers(List<MeasureComputer> computers) {
Map<String, MeasureComputer> computersByOutputMetric = new HashMap<>();
Map<String, MeasureComputer> computersByInputMetric = new HashMap<>();
- for (MeasureComputer computer : computers) {
- for (String outputMetric : computer.getOutputMetrics()) {
- computersByOutputMetric.put(outputMetric, computer);
- }
- for (String inputMetric : computer.getInputMetrics()) {
- computersByInputMetric.put(inputMetric, computer);
- }
- }
+ feedComputersByMetric(computers, computersByOutputMetric, computersByInputMetric);
ToComputerByKey toComputerByOutputMetricKey = new ToComputerByKey(computersByOutputMetric);
ToComputerByKey toComputerByInputMetricKey = new ToComputerByKey(computersByInputMetric);
return dag.sort();
}
+ private static void feedComputersByMetric(List<MeasureComputer> computers, Map<String, MeasureComputer> computersByOutputMetric,
+ Map<String, MeasureComputer> computersByInputMetric) {
+ for (MeasureComputer computer : computers) {
+ for (String outputMetric : computer.getOutputMetrics()) {
+ computersByOutputMetric.put(outputMetric, computer);
+ }
+ for (String inputMetric : computer.getInputMetrics()) {
+ computersByInputMetric.put(inputMetric, computer);
+ }
+ }
+ }
+
private void validateInputMetrics(List<MeasureComputer> computers) {
Set<String> pluginMetricKeys = FluentIterable.from(Arrays.asList(metricsRepositories))
.transformAndConcat(MetricsToMetricList.INSTANCE)
}
}
- private static Iterable<MeasureComputer> getDependencies(MeasureComputer measureComputer, ToComputerByKey toComputerByOutputMetricKey) {
+ private static Iterable<MeasureComputer> getDependencies(MeasureComputer measureComputer, ToComputerByKey toComputerByOutputMetricKey) {
// Remove null computer because a computer can depend on a metric that is only generated by a sensor or on a core metrics
return FluentIterable.from(measureComputer.getInputMetrics()).transform(toComputerByOutputMetricKey).filter(Predicates.notNull());
}
private static void writeDuplications(List<DuplicationsParser.Block> blocks, Map<String, String> refByComponentKey, JsonWriter json) {
for (DuplicationsParser.Block block : blocks) {
json.beginObject().name("blocks").beginArray();
- for (DuplicationsParser.Duplication duplication : block.duplications()) {
+ for (DuplicationsParser.Duplication duplication : block.getDuplications()) {
writeDuplication(refByComponentKey, duplication, json);
}
json.endArray().endObject();
if (b1 == null || b2 == null) {
return -1;
}
- List<Duplication> duplications1 = b1.duplications();
- List<Duplication> duplications2 = b2.duplications();
+ List<Duplication> duplications1 = b1.getDuplications();
+ List<Duplication> duplications2 = b2.getDuplications();
if (duplications1.isEmpty() || duplications2.isEmpty()) {
return -1;
}
}
}
- public static class Block {
- List<Duplication> duplications;
+ static class Block {
+ private final List<Duplication> duplications;
- Block(List<Duplication> duplications) {
+ public Block(List<Duplication> duplications) {
this.duplications = duplications;
}
- List<Duplication> duplications() {
+ public List<Duplication> getDuplications() {
return duplications;
}
}
package org.sonar.server.issue;
import com.google.common.base.Strings;
-import org.sonar.api.server.ServerSide;
+import java.util.Collection;
+import java.util.Map;
import org.sonar.api.issue.Issue;
import org.sonar.api.issue.condition.IsUnResolved;
-import org.sonar.core.issue.DefaultIssue;
+import org.sonar.api.server.ServerSide;
import org.sonar.api.user.User;
import org.sonar.api.user.UserFinder;
+import org.sonar.core.issue.DefaultIssue;
import org.sonar.core.issue.IssueUpdater;
import org.sonar.server.user.UserSession;
-import java.util.Collection;
-import java.util.Map;
-
@ServerSide
public class AssignAction extends Action {
- public static final String KEY = "assign";
+ private static final String ASSIGN_KEY = "assign";
public static final String VERIFIED_ASSIGNEE = "verifiedAssignee";
private final UserFinder userFinder;
private final IssueUpdater issueUpdater;
public AssignAction(UserFinder userFinder, IssueUpdater issueUpdater) {
- super(KEY);
+ super(ASSIGN_KEY);
this.userFinder = userFinder;
this.issueUpdater = issueUpdater;
super.setConditions(new IsUnResolved());
import java.util.Collection;
import java.util.Map;
import org.sonar.api.issue.Issue;
-import org.sonar.core.issue.DefaultIssue;
import org.sonar.api.server.ServerSide;
+import org.sonar.core.issue.DefaultIssue;
import org.sonar.core.issue.IssueUpdater;
import org.sonar.server.user.UserSession;
@ServerSide
public class CommentAction extends Action {
- public static final String KEY = "comment";
+ public static final String COMMENT_KEY = "comment";
public static final String COMMENT_PROPERTY = "comment";
private final IssueUpdater issueUpdater;
public CommentAction(IssueUpdater issueUpdater) {
- super(KEY);
+ super(COMMENT_KEY);
this.issueUpdater = issueUpdater;
}
hasComment = true;
Map<String, Object> commentMap = newHashMap();
commentMap.put(CommentAction.COMMENT_PROPERTY, comment);
- propertiesByActions.put(CommentAction.KEY, commentMap);
+ propertiesByActions.put(CommentAction.COMMENT_KEY, commentMap);
}
}
if (result.issuesChanged().contains(issue)) {
// Apply comment action only on changed issues
if (issueBulkChangeQuery.hasComment()) {
- applyAction(getAction(CommentAction.KEY), actionContext, issueBulkChangeQuery, result);
+ applyAction(getAction(CommentAction.COMMENT_KEY), actionContext, issueBulkChangeQuery, result);
}
issueStorage.save((DefaultIssue) issue);
if (issueBulkChangeQuery.sendNotifications()) {
package org.sonar.server.issue;
import com.google.common.base.Strings;
-import org.sonar.api.server.ServerSide;
+import java.util.Collection;
+import java.util.Map;
import org.sonar.api.issue.ActionPlan;
import org.sonar.api.issue.Issue;
import org.sonar.api.issue.condition.IsUnResolved;
+import org.sonar.api.server.ServerSide;
import org.sonar.core.issue.DefaultIssue;
import org.sonar.core.issue.IssueUpdater;
import org.sonar.server.issue.actionplan.ActionPlanService;
import org.sonar.server.user.UserSession;
-import java.util.Collection;
-import java.util.Map;
-
@ServerSide
public class PlanAction extends Action {
- public static final String KEY = "plan";
+ public static final String PLAN_KEY = "plan";
public static final String VERIFIED_ACTION_PLAN = "verifiedActionPlan";
private final ActionPlanService actionPlanService;
private final IssueUpdater issueUpdater;
public PlanAction(ActionPlanService actionPlanService, IssueUpdater issueUpdater) {
- super(KEY);
+ super(PLAN_KEY);
this.actionPlanService = actionPlanService;
this.issueUpdater = issueUpdater;
super.setConditions(new IsUnResolved());
import org.sonar.api.issue.Issue;
import org.sonar.api.issue.condition.Condition;
import org.sonar.api.issue.condition.IsUnResolved;
-import org.sonar.core.issue.DefaultIssue;
import org.sonar.api.server.ServerSide;
import org.sonar.api.web.UserRole;
+import org.sonar.core.issue.DefaultIssue;
import org.sonar.core.issue.IssueUpdater;
import org.sonar.server.user.UserSession;
@ServerSide
public class SetSeverityAction extends Action {
- public static final String KEY = "set_severity";
+ public static final String SET_SEVERITY_KEY = "set_severity";
private final IssueUpdater issueUpdater;
private final UserSession userSession;
public SetSeverityAction(IssueUpdater issueUpdater, UserSession userSession) {
- super(KEY);
+ super(SET_SEVERITY_KEY);
this.issueUpdater = issueUpdater;
this.userSession = userSession;
super.setConditions(new IsUnResolved(), new Condition() {
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.issue.Issue;
-import org.sonar.core.issue.DefaultIssue;
import org.sonar.api.server.ServerSide;
+import org.sonar.core.issue.DefaultIssue;
import org.sonar.core.issue.workflow.IssueWorkflow;
import org.sonar.core.issue.workflow.Transition;
import org.sonar.server.user.UserSession;
@ServerSide
public class TransitionAction extends Action {
- public static final String KEY = "do_transition";
+ public static final String DO_TRANSITION_KEY = "do_transition";
private final IssueWorkflow workflow;
private final UserSession userSession;
public TransitionAction(IssueWorkflow workflow, UserSession userSession) {
- super(KEY);
+ super(DO_TRANSITION_KEY);
this.workflow = workflow;
this.userSession = userSession;
}
ASSIGNEES, LANGUAGES, ASSIGNED, PLANNED, HIDE_RULES, CREATED_AT, CREATED_AFTER, CREATED_BEFORE, CREATED_IN_LAST, COMPONENT_UUIDS, COMPONENT_ROOT_UUIDS, FACET_MODE,
PROJECTS, PROJECT_UUIDS, PROJECT_KEYS, COMPONENT_KEYS, MODULE_UUIDS, DIRECTORIES, FILE_UUIDS, AUTHORS, HIDE_COMMENTS, PAGE_SIZE, PAGE_INDEX, SORT, ASC);
- public static final List<String> ALL_WITHOUT_PAGINATION = newArrayList(Iterables.filter(ALL, new Predicate<String>() {
+ static final List<String> ALL_WITHOUT_PAGINATION = newArrayList(Iterables.filter(ALL, new Predicate<String>() {
@Override
public boolean apply(String input) {
return !PAGE_INDEX.equals(input) && !PAGE_SIZE.equals(input);
usersByLogin.put(userLogin, user);
}
}
- }
-
- for (IssueComment comment : comments) {
- String userLogin = comment.userLogin();
- User user = usersByLogin.get(userLogin);
json
.beginObject()
.prop("key", comment.key())
private final List<Object> level4AddedComponents = Lists.newArrayList();
private final Profiler profiler = Profiler.createIfTrace(Loggers.get(Platform.class));
- public Platform() {
- }
-
public static Platform getInstance() {
return INSTANCE;
}
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
-import org.junit.rules.TemporaryFolder;
import org.sonar.api.resources.Language;
import org.sonar.api.utils.System2;
import org.sonar.batch.protocol.Constants;
@Rule
public BatchReportReaderRule reportReader = new BatchReportReaderRule();
- @Rule
- public TemporaryFolder temp = new TemporaryFolder();
-
DbClient dbClient = dbTester.getDbClient();
PersistFileSourcesStep underTest;
package org.sonar.server.debt;
import com.google.common.io.Resources;
+import java.nio.charset.StandardCharsets;
+import java.util.Collections;
+import java.util.List;
+import java.util.regex.Pattern;
import org.apache.commons.lang.CharUtils;
import org.apache.commons.lang.SystemUtils;
import org.custommonkey.xmlunit.Diff;
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;
-
import static com.google.common.collect.Lists.newArrayList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;
String xml = xmlExporter.export(debtModel, Collections.<RuleDebt>emptyList());
// root characteristics are sorted by the column "characteristic_order"
- Pattern regex = Pattern.compile(".*USABILITY.*PORTABILITY.*EFFICIENCY.*", Pattern.DOTALL);
- assertThat(regex.matcher(xml).matches());
+ assertThat(Pattern.compile(".*PORTABILITY.*USABILITY.*EFFICIENCY.*", Pattern.DOTALL).matcher(xml).matches()).isTrue();
+ assertThat(Pattern.compile(".*USABILITY.*PORTABILITY.*EFFICIENCY.*", Pattern.DOTALL).matcher(xml).matches()).isFalse();
// sub characteristics are sorted by name
- regex = Pattern.compile(".*CPU Efficiency.*Other Efficiency.*RAM Efficiency.*", Pattern.DOTALL);
- assertThat(regex.matcher(xml).matches());
+ assertThat(Pattern.compile(".*CPU Efficiency.*Other Efficiency.*RAM Efficiency.*", Pattern.DOTALL).matcher(xml).matches()).isTrue();
+ assertThat(Pattern.compile(".*CPU Efficiency.*RAM Efficiency.*Other Efficiency.*", Pattern.DOTALL).matcher(xml).matches()).isFalse();
}
@Test
List<DuplicationsParser.Block> blocks = parser.parse(currentFile, getData("duplication_on_same_file.xml"), session);
assertThat(blocks).hasSize(1);
- List<DuplicationsParser.Duplication> duplications = blocks.get(0).duplications();
+ List<DuplicationsParser.Duplication> duplications = blocks.get(0).getDuplications();
assertThat(duplications).hasSize(2);
// Smallest line comes first
List<DuplicationsParser.Block> blocks = parser.parse(currentFile, getData("duplication_on_same_project.xml"), session);
assertThat(blocks).hasSize(1);
- List<DuplicationsParser.Duplication> duplications = blocks.get(0).duplications();
+ List<DuplicationsParser.Duplication> duplications = blocks.get(0).getDuplications();
assertThat(duplications).hasSize(2);
// Current file comes first
List<DuplicationsParser.Block> blocks = parser.parse(currentFile, getData("duplications_on_different_project.xml"), session);
assertThat(blocks).hasSize(1);
- List<DuplicationsParser.Duplication> duplications = blocks.get(0).duplications();
+ List<DuplicationsParser.Duplication> duplications = blocks.get(0).getDuplications();
assertThat(duplications).hasSize(3);
// Current file's project comes first
// Block with smaller line should come first
- assertThat(blocks.get(0).duplications().get(0).from()).isEqualTo(38);
- assertThat(blocks.get(0).duplications().get(1).from()).isEqualTo(29);
+ assertThat(blocks.get(0).getDuplications().get(0).from()).isEqualTo(38);
+ assertThat(blocks.get(0).getDuplications().get(1).from()).isEqualTo(29);
- assertThat(blocks.get(1).duplications().get(0).from()).isEqualTo(94);
- assertThat(blocks.get(1).duplications().get(1).from()).isEqualTo(83);
+ assertThat(blocks.get(1).getDuplications().get(0).from()).isEqualTo(94);
+ assertThat(blocks.get(1).getDuplications().get(1).from()).isEqualTo(83);
}
@Test
List<DuplicationsParser.Block> blocks = parser.parse(currentFile, getData("duplication_on_removed_file.xml"), session);
assertThat(blocks).hasSize(1);
- List<DuplicationsParser.Duplication> duplications = blocks.get(0).duplications();
+ List<DuplicationsParser.Duplication> duplications = blocks.get(0).getDuplications();
assertThat(duplications).hasSize(2);
// Duplications on removed file