diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2012-04-02 17:24:11 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2012-04-02 17:28:02 +0200 |
commit | 0b6cd312475d048d9fd203e00250130ef0b7b5f2 (patch) | |
tree | 457455c98c594c6e7e7b71e7c676323327a3974d /sonar-core | |
parent | 3d8fd94d37c2b397e413cd7594d765e0f944f7a9 (diff) | |
download | sonarqube-0b6cd312475d048d9fd203e00250130ef0b7b5f2.tar.gz sonarqube-0b6cd312475d048d9fd203e00250130ef0b7b5f2.zip |
Do not filter qualifier when executing ResourceIndexerDao#indexResource()
Diffstat (limited to 'sonar-core')
3 files changed, 62 insertions, 16 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/resource/ResourceIndexerDao.java b/sonar-core/src/main/java/org/sonar/core/resource/ResourceIndexerDao.java index 80553c49eed..dc9df4e8f06 100644 --- a/sonar-core/src/main/java/org/sonar/core/resource/ResourceIndexerDao.java +++ b/sonar-core/src/main/java/org/sonar/core/resource/ResourceIndexerDao.java @@ -154,14 +154,12 @@ public class ResourceIndexerDao { public boolean indexResource(int id, String name, String qualifier, int rootId) { boolean indexed = false; - if (isIndexableQualifier(qualifier)) { - SqlSession session = mybatis.openSession(); - ResourceIndexerMapper mapper = session.getMapper(ResourceIndexerMapper.class); - try { - indexed = indexResource(id, name, qualifier, rootId, session, mapper); - } finally { - MyBatis.closeQuietly(session); - } + SqlSession session = mybatis.openSession(); + ResourceIndexerMapper mapper = session.getMapper(ResourceIndexerMapper.class); + try { + indexed = indexResource(id, name, qualifier, rootId, session, mapper); + } finally { + MyBatis.closeQuietly(session); } return indexed; } @@ -209,8 +207,4 @@ public class ResourceIndexerDao { static String nameToKey(String input) { return StringUtils.lowerCase(StringUtils.trimToEmpty(input)); } - - static boolean isIndexableQualifier(String qualifier) { - return ArrayUtils.contains(RENAMABLE_QUALIFIERS, qualifier) || ArrayUtils.contains(NOT_RENAMABLE_QUALIFIERS, qualifier); - } } diff --git a/sonar-core/src/test/java/org/sonar/core/resource/ResourceIndexerDaoTest.java b/sonar-core/src/test/java/org/sonar/core/resource/ResourceIndexerDaoTest.java index 78ccd3a77d5..49ab76cb84c 100644 --- a/sonar-core/src/test/java/org/sonar/core/resource/ResourceIndexerDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/resource/ResourceIndexerDaoTest.java @@ -19,11 +19,19 @@ */ package org.sonar.core.resource; +import org.hamcrest.core.Is; import org.junit.Before; import org.junit.Test; import org.sonar.api.resources.Qualifiers; import org.sonar.core.persistence.DaoTestCase; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; + +import static org.hamcrest.number.OrderingComparisons.greaterThan; +import static org.junit.Assert.assertThat; + public class ResourceIndexerDaoTest extends DaoTestCase { private static ResourceIndexerDao dao; @@ -70,12 +78,32 @@ public class ResourceIndexerDaoTest extends DaoTestCase { } @Test - public void shouldNotIndexPackage() { - setupData("empty"); + public void shouldNotIndexPackages() throws SQLException { + setupData("shouldNotIndexPackages"); - dao.indexResource(10, "org.codehaus.sonar", Qualifiers.PACKAGE, 3); + dao.indexProject(1); - checkTables("empty", new String[]{"id"}, "resource_index"); + Connection connection = getConnection().getConnection(); + ResultSet rs = null; + try { + // project + rs = connection.createStatement().executeQuery("select count(resource_id) from resource_index where resource_id=1"); + rs.next(); + assertThat(rs.getInt(1), greaterThan(0)); + + // directory + rs = connection.createStatement().executeQuery("select count(resource_id) from resource_index where resource_id=2"); + rs.next(); + assertThat(rs.getInt(1), Is.is(0)); + + // file + rs = connection.createStatement().executeQuery("select count(resource_id) from resource_index where resource_id=3"); + rs.next(); + assertThat(rs.getInt(1), greaterThan(0)); + } finally { + rs.close(); + connection.close(); + } } @Test diff --git a/sonar-core/src/test/resources/org/sonar/core/resource/ResourceIndexerDaoTest/shouldNotIndexPackages.xml b/sonar-core/src/test/resources/org/sonar/core/resource/ResourceIndexerDaoTest/shouldNotIndexPackages.xml new file mode 100644 index 00000000000..7e7124733f3 --- /dev/null +++ b/sonar-core/src/test/resources/org/sonar/core/resource/ResourceIndexerDaoTest/shouldNotIndexPackages.xml @@ -0,0 +1,24 @@ +<dataset> + + <!-- project --> + <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]" person_id="[null]"/> + + <!-- directory --> + <projects long_name="org.struts" id="2" scope="DIR" qualifier="PAC" kee="org.struts:struts:org.struts" + name="org.struts" root_id="1" + description="[null]" + enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/> + + <!-- file --> + <projects long_name="org.struts.RequestContext" id="3" scope="FIL" qualifier="CLA" kee="org.struts:struts:org.struts.RequestContext" + name="RequestContext" root_id="1" + description="[null]" + enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/> + + <snapshots purge_status="[null]" id="1" islast="[true]" root_project_id="1" project_id="1" scope="PRJ" qualifier="TRK"/> + <snapshots purge_status="[null]" id="2" islast="[true]" root_project_id="1" project_id="2" scope="DIR" qualifier="PAC"/> + <snapshots purge_status="[null]" id="3" islast="[true]" root_project_id="1" project_id="3" scope="FIL" qualifier="CLA"/> +</dataset> |