diff options
author | Evgeny Mandrikov <mandrikov@gmail.com> | 2012-01-24 17:17:59 +0400 |
---|---|---|
committer | Evgeny Mandrikov <mandrikov@gmail.com> | 2012-01-24 20:33:39 +0400 |
commit | ed409e8f0a53554aad46ac438b93b7adc02cc5d8 (patch) | |
tree | af3c6337ef286c9cd4b68b490b43994fbc78a32a /sonar-core | |
parent | 74ae0f80835d5b236480b78253ed9a30af56ca6a (diff) | |
download | sonarqube-ed409e8f0a53554aad46ac438b93b7adc02cc5d8.tar.gz sonarqube-ed409e8f0a53554aad46ac438b93b7adc02cc5d8.zip |
SONAR-3181,SONAR-3139 Enable cross project CPD for all languages
sonar.cpd.minimumTokens can't be used, because for index in database
tokens must be grouped by lines.
Diffstat (limited to 'sonar-core')
5 files changed, 29 insertions, 20 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/duplication/DuplicationDao.java b/sonar-core/src/main/java/org/sonar/core/duplication/DuplicationDao.java index 2d98f947ca8..e557d061ca7 100644 --- a/sonar-core/src/main/java/org/sonar/core/duplication/DuplicationDao.java +++ b/sonar-core/src/main/java/org/sonar/core/duplication/DuplicationDao.java @@ -36,11 +36,11 @@ public class DuplicationDao implements BatchComponent, ServerComponent { this.mybatis = mybatis; } - public List<DuplicationUnitDto> selectCandidates(int resourceSnapshotId, Integer lastSnapshotId) { + public List<DuplicationUnitDto> selectCandidates(int resourceSnapshotId, Integer lastSnapshotId, String language) { SqlSession session = mybatis.openSession(); try { DuplicationMapper mapper = session.getMapper(DuplicationMapper.class); - return mapper.selectCandidates(resourceSnapshotId, lastSnapshotId); + return mapper.selectCandidates(resourceSnapshotId, lastSnapshotId, language); } finally { MyBatis.closeSessionQuietly(session); } diff --git a/sonar-core/src/main/java/org/sonar/core/duplication/DuplicationMapper.java b/sonar-core/src/main/java/org/sonar/core/duplication/DuplicationMapper.java index fa4b30052cb..f7afbb79af4 100644 --- a/sonar-core/src/main/java/org/sonar/core/duplication/DuplicationMapper.java +++ b/sonar-core/src/main/java/org/sonar/core/duplication/DuplicationMapper.java @@ -27,7 +27,8 @@ public interface DuplicationMapper { List<DuplicationUnitDto> selectCandidates( @Param("resource_snapshot_id") int resourceSnapshotId, - @Param("last_project_snapshot_id") Integer lastSnapshotId); + @Param("last_project_snapshot_id") Integer lastSnapshotId, + @Param("language") String language); void batchInsert(DuplicationUnitDto unit); diff --git a/sonar-core/src/main/resources/org/sonar/core/duplication/DuplicationMapper.xml b/sonar-core/src/main/resources/org/sonar/core/duplication/DuplicationMapper.xml index c1dc43121e4..2f0af1b57e7 100644 --- a/sonar-core/src/main/resources/org/sonar/core/duplication/DuplicationMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/duplication/DuplicationMapper.xml @@ -11,6 +11,7 @@ AND to_blocks.snapshot_id = snapshot.id AND snapshot.islast = ${_true} AND snapshot.project_id = res.id + AND res.language = #{language} <if test="last_project_snapshot_id != null"> AND to_blocks.project_snapshot_id != #{last_project_snapshot_id} </if> diff --git a/sonar-core/src/test/java/org/sonar/core/duplication/DuplicationDaoTest.java b/sonar-core/src/test/java/org/sonar/core/duplication/DuplicationDaoTest.java index 08d10516240..c5a0cddbc5b 100644 --- a/sonar-core/src/test/java/org/sonar/core/duplication/DuplicationDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/duplication/DuplicationDaoTest.java @@ -42,7 +42,7 @@ public class DuplicationDaoTest extends DaoTestCase { public void shouldGetByHash() throws Exception { setupData("shouldGetByHash"); - List<DuplicationUnitDto> blocks = dao.selectCandidates(10, 7); + List<DuplicationUnitDto> blocks = dao.selectCandidates(10, 7, "java"); assertThat(blocks.size(), is(1)); DuplicationUnitDto block = blocks.get(0); @@ -53,7 +53,7 @@ public class DuplicationDaoTest extends DaoTestCase { assertThat("block end line", block.getEndLine(), is(2)); // check null for lastSnapshotId - blocks = dao.selectCandidates(10, null); + blocks = dao.selectCandidates(10, null, "java"); assertThat(blocks.size(), is(2)); } diff --git a/sonar-core/src/test/resources/org/sonar/core/duplication/DuplicationDaoTest/shouldGetByHash.xml b/sonar-core/src/test/resources/org/sonar/core/duplication/DuplicationDaoTest/shouldGetByHash.xml index b9fde7599f3..208fffdf891 100644 --- a/sonar-core/src/test/resources/org/sonar/core/duplication/DuplicationDaoTest/shouldGetByHash.xml +++ b/sonar-core/src/test/resources/org/sonar/core/duplication/DuplicationDaoTest/shouldGetByHash.xml @@ -1,24 +1,27 @@ <dataset> - <snapshots purge_status="[null]" id="1" status="P" islast="0" project_id="0" /> - <snapshots purge_status="[null]" id="2" status="P" islast="0" project_id="1" /> - <projects id="1" kee="bar-old" enabled="1" scope="FIL" qualifier="CLA" /> + <snapshots id="1" project_id="1" status="P" islast="0" purge_status="[null]" /> + <snapshots id="2" project_id="1" status="P" islast="0" purge_status="[null]" /> + <projects id="1" kee="bar-old" enabled="1" scope="FIL" qualifier="CLA" language="java" /> - <snapshots purge_status="[null]" id="3" status="P" islast="1" project_id="2" /> - <snapshots purge_status="[null]" id="4" status="P" islast="1" project_id="2" /> - <projects id="2" kee="bar-last" enabled="1" scope="FIL" qualifier="CLA" /> + <snapshots id="3" project_id="2" status="P" islast="1" purge_status="[null]" /> + <snapshots id="4" project_id="2" status="P" islast="1" purge_status="[null]" /> + <projects id="2" kee="bar-last" enabled="1" scope="FIL" qualifier="CLA" language="java" /> - <snapshots purge_status="[null]" id="5" status="P" islast="0" project_id="3" /> - <snapshots purge_status="[null]" id="6" status="P" islast="0" project_id="3" /> - <projects id="3" kee="foo-old" enabled="1" scope="FIL" qualifier="CLA" /> + <snapshots id="5" project_id="3" status="P" islast="0" purge_status="[null]" /> + <snapshots id="6" project_id="3" status="P" islast="0" purge_status="[null]" /> + <projects id="3" kee="foo-old" enabled="1" scope="FIL" qualifier="CLA" language="java" /> - <snapshots purge_status="[null]" id="7" status="P" islast="1" project_id="4" /> - <snapshots purge_status="[null]" id="8" status="P" islast="1" project_id="4" /> - <projects id="4" kee="foo-last" enabled="1" scope="FIL" qualifier="CLA" /> + <snapshots id="7" project_id="4" status="P" islast="1" purge_status="[null]" /> + <snapshots id="8" project_id="4" status="P" islast="1" purge_status="[null]" /> + <projects id="4" kee="foo-last" enabled="1" scope="FIL" qualifier="CLA" language="java" /> - <snapshots purge_status="[null]" id="9" status="U" islast="0" project_id="5" /> - <snapshots purge_status="[null]" id="10" status="U" islast="0" project_id="5" /> - <projects id="5" kee="foo" enabled="1" scope="FIL" qualifier="CLA" /> + <snapshots id="9" project_id="5" status="U" islast="0" purge_status="[null]" /> + <snapshots id="10" project_id="5" status="U" islast="0" purge_status="[null]" /> + <projects id="5" kee="foo" enabled="1" scope="FIL" qualifier="CLA" language="java" /> + + <snapshots id="11" project_id="6" purge_status="[null]" status="P" islast="1" /> + <projects id="6" kee="baz" enabled="1" scope="FIL" qualifier="CLA" language="grvy" /> <!-- Old snapshot of another project --> <!-- bar-old --> @@ -44,4 +47,8 @@ <!-- without "DISTINCT" we will select block from "bar-last" two times. --> <duplications_index project_snapshot_id="9" snapshot_id="10" hash="aa" index_in_file="1" start_line="1" end_line="1" /> + <!-- Last snapshot of project with another language --> + <!-- baz --> + <duplications_index project_snapshot_id="1" snapshot_id="11" hash="aa" index_in_file="0" start_line="0" end_line="0" /> + </dataset> |