aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvgeny Mandrikov <mandrikov@gmail.com>2011-09-07 16:25:05 +0400
committerEvgeny Mandrikov <mandrikov@gmail.com>2011-09-07 17:52:49 +0400
commit092ad0bbc8f0cd0ffc200b825cc6c1525150595c (patch)
treecb5e4b7590be78ff94bab7d19d730ac24bf52891
parent13d5c77e69b68e74206ea9ad5fbd4920e058e9c0 (diff)
downloadsonarqube-092ad0bbc8f0cd0ffc200b825cc6c1525150595c.tar.gz
sonarqube-092ad0bbc8f0cd0ffc200b825cc6c1525150595c.zip
SONAR-1091 CPD over different projects
* Fix SQL for Oracle and Derby. * Rename table clone_blocks to duplications_index. * The use of "sonar.branch" should deactivate detection of cross-project duplications. * Show info about used engine. * Set size of block - 10.
-rw-r--r--plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/CpdEngine.java11
-rw-r--r--plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/CpdSensor.java5
-rw-r--r--plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/PmdEngine.java4
-rw-r--r--plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/SonarEngine.java21
-rw-r--r--plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/index/DbDuplicationsIndex.java (renamed from plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/index/DbCloneIndex.java)17
-rw-r--r--plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/index/SonarDuplicationsIndex.java (renamed from plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/index/SonarCloneIndex.java)8
-rw-r--r--plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/index/DbDuplicationsIndexTest.java (renamed from plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/index/DbCloneIndexTest.java)10
-rw-r--r--plugins/sonar-cpd-plugin/src/test/resources/org/sonar/plugins/cpd/index/DbDuplicationsIndexTest/shouldGetByHash.xml (renamed from plugins/sonar-cpd-plugin/src/test/resources/org/sonar/plugins/cpd/index/DbCloneIndexTest/shouldGetByHash.xml)10
-rw-r--r--plugins/sonar-cpd-plugin/src/test/resources/org/sonar/plugins/cpd/index/DbDuplicationsIndexTest/shouldInsert-result.xml (renamed from plugins/sonar-cpd-plugin/src/test/resources/org/sonar/plugins/cpd/index/DbCloneIndexTest/shouldInsert-result.xml)2
-rw-r--r--plugins/sonar-cpd-plugin/src/test/resources/org/sonar/plugins/cpd/index/DbDuplicationsIndexTest/shouldInsert.xml (renamed from plugins/sonar-cpd-plugin/src/test/resources/org/sonar/plugins/cpd/index/DbCloneIndexTest/shouldInsert.xml)0
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/api/PurgeUtils.java21
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/api/PurgeUtilsTest/purgeSnapshots-result.xml4
-rw-r--r--plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/api/PurgeUtilsTest/purgeSnapshots.xml4
-rw-r--r--sonar-core/src/main/java/org/sonar/jpa/entity/DuplicationBlock.java (renamed from sonar-core/src/main/java/org/sonar/jpa/entity/CloneBlock.java)8
-rw-r--r--sonar-core/src/main/resources/META-INF/persistence.xml4
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/db/migrate/217_create_duplications_index.rb (renamed from sonar-server/src/main/webapp/WEB-INF/db/migrate/217_create_clone_blocks.rb)10
16 files changed, 80 insertions, 59 deletions
diff --git a/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/CpdEngine.java b/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/CpdEngine.java
index 2f8a5883f29..fd1be7bf22e 100644
--- a/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/CpdEngine.java
+++ b/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/CpdEngine.java
@@ -24,10 +24,15 @@ import org.sonar.api.batch.SensorContext;
import org.sonar.api.resources.Language;
import org.sonar.api.resources.Project;
-public interface CpdEngine extends BatchExtension {
+public abstract class CpdEngine implements BatchExtension {
- boolean isLanguageSupported(Language language);
+ abstract boolean isLanguageSupported(Language language);
- void analyse(Project project, SensorContext context);
+ abstract void analyse(Project project, SensorContext context);
+
+ @Override
+ public String toString() {
+ return getClass().getSimpleName();
+ }
}
diff --git a/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/CpdSensor.java b/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/CpdSensor.java
index 522d6db766c..a4aacb6c53c 100644
--- a/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/CpdSensor.java
+++ b/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/CpdSensor.java
@@ -25,6 +25,7 @@ import org.slf4j.LoggerFactory;
import org.sonar.api.batch.Sensor;
import org.sonar.api.batch.SensorContext;
import org.sonar.api.resources.Project;
+import org.sonar.api.utils.Logs;
public class CpdSensor implements Sensor {
@@ -75,7 +76,9 @@ public class CpdSensor implements Sensor {
}
public void analyse(Project project, SensorContext context) {
- getEngine(project).analyse(project, context);
+ CpdEngine engine = getEngine(project);
+ Logs.INFO.info("{} would be used", engine);
+ engine.analyse(project, context);
}
@Override
diff --git a/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/PmdEngine.java b/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/PmdEngine.java
index 8bad74bebe4..48584a83d65 100644
--- a/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/PmdEngine.java
+++ b/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/PmdEngine.java
@@ -33,7 +33,7 @@ import org.sonar.api.resources.Language;
import org.sonar.api.resources.Project;
import org.sonar.duplications.cpd.CPD;
-public class PmdEngine implements CpdEngine {
+public class PmdEngine extends CpdEngine {
private CpdMapping[] mappings;
@@ -41,6 +41,7 @@ public class PmdEngine implements CpdEngine {
this.mappings = mappings;
}
+ @Override
public boolean isLanguageSupported(Language language) {
return getMapping(language) != null;
}
@@ -54,6 +55,7 @@ public class PmdEngine implements CpdEngine {
return null;
}
+ @Override
public void analyse(Project project, SensorContext context) {
CpdMapping mapping = getMapping(project.getLanguage());
CPD cpd = executeCPD(project, mapping, project.getFileSystem().getSourceCharset());
diff --git a/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/SonarEngine.java b/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/SonarEngine.java
index 46d876a6dc5..a81c754ba97 100644
--- a/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/SonarEngine.java
+++ b/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/SonarEngine.java
@@ -28,6 +28,8 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
+import org.apache.commons.lang.StringUtils;
+import org.sonar.api.CoreProperties;
import org.sonar.api.batch.SensorContext;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.ResourceModel;
@@ -52,12 +54,12 @@ import org.sonar.duplications.statement.Statement;
import org.sonar.duplications.statement.StatementChunker;
import org.sonar.duplications.token.TokenChunker;
import org.sonar.duplications.token.TokenQueue;
-import org.sonar.plugins.cpd.index.DbCloneIndex;
-import org.sonar.plugins.cpd.index.SonarCloneIndex;
+import org.sonar.plugins.cpd.index.DbDuplicationsIndex;
+import org.sonar.plugins.cpd.index.SonarDuplicationsIndex;
-public class SonarEngine implements CpdEngine {
+public class SonarEngine extends CpdEngine {
- private static final int BLOCK_SIZE = 13;
+ private static final int BLOCK_SIZE = 10;
private final ResourcePersister resourcePersister;
private final DatabaseSession dbSession;
@@ -74,6 +76,7 @@ public class SonarEngine implements CpdEngine {
this.dbSession = dbSession;
}
+ @Override
public boolean isLanguageSupported(Language language) {
return Java.INSTANCE.equals(language);
}
@@ -83,7 +86,8 @@ public class SonarEngine implements CpdEngine {
*/
private boolean isCrossProject(Project project) {
return project.getConfiguration().getBoolean("sonar.cpd.cross_project", false)
- && resourcePersister != null && dbSession != null;
+ && resourcePersister != null && dbSession != null
+ && StringUtils.isBlank(project.getConfiguration().getString(CoreProperties.PROJECT_BRANCH_PROPERTY));
}
private static String getFullKey(Project project, Resource resource) {
@@ -94,6 +98,7 @@ public class SonarEngine implements CpdEngine {
.toString();
}
+ @Override
public void analyse(Project project, SensorContext context) {
List<InputFile> inputFiles = project.getFileSystem().mainFiles(project.getLanguageKey());
if (inputFiles.isEmpty()) {
@@ -101,13 +106,13 @@ public class SonarEngine implements CpdEngine {
}
// Create index
- final SonarCloneIndex index;
+ final SonarDuplicationsIndex index;
if (isCrossProject(project)) {
Logs.INFO.info("Cross-project analysis enabled");
- index = new SonarCloneIndex(new DbCloneIndex(dbSession, resourcePersister, project));
+ index = new SonarDuplicationsIndex(new DbDuplicationsIndex(dbSession, resourcePersister, project));
} else {
Logs.INFO.info("Cross-project analysis disabled");
- index = new SonarCloneIndex();
+ index = new SonarDuplicationsIndex();
}
TokenChunker tokenChunker = JavaTokenProducer.build();
diff --git a/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/index/DbCloneIndex.java b/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/index/DbDuplicationsIndex.java
index 8cbaff39900..a0a5529483b 100644
--- a/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/index/DbCloneIndex.java
+++ b/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/index/DbDuplicationsIndex.java
@@ -35,12 +35,12 @@ import org.sonar.api.resources.Resource;
import org.sonar.batch.index.ResourcePersister;
import org.sonar.duplications.block.Block;
import org.sonar.duplications.block.ByteArray;
-import org.sonar.jpa.entity.CloneBlock;
+import org.sonar.jpa.entity.DuplicationBlock;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
-public class DbCloneIndex {
+public class DbDuplicationsIndex {
private final Map<ByteArray, Collection<Block>> cache = Maps.newHashMap();
@@ -49,7 +49,7 @@ public class DbCloneIndex {
private final int currentProjectSnapshotId;
private final Integer lastSnapshotId;
- public DbCloneIndex(DatabaseSession session, ResourcePersister resourcePersister, Project currentProject) {
+ public DbDuplicationsIndex(DatabaseSession session, ResourcePersister resourcePersister, Project currentProject) {
this.session = session;
this.resourcePersister = resourcePersister;
Snapshot currentSnapshot = resourcePersister.getSnapshotOrFail(currentProject);
@@ -61,7 +61,7 @@ public class DbCloneIndex {
/**
* For tests.
*/
- DbCloneIndex(DatabaseSession session, ResourcePersister resourcePersister, Integer currentProjectSnapshotId, Integer prevSnapshotId) {
+ DbDuplicationsIndex(DatabaseSession session, ResourcePersister resourcePersister, Integer currentProjectSnapshotId, Integer prevSnapshotId) {
this.session = session;
this.resourcePersister = resourcePersister;
this.currentProjectSnapshotId = currentProjectSnapshotId;
@@ -77,18 +77,19 @@ public class DbCloneIndex {
// Order of columns is important - see code below!
String sql = "SELECT to_blocks.hash, resource.kee, to_blocks.index_in_file, to_blocks.start_line, to_blocks.end_line" +
- " FROM clone_blocks AS to_blocks, clone_blocks AS from_blocks, snapshots AS snapshot, projects AS resource" +
+ " FROM duplications_index to_blocks, duplications_index from_blocks, snapshots snapshot, projects resource" +
" WHERE from_blocks.snapshot_id = :resource_snapshot_id" +
" AND to_blocks.hash = from_blocks.hash" +
" AND to_blocks.snapshot_id = snapshot.id" +
- " AND snapshot.islast = true" +
+ " AND snapshot.islast = :is_last" +
" AND snapshot.project_id = resource.id";
if (lastSnapshotId != null) {
// Filter for blocks from previous snapshot of current project
sql += " AND to_blocks.project_snapshot_id != :last_project_snapshot_id";
}
Query query = session.getEntityManager().createNativeQuery(sql)
- .setParameter("resource_snapshot_id", resourceSnapshotId);
+ .setParameter("resource_snapshot_id", resourceSnapshotId)
+ .setParameter("is_last", Boolean.TRUE);
if (lastSnapshotId != null) {
query.setParameter("last_project_snapshot_id", lastSnapshotId);
}
@@ -128,7 +129,7 @@ public class DbCloneIndex {
public void insert(Resource resource, Collection<Block> blocks) {
int resourceSnapshotId = getSnapshotIdFor(resource);
for (Block block : blocks) {
- CloneBlock dbBlock = new CloneBlock(
+ DuplicationBlock dbBlock = new DuplicationBlock(
currentProjectSnapshotId,
resourceSnapshotId,
block.getBlockHash().toString(),
diff --git a/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/index/SonarCloneIndex.java b/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/index/SonarDuplicationsIndex.java
index f5bd39542c1..f5ddf5bd579 100644
--- a/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/index/SonarCloneIndex.java
+++ b/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/index/SonarDuplicationsIndex.java
@@ -31,16 +31,16 @@ import org.sonar.duplications.index.PackedMemoryCloneIndex;
import com.google.common.collect.Lists;
-public class SonarCloneIndex extends AbstractCloneIndex {
+public class SonarDuplicationsIndex extends AbstractCloneIndex {
private final CloneIndex mem = new PackedMemoryCloneIndex();
- private final DbCloneIndex db;
+ private final DbDuplicationsIndex db;
- public SonarCloneIndex() {
+ public SonarDuplicationsIndex() {
this(null);
}
- public SonarCloneIndex(DbCloneIndex db) {
+ public SonarDuplicationsIndex(DbDuplicationsIndex db) {
this.db = db;
}
diff --git a/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/index/DbCloneIndexTest.java b/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/index/DbDuplicationsIndexTest.java
index 5823c9f6044..fedf032033c 100644
--- a/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/index/DbCloneIndexTest.java
+++ b/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/index/DbDuplicationsIndexTest.java
@@ -35,14 +35,14 @@ import org.sonar.duplications.block.Block;
import org.sonar.duplications.block.ByteArray;
import org.sonar.jpa.test.AbstractDbUnitTestCase;
-public class DbCloneIndexTest extends AbstractDbUnitTestCase {
+public class DbDuplicationsIndexTest extends AbstractDbUnitTestCase {
- private DbCloneIndex index;
+ private DbDuplicationsIndex index;
@Test
public void shouldGetByHash() {
Resource resource = new JavaFile("foo");
- index = spy(new DbCloneIndex(getSession(), null, 9, 7));
+ index = spy(new DbDuplicationsIndex(getSession(), null, 9, 7));
doReturn(10).when(index).getSnapshotIdFor(resource);
setupData("shouldGetByHash");
@@ -63,13 +63,13 @@ public class DbCloneIndexTest extends AbstractDbUnitTestCase {
@Test
public void shouldInsert() {
Resource resource = new JavaFile("foo");
- index = spy(new DbCloneIndex(getSession(), null, 1, null));
+ index = spy(new DbDuplicationsIndex(getSession(), null, 1, null));
doReturn(2).when(index).getSnapshotIdFor(resource);
setupData("shouldInsert");
index.insert(resource, Arrays.asList(new Block("foo", new ByteArray("bb"), 0, 1, 2)));
- checkTables("shouldInsert", "clone_blocks");
+ checkTables("shouldInsert", "duplications_index");
}
}
diff --git a/plugins/sonar-cpd-plugin/src/test/resources/org/sonar/plugins/cpd/index/DbCloneIndexTest/shouldGetByHash.xml b/plugins/sonar-cpd-plugin/src/test/resources/org/sonar/plugins/cpd/index/DbDuplicationsIndexTest/shouldGetByHash.xml
index 1dab2d464cf..ecef7dd2739 100644
--- a/plugins/sonar-cpd-plugin/src/test/resources/org/sonar/plugins/cpd/index/DbCloneIndexTest/shouldGetByHash.xml
+++ b/plugins/sonar-cpd-plugin/src/test/resources/org/sonar/plugins/cpd/index/DbDuplicationsIndexTest/shouldGetByHash.xml
@@ -22,22 +22,22 @@
<!-- Old snapshot of another project -->
<!-- bar-old -->
- <clone_blocks id="1" project_snapshot_id="1" snapshot_id="2" hash="bb" index_in_file="0" start_line="0" end_line="0" />
+ <duplications_index id="1" project_snapshot_id="1" snapshot_id="2" hash="bb" index_in_file="0" start_line="0" end_line="0" />
<!-- Last snapshot of another project -->
<!-- bar-last -->
- <clone_blocks id="2" project_snapshot_id="3" snapshot_id="4" hash="aa" index_in_file="0" start_line="1" end_line="2" />
+ <duplications_index id="2" project_snapshot_id="3" snapshot_id="4" hash="aa" index_in_file="0" start_line="1" end_line="2" />
<!-- Old snapshot of current project -->
<!-- foo-old -->
- <clone_blocks id="3" project_snapshot_id="5" snapshot_id="6" hash="bb" index_in_file="0" start_line="0" end_line="0" />
+ <duplications_index id="3" project_snapshot_id="5" snapshot_id="6" hash="bb" index_in_file="0" start_line="0" end_line="0" />
<!-- Last snapshot of current project -->
<!-- foo-last -->
- <clone_blocks id="4" project_snapshot_id="7" snapshot_id="8" hash="bb" index_in_file="0" start_line="0" end_line="0" />
+ <duplications_index id="4" project_snapshot_id="7" snapshot_id="8" hash="bb" index_in_file="0" start_line="0" end_line="0" />
<!-- New snapshot of current project -->
<!-- foo -->
- <clone_blocks id="5" project_snapshot_id="9" snapshot_id="10" hash="aa" index_in_file="0" start_line="0" end_line="0" />
+ <duplications_index id="5" project_snapshot_id="9" snapshot_id="10" hash="aa" index_in_file="0" start_line="0" end_line="0" />
</dataset>
diff --git a/plugins/sonar-cpd-plugin/src/test/resources/org/sonar/plugins/cpd/index/DbCloneIndexTest/shouldInsert-result.xml b/plugins/sonar-cpd-plugin/src/test/resources/org/sonar/plugins/cpd/index/DbDuplicationsIndexTest/shouldInsert-result.xml
index e3e709ffc45..5848ecb5723 100644
--- a/plugins/sonar-cpd-plugin/src/test/resources/org/sonar/plugins/cpd/index/DbCloneIndexTest/shouldInsert-result.xml
+++ b/plugins/sonar-cpd-plugin/src/test/resources/org/sonar/plugins/cpd/index/DbDuplicationsIndexTest/shouldInsert-result.xml
@@ -4,6 +4,6 @@
<snapshots id="2" status="U" islast="false" project_id="1" />
<projects id="1" kee="foo" enabled="true" scope="FIL" qualifier="CLA" />
- <clone_blocks id="1" project_snapshot_id="1" snapshot_id="2" hash="bb" index_in_file="0" start_line="1" end_line="2" />
+ <duplications_index id="1" project_snapshot_id="1" snapshot_id="2" hash="bb" index_in_file="0" start_line="1" end_line="2" />
</dataset>
diff --git a/plugins/sonar-cpd-plugin/src/test/resources/org/sonar/plugins/cpd/index/DbCloneIndexTest/shouldInsert.xml b/plugins/sonar-cpd-plugin/src/test/resources/org/sonar/plugins/cpd/index/DbDuplicationsIndexTest/shouldInsert.xml
index 940281a0599..940281a0599 100644
--- a/plugins/sonar-cpd-plugin/src/test/resources/org/sonar/plugins/cpd/index/DbCloneIndexTest/shouldInsert.xml
+++ b/plugins/sonar-cpd-plugin/src/test/resources/org/sonar/plugins/cpd/index/DbDuplicationsIndexTest/shouldInsert.xml
diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/api/PurgeUtils.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/api/PurgeUtils.java
index 8a7451b9d80..c18a68dea7b 100644
--- a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/api/PurgeUtils.java
+++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/api/PurgeUtils.java
@@ -19,15 +19,20 @@
*/
package org.sonar.plugins.dbcleaner.api;
+import java.util.List;
+
+import javax.persistence.Query;
+
import org.apache.commons.configuration.Configuration;
import org.sonar.api.database.DatabaseSession;
-import org.sonar.api.database.model.*;
+import org.sonar.api.database.model.MeasureData;
+import org.sonar.api.database.model.MeasureModel;
+import org.sonar.api.database.model.RuleFailureModel;
+import org.sonar.api.database.model.Snapshot;
+import org.sonar.api.database.model.SnapshotSource;
import org.sonar.api.design.DependencyDto;
import org.sonar.api.utils.TimeProfiler;
-import org.sonar.jpa.entity.CloneBlock;
-
-import javax.persistence.Query;
-import java.util.List;
+import org.sonar.jpa.entity.DuplicationBlock;
/**
* @since 2.5
@@ -59,7 +64,7 @@ public final class PurgeUtils {
deleteSources(session, snapshotIds);
deleteViolations(session, snapshotIds);
deleteDependencies(session, snapshotIds);
- deleteCloneBlocks(session, snapshotIds);
+ deleteDuplicationBlocks(session, snapshotIds);
deleteSnapshots(session, snapshotIds);
}
@@ -101,8 +106,8 @@ public final class PurgeUtils {
/**
* @since 2.11
*/
- private static void deleteCloneBlocks(DatabaseSession session, List<Integer> snapshotIds) {
- executeQuery(session, "delete clone blocks", snapshotIds, "delete from " + CloneBlock.class.getSimpleName() + " e where e.snapshotId in (:ids)");
+ private static void deleteDuplicationBlocks(DatabaseSession session, List<Integer> snapshotIds) {
+ executeQuery(session, "delete duplication blocks", snapshotIds, "delete from " + DuplicationBlock.class.getSimpleName() + " e where e.snapshotId in (:ids)");
}
/**
diff --git a/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/api/PurgeUtilsTest/purgeSnapshots-result.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/api/PurgeUtilsTest/purgeSnapshots-result.xml
index 23847972836..f27fa810e06 100644
--- a/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/api/PurgeUtilsTest/purgeSnapshots-result.xml
+++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/api/PurgeUtilsTest/purgeSnapshots-result.xml
@@ -108,7 +108,7 @@
<!--parent_dependency_id="[null]" project_snapshot_id="1"-->
<!--dep_usage="INHERITS" dep_weight="1" from_scope="FIL" to_scope="FIL"/>-->
- <!--<clone_blocks id="1" project_snapshot_id="1" snapshot_id="3" hash="bb" index_in_file="0" start_line="0" end_line="0" />-->
- <!--<clone_blocks id="2" project_snapshot_id="1" snapshot_id="4" hash="bb" index_in_file="0" start_line="0" end_line="0" />-->
+ <!--<duplications_index id="1" project_snapshot_id="1" snapshot_id="3" hash="bb" index_in_file="0" start_line="0" end_line="0" />-->
+ <!--<duplications_index id="2" project_snapshot_id="1" snapshot_id="4" hash="bb" index_in_file="0" start_line="0" end_line="0" />-->
</dataset>
diff --git a/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/api/PurgeUtilsTest/purgeSnapshots.xml b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/api/PurgeUtilsTest/purgeSnapshots.xml
index 6f2a149c513..4627eaaf748 100644
--- a/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/api/PurgeUtilsTest/purgeSnapshots.xml
+++ b/plugins/sonar-dbcleaner-plugin/src/test/resources/org/sonar/plugins/dbcleaner/api/PurgeUtilsTest/purgeSnapshots.xml
@@ -108,7 +108,7 @@
parent_dependency_id="[null]" project_snapshot_id="1"
dep_usage="INHERITS" dep_weight="1" from_scope="FIL" to_scope="FIL" />
- <clone_blocks id="1" project_snapshot_id="1" snapshot_id="3" hash="bb" index_in_file="0" start_line="0" end_line="0" />
- <clone_blocks id="2" project_snapshot_id="1" snapshot_id="4" hash="bb" index_in_file="0" start_line="0" end_line="0" />
+ <duplications_index id="1" project_snapshot_id="1" snapshot_id="3" hash="bb" index_in_file="0" start_line="0" end_line="0" />
+ <duplications_index id="2" project_snapshot_id="1" snapshot_id="4" hash="bb" index_in_file="0" start_line="0" end_line="0" />
</dataset>
diff --git a/sonar-core/src/main/java/org/sonar/jpa/entity/CloneBlock.java b/sonar-core/src/main/java/org/sonar/jpa/entity/DuplicationBlock.java
index 7589a9947dd..4e4ea87e4c7 100644
--- a/sonar-core/src/main/java/org/sonar/jpa/entity/CloneBlock.java
+++ b/sonar-core/src/main/java/org/sonar/jpa/entity/DuplicationBlock.java
@@ -29,8 +29,8 @@ import javax.persistence.Table;
* @since 2.11
*/
@Entity
-@Table(name = "clone_blocks")
-public class CloneBlock {
+@Table(name = "duplications_index")
+public class DuplicationBlock {
public static final int BLOCK_HASH_SIZE = 50;
@@ -57,10 +57,10 @@ public class CloneBlock {
@Column(name = "end_line", updatable = false, nullable = false)
private Integer endLine;
- public CloneBlock() {
+ public DuplicationBlock() {
}
- public CloneBlock(Integer projectSnapshotId, Integer snapshotId, String hash, Integer indexInFile, Integer startLine, Integer endLine) {
+ public DuplicationBlock(Integer projectSnapshotId, Integer snapshotId, String hash, Integer indexInFile, Integer startLine, Integer endLine) {
this.projectSnapshotId = projectSnapshotId;
this.snapshotId = snapshotId;
this.hash = hash;
diff --git a/sonar-core/src/main/resources/META-INF/persistence.xml b/sonar-core/src/main/resources/META-INF/persistence.xml
index ed9f92cc06c..2d427ffec04 100644
--- a/sonar-core/src/main/resources/META-INF/persistence.xml
+++ b/sonar-core/src/main/resources/META-INF/persistence.xml
@@ -36,8 +36,8 @@
<class>org.sonar.api.rules.ActiveRuleParamChange</class>
<class>org.sonar.jpa.entity.Review</class>
<class>org.sonar.jpa.entity.NotificationQueueElement</class>
- <class>org.sonar.jpa.entity.CloneBlock</class>
-
+ <class>org.sonar.jpa.entity.DuplicationBlock</class>
+
<properties>
<property name="hibernate.current_session_context_class" value="thread"/>
<property name="hibernate.connection.release_mode" value="after_transaction"/>
diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/217_create_clone_blocks.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/217_create_duplications_index.rb
index 4ea9a8343d1..18ebb0806e6 100644
--- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/217_create_clone_blocks.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/217_create_duplications_index.rb
@@ -21,10 +21,10 @@
#
# Sonar 2.11
#
-class CreateCloneBlocks < ActiveRecord::Migration
+class CreateDuplicationsIndex < ActiveRecord::Migration
def self.up
- create_table :clone_blocks do |t|
+ create_table :duplications_index do |t|
t.column :project_snapshot_id, :integer, :null => false
t.column :snapshot_id, :integer, :null => false
t.column :hash, :string, :null => false, :limit => 50
@@ -33,9 +33,9 @@ class CreateCloneBlocks < ActiveRecord::Migration
t.column :end_line, :integer, :null => false
end
- add_index :clone_blocks, :project_snapshot_id, :name => 'clone_blocks_project_snapshot'
- add_index :clone_blocks, :snapshot_id, :name => 'clone_blocks_snapshot'
- add_index :clone_blocks, :hash, :name => 'clone_blocks_hash'
+ add_index :duplications_index, :project_snapshot_id, :name => 'duplications_index_psid'
+ add_index :duplications_index, :snapshot_id, :name => 'duplications_index_sid'
+ add_index :duplications_index, :hash, :name => 'duplications_index_hash'
end
end