From a0c39b6e623876693382842b1d9ec7534f453059 Mon Sep 17 00:00:00 2001 From: Evgeny Mandrikov Date: Fri, 11 Mar 2011 22:40:16 +0300 Subject: [PATCH] Reduce dependencies on database * Remove unused method DefaultDecoratorContext#getSession() and as a result dependency on DatabaseSession * Replace DefaultIndex by SonarIndex in DefaultDecoratorContext and in DefaultSensorContext --- .../sonar/batch/DefaultDecoratorContext.java | 29 +++++++------------ .../org/sonar/batch/DefaultSensorContext.java | 6 ++-- .../java/org/sonar/batch/ProjectBatch.java | 1 - .../batch/phases/DecoratorsExecutor.java | 17 +++++------ .../java/org/sonar/api/batch/SonarIndex.java | 5 ++++ 5 files changed, 25 insertions(+), 33 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 dedee60406a..fde3c9099d4 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/DefaultDecoratorContext.java +++ b/sonar-batch/src/main/java/org/sonar/batch/DefaultDecoratorContext.java @@ -19,10 +19,15 @@ */ 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.database.DatabaseSession; +import org.sonar.api.batch.SonarIndex; import org.sonar.api.design.Dependency; import org.sonar.api.measures.Measure; import org.sonar.api.measures.MeasuresFilter; @@ -31,28 +36,19 @@ 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.batch.index.DefaultIndex; - -import java.util.Collection; -import java.util.Date; -import java.util.List; -import java.util.Set; public class DefaultDecoratorContext implements DecoratorContext { - private DatabaseSession session; - private DefaultIndex index; + private SonarIndex index; private Resource resource; private boolean readOnly = false; private List childrenContexts; public DefaultDecoratorContext(Resource resource, - DefaultIndex index, - List childrenContexts, - DatabaseSession session) { + SonarIndex index, + List childrenContexts) { this.index = index; - this.session = session; this.resource = resource; this.childrenContexts = childrenContexts; } @@ -121,7 +117,6 @@ public class DefaultDecoratorContext implements DecoratorContext { return this; } - public List getViolations() { return index.getViolations(resource); } @@ -143,10 +138,6 @@ public class DefaultDecoratorContext implements DecoratorContext { return index.getOutgoingEdges(resource); } - protected DatabaseSession getSession() { - return session; - } - public List getEvents() { return index.getEvents(resource); } @@ -158,7 +149,7 @@ public class DefaultDecoratorContext implements DecoratorContext { public void deleteEvent(Event event) { index.deleteEvent(event); } - + public DefaultDecoratorContext saveViolation(Violation violation, boolean force) { if (violation.getResource() == null) { violation.setResource(resource); diff --git a/sonar-batch/src/main/java/org/sonar/batch/DefaultSensorContext.java b/sonar-batch/src/main/java/org/sonar/batch/DefaultSensorContext.java index 1689bc4269f..5dcda3d3332 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/DefaultSensorContext.java +++ b/sonar-batch/src/main/java/org/sonar/batch/DefaultSensorContext.java @@ -21,13 +21,13 @@ package org.sonar.batch; import org.sonar.api.batch.Event; import org.sonar.api.batch.SensorContext; +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.Metric; import org.sonar.api.resources.*; import org.sonar.api.rules.Violation; -import org.sonar.batch.index.DefaultIndex; import java.util.Collection; import java.util.Date; @@ -36,10 +36,10 @@ import java.util.Set; public class DefaultSensorContext implements SensorContext { - private DefaultIndex index; + private SonarIndex index; private Project project; - public DefaultSensorContext(DefaultIndex index, Project project) { + public DefaultSensorContext(SonarIndex index, Project project) { this.index = index; this.project = project; } diff --git a/sonar-batch/src/main/java/org/sonar/batch/ProjectBatch.java b/sonar-batch/src/main/java/org/sonar/batch/ProjectBatch.java index 14406cf4ff9..1ffbcb954ad 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/ProjectBatch.java +++ b/sonar-batch/src/main/java/org/sonar/batch/ProjectBatch.java @@ -121,7 +121,6 @@ public class ProjectBatch { // the Snapshot component will be removed when asynchronous measures are improved (required for AsynchronousMeasureSensor) addComponent(getComponent(DefaultResourcePersister.class).getSnapshot(project)); - // TODO was addComponent(globalComponents.getComponent(DefaultResourcePersister.class).getSnapshot(project)); addComponent(org.sonar.api.database.daos.MeasuresDao.class); addComponent(ProfilesDao.class); diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/DecoratorsExecutor.java b/sonar-batch/src/main/java/org/sonar/batch/phases/DecoratorsExecutor.java index 9b294e8eb90..70cc2a1d16b 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/phases/DecoratorsExecutor.java +++ b/sonar-batch/src/main/java/org/sonar/batch/phases/DecoratorsExecutor.java @@ -19,15 +19,12 @@ */ package org.sonar.batch.phases; -import java.util.Collection; -import java.util.List; - import com.google.common.collect.Lists; import org.sonar.api.BatchComponent; import org.sonar.api.batch.BatchExtensionDictionnary; import org.sonar.api.batch.Decorator; import org.sonar.api.batch.DecoratorContext; -import org.sonar.api.database.DatabaseSession; +import org.sonar.api.batch.SonarIndex; import org.sonar.api.resources.Project; import org.sonar.api.resources.Resource; import org.sonar.batch.DecoratorsSelector; @@ -35,18 +32,18 @@ import org.sonar.batch.DefaultDecoratorContext; import org.sonar.batch.events.DecoratorExecutionEvent; import org.sonar.batch.events.DecoratorsPhaseEvent; import org.sonar.batch.events.EventBus; -import org.sonar.batch.index.DefaultIndex; + +import java.util.Collection; +import java.util.List; public class DecoratorsExecutor implements BatchComponent { private DecoratorsSelector decoratorsSelector; - private DatabaseSession session; - private DefaultIndex index; + private SonarIndex index; private EventBus eventBus; - public DecoratorsExecutor(BatchExtensionDictionnary extensionDictionnary, DefaultIndex index, DatabaseSession session, EventBus eventBus) { + public DecoratorsExecutor(BatchExtensionDictionnary extensionDictionnary, SonarIndex index, EventBus eventBus) { this.decoratorsSelector = new DecoratorsSelector(extensionDictionnary); - this.session = session; this.index = index; this.eventBus = eventBus; } @@ -66,7 +63,7 @@ public class DecoratorsExecutor implements BatchComponent { childrenContexts.add(childContext.setReadOnly(true)); } - DefaultDecoratorContext context = new DefaultDecoratorContext(resource, index, childrenContexts, session); + DefaultDecoratorContext context = new DefaultDecoratorContext(resource, index, childrenContexts); if (executeDecorators) { for (Decorator decorator : decorators) { eventBus.fireEvent(new DecoratorExecutionEvent(decorator, true)); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/SonarIndex.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/SonarIndex.java index b7974c57a2c..02bb82d1153 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/SonarIndex.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/SonarIndex.java @@ -116,6 +116,11 @@ public abstract class SonarIndex implements DirectedGraphAccessor M getMeasures(Resource resource, MeasuresFilter filter); + /** + * @since 2.7 + */ + public abstract List getViolations(Resource resource); + /** * @since 2.5 */ -- 2.39.5