.setEndLine(block.getEndLine())
.setIndexInFile(indexInFile)
.setSnapshotId(dbIdsRepository.getSnapshotId(component))
- .setProjectSnapshotId(projectSnapshotId)
- );
+ .setComponentUuid(component.getUuid())
+ .setProjectSnapshotId(projectSnapshotId));
indexInFile++;
}
} finally {
*/
package org.sonar.server.computation.step;
-import java.util.*;
-
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.mockito.Mockito.when;
import static org.sonar.server.computation.component.Component.Type.FILE;
import static org.sonar.server.computation.component.Component.Type.PROJECT;
@Rule
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule().setRoot(
ReportComponent.builder(PROJECT, PROJECT_REF)
- .addChildren(CURRENT_FILE
- ).build());
+ .addChildren(CURRENT_FILE).build());
@Rule
public BatchReportReaderRule batchReportReader = new BatchReportReaderRule();
.setEndLine(55)
.setIndexInFile(0)
.setProjectSnapshotId(otherProjectSnapshot.getId())
- .setSnapshotId(otherFileSnapshot.getId());
+ .setSnapshotId(otherFileSnapshot.getId())
+ .setComponentUuid(otherFileSnapshot.getComponentUuid());
dbClient.duplicationDao().insert(dbSession, duplicate);
dbSession.commit();
.setIndexInFile(0)
.setLines(originBlock.getStartLine(), originBlock.getEndLine())
.setUnit(originBlock.getStartTokenIndex(), originBlock.getEndTokenIndex())
- .build()
- ),
+ .build()),
Arrays.asList(
new Block.Builder()
.setResourceId(otherFIle.getKey())
.setBlockHash(new ByteArray(hash))
.setIndexInFile(duplicate.getIndexInFile())
.setLines(duplicate.getStartLine(), duplicate.getEndLine())
- .build()
- )
- );
+ .build()));
}
@Test
.setEndLine(55)
.setIndexInFile(0)
.setProjectSnapshotId(otherProjectSnapshot.getId())
- .setSnapshotId(otherFileSnapshot.getId());
+ .setSnapshotId(otherFileSnapshot.getId())
+ .setComponentUuid(otherFileSnapshot.getComponentUuid());
DuplicationUnitDto duplicate2 = new DuplicationUnitDto()
.setHash(originBlock2.getHash())
.setEndLine(35)
.setIndexInFile(1)
.setProjectSnapshotId(otherProjectSnapshot.getId())
- .setSnapshotId(otherFileSnapshot.getId());
+ .setSnapshotId(otherFileSnapshot.getId())
+ .setComponentUuid(otherFileSnapshot.getComponentUuid());
dbClient.duplicationDao().insert(dbSession, duplicate1);
dbClient.duplicationDao().insert(dbSession, duplicate2);
dbSession.commit();
.setIndexInFile(0)
.setLines(originBlock1.getStartLine(), originBlock1.getEndLine())
.setUnit(originBlock1.getStartTokenIndex(), originBlock1.getEndTokenIndex())
- .build()
- );
+ .build());
assertThat(originBlocksByIndex.get(1)).isEqualTo(
new Block.Builder()
.setResourceId(CURRENT_FILE_KEY)
.setIndexInFile(1)
.setLines(originBlock2.getStartLine(), originBlock2.getEndLine())
.setUnit(originBlock2.getStartTokenIndex(), originBlock2.getEndTokenIndex())
- .build()
- );
+ .build());
Map<Integer, Block> duplicationBlocksByIndex = blocksByIndexInFile(duplicationBlocks.getValue());
assertThat(duplicationBlocksByIndex.get(0)).isEqualTo(
.setBlockHash(new ByteArray(originBlock1.getHash()))
.setIndexInFile(duplicate1.getIndexInFile())
.setLines(duplicate1.getStartLine(), duplicate1.getEndLine())
- .build()
- );
+ .build());
assertThat(duplicationBlocksByIndex.get(1)).isEqualTo(
new Block.Builder()
.setResourceId(otherFIle.getKey())
.setBlockHash(new ByteArray(originBlock2.getHash()))
.setIndexInFile(duplicate2.getIndexInFile())
.setLines(duplicate2.getStartLine(), duplicate2.getEndLine())
- .build()
- );
+ .build());
}
@Test
.setEndLine(55)
.setIndexInFile(0)
.setProjectSnapshotId(otherProjectSnapshot.getId())
- .setSnapshotId(otherFileSnapshot.getId());
+ .setSnapshotId(otherFileSnapshot.getId())
+ .setComponentUuid(otherFileSnapshot.getComponentUuid());
dbClient.duplicationDao().insert(dbSession, duplicate);
dbSession.commit();
import java.util.Collections;
import java.util.List;
import java.util.Map;
-
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
underTest.execute();
Map<String, Object> dto = dbTester.selectFirst("select hash as \"hash\", start_line as \"startLine\", end_line as \"endLine\", index_in_file as \"indexInFile\", " +
- "snapshot_id as \"snapshotId\", project_snapshot_id as \"projectSnapshotId\" from duplications_index");
+ "snapshot_id as \"snapshotId\", component_uuid as \"componentUuid\", project_snapshot_id as \"projectSnapshotId\" from duplications_index");
assertThat(dto.get("hash")).isEqualTo(CPD_TEXT_BLOCK.getHash());
assertThat(dto.get("startLine")).isEqualTo(30L);
assertThat(dto.get("endLine")).isEqualTo(45L);
assertThat(dto.get("indexInFile")).isEqualTo(0L);
assertThat(dto.get("snapshotId")).isEqualTo(FILE_SNAPSHOT_ID);
+ assertThat(dto.get("componentUuid")).isEqualTo(FILE.getUuid());
assertThat(dto.get("projectSnapshotId")).isEqualTo(PROJECT_SNAPSHOT_ID);
}
underTest.execute();
List<Map<String, Object>> dtos = dbTester.select("select hash as \"hash\", start_line as \"startLine\", end_line as \"endLine\", index_in_file as \"indexInFile\", " +
- "snapshot_id as \"snapshotId\", project_snapshot_id as \"projectSnapshotId\" from duplications_index");
+ "snapshot_id as \"snapshotId\", component_uuid as \"componentUuid\", project_snapshot_id as \"projectSnapshotId\" from duplications_index");
assertThat(dtos).extracting("hash").containsOnly(CPD_TEXT_BLOCK.getHash(), "b1234353e96320ff");
assertThat(dtos).extracting("startLine").containsOnly(30L, 20L);
assertThat(dtos).extracting("endLine").containsOnly(45L, 15L);
assertThat(dtos).extracting("indexInFile").containsOnly(0L, 1L);
assertThat(dtos).extracting("snapshotId").containsOnly(FILE_SNAPSHOT_ID);
+ assertThat(dtos).extracting("componentUuid").containsOnly(FILE.getUuid());
assertThat(dtos).extracting("projectSnapshotId").containsOnly(PROJECT_SNAPSHOT_ID);
}
private long id;
private long snapshotId;
+ private String componentUuid;
private long projectSnapshotId;
private String hash;
return this;
}
+ public String getComponentUuid() {
+ return componentUuid;
+ }
+
+ public DuplicationUnitDto setComponentUuid(String componentUuid) {
+ this.componentUuid = componentUuid;
+ return this;
+ }
+
public long getProjectSnapshotId() {
return projectSnapshotId;
}
SELECT DISTINCT
duplication_block.id as id,
duplication_block.snapshot_id as snapshotId,
+ duplication_block.component_uuid as componentUuid,
duplication_block.project_snapshot_id as projectSnapshotId,
duplication_block.hash as hash,
duplication_block.index_in_file as indexInFile,
file_component.kee as componentKey
FROM duplications_index duplication_block
INNER JOIN snapshots snapshot ON duplication_block.snapshot_id=snapshot.id AND snapshot.islast=${_true}
- INNER JOIN projects file_component ON file_component.uuid=snapshot.component_uuid AND file_component.language=#{language}
+ INNER JOIN projects file_component ON file_component.uuid=duplication_block.component_uuid AND file_component.language=#{language}
AND file_component.enabled=${_true}
<where>
AND duplication_block.hash in
</select>
<insert id="batchInsert" parameterType="DuplicationUnit" useGeneratedKeys="false">
- INSERT INTO duplications_index (snapshot_id, project_snapshot_id, hash, index_in_file, start_line, end_line)
- VALUES (#{snapshotId}, #{projectSnapshotId}, #{hash}, #{indexInFile}, #{startLine}, #{endLine})
+ INSERT INTO duplications_index (snapshot_id, component_uuid, project_snapshot_id, hash, index_in_file, start_line, end_line)
+ VALUES (#{snapshotId}, #{componentUuid}, #{projectSnapshotId}, #{hash}, #{indexInFile}, #{startLine}, #{endLine})
</insert>
</mapper>
DuplicationUnitDto block = blocks.get(0);
assertThat(block.getComponentKey()).isEqualTo("bar-last");
+ assertThat(block.getComponentUuid()).isEqualTo("uuid_2");
assertThat(block.getHash()).isEqualTo("aa");
assertThat(block.getIndexInFile()).isEqualTo(0);
assertThat(block.getStartLine()).isEqualTo(1);
dao.insert(dbSession, new DuplicationUnitDto()
.setProjectSnapshotId(1)
.setSnapshotId(2)
+ .setComponentUuid("uuid_1")
.setHash("bb")
.setIndexInFile(0)
.setStartLine(1)
project_id="1"/>
<projects id="1" uuid="1" kee="foo" enabled="1" scope="FIL" qualifier="CLA"/>
- <duplications_index id="1" project_snapshot_id="1" snapshot_id="2" hash="bb" index_in_file="0" start_line="1"
+ <duplications_index id="1"
+ project_snapshot_id="1"
+ snapshot_id="2"
+ component_uuid="uuid_1"
+ hash="bb"
+ index_in_file="0"
+ start_line="1"
end_line="2"/>
</dataset>
<!-- Old snapshot of another project -->
<!-- bar-old -->
- <duplications_index id="1" project_snapshot_id="1" snapshot_id="2" hash="bb" index_in_file="0" start_line="0"
+ <duplications_index id="1"
+ project_snapshot_id="1"
+ snapshot_id="2"
+ component_uuid="uuid_1"
+ hash="bb"
+ index_in_file="0"
+ start_line="0"
end_line="0"/>
<!-- Last snapshot of another project -->
<!-- bar-last -->
- <duplications_index id="2" project_snapshot_id="3" snapshot_id="4" hash="aa" index_in_file="0" start_line="1"
+ <duplications_index id="2"
+ project_snapshot_id="3"
+ snapshot_id="4"
+ component_uuid="uuid_2"
+ hash="aa"
+ index_in_file="0"
+ start_line="1"
end_line="2"/>
<!-- Old snapshot of current project -->
<!-- foo-old -->
- <duplications_index id="3" project_snapshot_id="5" snapshot_id="6" hash="bb" index_in_file="0" start_line="0"
+ <duplications_index id="3"
+ project_snapshot_id="5"
+ snapshot_id="6"
+ component_uuid="uuid_3"
+ hash="bb"
+ index_in_file="0"
+ start_line="0"
end_line="0"/>
<!-- Last snapshot of current project -->
<!-- foo-last -->
- <duplications_index id="4" project_snapshot_id="7" snapshot_id="8" hash="aa" index_in_file="0" start_line="0"
+ <duplications_index id="4"
+ project_snapshot_id="7"
+ snapshot_id="8"
+ component_uuid="uuid_4"
+ hash="aa"
+ index_in_file="0"
+ start_line="0"
end_line="0"/>
<!-- New snapshot of current project -->
<!-- foo -->
- <duplications_index id="5" project_snapshot_id="9" snapshot_id="10" hash="aa" index_in_file="0" start_line="0"
+ <duplications_index id="5"
+ project_snapshot_id="9"
+ snapshot_id="10"
+ component_uuid="uuid_5"
+ hash="aa"
+ index_in_file="0"
+ start_line="0"
end_line="0"/>
<!-- Note that there is two blocks with same hash for current analysis to verify that we use "SELECT DISTINCT", -->
<!-- without "DISTINCT" we will select block from "bar-last" two times. -->
- <duplications_index id="6" project_snapshot_id="9" snapshot_id="10" hash="aa" index_in_file="1" start_line="1"
+ <duplications_index id="6"
+ project_snapshot_id="9"
+ snapshot_id="10"
+ component_uuid="uuid_5"
+ hash="aa"
+ index_in_file="1"
+ start_line="1"
end_line="1"/>
<!-- Last snapshot of project with another language -->
<!-- baz -->
- <duplications_index id="7" project_snapshot_id="1" snapshot_id="11" hash="aa" index_in_file="0" start_line="0"
+ <duplications_index id="7"
+ project_snapshot_id="1"
+ snapshot_id="11"
+ component_uuid="uuid_6"
+ hash="aa"
+ index_in_file="0"
+ start_line="0"
end_line="0"/>
</dataset>
alert_status="[null]" description="[null]" measure_data="[null]"/>
<events id="1" name="Version 1.0" component_uuid="1" snapshot_id="1" category="VERSION" description="[null]"
event_date="1228222680000" created_at="1228222680000" event_data="[null]"/>
- <duplications_index id="1" project_snapshot_id="1" snapshot_id="1" hash="bb" index_in_file="0" start_line="0"
+ <duplications_index id="1"
+ project_snapshot_id="1"
+ component_uuid="uuid_1"
+ snapshot_id="1"
+ hash="bb"
+ index_in_file="0"
+ start_line="0"
end_line="0"/>
</dataset>
alert_status="[null]" description="[null]" measure_data="[null]"/>
<events id="1" name="Version 1.0" component_uuid="1" snapshot_id="1" category="VERSION" description="[null]"
event_date="1228222680000" created_at="1228222680000" event_data="[null]"/>
- <duplications_index id="1" project_snapshot_id="1" snapshot_id="1" hash="bb" index_in_file="0" start_line="0"
+ <duplications_index id="1"
+ project_snapshot_id="1"
+ snapshot_id="1"
+ component_uuid="uuid_1"
+ hash="bb"
+ index_in_file="0"
+ start_line="0"
end_line="0"/>
alert_status="[null]" description="[null]" measure_data="[null]"/>
<events id="2" name="Version 1.0" component_uuid="5" snapshot_id="5" category="VERSION" description="[null]"
event_date="1228222680000" created_at="1228222680000" event_data="[null]"/>
- <duplications_index id="2" project_snapshot_id="5" snapshot_id="5" hash="bb" index_in_file="0" start_line="0"
+ <duplications_index id="2"
+ project_snapshot_id="5"
+ snapshot_id="5"
+ component_uuid="uuid_5"
+ hash="bb"
+ index_in_file="0"
+ start_line="0"
end_line="0"/>
created_at="1228222680000"
event_data="[null]"/>
- <duplications_index id="2" project_snapshot_id="2" snapshot_id="2"
- hash="bb" index_in_file="0" start_line="0" end_line="0"/>
+ <duplications_index id="2"
+ project_snapshot_id="2"
+ snapshot_id="2"
+ component_uuid="uuid_2"
+ hash="bb"
+ index_in_file="0"
+ start_line="0"
+ end_line="0"/>
</dataset>
created_at="1228222680000"
event_data="[null]"/>
- <duplications_index id="1" project_snapshot_id="1" snapshot_id="1"
- hash="bb" index_in_file="0" start_line="0" end_line="0"/>
+ <duplications_index id="1"
+ project_snapshot_id="1"
+ snapshot_id="1"
+ component_uuid="uuid_1"
+ hash="bb"
+ index_in_file="0"
+ start_line="0"
+ end_line="0"/>
<!-- The following is not purged but is kept for DBUnit -->
created_at="1228222680000"
event_data="[null]"/>
- <duplications_index id="2" project_snapshot_id="2" snapshot_id="2"
- hash="bb" index_in_file="0" start_line="0" end_line="0"/>
+ <duplications_index id="2"
+ project_snapshot_id="2"
+ snapshot_id="2"
+ component_uuid="uuid_2"
+ hash="bb"
+ index_in_file="0"
+ start_line="0"
+ end_line="0"/>
</dataset>