From e93f4cb61c1777fcb8d4befa99a6810a5e8930d6 Mon Sep 17 00:00:00 2001 From: Evgeny Mandrikov Date: Fri, 11 Mar 2011 12:27:57 +0300 Subject: [PATCH] Fix violations --- .../components/PastSnapshotFinderByPreviousAnalysis.java | 4 +++- .../main/java/org/sonar/batch/index/DefaultIndex.java | 7 ++++--- .../org/sonar/batch/index/DefaultResourcePersister.java | 9 +++++++-- .../main/java/org/sonar/batch/index/MemoryOptimizer.java | 4 ++-- .../java/org/sonar/batch/index/ViolationPersister.java | 2 +- .../java/org/sonar/batch/phases/DecoratorsExecutor.java | 2 +- 6 files changed, 18 insertions(+), 10 deletions(-) diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysis.java b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysis.java index c036530682c..2168ad2bfb4 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysis.java +++ b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshotFinderByPreviousAnalysis.java @@ -29,6 +29,8 @@ import org.sonar.api.utils.DateUtils; import java.text.SimpleDateFormat; import java.util.List; +import org.sonar.api.resources.Qualifiers; + public class PastSnapshotFinderByPreviousAnalysis implements BatchExtension { private DatabaseSession session; @@ -44,7 +46,7 @@ public class PastSnapshotFinderByPreviousAnalysis implements BatchExtension { .setParameter("resourceId", projectSnapshot.getResourceId()) .setParameter("status", Snapshot.STATUS_PROCESSED) .setParameter("last", true) - .setParameter("lib", Project.QUALIFIER_LIB) + .setParameter("lib", Qualifiers.LIBRARY) .setMaxResults(1) .getResultList(); 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 494e1a84997..75e1f03ca78 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 @@ -137,7 +137,7 @@ public class DefaultIndex extends SonarIndex { Bucket bucket = buckets.get(resource); if (bucket != null) { Measure measure = bucket.getMeasures(MeasuresFilters.metric(metric)); - if (measure!=null) { + if (measure != null) { return persistence.reloadMeasure(measure); } } @@ -390,7 +390,7 @@ public class DefaultIndex extends SonarIndex { static String createUID(Project project, Resource resource) { String uid = resource.getKey(); - if (!StringUtils.equals(Resource.SCOPE_SET, resource.getScope())) { + if (!StringUtils.equals(Scopes.PROJECT, resource.getScope())) { // not a project nor a library uid = new StringBuilder(ResourceModel.KEY_SIZE) .append(project.getKey()) @@ -416,8 +416,9 @@ public class DefaultIndex extends SonarIndex { Bucket bucket = getBucket(resource, acceptExcluded); if (bucket != null) { for (Bucket childBucket : bucket.getChildren()) { - if (acceptExcluded || !childBucket.isExcluded()) + if (acceptExcluded || !childBucket.isExcluded()) { children.add(childBucket.getResource()); + } } } return children; diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java index fd72b491777..ca65806e20e 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultResourcePersister.java @@ -30,6 +30,11 @@ import org.sonar.api.utils.SonarException; import javax.persistence.NonUniqueResultException; import javax.persistence.Query; + +import org.sonar.api.resources.Qualifiers; + +import org.sonar.api.resources.Scopes; + import java.util.Iterator; import java.util.List; import java.util.Map; @@ -160,8 +165,8 @@ public final class DefaultResourcePersister implements ResourcePersister { " s WHERE s.resourceId=:resourceId AND s.version=:version AND s.scope=:scope AND s.qualifier<>:qualifier AND s.last=:last"); query.setParameter("resourceId", resourceId); query.setParameter("version", version); - query.setParameter("scope", Resource.SCOPE_SET); - query.setParameter("qualifier", Resource.QUALIFIER_LIB); + query.setParameter("scope", Scopes.PROJECT); + query.setParameter("qualifier", Qualifiers.LIBRARY); query.setParameter("last", Boolean.TRUE); List snapshots = query.getResultList(); if (snapshots.isEmpty()) { diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/MemoryOptimizer.java b/sonar-batch/src/main/java/org/sonar/batch/index/MemoryOptimizer.java index 0fa0610d900..aec3e771324 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/MemoryOptimizer.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/MemoryOptimizer.java @@ -82,7 +82,7 @@ public class MemoryOptimizer { } public void flushMemory() { - if (LOG.isDebugEnabled() && loadedMeasures.size() > 0) { + if (LOG.isDebugEnabled() && !loadedMeasures.isEmpty()) { LOG.debug("Flush " + loadedMeasures.size() + " data measures from memory: "); } for (Measure measure : loadedMeasures) { @@ -92,6 +92,6 @@ public class MemoryOptimizer { } boolean isTracked(Long measureId) { - return dataIdByMeasureId.get(measureId)!=null; + return dataIdByMeasureId.get(measureId) != null; } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/ViolationPersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/ViolationPersister.java index 0613954e4cc..c840adbfa78 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/ViolationPersister.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/ViolationPersister.java @@ -68,7 +68,7 @@ public final class ViolationPersister { private RuleFailureModel mergeModel(Violation violation, RuleFailureModel merge) { Rule rule = ruleFinder.findByKey(violation.getRule().getRepositoryKey(), violation.getRule().getKey()); merge.setRuleId(rule.getId()); - merge.setPriority(violation.getPriority()); + merge.setPriority(violation.getSeverity()); merge.setLine(violation.getLineId()); merge.setMessage(violation.getMessage()); merge.setCost(violation.getCost()); diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/DecoratorsExecutor.java b/sonar-batch/src/main/java/org/sonar/batch/phases/DecoratorsExecutor.java index 15532994702..a8f7e3ab862 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/phases/DecoratorsExecutor.java +++ b/sonar-batch/src/main/java/org/sonar/batch/phases/DecoratorsExecutor.java @@ -121,7 +121,7 @@ public class DecoratorsExecutor implements BatchComponent { } String getMessage() { - StringBuilder sb = new StringBuilder("Decorator time:" + SystemUtils.LINE_SEPARATOR); + StringBuilder sb = new StringBuilder("Decorator time:").append(SystemUtils.LINE_SEPARATOR); for (Decorator decorator : decorators) { sb.append("\t").append(decorator.toString()).append(": ").append(durations.get(decorator)).append("ms").append(SystemUtils.LINE_SEPARATOR); } -- 2.39.5