aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch/src
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2014-01-31 14:02:31 +0100
committerJulien HENRY <julien.henry@sonarsource.com>2014-01-31 14:03:11 +0100
commit9f4a61ab12ec9449df444b0497a02568992cca99 (patch)
tree34b4ea35123e075a6dfcb6522ee036eb510fc4a5 /sonar-batch/src
parentbef5ca80e046db319730a386f81c2766d2b49b99 (diff)
downloadsonarqube-9f4a61ab12ec9449df444b0497a02568992cca99.tar.gz
sonarqube-9f4a61ab12ec9449df444b0497a02568992cca99.zip
SONAR-926 Optimize resource lookup using deprecated key
Diffstat (limited to 'sonar-batch/src')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java46
1 files changed, 25 insertions, 21 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java
index d4cb7c0e95e..76f37e5d104 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java
@@ -28,7 +28,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.batch.Event;
import org.sonar.api.batch.SonarIndex;
-import org.sonar.api.batch.SquidUtils;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.database.model.Snapshot;
import org.sonar.api.design.Dependency;
@@ -82,6 +81,7 @@ public class DefaultIndex extends SonarIndex {
// caches
private Project currentProject;
private Map<Resource, Bucket> buckets = Maps.newHashMap();
+ private Map<String, Bucket> bucketsByDeprecatedKey = Maps.newHashMap();
private Set<Dependency> dependencies = Sets.newHashSet();
private Map<Resource, Map<Resource, Dependency>> outgoingDependenciesByResource = Maps.newHashMap();
private Map<Resource, Map<Resource, Dependency>> incomingDependenciesByResource = Maps.newHashMap();
@@ -110,7 +110,7 @@ public class DefaultIndex extends SonarIndex {
void doStart(Project rootProject) {
Bucket bucket = new Bucket(rootProject);
- buckets.put(rootProject, bucket);
+ addBucket(rootProject, bucket);
migration.checkIfMigrationNeeded(rootProject);
persistence.saveProject(rootProject, null);
currentProject = rootProject;
@@ -120,6 +120,13 @@ public class DefaultIndex extends SonarIndex {
}
}
+ private void addBucket(Resource resource, Bucket bucket) {
+ buckets.put(resource, bucket);
+ if (StringUtils.isNotBlank(resource.getDeprecatedKey())) {
+ bucketsByDeprecatedKey.put(resource.getDeprecatedKey(), bucket);
+ }
+ }
+
private void addModule(Project parent, Project module) {
ProjectDefinition parentDefinition = projectTree.getProjectDefinition(parent);
java.io.File parentBaseDir = parentDefinition.getBaseDir();
@@ -554,7 +561,7 @@ public class DefaultIndex extends SonarIndex {
resource.setEffectiveKey(ComponentKeys.createEffectiveKey(currentProject, resource));
bucket = new Bucket(resource).setParent(parentBucket);
- buckets.put(resource, bucket);
+ addBucket(resource, bucket);
boolean excluded = checkExclusion(resource, parentBucket);
if (!excluded) {
@@ -601,30 +608,27 @@ public class DefaultIndex extends SonarIndex {
}
/**
- * Should support 3 situations
+ * Should support 2 situations
* 1) key = new key and deprecatedKey = old key : this is the standard use case in a perfect world
- * 2) key = old key and deprecatedKey = null : this is to support backard compatibility for plugins using
- * {@link SquidUtils#convertJavaFileKeyFromSquidFormat(String)} or {@link SquidUtils#convertJavaPackageKeyFromSquidFormat(String)}
- * 3) key = null and deprecatedKey = oldKey : this is for plugins that are using deprecated constructors of {@link JavaFile}, {@link JavaPackage}, {@link File}, {@link Directory}
+ * 2) key = null and deprecatedKey = oldKey : this is for plugins that are using deprecated constructors of
+ * {@link JavaFile}, {@link JavaPackage}, {@link File}, {@link Directory}
*
- * @param res
+ * @param reference
* @return
*/
- private Bucket getBucket(Resource res) {
- if (StringUtils.isNotBlank(res.getKey())) {
- return buckets.get(res);
+ private Bucket getBucket(Resource reference) {
+ if (StringUtils.isNotBlank(reference.getKey())) {
+ return buckets.get(reference);
}
- if (StringUtils.isNotBlank(res.getDeprecatedKey())) {
+ if (StringUtils.isNotBlank(reference.getDeprecatedKey())) {
// Fallback to use deprecated key
- for (Map.Entry<Resource, Bucket> entry : buckets.entrySet()) {
- Resource indexedResource = entry.getKey();
- if (res.getClass() == indexedResource.getClass() && res.getDeprecatedKey().equals(indexedResource.getDeprecatedKey())) {
- LOG.debug("Resource " + res + " was found using deprecated key. Please update your plugin.");
- // Fix resource key
- Bucket bucket = entry.getValue();
- res.setKey(bucket.getResource().getKey());
- return bucket;
- }
+ Bucket bucket = bucketsByDeprecatedKey.get(reference.getDeprecatedKey());
+ if (bucket != null) {
+ // Fix reference resource
+ reference.setKey(bucket.getResource().getKey());
+ reference.setPath(bucket.getResource().getPath());
+ LOG.debug("Resource {} was found using deprecated key. Please update your plugin.", reference);
+ return bucket;
}
}
return null;