if (rulesBag != null) {
for (Multiset.Entry<Rule> entry : rulesBag.entrySet()) {
RuleMeasure measure = RuleMeasure.createForRule(metric, entry.getElement(), (double) entry.getCount());
- measure.setRulePriority(severity);
+ measure.setSeverity(severity);
context.saveMeasure(measure);
}
}
for (Rule rule : rules) {
RuleMeasure measure = RuleMeasure.createForRule(metric, rule, null);
- measure.setRulePriority(severity);
+ measure.setSeverity(severity);
for (PastSnapshot pastSnapshot : timeMachineConfiguration.getProjectPastSnapshots()) {
int variationIndex = pastSnapshot.getIndex();
int count = countViolations(violationsPerRule.get(rule), pastSnapshot.getTargetDate());
}
if (measure instanceof RuleMeasure) {
RuleMeasure ruleMeasure = (RuleMeasure) measure;
- merge.setRulePriority(ruleMeasure.getRulePriority());
+ merge.setRulePriority(ruleMeasure.getSeverity());
if (ruleMeasure.getRule() != null) {
Rule ruleWithId = ruleFinder.findByKey(ruleMeasure.getRule().getRepositoryKey(), ruleMeasure.getRule().getKey());
if (ruleWithId != null) {
SqlSession session = mybatis.openBatchSession();
PurgeMapper purgeMapper = session.getMapper(PurgeMapper.class);
try {
- List<Long> projectIds = resourceDao.getDescendantProjectIdsAndSelf(rootProjectId, session);
+ List<Long> projectIds = Lists.newArrayList(rootProjectId);
+ projectIds.addAll(resourceDao.getDescendantProjectIds(rootProjectId, session));
for (Long projectId : projectIds) {
purgeProject(projectId, session, purgeMapper);
}
}
public PurgeSnapshotQuery setScopes(String[] scopes) {
- this.scopes = scopes;
+ this.scopes = scopes; //NOSONAR May expose internal representation by incorporating reference to mutable object
return this;
}
}
public PurgeSnapshotQuery setQualifiers(String[] qualifiers) {
- this.qualifiers = qualifiers;
+ this.qualifiers = qualifiers;//NOSONAR May expose internal representation by incorporating reference to mutable object
return this;
}
this.mybatis = mybatis;
}
- public List<Long> getDescendantProjectIdsAndSelf(long projectId) {
+ public List<Long> getDescendantProjectIds(long projectId) {
SqlSession session = mybatis.openSession();
try {
- return getDescendantProjectIdsAndSelf(projectId, session);
+ return getDescendantProjectIds(projectId, session);
} finally {
MyBatis.closeQuietly(session);
}
}
- public List<Long> getDescendantProjectIdsAndSelf(long projectId, SqlSession session) {
+ public List<Long> getDescendantProjectIds(long projectId, SqlSession session) {
ResourceMapper mapper = session.getMapper(ResourceMapper.class);
List<Long> ids = Lists.newArrayList();
appendChildProjectIds(projectId, mapper, ids);
}
private void appendChildProjectIds(long projectId, ResourceMapper mapper, List<Long> ids) {
- ids.add(projectId);
List<Long> subProjectIds = mapper.selectDescendantProjectIds(projectId);
for (Long subProjectId : subProjectIds) {
ids.add(subProjectId);
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.core.purge;
+
+import org.junit.Test;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.number.OrderingComparisons.greaterThan;
+import static org.junit.Assert.assertThat;
+
+public class PurgeableSnapshotDtoTest {
+ @Test
+ public void testEquals() {
+ PurgeableSnapshotDto dto1 = new PurgeableSnapshotDto().setSnapshotId(3L);
+ PurgeableSnapshotDto dto2 = new PurgeableSnapshotDto().setSnapshotId(4L);
+ assertThat(dto1.equals(dto2), is(false));
+ assertThat(dto2.equals(dto1), is(false));
+ assertThat(dto1.equals(dto1), is(true));
+ assertThat(dto1.equals(new PurgeableSnapshotDto().setSnapshotId(3L)), is(true));
+ assertThat(dto1.equals("bi_bop_a_lou_la"), is(false));
+ assertThat(dto1.equals(null), is(false));
+ }
+
+ @Test
+ public void testHasCode() {
+ PurgeableSnapshotDto dto = new PurgeableSnapshotDto().setSnapshotId(3L);
+ assertThat(dto.hashCode(), is(dto.hashCode()));
+
+ // no id
+ dto = new PurgeableSnapshotDto();
+ assertThat(dto.hashCode(), is(dto.hashCode()));
+ }
+
+ @Test
+ public void testToString() {
+ PurgeableSnapshotDto dto = new PurgeableSnapshotDto().setSnapshotId(3L);
+ assertThat(dto.toString().length(), greaterThan(0));
+ }
+}
--- /dev/null
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar 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.
+ *
+ * Sonar 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 Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.core.resource;
+
+import org.hamcrest.core.Is;
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.core.persistence.DaoTestCase;
+
+import java.util.List;
+
+import static org.hamcrest.core.IsNot.not;
+import static org.hamcrest.core.IsNull.nullValue;
+import static org.junit.Assert.assertThat;
+import static org.junit.matchers.JUnitMatchers.hasItems;
+
+public class ResourceDaoTest extends DaoTestCase {
+
+ private ResourceDao dao;
+
+ @Before
+ public void createDao() {
+ dao = new ResourceDao(getMyBatis());
+ }
+
+ @Test
+ public void testDescendantProjectIdsAndSelf() {
+ setupData("fixture");
+
+ List<Long> ids = dao.getDescendantProjectIds(1L);
+
+ assertThat(ids, hasItems(2L));
+ assertThat(ids.size(), Is.is(1));
+ }
+
+ @Test
+ public void testDescendantProjectIdsAndSelf_id_not_found() {
+ setupData("fixture");
+
+ List<Long> ids = dao.getDescendantProjectIds(33333L);
+
+ assertThat(ids, not(nullValue()));
+ assertThat(ids.size(), Is.is(0));
+ }
+}
+
--- /dev/null
+<dataset>
+
+ <!-- root project -->
+ <projects id="1" root_id="[null]" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Struts"
+ description="[null]" long_name="Struts"
+ enabled="[true]" language="java" copy_resource_id="[null]"/>
+ <snapshots id="1" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
+ status="P" islast="[false]" purge_status="[null]"
+ period1_mode="[null]" period1_param="[null]" period1_date="[null]"
+ period2_mode="[null]" period2_param="[null]" period2_date="[null]"
+ period3_mode="[null]" period3_param="[null]" period3_date="[null]"
+ period4_mode="[null]" period4_param="[null]" period4_date="[null]"
+ period5_mode="[null]" period5_param="[null]" period5_date="[null]"
+ depth="[null]" scope="PRJ" qualifier="TRK" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00"
+ version="[null]" path="[null]"/>
+
+ <!-- project -->
+ <projects id="2" root_id="1" kee="org.struts:struts-core" name="Struts Core"
+ scope="PRJ" qualifier="BRC" long_name="Struts Core"
+ description="[null]" enabled="[true]" language="java" copy_resource_id="[null]"/>
+ <snapshots id="2" project_id="2" parent_snapshot_id="1" root_project_id="1" root_snapshot_id="1"
+ status="P" islast="[false]" purge_status="[null]"
+ period1_mode="[null]" period1_param="[null]" period1_date="[null]"
+ period2_mode="[null]" period2_param="[null]" period2_date="[null]"
+ period3_mode="[null]" period3_param="[null]" period3_date="[null]"
+ period4_mode="[null]" period4_param="[null]" period4_date="[null]"
+ period5_mode="[null]" period5_param="[null]" period5_date="[null]"
+ depth="[null]" scope="PRJ" qualifier="BRC" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00"
+ version="[null]" path="[null]"/>
+
+ <!-- directory -->
+ <projects long_name="org.struts" id="3" scope="DIR" qualifier="PAC" kee="org.struts:struts:org.struts"
+ name="org.struts" root_id="1"
+ description="[null]"
+ enabled="[true]" language="java" copy_resource_id="[null]"/>
+ <snapshots id="3" project_id="3" parent_snapshot_id="2" root_project_id="1" root_snapshot_id="1"
+ status="P" islast="[false]" purge_status="[null]"
+ period1_mode="[null]" period1_param="[null]" period1_date="[null]"
+ period2_mode="[null]" period2_param="[null]" period2_date="[null]"
+ period3_mode="[null]" period3_param="[null]" period3_date="[null]"
+ period4_mode="[null]" period4_param="[null]" period4_date="[null]"
+ period5_mode="[null]" period5_param="[null]" period5_date="[null]"
+ depth="[null]" scope="DIR" qualifier="PAC" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00"
+ version="[null]" path="[null]"/>
+
+ <!-- file -->
+ <projects long_name="org.struts.RequestContext" id="4" scope="FIL" qualifier="CLA" kee="org.struts:struts:org.struts.RequestContext"
+ name="RequestContext" root_id="1"
+ description="[null]"
+ enabled="[true]" language="java" copy_resource_id="[null]"/>
+
+ <snapshots id="4" project_id="4" parent_snapshot_id="3" root_project_id="1" root_snapshot_id="1"
+ status="P" islast="[false]" purge_status="[null]"
+ period1_mode="[null]" period1_param="[null]" period1_date="[null]"
+ period2_mode="[null]" period2_param="[null]" period2_date="[null]"
+ period3_mode="[null]" period3_param="[null]" period3_date="[null]"
+ period4_mode="[null]" period4_param="[null]" period4_date="[null]"
+ period5_mode="[null]" period5_param="[null]" period5_date="[null]"
+ depth="[null]" scope="FIL" qualifier="CLA" created_at="2008-12-02 13:58:00.00" build_date="2008-12-02 13:58:00.00"
+ version="[null]" path="[null]"/>
+</dataset>