return null;
}
- resource.setEffectiveKey(ComponentKeys.createKey(currentProject, resource));
- resource.setDeprecatedEffectiveKey(ComponentKeys.createDeprecatedKey(currentProject, resource));
+ resource.setEffectiveKey(ComponentKeys.createEffectiveKey(currentProject, resource));
+ resource.setDeprecatedEffectiveKey(ComponentKeys.createDeprecatedEffectiveKey(currentProject, resource));
bucket = new Bucket(resource).setParent(parentBucket);
buckets.put(resource, bucket);
for (Map.Entry<Resource, Bucket> entry : buckets.entrySet()) {
Resource indexedResource = entry.getKey();
if (res.getClass() == indexedResource.getClass() && res.getDeprecatedKey().equals(indexedResource.getDeprecatedKey())) {
- LOG.warn("Resource was found using deprecated key. Please update your plugin.");
+ LOG.warn("Resource " + res + " was found using deprecated key. Please update your plugin.");
// Fix resource key
Bucket bucket = entry.getValue();
res.setKey(bucket.getResource().getKey());
import org.sonar.api.security.ResourcePermissions;
import org.sonar.api.utils.SonarException;
-import javax.annotation.Nullable;
import javax.persistence.NonUniqueResultException;
import javax.persistence.Query;
// temporary hack
project.setEffectiveKey(project.getKey());
- ResourceModel model = findOrCreateModel(null, project);
+ ResourceModel model = findOrCreateModel(project);
// ugly, only for projects
model.setLanguageKey(project.getLanguageKey());
}
private Snapshot persistLibrary(Project project, Library library) {
- ResourceModel model = findOrCreateModel(null, library);
+ ResourceModel model = findOrCreateModel(library);
model = session.save(model);
// TODO to be removed
library.setId(model.getId());
private Snapshot persistFileOrDirectory(Project project, Resource resource, Resource parentReference) {
Snapshot moduleSnapshot = snapshotsByResource.get(project);
Integer moduleId = moduleSnapshot.getResourceId();
- ResourceModel model = findOrCreateModel(moduleId, resource);
+ ResourceModel model = findOrCreateModel(resource);
model.setRootId(moduleId);
model = session.save(model);
resource.setId(model.getId());
}
}
- /**
- * @param rootModuleId can be null and in this case resource will be searched using deprecated key instead of path
- */
- private ResourceModel findOrCreateModel(@Nullable Integer rootModuleId, Resource resource) {
+ private ResourceModel findOrCreateModel(Resource resource) {
ResourceModel model;
try {
model = session.getSingleResult(ResourceModel.class, "key", resource.getEffectiveKey());
- if (model == null) {
+ if (model == null && !StringUtils.equals(resource.getEffectiveKey(), resource.getDeprecatedEffectiveKey())) {
// Fallback on deprecated key when resource has not already been migrated
model = session.getSingleResult(ResourceModel.class, "key", resource.getDeprecatedEffectiveKey(), "deprecatedKey", null);
}
* @param resource
* @return the full key of a component, based on its parent projects' key and own key
*/
- public static String createKey(Project project, Resource resource) {
+ public static String createEffectiveKey(Project project, Resource resource) {
String key = resource.getKey();
if (!StringUtils.equals(Scopes.PROJECT, resource.getScope())) {
// not a project nor a library
return key;
}
- public static String createDeprecatedKey(Project project, Resource resource) {
+ public static String createDeprecatedEffectiveKey(Project project, Resource resource) {
String key = resource.getKey();
if (!StringUtils.equals(Scopes.PROJECT, resource.getScope())) {
// not a project nor a library
@Test
public void shouldCreateUID() {
Project project = new Project("my_project");
- assertThat(ComponentKeys.createKey(project, project)).isEqualTo("my_project");
+ assertThat(ComponentKeys.createEffectiveKey(project, project)).isEqualTo("my_project");
JavaPackage javaPackage = JavaPackage.create("src/org/foo", "org.foo");
- assertThat(ComponentKeys.createKey(project, javaPackage)).isEqualTo("my_project:/src/org/foo");
- assertThat(ComponentKeys.createDeprecatedKey(project, javaPackage)).isEqualTo("my_project:org.foo");
+ assertThat(ComponentKeys.createEffectiveKey(project, javaPackage)).isEqualTo("my_project:/src/org/foo");
+ assertThat(ComponentKeys.createDeprecatedEffectiveKey(project, javaPackage)).isEqualTo("my_project:org.foo");
Library library = new Library("junit:junit", "4.7");
- assertThat(ComponentKeys.createKey(project, library)).isEqualTo("junit:junit");
+ assertThat(ComponentKeys.createEffectiveKey(project, library)).isEqualTo("junit:junit");
}
}
public Library(String key, String version) {
setKey(key);
+ setDeprecatedKey(key);
this.version = version;
}
@Override
public String toString() {
return new ToStringBuilder(this)
- .append("key", getKey())
- .append("name", getName())
- .append("version", version)
- .toString();
+ .append("key", getKey())
+ .append("name", getName())
+ .append("version", version)
+ .toString();
}
}
public Project(String key) {
setKey(key);
+ setDeprecatedKey(key);
setEffectiveKey(key);
+ setDeprecatedEffectiveKey(key);
}
public Project(String key, String branch, String name) {
setKey(key);
this.name = name;
}
+ setDeprecatedKey(getKey());
setEffectiveKey(getKey());
+ setDeprecatedEffectiveKey(getKey());
this.branch = branch;
}
}
public Project getRoot() {
- return parent==null ? this : parent.getRoot();
+ return parent == null ? this : parent.getRoot();
}
/**
*/
@Deprecated
public boolean getReuseExistingRulesConfig() {
- return configuration!=null && configuration.getBoolean(CoreProperties.REUSE_RULES_CONFIGURATION_PROPERTY, false);
+ return configuration != null && configuration.getBoolean(CoreProperties.REUSE_RULES_CONFIGURATION_PROPERTY, false);
}
/**
*/
@Deprecated
public String[] getExclusionPatterns() {
- return trimExclusions(ImmutableList.<String> builder()
+ return trimExclusions(ImmutableList.<String>builder()
.add(configuration.getStringArray(CoreProperties.PROJECT_EXCLUSIONS_PROPERTY))
.add(configuration.getStringArray(CoreProperties.GLOBAL_EXCLUSIONS_PROPERTY)).build());
}
globalTestExclusions = new String[] {CoreProperties.GLOBAL_TEST_EXCLUSIONS_DEFAULT};
}
- return trimExclusions(ImmutableList.<String> builder()
- .add(configuration.getStringArray(CoreProperties.PROJECT_TEST_EXCLUSIONS_PROPERTY))
- .add(globalTestExclusions).build());
+ return trimExclusions(ImmutableList.<String>builder()
+ .add(configuration.getStringArray(CoreProperties.PROJECT_TEST_EXCLUSIONS_PROPERTY))
+ .add(globalTestExclusions).build());
}
// http://jira.codehaus.org/browse/SONAR-2261 - exclusion must be trimmed
@Override
public String toString() {
return new ToStringBuilder(this)
- .append("id", getId())
- .append("key", getKey())
- .append("qualifier", getQualifier())
- .toString();
+ .append("id", getId())
+ .append("key", getKey())
+ .append("qualifier", getQualifier())
+ .toString();
}
@Override