From 092ad0bbc8f0cd0ffc200b825cc6c1525150595c Mon Sep 17 00:00:00 2001 From: Evgeny Mandrikov Date: Wed, 7 Sep 2011 16:25:05 +0400 Subject: 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. --- .../main/java/org/sonar/plugins/cpd/CpdEngine.java | 11 +- .../main/java/org/sonar/plugins/cpd/CpdSensor.java | 5 +- .../main/java/org/sonar/plugins/cpd/PmdEngine.java | 4 +- .../java/org/sonar/plugins/cpd/SonarEngine.java | 21 +-- .../org/sonar/plugins/cpd/index/DbCloneIndex.java | 143 -------------------- .../plugins/cpd/index/DbDuplicationsIndex.java | 144 +++++++++++++++++++++ .../sonar/plugins/cpd/index/SonarCloneIndex.java | 81 ------------ .../plugins/cpd/index/SonarDuplicationsIndex.java | 81 ++++++++++++ .../sonar/plugins/cpd/index/DbCloneIndexTest.java | 75 ----------- .../plugins/cpd/index/DbDuplicationsIndexTest.java | 75 +++++++++++ .../cpd/index/DbCloneIndexTest/shouldGetByHash.xml | 43 ------ .../index/DbCloneIndexTest/shouldInsert-result.xml | 9 -- .../cpd/index/DbCloneIndexTest/shouldInsert.xml | 7 - .../DbDuplicationsIndexTest/shouldGetByHash.xml | 43 ++++++ .../shouldInsert-result.xml | 9 ++ .../index/DbDuplicationsIndexTest/shouldInsert.xml | 7 + .../sonar/plugins/dbcleaner/api/PurgeUtils.java | 21 +-- .../api/PurgeUtilsTest/purgeSnapshots-result.xml | 4 +- .../api/PurgeUtilsTest/purgeSnapshots.xml | 4 +- .../main/java/org/sonar/jpa/entity/CloneBlock.java | 100 -------------- .../org/sonar/jpa/entity/DuplicationBlock.java | 100 ++++++++++++++ .../src/main/resources/META-INF/persistence.xml | 4 +- .../WEB-INF/db/migrate/217_create_clone_blocks.rb | 41 ------ .../db/migrate/217_create_duplications_index.rb | 41 ++++++ 24 files changed, 547 insertions(+), 526 deletions(-) delete mode 100644 plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/index/DbCloneIndex.java create mode 100644 plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/index/DbDuplicationsIndex.java delete mode 100644 plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/index/SonarCloneIndex.java create mode 100644 plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/index/SonarDuplicationsIndex.java delete mode 100644 plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/index/DbCloneIndexTest.java create mode 100644 plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/index/DbDuplicationsIndexTest.java delete mode 100644 plugins/sonar-cpd-plugin/src/test/resources/org/sonar/plugins/cpd/index/DbCloneIndexTest/shouldGetByHash.xml delete mode 100644 plugins/sonar-cpd-plugin/src/test/resources/org/sonar/plugins/cpd/index/DbCloneIndexTest/shouldInsert-result.xml delete mode 100644 plugins/sonar-cpd-plugin/src/test/resources/org/sonar/plugins/cpd/index/DbCloneIndexTest/shouldInsert.xml create mode 100644 plugins/sonar-cpd-plugin/src/test/resources/org/sonar/plugins/cpd/index/DbDuplicationsIndexTest/shouldGetByHash.xml create mode 100644 plugins/sonar-cpd-plugin/src/test/resources/org/sonar/plugins/cpd/index/DbDuplicationsIndexTest/shouldInsert-result.xml create mode 100644 plugins/sonar-cpd-plugin/src/test/resources/org/sonar/plugins/cpd/index/DbDuplicationsIndexTest/shouldInsert.xml delete mode 100644 sonar-core/src/main/java/org/sonar/jpa/entity/CloneBlock.java create mode 100644 sonar-core/src/main/java/org/sonar/jpa/entity/DuplicationBlock.java delete mode 100644 sonar-server/src/main/webapp/WEB-INF/db/migrate/217_create_clone_blocks.rb create mode 100644 sonar-server/src/main/webapp/WEB-INF/db/migrate/217_create_duplications_index.rb 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 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/DbCloneIndex.java deleted file mode 100644 index 8cbaff39900..00000000000 --- a/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/index/DbCloneIndex.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2008-2011 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.plugins.cpd.index; - -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -import javax.persistence.Query; - -import org.hibernate.ejb.HibernateQuery; -import org.hibernate.transform.Transformers; -import org.sonar.api.database.DatabaseSession; -import org.sonar.api.database.model.Snapshot; -import org.sonar.api.resources.Project; -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 com.google.common.collect.Lists; -import com.google.common.collect.Maps; - -public class DbCloneIndex { - - private final Map> cache = Maps.newHashMap(); - - private final DatabaseSession session; - private final ResourcePersister resourcePersister; - private final int currentProjectSnapshotId; - private final Integer lastSnapshotId; - - public DbCloneIndex(DatabaseSession session, ResourcePersister resourcePersister, Project currentProject) { - this.session = session; - this.resourcePersister = resourcePersister; - Snapshot currentSnapshot = resourcePersister.getSnapshotOrFail(currentProject); - Snapshot lastSnapshot = resourcePersister.getLastSnapshot(currentSnapshot, false); - this.currentProjectSnapshotId = currentSnapshot.getId(); - this.lastSnapshotId = lastSnapshot == null ? null : lastSnapshot.getId(); - } - - /** - * For tests. - */ - DbCloneIndex(DatabaseSession session, ResourcePersister resourcePersister, Integer currentProjectSnapshotId, Integer prevSnapshotId) { - this.session = session; - this.resourcePersister = resourcePersister; - this.currentProjectSnapshotId = currentProjectSnapshotId; - this.lastSnapshotId = prevSnapshotId; - } - - int getSnapshotIdFor(Resource resource) { - return resourcePersister.getSnapshotOrFail(resource).getId(); - } - - public void prepareCache(Resource resource) { - int resourceSnapshotId = getSnapshotIdFor(resource); - - // 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" + - " 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.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); - if (lastSnapshotId != null) { - query.setParameter("last_project_snapshot_id", lastSnapshotId); - } - // Ugly hack for mapping results of custom SQL query into plain list (MyBatis is coming soon) - ((HibernateQuery) query).getHibernateQuery().setResultTransformer(Transformers.TO_LIST); - List> blocks = query.getResultList(); - - cache.clear(); - for (List dbBlock : blocks) { - String hash = (String) dbBlock.get(0); - String resourceKey = (String) dbBlock.get(1); - int indexInFile = (Integer) dbBlock.get(2); - int startLine = (Integer) dbBlock.get(3); - int endLine = (Integer) dbBlock.get(4); - - Block block = new Block(resourceKey, new ByteArray(hash), indexInFile, startLine, endLine); - - // Group blocks by hash - Collection sameHash = cache.get(block.getBlockHash()); - if (sameHash == null) { - sameHash = Lists.newArrayList(); - cache.put(block.getBlockHash(), sameHash); - } - sameHash.add(block); - } - } - - public Collection getByHash(ByteArray hash) { - Collection result = cache.get(hash); - if (result != null) { - return result; - } else { - return Collections.emptyList(); - } - } - - public void insert(Resource resource, Collection blocks) { - int resourceSnapshotId = getSnapshotIdFor(resource); - for (Block block : blocks) { - CloneBlock dbBlock = new CloneBlock( - currentProjectSnapshotId, - resourceSnapshotId, - block.getBlockHash().toString(), - block.getIndexInFile(), - block.getFirstLineNumber(), - block.getLastLineNumber()); - session.save(dbBlock); - } - session.commit(); - } - -} diff --git a/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/index/DbDuplicationsIndex.java b/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/index/DbDuplicationsIndex.java new file mode 100644 index 00000000000..a0a5529483b --- /dev/null +++ b/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/index/DbDuplicationsIndex.java @@ -0,0 +1,144 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2011 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.plugins.cpd.index; + +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import javax.persistence.Query; + +import org.hibernate.ejb.HibernateQuery; +import org.hibernate.transform.Transformers; +import org.sonar.api.database.DatabaseSession; +import org.sonar.api.database.model.Snapshot; +import org.sonar.api.resources.Project; +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.DuplicationBlock; + +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; + +public class DbDuplicationsIndex { + + private final Map> cache = Maps.newHashMap(); + + private final DatabaseSession session; + private final ResourcePersister resourcePersister; + private final int currentProjectSnapshotId; + private final Integer lastSnapshotId; + + public DbDuplicationsIndex(DatabaseSession session, ResourcePersister resourcePersister, Project currentProject) { + this.session = session; + this.resourcePersister = resourcePersister; + Snapshot currentSnapshot = resourcePersister.getSnapshotOrFail(currentProject); + Snapshot lastSnapshot = resourcePersister.getLastSnapshot(currentSnapshot, false); + this.currentProjectSnapshotId = currentSnapshot.getId(); + this.lastSnapshotId = lastSnapshot == null ? null : lastSnapshot.getId(); + } + + /** + * For tests. + */ + DbDuplicationsIndex(DatabaseSession session, ResourcePersister resourcePersister, Integer currentProjectSnapshotId, Integer prevSnapshotId) { + this.session = session; + this.resourcePersister = resourcePersister; + this.currentProjectSnapshotId = currentProjectSnapshotId; + this.lastSnapshotId = prevSnapshotId; + } + + int getSnapshotIdFor(Resource resource) { + return resourcePersister.getSnapshotOrFail(resource).getId(); + } + + public void prepareCache(Resource resource) { + int resourceSnapshotId = getSnapshotIdFor(resource); + + // 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 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 = :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("is_last", Boolean.TRUE); + if (lastSnapshotId != null) { + query.setParameter("last_project_snapshot_id", lastSnapshotId); + } + // Ugly hack for mapping results of custom SQL query into plain list (MyBatis is coming soon) + ((HibernateQuery) query).getHibernateQuery().setResultTransformer(Transformers.TO_LIST); + List> blocks = query.getResultList(); + + cache.clear(); + for (List dbBlock : blocks) { + String hash = (String) dbBlock.get(0); + String resourceKey = (String) dbBlock.get(1); + int indexInFile = (Integer) dbBlock.get(2); + int startLine = (Integer) dbBlock.get(3); + int endLine = (Integer) dbBlock.get(4); + + Block block = new Block(resourceKey, new ByteArray(hash), indexInFile, startLine, endLine); + + // Group blocks by hash + Collection sameHash = cache.get(block.getBlockHash()); + if (sameHash == null) { + sameHash = Lists.newArrayList(); + cache.put(block.getBlockHash(), sameHash); + } + sameHash.add(block); + } + } + + public Collection getByHash(ByteArray hash) { + Collection result = cache.get(hash); + if (result != null) { + return result; + } else { + return Collections.emptyList(); + } + } + + public void insert(Resource resource, Collection blocks) { + int resourceSnapshotId = getSnapshotIdFor(resource); + for (Block block : blocks) { + DuplicationBlock dbBlock = new DuplicationBlock( + currentProjectSnapshotId, + resourceSnapshotId, + block.getBlockHash().toString(), + block.getIndexInFile(), + block.getFirstLineNumber(), + block.getLastLineNumber()); + session.save(dbBlock); + } + session.commit(); + } + +} 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/SonarCloneIndex.java deleted file mode 100644 index f5bd39542c1..00000000000 --- a/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/index/SonarCloneIndex.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2008-2011 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.plugins.cpd.index; - -import java.util.Collection; -import java.util.List; - -import org.sonar.api.resources.Resource; -import org.sonar.duplications.block.Block; -import org.sonar.duplications.block.ByteArray; -import org.sonar.duplications.index.AbstractCloneIndex; -import org.sonar.duplications.index.CloneIndex; -import org.sonar.duplications.index.PackedMemoryCloneIndex; - -import com.google.common.collect.Lists; - -public class SonarCloneIndex extends AbstractCloneIndex { - - private final CloneIndex mem = new PackedMemoryCloneIndex(); - private final DbCloneIndex db; - - public SonarCloneIndex() { - this(null); - } - - public SonarCloneIndex(DbCloneIndex db) { - this.db = db; - } - - public void insert(Resource resource, Collection blocks) { - for (Block block : blocks) { - mem.insert(block); - } - if (db != null) { - db.insert(resource, blocks); - } - } - - public Collection getByResource(Resource resource, String resourceKey) { - if (db != null) { - db.prepareCache(resource); - } - return mem.getByResourceId(resourceKey); - } - - public Collection getBySequenceHash(ByteArray hash) { - if (db == null) { - return mem.getBySequenceHash(hash); - } else { - List result = Lists.newArrayList(mem.getBySequenceHash(hash)); - result.addAll(db.getByHash(hash)); - return result; - } - } - - public Collection getByResourceId(String resourceId) { - throw new UnsupportedOperationException(); - } - - public void insert(Block block) { - throw new UnsupportedOperationException(); - } - -} diff --git a/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/index/SonarDuplicationsIndex.java b/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/index/SonarDuplicationsIndex.java new file mode 100644 index 00000000000..f5ddf5bd579 --- /dev/null +++ b/plugins/sonar-cpd-plugin/src/main/java/org/sonar/plugins/cpd/index/SonarDuplicationsIndex.java @@ -0,0 +1,81 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2011 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.plugins.cpd.index; + +import java.util.Collection; +import java.util.List; + +import org.sonar.api.resources.Resource; +import org.sonar.duplications.block.Block; +import org.sonar.duplications.block.ByteArray; +import org.sonar.duplications.index.AbstractCloneIndex; +import org.sonar.duplications.index.CloneIndex; +import org.sonar.duplications.index.PackedMemoryCloneIndex; + +import com.google.common.collect.Lists; + +public class SonarDuplicationsIndex extends AbstractCloneIndex { + + private final CloneIndex mem = new PackedMemoryCloneIndex(); + private final DbDuplicationsIndex db; + + public SonarDuplicationsIndex() { + this(null); + } + + public SonarDuplicationsIndex(DbDuplicationsIndex db) { + this.db = db; + } + + public void insert(Resource resource, Collection blocks) { + for (Block block : blocks) { + mem.insert(block); + } + if (db != null) { + db.insert(resource, blocks); + } + } + + public Collection getByResource(Resource resource, String resourceKey) { + if (db != null) { + db.prepareCache(resource); + } + return mem.getByResourceId(resourceKey); + } + + public Collection getBySequenceHash(ByteArray hash) { + if (db == null) { + return mem.getBySequenceHash(hash); + } else { + List result = Lists.newArrayList(mem.getBySequenceHash(hash)); + result.addAll(db.getByHash(hash)); + return result; + } + } + + public Collection getByResourceId(String resourceId) { + throw new UnsupportedOperationException(); + } + + public void insert(Block block) { + throw new UnsupportedOperationException(); + } + +} 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/DbCloneIndexTest.java deleted file mode 100644 index 5823c9f6044..00000000000 --- a/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/index/DbCloneIndexTest.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2008-2011 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.plugins.cpd.index; - -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.spy; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Iterator; - -import org.junit.Test; -import org.sonar.api.resources.JavaFile; -import org.sonar.api.resources.Resource; -import org.sonar.duplications.block.Block; -import org.sonar.duplications.block.ByteArray; -import org.sonar.jpa.test.AbstractDbUnitTestCase; - -public class DbCloneIndexTest extends AbstractDbUnitTestCase { - - private DbCloneIndex index; - - @Test - public void shouldGetByHash() { - Resource resource = new JavaFile("foo"); - index = spy(new DbCloneIndex(getSession(), null, 9, 7)); - doReturn(10).when(index).getSnapshotIdFor(resource); - setupData("shouldGetByHash"); - - index.prepareCache(resource); - Collection blocks = index.getByHash(new ByteArray("aa")); - Iterator blocksIterator = blocks.iterator(); - - assertThat(blocks.size(), is(1)); - - Block block = blocksIterator.next(); - assertThat("block resourceId", block.getResourceId(), is("bar-last")); - assertThat("block hash", block.getBlockHash(), is(new ByteArray("aa"))); - assertThat("block index in file", block.getIndexInFile(), is(0)); - assertThat("block start line", block.getFirstLineNumber(), is(1)); - assertThat("block end line", block.getLastLineNumber(), is(2)); - } - - @Test - public void shouldInsert() { - Resource resource = new JavaFile("foo"); - index = spy(new DbCloneIndex(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"); - } - -} diff --git a/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/index/DbDuplicationsIndexTest.java b/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/index/DbDuplicationsIndexTest.java new file mode 100644 index 00000000000..fedf032033c --- /dev/null +++ b/plugins/sonar-cpd-plugin/src/test/java/org/sonar/plugins/cpd/index/DbDuplicationsIndexTest.java @@ -0,0 +1,75 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2011 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.plugins.cpd.index; + +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.spy; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Iterator; + +import org.junit.Test; +import org.sonar.api.resources.JavaFile; +import org.sonar.api.resources.Resource; +import org.sonar.duplications.block.Block; +import org.sonar.duplications.block.ByteArray; +import org.sonar.jpa.test.AbstractDbUnitTestCase; + +public class DbDuplicationsIndexTest extends AbstractDbUnitTestCase { + + private DbDuplicationsIndex index; + + @Test + public void shouldGetByHash() { + Resource resource = new JavaFile("foo"); + index = spy(new DbDuplicationsIndex(getSession(), null, 9, 7)); + doReturn(10).when(index).getSnapshotIdFor(resource); + setupData("shouldGetByHash"); + + index.prepareCache(resource); + Collection blocks = index.getByHash(new ByteArray("aa")); + Iterator blocksIterator = blocks.iterator(); + + assertThat(blocks.size(), is(1)); + + Block block = blocksIterator.next(); + assertThat("block resourceId", block.getResourceId(), is("bar-last")); + assertThat("block hash", block.getBlockHash(), is(new ByteArray("aa"))); + assertThat("block index in file", block.getIndexInFile(), is(0)); + assertThat("block start line", block.getFirstLineNumber(), is(1)); + assertThat("block end line", block.getLastLineNumber(), is(2)); + } + + @Test + public void shouldInsert() { + Resource resource = new JavaFile("foo"); + 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", "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/DbCloneIndexTest/shouldGetByHash.xml deleted file mode 100644 index 1dab2d464cf..00000000000 --- a/plugins/sonar-cpd-plugin/src/test/resources/org/sonar/plugins/cpd/index/DbCloneIndexTest/shouldGetByHash.xml +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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/DbCloneIndexTest/shouldInsert-result.xml deleted file mode 100644 index e3e709ffc45..00000000000 --- a/plugins/sonar-cpd-plugin/src/test/resources/org/sonar/plugins/cpd/index/DbCloneIndexTest/shouldInsert-result.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - 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/DbCloneIndexTest/shouldInsert.xml deleted file mode 100644 index 940281a0599..00000000000 --- a/plugins/sonar-cpd-plugin/src/test/resources/org/sonar/plugins/cpd/index/DbCloneIndexTest/shouldInsert.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/plugins/sonar-cpd-plugin/src/test/resources/org/sonar/plugins/cpd/index/DbDuplicationsIndexTest/shouldGetByHash.xml b/plugins/sonar-cpd-plugin/src/test/resources/org/sonar/plugins/cpd/index/DbDuplicationsIndexTest/shouldGetByHash.xml new file mode 100644 index 00000000000..ecef7dd2739 --- /dev/null +++ b/plugins/sonar-cpd-plugin/src/test/resources/org/sonar/plugins/cpd/index/DbDuplicationsIndexTest/shouldGetByHash.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/sonar-cpd-plugin/src/test/resources/org/sonar/plugins/cpd/index/DbDuplicationsIndexTest/shouldInsert-result.xml b/plugins/sonar-cpd-plugin/src/test/resources/org/sonar/plugins/cpd/index/DbDuplicationsIndexTest/shouldInsert-result.xml new file mode 100644 index 00000000000..5848ecb5723 --- /dev/null +++ b/plugins/sonar-cpd-plugin/src/test/resources/org/sonar/plugins/cpd/index/DbDuplicationsIndexTest/shouldInsert-result.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/plugins/sonar-cpd-plugin/src/test/resources/org/sonar/plugins/cpd/index/DbDuplicationsIndexTest/shouldInsert.xml b/plugins/sonar-cpd-plugin/src/test/resources/org/sonar/plugins/cpd/index/DbDuplicationsIndexTest/shouldInsert.xml new file mode 100644 index 00000000000..940281a0599 --- /dev/null +++ b/plugins/sonar-cpd-plugin/src/test/resources/org/sonar/plugins/cpd/index/DbDuplicationsIndexTest/shouldInsert.xml @@ -0,0 +1,7 @@ + + + + + + + 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 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 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 @@ - - + + 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" /> - - + + diff --git a/sonar-core/src/main/java/org/sonar/jpa/entity/CloneBlock.java b/sonar-core/src/main/java/org/sonar/jpa/entity/CloneBlock.java deleted file mode 100644 index 7589a9947dd..00000000000 --- a/sonar-core/src/main/java/org/sonar/jpa/entity/CloneBlock.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2008-2011 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.jpa.entity; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.Table; - -/** - * @since 2.11 - */ -@Entity -@Table(name = "clone_blocks") -public class CloneBlock { - - public static final int BLOCK_HASH_SIZE = 50; - - @Id - @Column(name = "id") - @GeneratedValue - private Integer id; - - @Column(name = "snapshot_id", updatable = false, nullable = false) - private Integer snapshotId; - - @Column(name = "project_snapshot_id", updatable = false, nullable = false) - private Integer projectSnapshotId; - - @Column(name = "hash", updatable = false, nullable = false, length = BLOCK_HASH_SIZE) - private String hash; - - @Column(name = "index_in_file", updatable = false, nullable = false) - private Integer indexInFile; - - @Column(name = "start_line", updatable = false, nullable = false) - private Integer startLine; - - @Column(name = "end_line", updatable = false, nullable = false) - private Integer endLine; - - public CloneBlock() { - } - - public CloneBlock(Integer projectSnapshotId, Integer snapshotId, String hash, Integer indexInFile, Integer startLine, Integer endLine) { - this.projectSnapshotId = projectSnapshotId; - this.snapshotId = snapshotId; - this.hash = hash; - this.indexInFile = indexInFile; - this.startLine = startLine; - this.endLine = endLine; - } - - public Integer getId() { - return id; - } - - public Integer getSnapshotId() { - return snapshotId; - } - - public Integer getProjectSnapshotId() { - return projectSnapshotId; - } - - public String getHash() { - return hash; - } - - public Integer getIndexInFile() { - return indexInFile; - } - - public Integer getStartLine() { - return startLine; - } - - public Integer getEndLine() { - return endLine; - } - -} diff --git a/sonar-core/src/main/java/org/sonar/jpa/entity/DuplicationBlock.java b/sonar-core/src/main/java/org/sonar/jpa/entity/DuplicationBlock.java new file mode 100644 index 00000000000..4e4ea87e4c7 --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/jpa/entity/DuplicationBlock.java @@ -0,0 +1,100 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2011 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.jpa.entity; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; + +/** + * @since 2.11 + */ +@Entity +@Table(name = "duplications_index") +public class DuplicationBlock { + + public static final int BLOCK_HASH_SIZE = 50; + + @Id + @Column(name = "id") + @GeneratedValue + private Integer id; + + @Column(name = "snapshot_id", updatable = false, nullable = false) + private Integer snapshotId; + + @Column(name = "project_snapshot_id", updatable = false, nullable = false) + private Integer projectSnapshotId; + + @Column(name = "hash", updatable = false, nullable = false, length = BLOCK_HASH_SIZE) + private String hash; + + @Column(name = "index_in_file", updatable = false, nullable = false) + private Integer indexInFile; + + @Column(name = "start_line", updatable = false, nullable = false) + private Integer startLine; + + @Column(name = "end_line", updatable = false, nullable = false) + private Integer endLine; + + public DuplicationBlock() { + } + + public DuplicationBlock(Integer projectSnapshotId, Integer snapshotId, String hash, Integer indexInFile, Integer startLine, Integer endLine) { + this.projectSnapshotId = projectSnapshotId; + this.snapshotId = snapshotId; + this.hash = hash; + this.indexInFile = indexInFile; + this.startLine = startLine; + this.endLine = endLine; + } + + public Integer getId() { + return id; + } + + public Integer getSnapshotId() { + return snapshotId; + } + + public Integer getProjectSnapshotId() { + return projectSnapshotId; + } + + public String getHash() { + return hash; + } + + public Integer getIndexInFile() { + return indexInFile; + } + + public Integer getStartLine() { + return startLine; + } + + public Integer getEndLine() { + return endLine; + } + +} 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 @@ org.sonar.api.rules.ActiveRuleParamChange org.sonar.jpa.entity.Review org.sonar.jpa.entity.NotificationQueueElement - org.sonar.jpa.entity.CloneBlock - + org.sonar.jpa.entity.DuplicationBlock + 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_clone_blocks.rb deleted file mode 100644 index 4ea9a8343d1..00000000000 --- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/217_create_clone_blocks.rb +++ /dev/null @@ -1,41 +0,0 @@ -# -# Sonar, entreprise quality control tool. -# Copyright (C) 2008-2011 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 -# - -# -# Sonar 2.11 -# -class CreateCloneBlocks < ActiveRecord::Migration - - def self.up - create_table :clone_blocks 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 - t.column :index_in_file, :integer, :null => false - t.column :start_line, :integer, :null => false - 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' - end - -end diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/217_create_duplications_index.rb b/sonar-server/src/main/webapp/WEB-INF/db/migrate/217_create_duplications_index.rb new file mode 100644 index 00000000000..18ebb0806e6 --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/217_create_duplications_index.rb @@ -0,0 +1,41 @@ +# +# Sonar, entreprise quality control tool. +# Copyright (C) 2008-2011 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 +# + +# +# Sonar 2.11 +# +class CreateDuplicationsIndex < ActiveRecord::Migration + + def self.up + 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 + t.column :index_in_file, :integer, :null => false + t.column :start_line, :integer, :null => false + t.column :end_line, :integer, :null => false + end + + 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 -- cgit v1.2.3