return getField(IssueIndexDefinition.FIELD_ISSUE_COMPONENT_UUID);
}
+ @CheckForNull
public String moduleUuid() {
return getField(IssueIndexDefinition.FIELD_ISSUE_MODULE_UUID);
}
+ public String modulePath() {
+ return getField(IssueIndexDefinition.FIELD_ISSUE_MODULE_PATH);
+ }
+
@Override
public String projectKey() {
throw new IllegalStateException("projectKey is not available on server side");
return getNullableField(IssueIndexDefinition.FIELD_ISSUE_FILE_PATH);
}
+ @CheckForNull
+ public String directoryPath() {
+ return getNullableField(IssueIndexDefinition.FIELD_ISSUE_DIRECTORY_PATH);
+ }
+
public IssueDoc setKey(@Nullable String s) {
setField(IssueIndexDefinition.FIELD_ISSUE_KEY, s);
return this;
return this;
}
+ public IssueDoc setDirectoryPath(@Nullable String s) {
+ setField(IssueIndexDefinition.FIELD_ISSUE_DIRECTORY_PATH, s);
+ return this;
+ }
+
public IssueDoc setModuleUuidPath(@Nullable String s) {
setField(IssueIndexDefinition.FIELD_ISSUE_MODULE_PATH, s);
return this;
public static final String FIELD_ISSUE_MODULE_UUID = "module";
public static final String FIELD_ISSUE_MODULE_PATH = "modulePath";
public static final String FIELD_ISSUE_PROJECT_UUID = "project";
+ public static final String FIELD_ISSUE_DIRECTORY_PATH = "dirPath";
public static final String FIELD_ISSUE_REPORTER = "reporter";
public static final String FIELD_ISSUE_RESOLUTION = "resolution";
public static final String FIELD_ISSUE_RULE_KEY = "ruleKey";
issueMapping.stringFieldBuilder(FIELD_ISSUE_MODULE_UUID).build();
issueMapping.createUuidPathField(FIELD_ISSUE_MODULE_PATH);
issueMapping.stringFieldBuilder(FIELD_ISSUE_PROJECT_UUID).enableSorting().build();
+ issueMapping.stringFieldBuilder(FIELD_ISSUE_DIRECTORY_PATH).build();
issueMapping.stringFieldBuilder(FIELD_ISSUE_REPORTER).build();
issueMapping.stringFieldBuilder(FIELD_ISSUE_RESOLUTION).build();
issueMapping.stringFieldBuilder(FIELD_ISSUE_RULE_KEY).build();
*/
package org.sonar.server.issue.index;
+import com.google.common.base.CharMatcher;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Maps;
import org.sonar.server.db.ResultSetIterator;
import org.sonar.server.db.migrations.SqlUtil;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
+
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
doc.setModuleUuid(rs.getString(23));
doc.setModuleUuidPath(rs.getString(24));
doc.setFilePath(rs.getString(25));
+ doc.setDirectoryPath(extractDirPath(doc.filePath()));
String tags = rs.getString(26);
doc.setTags(ImmutableList.copyOf(TAGS_SPLITTER.split(tags == null ? "" : tags)));
return doc;
}
+
+ @CheckForNull
+ private static String extractDirPath(@Nullable String filePath) {
+ if (filePath != null) {
+ StringBuilder dirPath = new StringBuilder("/");
+ int lastSlashIndex = CharMatcher.anyOf("/").lastIndexIn(filePath);
+ if (lastSlashIndex > 0) {
+ dirPath.append(filePath.substring(0, lastSlashIndex));
+ }
+ return dirPath.toString();
+ }
+ return null;
+ }
}
IssueDoc doc = docs.get(0);
assertThat(doc.projectUuid()).isEqualTo("THE_PROJECT");
assertThat(doc.componentUuid()).isEqualTo("THE_FILE");
+ assertThat(doc.moduleUuid()).isEqualTo("THE_PROJECT");
+ assertThat(doc.modulePath()).isEqualTo(".THE_PROJECT.");
+ assertThat(doc.directoryPath()).isEqualTo("/src/main/java");
assertThat(doc.severity()).isEqualTo("BLOCKER");
assertThat(doc.ruleKey()).isEqualTo(RuleKey.of("squid", "AvoidCycles"));
assertThat(issue.assignee()).isEqualTo("guy1");
assertThat(issue.componentUuid()).isEqualTo("FILE1");
assertThat(issue.projectUuid()).isEqualTo("PROJECT1");
+ assertThat(issue.filePath()).isEqualTo("src/main/java/Action.java");
assertThat(issue.tags()).containsOnly("tag1", "tag2", "tag3");
assertThat(issue.debt().toMinutes()).isGreaterThan(0L);
assertThat(issue.assignee()).isEqualTo("guy2");
assertThat(issue.componentUuid()).isEqualTo("FILE1");
assertThat(issue.projectUuid()).isEqualTo("PROJECT1");
+ assertThat(issue.filePath()).isEqualTo("src/main/java/Action.java");
assertThat(issue.tags()).isEmpty();
assertThat(issue.debt().toMinutes()).isGreaterThan(0L);
+ }
+
+ @Test
+ public void extract_directory_path() throws Exception {
+ dbTester.prepareDbUnit(getClass(), "extract_directory_path.xml");
+ IssueResultSetIterator it = IssueResultSetIterator.create(client, connection, 0L);
+ Map<String, IssueDoc> issuesByKey = Maps.uniqueIndex(it, new Function<IssueDoc, String>() {
+ @Override
+ public String apply(IssueDoc issue) {
+ return issue.key();
+ }
+ });
+ it.close();
+
+ assertThat(issuesByKey).hasSize(3);
+
+ // File in sub directoy
+ assertThat(issuesByKey.get("ABC").directoryPath()).isEqualTo("/src/main/java");
+
+ // File in root directoy
+ assertThat(issuesByKey.get("DEF").directoryPath()).isEqualTo("/");
+ // Project
+ assertThat(issuesByKey.get("EFG").directoryPath()).isNull();
}
@Test
plugin_config_key="[null]" plugin_name="squid"/>
<projects id="10" scope="PRJ" qualifier="TRK" kee="the_project" name="TheProject"
- uuid="THE_PROJECT" module_uuid="[null]" module_uuid_path="."/>
+ uuid="THE_PROJECT" module_uuid="[null]" module_uuid_path="." path="[null]"/>
<projects id="11" scope="FIL" qualifier="FIL" kee="abcde" name="TheFile"
- uuid="THE_FILE" module_uuid="THE_PROJECT" module_uuid_path="."/>
+ uuid="THE_FILE" module_uuid="THE_PROJECT" module_uuid_path=".THE_PROJECT." path="src/main/java/TheFile.java"/>
<issues id="1"
kee="ABCDE"
--- /dev/null
+<dataset>
+ <rules tags="[null]" system_tags="[null]" id="200" name="Avoid Cycles" plugin_rule_key="AvoidCycles"
+ plugin_config_key="[null]" plugin_name="squid"/>
+
+ <projects id="10" scope="PRJ" qualifier="TRK" kee="struts" name="Struts" uuid="PROJECT1" path="[null]"/>
+ <projects id="100" scope="FIL" qualifier="CLA" kee="struts:Action" name="Action" uuid="FILE1" path="src/main/java/Action.java"/>
+ <projects id="101" scope="FIL" qualifier="CLA" kee="pom" name="pom.xml" uuid="ROOT_FILE1" path="pom.xml"/>
+
+ <issues
+ id="1"
+ kee="ABC"
+ resolution="FIXED"
+ status="RESOLVED"
+ severity="BLOCKER"
+ manual_severity="[false]"
+ assignee="guy1"
+ author_login="guy2"
+ checksum="FFFFF"
+ effort_to_fix="[null]"
+ technical_debt="10"
+ message="[null]"
+ line="444"
+ component_id="100"
+ root_component_id="10"
+ rule_id="200"
+ reporter="[null]"
+ issue_attributes="JIRA=http://jira.com"
+ action_plan_key="PLAN1"
+ tags="tag1,tag2,tag3"
+ created_at="1400000000000"
+ updated_at="1400000000000"
+ issue_creation_date="2005-05-12 00:00:00.0"
+ issue_update_date="2013-01-01 00:00:00.0"
+ issue_close_date="[null]"/>
+
+ <issues
+ id="2"
+ kee="DEF"
+ resolution="[null]"
+ status="OPEN"
+ severity="MAJOR"
+ manual_severity="[false]"
+ assignee="guy2"
+ author_login="[null]"
+ checksum="FFFFF"
+ effort_to_fix="[null]"
+ technical_debt="15"
+ message="[null]"
+ line="444"
+ component_id="101"
+ root_component_id="10"
+ rule_id="200"
+ reporter="[null]"
+ issue_attributes="JIRA=http://jira.com"
+ action_plan_key="PLAN2"
+ tags="[null]"
+ created_at="1400000000000"
+ updated_at="1450000000000"
+ issue_creation_date="2005-05-12 00:00:00.0"
+ issue_update_date="2013-05-18 00:00:00.0"
+ issue_close_date="[null]"/>
+
+ <issues
+ id="3"
+ kee="EFG"
+ resolution="[null]"
+ status="OPEN"
+ severity="MAJOR"
+ manual_severity="[false]"
+ assignee="guy2"
+ author_login="[null]"
+ checksum="FFFFF"
+ effort_to_fix="[null]"
+ technical_debt="15"
+ message="[null]"
+ line="444"
+ component_id="10"
+ root_component_id="10"
+ rule_id="200"
+ reporter="[null]"
+ issue_attributes="JIRA=http://jira.com"
+ action_plan_key="PLAN2"
+ tags="[null]"
+ created_at="1400000000000"
+ updated_at="1450000000000"
+ issue_creation_date="2005-05-12 00:00:00.0"
+ issue_update_date="2013-05-18 00:00:00.0"
+ issue_close_date="[null]"/>
+
+</dataset>
<rules tags="[null]" system_tags="[null]" id="200" name="Avoid Cycles" plugin_rule_key="AvoidCycles"
plugin_config_key="[null]" plugin_name="squid"/>
- <projects id="10" scope="PRJ" qualifier="TRK" kee="struts" name="Struts" uuid="PROJECT1"/>
- <projects id="100" scope="FIL" qualifier="CLA" kee="struts:Action" name="Action" uuid="FILE1"/>
+ <projects id="10" scope="PRJ" qualifier="TRK" kee="struts" name="Struts" uuid="PROJECT1" path="[null]"/>
+ <projects id="100" scope="FIL" qualifier="CLA" kee="struts:Action" name="Action" uuid="FILE1" path="src/main/java/Action.java"/>
<issues
id="1"