]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-926 Export component path in issues WS search results
authorJulien HENRY <julien.henry@sonarsource.com>
Tue, 11 Feb 2014 09:50:49 +0000 (10:50 +0100)
committerJulien HENRY <julien.henry@sonarsource.com>
Tue, 11 Feb 2014 09:51:48 +0000 (10:51 +0100)
13 files changed:
sonar-core/src/main/java/org/sonar/core/component/ComponentDto.java
sonar-core/src/main/java/org/sonar/core/component/ComponentVertex.java
sonar-core/src/main/java/org/sonar/core/component/ResourceComponent.java
sonar-core/src/main/java/org/sonar/core/resource/ResourceDao.java
sonar-core/src/main/resources/org/sonar/core/resource/ResourceMapper.xml
sonar-core/src/test/java/org/sonar/core/component/ComponentVertexTest.java
sonar-core/src/test/java/org/sonar/core/resource/ResourceDaoTest.java
sonar-core/src/test/resources/org/sonar/core/resource/ResourceDaoTest/fixture.xml
sonar-plugin-api/src/main/java/org/sonar/api/component/Component.java
sonar-plugin-api/src/main/java/org/sonar/api/component/mock/MockSourceFile.java
sonar-plugin-api/src/main/java/org/sonar/api/resources/Project.java
sonar-server/src/main/webapp/WEB-INF/app/controllers/api/issues_controller.rb
sonar-ws-client/src/main/java/org/sonar/wsclient/component/Component.java

