aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorEvgeny Mandrikov <mandrikov@gmail.com>2011-04-19 19:36:14 +0400
committerEvgeny Mandrikov <mandrikov@gmail.com>2011-04-20 13:32:53 +0400
commitee7b180068da45ddbe70031a4d2cdd94c6c377d3 (patch)
tree5b60ef6ee0d89a935c249b4df79165c63b53a6c9 /sonar-batch
parentc6d954e8c39d9d9555ceb2e966feefef1c6b3c0b (diff)
downloadsonarqube-ee7b180068da45ddbe70031a4d2cdd94c6c377d3.tar.gz
sonarqube-ee7b180068da45ddbe70031a4d2cdd94c6c377d3.zip
Fix crlf
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/DefaultDecoratorContext.java350
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java1098
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/ViolationPersister.java176
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java476
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/index/ViolationPersisterTest.java192
-rw-r--r--sonar-batch/src/test/resources/org/sonar/batch/index/ViolationPersisterTest/shared.xml48
-rw-r--r--sonar-batch/src/test/resources/org/sonar/batch/index/ViolationPersisterTest/shouldCopyPermanentIdFromPastViolation-result.xml52
-rw-r--r--sonar-batch/src/test/resources/org/sonar/batch/index/ViolationPersisterTest/shouldCopySwitchedOffFromPastViolation-result.xml54
-rw-r--r--sonar-batch/src/test/resources/org/sonar/batch/index/ViolationPersisterTest/shouldInsertViolations-result.xml50
9 files changed, 1248 insertions, 1248 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/DefaultDecoratorContext.java b/sonar-batch/src/main/java/org/sonar/batch/DefaultDecoratorContext.java
index 4ca401c310a..3e5caae2957 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/DefaultDecoratorContext.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/DefaultDecoratorContext.java
@@ -1,175 +1,175 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.batch;
-
-import java.util.Collection;
-import java.util.Date;
-import java.util.List;
-import java.util.Set;
-
-import com.google.common.collect.Lists;
-import org.sonar.api.batch.DecoratorContext;
-import org.sonar.api.batch.Event;
-import org.sonar.api.batch.SonarIndex;
-import org.sonar.api.design.Dependency;
-import org.sonar.api.measures.Measure;
-import org.sonar.api.measures.MeasuresFilter;
-import org.sonar.api.measures.MeasuresFilters;
-import org.sonar.api.measures.Metric;
-import org.sonar.api.resources.Project;
-import org.sonar.api.resources.Resource;
-import org.sonar.api.rules.Violation;
-import org.sonar.api.violations.ViolationQuery;
-
-public class DefaultDecoratorContext implements DecoratorContext {
-
- private SonarIndex index;
- private Resource resource;
- private boolean readOnly = false;
-
- private List<DecoratorContext> childrenContexts;
-
- public DefaultDecoratorContext(Resource resource,
- SonarIndex index,
- List<DecoratorContext> childrenContexts) {
- this.index = index;
- this.resource = resource;
- this.childrenContexts = childrenContexts;
- }
-
- public DefaultDecoratorContext setReadOnly(boolean b) {
- readOnly = b;
- childrenContexts = null;
- return this;
- }
-
- public Project getProject() {
- return index.getProject();
- }
-
- public List<DecoratorContext> getChildren() {
- checkReadOnly("getModules");
- return childrenContexts;
- }
-
- private void checkReadOnly(String methodName) {
- if (readOnly) {
- throw new IllegalStateException("Method DecoratorContext." + methodName + "() can not be executed on children.");
- }
- }
-
- public <M> M getMeasures(MeasuresFilter<M> filter) {
- return index.getMeasures(resource, filter);
- }
-
- public Measure getMeasure(Metric metric) {
- return index.getMeasure(resource, metric);
- }
-
- public Collection<Measure> getChildrenMeasures(MeasuresFilter filter) {
- List<Measure> result = Lists.newArrayList();
- for (DecoratorContext childContext : childrenContexts) {
- Object childResult = childContext.getMeasures(filter);
- if (childResult != null) {
- if (childResult instanceof Collection) {
- result.addAll((Collection) childResult);
- } else {
- result.add((Measure) childResult);
- }
- }
- }
- return result;
- }
-
- public Collection<Measure> getChildrenMeasures(Metric metric) {
- return getChildrenMeasures(MeasuresFilters.metric(metric));
- }
-
- public Resource getResource() {
- return resource;
- }
-
- public DecoratorContext saveMeasure(Measure measure) {
- checkReadOnly("saveMeasure");
- index.addMeasure(resource, measure);
- return this;
- }
-
- public DecoratorContext saveMeasure(Metric metric, Double value) {
- checkReadOnly("saveMeasure");
- index.addMeasure(resource, new Measure(metric, value));
- return this;
- }
-
- /**
- * {@inheritDoc}
- */
- public List<Violation> getViolations(ViolationQuery violationQuery) {
- return index.getViolations(violationQuery);
- }
-
- /**
- * {@inheritDoc}
- */
- public List<Violation> getViolations() {
- return index.getViolations(resource);
- }
-
- public Dependency saveDependency(Dependency dependency) {
- checkReadOnly("addDependency");
- return index.addDependency(dependency);
- }
-
- public Set<Dependency> getDependencies() {
- return index.getDependencies();
- }
-
- public Collection<Dependency> getIncomingDependencies() {
- return index.getIncomingEdges(resource);
- }
-
- public Collection<Dependency> getOutgoingDependencies() {
- return index.getOutgoingEdges(resource);
- }
-
- public List<Event> getEvents() {
- return index.getEvents(resource);
- }
-
- public Event createEvent(String name, String description, String category, Date date) {
- return index.addEvent(resource, name, description, category, date);
- }
-
- public void deleteEvent(Event event) {
- index.deleteEvent(event);
- }
-
- public DefaultDecoratorContext saveViolation(Violation violation, boolean force) {
- if (violation.getResource() == null) {
- violation.setResource(resource);
- }
- index.addViolation(violation, force);
- return this;
- }
-
- public DefaultDecoratorContext saveViolation(Violation violation) {
- return saveViolation(violation, false);
- }
-}
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.batch;
+
+import java.util.Collection;
+import java.util.Date;
+import java.util.List;
+import java.util.Set;
+
+import com.google.common.collect.Lists;
+import org.sonar.api.batch.DecoratorContext;
+import org.sonar.api.batch.Event;
+import org.sonar.api.batch.SonarIndex;
+import org.sonar.api.design.Dependency;
+import org.sonar.api.measures.Measure;
+import org.sonar.api.measures.MeasuresFilter;
+import org.sonar.api.measures.MeasuresFilters;
+import org.sonar.api.measures.Metric;
+import org.sonar.api.resources.Project;
+import org.sonar.api.resources.Resource;
+import org.sonar.api.rules.Violation;
+import org.sonar.api.violations.ViolationQuery;
+
+public class DefaultDecoratorContext implements DecoratorContext {
+
+ private SonarIndex index;
+ private Resource resource;
+ private boolean readOnly = false;
+
+ private List<DecoratorContext> childrenContexts;
+
+ public DefaultDecoratorContext(Resource resource,
+ SonarIndex index,
+ List<DecoratorContext> childrenContexts) {
+ this.index = index;
+ this.resource = resource;
+ this.childrenContexts = childrenContexts;
+ }
+
+ public DefaultDecoratorContext setReadOnly(boolean b) {
+ readOnly = b;
+ childrenContexts = null;
+ return this;
+ }
+
+ public Project getProject() {
+ return index.getProject();
+ }
+
+ public List<DecoratorContext> getChildren() {
+ checkReadOnly("getModules");
+ return childrenContexts;
+ }
+
+ private void checkReadOnly(String methodName) {
+ if (readOnly) {
+ throw new IllegalStateException("Method DecoratorContext." + methodName + "() can not be executed on children.");
+ }
+ }
+
+ public <M> M getMeasures(MeasuresFilter<M> filter) {
+ return index.getMeasures(resource, filter);
+ }
+
+ public Measure getMeasure(Metric metric) {
+ return index.getMeasure(resource, metric);
+ }
+
+ public Collection<Measure> getChildrenMeasures(MeasuresFilter filter) {
+ List<Measure> result = Lists.newArrayList();
+ for (DecoratorContext childContext : childrenContexts) {
+ Object childResult = childContext.getMeasures(filter);
+ if (childResult != null) {
+ if (childResult instanceof Collection) {
+ result.addAll((Collection) childResult);
+ } else {
+ result.add((Measure) childResult);
+ }
+ }
+ }
+ return result;
+ }
+
+ public Collection<Measure> getChildrenMeasures(Metric metric) {
+ return getChildrenMeasures(MeasuresFilters.metric(metric));
+ }
+
+ public Resource getResource() {
+ return resource;
+ }
+
+ public DecoratorContext saveMeasure(Measure measure) {
+ checkReadOnly("saveMeasure");
+ index.addMeasure(resource, measure);
+ return this;
+ }
+
+ public DecoratorContext saveMeasure(Metric metric, Double value) {
+ checkReadOnly("saveMeasure");
+ index.addMeasure(resource, new Measure(metric, value));
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public List<Violation> getViolations(ViolationQuery violationQuery) {
+ return index.getViolations(violationQuery);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public List<Violation> getViolations() {
+ return index.getViolations(resource);
+ }
+
+ public Dependency saveDependency(Dependency dependency) {
+ checkReadOnly("addDependency");
+ return index.addDependency(dependency);
+ }
+
+ public Set<Dependency> getDependencies() {
+ return index.getDependencies();
+ }
+
+ public Collection<Dependency> getIncomingDependencies() {
+ return index.getIncomingEdges(resource);
+ }
+
+ public Collection<Dependency> getOutgoingDependencies() {
+ return index.getOutgoingEdges(resource);
+ }
+
+ public List<Event> getEvents() {
+ return index.getEvents(resource);
+ }
+
+ public Event createEvent(String name, String description, String category, Date date) {
+ return index.addEvent(resource, name, description, category, date);
+ }
+
+ public void deleteEvent(Event event) {
+ index.deleteEvent(event);
+ }
+
+ public DefaultDecoratorContext saveViolation(Violation violation, boolean force) {
+ if (violation.getResource() == null) {
+ violation.setResource(resource);
+ }
+ index.addViolation(violation, force);
+ return this;
+ }
+
+ public DefaultDecoratorContext saveViolation(Violation violation) {
+ return saveViolation(violation, false);
+ }
+}
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 b8f42c96040..5b4dd14c5fd 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
@@ -1,549 +1,549 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.batch.index;
-
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
-import org.apache.commons.lang.ObjectUtils;
-import org.apache.commons.lang.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.sonar.api.batch.Event;
-import org.sonar.api.batch.SonarIndex;
-import org.sonar.api.database.model.ResourceModel;
-import org.sonar.api.design.Dependency;
-import org.sonar.api.measures.*;
-import org.sonar.api.profiles.RulesProfile;
-import org.sonar.api.resources.*;
-import org.sonar.api.rules.ActiveRule;
-import org.sonar.api.rules.Violation;
-import org.sonar.api.utils.SonarException;
-import org.sonar.api.violations.ViolationQuery;
-import org.sonar.batch.DefaultResourceCreationLock;
-import org.sonar.batch.ProjectTree;
-import org.sonar.batch.ResourceFilters;
-import org.sonar.batch.ViolationFilters;
-
-import java.util.*;
-
-public class DefaultIndex extends SonarIndex {
-
- private static final Logger LOG = LoggerFactory.getLogger(DefaultIndex.class);
-
- private RulesProfile profile;
- private PersistenceManager persistence;
- private DefaultResourceCreationLock lock;
- private MetricFinder metricFinder;
-
- // filters
- private ViolationFilters violationFilters;
- private ResourceFilters resourceFilters;
-
- // caches
- private Project currentProject;
- private Map<Resource, Bucket> buckets = 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();
- private ProjectTree projectTree;
-
- public DefaultIndex(PersistenceManager persistence, DefaultResourceCreationLock lock, ProjectTree projectTree, MetricFinder metricFinder) {
- this.persistence = persistence;
- this.lock = lock;
- this.projectTree = projectTree;
- this.metricFinder = metricFinder;
- }
-
- public void start() {
- Project rootProject = projectTree.getRootProject();
- doStart(rootProject);
- }
-
- void doStart(Project rootProject) {
- Bucket bucket = new Bucket(rootProject);
- buckets.put(rootProject, bucket);
- persistence.saveProject(rootProject, null);
- currentProject = rootProject;
-
- for (Project project : rootProject.getModules()) {
- addProject(project);
- }
- }
-
- private void addProject(Project project) {
- addResource(project);
- for (Project module : project.getModules()) {
- addProject(module);
- }
- }
-
- public Project getProject() {
- return currentProject;
- }
-
- public void setCurrentProject(Project project, ResourceFilters resourceFilters, ViolationFilters violationFilters, RulesProfile profile) {
- this.currentProject = project;
-
- // the following components depend on the current project, so they need to be reloaded.
- this.resourceFilters = resourceFilters;
- this.violationFilters = violationFilters;
- this.profile = profile;
- }
-
- /**
- * Keep only project stuff
- */
- public void clear() {
- Iterator<Map.Entry<Resource, Bucket>> it = buckets.entrySet().iterator();
- while (it.hasNext()) {
- Map.Entry<Resource, Bucket> entry = it.next();
- Resource resource = entry.getKey();
- if (!ResourceUtils.isSet(resource)) {
- entry.getValue().clear();
- it.remove();
- }
- }
-
- Set<Dependency> projectDependencies = getDependenciesBetweenProjects();
- dependencies.clear();
- incomingDependenciesByResource.clear();
- outgoingDependenciesByResource.clear();
- for (Dependency projectDependency : projectDependencies) {
- projectDependency.setId(null);
- registerDependency(projectDependency);
- }
-
- lock.unlock();
- }
-
- public Measure getMeasure(Resource resource, Metric metric) {
- Bucket bucket = buckets.get(resource);
- if (bucket != null) {
- Measure measure = bucket.getMeasures(MeasuresFilters.metric(metric));
- if (measure != null) {
- return persistence.reloadMeasure(measure);
- }
- }
- return null;
- }
-
- public <M> M getMeasures(Resource resource, MeasuresFilter<M> filter) {
- Bucket bucket = buckets.get(resource);
- if (bucket != null) {
- // TODO the data measures which are not kept in memory are not reloaded yet. Use getMeasure().
- return bucket.getMeasures(filter);
- }
- return null;
- }
-
- /**
- * the measure is updated if it's already registered.
- */
- public Measure addMeasure(Resource resource, Measure measure) {
- Bucket bucket = checkIndexed(resource);
- if (bucket != null && !bucket.isExcluded()) {
- Metric metric = metricFinder.findByKey(measure.getMetricKey());
- if (metric == null) {
- throw new SonarException("Unknown metric: " + measure.getMetricKey());
- }
- measure.setMetric(metric);
- bucket.addMeasure(measure);
-
- if (measure.getPersistenceMode().useDatabase()) {
- persistence.saveMeasure(resource, measure);
- }
- }
- return measure;
- }
-
- //
- //
- //
- // DEPENDENCIES
- //
- //
- //
-
- public Dependency addDependency(Dependency dependency) {
- Dependency existingDep = getEdge(dependency.getFrom(), dependency.getTo());
- if (existingDep != null) {
- return existingDep;
- }
-
- Dependency parentDependency = dependency.getParent();
- if (parentDependency != null) {
- addDependency(parentDependency);
- }
-
- if (registerDependency(dependency)) {
- persistence.saveDependency(currentProject, dependency, parentDependency);
- }
- return dependency;
- }
-
- boolean registerDependency(Dependency dependency) {
- Bucket fromBucket = doIndex(dependency.getFrom());
- Bucket toBucket = doIndex(dependency.getTo());
-
- if (fromBucket != null && !fromBucket.isExcluded() && toBucket != null && !toBucket.isExcluded()) {
- dependencies.add(dependency);
- registerOutgoingDependency(dependency);
- registerIncomingDependency(dependency);
- return true;
- }
- return false;
- }
-
- private void registerOutgoingDependency(Dependency dependency) {
- Map<Resource, Dependency> outgoingDeps = outgoingDependenciesByResource.get(dependency.getFrom());
- if (outgoingDeps == null) {
- outgoingDeps = new HashMap<Resource, Dependency>();
- outgoingDependenciesByResource.put(dependency.getFrom(), outgoingDeps);
- }
- outgoingDeps.put(dependency.getTo(), dependency);
- }
-
- private void registerIncomingDependency(Dependency dependency) {
- Map<Resource, Dependency> incomingDeps = incomingDependenciesByResource.get(dependency.getTo());
- if (incomingDeps == null) {
- incomingDeps = new HashMap<Resource, Dependency>();
- incomingDependenciesByResource.put(dependency.getTo(), incomingDeps);
- }
- incomingDeps.put(dependency.getFrom(), dependency);
- }
-
- public Set<Dependency> getDependencies() {
- return dependencies;
- }
-
- public Dependency getEdge(Resource from, Resource to) {
- Map<Resource, Dependency> map = outgoingDependenciesByResource.get(from);
- if (map != null) {
- return map.get(to);
- }
- return null;
- }
-
- public boolean hasEdge(Resource from, Resource to) {
- return getEdge(from, to) != null;
- }
-
- public Set<Resource> getVertices() {
- return buckets.keySet();
- }
-
- public Collection<Dependency> getOutgoingEdges(Resource from) {
- Map<Resource, Dependency> deps = outgoingDependenciesByResource.get(from);
- if (deps != null) {
- return deps.values();
- }
- return Collections.emptyList();
- }
-
- public Collection<Dependency> getIncomingEdges(Resource to) {
- Map<Resource, Dependency> deps = incomingDependenciesByResource.get(to);
- if (deps != null) {
- return deps.values();
- }
- return Collections.emptyList();
- }
-
- Set<Dependency> getDependenciesBetweenProjects() {
- Set<Dependency> result = Sets.newLinkedHashSet();
- for (Dependency dependency : dependencies) {
- if (ResourceUtils.isSet(dependency.getFrom()) || ResourceUtils.isSet(dependency.getTo())) {
- result.add(dependency);
- }
- }
- return result;
- }
-
- //
- //
- //
- // VIOLATIONS
- //
- //
- //
-
- /**
- * {@inheritDoc}
- */
- public List<Violation> getViolations(ViolationQuery violationQuery) {
- Resource resource = violationQuery.getResource();
- if (resource == null) {
- throw new IllegalArgumentException("A resource must be set on the ViolationQuery in order to search for violations.");
- }
- Bucket bucket = buckets.get(resource);
- if (bucket == null) {
- return Collections.emptyList();
- }
- List<Violation> filteredViolations = Lists.newArrayList();
- boolean ignoreSwitchedOff = violationQuery.ignoreSwitchedOff();
- for (Violation violation : bucket.getViolations()) {
- if ( ignoreSwitchedOff && violation.isSwitchedOff()) {
- continue;
- }
- filteredViolations.add(violation);
- }
- return filteredViolations;
- }
-
- public void addViolation(Violation violation, boolean force) {
- Resource resource = violation.getResource();
- if (resource == null) {
- violation.setResource(currentProject);
- } else if (!Scopes.isHigherThanOrEquals(resource, Scopes.FILE)) {
- throw new IllegalArgumentException("Violations are only supported on files, directories and project");
- }
-
- if (violation.getRule() == null) {
- LOG.warn("Rule is null, ignoring violation {}", violation);
- return;
- }
-
- Bucket bucket = checkIndexed(resource);
- if (bucket != null && !bucket.isExcluded()) {
- boolean isIgnored = !force && violationFilters != null && violationFilters.isIgnored(violation);
- if (!isIgnored) {
- ActiveRule activeRule = profile.getActiveRule(violation.getRule());
- if (activeRule == null) {
- if (currentProject.getReuseExistingRulesConfig()) {
- violation.setSeverity(violation.getRule().getSeverity());
- doAddViolation(violation, bucket);
-
- } else {
- LoggerFactory.getLogger(getClass()).debug("Rule is not activated, ignoring violation {}", violation);
- }
-
- } else {
- violation.setSeverity(activeRule.getSeverity());
- doAddViolation(violation, bucket);
- }
- }
- }
- }
-
- private void doAddViolation(Violation violation, Bucket bucket) {
- bucket.addViolation(violation);
- }
-
- //
- //
- //
- // LINKS
- //
- //
- //
-
- public void addLink(ProjectLink link) {
- persistence.saveLink(currentProject, link);
- }
-
- public void deleteLink(String key) {
- persistence.deleteLink(currentProject, key);
- }
-
- //
- //
- //
- // EVENTS
- //
- //
- //
-
- public List<Event> getEvents(Resource resource) {
- // currently events are not cached in memory
- return persistence.getEvents(resource);
- }
-
- public void deleteEvent(Event event) {
- persistence.deleteEvent(event);
- }
-
- public Event addEvent(Resource resource, String name, String description, String category, Date date) {
- Event event = new Event(name, description, category);
- event.setDate(date);
- persistence.saveEvent(resource, event);
- return null;
- }
-
- public void setSource(Resource reference, String source) {
- Bucket bucket = checkIndexed(reference);
- if (bucket != null && !bucket.isExcluded()) {
- persistence.setSource(reference, source);
- }
- }
-
- /**
- * Does nothing if the resource is already registered.
- */
- public Resource addResource(Resource resource) {
- Bucket bucket = doIndex(resource);
- return bucket != null ? bucket.getResource() : null;
- }
-
- public <R extends Resource> R getResource(R reference) {
- Bucket bucket = buckets.get(reference);
- if (bucket != null) {
- return (R) bucket.getResource();
- }
- return null;
- }
-
- static String createUID(Project project, Resource resource) {
- String uid = resource.getKey();
- if (!StringUtils.equals(Scopes.PROJECT, resource.getScope())) {
- // not a project nor a library
- uid = new StringBuilder(ResourceModel.KEY_SIZE)
- .append(project.getKey())
- .append(':')
- .append(resource.getKey())
- .toString();
- }
- return uid;
- }
-
- private boolean checkExclusion(Resource resource, Bucket parent) {
- boolean excluded = (parent != null && parent.isExcluded()) || (resourceFilters != null && resourceFilters.isExcluded(resource));
- resource.setExcluded(excluded);
- return excluded;
- }
-
- public List<Resource> getChildren(Resource resource) {
- return getChildren(resource, false);
- }
-
- public List<Resource> getChildren(Resource resource, boolean acceptExcluded) {
- List<Resource> children = Lists.newLinkedList();
- Bucket bucket = getBucket(resource, acceptExcluded);
- if (bucket != null) {
- for (Bucket childBucket : bucket.getChildren()) {
- if (acceptExcluded || !childBucket.isExcluded()) {
- children.add(childBucket.getResource());
- }
- }
- }
- return children;
- }
-
- public Resource getParent(Resource resource) {
- Bucket bucket = getBucket(resource, false);
- if (bucket != null && bucket.getParent() != null) {
- return bucket.getParent().getResource();
- }
- return null;
- }
-
- public boolean index(Resource resource) {
- Bucket bucket = doIndex(resource);
- return bucket != null && !bucket.isExcluded();
- }
-
- private Bucket doIndex(Resource resource) {
- if (resource.getParent() != null) {
- doIndex(resource.getParent());
- }
- return doIndex(resource, resource.getParent());
- }
-
- public boolean index(Resource resource, Resource parentReference) {
- Bucket bucket = doIndex(resource, parentReference);
- return bucket != null && !bucket.isExcluded();
- }
-
- private Bucket doIndex(Resource resource, Resource parentReference) {
- Bucket bucket = buckets.get(resource);
- if (bucket != null) {
- return bucket;
- }
-
- checkLock(resource);
-
- Resource parent = null;
- if (!ResourceUtils.isLibrary(resource)) {
- // a library has no parent
- parent = (Resource) ObjectUtils.defaultIfNull(parentReference, currentProject);
- }
-
- Bucket parentBucket = getBucket(parent, true);
- if (parentBucket == null && parent != null) {
- LOG.warn("Resource ignored, parent is not indexed: " + resource);
- return null;
- }
-
- resource.setEffectiveKey(createUID(currentProject, resource));
- bucket = new Bucket(resource).setParent(parentBucket);
- buckets.put(resource, bucket);
-
- boolean excluded = checkExclusion(resource, parentBucket);
- if (!excluded) {
- persistence.saveResource(currentProject, resource, (parentBucket != null ? parentBucket.getResource() : null));
- }
- return bucket;
- }
-
- private void checkLock(Resource resource) {
- if (lock.isLocked() && !ResourceUtils.isLibrary(resource)) {
- if (lock.isFailWhenLocked()) {
- throw new SonarException("Index is locked, resource can not be indexed: " + resource);
- }
- }
- }
-
- private Bucket checkIndexed(Resource resource) {
- Bucket bucket = getBucket(resource, true);
- if (bucket == null) {
- if (lock.isLocked()) {
- if (lock.isFailWhenLocked()) {
- throw new ResourceNotIndexedException(resource);
- }
- LOG.warn("Resource will be ignored in next Sonar versions, index is locked: " + resource);
- }
- if (Scopes.isDirectory(resource) || Scopes.isFile(resource)) {
- bucket = doIndex(resource);
- } else if (!lock.isLocked()) {
- LOG.warn("Resource will be ignored in next Sonar versions, it must be indexed before adding data: " + resource);
- }
- }
- return bucket;
- }
-
- public boolean isExcluded(Resource reference) {
- Bucket bucket = getBucket(reference, true);
- return bucket != null && bucket.isExcluded();
- }
-
- public boolean isIndexed(Resource reference, boolean acceptExcluded) {
- return getBucket(reference, acceptExcluded) != null;
- }
-
- private Bucket getBucket(Resource resource, boolean acceptExcluded) {
- Bucket bucket = null;
- if (resource != null) {
- bucket = buckets.get(resource);
- if (!acceptExcluded && bucket != null && bucket.isExcluded()) {
- bucket = null;
- }
- }
- return bucket;
- }
-}
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.batch.index;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+import org.apache.commons.lang.ObjectUtils;
+import org.apache.commons.lang.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.sonar.api.batch.Event;
+import org.sonar.api.batch.SonarIndex;
+import org.sonar.api.database.model.ResourceModel;
+import org.sonar.api.design.Dependency;
+import org.sonar.api.measures.*;
+import org.sonar.api.profiles.RulesProfile;
+import org.sonar.api.resources.*;
+import org.sonar.api.rules.ActiveRule;
+import org.sonar.api.rules.Violation;
+import org.sonar.api.utils.SonarException;
+import org.sonar.api.violations.ViolationQuery;
+import org.sonar.batch.DefaultResourceCreationLock;
+import org.sonar.batch.ProjectTree;
+import org.sonar.batch.ResourceFilters;
+import org.sonar.batch.ViolationFilters;
+
+import java.util.*;
+
+public class DefaultIndex extends SonarIndex {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DefaultIndex.class);
+
+ private RulesProfile profile;
+ private PersistenceManager persistence;
+ private DefaultResourceCreationLock lock;
+ private MetricFinder metricFinder;
+
+ // filters
+ private ViolationFilters violationFilters;
+ private ResourceFilters resourceFilters;
+
+ // caches
+ private Project currentProject;
+ private Map<Resource, Bucket> buckets = 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();
+ private ProjectTree projectTree;
+
+ public DefaultIndex(PersistenceManager persistence, DefaultResourceCreationLock lock, ProjectTree projectTree, MetricFinder metricFinder) {
+ this.persistence = persistence;
+ this.lock = lock;
+ this.projectTree = projectTree;
+ this.metricFinder = metricFinder;
+ }
+
+ public void start() {
+ Project rootProject = projectTree.getRootProject();
+ doStart(rootProject);
+ }
+
+ void doStart(Project rootProject) {
+ Bucket bucket = new Bucket(rootProject);
+ buckets.put(rootProject, bucket);
+ persistence.saveProject(rootProject, null);
+ currentProject = rootProject;
+
+ for (Project project : rootProject.getModules()) {
+ addProject(project);
+ }
+ }
+
+ private void addProject(Project project) {
+ addResource(project);
+ for (Project module : project.getModules()) {
+ addProject(module);
+ }
+ }
+
+ public Project getProject() {
+ return currentProject;
+ }
+
+ public void setCurrentProject(Project project, ResourceFilters resourceFilters, ViolationFilters violationFilters, RulesProfile profile) {
+ this.currentProject = project;
+
+ // the following components depend on the current project, so they need to be reloaded.
+ this.resourceFilters = resourceFilters;
+ this.violationFilters = violationFilters;
+ this.profile = profile;
+ }
+
+ /**
+ * Keep only project stuff
+ */
+ public void clear() {
+ Iterator<Map.Entry<Resource, Bucket>> it = buckets.entrySet().iterator();
+ while (it.hasNext()) {
+ Map.Entry<Resource, Bucket> entry = it.next();
+ Resource resource = entry.getKey();
+ if (!ResourceUtils.isSet(resource)) {
+ entry.getValue().clear();
+ it.remove();
+ }
+ }
+
+ Set<Dependency> projectDependencies = getDependenciesBetweenProjects();
+ dependencies.clear();
+ incomingDependenciesByResource.clear();
+ outgoingDependenciesByResource.clear();
+ for (Dependency projectDependency : projectDependencies) {
+ projectDependency.setId(null);
+ registerDependency(projectDependency);
+ }
+
+ lock.unlock();
+ }
+
+ public Measure getMeasure(Resource resource, Metric metric) {
+ Bucket bucket = buckets.get(resource);
+ if (bucket != null) {
+ Measure measure = bucket.getMeasures(MeasuresFilters.metric(metric));
+ if (measure != null) {
+ return persistence.reloadMeasure(measure);
+ }
+ }
+ return null;
+ }
+
+ public <M> M getMeasures(Resource resource, MeasuresFilter<M> filter) {
+ Bucket bucket = buckets.get(resource);
+ if (bucket != null) {
+ // TODO the data measures which are not kept in memory are not reloaded yet. Use getMeasure().
+ return bucket.getMeasures(filter);
+ }
+ return null;
+ }
+
+ /**
+ * the measure is updated if it's already registered.
+ */
+ public Measure addMeasure(Resource resource, Measure measure) {
+ Bucket bucket = checkIndexed(resource);
+ if (bucket != null && !bucket.isExcluded()) {
+ Metric metric = metricFinder.findByKey(measure.getMetricKey());
+ if (metric == null) {
+ throw new SonarException("Unknown metric: " + measure.getMetricKey());
+ }
+ measure.setMetric(metric);
+ bucket.addMeasure(measure);
+
+ if (measure.getPersistenceMode().useDatabase()) {
+ persistence.saveMeasure(resource, measure);
+ }
+ }
+ return measure;
+ }
+
+ //
+ //
+ //
+ // DEPENDENCIES
+ //
+ //
+ //
+
+ public Dependency addDependency(Dependency dependency) {
+ Dependency existingDep = getEdge(dependency.getFrom(), dependency.getTo());
+ if (existingDep != null) {
+ return existingDep;
+ }
+
+ Dependency parentDependency = dependency.getParent();
+ if (parentDependency != null) {
+ addDependency(parentDependency);
+ }
+
+ if (registerDependency(dependency)) {
+ persistence.saveDependency(currentProject, dependency, parentDependency);
+ }
+ return dependency;
+ }
+
+ boolean registerDependency(Dependency dependency) {
+ Bucket fromBucket = doIndex(dependency.getFrom());
+ Bucket toBucket = doIndex(dependency.getTo());
+
+ if (fromBucket != null && !fromBucket.isExcluded() && toBucket != null && !toBucket.isExcluded()) {
+ dependencies.add(dependency);
+ registerOutgoingDependency(dependency);
+ registerIncomingDependency(dependency);
+ return true;
+ }
+ return false;
+ }
+
+ private void registerOutgoingDependency(Dependency dependency) {
+ Map<Resource, Dependency> outgoingDeps = outgoingDependenciesByResource.get(dependency.getFrom());
+ if (outgoingDeps == null) {
+ outgoingDeps = new HashMap<Resource, Dependency>();
+ outgoingDependenciesByResource.put(dependency.getFrom(), outgoingDeps);
+ }
+ outgoingDeps.put(dependency.getTo(), dependency);
+ }
+
+ private void registerIncomingDependency(Dependency dependency) {
+ Map<Resource, Dependency> incomingDeps = incomingDependenciesByResource.get(dependency.getTo());
+ if (incomingDeps == null) {
+ incomingDeps = new HashMap<Resource, Dependency>();
+ incomingDependenciesByResource.put(dependency.getTo(), incomingDeps);
+ }
+ incomingDeps.put(dependency.getFrom(), dependency);
+ }
+
+ public Set<Dependency> getDependencies() {
+ return dependencies;
+ }
+
+ public Dependency getEdge(Resource from, Resource to) {
+ Map<Resource, Dependency> map = outgoingDependenciesByResource.get(from);
+ if (map != null) {
+ return map.get(to);
+ }
+ return null;
+ }
+
+ public boolean hasEdge(Resource from, Resource to) {
+ return getEdge(from, to) != null;
+ }
+
+ public Set<Resource> getVertices() {
+ return buckets.keySet();
+ }
+
+ public Collection<Dependency> getOutgoingEdges(Resource from) {
+ Map<Resource, Dependency> deps = outgoingDependenciesByResource.get(from);
+ if (deps != null) {
+ return deps.values();
+ }
+ return Collections.emptyList();
+ }
+
+ public Collection<Dependency> getIncomingEdges(Resource to) {
+ Map<Resource, Dependency> deps = incomingDependenciesByResource.get(to);
+ if (deps != null) {
+ return deps.values();
+ }
+ return Collections.emptyList();
+ }
+
+ Set<Dependency> getDependenciesBetweenProjects() {
+ Set<Dependency> result = Sets.newLinkedHashSet();
+ for (Dependency dependency : dependencies) {
+ if (ResourceUtils.isSet(dependency.getFrom()) || ResourceUtils.isSet(dependency.getTo())) {
+ result.add(dependency);
+ }
+ }
+ return result;
+ }
+
+ //
+ //
+ //
+ // VIOLATIONS
+ //
+ //
+ //
+
+ /**
+ * {@inheritDoc}
+ */
+ public List<Violation> getViolations(ViolationQuery violationQuery) {
+ Resource resource = violationQuery.getResource();
+ if (resource == null) {
+ throw new IllegalArgumentException("A resource must be set on the ViolationQuery in order to search for violations.");
+ }
+ Bucket bucket = buckets.get(resource);
+ if (bucket == null) {
+ return Collections.emptyList();
+ }
+ List<Violation> filteredViolations = Lists.newArrayList();
+ boolean ignoreSwitchedOff = violationQuery.ignoreSwitchedOff();
+ for (Violation violation : bucket.getViolations()) {
+ if ( ignoreSwitchedOff && violation.isSwitchedOff()) {
+ continue;
+ }
+ filteredViolations.add(violation);
+ }
+ return filteredViolations;
+ }
+
+ public void addViolation(Violation violation, boolean force) {
+ Resource resource = violation.getResource();
+ if (resource == null) {
+ violation.setResource(currentProject);
+ } else if (!Scopes.isHigherThanOrEquals(resource, Scopes.FILE)) {
+ throw new IllegalArgumentException("Violations are only supported on files, directories and project");
+ }
+
+ if (violation.getRule() == null) {
+ LOG.warn("Rule is null, ignoring violation {}", violation);
+ return;
+ }
+
+ Bucket bucket = checkIndexed(resource);
+ if (bucket != null && !bucket.isExcluded()) {
+ boolean isIgnored = !force && violationFilters != null && violationFilters.isIgnored(violation);
+ if (!isIgnored) {
+ ActiveRule activeRule = profile.getActiveRule(violation.getRule());
+ if (activeRule == null) {
+ if (currentProject.getReuseExistingRulesConfig()) {
+ violation.setSeverity(violation.getRule().getSeverity());
+ doAddViolation(violation, bucket);
+
+ } else {
+ LoggerFactory.getLogger(getClass()).debug("Rule is not activated, ignoring violation {}", violation);
+ }
+
+ } else {
+ violation.setSeverity(activeRule.getSeverity());
+ doAddViolation(violation, bucket);
+ }
+ }
+ }
+ }
+
+ private void doAddViolation(Violation violation, Bucket bucket) {
+ bucket.addViolation(violation);
+ }
+
+ //
+ //
+ //
+ // LINKS
+ //
+ //
+ //
+
+ public void addLink(ProjectLink link) {
+ persistence.saveLink(currentProject, link);
+ }
+
+ public void deleteLink(String key) {
+ persistence.deleteLink(currentProject, key);
+ }
+
+ //
+ //
+ //
+ // EVENTS
+ //
+ //
+ //
+
+ public List<Event> getEvents(Resource resource) {
+ // currently events are not cached in memory
+ return persistence.getEvents(resource);
+ }
+
+ public void deleteEvent(Event event) {
+ persistence.deleteEvent(event);
+ }
+
+ public Event addEvent(Resource resource, String name, String description, String category, Date date) {
+ Event event = new Event(name, description, category);
+ event.setDate(date);
+ persistence.saveEvent(resource, event);
+ return null;
+ }
+
+ public void setSource(Resource reference, String source) {
+ Bucket bucket = checkIndexed(reference);
+ if (bucket != null && !bucket.isExcluded()) {
+ persistence.setSource(reference, source);
+ }
+ }
+
+ /**
+ * Does nothing if the resource is already registered.
+ */
+ public Resource addResource(Resource resource) {
+ Bucket bucket = doIndex(resource);
+ return bucket != null ? bucket.getResource() : null;
+ }
+
+ public <R extends Resource> R getResource(R reference) {
+ Bucket bucket = buckets.get(reference);
+ if (bucket != null) {
+ return (R) bucket.getResource();
+ }
+ return null;
+ }
+
+ static String createUID(Project project, Resource resource) {
+ String uid = resource.getKey();
+ if (!StringUtils.equals(Scopes.PROJECT, resource.getScope())) {
+ // not a project nor a library
+ uid = new StringBuilder(ResourceModel.KEY_SIZE)
+ .append(project.getKey())
+ .append(':')
+ .append(resource.getKey())
+ .toString();
+ }
+ return uid;
+ }
+
+ private boolean checkExclusion(Resource resource, Bucket parent) {
+ boolean excluded = (parent != null && parent.isExcluded()) || (resourceFilters != null && resourceFilters.isExcluded(resource));
+ resource.setExcluded(excluded);
+ return excluded;
+ }
+
+ public List<Resource> getChildren(Resource resource) {
+ return getChildren(resource, false);
+ }
+
+ public List<Resource> getChildren(Resource resource, boolean acceptExcluded) {
+ List<Resource> children = Lists.newLinkedList();
+ Bucket bucket = getBucket(resource, acceptExcluded);
+ if (bucket != null) {
+ for (Bucket childBucket : bucket.getChildren()) {
+ if (acceptExcluded || !childBucket.isExcluded()) {
+ children.add(childBucket.getResource());
+ }
+ }
+ }
+ return children;
+ }
+
+ public Resource getParent(Resource resource) {
+ Bucket bucket = getBucket(resource, false);
+ if (bucket != null && bucket.getParent() != null) {
+ return bucket.getParent().getResource();
+ }
+ return null;
+ }
+
+ public boolean index(Resource resource) {
+ Bucket bucket = doIndex(resource);
+ return bucket != null && !bucket.isExcluded();
+ }
+
+ private Bucket doIndex(Resource resource) {
+ if (resource.getParent() != null) {
+ doIndex(resource.getParent());
+ }
+ return doIndex(resource, resource.getParent());
+ }
+
+ public boolean index(Resource resource, Resource parentReference) {
+ Bucket bucket = doIndex(resource, parentReference);
+ return bucket != null && !bucket.isExcluded();
+ }
+
+ private Bucket doIndex(Resource resource, Resource parentReference) {
+ Bucket bucket = buckets.get(resource);
+ if (bucket != null) {
+ return bucket;
+ }
+
+ checkLock(resource);
+
+ Resource parent = null;
+ if (!ResourceUtils.isLibrary(resource)) {
+ // a library has no parent
+ parent = (Resource) ObjectUtils.defaultIfNull(parentReference, currentProject);
+ }
+
+ Bucket parentBucket = getBucket(parent, true);
+ if (parentBucket == null && parent != null) {
+ LOG.warn("Resource ignored, parent is not indexed: " + resource);
+ return null;
+ }
+
+ resource.setEffectiveKey(createUID(currentProject, resource));
+ bucket = new Bucket(resource).setParent(parentBucket);
+ buckets.put(resource, bucket);
+
+ boolean excluded = checkExclusion(resource, parentBucket);
+ if (!excluded) {
+ persistence.saveResource(currentProject, resource, (parentBucket != null ? parentBucket.getResource() : null));
+ }
+ return bucket;
+ }
+
+ private void checkLock(Resource resource) {
+ if (lock.isLocked() && !ResourceUtils.isLibrary(resource)) {
+ if (lock.isFailWhenLocked()) {
+ throw new SonarException("Index is locked, resource can not be indexed: " + resource);
+ }
+ }
+ }
+
+ private Bucket checkIndexed(Resource resource) {
+ Bucket bucket = getBucket(resource, true);
+ if (bucket == null) {
+ if (lock.isLocked()) {
+ if (lock.isFailWhenLocked()) {
+ throw new ResourceNotIndexedException(resource);
+ }
+ LOG.warn("Resource will be ignored in next Sonar versions, index is locked: " + resource);
+ }
+ if (Scopes.isDirectory(resource) || Scopes.isFile(resource)) {
+ bucket = doIndex(resource);
+ } else if (!lock.isLocked()) {
+ LOG.warn("Resource will be ignored in next Sonar versions, it must be indexed before adding data: " + resource);
+ }
+ }
+ return bucket;
+ }
+
+ public boolean isExcluded(Resource reference) {
+ Bucket bucket = getBucket(reference, true);
+ return bucket != null && bucket.isExcluded();
+ }
+
+ public boolean isIndexed(Resource reference, boolean acceptExcluded) {
+ return getBucket(reference, acceptExcluded) != null;
+ }
+
+ private Bucket getBucket(Resource resource, boolean acceptExcluded) {
+ Bucket bucket = null;
+ if (resource != null) {
+ bucket = buckets.get(resource);
+ if (!acceptExcluded && bucket != null && bucket.isExcluded()) {
+ bucket = null;
+ }
+ }
+ return bucket;
+ }
+}
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 cc156125a5d..2334c0f8714 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
@@ -1,88 +1,88 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.batch.index;
-
-import org.sonar.api.database.DatabaseSession;
-import org.sonar.api.database.model.RuleFailureModel;
-import org.sonar.api.database.model.Snapshot;
-import org.sonar.api.resources.Project;
-import org.sonar.api.rules.Rule;
-import org.sonar.api.rules.RuleFinder;
-import org.sonar.api.rules.Violation;
-
-public final class ViolationPersister {
-
- private DatabaseSession session;
- private ResourcePersister resourcePersister;
- private RuleFinder ruleFinder;
-
- public ViolationPersister(DatabaseSession session, ResourcePersister resourcePersister, RuleFinder ruleFinder) {
- this.session = session;
- this.resourcePersister = resourcePersister;
- this.ruleFinder = ruleFinder;
- }
-
- void saveViolation(Project project, Violation violation) {
- saveViolation(project, violation, null, null);
- }
-
- public void saveViolation(Project project, Violation violation, RuleFailureModel pastViolation, String checksum) {
- Snapshot snapshot = resourcePersister.saveResource(project, violation.getResource());
-
- RuleFailureModel model = createModel(violation);
- if (pastViolation!=null) {
- model.setCreatedAt(pastViolation.getCreatedAt());
- model.setPermanentId(pastViolation.getPermanentId());
- model.setSwitchedOff(pastViolation.isSwitchedOff());
- } else {
- // avoid plugins setting date
- model.setCreatedAt(snapshot.getCreatedAt());
- }
- model.setSnapshotId(snapshot.getId());
- model.setChecksum(checksum);
- session.save(model);
-
- if (model.getPermanentId()==null) {
- model.setPermanentId(model.getId());
- session.save(model);
- }
-
- // the following fields can have been changed
- violation.setMessage(model.getMessage());// the message can be changed in the class RuleFailure (truncate + trim)
- violation.setCreatedAt(model.getCreatedAt());
- violation.setSwitchedOff(model.isSwitchedOff());
- }
-
- public void commit() {
- session.commit();
- }
-
- private RuleFailureModel createModel(Violation violation) {
- RuleFailureModel model = new RuleFailureModel();
- Rule rule = ruleFinder.findByKey(violation.getRule().getRepositoryKey(), violation.getRule().getKey());
- model.setRuleId(rule.getId());
- model.setPriority(violation.getSeverity());
- model.setLine(violation.getLineId());
- model.setMessage(violation.getMessage());
- model.setCost(violation.getCost());
- return model;
- }
-
-}
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.batch.index;
+
+import org.sonar.api.database.DatabaseSession;
+import org.sonar.api.database.model.RuleFailureModel;
+import org.sonar.api.database.model.Snapshot;
+import org.sonar.api.resources.Project;
+import org.sonar.api.rules.Rule;
+import org.sonar.api.rules.RuleFinder;
+import org.sonar.api.rules.Violation;
+
+public final class ViolationPersister {
+
+ private DatabaseSession session;
+ private ResourcePersister resourcePersister;
+ private RuleFinder ruleFinder;
+
+ public ViolationPersister(DatabaseSession session, ResourcePersister resourcePersister, RuleFinder ruleFinder) {
+ this.session = session;
+ this.resourcePersister = resourcePersister;
+ this.ruleFinder = ruleFinder;
+ }
+
+ void saveViolation(Project project, Violation violation) {
+ saveViolation(project, violation, null, null);
+ }
+
+ public void saveViolation(Project project, Violation violation, RuleFailureModel pastViolation, String checksum) {
+ Snapshot snapshot = resourcePersister.saveResource(project, violation.getResource());
+
+ RuleFailureModel model = createModel(violation);
+ if (pastViolation!=null) {
+ model.setCreatedAt(pastViolation.getCreatedAt());
+ model.setPermanentId(pastViolation.getPermanentId());
+ model.setSwitchedOff(pastViolation.isSwitchedOff());
+ } else {
+ // avoid plugins setting date
+ model.setCreatedAt(snapshot.getCreatedAt());
+ }
+ model.setSnapshotId(snapshot.getId());
+ model.setChecksum(checksum);
+ session.save(model);
+
+ if (model.getPermanentId()==null) {
+ model.setPermanentId(model.getId());
+ session.save(model);
+ }
+
+ // the following fields can have been changed
+ violation.setMessage(model.getMessage());// the message can be changed in the class RuleFailure (truncate + trim)
+ violation.setCreatedAt(model.getCreatedAt());
+ violation.setSwitchedOff(model.isSwitchedOff());
+ }
+
+ public void commit() {
+ session.commit();
+ }
+
+ private RuleFailureModel createModel(Violation violation) {
+ RuleFailureModel model = new RuleFailureModel();
+ Rule rule = ruleFinder.findByKey(violation.getRule().getRepositoryKey(), violation.getRule().getKey());
+ model.setRuleId(rule.getId());
+ model.setPriority(violation.getSeverity());
+ model.setLine(violation.getLineId());
+ model.setMessage(violation.getMessage());
+ model.setCost(violation.getCost());
+ return model;
+ }
+
+}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java
index 6457cf2cc43..48946226df4 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/index/DefaultIndexTest.java
@@ -1,238 +1,238 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.batch.index;
-
-import static org.hamcrest.Matchers.nullValue;
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import org.apache.commons.lang.StringUtils;
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.api.batch.ResourceFilter;
-import org.sonar.api.measures.CoreMetrics;
-import org.sonar.api.measures.Measure;
-import org.sonar.api.measures.MeasuresFilters;
-import org.sonar.api.measures.MetricFinder;
-import org.sonar.api.profiles.RulesProfile;
-import org.sonar.api.resources.Directory;
-import org.sonar.api.resources.File;
-import org.sonar.api.resources.Java;
-import org.sonar.api.resources.JavaPackage;
-import org.sonar.api.resources.Language;
-import org.sonar.api.resources.Library;
-import org.sonar.api.resources.Project;
-import org.sonar.api.resources.Qualifiers;
-import org.sonar.api.resources.Resource;
-import org.sonar.api.rules.Rule;
-import org.sonar.api.rules.Violation;
-import org.sonar.api.utils.SonarException;
-import org.sonar.api.violations.ViolationQuery;
-import org.sonar.batch.DefaultResourceCreationLock;
-import org.sonar.batch.ProjectTree;
-import org.sonar.batch.ResourceFilters;
-import org.sonar.batch.ViolationFilters;
-
-public class DefaultIndexTest {
-
- private DefaultIndex index = null;
- private DefaultResourceCreationLock lock;
- private Rule rule;
-
- @Before
- public void createIndex() {
- lock = new DefaultResourceCreationLock();
- MetricFinder metricFinder = mock(MetricFinder.class);
- when(metricFinder.findByKey("ncloc")).thenReturn(CoreMetrics.NCLOC);
-
- index = new DefaultIndex(mock(PersistenceManager.class), lock, mock(ProjectTree.class), metricFinder);
- Project project = new Project("project");
-
- ResourceFilter filter = new ResourceFilter() {
-
- public boolean isIgnored(Resource resource) {
- return StringUtils.containsIgnoreCase(resource.getKey(), "excluded");
- }
- };
- RulesProfile rulesProfile = RulesProfile.create();
- rule = Rule.create("repoKey", "ruleKey", "Rule");
- rulesProfile.activateRule(rule, null);
- index.setCurrentProject(project, new ResourceFilters(new ResourceFilter[] { filter }), new ViolationFilters(), rulesProfile);
- index.doStart(project);
- }
-
- @Test
- public void shouldCreateUID() {
- Project project = new Project("my_project");
- assertThat(DefaultIndex.createUID(project, project), is("my_project"));
-
- JavaPackage javaPackage = new JavaPackage("org.foo");
- assertThat(DefaultIndex.createUID(project, javaPackage), is("my_project:org.foo"));
-
- Library library = new Library("junit:junit", "4.7");
- assertThat(DefaultIndex.createUID(project, library), is("junit:junit"));
- }
-
- @Test
- public void shouldIndexParentOfDeprecatedFiles() {
- File file = new File("org/foo/Bar.java");
- assertThat(index.index(file), is(true));
-
- Directory reference = new Directory("org/foo");
- assertThat(index.getResource(reference).getName(), is("org/foo"));
- assertThat(index.isIndexed(reference, true), is(true));
- assertThat(index.isExcluded(reference), is(false));
- assertThat(index.getChildren(reference).size(), is(1));
- assertThat(index.getParent(reference), is(Project.class));
- }
-
- @Test
- public void shouldIndexTreeOfResources() {
- Directory directory = new Directory("org/foo");
- File file = new File("org/foo/Bar.java");
- file.setLanguage(Java.INSTANCE);
-
- assertThat(index.index(directory), is(true));
- assertThat(index.index(file, directory), is(true));
-
- File fileRef = new File("org/foo/Bar.java");
- assertThat(index.getResource(fileRef).getKey(), is("org/foo/Bar.java"));
- assertThat(index.getResource(fileRef).getLanguage(), is((Language) Java.INSTANCE));
- assertThat(index.isIndexed(fileRef, true), is(true));
- assertThat(index.isExcluded(fileRef), is(false));
- assertThat(index.getChildren(fileRef).size(), is(0));
- assertThat(index.getParent(fileRef), is(Directory.class));
- }
-
- @Test
- public void shouldIndexLibraryOutsideProjectTree() {
- Library lib = new Library("junit", "4.8");
- assertThat(index.index(lib), is(true));
-
- Library reference = new Library("junit", "4.8");
- assertThat(index.getResource(reference).getQualifier(), is(Qualifiers.LIBRARY));
- assertThat(index.isIndexed(reference, true), is(true));
- assertThat(index.isExcluded(reference), is(false));
- }
-
- @Test
- public void shouldNotIndexResourceIfParentNotIndexed() {
- Directory directory = new Directory("org/other");
- File file = new File("org/foo/Bar.java");
-
- assertThat(index.index(file, directory), is(false));
-
- File fileRef = new File("org/foo/Bar.java");
- assertThat(index.isIndexed(directory, true), is(false));
- assertThat(index.isIndexed(fileRef, true), is(false));
- assertThat(index.isExcluded(fileRef), is(false));
- assertThat(index.getChildren(fileRef).size(), is(0));
- assertThat(index.getParent(fileRef), nullValue());
- }
-
- /**
- * Only a warning is logged when index is locked.
- */
- @Test
- public void shouldIndexEvenIfLocked() {
- lock.lock();
-
- Directory dir = new Directory("org/foo");
- assertThat(index.index(dir), is(true));
- assertThat(index.isIndexed(dir, true), is(true));
- }
-
- @Test(expected = SonarException.class)
- public void shouldFailIfIndexingAndLocked() {
- lock.setFailWhenLocked(true);
- lock.lock();
-
- Directory dir = new Directory("org/foo");
- index.index(dir);
- }
-
- @Test
- public void shouldBeExcluded() {
- File file = new File("org/foo/ExcludedBar.java");
- assertThat(index.index(file), is(false));
- assertThat(index.isIndexed(file, true), is(true));
- assertThat(index.isIndexed(file, false), is(false));
- assertThat(index.isExcluded(file), is(true));
- }
-
- @Test
- public void shouldIndexResourceWhenAddingMeasure() {
- Resource dir = new Directory("org/foo");
- index.addMeasure(dir, new Measure("ncloc").setValue(50.0));
-
- assertThat(index.isIndexed(dir, true), is(true));
- assertThat(index.getMeasures(dir, MeasuresFilters.metric("ncloc")).getIntValue(), is(50));
- }
-
- /**
- * See http://jira.codehaus.org/browse/SONAR-2107
- */
- @Test
- public void shouldNotFailWhenSavingViolationOnNullRule() {
- File file = new File("org/foo/Bar.java");
- Violation violation = Violation.create((Rule) null, file);
- index.addViolation(violation);
-
- assertThat(index.getViolations(file).size(), is(0));
- }
-
- @Test
- public void testGetViolations() {
- File file = new File("org/foo/Bar.java");
- Violation violation1 = Violation.create(rule, file);
- index.addViolation(violation1);
- Violation violation2 = Violation.create(rule, file);
- violation2.setSwitchedOff(true);
- index.addViolation(violation2);
- Violation violation3 = Violation.create(rule, file);
- violation3.setSwitchedOff(true);
- index.addViolation(violation3);
-
- assertThat(index.getViolations(file).size(), is(1));
- }
-
- @Test
- public void testGetViolationsWithQuery() {
- File file = new File("org/foo/Bar.java");
- Violation violation1 = Violation.create(rule, file);
- index.addViolation(violation1);
- Violation violation2 = Violation.create(rule, file);
- violation2.setSwitchedOff(true);
- index.addViolation(violation2);
- Violation violation3 = Violation.create(rule, file);
- violation3.setSwitchedOff(true);
- index.addViolation(violation3);
-
- assertThat(index.getViolations(ViolationQuery.create().forResource(file).ignoreSwitchedOff(false)).size(), is(3));
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testGetViolationsWithQueryWithNoResource() {
- index.getViolations(ViolationQuery.create());
- }
-
-}
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.batch.index;
+
+import static org.hamcrest.Matchers.nullValue;
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.apache.commons.lang.StringUtils;
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.api.batch.ResourceFilter;
+import org.sonar.api.measures.CoreMetrics;
+import org.sonar.api.measures.Measure;
+import org.sonar.api.measures.MeasuresFilters;
+import org.sonar.api.measures.MetricFinder;
+import org.sonar.api.profiles.RulesProfile;
+import org.sonar.api.resources.Directory;
+import org.sonar.api.resources.File;
+import org.sonar.api.resources.Java;
+import org.sonar.api.resources.JavaPackage;
+import org.sonar.api.resources.Language;
+import org.sonar.api.resources.Library;
+import org.sonar.api.resources.Project;
+import org.sonar.api.resources.Qualifiers;
+import org.sonar.api.resources.Resource;
+import org.sonar.api.rules.Rule;
+import org.sonar.api.rules.Violation;
+import org.sonar.api.utils.SonarException;
+import org.sonar.api.violations.ViolationQuery;
+import org.sonar.batch.DefaultResourceCreationLock;
+import org.sonar.batch.ProjectTree;
+import org.sonar.batch.ResourceFilters;
+import org.sonar.batch.ViolationFilters;
+
+public class DefaultIndexTest {
+
+ private DefaultIndex index = null;
+ private DefaultResourceCreationLock lock;
+ private Rule rule;
+
+ @Before
+ public void createIndex() {
+ lock = new DefaultResourceCreationLock();
+ MetricFinder metricFinder = mock(MetricFinder.class);
+ when(metricFinder.findByKey("ncloc")).thenReturn(CoreMetrics.NCLOC);
+
+ index = new DefaultIndex(mock(PersistenceManager.class), lock, mock(ProjectTree.class), metricFinder);
+ Project project = new Project("project");
+
+ ResourceFilter filter = new ResourceFilter() {
+
+ public boolean isIgnored(Resource resource) {
+ return StringUtils.containsIgnoreCase(resource.getKey(), "excluded");
+ }
+ };
+ RulesProfile rulesProfile = RulesProfile.create();
+ rule = Rule.create("repoKey", "ruleKey", "Rule");
+ rulesProfile.activateRule(rule, null);
+ index.setCurrentProject(project, new ResourceFilters(new ResourceFilter[] { filter }), new ViolationFilters(), rulesProfile);
+ index.doStart(project);
+ }
+
+ @Test
+ public void shouldCreateUID() {
+ Project project = new Project("my_project");
+ assertThat(DefaultIndex.createUID(project, project), is("my_project"));
+
+ JavaPackage javaPackage = new JavaPackage("org.foo");
+ assertThat(DefaultIndex.createUID(project, javaPackage), is("my_project:org.foo"));
+
+ Library library = new Library("junit:junit", "4.7");
+ assertThat(DefaultIndex.createUID(project, library), is("junit:junit"));
+ }
+
+ @Test
+ public void shouldIndexParentOfDeprecatedFiles() {
+ File file = new File("org/foo/Bar.java");
+ assertThat(index.index(file), is(true));
+
+ Directory reference = new Directory("org/foo");
+ assertThat(index.getResource(reference).getName(), is("org/foo"));
+ assertThat(index.isIndexed(reference, true), is(true));
+ assertThat(index.isExcluded(reference), is(false));
+ assertThat(index.getChildren(reference).size(), is(1));
+ assertThat(index.getParent(reference), is(Project.class));
+ }
+
+ @Test
+ public void shouldIndexTreeOfResources() {
+ Directory directory = new Directory("org/foo");
+ File file = new File("org/foo/Bar.java");
+ file.setLanguage(Java.INSTANCE);
+
+ assertThat(index.index(directory), is(true));
+ assertThat(index.index(file, directory), is(true));
+
+ File fileRef = new File("org/foo/Bar.java");
+ assertThat(index.getResource(fileRef).getKey(), is("org/foo/Bar.java"));
+ assertThat(index.getResource(fileRef).getLanguage(), is((Language) Java.INSTANCE));
+ assertThat(index.isIndexed(fileRef, true), is(true));
+ assertThat(index.isExcluded(fileRef), is(false));
+ assertThat(index.getChildren(fileRef).size(), is(0));
+ assertThat(index.getParent(fileRef), is(Directory.class));
+ }
+
+ @Test
+ public void shouldIndexLibraryOutsideProjectTree() {
+ Library lib = new Library("junit", "4.8");
+ assertThat(index.index(lib), is(true));
+
+ Library reference = new Library("junit", "4.8");
+ assertThat(index.getResource(reference).getQualifier(), is(Qualifiers.LIBRARY));
+ assertThat(index.isIndexed(reference, true), is(true));
+ assertThat(index.isExcluded(reference), is(false));
+ }
+
+ @Test
+ public void shouldNotIndexResourceIfParentNotIndexed() {
+ Directory directory = new Directory("org/other");
+ File file = new File("org/foo/Bar.java");
+
+ assertThat(index.index(file, directory), is(false));
+
+ File fileRef = new File("org/foo/Bar.java");
+ assertThat(index.isIndexed(directory, true), is(false));
+ assertThat(index.isIndexed(fileRef, true), is(false));
+ assertThat(index.isExcluded(fileRef), is(false));
+ assertThat(index.getChildren(fileRef).size(), is(0));
+ assertThat(index.getParent(fileRef), nullValue());
+ }
+
+ /**
+ * Only a warning is logged when index is locked.
+ */
+ @Test
+ public void shouldIndexEvenIfLocked() {
+ lock.lock();
+
+ Directory dir = new Directory("org/foo");
+ assertThat(index.index(dir), is(true));
+ assertThat(index.isIndexed(dir, true), is(true));
+ }
+
+ @Test(expected = SonarException.class)
+ public void shouldFailIfIndexingAndLocked() {
+ lock.setFailWhenLocked(true);
+ lock.lock();
+
+ Directory dir = new Directory("org/foo");
+ index.index(dir);
+ }
+
+ @Test
+ public void shouldBeExcluded() {
+ File file = new File("org/foo/ExcludedBar.java");
+ assertThat(index.index(file), is(false));
+ assertThat(index.isIndexed(file, true), is(true));
+ assertThat(index.isIndexed(file, false), is(false));
+ assertThat(index.isExcluded(file), is(true));
+ }
+
+ @Test
+ public void shouldIndexResourceWhenAddingMeasure() {
+ Resource dir = new Directory("org/foo");
+ index.addMeasure(dir, new Measure("ncloc").setValue(50.0));
+
+ assertThat(index.isIndexed(dir, true), is(true));
+ assertThat(index.getMeasures(dir, MeasuresFilters.metric("ncloc")).getIntValue(), is(50));
+ }
+
+ /**
+ * See http://jira.codehaus.org/browse/SONAR-2107
+ */
+ @Test
+ public void shouldNotFailWhenSavingViolationOnNullRule() {
+ File file = new File("org/foo/Bar.java");
+ Violation violation = Violation.create((Rule) null, file);
+ index.addViolation(violation);
+
+ assertThat(index.getViolations(file).size(), is(0));
+ }
+
+ @Test
+ public void testGetViolations() {
+ File file = new File("org/foo/Bar.java");
+ Violation violation1 = Violation.create(rule, file);
+ index.addViolation(violation1);
+ Violation violation2 = Violation.create(rule, file);
+ violation2.setSwitchedOff(true);
+ index.addViolation(violation2);
+ Violation violation3 = Violation.create(rule, file);
+ violation3.setSwitchedOff(true);
+ index.addViolation(violation3);
+
+ assertThat(index.getViolations(file).size(), is(1));
+ }
+
+ @Test
+ public void testGetViolationsWithQuery() {
+ File file = new File("org/foo/Bar.java");
+ Violation violation1 = Violation.create(rule, file);
+ index.addViolation(violation1);
+ Violation violation2 = Violation.create(rule, file);
+ violation2.setSwitchedOff(true);
+ index.addViolation(violation2);
+ Violation violation3 = Violation.create(rule, file);
+ violation3.setSwitchedOff(true);
+ index.addViolation(violation3);
+
+ assertThat(index.getViolations(ViolationQuery.create().forResource(file).ignoreSwitchedOff(false)).size(), is(3));
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testGetViolationsWithQueryWithNoResource() {
+ index.getViolations(ViolationQuery.create());
+ }
+
+}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/ViolationPersisterTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/ViolationPersisterTest.java
index d1d3b775f5c..bb5bc1a34e9 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/index/ViolationPersisterTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/index/ViolationPersisterTest.java
@@ -1,96 +1,96 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * Sonar is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package org.sonar.batch.index;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.api.database.model.RuleFailureModel;
-import org.sonar.api.database.model.Snapshot;
-import org.sonar.api.resources.JavaFile;
-import org.sonar.api.resources.Project;
-import org.sonar.api.rules.Rule;
-import org.sonar.api.rules.RulePriority;
-import org.sonar.api.rules.Violation;
-import org.sonar.core.components.DefaultRuleFinder;
-import org.sonar.jpa.test.AbstractDbUnitTestCase;
-
-import static org.mockito.Matchers.anyObject;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class ViolationPersisterTest extends AbstractDbUnitTestCase {
-
- private ViolationPersister violationPersister;
- private Rule rule1 = Rule.create("checkstyle", "com.puppycrawl.tools.checkstyle.checks.header.HeaderCheck", "Check Header");
- private Rule rule2 = Rule.create("checkstyle", "com.puppycrawl.tools.checkstyle.checks.coding.EqualsAvoidNullCheck", "Equals Avoid Null");
- private JavaFile javaFile = new JavaFile("org.foo.Bar");
- Project project = new Project("project");
-
- @Before
- public void before() {
- setupData("shared");
- Snapshot snapshot = getSession().getSingleResult(Snapshot.class, "id", 1000);
- ResourcePersister resourcePersister = mock(ResourcePersister.class);
- when(resourcePersister.saveResource((Project) anyObject(), eq(javaFile))).thenReturn(snapshot);
- when(resourcePersister.getSnapshot(javaFile)).thenReturn(snapshot);
- violationPersister = new ViolationPersister(getSession(), resourcePersister, new DefaultRuleFinder(getSessionFactory()));
- }
-
- @Test
- public void shouldSaveViolations() {
- Violation violation1a = Violation.create(rule1, javaFile)
- .setSeverity(RulePriority.CRITICAL).setLineId(20).setCost(55.6)
- .setMessage("the message");
- Violation violation1b = Violation.create(rule1, javaFile)
- .setSeverity(RulePriority.CRITICAL).setLineId(50).setCost(80.0);
- Violation violation2 = Violation.create(rule2, javaFile)
- .setSeverity(RulePriority.MINOR);
-
- violationPersister.saveViolation(project, violation1a);
- violationPersister.saveViolation(project, violation1b);
- violationPersister.saveViolation(project, violation2);
-
- checkTables("shouldInsertViolations", "rule_failures");
- }
-
- @Test
- public void shouldCopyPermanentIdFromPastViolation() {
- RuleFailureModel pastViolation = getSession().getSingleResult(RuleFailureModel.class, "id", 1);
-
- Violation violation = Violation.create(rule1, javaFile).setSeverity(RulePriority.MAJOR).setMessage("new message");
- violationPersister.saveViolation(project, violation, pastViolation, "line_checksum");
-
- checkTables("shouldCopyPermanentIdFromPastViolation", "rule_failures");
- }
-
- @Test
- public void shouldCopySwitchedOffFromPastViolation() {
- RuleFailureModel pastViolation1 = getSession().getSingleResult(RuleFailureModel.class, "id", 1);
- Violation violation1 = Violation.create(rule1, javaFile).setSeverity(RulePriority.MAJOR).setMessage("new message");
- violationPersister.saveViolation(project, violation1, pastViolation1, "line_checksum");
-
- RuleFailureModel pastViolation2 = getSession().getSingleResult(RuleFailureModel.class, "id", 2);
- Violation violation2 = Violation.create(rule1, javaFile).setSeverity(RulePriority.MAJOR).setMessage("new message");
- violationPersister.saveViolation(project, violation2, pastViolation2, "line_checksum");
-
- checkTables("shouldCopySwitchedOffFromPastViolation", "rule_failures");
- }
-}
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2011 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.batch.index;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.api.database.model.RuleFailureModel;
+import org.sonar.api.database.model.Snapshot;
+import org.sonar.api.resources.JavaFile;
+import org.sonar.api.resources.Project;
+import org.sonar.api.rules.Rule;
+import org.sonar.api.rules.RulePriority;
+import org.sonar.api.rules.Violation;
+import org.sonar.core.components.DefaultRuleFinder;
+import org.sonar.jpa.test.AbstractDbUnitTestCase;
+
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class ViolationPersisterTest extends AbstractDbUnitTestCase {
+
+ private ViolationPersister violationPersister;
+ private Rule rule1 = Rule.create("checkstyle", "com.puppycrawl.tools.checkstyle.checks.header.HeaderCheck", "Check Header");
+ private Rule rule2 = Rule.create("checkstyle", "com.puppycrawl.tools.checkstyle.checks.coding.EqualsAvoidNullCheck", "Equals Avoid Null");
+ private JavaFile javaFile = new JavaFile("org.foo.Bar");
+ Project project = new Project("project");
+
+ @Before
+ public void before() {
+ setupData("shared");
+ Snapshot snapshot = getSession().getSingleResult(Snapshot.class, "id", 1000);
+ ResourcePersister resourcePersister = mock(ResourcePersister.class);
+ when(resourcePersister.saveResource((Project) anyObject(), eq(javaFile))).thenReturn(snapshot);
+ when(resourcePersister.getSnapshot(javaFile)).thenReturn(snapshot);
+ violationPersister = new ViolationPersister(getSession(), resourcePersister, new DefaultRuleFinder(getSessionFactory()));
+ }
+
+ @Test
+ public void shouldSaveViolations() {
+ Violation violation1a = Violation.create(rule1, javaFile)
+ .setSeverity(RulePriority.CRITICAL).setLineId(20).setCost(55.6)
+ .setMessage("the message");
+ Violation violation1b = Violation.create(rule1, javaFile)
+ .setSeverity(RulePriority.CRITICAL).setLineId(50).setCost(80.0);
+ Violation violation2 = Violation.create(rule2, javaFile)
+ .setSeverity(RulePriority.MINOR);
+
+ violationPersister.saveViolation(project, violation1a);
+ violationPersister.saveViolation(project, violation1b);
+ violationPersister.saveViolation(project, violation2);
+
+ checkTables("shouldInsertViolations", "rule_failures");
+ }
+
+ @Test
+ public void shouldCopyPermanentIdFromPastViolation() {
+ RuleFailureModel pastViolation = getSession().getSingleResult(RuleFailureModel.class, "id", 1);
+
+ Violation violation = Violation.create(rule1, javaFile).setSeverity(RulePriority.MAJOR).setMessage("new message");
+ violationPersister.saveViolation(project, violation, pastViolation, "line_checksum");
+
+ checkTables("shouldCopyPermanentIdFromPastViolation", "rule_failures");
+ }
+
+ @Test
+ public void shouldCopySwitchedOffFromPastViolation() {
+ RuleFailureModel pastViolation1 = getSession().getSingleResult(RuleFailureModel.class, "id", 1);
+ Violation violation1 = Violation.create(rule1, javaFile).setSeverity(RulePriority.MAJOR).setMessage("new message");
+ violationPersister.saveViolation(project, violation1, pastViolation1, "line_checksum");
+
+ RuleFailureModel pastViolation2 = getSession().getSingleResult(RuleFailureModel.class, "id", 2);
+ Violation violation2 = Violation.create(rule1, javaFile).setSeverity(RulePriority.MAJOR).setMessage("new message");
+ violationPersister.saveViolation(project, violation2, pastViolation2, "line_checksum");
+
+ checkTables("shouldCopySwitchedOffFromPastViolation", "rule_failures");
+ }
+}
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/ViolationPersisterTest/shared.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/ViolationPersisterTest/shared.xml
index cc50133e0bd..90a3f202297 100644
--- a/sonar-batch/src/test/resources/org/sonar/batch/index/ViolationPersisterTest/shared.xml
+++ b/sonar-batch/src/test/resources/org/sonar/batch/index/ViolationPersisterTest/shared.xml
@@ -1,24 +1,24 @@
-<dataset>
-
- <rules_categories id="1" name="Efficiency" description="[null]"/>
- <rules_categories id="6" name="Usability" description="[null]"/>
-
- <rules id="30" name="Check Header" plugin_rule_key="com.puppycrawl.tools.checkstyle.checks.header.HeaderCheck"
- plugin_config_key="Checker/Treewalker/HeaderCheck" plugin_name="checkstyle" description="[null]" priority="4" enabled="true"
- cardinality="SINGLE" parent_id="[null]"/>
-
- <rules id="31" name="Equals Avoid Null" plugin_rule_key="com.puppycrawl.tools.checkstyle.checks.coding.EqualsAvoidNullCheck"
- plugin_config_key="Checker/TreeWalker/EqualsAvoidNull" plugin_name="checkstyle" description="[null]" priority="4" enabled="true"
- cardinality="SINGLE" parent_id="[null]"/>
-
- <projects id="200" scope="FIL" qualifier="CLA" kee="project:org.foo.Bar" root_id="[null]"
- name="Bar" long_name="org.foo.Bar" description="[null]"
- enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/>
-
- <snapshots period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" id="1000" project_id="200" parent_snapshot_id="[null]" root_project_id="100" root_snapshot_id="[null]"
- scope="FIL" qualifier="CLA" created_at="2008-11-01 13:58:00.00" version="[null]" path=""
- status="U" islast="false" depth="3" />
-
- <rule_failures switched_off="false" permanent_id="1" ID="1" SNAPSHOT_ID="1000" RULE_ID="30" FAILURE_LEVEL="3" MESSAGE="old message" LINE="10" COST="[null]" created_at="2008-11-01 13:58:00.00" checksum="[null]"/>
- <rule_failures switched_off="true" permanent_id="2" ID="2" SNAPSHOT_ID="1000" RULE_ID="30" FAILURE_LEVEL="3" MESSAGE="old message" LINE="10" COST="[null]" created_at="2008-11-01 13:58:00.00" checksum="[null]"/>
-</dataset>
+<dataset>
+
+ <rules_categories id="1" name="Efficiency" description="[null]"/>
+ <rules_categories id="6" name="Usability" description="[null]"/>
+
+ <rules id="30" name="Check Header" plugin_rule_key="com.puppycrawl.tools.checkstyle.checks.header.HeaderCheck"
+ plugin_config_key="Checker/Treewalker/HeaderCheck" plugin_name="checkstyle" description="[null]" priority="4" enabled="true"
+ cardinality="SINGLE" parent_id="[null]"/>
+
+ <rules id="31" name="Equals Avoid Null" plugin_rule_key="com.puppycrawl.tools.checkstyle.checks.coding.EqualsAvoidNullCheck"
+ plugin_config_key="Checker/TreeWalker/EqualsAvoidNull" plugin_name="checkstyle" description="[null]" priority="4" enabled="true"
+ cardinality="SINGLE" parent_id="[null]"/>
+
+ <projects id="200" scope="FIL" qualifier="CLA" kee="project:org.foo.Bar" root_id="[null]"
+ name="Bar" long_name="org.foo.Bar" description="[null]"
+ enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/>
+
+ <snapshots period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" id="1000" project_id="200" parent_snapshot_id="[null]" root_project_id="100" root_snapshot_id="[null]"
+ scope="FIL" qualifier="CLA" created_at="2008-11-01 13:58:00.00" version="[null]" path=""
+ status="U" islast="false" depth="3" />
+
+ <rule_failures switched_off="false" permanent_id="1" ID="1" SNAPSHOT_ID="1000" RULE_ID="30" FAILURE_LEVEL="3" MESSAGE="old message" LINE="10" COST="[null]" created_at="2008-11-01 13:58:00.00" checksum="[null]"/>
+ <rule_failures switched_off="true" permanent_id="2" ID="2" SNAPSHOT_ID="1000" RULE_ID="30" FAILURE_LEVEL="3" MESSAGE="old message" LINE="10" COST="[null]" created_at="2008-11-01 13:58:00.00" checksum="[null]"/>
+</dataset>
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/ViolationPersisterTest/shouldCopyPermanentIdFromPastViolation-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/ViolationPersisterTest/shouldCopyPermanentIdFromPastViolation-result.xml
index 842a7e10765..881a88dc3bb 100644
--- a/sonar-batch/src/test/resources/org/sonar/batch/index/ViolationPersisterTest/shouldCopyPermanentIdFromPastViolation-result.xml
+++ b/sonar-batch/src/test/resources/org/sonar/batch/index/ViolationPersisterTest/shouldCopyPermanentIdFromPastViolation-result.xml
@@ -1,26 +1,26 @@
-<dataset>
-
- <rules_categories id="1" name="Efficiency" description="[null]"/>
- <rules_categories id="6" name="Usability" description="[null]"/>
-
- <rules id="30" name="Check Header" plugin_rule_key="com.puppycrawl.tools.checkstyle.checks.header.HeaderCheck"
- plugin_config_key="Checker/Treewalker/HeaderCheck" plugin_name="checkstyle" description="[null]" priority="4" enabled="true"
- cardinality="SINGLE" parent_id="[null]"/>
-
- <rules id="31" name="Equals Avoid Null" plugin_rule_key="com.puppycrawl.tools.checkstyle.checks.coding.EqualsAvoidNullCheck"
- plugin_config_key="Checker/TreeWalker/EqualsAvoidNull" plugin_name="checkstyle" description="[null]" priority="4" enabled="true"
- cardinality="SINGLE" parent_id="[null]"/>
-
- <projects id="200" scope="FIL" qualifier="CLA" kee="project:org.foo.Bar" root_id="[null]"
- name="Bar" long_name="org.foo.Bar" description="[null]"
- enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/>
-
- <snapshots period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" id="1000" project_id="200" parent_snapshot_id="[null]" root_project_id="100" root_snapshot_id="[null]"
- scope="FIL" qualifier="CLA" created_at="2008-11-01 13:58:00.00" version="[null]" path=""
- status="U" islast="false" depth="3" />
-
- <rule_failures switched_off="false" permanent_id="1" ID="1" SNAPSHOT_ID="1000" RULE_ID="30" FAILURE_LEVEL="3" MESSAGE="old message" LINE="10" COST="[null]" created_at="2008-11-01 13:58:00.00" checksum="[null]"/>
- <rule_failures switched_off="true" permanent_id="2" ID="2" SNAPSHOT_ID="1000" RULE_ID="30" FAILURE_LEVEL="3" MESSAGE="old message" LINE="10" COST="[null]" created_at="2008-11-01 13:58:00.00" checksum="[null]"/>
-
- <rule_failures switched_off="false" permanent_id="1" ID="3" SNAPSHOT_ID="1000" RULE_ID="30" FAILURE_LEVEL="2" MESSAGE="new message" LINE="[null]" COST="[null]" created_at="2008-11-01 13:58:00.00" checksum="line_checksum"/>
-</dataset>
+<dataset>
+
+ <rules_categories id="1" name="Efficiency" description="[null]"/>
+ <rules_categories id="6" name="Usability" description="[null]"/>
+
+ <rules id="30" name="Check Header" plugin_rule_key="com.puppycrawl.tools.checkstyle.checks.header.HeaderCheck"
+ plugin_config_key="Checker/Treewalker/HeaderCheck" plugin_name="checkstyle" description="[null]" priority="4" enabled="true"
+ cardinality="SINGLE" parent_id="[null]"/>
+
+ <rules id="31" name="Equals Avoid Null" plugin_rule_key="com.puppycrawl.tools.checkstyle.checks.coding.EqualsAvoidNullCheck"
+ plugin_config_key="Checker/TreeWalker/EqualsAvoidNull" plugin_name="checkstyle" description="[null]" priority="4" enabled="true"
+ cardinality="SINGLE" parent_id="[null]"/>
+
+ <projects id="200" scope="FIL" qualifier="CLA" kee="project:org.foo.Bar" root_id="[null]"
+ name="Bar" long_name="org.foo.Bar" description="[null]"
+ enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/>
+
+ <snapshots period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" id="1000" project_id="200" parent_snapshot_id="[null]" root_project_id="100" root_snapshot_id="[null]"
+ scope="FIL" qualifier="CLA" created_at="2008-11-01 13:58:00.00" version="[null]" path=""
+ status="U" islast="false" depth="3" />
+
+ <rule_failures switched_off="false" permanent_id="1" ID="1" SNAPSHOT_ID="1000" RULE_ID="30" FAILURE_LEVEL="3" MESSAGE="old message" LINE="10" COST="[null]" created_at="2008-11-01 13:58:00.00" checksum="[null]"/>
+ <rule_failures switched_off="true" permanent_id="2" ID="2" SNAPSHOT_ID="1000" RULE_ID="30" FAILURE_LEVEL="3" MESSAGE="old message" LINE="10" COST="[null]" created_at="2008-11-01 13:58:00.00" checksum="[null]"/>
+
+ <rule_failures switched_off="false" permanent_id="1" ID="3" SNAPSHOT_ID="1000" RULE_ID="30" FAILURE_LEVEL="2" MESSAGE="new message" LINE="[null]" COST="[null]" created_at="2008-11-01 13:58:00.00" checksum="line_checksum"/>
+</dataset>
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/ViolationPersisterTest/shouldCopySwitchedOffFromPastViolation-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/ViolationPersisterTest/shouldCopySwitchedOffFromPastViolation-result.xml
index f72c573676d..bc366b16a45 100644
--- a/sonar-batch/src/test/resources/org/sonar/batch/index/ViolationPersisterTest/shouldCopySwitchedOffFromPastViolation-result.xml
+++ b/sonar-batch/src/test/resources/org/sonar/batch/index/ViolationPersisterTest/shouldCopySwitchedOffFromPastViolation-result.xml
@@ -1,27 +1,27 @@
-<dataset>
-
- <rules_categories id="1" name="Efficiency" description="[null]"/>
- <rules_categories id="6" name="Usability" description="[null]"/>
-
- <rules id="30" name="Check Header" plugin_rule_key="com.puppycrawl.tools.checkstyle.checks.header.HeaderCheck"
- plugin_config_key="Checker/Treewalker/HeaderCheck" plugin_name="checkstyle" description="[null]" priority="4" enabled="true"
- cardinality="SINGLE" parent_id="[null]"/>
-
- <rules id="31" name="Equals Avoid Null" plugin_rule_key="com.puppycrawl.tools.checkstyle.checks.coding.EqualsAvoidNullCheck"
- plugin_config_key="Checker/TreeWalker/EqualsAvoidNull" plugin_name="checkstyle" description="[null]" priority="4" enabled="true"
- cardinality="SINGLE" parent_id="[null]"/>
-
- <projects id="200" scope="FIL" qualifier="CLA" kee="project:org.foo.Bar" root_id="[null]"
- name="Bar" long_name="org.foo.Bar" description="[null]"
- enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/>
-
- <snapshots period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" id="1000" project_id="200" parent_snapshot_id="[null]" root_project_id="100" root_snapshot_id="[null]"
- scope="FIL" qualifier="CLA" created_at="2008-11-01 13:58:00.00" version="[null]" path=""
- status="U" islast="false" depth="3" />
-
- <rule_failures switched_off="false" permanent_id="1" ID="1" SNAPSHOT_ID="1000" RULE_ID="30" FAILURE_LEVEL="3" MESSAGE="old message" LINE="10" COST="[null]" created_at="2008-11-01 13:58:00.00" checksum="[null]"/>
- <rule_failures switched_off="true" permanent_id="2" ID="2" SNAPSHOT_ID="1000" RULE_ID="30" FAILURE_LEVEL="3" MESSAGE="old message" LINE="10" COST="[null]" created_at="2008-11-01 13:58:00.00" checksum="[null]"/>
-
- <rule_failures switched_off="false" permanent_id="1" ID="3" SNAPSHOT_ID="1000" RULE_ID="30" FAILURE_LEVEL="2" MESSAGE="new message" LINE="[null]" COST="[null]" created_at="2008-11-01 13:58:00.00" checksum="line_checksum"/>
- <rule_failures switched_off="true" permanent_id="2" ID="4" SNAPSHOT_ID="1000" RULE_ID="30" FAILURE_LEVEL="2" MESSAGE="new message" LINE="[null]" COST="[null]" created_at="2008-11-01 13:58:00.00" checksum="line_checksum"/>
-</dataset>
+<dataset>
+
+ <rules_categories id="1" name="Efficiency" description="[null]"/>
+ <rules_categories id="6" name="Usability" description="[null]"/>
+
+ <rules id="30" name="Check Header" plugin_rule_key="com.puppycrawl.tools.checkstyle.checks.header.HeaderCheck"
+ plugin_config_key="Checker/Treewalker/HeaderCheck" plugin_name="checkstyle" description="[null]" priority="4" enabled="true"
+ cardinality="SINGLE" parent_id="[null]"/>
+
+ <rules id="31" name="Equals Avoid Null" plugin_rule_key="com.puppycrawl.tools.checkstyle.checks.coding.EqualsAvoidNullCheck"
+ plugin_config_key="Checker/TreeWalker/EqualsAvoidNull" plugin_name="checkstyle" description="[null]" priority="4" enabled="true"
+ cardinality="SINGLE" parent_id="[null]"/>
+
+ <projects id="200" scope="FIL" qualifier="CLA" kee="project:org.foo.Bar" root_id="[null]"
+ name="Bar" long_name="org.foo.Bar" description="[null]"
+ enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/>
+
+ <snapshots period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" id="1000" project_id="200" parent_snapshot_id="[null]" root_project_id="100" root_snapshot_id="[null]"
+ scope="FIL" qualifier="CLA" created_at="2008-11-01 13:58:00.00" version="[null]" path=""
+ status="U" islast="false" depth="3" />
+
+ <rule_failures switched_off="false" permanent_id="1" ID="1" SNAPSHOT_ID="1000" RULE_ID="30" FAILURE_LEVEL="3" MESSAGE="old message" LINE="10" COST="[null]" created_at="2008-11-01 13:58:00.00" checksum="[null]"/>
+ <rule_failures switched_off="true" permanent_id="2" ID="2" SNAPSHOT_ID="1000" RULE_ID="30" FAILURE_LEVEL="3" MESSAGE="old message" LINE="10" COST="[null]" created_at="2008-11-01 13:58:00.00" checksum="[null]"/>
+
+ <rule_failures switched_off="false" permanent_id="1" ID="3" SNAPSHOT_ID="1000" RULE_ID="30" FAILURE_LEVEL="2" MESSAGE="new message" LINE="[null]" COST="[null]" created_at="2008-11-01 13:58:00.00" checksum="line_checksum"/>
+ <rule_failures switched_off="true" permanent_id="2" ID="4" SNAPSHOT_ID="1000" RULE_ID="30" FAILURE_LEVEL="2" MESSAGE="new message" LINE="[null]" COST="[null]" created_at="2008-11-01 13:58:00.00" checksum="line_checksum"/>
+</dataset>
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/index/ViolationPersisterTest/shouldInsertViolations-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/index/ViolationPersisterTest/shouldInsertViolations-result.xml
index 765a84bae8c..3b3215ffe11 100644
--- a/sonar-batch/src/test/resources/org/sonar/batch/index/ViolationPersisterTest/shouldInsertViolations-result.xml
+++ b/sonar-batch/src/test/resources/org/sonar/batch/index/ViolationPersisterTest/shouldInsertViolations-result.xml
@@ -1,26 +1,26 @@
-<dataset>
- <rules_categories id="1" name="Efficiency" description="[null]"/>
- <rules_categories id="6" name="Usability" description="[null]"/>
-
- <rules id="30" name="Check Header" plugin_rule_key="com.puppycrawl.tools.checkstyle.checks.header.HeaderCheck"
- plugin_config_key="Checker/Treewalker/HeaderCheck" plugin_name="checkstyle" description="[null]" priority="4" enabled="true"
- cardinality="SINGLE" parent_id="[null]"/>
-
- <rules id="31" name="Equals Avoid Null" plugin_rule_key="com.puppycrawl.tools.checkstyle.checks.coding.EqualsAvoidNullCheck"
- plugin_config_key="Checker/TreeWalker/EqualsAvoidNull" plugin_name="checkstyle" description="[null]" priority="4" enabled="true"
- cardinality="SINGLE" parent_id="[null]"/>
-
- <projects id="200" scope="FIL" qualifier="CLA" kee="project:org.foo.Bar" root_id="[null]"
- name="Bar" long_name="org.foo.Bar" description="[null]"
- enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/>
-
- <snapshots period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" id="1000" project_id="200" parent_snapshot_id="[null]" root_project_id="100" root_snapshot_id="[null]"
- scope="FIL" qualifier="CLA" created_at="2008-11-01 13:58:00.00" version="[null]" path=""
- status="U" islast="false" depth="3" />
-
- <rule_failures switched_off="false" permanent_id="1" ID="1" SNAPSHOT_ID="1000" RULE_ID="30" FAILURE_LEVEL="3" MESSAGE="old message" LINE="10" COST="[null]" created_at="2008-11-01 13:58:00.00" checksum="[null]"/>
- <rule_failures switched_off="true" permanent_id="2" ID="2" SNAPSHOT_ID="1000" RULE_ID="30" FAILURE_LEVEL="3" MESSAGE="old message" LINE="10" COST="[null]" created_at="2008-11-01 13:58:00.00" checksum="[null]"/>
- <rule_failures switched_off="false" permanent_id="3" ID="3" SNAPSHOT_ID="1000" RULE_ID="30" FAILURE_LEVEL="3" MESSAGE="the message" LINE="20" COST="55.6" created_at="2008-11-01 13:58:00.00" checksum="[null]"/>
- <rule_failures switched_off="false" permanent_id="4" ID="4" SNAPSHOT_ID="1000" RULE_ID="30" FAILURE_LEVEL="3" MESSAGE="[null]" LINE="50" COST="80" created_at="2008-11-01 13:58:00.00" checksum="[null]"/>
- <rule_failures switched_off="false" permanent_id="5" ID="5" SNAPSHOT_ID="1000" RULE_ID="31" FAILURE_LEVEL="1" MESSAGE="[null]" LINE="[null]" COST="[null]" created_at="2008-11-01 13:58:00.00" checksum="[null]"/>
+<dataset>
+ <rules_categories id="1" name="Efficiency" description="[null]"/>
+ <rules_categories id="6" name="Usability" description="[null]"/>
+
+ <rules id="30" name="Check Header" plugin_rule_key="com.puppycrawl.tools.checkstyle.checks.header.HeaderCheck"
+ plugin_config_key="Checker/Treewalker/HeaderCheck" plugin_name="checkstyle" description="[null]" priority="4" enabled="true"
+ cardinality="SINGLE" parent_id="[null]"/>
+
+ <rules id="31" name="Equals Avoid Null" plugin_rule_key="com.puppycrawl.tools.checkstyle.checks.coding.EqualsAvoidNullCheck"
+ plugin_config_key="Checker/TreeWalker/EqualsAvoidNull" plugin_name="checkstyle" description="[null]" priority="4" enabled="true"
+ cardinality="SINGLE" parent_id="[null]"/>
+
+ <projects id="200" scope="FIL" qualifier="CLA" kee="project:org.foo.Bar" root_id="[null]"
+ name="Bar" long_name="org.foo.Bar" description="[null]"
+ enabled="true" language="java" copy_resource_id="[null]" profile_id="[null]"/>
+
+ <snapshots period1_mode="[null]" period1_param="[null]" period1_date="[null]" period2_mode="[null]" period2_param="[null]" period2_date="[null]" period3_mode="[null]" period3_param="[null]" period3_date="[null]" period4_mode="[null]" period4_param="[null]" period4_date="[null]" period5_mode="[null]" period5_param="[null]" period5_date="[null]" id="1000" project_id="200" parent_snapshot_id="[null]" root_project_id="100" root_snapshot_id="[null]"
+ scope="FIL" qualifier="CLA" created_at="2008-11-01 13:58:00.00" version="[null]" path=""
+ status="U" islast="false" depth="3" />
+
+ <rule_failures switched_off="false" permanent_id="1" ID="1" SNAPSHOT_ID="1000" RULE_ID="30" FAILURE_LEVEL="3" MESSAGE="old message" LINE="10" COST="[null]" created_at="2008-11-01 13:58:00.00" checksum="[null]"/>
+ <rule_failures switched_off="true" permanent_id="2" ID="2" SNAPSHOT_ID="1000" RULE_ID="30" FAILURE_LEVEL="3" MESSAGE="old message" LINE="10" COST="[null]" created_at="2008-11-01 13:58:00.00" checksum="[null]"/>
+ <rule_failures switched_off="false" permanent_id="3" ID="3" SNAPSHOT_ID="1000" RULE_ID="30" FAILURE_LEVEL="3" MESSAGE="the message" LINE="20" COST="55.6" created_at="2008-11-01 13:58:00.00" checksum="[null]"/>
+ <rule_failures switched_off="false" permanent_id="4" ID="4" SNAPSHOT_ID="1000" RULE_ID="30" FAILURE_LEVEL="3" MESSAGE="[null]" LINE="50" COST="80" created_at="2008-11-01 13:58:00.00" checksum="[null]"/>
+ <rule_failures switched_off="false" permanent_id="5" ID="5" SNAPSHOT_ID="1000" RULE_ID="31" FAILURE_LEVEL="1" MESSAGE="[null]" LINE="[null]" COST="[null]" created_at="2008-11-01 13:58:00.00" checksum="[null]"/>
</dataset> \ No newline at end of file