diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2015-06-24 16:41:13 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2015-07-02 16:08:07 +0200 |
commit | 44a34aca80bb01c3a7689fe02d34f17718bf9293 (patch) | |
tree | b12af552ec4036c534ea975045ddf4a8cd93c30e /sonar-core | |
parent | 534bda208505d82734a41f44791ccd50ea928432 (diff) | |
download | sonarqube-44a34aca80bb01c3a7689fe02d34f17718bf9293.tar.gz sonarqube-44a34aca80bb01c3a7689fe02d34f17718bf9293.zip |
SONAR-6588 integrate issues to Compute Engine
Diffstat (limited to 'sonar-core')
21 files changed, 228 insertions, 676 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/dashboard/ActiveDashboardDao.java b/sonar-core/src/main/java/org/sonar/core/dashboard/ActiveDashboardDao.java index 7ac05f224f6..cfacc608706 100644 --- a/sonar-core/src/main/java/org/sonar/core/dashboard/ActiveDashboardDao.java +++ b/sonar-core/src/main/java/org/sonar/core/dashboard/ActiveDashboardDao.java @@ -19,17 +19,13 @@ */ package org.sonar.core.dashboard; +import java.util.List; +import javax.annotation.Nullable; import org.apache.ibatis.session.SqlSession; -import org.sonar.api.batch.BatchSide; import org.sonar.api.server.ServerSide; import org.sonar.core.persistence.DaoComponent; import org.sonar.core.persistence.MyBatis; -import javax.annotation.Nullable; - -import java.util.List; - -@BatchSide @ServerSide public class ActiveDashboardDao implements DaoComponent { diff --git a/sonar-core/src/main/java/org/sonar/core/issue/db/ActionPlanDao.java b/sonar-core/src/main/java/org/sonar/core/issue/db/ActionPlanDao.java index 774956178fe..cc75c1e1a93 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/db/ActionPlanDao.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/db/ActionPlanDao.java @@ -21,22 +21,16 @@ package org.sonar.core.issue.db; import com.google.common.collect.Lists; +import java.util.Collection; +import java.util.Collections; +import java.util.List; import org.apache.ibatis.session.SqlSession; -import org.sonar.api.batch.BatchSide; import org.sonar.api.server.ServerSide; import org.sonar.core.persistence.DaoComponent; import org.sonar.core.persistence.MyBatis; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - import static com.google.common.collect.Lists.newArrayList; -/** - * @since 3.6 - */ -@BatchSide @ServerSide public class ActionPlanDao implements DaoComponent { diff --git a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeDao.java b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeDao.java index a400a04c9cd..3e7c21e8d23 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeDao.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeDao.java @@ -21,28 +21,20 @@ package org.sonar.core.issue.db; import com.google.common.collect.Lists; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.List; -import java.util.Map; import javax.annotation.CheckForNull; -import org.apache.ibatis.session.ResultHandler; -import org.sonar.api.batch.BatchSide; +import org.sonar.api.server.ServerSide; import org.sonar.core.issue.DefaultIssueComment; import org.sonar.core.issue.FieldDiffs; -import org.sonar.api.server.ServerSide; import org.sonar.core.persistence.DaoComponent; import org.sonar.core.persistence.DbSession; import org.sonar.core.persistence.MyBatis; import static com.google.common.collect.Lists.newArrayList; -import static com.google.common.collect.Maps.newHashMap; +import static java.util.Arrays.asList; -/** - * @since 3.6 - */ -@BatchSide @ServerSide public class IssueChangeDao implements DaoComponent { @@ -64,7 +56,7 @@ public class IssueChangeDao implements DaoComponent { DbSession session = mybatis.openSession(false); try { List<FieldDiffs> result = Lists.newArrayList(); - for (IssueChangeDto dto : selectByIssuesAndType(session, Arrays.asList(issueKey), IssueChangeDto.TYPE_FIELD_CHANGE)) { + for (IssueChangeDto dto : selectByIssuesAndType(session, asList(issueKey), IssueChangeDto.TYPE_FIELD_CHANGE)) { result.add(dto.toFieldDiffs()); } return result; @@ -73,13 +65,11 @@ public class IssueChangeDao implements DaoComponent { } } - public void selectChangelogOnNonClosedIssuesByModuleAndType(long componentId, ResultHandler handler) { + public List<IssueChangeDto> selectChangelogOfUnresolvedIssuesByComponent(String componentUuid) { DbSession session = mybatis.openSession(false); try { - Map<String, Object> params = newHashMap(); - params.put("componentId", componentId); - params.put("changeType", IssueChangeDto.TYPE_FIELD_CHANGE); - session.select("org.sonar.core.issue.db.IssueChangeMapper.selectChangelogOnNonClosedIssuesByModuleAndType", params, handler); + IssueChangeMapper mapper = session.getMapper(IssueChangeMapper.class); + return mapper.selectChangelogOfUnresolvedIssuesByComponent(componentUuid, IssueChangeDto.TYPE_FIELD_CHANGE); } finally { MyBatis.closeQuietly(session); diff --git a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeMapper.java b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeMapper.java index cadf024cda4..732ddc5c75b 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeMapper.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeMapper.java @@ -20,15 +20,10 @@ package org.sonar.core.issue.db; -import org.apache.ibatis.annotations.Param; - -import javax.annotation.CheckForNull; - import java.util.List; +import javax.annotation.CheckForNull; +import org.apache.ibatis.annotations.Param; -/** - * @since 3.6 - */ public interface IssueChangeMapper { void insert(IssueChangeDto dto); @@ -38,13 +33,13 @@ public interface IssueChangeMapper { int update(IssueChangeDto change); @CheckForNull - IssueChangeDto selectByKeyAndType(@Param("key") String key, - @Param("changeType") String type); + IssueChangeDto selectByKeyAndType(@Param("key") String key, @Param("changeType") String type); + /** * Issue changes by chronological date of creation */ List<IssueChangeDto> selectByIssuesAndType(@Param("issueKeys") List<String> issueKeys, - @Param("changeType") String changeType); + @Param("changeType") String changeType); - List<IssueChangeDto> selectByIssue(String issueKey); + List<IssueChangeDto> selectChangelogOfUnresolvedIssuesByComponent(@Param("componentUuid") String componentUuid, @Param("changeType") String changeType); } diff --git a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDto.java b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDto.java index 44baff06b8c..ec3b3b60cea 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDto.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDto.java @@ -661,6 +661,7 @@ public final class IssueDto implements Serializable { issue.setEffortToFix(effortToFix); issue.setDebt(debt != null ? Duration.create(debt) : null); issue.setLine(line); + issue.setChecksum(checksum); issue.setSeverity(severity); issue.setReporter(reporter); issue.setAssignee(assignee); diff --git a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueMapper.java b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueMapper.java index aba2531071e..a3a8f61c490 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueMapper.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueMapper.java @@ -26,7 +26,7 @@ public interface IssueMapper { IssueDto selectByKey(String key); - List<IssueDto> selectOpenByComponentUuid(String componentUuid); + List<IssueDto> selectNonClosedByComponentUuid(String componentUuid); Set<String> selectComponentUuidsOfOpenIssuesForProjectUuid(String projectUuid); diff --git a/sonar-core/src/main/java/org/sonar/core/issue/tracking/LazyInput.java b/sonar-core/src/main/java/org/sonar/core/issue/tracking/LazyInput.java index 0406c631f09..2a5dc580a81 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/tracking/LazyInput.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/tracking/LazyInput.java @@ -31,7 +31,7 @@ public abstract class LazyInput<ISSUE extends Trackable> implements Input<ISSUE> @Override public LineHashSequence getLineHashSequence() { if (lineHashSeq == null) { - lineHashSeq = LineHashSequence.createForLines(loadSourceLines()); + lineHashSeq = loadLineHashSequence(); } return lineHashSeq; } @@ -52,7 +52,7 @@ public abstract class LazyInput<ISSUE extends Trackable> implements Input<ISSUE> return issues; } - protected abstract Iterable<String> loadSourceLines(); + protected abstract LineHashSequence loadLineHashSequence(); protected abstract List<ISSUE> loadIssues(); } diff --git a/sonar-core/src/main/java/org/sonar/core/issue/tracking/Tracker.java b/sonar-core/src/main/java/org/sonar/core/issue/tracking/Tracker.java index 8691757440c..5da2ca5da04 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/tracking/Tracker.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/tracking/Tracker.java @@ -27,7 +27,9 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Objects; import javax.annotation.Nonnull; +import org.apache.commons.lang.StringUtils; import org.sonar.api.rule.RuleKey; +import org.sonar.api.utils.log.Loggers; import static com.google.common.collect.FluentIterable.from; @@ -43,7 +45,7 @@ public class Tracker<RAW extends Trackable, BASE extends Trackable> { detectCodeMoves(rawInput, baseInput, tracking); // 3. match issues with same rule, same message and same line hash - match(tracking, LineHashAndMessagekeyFactory.INSTANCE); + match(tracking, LineHashAndMessageKeyFactory.INSTANCE); // 4. match issues with same rule, same line and same message match(tracking, LineAndMessageKeyFactory.INSTANCE); @@ -135,7 +137,7 @@ public class Tracker<RAW extends Trackable, BASE extends Trackable> { LineAndLineHashKey(Trackable trackable) { this.ruleKey = trackable.getRuleKey(); this.line = trackable.getLine(); - this.lineHash = trackable.getLineHash(); + this.lineHash = StringUtils.defaultString(trackable.getLineHash(), ""); } @Override @@ -178,7 +180,7 @@ public class Tracker<RAW extends Trackable, BASE extends Trackable> { LineHashAndMessageKey(Trackable trackable) { this.ruleKey = trackable.getRuleKey(); this.message = trackable.getMessage(); - this.lineHash = trackable.getLineHash(); + this.lineHash = StringUtils.defaultString(trackable.getLineHash(), ""); } @Override @@ -206,7 +208,7 @@ public class Tracker<RAW extends Trackable, BASE extends Trackable> { } } - private enum LineHashAndMessagekeyFactory implements SearchKeyFactory { + private enum LineHashAndMessageKeyFactory implements SearchKeyFactory { INSTANCE; @Override public SearchKey create(Trackable t) { diff --git a/sonar-core/src/main/java/org/sonar/core/issue/tracking/Tracking.java b/sonar-core/src/main/java/org/sonar/core/issue/tracking/Tracking.java index 27f34ac3887..f2a5306e500 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/tracking/Tracking.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/tracking/Tracking.java @@ -19,6 +19,7 @@ */ package org.sonar.core.issue.tracking; +import com.google.common.base.Objects; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Multimap; import java.util.Collection; @@ -53,14 +54,7 @@ public class Tracking<RAW extends Trackable, BASE extends Trackable> { private final Multimap<Integer, BASE> openManualIssues = ArrayListMultimap.create(); public Tracking(Input<RAW> rawInput, Input<BASE> baseInput) { - for (RAW raw : rawInput.getIssues()) { - // Extra verification if some plugins create issues on wrong lines - Integer rawLine = raw.getLine(); - if (rawLine != null && !rawInput.getLineHashSequence().hasLine(rawLine)) { - throw new IllegalArgumentException("Issue line is not valid: " + raw); - } - this.unmatchedRaws.add(raw); - } + this.unmatchedRaws.addAll(rawInput.getIssues()); this.unmatchedBases.addAll(baseInput.getIssues()); } @@ -90,15 +84,24 @@ public class Tracking<RAW extends Trackable, BASE extends Trackable> { void associateRawToBase(RAW raw, BASE base) { rawToBase.put(raw, base); - unmatchedBases.remove(base); + if (!unmatchedBases.remove(base)) { + throw new IllegalStateException(String.format("Fail to associate base issue %s to %s among %s", base, raw, this)); + } } void markRawAsAssociated(RAW raw) { - unmatchedRaws.remove(raw); + if (!unmatchedRaws.remove(raw)) { + throw new IllegalStateException(String.format("Fail to mark issue as associated: %s among %s", raw, this)); + } } void markRawsAsAssociated(Collection<RAW> c) { - unmatchedRaws.removeAll(c); + // important : do not use unmatchedRaws.removeAll(Collection) as it's buggy. See: + // http://stackoverflow.com/questions/19682542/why-identityhashmap-keyset-removeallkeys-does-not-use-identity-is-it-a-bug/19682543#19682543 + // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6588783 + for (RAW raw : c) { + markRawAsAssociated(raw); + } } boolean isComplete() { @@ -113,4 +116,14 @@ public class Tracking<RAW extends Trackable, BASE extends Trackable> { openManualIssues.put(line, manualIssue); unmatchedBases.remove(manualIssue); } + + @Override + public String toString() { + return Objects.toStringHelper(this) + .add("rawToBase", rawToBase) + .add("unmatchedRaws", unmatchedRaws) + .add("unmatchedBases", unmatchedBases) + .add("openManualIssues", openManualIssues) + .toString(); + } } diff --git a/sonar-core/src/main/java/org/sonar/core/issue/workflow/SetClosed.java b/sonar-core/src/main/java/org/sonar/core/issue/workflow/SetClosed.java index cee06ac4181..49b874220e7 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/workflow/SetClosed.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/workflow/SetClosed.java @@ -29,7 +29,7 @@ public enum SetClosed implements Function { public void execute(Context context) { DefaultIssue issue = (DefaultIssue) context.issue(); if (!issue.isBeingClosed()) { - throw new IllegalStateException("Issue is still alive: " + issue); + throw new IllegalStateException("Issue is still open: " + issue); } if (issue.isOnDisabledRule()) { context.setResolution(Issue.RESOLUTION_REMOVED); diff --git a/sonar-core/src/main/java/org/sonar/core/persistence/DaoComponent.java b/sonar-core/src/main/java/org/sonar/core/persistence/DaoComponent.java index da0a5f12224..09849be20fb 100644 --- a/sonar-core/src/main/java/org/sonar/core/persistence/DaoComponent.java +++ b/sonar-core/src/main/java/org/sonar/core/persistence/DaoComponent.java @@ -19,8 +19,5 @@ */ package org.sonar.core.persistence; -/** - * @since 4.4 - */ public interface DaoComponent { } diff --git a/sonar-core/src/main/java/org/sonar/core/technicaldebt/DefaultTechnicalDebtModel.java b/sonar-core/src/main/java/org/sonar/core/technicaldebt/DefaultTechnicalDebtModel.java deleted file mode 100644 index a7016a55947..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/technicaldebt/DefaultTechnicalDebtModel.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -package org.sonar.core.technicaldebt; - -import com.google.common.base.Predicate; -import com.google.common.collect.Iterables; -import org.sonar.api.batch.RequiresDB; -import org.sonar.api.batch.debt.DebtCharacteristic; -import org.sonar.api.batch.debt.DebtModel; -import org.sonar.api.batch.debt.internal.DefaultDebtCharacteristic; -import org.sonar.api.rule.RuleKey; -import org.sonar.api.technicaldebt.batch.TechnicalDebtModel; -import org.sonar.api.technicaldebt.batch.internal.DefaultCharacteristic; -import org.sonar.api.technicaldebt.batch.internal.DefaultRequirement; - -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; - -import java.util.Collections; -import java.util.List; - -import static com.google.common.collect.Lists.newArrayList; - -@RequiresDB -public class DefaultTechnicalDebtModel implements TechnicalDebtModel { - - private final DebtModel model; - - public DefaultTechnicalDebtModel(DebtModel model) { - this.model = model; - } - - public List<DefaultCharacteristic> rootCharacteristics() { - return newArrayList(Iterables.filter(characteristics(), new Predicate<DefaultCharacteristic>() { - @Override - public boolean apply(DefaultCharacteristic input) { - return input.isRoot(); - } - })); - } - - @Override - @CheckForNull - public DefaultCharacteristic characteristicByKey(final String key) { - return Iterables.find(characteristics(), new Predicate<DefaultCharacteristic>() { - @Override - public boolean apply(DefaultCharacteristic input) { - return input.key().equals(key); - } - }, null); - } - - @Override - @CheckForNull - public DefaultCharacteristic characteristicById(final Integer id) { - return Iterables.find(characteristics(), new Predicate<DefaultCharacteristic>() { - @Override - public boolean apply(DefaultCharacteristic input) { - return input.id().equals(id); - } - }, null); - } - - @Override - @CheckForNull - public DefaultRequirement requirementsByRule(final RuleKey ruleKey) { - return null; - } - - @Override - @CheckForNull - public DefaultRequirement requirementsById(final Integer id) { - return null; - } - - @Override - public List<DefaultCharacteristic> characteristics() { - List<DefaultCharacteristic> flatCharacteristics = newArrayList(); - for (DebtCharacteristic characteristic : model.characteristics()) { - DefaultCharacteristic root = toDefaultCharacteristic((DefaultDebtCharacteristic) characteristic, null); - flatCharacteristics.add(root); - for (DebtCharacteristic subCharacteristic : model.subCharacteristics(characteristic.key())) { - flatCharacteristics.add(toDefaultCharacteristic((DefaultDebtCharacteristic) subCharacteristic, root)); - } - } - return flatCharacteristics; - } - - @Override - public List<DefaultRequirement> requirements() { - return Collections.emptyList(); - } - - public boolean isEmpty() { - return model.allCharacteristics().isEmpty(); - } - - private static DefaultCharacteristic toDefaultCharacteristic(DefaultDebtCharacteristic debtCharacteristic, @Nullable DefaultCharacteristic parentCharacteristic) { - return new DefaultCharacteristic() - .setId(debtCharacteristic.id()) - .setKey(debtCharacteristic.key()) - .setName(debtCharacteristic.name()) - .setOrder(debtCharacteristic.order()) - .setParent(parentCharacteristic) - .setRoot(parentCharacteristic) - .setCreatedAt(debtCharacteristic.createdAt()) - .setUpdatedAt(debtCharacteristic.updatedAt()); - } - -} diff --git a/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueChangeMapper.xml b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueChangeMapper.xml index 47d0bc96d71..e810f1dc33c 100644 --- a/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueChangeMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueChangeMapper.xml @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8" ?> -<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mappei.dtd"> +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="org.sonar.core.issue.db.IssueChangeMapper"> @@ -43,20 +43,6 @@ order by c.created_at </select> - <select id="selectChangelogOnNonClosedIssuesByModuleAndType" parameterType="map" resultType="IssueChange"> - select - <include refid="issueChangeColumns"/> - from issue_changes c - inner join issues i on i.kee = c.issue_key - inner join (select p.id, p.uuid, p.kee from projects p where (p.root_id=#{componentId} and p.qualifier <> 'BRC') or - (p.id=#{componentId})) p on p.uuid=i.component_uuid - <where> - and c.change_type=#{changeType} - and i.status <> 'CLOSED' - </where> - order by c.issue_change_creation_date asc - </select> - <select id="selectByKeyAndType" parameterType="map" resultType="IssueChange"> select <include refid="issueChangeColumns"/> @@ -71,5 +57,15 @@ where c.issue_key=#{id} order by created_at asc </select> + + <select id="selectChangelogOfUnresolvedIssuesByComponent" parameterType="map" resultType="IssueChange"> + select + <include refid="issueChangeColumns"/> + from issue_changes c + inner join issues i on i.kee = c.issue_key + where i.component_uuid=#{componentUuid} + and c.change_type=#{changeType} + and i.resolution is null + </select> </mapper> diff --git a/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml index 50eb94db4d3..a6511b06329 100644 --- a/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml @@ -148,36 +148,13 @@ where i.kee=#{kee} </select> - <select id="selectOpenByComponentUuid" parameterType="String" resultType="Issue"> + <select id="selectNonClosedByComponentUuid" parameterType="String" resultType="Issue"> select - i.id, - i.kee as kee, - i.rule_id as ruleId, - i.action_plan_key as actionPlanKey, - i.severity as severity, - i.manual_severity as manualSeverity, - i.message as message, - i.line as line, - i.effort_to_fix as effortToFix, - i.technical_debt as debt, - i.status as status, - i.resolution as resolution, - i.checksum as checksum, - i.reporter as reporter, - i.assignee as assignee, - i.author_login as authorLogin, - i.tags as tagsString, - i.issue_attributes as issueAttributes, - i.issue_creation_date as issueCreationTime, - i.issue_update_date as issueUpdateTime, - i.issue_close_date as issueCloseTime, - i.created_at as createdAt, - i.updated_at as updatedAt, - r.plugin_rule_key as ruleKey, - i.component_uuid as componentUuid, - i.project_uuid as projectUuid + <include refid="issueColumns"/> from issues i inner join rules r on r.id=i.rule_id + inner join projects p on p.uuid=i.component_uuid + inner join projects root on root.uuid=i.project_uuid where i.component_uuid=#{componentUuid} and i.status <> 'CLOSED' diff --git a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeDaoTest.java b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeDaoTest.java index 411048b421e..2d379cfee6c 100644 --- a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeDaoTest.java @@ -19,21 +19,19 @@ */ package org.sonar.core.issue.db; -import org.apache.ibatis.executor.result.DefaultResultHandler; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.sonar.api.utils.DateUtils; import org.sonar.core.issue.DefaultIssueComment; import org.sonar.core.issue.FieldDiffs; -import org.sonar.api.utils.DateUtils; import org.sonar.core.persistence.AbstractDaoTestCase; import org.sonar.core.persistence.DbSession; import org.sonar.core.persistence.MyBatis; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - import static com.google.common.collect.Lists.newArrayList; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -115,45 +113,11 @@ public class IssueChangeDaoTest extends AbstractDaoTestCase { } @Test - public void select_issue_changelog_by_module() { - setupData("select_issue_changelog_by_module"); - - // 400 is a non-root module, we should find 2 + 1 changelog from classes and one on itself - DefaultResultHandler handler = new DefaultResultHandler(); - dao.selectChangelogOnNonClosedIssuesByModuleAndType(400, handler); - assertThat(handler.getResultList()).hasSize(4); - - IssueChangeDto issueChangeDto = (IssueChangeDto) handler.getResultList().get(0); - assertThat(issueChangeDto.getId()).isNotNull(); - assertThat(issueChangeDto.getKey()).isNotNull(); - assertThat(issueChangeDto.getIssueKey()).isNotNull(); - assertThat(issueChangeDto.getUserLogin()).isNotNull(); - assertThat(issueChangeDto.getChangeType()).isNotNull(); - assertThat(issueChangeDto.getChangeData()).isNotNull(); - assertThat(issueChangeDto.getCreatedAt()).isNotNull(); - assertThat(issueChangeDto.getUpdatedAt()).isNotNull(); - - for (Object changeDtoObject : handler.getResultList()) { - IssueChangeDto changeDto = (IssueChangeDto) changeDtoObject; - assertThat(changeDto.getChangeType()).isEqualTo(IssueChangeDto.TYPE_FIELD_CHANGE); - } + public void selectChangelogOfUnresolvedIssuesByComponent() { + setupData("selectChangelogOfUnresolvedIssuesByComponent"); - // 399 is the root module, we should only find 1 changelog on itself - handler = new DefaultResultHandler(); - dao.selectChangelogOnNonClosedIssuesByModuleAndType(399, handler); - assertThat(handler.getResultList()).hasSize(1); - } - - @Test - public void select_issue_changelog_by_module_should_be_sorted_by_creation_date() { - setupData("select_issue_changelog_by_module_are_sorted_by_creation_date"); - - DefaultResultHandler handler = new DefaultResultHandler(); - dao.selectChangelogOnNonClosedIssuesByModuleAndType(399, handler); - assertThat(handler.getResultList()).hasSize(3); - assertThat(((IssueChangeDto) handler.getResultList().get(0)).getId()).isEqualTo(1001); - assertThat(((IssueChangeDto) handler.getResultList().get(1)).getId()).isEqualTo(1002); - assertThat(((IssueChangeDto) handler.getResultList().get(2)).getId()).isEqualTo(1000); + List<IssueChangeDto> dtos = dao.selectChangelogOfUnresolvedIssuesByComponent("FILE_1"); + assertThat(dtos).extracting("id").containsExactly(100L); } @Test diff --git a/sonar-core/src/test/java/org/sonar/core/issue/tracking/TrackerTest.java b/sonar-core/src/test/java/org/sonar/core/issue/tracking/TrackerTest.java index 37391225a84..a9fe647095e 100644 --- a/sonar-core/src/test/java/org/sonar/core/issue/tracking/TrackerTest.java +++ b/sonar-core/src/test/java/org/sonar/core/issue/tracking/TrackerTest.java @@ -196,13 +196,13 @@ public class TrackerTest { } @Test - public void fail_if_raw_line_does_not_exist() throws Exception { + public void do_not_fail_if_raw_line_does_not_exist() throws Exception { FakeInput baseInput = new FakeInput(); FakeInput rawInput = new FakeInput("H1").addIssue(new Issue(200, "H200", RULE_SYSTEM_PRINT, "msg")); - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Issue line is not valid"); - tracker.track(rawInput, baseInput); + Tracking<Issue, Issue> tracking = tracker.track(rawInput, baseInput); + + assertThat(tracking.getUnmatchedRaws()).hasSize(1); } /** @@ -406,7 +406,7 @@ public class TrackerTest { private final List<Issue> issues = new ArrayList<>(); private final List<String> lineHashes; - public FakeInput(String... lineHashes) { + FakeInput(String... lineHashes) { this.lineHashes = asList(lineHashes); } @@ -418,7 +418,7 @@ public class TrackerTest { return new FakeInput(hashes); } - public Issue createIssueOnLine(int line, RuleKey ruleKey, String message) { + Issue createIssueOnLine(int line, RuleKey ruleKey, String message) { Issue issue = new Issue(line, lineHashes.get(line - 1), ruleKey, message); issues.add(issue); return issue; @@ -427,13 +427,13 @@ public class TrackerTest { /** * No line (line 0) */ - public Issue createIssue(RuleKey ruleKey, String message) { + Issue createIssue(RuleKey ruleKey, String message) { Issue issue = new Issue(null, "", ruleKey, message); issues.add(issue); return issue; } - public FakeInput addIssue(Issue issue) { + FakeInput addIssue(Issue issue) { this.issues.add(issue); return this; } diff --git a/sonar-core/src/test/java/org/sonar/core/issue/workflow/SetClosedTest.java b/sonar-core/src/test/java/org/sonar/core/issue/workflow/SetClosedTest.java index 84e46786292..3418cd9d1d3 100644 --- a/sonar-core/src/test/java/org/sonar/core/issue/workflow/SetClosedTest.java +++ b/sonar-core/src/test/java/org/sonar/core/issue/workflow/SetClosedTest.java @@ -56,7 +56,7 @@ public class SetClosedTest { INSTANCE.execute(context); fail(); } catch (IllegalStateException e) { - assertThat(e.getMessage()).contains("Issue is still alive"); + assertThat(e.getMessage()).contains("Issue is still open"); verify(context, never()).setResolution(anyString()); } } diff --git a/sonar-core/src/test/java/org/sonar/core/technicaldebt/DefaultTechnicalDebtModelTest.java b/sonar-core/src/test/java/org/sonar/core/technicaldebt/DefaultTechnicalDebtModelTest.java deleted file mode 100644 index 3ea3a311fda..00000000000 --- a/sonar-core/src/test/java/org/sonar/core/technicaldebt/DefaultTechnicalDebtModelTest.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -package org.sonar.core.technicaldebt; - -import org.junit.Before; -import org.junit.Test; -import org.sonar.api.batch.debt.internal.DefaultDebtCharacteristic; -import org.sonar.api.batch.debt.internal.DefaultDebtModel; -import org.sonar.api.rule.RuleKey; -import org.sonar.api.technicaldebt.batch.internal.DefaultCharacteristic; - -import static org.assertj.core.api.Assertions.assertThat; - -public class DefaultTechnicalDebtModelTest { - - private DefaultTechnicalDebtModel sqaleModel; - - @Before - public void setUp() { - DefaultDebtModel debtModel = new DefaultDebtModel(); - debtModel.addCharacteristic( - new DefaultDebtCharacteristic().setId(1) - .setKey("MEMORY_EFFICIENCY") - .setName("Memory use") - .setOrder(1) - ); - debtModel.addSubCharacteristic( - new DefaultDebtCharacteristic().setId(2) - .setKey("EFFICIENCY") - .setName("Efficiency") - .setParentId(1), - "MEMORY_EFFICIENCY" - ); - sqaleModel = new DefaultTechnicalDebtModel(debtModel); - } - - @Test - public void get_characteristics() { - assertThat(sqaleModel.rootCharacteristics()).hasSize(1); - - DefaultCharacteristic resultRootCharacteristic = sqaleModel.rootCharacteristics().get(0); - assertThat(resultRootCharacteristic.id()).isEqualTo(1); - assertThat(resultRootCharacteristic.key()).isEqualTo("MEMORY_EFFICIENCY"); - assertThat(resultRootCharacteristic.name()).isEqualTo("Memory use"); - assertThat(resultRootCharacteristic.order()).isEqualTo(1); - assertThat(resultRootCharacteristic.children()).hasSize(1); - assertThat(resultRootCharacteristic.parent()).isNull(); - assertThat(resultRootCharacteristic.root()).isNull(); - } - - @Test - public void get_characteristic_by_key() { - assertThat(sqaleModel.characteristicByKey("MEMORY_EFFICIENCY")).isNotNull(); - assertThat(sqaleModel.characteristicByKey("EFFICIENCY")).isNotNull(); - assertThat(sqaleModel.characteristicByKey("EFFICIENCY").parent()).isNotNull(); - - assertThat(sqaleModel.characteristicByKey("UNKNOWN")).isNull(); - } - - @Test - public void characteristic_by_id() { - assertThat(sqaleModel.characteristicById(1)).isNotNull(); - assertThat(sqaleModel.characteristicById(2)).isNotNull(); - assertThat(sqaleModel.characteristicById(123)).isNull(); - } - - @Test - public void get_requirement_by_rule_key_always_return_null() { - assertThat(sqaleModel.requirementsByRule(RuleKey.of("checkstyle", "Regexp"))).isNull(); - } - - @Test - public void get_requirement_by_id_always_return_null() { - assertThat(sqaleModel.requirementsById(1)).isNull(); - } - - @Test - public void get_requirements_always_return_empty_list() { - assertThat(sqaleModel.requirements()).isEmpty(); - } - -} diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/selectChangelogOfUnresolvedIssuesByComponent.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/selectChangelogOfUnresolvedIssuesByComponent.xml new file mode 100644 index 00000000000..966f7c31cac --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/selectChangelogOfUnresolvedIssuesByComponent.xml @@ -0,0 +1,144 @@ +<dataset> + + <!-- Unresolved --> + <issues + id="1" + kee="UNRESOLVED_ON_FILE_1" + component_uuid="FILE_1" + project_uuid="PROJECT_1" + resolution="[null]" + status="OPEN" + rule_id="500" + severity="BLOCKER" + manual_severity="[false]" + message="[null]" + line="200" + effort_to_fix="[null]" + checksum="[null]" + reporter="user" + assignee="user" + author_login="[null]" + issue_attributes="[null]" + issue_creation_date="1366063200000" + issue_update_date="1366063200000" + issue_close_date="1366063200000" + created_at="1400000000000" + updated_at="[null]" + /> + + <!-- diff --> + <issue_changes + id="100" + kee="100" + issue_key="UNRESOLVED_ON_FILE_1" + user_login="arthur" + change_type="diff" + change_data="severity=MAJOR|BLOCKER" + created_at="1410213600000" + updated_at="1410213600000" + issue_change_creation_date="1410213600000" + /> + + <!-- comment --> + <issue_changes + id="102" + kee="102" + issue_key="UNRESOLVED_ON_FILE_1" + user_login="arthur" + change_type="comment" + change_data="recent comment" + created_at="1410213600000" + updated_at="1410213600000" + issue_change_creation_date="[null]" + /> + + <!-- Resolved: to be ignored --> + <issues + id="2" + kee="RESOLVED_ON_FILE_1" + component_uuid="FILE_1" + project_uuid="PROJECT_1" + resolution="FIXED" + status="RESOLVED" + rule_id="501" + severity="MAJOR" + manual_severity="[false]" + message="[null]" + line="120" + effort_to_fix="[null]" + checksum="[null]" + reporter="[null]" + assignee="user" + author_login="[null]" + issue_attributes="[null]" + issue_creation_date="1366063200000" + issue_update_date="1366063200000" + issue_close_date="1366063200000" + created_at="1400000000000" + updated_at="[null]" + /> + + <issue_changes + id="103" + kee="103" + issue_key="RESOLVED_ON_FILE_1" + user_login="arthur" + change_type="diff" + change_data="severity=MAJOR|BLOCKER" + created_at="1410213600000" + updated_at="1410213600000" + issue_change_creation_date="1410213600000" + /> + + <!-- Unresolved on other file --> + <issues + id="3" + kee="UNRESOLVED_ON_FILE_2" + component_uuid="FILE_2" + project_uuid="PROJECT_1" + resolution="[null]" + status="OPEN" + rule_id="500" + severity="BLOCKER" + manual_severity="[false]" + message="[null]" + line="200" + effort_to_fix="[null]" + checksum="[null]" + reporter="user" + assignee="user" + author_login="[null]" + issue_attributes="[null]" + issue_creation_date="1366063200000" + issue_update_date="1366063200000" + issue_close_date="1366063200000" + created_at="1400000000000" + updated_at="[null]" + /> + + <!-- diff --> + <issue_changes + id="104" + kee="104" + issue_key="UNRESOLVED_ON_FILE_2" + user_login="arthur" + change_type="diff" + change_data="severity=MAJOR|BLOCKER" + created_at="1410213600000" + updated_at="1410213600000" + issue_change_creation_date="1410213600000" + /> + + <!-- comment --> + <issue_changes + id="105" + kee="105" + issue_key="UNRESOLVED_ON_FILE_2" + user_login="arthur" + change_type="comment" + change_data="recent comment" + created_at="1410213600000" + updated_at="1410213600000" + issue_change_creation_date="[null]" + /> +</dataset> diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/select_issue_changelog_by_module.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/select_issue_changelog_by_module.xml deleted file mode 100644 index fd4ee9c31d0..00000000000 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/select_issue_changelog_by_module.xml +++ /dev/null @@ -1,222 +0,0 @@ -<dataset> - - <projects id="399" uuid="uuid-399" kee="struts" root_id="[null]" project_uuid="[null]" qualifier="TRK" scope="PRJ" /> - <projects id="400" uuid="uuid-400" kee="struts-core" root_id="399" project_uuid="uuid-399" qualifier="BRC" scope="PRJ" /> - <projects id="401" uuid="uuid-401" kee="Action.java" root_id="400" project_uuid="uuid-400" qualifier="CLA" scope="PRJ" /> - <projects id="402" uuid="uuid-402" kee="Filter.java" root_id="400" project_uuid="uuid-400" qualifier="CLA" scope="PRJ" /> - - <!-- Open Issue on a file --> - <issues - id="100" - kee="100" - component_uuid="uuid-401" - project_uuid="uuid-399" - rule_id="500" - severity="BLOCKER" - manual_severity="[false]" - message="[null]" - line="200" - effort_to_fix="[null]" - status="OPEN" - resolution="[null]" - checksum="[null]" - reporter="user" - assignee="user" - author_login="[null]" - issue_attributes="[null]" - issue_creation_date="1366063200000" - issue_update_date="1366063200000" - issue_close_date="1366063200000" - created_at="1400000000000" - updated_at="[null]" - /> - - <issue_changes - id="100" - kee="100" - issue_key="100" - user_login="arthur" - change_type="diff" - change_data="severity=MAJOR|BLOCKER" - created_at="1410213600000" - updated_at="1410213600000" - issue_change_creation_date="1410213600000" - /> - - <issue_changes - id="1000" - kee="1000" - issue_key="100" - user_login="arthur" - change_type="diff" - change_data="actionPlan=1.0|1.1" - created_at="1410213600000" - updated_at="1410213600000" - issue_change_creation_date="1410213600000" - /> - - <issue_changes - id="1001" - kee="1001" - issue_key="100" - user_login="arthur" - change_type="comment" - change_data="recent comment" - created_at="1410213600000" - updated_at="1410213600000" - issue_change_creation_date="[null]" - /> - - <!-- Open Issue on a file --> - <issues - id="101" - kee="101" - component_uuid="uuid-402" - project_uuid="uuid-399" - rule_id="501" - severity="MAJOR" - manual_severity="[false]" - message="[null]" - line="120" - effort_to_fix="[null]" - status="OPEN" - resolution="[null]" - checksum="[null]" - reporter="[null]" - assignee="user" - author_login="[null]" - issue_attributes="[null]" - issue_creation_date="1366063200000" - issue_update_date="1366063200000" - issue_close_date="1366063200000" - created_at="1400000000000" - updated_at="[null]" - /> - - <issue_changes - id="101" - kee="101" - issue_key="101" - user_login="arthur" - change_type="diff" - change_data="severity=MAJOR|BLOCKER" - created_at="1410213600000" - updated_at="1410213600000" - issue_change_creation_date="1410213600000" - /> - - <!-- Closed Issue on a file --> - <issues - id="102" - kee="102" - component_uuid="uuid-402" - project_uuid="uuid-399" - rule_id="501" - severity="MAJOR" - manual_severity="[false]" - message="[null]" - line="120" - effort_to_fix="[null]" - status="CLOSED" - resolution="FIXED" - checksum="[null]" - reporter="[null]" - assignee="user" - author_login="[null]" - issue_attributes="[null]" - issue_creation_date="1366063200000" - issue_update_date="1366063200000" - issue_close_date="1366063200000" - created_at="1400000000000" - updated_at="[null]" - /> - - <issue_changes - id="102" - kee="102" - issue_key="102" - user_login="arthur" - change_type="diff" - change_data="severity=MAJOR|BLOCKER" - created_at="1410213600000" - updated_at="1410213600000" - issue_change_creation_date="1410213600000" - /> - - <!-- Open Issue on a sub module --> - <issues - id="103" - kee="103" - component_uuid="uuid-400" - project_uuid="uuid-399" - rule_id="501" - severity="MAJOR" - manual_severity="[false]" - message="[null]" - line="[null]" - effort_to_fix="[null]" - status="OPEN" - resolution="[null]" - checksum="[null]" - reporter="[null]" - assignee="user" - author_login="[null]" - issue_attributes="[null]" - issue_creation_date="1366063200000" - issue_update_date="1366063200000" - issue_close_date="1366063200000" - created_at="1400000000000" - updated_at="[null]" - /> - - <issue_changes - id="103" - kee="103" - issue_key="103" - user_login="arthur" - change_type="diff" - change_data="severity=MAJOR|BLOCKER" - created_at="1410213600000" - updated_at="1410213600000" - issue_change_creation_date="1410213600000" - /> - - <!-- Open Issue on a root module --> - <issues - id="104" - kee="104" - component_uuid="uuid-399" - project_uuid="uuid-399" - rule_id="501" - severity="MAJOR" - manual_severity="[false]" - message="[null]" - line="[null]" - effort_to_fix="[null]" - status="OPEN" - resolution="[null]" - checksum="[null]" - reporter="[null]" - assignee="user" - author_login="[null]" - issue_attributes="[null]" - issue_creation_date="1366063200000" - issue_update_date="1366063200000" - issue_close_date="1366063200000" - created_at="1400000000000" - updated_at="[null]" - /> - - <issue_changes - id="104" - kee="104" - issue_key="104" - user_login="arthur" - change_type="diff" - change_data="severity=MAJOR|BLOCKER" - created_at="1410213600000" - updated_at="1410213600000" - issue_change_creation_date="1410213600000" - /> - -</dataset> diff --git a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/select_issue_changelog_by_module_are_sorted_by_creation_date.xml b/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/select_issue_changelog_by_module_are_sorted_by_creation_date.xml deleted file mode 100644 index b019869a390..00000000000 --- a/sonar-core/src/test/resources/org/sonar/core/issue/db/IssueChangeDaoTest/select_issue_changelog_by_module_are_sorted_by_creation_date.xml +++ /dev/null @@ -1,67 +0,0 @@ -<dataset> - - <projects id="399" uuid="uuid-399" kee="struts" root_id="[null]" project_uuid="[null]" qualifier="TRK" scope="PRJ" /> - - <!-- Open Issue on a root module --> - <issues - id="104" - kee="104" - component_uuid="uuid-399" - project_uuid="uuid-399" - rule_id="501" - severity="MAJOR" - manual_severity="[false]" - message="[null]" - line="[null]" - effort_to_fix="[null]" - status="OPEN" - resolution="[null]" - checksum="[null]" - reporter="[null]" - assignee="user" - author_login="[null]" - issue_attributes="[null]" - issue_creation_date="1366063200000" - issue_update_date="1366063200000" - issue_close_date="1366063200000" - created_at="1400000000000" - updated_at="[null]" - /> - - <issue_changes - id="1000" - kee="1000" - issue_key="104" - user_login="arthur" - change_type="diff" - change_data="severity=MAJOR|BLOCKER" - created_at="1410386400000" - updated_at="1410386400000" - issue_change_creation_date="1410386400000" - /> - - <issue_changes - id="1001" - kee="1001" - issue_key="104" - user_login="arthur" - change_type="diff" - change_data="severity=MAJOR|BLOCKER" - created_at="1410213600000" - updated_at="1410213600000" - issue_change_creation_date="1410213600000" - /> - - <issue_changes - id="1002" - kee="1002" - issue_key="104" - user_login="arthur" - change_type="diff" - change_data="actionPlan=1.0|1.1" - created_at="1410300000000" - updated_at="1410300000000" - issue_change_creation_date="1410300000000" - /> - -</dataset> |