index 3e41b2d79318716015c13e514587743886874ef2..1c6bcf867322c16224b87f6fcf7ce159317cd7e1 100644 (file)
@@ -25,6 +25,7 @@ public class ComponentDto implements Component {
 
   private Long id;
   private String kee;
+  private String path;
   private String name;
   private String longName;
   private String qualifier;
@@ -48,6 +49,16 @@ public class ComponentDto implements Component {
     return this;
   }
 
+  @Override
+  public String path() {
+    return path;
+  }
+
+  public ComponentDto setPath(String path) {
+    this.path = path;
+    return this;
+  }
+
   @Override
   public String name() {
     return name;
@@ -63,7 +74,6 @@ public class ComponentDto implements Component {
     return longName;
   }
 
-
   public ComponentDto setLongName(String longName) {
     this.longName = longName;
     return this;
index 6adc414ddf049c4125a0baa9100fc34f383144ef..8297c0819682cadfd6c0496539e73dce1526cce7 100644 (file)
@@ -28,6 +28,10 @@ public class ComponentVertex extends BeanVertex implements Component {
     return (String) getProperty("key");
   }
 
+  public String path() {
+    return (String) getProperty("path");
+  }
+
   public String name() {
     return (String) getProperty("name");
   }
@@ -42,6 +46,7 @@ public class ComponentVertex extends BeanVertex implements Component {
 
   void copyFrom(Component component) {
     setProperty("key", component.key());
+    setProperty("path", component.path());
     setProperty("name", component.name());
     setProperty("longName", component.longName());
     setProperty("qualifier", component.qualifier());
index 3307fb82051209a6d60e0923458b1f61bb82ed79..730a9da2469dc2b4818241096ebcea8da07d7b95 100644 (file)
@@ -28,6 +28,7 @@ import javax.annotation.Nullable;
 
 public class ResourceComponent implements Component {
   private String key;
+  private String path;
   private String name;
   private String longName;
   private String qualifier;
@@ -37,6 +38,7 @@ public class ResourceComponent implements Component {
 
   public ResourceComponent(Resource resource, @Nullable Snapshot snapshot) {
     this.key = resource.getEffectiveKey();
+    this.path = resource.getPath();
     if (Strings.isNullOrEmpty(key)) {
       throw new IllegalArgumentException("Missing component key");
     }
@@ -58,6 +60,11 @@ public class ResourceComponent implements Component {
     return key;
   }
 
+  @Override
+  public String path() {
+    return path;
+  }
+
   public String name() {
     return name;
   }
@@ -66,7 +73,6 @@ public class ResourceComponent implements Component {
     return longName;
   }
 
-
   public String qualifier() {
     return qualifier;
   }
index 5c1d75a85909ea1184fd70e2aa02f36c42a8c570..34f0cac01bed64caea2cf9f5ed6de4bb5fb4c445 100644 (file)
@@ -307,6 +307,7 @@ public class ResourceDao {
     return new ComponentDto()
       .setId(resourceDto.getId())
       .setKey(resourceDto.getKey())
+      .setPath(resourceDto.getPath())
       .setLongName(resourceDto.getLongName())
       .setName(resourceDto.getName())
       .setQualifier(resourceDto.getQualifier());
index ef9389a5a272d73f89390ca654a2ae355cd806d0..a9ba7ad6b0e696eab6b5ff17f104799dfd707bd7 100644 (file)
@@ -6,6 +6,7 @@
   <sql id="resourceColumns">
     p.id,
     p.kee as key,
+    p.path as path,
     p.deprecated_kee as deprecatedKey,
     p.name as name,
     p.long_name as longName,
index c012933747d950642b73e38ee3a202003da6f24f..b17d5bcbfadc42d185ea2ab770e3f247494d0fbc 100644 (file)
@@ -35,13 +35,15 @@ public class ComponentVertexTest {
   public void should_copy() {
     BeanGraph beanGraph = new BeanGraph(new TinkerGraph());
     ComponentVertex vertex = beanGraph.createVertex(ComponentVertex.class);
-    Component file = MockSourceFile.createMain("myproject:org/Foo.java").setName("Foo.java").setQualifier(Qualifiers.FILE);
+    Component file = MockSourceFile.createMain("myproject:org/Foo.java").setName("Foo.java").setQualifier(Qualifiers.FILE)
+      .setPath("src/org/Foo.java");
 
     vertex.copyFrom(file);
 
     assertThat(vertex.key()).isEqualTo("myproject:org/Foo.java");
     assertThat(vertex.name()).isEqualTo("Foo.java");
     assertThat(vertex.qualifier()).isEqualTo(Qualifiers.FILE);
+    assertThat(vertex.path()).isEqualTo("src/org/Foo.java");
   }
 
   @Test
index 5420558b1eb2a683f9c4e41534e25dcce747de3e..9d55f8a70a41dce75358883f1799ad1fe270e121 100644 (file)
@@ -72,6 +72,7 @@ public class ResourceDaoTest extends AbstractDaoTestCase {
 
     ResourceDto resource = dao.getResource(1L);
 
+    assertThat(resource.getPath()).isNull();
     assertThat(resource.getName()).isEqualTo("Struts");
     assertThat(resource.getLongName()).isEqualTo("Apache Struts");
     assertThat(resource.getScope()).isEqualTo("PRJ");
@@ -316,7 +317,9 @@ public class ResourceDaoTest extends AbstractDaoTestCase {
     setupData("fixture");
 
     assertThat(dao.findByKey("org.struts:struts")).isNotNull();
-    assertThat(dao.findByKey("org.struts:struts:org.struts.RequestContext")).isNotNull();
+    Component<?> component = dao.findByKey("org.struts:struts:org.struts.RequestContext");
+    assertThat(component).isNotNull();
+    assertThat(component.path()).isEqualTo("src/main/java/RequestContext.java");
     assertThat(dao.findByKey("unknown")).isNull();
   }
 
index 57be22f2d1c67a4361313adecb724069865b95c2..c2e7b8638fb143f736fa845d61c31d3cc108f591 100644 (file)
@@ -7,7 +7,7 @@
   <!-- root project -->
   <projects id="1" root_id="[null]" scope="PRJ" qualifier="TRK" kee="org.struts:struts" name="Struts"
             description="the description" long_name="Apache Struts"
-            enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]"/>
+            enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" path="[null]"/>
   <snapshots id="1" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
                status="P" islast="[true]" purge_status="[null]"
                period1_mode="[null]" period1_param="[null]" period1_date="[null]"
                version="[null]" path="1.2."/>
 
   <!-- file -->
-  <projects long_name="org.struts.RequestContext" id="4" scope="FIL" qualifier="CLA" kee="org.struts:struts:org.struts.RequestContext"
+  <projects long_name="org.struts.RequestContext" id="4" scope="FIL" qualifier="FIL" 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]"/>
+            enabled="[true]" language="java" copy_resource_id="[null]" person_id="[null]" path="src/main/java/RequestContext.java"/>
 
   <snapshots id="4" project_id="4" parent_snapshot_id="3" root_project_id="1" root_snapshot_id="1"
                status="P" islast="[true]" purge_status="[null]"
index b658be87d190faa696c278ff9f9b060bddc0a4dd..064f51f37fc3b787b541d0b119a5cd3fb4417215 100644 (file)
@@ -22,6 +22,11 @@ package org.sonar.api.component;
 public interface Component<C extends Component> {
   String key();
 
+  /**
+   * @since 4.2
+   */
+  String path();
+
   String name();
 
   String longName();
index 0e6f2b7fe95d66c90024e8adc5383fb23f0d7c1c..428c17a5a4c3ddf107cccecf370437a34a6c34d8 100644 (file)
@@ -23,6 +23,7 @@ import org.sonar.api.component.SourceFile;
 
 public class MockSourceFile implements SourceFile {
   private String key;
+  private String path;
   private String qualifier;
   private String language;
   private String name;
@@ -40,6 +41,16 @@ public class MockSourceFile implements SourceFile {
     return this;
   }
 
+  @Override
+  public String path() {
+    return path;
+  }
+
+  public MockSourceFile setPath(String path) {
+    this.path = path;
+    return this;
+  }
+
   public String qualifier() {
     return qualifier;
   }
index a4aaf28b34292e39e3db58e1b2d9fbdb7d345312..2119c04a1f26671c77a84a71841eab8a07d5c2d0 100644 (file)
@@ -502,6 +502,11 @@ public class Project extends Resource implements Component {
     return getName();
   }
 
+  @Override
+  public String path() {
+    return getPath();
+  }
+
   @Override
   public String longName() {
     return getLongName();
index 7aa39a5161d32a3c5d642bcdd999cd9a56b5f6a3..8246d73acc44a2ef225041d3b96d07832494e288 100644 (file)
@@ -342,6 +342,7 @@ class Api::IssuesController < Api::ApiController
     }
     hash[:name] = component.name if component.name
     hash[:longName] = component.longName if component.longName
+    hash[:path] = component.path if component.path
     hash
   end
 
index 1a1114836bc9f259e7e4ed961dc78f854a8466a7..a348adbd9a418577e397c45db7c270af2aaddb9f 100644 (file)
@@ -22,6 +22,7 @@ package org.sonar.wsclient.component;
 import org.sonar.wsclient.unmarshallers.JsonUtils;
 
 import javax.annotation.CheckForNull;
+
 import java.util.Map;
 
 public class Component {
@@ -39,6 +40,14 @@ public class Component {
     return JsonUtils.getString(json, "key");
   }
 
+  /**
+   * @since 4.2
+   */
+  @CheckForNull
+  public String path() {
+    return JsonUtils.getString(json, "path");
+  }
+
   public String name() {
     return JsonUtils.getString(json, "name");
   }