diff options
author | simonbrandhof <simon.brandhof@gmail.com> | 2011-12-20 21:32:31 +0100 |
---|---|---|
committer | simonbrandhof <simon.brandhof@gmail.com> | 2011-12-20 21:32:31 +0100 |
commit | eae7223b4cdfbce089c4f30a31692ae8130df600 (patch) | |
tree | 936eb6cf351052b30e3bc735a4ea834fa38d712c /sonar-core/src | |
parent | 3abd667d979c3899a4f529a6e0dbf0e0dddb8245 (diff) | |
download | sonarqube-eae7223b4cdfbce089c4f30a31692ae8130df600.tar.gz sonarqube-eae7223b4cdfbce089c4f30a31692ae8130df600.zip |
SONAR-983 resources are indexed during analysis
* Rename the column RESOURCE_INDEX.PROJECT_ID to ROOT_PROJECT_ID
* Increase the size of RESOURCE_INDEX.PROJECT_ID
* Clean resource index from dbcleaner plugin
* Experimental: indexes all the existing resources during upgrade from sonar < 2.13
Diffstat (limited to 'sonar-core/src')
17 files changed, 334 insertions, 81 deletions
diff --git a/sonar-core/src/main/java/org/sonar/persistence/resource/ResourceIndexDto.java b/sonar-core/src/main/java/org/sonar/persistence/resource/ResourceIndexDto.java index 5272747b0ec..e1622a105ba 100644 --- a/sonar-core/src/main/java/org/sonar/persistence/resource/ResourceIndexDto.java +++ b/sonar-core/src/main/java/org/sonar/persistence/resource/ResourceIndexDto.java @@ -25,7 +25,7 @@ public final class ResourceIndexDto { private int position; private int nameSize; private int resourceId; - private int projectId; + private int rootProjectId; public String getKey() { return key; @@ -54,12 +54,12 @@ public final class ResourceIndexDto { return this; } - public int getProjectId() { - return projectId; + public int getRootProjectId() { + return rootProjectId; } - public ResourceIndexDto setProjectId(int i) { - this.projectId = i; + public ResourceIndexDto setRootProjectId(int i) { + this.rootProjectId = i; return this; } diff --git a/sonar-core/src/main/java/org/sonar/persistence/resource/ResourceIndexerDao.java b/sonar-core/src/main/java/org/sonar/persistence/resource/ResourceIndexerDao.java index 485539a2e5a..3cc2900d356 100644 --- a/sonar-core/src/main/java/org/sonar/persistence/resource/ResourceIndexerDao.java +++ b/sonar-core/src/main/java/org/sonar/persistence/resource/ResourceIndexerDao.java @@ -19,14 +19,18 @@ */ package org.sonar.persistence.resource; +import com.google.common.collect.Lists; import org.apache.commons.lang.ObjectUtils; import org.apache.commons.lang.StringUtils; import org.apache.ibatis.session.ExecutorType; import org.apache.ibatis.session.ResultContext; import org.apache.ibatis.session.ResultHandler; import org.apache.ibatis.session.SqlSession; +import org.sonar.persistence.DatabaseUtils; import org.sonar.persistence.MyBatis; +import java.util.List; + public class ResourceIndexerDao { public static final int MINIMUM_KEY_SIZE = 3; @@ -37,68 +41,117 @@ public class ResourceIndexerDao { this.mybatis = mybatis; } - void index(ResourceDto resource, SqlSession session) { - String name = resource.getName(); - if (StringUtils.isBlank(name)) { - return; - } - String normalizedName = normalize(name); - if (normalizedName.length() >= MINIMUM_KEY_SIZE) { - ResourceIndexerMapper mapper = session.getMapper(ResourceIndexerMapper.class); - - Integer rootId; - if (resource.getRootId() != null) { - ResourceDto root = mapper.selectRootId(resource.getRootId()); - if (root != null) { - rootId = (Integer) ObjectUtils.defaultIfNull(root.getRootId(), root.getId()); - } else { - rootId = resource.getRootId(); - } - } else { - rootId = resource.getId(); - } - - ResourceIndexDto dto = new ResourceIndexDto() - .setResourceId(resource.getId()) - .setProjectId(rootId) - .setNameSize(name.length()); - - for (int position = 0; position <= normalizedName.length() - MINIMUM_KEY_SIZE; position++) { - dto.setPosition(position); - dto.setKey(StringUtils.substring(normalizedName, position)); - mapper.insert(dto); - } - - session.commit(); - } - } - - public void index(String resourceName, int resourceId, int projectId) { + public ResourceIndexerDao index(String resourceName, int resourceId, int rootProjectId) { SqlSession sqlSession = mybatis.openSession(); try { - index(new ResourceDto().setId(resourceId).setName(resourceName).setRootId(projectId), sqlSession); + index(new ResourceDto().setId(resourceId).setName(resourceName).setRootId(rootProjectId), sqlSession, true); } finally { sqlSession.close(); } + return this; } - public void index(ResourceIndexerFilter filter) { + public ResourceIndexerDao index(ResourceIndexerFilter filter) { final SqlSession sqlSession = mybatis.openSession(ExecutorType.BATCH); try { sqlSession.select("selectResourcesToIndex", filter, new ResultHandler() { public void handleResult(ResultContext context) { ResourceDto resource = (ResourceDto) context.getResultObject(); - index(resource, sqlSession); + + // The column PROJECTS.ROOT_ID references the module but not the root project in a multi-modules project. + boolean correctRootProjectId = false; + + index(resource, sqlSession, correctRootProjectId); } }); } finally { sqlSession.close(); } + return this; + } + + public ResourceIndexerDao delete(List<Integer> resourceIds) { + final SqlSession sqlSession = mybatis.openSession(); + try { + ResourceIndexerMapper mapper = sqlSession.getMapper(ResourceIndexerMapper.class); + List<List<Integer>> partitionsOfResourceIds = Lists.partition(resourceIds, DatabaseUtils.MAX_IN_ELEMENTS); + for (List<Integer> partitionOfResourceIds : partitionsOfResourceIds) { + if (!partitionOfResourceIds.isEmpty()) { + mapper.deleteByResourceIds(partitionOfResourceIds); + } + } + sqlSession.commit(); + + } finally { + sqlSession.close(); + } + return this; + } + + void index(ResourceDto resource, SqlSession session, boolean correctProjectRootId) { + String name = resource.getName(); + if (StringUtils.isBlank(name) || resource.getId() == null) { + return; + } + + String key = toKey(name); + if (key.length() >= MINIMUM_KEY_SIZE) { + ResourceIndexerMapper mapper = session.getMapper(ResourceIndexerMapper.class); + boolean toBeIndexed = sanitizeIndex(resource, key, mapper); + if (toBeIndexed) { + + ResourceIndexDto dto = new ResourceIndexDto() + .setResourceId(resource.getId()) + .setRootProjectId(loadRootProjectId(resource, mapper, correctProjectRootId)) + .setNameSize(name.length()); + + for (int position = 0; position <= key.length() - MINIMUM_KEY_SIZE; position++) { + dto.setPosition(position); + dto.setKey(StringUtils.substring(key, position)); + mapper.insert(dto); + } + + session.commit(); + } + } + } + + private Integer loadRootProjectId(ResourceDto resource, ResourceIndexerMapper mapper, boolean correctProjectRootId) { + if (correctProjectRootId) { + return resource.getRootId(); + } + Integer rootId; + if (resource.getRootId() != null) { + ResourceDto root = mapper.selectRootId(resource.getRootId()); + if (root != null) { + rootId = (Integer) ObjectUtils.defaultIfNull(root.getRootId(), root.getId()); + } else { + rootId = resource.getRootId(); + } + } else { + rootId = resource.getId(); + } + return rootId; + } + + /** + * Return true if the resource must be indexed, false if the resource is already indexed. + * If the resource is indexed with a different key, then this index is dropped and the + * resource must be indexed again. + */ + private boolean sanitizeIndex(ResourceDto resource, String key, ResourceIndexerMapper mapper) { + ResourceIndexDto masterIndex = mapper.selectMasterIndexByResourceId(resource.getId()); + if (masterIndex != null && !StringUtils.equals(key, masterIndex.getKey())) { + // resource has been renamed -> drop existing indexes + mapper.deleteByResourceId(resource.getId()); + masterIndex = null; + } + return masterIndex == null; } - static String normalize(String input) { + static String toKey(String input) { return StringUtils.lowerCase(input); } } diff --git a/sonar-core/src/main/java/org/sonar/persistence/resource/ResourceIndexerMapper.java b/sonar-core/src/main/java/org/sonar/persistence/resource/ResourceIndexerMapper.java index 209126ce466..beec37e4bfd 100644 --- a/sonar-core/src/main/java/org/sonar/persistence/resource/ResourceIndexerMapper.java +++ b/sonar-core/src/main/java/org/sonar/persistence/resource/ResourceIndexerMapper.java @@ -19,9 +19,19 @@ */ package org.sonar.persistence.resource; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + public interface ResourceIndexerMapper { ResourceDto selectRootId(int id); + ResourceIndexDto selectMasterIndexByResourceId(int resourceId); + + void deleteByResourceId(int resourceId); + + void deleteByResourceIds(@Param("resourceIds") List<Integer> resourceIds); + void insert(ResourceIndexDto dto); } diff --git a/sonar-core/src/main/resources/org/sonar/persistence/resource/ResourceIndexerMapper.xml b/sonar-core/src/main/resources/org/sonar/persistence/resource/ResourceIndexerMapper.xml index 5b0c389d3d1..94ac6e57a95 100644 --- a/sonar-core/src/main/resources/org/sonar/persistence/resource/ResourceIndexerMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/persistence/resource/ResourceIndexerMapper.xml @@ -3,7 +3,7 @@ <mapper namespace="org.sonar.persistence.resource.ResourceIndexerMapper"> - <select id="selectResourcesToIndex" parameterType="map" resultType="resource"> + <select id="selectResourcesToIndex" parameterType="map" resultType="Resource"> select id, root_id as "rootId", name from projects <where> @@ -18,16 +18,33 @@ </where> </select> - <select id="selectRootId" parameterType="int" resultType="resource"> + <select id="selectRootId" parameterType="int" resultType="Resource"> select id, root_id as "rootId" from projects where id=#{id} </select> + <select id="selectMasterIndexByResourceId" parameterType="int" resultType="ResourceIndex"> + select kee as "key", resource_id as "resourceId" + from resource_index + where resource_id=#{id} and position=0 + </select> + + <delete id="deleteByResourceId" parameterType="int"> + delete from resource_index + where resource_id=#{id} + </delete> + + <delete id="deleteByResourceIds" parameterType="map"> + delete from resource_index + where resource_id in + <foreach item="i" index="index" collection="resourceIds" open="(" separator="," close=")">#{i}</foreach> + </delete> + <insert id="insert" parameterType="ResourceIndex" useGeneratedKeys="false"> - insert into resource_index (kee, position, name_size, resource_id, project_id) - values (#{key}, #{position}, #{nameSize}, #{resourceId}, #{projectId}) + insert into resource_index (kee, position, name_size, resource_id, root_project_id) + values (#{key}, #{position}, #{nameSize}, #{resourceId}, #{rootProjectId}) </insert> </mapper> diff --git a/sonar-core/src/main/resources/org/sonar/persistence/schema-derby.ddl b/sonar-core/src/main/resources/org/sonar/persistence/schema-derby.ddl index 02ae63063d2..879e426a883 100644 --- a/sonar-core/src/main/resources/org/sonar/persistence/schema-derby.ddl +++ b/sonar-core/src/main/resources/org/sonar/persistence/schema-derby.ddl @@ -460,11 +460,11 @@ CREATE TABLE "LOADED_TEMPLATES" ( ); CREATE TABLE "RESOURCE_INDEX" ( - "KEE" VARCHAR(100) NOT NULL, + "KEE" VARCHAR(400) NOT NULL, "POSITION" INTEGER NOT NULL, "NAME_SIZE" INTEGER NOT NULL, "RESOURCE_ID" INTEGER NOT NULL, - "PROJECT_ID" INTEGER NOT NULL + "ROOT_PROJECT_ID" INTEGER NOT NULL ); CREATE TABLE "ACTION_PLANS" ( diff --git a/sonar-core/src/test/java/org/sonar/persistence/resource/ResourceIndexerDaoTest.java b/sonar-core/src/test/java/org/sonar/persistence/resource/ResourceIndexerDaoTest.java index 08eeaf64efe..3ee2e28b5a3 100644 --- a/sonar-core/src/test/java/org/sonar/persistence/resource/ResourceIndexerDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/persistence/resource/ResourceIndexerDaoTest.java @@ -23,6 +23,8 @@ import org.junit.Before; import org.junit.Test; import org.sonar.persistence.DaoTestCase; +import java.util.Arrays; + public class ResourceIndexerDaoTest extends DaoTestCase { private static ResourceIndexerDao dao; @@ -33,21 +35,47 @@ public class ResourceIndexerDaoTest extends DaoTestCase { } @Test - public void testIndex() { - setupData("testIndex"); + public void shouldIndexSingleResource() { + setupData("shouldIndexSingleResource"); dao.index("ZipUtils", 10, 8); - checkTables("testIndex", "resource_index"); + checkTables("shouldIndexSingleResource", "resource_index"); } @Test - public void testIndexAll() { - setupData("testIndexAll"); + public void shouldIndexAllResources() { + setupData("shouldIndexAllResources"); dao.index(ResourceIndexerFilter.create()); - checkTables("testIndexAll", "resource_index"); + checkTables("shouldIndexAllResources", "resource_index"); } + @Test + public void shouldIndexMultiModulesProject() { + setupData("shouldIndexMultiModulesProject"); + + dao.index(ResourceIndexerFilter.create()); + + checkTables("shouldIndexMultiModulesProject", "resource_index"); + } + + @Test + public void shouldReindexProjectAfterRenaming() { + setupData("shouldReindexProjectAfterRenaming"); + + dao.index(ResourceIndexerFilter.create()); + + checkTables("shouldReindexProjectAfterRenaming", "resource_index"); + } + + @Test + public void shouldDeleteIndexes() { + setupData("shouldDeleteIndexes"); + + dao.delete(Arrays.asList(3, 4, 5, 6)); + + checkTables("shouldDeleteIndexes", "resource_index"); + } } diff --git a/sonar-core/src/test/resources/org/sonar/persistence/resource/ResourceIndexerDaoTest/shouldDeleteIndexes-result.xml b/sonar-core/src/test/resources/org/sonar/persistence/resource/ResourceIndexerDaoTest/shouldDeleteIndexes-result.xml new file mode 100644 index 00000000000..b863399fac1 --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/persistence/resource/ResourceIndexerDaoTest/shouldDeleteIndexes-result.xml @@ -0,0 +1,8 @@ +<dataset> + + <resource_index kee="struts" position="0" name_size="6" resource_id="1" root_project_id="1"/> + <resource_index kee="truts" position="1" name_size="6" resource_id="1" root_project_id="1"/> + <resource_index kee="ruts" position="2" name_size="6" resource_id="1" root_project_id="1"/> + <resource_index kee="uts" position="3" name_size="6" resource_id="1" root_project_id="1"/> + +</dataset> diff --git a/sonar-core/src/test/resources/org/sonar/persistence/resource/ResourceIndexerDaoTest/shouldDeleteIndexes.xml b/sonar-core/src/test/resources/org/sonar/persistence/resource/ResourceIndexerDaoTest/shouldDeleteIndexes.xml new file mode 100644 index 00000000000..535d54380cb --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/persistence/resource/ResourceIndexerDaoTest/shouldDeleteIndexes.xml @@ -0,0 +1,31 @@ +<dataset> + + <!-- Struts --> + <resource_index kee="struts" position="0" name_size="6" resource_id="1" root_project_id="1"/> + <resource_index kee="truts" position="1" name_size="6" resource_id="1" root_project_id="1"/> + <resource_index kee="ruts" position="2" name_size="6" resource_id="1" root_project_id="1"/> + <resource_index kee="uts" position="3" name_size="6" resource_id="1" root_project_id="1"/> + + <!-- RequestContext --> + <resource_index kee="requestcontext" position="0" name_size="14" resource_id="3" root_project_id="1"/> + <resource_index kee="equestcontext" position="1" name_size="14" resource_id="3" root_project_id="1"/> + <resource_index kee="questcontext" position="2" name_size="14" resource_id="3" root_project_id="1"/> + <resource_index kee="uestcontext" position="3" name_size="14" resource_id="3" root_project_id="1"/> + <resource_index kee="estcontext" position="4" name_size="14" resource_id="3" root_project_id="1"/> + <resource_index kee="stcontext" position="5" name_size="14" resource_id="3" root_project_id="1"/> + <resource_index kee="tcontext" position="6" name_size="14" resource_id="3" root_project_id="1"/> + <resource_index kee="context" position="7" name_size="14" resource_id="3" root_project_id="1"/> + <resource_index kee="ontext" position="8" name_size="14" resource_id="3" root_project_id="1"/> + <resource_index kee="ntext" position="9" name_size="14" resource_id="3" root_project_id="1"/> + <resource_index kee="text" position="10" name_size="14" resource_id="3" root_project_id="1"/> + <resource_index kee="ext" position="11" name_size="14" resource_id="3" root_project_id="1"/> + + <!-- ZipUtils --> + <resource_index kee="ziputils" position="0" name_size="8" resource_id="6" root_project_id="1"/> + <resource_index kee="iputils" position="1" name_size="8" resource_id="6" root_project_id="1"/> + <resource_index kee="putils" position="2" name_size="8" resource_id="6" root_project_id="1"/> + <resource_index kee="utils" position="3" name_size="8" resource_id="6" root_project_id="1"/> + <resource_index kee="tils" position="4" name_size="8" resource_id="6" root_project_id="1"/> + <resource_index kee="ils" position="5" name_size="8" resource_id="6" root_project_id="1"/> + +</dataset> diff --git a/sonar-core/src/test/resources/org/sonar/persistence/resource/ResourceIndexerDaoTest/testIndexAll-result.xml b/sonar-core/src/test/resources/org/sonar/persistence/resource/ResourceIndexerDaoTest/shouldIndexAllResources-result.xml index c1dd1bf9944..814c0cfbaca 100644 --- a/sonar-core/src/test/resources/org/sonar/persistence/resource/ResourceIndexerDaoTest/testIndexAll-result.xml +++ b/sonar-core/src/test/resources/org/sonar/persistence/resource/ResourceIndexerDaoTest/shouldIndexAllResources-result.xml @@ -11,22 +11,22 @@ enabled="[true]" language="java" copy_resource_id="[null]"/> <!-- Struts --> - <resource_index kee="struts" position="0" name_size="6" resource_id="1" project_id="1"/> - <resource_index kee="truts" position="1" name_size="6" resource_id="1" project_id="1"/> - <resource_index kee="ruts" position="2" name_size="6" resource_id="1" project_id="1"/> - <resource_index kee="uts" position="3" name_size="6" resource_id="1" project_id="1"/> + <resource_index kee="struts" position="0" name_size="6" resource_id="1" root_project_id="1"/> + <resource_index kee="truts" position="1" name_size="6" resource_id="1" root_project_id="1"/> + <resource_index kee="ruts" position="2" name_size="6" resource_id="1" root_project_id="1"/> + <resource_index kee="uts" position="3" name_size="6" resource_id="1" root_project_id="1"/> <!-- RequestContext --> - <resource_index kee="requestcontext" position="0" name_size="14" resource_id="3" project_id="1"/> - <resource_index kee="equestcontext" position="1" name_size="14" resource_id="3" project_id="1"/> - <resource_index kee="questcontext" position="2" name_size="14" resource_id="3" project_id="1"/> - <resource_index kee="uestcontext" position="3" name_size="14" resource_id="3" project_id="1"/> - <resource_index kee="estcontext" position="4" name_size="14" resource_id="3" project_id="1"/> - <resource_index kee="stcontext" position="5" name_size="14" resource_id="3" project_id="1"/> - <resource_index kee="tcontext" position="6" name_size="14" resource_id="3" project_id="1"/> - <resource_index kee="context" position="7" name_size="14" resource_id="3" project_id="1"/> - <resource_index kee="ontext" position="8" name_size="14" resource_id="3" project_id="1"/> - <resource_index kee="ntext" position="9" name_size="14" resource_id="3" project_id="1"/> - <resource_index kee="text" position="10" name_size="14" resource_id="3" project_id="1"/> - <resource_index kee="ext" position="11" name_size="14" resource_id="3" project_id="1"/> + <resource_index kee="requestcontext" position="0" name_size="14" resource_id="3" root_project_id="1"/> + <resource_index kee="equestcontext" position="1" name_size="14" resource_id="3" root_project_id="1"/> + <resource_index kee="questcontext" position="2" name_size="14" resource_id="3" root_project_id="1"/> + <resource_index kee="uestcontext" position="3" name_size="14" resource_id="3" root_project_id="1"/> + <resource_index kee="estcontext" position="4" name_size="14" resource_id="3" root_project_id="1"/> + <resource_index kee="stcontext" position="5" name_size="14" resource_id="3" root_project_id="1"/> + <resource_index kee="tcontext" position="6" name_size="14" resource_id="3" root_project_id="1"/> + <resource_index kee="context" position="7" name_size="14" resource_id="3" root_project_id="1"/> + <resource_index kee="ontext" position="8" name_size="14" resource_id="3" root_project_id="1"/> + <resource_index kee="ntext" position="9" name_size="14" resource_id="3" root_project_id="1"/> + <resource_index kee="text" position="10" name_size="14" resource_id="3" root_project_id="1"/> + <resource_index kee="ext" position="11" name_size="14" resource_id="3" root_project_id="1"/> </dataset> diff --git a/sonar-core/src/test/resources/org/sonar/persistence/resource/ResourceIndexerDaoTest/testIndexAll.xml b/sonar-core/src/test/resources/org/sonar/persistence/resource/ResourceIndexerDaoTest/shouldIndexAllResources.xml index f89a5e67f25..f89a5e67f25 100644 --- a/sonar-core/src/test/resources/org/sonar/persistence/resource/ResourceIndexerDaoTest/testIndexAll.xml +++ b/sonar-core/src/test/resources/org/sonar/persistence/resource/ResourceIndexerDaoTest/shouldIndexAllResources.xml diff --git a/sonar-core/src/test/resources/org/sonar/persistence/resource/ResourceIndexerDaoTest/shouldIndexMultiModulesProject-result.xml b/sonar-core/src/test/resources/org/sonar/persistence/resource/ResourceIndexerDaoTest/shouldIndexMultiModulesProject-result.xml new file mode 100644 index 00000000000..e009e317898 --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/persistence/resource/ResourceIndexerDaoTest/shouldIndexMultiModulesProject-result.xml @@ -0,0 +1,52 @@ +<dataset> + + <!-- project "struts" -> module "struts-core" -> file "RequestContext" --> + <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Struts" + root_id="[null]" + description="[null]" + enabled="[true]" language="java" copy_resource_id="[null]"/> + + <projects long_name="[null]" id="2" scope="PRJ" qualifier="BRC" kee="org.struts:struts-core" name="Struts Core" + root_id="1" + description="[null]" + enabled="[true]" language="java" copy_resource_id="[null]"/> + + <projects long_name="org.struts.RequestContext" id="3" scope="FIL" qualifier="CLA" kee="org.struts:struts-core:org.struts.RequestContext" + name="RequestContext" root_id="2" + description="[null]" + enabled="[true]" language="java" copy_resource_id="[null]"/> + + + <!-- The major goal is to test root_project_id --> + + <!-- Struts --> + <resource_index kee="struts" position="0" name_size="6" resource_id="1" root_project_id="1"/> + <resource_index kee="truts" position="1" name_size="6" resource_id="1" root_project_id="1"/> + <resource_index kee="ruts" position="2" name_size="6" resource_id="1" root_project_id="1"/> + <resource_index kee="uts" position="3" name_size="6" resource_id="1" root_project_id="1"/> + + <!-- Struts Core --> + <resource_index kee="struts core" position="0" name_size="11" resource_id="2" root_project_id="1"/> + <resource_index kee="truts core" position="1" name_size="11" resource_id="2" root_project_id="1"/> + <resource_index kee="ruts core" position="2" name_size="11" resource_id="2" root_project_id="1"/> + <resource_index kee="uts core" position="3" name_size="11" resource_id="2" root_project_id="1"/> + <resource_index kee="ts core" position="4" name_size="11" resource_id="2" root_project_id="1"/> + <resource_index kee="s core" position="5" name_size="11" resource_id="2" root_project_id="1"/> + <resource_index kee=" core" position="6" name_size="11" resource_id="2" root_project_id="1"/> + <resource_index kee="core" position="7" name_size="11" resource_id="2" root_project_id="1"/> + <resource_index kee="ore" position="8" name_size="11" resource_id="2" root_project_id="1"/> + + <!-- RequestContext --> + <resource_index kee="requestcontext" position="0" name_size="14" resource_id="3" root_project_id="1"/> + <resource_index kee="equestcontext" position="1" name_size="14" resource_id="3" root_project_id="1"/> + <resource_index kee="questcontext" position="2" name_size="14" resource_id="3" root_project_id="1"/> + <resource_index kee="uestcontext" position="3" name_size="14" resource_id="3" root_project_id="1"/> + <resource_index kee="estcontext" position="4" name_size="14" resource_id="3" root_project_id="1"/> + <resource_index kee="stcontext" position="5" name_size="14" resource_id="3" root_project_id="1"/> + <resource_index kee="tcontext" position="6" name_size="14" resource_id="3" root_project_id="1"/> + <resource_index kee="context" position="7" name_size="14" resource_id="3" root_project_id="1"/> + <resource_index kee="ontext" position="8" name_size="14" resource_id="3" root_project_id="1"/> + <resource_index kee="ntext" position="9" name_size="14" resource_id="3" root_project_id="1"/> + <resource_index kee="text" position="10" name_size="14" resource_id="3" root_project_id="1"/> + <resource_index kee="ext" position="11" name_size="14" resource_id="3" root_project_id="1"/> +</dataset> diff --git a/sonar-core/src/test/resources/org/sonar/persistence/resource/ResourceIndexerDaoTest/shouldIndexMultiModulesProject.xml b/sonar-core/src/test/resources/org/sonar/persistence/resource/ResourceIndexerDaoTest/shouldIndexMultiModulesProject.xml new file mode 100644 index 00000000000..4dabdc5beb8 --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/persistence/resource/ResourceIndexerDaoTest/shouldIndexMultiModulesProject.xml @@ -0,0 +1,19 @@ +<dataset> + + <!-- project "struts" -> module "struts-core" -> file "RequestContext" --> + <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Struts" + root_id="[null]" + description="[null]" + enabled="[true]" language="java" copy_resource_id="[null]"/> + + <projects long_name="[null]" id="2" scope="PRJ" qualifier="BRC" kee="org.struts:struts-core" name="Struts Core" + root_id="1" + description="[null]" + enabled="[true]" language="java" copy_resource_id="[null]"/> + + <projects long_name="org.struts.RequestContext" id="3" scope="FIL" qualifier="CLA" kee="org.struts:struts-core:org.struts.RequestContext" + name="RequestContext" root_id="2" + description="[null]" + enabled="[true]" language="java" copy_resource_id="[null]"/> + +</dataset> diff --git a/sonar-core/src/test/resources/org/sonar/persistence/resource/ResourceIndexerDaoTest/testIndex-result.xml b/sonar-core/src/test/resources/org/sonar/persistence/resource/ResourceIndexerDaoTest/shouldIndexSingleResource-result.xml index 3c1544c8f9a..f0b879c3925 100644 --- a/sonar-core/src/test/resources/org/sonar/persistence/resource/ResourceIndexerDaoTest/testIndex-result.xml +++ b/sonar-core/src/test/resources/org/sonar/persistence/resource/ResourceIndexerDaoTest/shouldIndexSingleResource-result.xml @@ -1,8 +1,8 @@ <dataset> - <resource_index kee="ziputils" position="0" name_size="8" resource_id="10" project_id="8"/> - <resource_index kee="iputils" position="1" name_size="8" resource_id="10" project_id="8"/> - <resource_index kee="putils" position="2" name_size="8" resource_id="10" project_id="8"/> - <resource_index kee="utils" position="3" name_size="8" resource_id="10" project_id="8"/> - <resource_index kee="tils" position="4" name_size="8" resource_id="10" project_id="8"/> - <resource_index kee="ils" position="5" name_size="8" resource_id="10" project_id="8"/> + <resource_index kee="ziputils" position="0" name_size="8" resource_id="10" root_project_id="8"/> + <resource_index kee="iputils" position="1" name_size="8" resource_id="10" root_project_id="8"/> + <resource_index kee="putils" position="2" name_size="8" resource_id="10" root_project_id="8"/> + <resource_index kee="utils" position="3" name_size="8" resource_id="10" root_project_id="8"/> + <resource_index kee="tils" position="4" name_size="8" resource_id="10" root_project_id="8"/> + <resource_index kee="ils" position="5" name_size="8" resource_id="10" root_project_id="8"/> </dataset>
\ No newline at end of file diff --git a/sonar-core/src/test/resources/org/sonar/persistence/resource/ResourceIndexerDaoTest/shouldIndexSingleResource.xml b/sonar-core/src/test/resources/org/sonar/persistence/resource/ResourceIndexerDaoTest/shouldIndexSingleResource.xml new file mode 100644 index 00000000000..5a4a28b7df3 --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/persistence/resource/ResourceIndexerDaoTest/shouldIndexSingleResource.xml @@ -0,0 +1 @@ +<dataset></dataset> diff --git a/sonar-core/src/test/resources/org/sonar/persistence/resource/ResourceIndexerDaoTest/shouldReindexProjectAfterRenaming-result.xml b/sonar-core/src/test/resources/org/sonar/persistence/resource/ResourceIndexerDaoTest/shouldReindexProjectAfterRenaming-result.xml new file mode 100644 index 00000000000..23893f22365 --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/persistence/resource/ResourceIndexerDaoTest/shouldReindexProjectAfterRenaming-result.xml @@ -0,0 +1,21 @@ +<dataset> + + <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Apache Struts" + root_id="[null]" + description="[null]" + enabled="[true]" language="java" copy_resource_id="[null]"/> + + + <resource_index kee="apache struts" position="0" name_size="13" resource_id="1" root_project_id="1"/> + <resource_index kee="pache struts" position="1" name_size="13" resource_id="1" root_project_id="1"/> + <resource_index kee="ache struts" position="2" name_size="13" resource_id="1" root_project_id="1"/> + <resource_index kee="che struts" position="3" name_size="13" resource_id="1" root_project_id="1"/> + <resource_index kee="he struts" position="4" name_size="13" resource_id="1" root_project_id="1"/> + <resource_index kee="e struts" position="5" name_size="13" resource_id="1" root_project_id="1"/> + <resource_index kee=" struts" position="6" name_size="13" resource_id="1" root_project_id="1"/> + <resource_index kee="struts" position="7" name_size="13" resource_id="1" root_project_id="1"/> + <resource_index kee="truts" position="8" name_size="13" resource_id="1" root_project_id="1"/> + <resource_index kee="ruts" position="9" name_size="13" resource_id="1" root_project_id="1"/> + <resource_index kee="uts" position="10" name_size="13" resource_id="1" root_project_id="1"/> + +</dataset> diff --git a/sonar-core/src/test/resources/org/sonar/persistence/resource/ResourceIndexerDaoTest/shouldReindexProjectAfterRenaming.xml b/sonar-core/src/test/resources/org/sonar/persistence/resource/ResourceIndexerDaoTest/shouldReindexProjectAfterRenaming.xml new file mode 100644 index 00000000000..e29238680c8 --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/persistence/resource/ResourceIndexerDaoTest/shouldReindexProjectAfterRenaming.xml @@ -0,0 +1,14 @@ +<dataset> + + <projects long_name="[null]" id="1" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Apache Struts" + root_id="[null]" + description="[null]" + enabled="[true]" language="java" copy_resource_id="[null]"/> + + <!-- the index is on the old name "Struts" but not on "Apache Struts --> + <resource_index kee="struts" position="0" name_size="6" resource_id="1" root_project_id="1"/> + <resource_index kee="truts" position="1" name_size="6" resource_id="1" root_project_id="1"/> + <resource_index kee="ruts" position="2" name_size="6" resource_id="1" root_project_id="1"/> + <resource_index kee="uts" position="3" name_size="6" resource_id="1" root_project_id="1"/> + +</dataset> diff --git a/sonar-core/src/test/resources/org/sonar/persistence/resource/ResourceIndexerDaoTest/testIndex.xml b/sonar-core/src/test/resources/org/sonar/persistence/resource/ResourceIndexerDaoTest/testIndex.xml deleted file mode 100644 index 5ed00ba028b..00000000000 --- a/sonar-core/src/test/resources/org/sonar/persistence/resource/ResourceIndexerDaoTest/testIndex.xml +++ /dev/null @@ -1 +0,0 @@ -<dataset></dataset>
\ No newline at end of file |