private Long id;
private String kee;
-
- // TODO delete it
private String path;
-
- // TODO delete it
- private String moduleKey;
-
private String name;
private String longName;
private String qualifier;
return this;
}
- @Override
- public String moduleKey() {
- return moduleKey;
- }
-
- public ComponentDto setModuleKey(String moduleKey) {
- this.moduleKey = moduleKey;
- return this;
- }
-
@Override
public String name() {
return name;
return (String) getProperty("path");
}
- public String moduleKey() {
- return (String) getProperty("moduleKey");
- }
-
public String name() {
return (String) getProperty("name");
}
void copyFrom(Component component) {
setProperty("key", component.key());
setProperty("path", component.path());
- setProperty("moduleKey", component.moduleKey());
setProperty("name", component.name());
setProperty("longName", component.longName());
setProperty("qualifier", component.qualifier());
package org.sonar.core.component;
import com.google.common.base.Strings;
-import org.apache.commons.lang.StringUtils;
import org.sonar.api.component.Component;
import org.sonar.api.database.model.Snapshot;
import org.sonar.api.resources.Resource;
public class ResourceComponent implements Component {
private String key;
private String path;
- private String moduleKey;
private String name;
private String longName;
private String qualifier;
public ResourceComponent(Resource resource, @Nullable Snapshot snapshot) {
this.key = resource.getEffectiveKey();
this.path = resource.getPath();
- // Kind of a hack as it depends on format of resource effective key
- this.moduleKey = StringUtils.removeEnd(resource.getEffectiveKey(), ":" + resource.getKey());
if (Strings.isNullOrEmpty(key)) {
throw new IllegalArgumentException("Missing component key");
}
return path;
}
- @Override
- public String moduleKey() {
- return moduleKey;
- }
-
public String name() {
return name;
}
return new ComponentDto()
.setId(resourceDto.getId())
.setKey(resourceDto.getKey())
- .setModuleKey(resourceDto.getModuleKey())
.setPath(resourceDto.getPath())
.setLongName(resourceDto.getLongName())
.setName(resourceDto.getName())
private String name;
private String longName;
private Long rootId;
- private String moduleKey;
private String path;
private String scope;
private String qualifier;
return this;
}
- public String getModuleKey() {
- return moduleKey;
- }
-
- public ResourceDto setModuleKey(String s) {
- this.moduleKey = s;
- return this;
- }
-
public String getLongName() {
return longName;
}
<result property="key" column="kee"/>
<result property="deprecatedKey" column="deprecated_kee"/>
<result property="path" column="path"/>
- <result property="moduleKey" column="moduleKey"/>
<result property="name" column="name"/>
<result property="longName" column="long_name"/>
<result property="rootId" column="root_id"/>
</resultMap>
<select id="selectResources" parameterType="map" resultMap="resourceResultMap">
- select p.*, r.kee moduleKey
- from projects p left outer join projects r on p.root_id=r.id
+ select * from projects p
<where>
<if test="qualifiers != null and qualifiers.length!=0">
and p.qualifier in
</select>
<select id="selectResource" parameterType="long" resultMap="resourceResultMap">
- select p.*, r.kee moduleKey
- from projects p left outer join projects r on p.root_id=r.id
+ select * from projects p
where p.id=#{id}
</select>
assertThat(vertex.name()).isEqualTo("Foo.java");
assertThat(vertex.qualifier()).isEqualTo(Qualifiers.FILE);
assertThat(vertex.path()).isEqualTo("src/org/Foo.java");
- assertThat(vertex.moduleKey()).isEqualTo("myproject");
}
@Test
public void should_use_effective_key() {
ResourceComponent component = new ResourceComponent(file);
assertThat(component.key()).isEqualTo("myproject:path/to/foo.c");
- assertThat(component.moduleKey()).isEqualTo("myproject");
}
@Test
ResourceDto resource = dao.getResource(1L);
assertThat(resource.getPath()).isNull();
- assertThat(resource.getModuleKey()).isNull();
assertThat(resource.getName()).isEqualTo("Struts");
assertThat(resource.getLongName()).isEqualTo("Apache Struts");
assertThat(resource.getScope()).isEqualTo("PRJ");
ResourceDto dir = dao.getResource(3L);
assertThat(dir.getPath()).isEqualTo("src/org/struts");
- assertThat(dir.getModuleKey()).isEqualTo("org.struts:struts-core");
ResourceDto file = dao.getResource(4L);
assertThat(file.getPath()).isEqualTo("src/org/struts/RequestContext.java");
- assertThat(file.getModuleKey()).isEqualTo("org.struts:struts-core");
}
@Test
@CheckForNull
String path();
- /**
- * Key of the module this component belong to.
- * @return null for components that are module themself
- * @since 4.2
- */
- @CheckForNull
- String moduleKey();
-
String name();
String longName();
return this;
}
- @Override
- public String moduleKey() {
- return moduleKey;
- }
-
public MockSourceFile setModuleKey(String moduleKey) {
this.moduleKey = moduleKey;
return this;
return getKey();
}
- @Override
- public String moduleKey() {
- return null;
- }
-
@Override
public String name() {
return getName();