aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2015-05-28 10:47:20 +0200
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2015-06-01 17:08:29 +0200
commit37354408fb62442411642698dfe926ad4c4dcae5 (patch)
tree4919bb04259e875b1e5de1f79153a9ca8579bd0d /server
parent23c63879bf5b848d9911e31ff6dce4ea2490432e (diff)
downloadsonarqube-37354408fb62442411642698dfe926ad4c4dcae5.tar.gz
sonarqube-37354408fb62442411642698dfe926ad4c4dcae5.zip
SONAR-6589 remove Component.getContext()
Diffstat (limited to 'server')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/ComputationContext.java2
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/component/Component.java3
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/component/ComponentImpl.java10
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/component/ComponentTreeBuilder.java4
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/component/ComponentTreeBuilders.java15
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/step/ParseReportStep.java22
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistDuplicationsStep.java10
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistEventsStep.java6
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistFileSourcesStep.java6
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistMeasuresStep.java6
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistNumberOfDaysSinceLastCommitStep.java6
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistProjectLinksStep.java6
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/component/DumbComponent.java24
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/computation/step/QualityProfileEventsStepTest.java4
14 files changed, 41 insertions, 83 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/ComputationContext.java b/server/sonar-server/src/main/java/org/sonar/server/computation/ComputationContext.java
index 5a1f77daaf2..d6a2c75e309 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/ComputationContext.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/ComputationContext.java
@@ -26,7 +26,7 @@ public class ComputationContext implements org.sonar.server.computation.context.
private final Component component;
public ComputationContext(ComponentTreeBuilder componentTreeBuilder) {
- this.component = componentTreeBuilder.build(this);
+ this.component = componentTreeBuilder.build();
}
@Override
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/component/Component.java b/server/sonar-server/src/main/java/org/sonar/server/computation/component/Component.java
index 2bbb79ef1fe..cefa2dfa615 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/component/Component.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/component/Component.java
@@ -20,7 +20,6 @@
package org.sonar.server.computation.component;
import java.util.List;
-import org.sonar.server.computation.context.ComputationContext;
import org.sonar.server.computation.step.PopulateComponentsUuidAndKeyStep;
public interface Component {
@@ -42,8 +41,6 @@ public interface Component {
}
}
- ComputationContext getContext();
-
Type getType();
/**
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/component/ComponentImpl.java b/server/sonar-server/src/main/java/org/sonar/server/computation/component/ComponentImpl.java
index f5952196b02..318a8b83b47 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/component/ComponentImpl.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/component/ComponentImpl.java
@@ -24,14 +24,12 @@ import java.util.List;
import javax.annotation.Nullable;
import org.sonar.batch.protocol.Constants;
import org.sonar.batch.protocol.output.BatchReport;
-import org.sonar.server.computation.ComputationContext;
import static com.google.common.base.Predicates.notNull;
import static com.google.common.collect.ImmutableList.copyOf;
import static com.google.common.collect.Iterables.filter;
public class ComponentImpl implements Component {
- private final ComputationContext context;
private final Type type;
private final BatchReport.Component component;
private final List<Component> children;
@@ -40,8 +38,7 @@ public class ComponentImpl implements Component {
private String key;
private String uuid;
- public ComponentImpl(ComputationContext context, BatchReport.Component component, @Nullable Iterable<Component> children) {
- this.context = context;
+ public ComponentImpl(BatchReport.Component component, @Nullable Iterable<Component> children) {
this.component = component;
this.type = convertType(component.getType());
this.children = children == null ? Collections.<Component>emptyList() : copyOf(filter(children, notNull()));
@@ -101,9 +98,4 @@ public class ComponentImpl implements Component {
return children;
}
- @Override
- public org.sonar.server.computation.context.ComputationContext getContext() {
- return context;
- }
-
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/component/ComponentTreeBuilder.java b/server/sonar-server/src/main/java/org/sonar/server/computation/component/ComponentTreeBuilder.java
index 82aab5f6564..f2089cf7589 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/component/ComponentTreeBuilder.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/component/ComponentTreeBuilder.java
@@ -19,12 +19,10 @@
*/
package org.sonar.server.computation.component;
-import org.sonar.server.computation.ComputationContext;
-
public interface ComponentTreeBuilder {
/**
* Builds the tree of components for the specified ComputationContext and returns the Component of the root of this
* tree.
*/
- Component build(ComputationContext context);
+ Component build();
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/component/ComponentTreeBuilders.java b/server/sonar-server/src/main/java/org/sonar/server/computation/component/ComponentTreeBuilders.java
index 55b106b5425..bfa2b97bb83 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/component/ComponentTreeBuilders.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/component/ComponentTreeBuilders.java
@@ -24,7 +24,6 @@ import com.google.common.collect.Iterables;
import javax.annotation.Nonnull;
import org.sonar.batch.protocol.output.BatchReport;
import org.sonar.server.computation.batch.BatchReportReader;
-import org.sonar.server.computation.ComputationContext;
import static java.util.Objects.requireNonNull;
@@ -41,7 +40,7 @@ public final class ComponentTreeBuilders {
requireNonNull(root);
return new ComponentTreeBuilder() {
@Override
- public Component build(ComputationContext context) {
+ public Component build() {
return root;
}
};
@@ -59,17 +58,17 @@ public final class ComponentTreeBuilders {
}
@Override
- public Component build(ComputationContext context) {
- return buildComponentRoot(context, reportReader);
+ public Component build() {
+ return buildComponentRoot(reportReader);
}
- private Component buildComponentRoot(ComputationContext computationContext, BatchReportReader reportReader) {
+ private Component buildComponentRoot(BatchReportReader reportReader) {
int rootComponentRef = reportReader.readMetadata().getRootComponentRef();
BatchReport.Component component = reportReader.readComponent(rootComponentRef);
- return new ComponentImpl(computationContext, component, buildComponent(computationContext, rootComponentRef));
+ return new ComponentImpl(component, buildComponent(rootComponentRef));
}
- private Iterable<Component> buildComponent(final ComputationContext computationContext, int componentRef) {
+ private Iterable<Component> buildComponent(int componentRef) {
BatchReport.Component component = reportReader.readComponent(componentRef);
return Iterables.transform(
component.getChildRefList(),
@@ -77,7 +76,7 @@ public final class ComponentTreeBuilders {
@Override
public Component apply(@Nonnull Integer componentRef) {
BatchReport.Component component = reportReader.readComponent(componentRef);
- return new ComponentImpl(computationContext, component, buildComponent(computationContext, componentRef));
+ return new ComponentImpl(component, buildComponent(componentRef));
}
}
);
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/ParseReportStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/ParseReportStep.java
index d1caf76ab5e..28edc272344 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/ParseReportStep.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/ParseReportStep.java
@@ -40,13 +40,13 @@ public class ParseReportStep implements ComputationStep {
@Override
public void execute(ComputationContext context) {
- IssueDepthTraversalTypeAwareVisitor visitor = new IssueDepthTraversalTypeAwareVisitor(context);
+ IssueDepthTraversalTypeAwareVisitor visitor = new IssueDepthTraversalTypeAwareVisitor();
visitor.visit(context.getRoot());
- processDeletedComponents(context, visitor);
+ processDeletedComponents(visitor);
issueComputation.afterReportProcessing();
}
- private void processDeletedComponents(ComputationContext context, IssueDepthTraversalTypeAwareVisitor visitor) {
+ private void processDeletedComponents(IssueDepthTraversalTypeAwareVisitor visitor) {
int deletedComponentsCount = reportReader.readMetadata().getDeletedComponentsCount();
for (int componentRef = 1; componentRef <= deletedComponentsCount; componentRef++) {
BatchReport.Issues issues = reportReader.readDeletedComponentIssues(componentRef);
@@ -60,40 +60,36 @@ public class ParseReportStep implements ComputationStep {
}
private class IssueDepthTraversalTypeAwareVisitor extends DepthTraversalTypeAwareVisitor {
-
- private final ComputationContext context;
-
private String projectKey;
private String projectUuid;
- public IssueDepthTraversalTypeAwareVisitor(ComputationContext context) {
+ public IssueDepthTraversalTypeAwareVisitor() {
super(Component.Type.FILE, Order.PRE_ORDER);
- this.context = context;
}
@Override
public void visitProject(Component tree) {
projectKey = tree.getKey();
projectUuid = tree.getUuid();
- executeForComponent(tree, context);
+ executeForComponent(tree);
}
@Override
public void visitModule(Component module) {
- executeForComponent(module, context);
+ executeForComponent(module);
}
@Override
public void visitDirectory(Component directory) {
- executeForComponent(directory, context);
+ executeForComponent(directory);
}
@Override
public void visitFile(Component file) {
- executeForComponent(file, context);
+ executeForComponent(file);
}
- private void executeForComponent(Component component, ComputationContext context) {
+ private void executeForComponent(Component component) {
int componentRef = component.getRef();
List<BatchReport.Issue> issues = reportReader.readComponentIssues(componentRef);
issueComputation.processComponentIssues(issues, component.getUuid(), componentRef, projectKey, projectUuid);
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistDuplicationsStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistDuplicationsStep.java
index 15213ffbc07..bab1dd86c28 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistDuplicationsStep.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistDuplicationsStep.java
@@ -54,7 +54,7 @@ public class PersistDuplicationsStep implements ComputationStep {
DbSession session = dbClient.openSession(true);
try {
MetricDto duplicationMetric = dbClient.metricDao().selectByKey(session, CoreMetrics.DUPLICATIONS_DATA_KEY);
- DuplicationContext duplicationContext = new DuplicationContext(context, duplicationMetric, session);
+ DuplicationContext duplicationContext = new DuplicationContext(duplicationMetric, session);
int rootComponentRef = reportReader.readMetadata().getRootComponentRef();
recursivelyProcessComponent(duplicationContext, rootComponentRef);
session.commit();
@@ -136,19 +136,13 @@ public class PersistDuplicationsStep implements ComputationStep {
private static class DuplicationContext {
private DbSession session;
- private ComputationContext context;
private MetricDto duplicationMetric;
- DuplicationContext(ComputationContext context, MetricDto duplicationMetric, DbSession session) {
- this.context = context;
+ DuplicationContext(MetricDto duplicationMetric, DbSession session) {
this.duplicationMetric = duplicationMetric;
this.session = session;
}
- public ComputationContext context() {
- return context;
- }
-
public MetricDto metric() {
return duplicationMetric;
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistEventsStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistEventsStep.java
index fbd482e58a5..a5fec0b4531 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistEventsStep.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistEventsStep.java
@@ -51,21 +51,21 @@ public class PersistEventsStep implements ComputationStep {
DbSession session = dbClient.openSession(false);
try {
int rootComponentRef = reportReader.readMetadata().getRootComponentRef();
- recursivelyProcessComponent(session, context, rootComponentRef);
+ recursivelyProcessComponent(session, rootComponentRef);
session.commit();
} finally {
MyBatis.closeQuietly(session);
}
}
- private void recursivelyProcessComponent(DbSession session, ComputationContext context, int componentRef) {
+ private void recursivelyProcessComponent(DbSession session, int componentRef) {
BatchReport.Component component = reportReader.readComponent(componentRef);
long analysisDate = reportReader.readMetadata().getAnalysisDate();
processEvents(session, component, analysisDate);
saveVersionEvent(session, component, analysisDate);
for (Integer childRef : component.getChildRefList()) {
- recursivelyProcessComponent(session, context, childRef);
+ recursivelyProcessComponent(session, childRef);
}
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistFileSourcesStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistFileSourcesStep.java
index ffeaf4d0471..c6c8fe6f205 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistFileSourcesStep.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistFileSourcesStep.java
@@ -80,7 +80,7 @@ public class PersistFileSourcesStep implements ComputationStep {
}
});
- recursivelyProcessComponent(new FileSourcesContext(session, context, previousFileSourcesByUuid, projectUuid), rootComponentRef);
+ recursivelyProcessComponent(new FileSourcesContext(session, previousFileSourcesByUuid, projectUuid), rootComponentRef);
} finally {
MyBatis.closeQuietly(session);
}
@@ -153,12 +153,10 @@ public class PersistFileSourcesStep implements ComputationStep {
private static class FileSourcesContext {
DbSession session;
- ComputationContext context;
Map<String, FileSourceDto> previousFileSourcesByUuid;
String projectUuid;
- public FileSourcesContext(DbSession session, ComputationContext context, Map<String, FileSourceDto> previousFileSourcesByUuid, String projectUuid) {
- this.context = context;
+ public FileSourcesContext(DbSession session, Map<String, FileSourceDto> previousFileSourcesByUuid, String projectUuid) {
this.previousFileSourcesByUuid = previousFileSourcesByUuid;
this.session = session;
this.projectUuid = projectUuid;
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistMeasuresStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistMeasuresStep.java
index 627aacab9ed..fe4d804bde6 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistMeasuresStep.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistMeasuresStep.java
@@ -68,17 +68,17 @@ public class PersistMeasuresStep implements ComputationStep {
public void execute(ComputationContext context) {
int rootComponentRef = reportReader.readMetadata().getRootComponentRef();
try (DbSession dbSession = dbClient.openSession(true)) {
- recursivelyProcessComponent(dbSession, context, rootComponentRef);
+ recursivelyProcessComponent(dbSession, rootComponentRef);
dbSession.commit();
}
}
- private void recursivelyProcessComponent(DbSession dbSession, ComputationContext context, int componentRef) {
+ private void recursivelyProcessComponent(DbSession dbSession, int componentRef) {
BatchReport.Component component = reportReader.readComponent(componentRef);
List<BatchReport.Measure> measures = reportReader.readComponentMeasures(componentRef);
persistMeasures(dbSession, measures, component);
for (Integer childRef : component.getChildRefList()) {
- recursivelyProcessComponent(dbSession, context, childRef);
+ recursivelyProcessComponent(dbSession, childRef);
}
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistNumberOfDaysSinceLastCommitStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistNumberOfDaysSinceLastCommitStep.java
index e3585ecd32d..1e041c0d328 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistNumberOfDaysSinceLastCommitStep.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistNumberOfDaysSinceLastCommitStep.java
@@ -70,7 +70,7 @@ public class PersistNumberOfDaysSinceLastCommitStep implements ComputationStep {
@Override
public void execute(ComputationContext context) {
int rootComponentRef = reportReader.readMetadata().getRootComponentRef();
- recursivelyProcessComponent(context, rootComponentRef);
+ recursivelyProcessComponent(rootComponentRef);
if (!commitFound()) {
Long lastCommitFromIndex = lastCommitFromIndex(dbComponentsRefCache.getByRef(rootComponentRef).getUuid());
@@ -82,13 +82,13 @@ public class PersistNumberOfDaysSinceLastCommitStep implements ComputationStep {
}
}
- private void recursivelyProcessComponent(ComputationContext context, int componentRef) {
+ private void recursivelyProcessComponent(int componentRef) {
BatchReport.Component component = reportReader.readComponent(componentRef);
BatchReport.Changesets scm = reportReader.readChangesets(componentRef);
processScm(scm);
for (Integer childRef : component.getChildRefList()) {
- recursivelyProcessComponent(context, childRef);
+ recursivelyProcessComponent(childRef);
}
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistProjectLinksStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistProjectLinksStep.java
index 8fab3b3aa44..3ccbe83d9cf 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistProjectLinksStep.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistProjectLinksStep.java
@@ -71,19 +71,19 @@ public class PersistProjectLinksStep implements ComputationStep {
DbSession session = dbClient.openSession(false);
try {
int rootComponentRef = reportReader.readMetadata().getRootComponentRef();
- recursivelyProcessComponent(session, context, rootComponentRef);
+ recursivelyProcessComponent(session, rootComponentRef);
session.commit();
} finally {
MyBatis.closeQuietly(session);
}
}
- private void recursivelyProcessComponent(DbSession session, ComputationContext context, int componentRef) {
+ private void recursivelyProcessComponent(DbSession session, int componentRef) {
BatchReport.Component component = reportReader.readComponent(componentRef);
processLinks(session, component);
for (Integer childRef : component.getChildRefList()) {
- recursivelyProcessComponent(session, context, childRef);
+ recursivelyProcessComponent(session, childRef);
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/component/DumbComponent.java b/server/sonar-server/src/test/java/org/sonar/server/computation/component/DumbComponent.java
index e2f7061f0b4..b51d4770365 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/component/DumbComponent.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/component/DumbComponent.java
@@ -23,29 +23,21 @@ import com.google.common.collect.ImmutableList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
-import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
-import org.sonar.server.computation.context.ComputationContext;
+/**
+ * Implementation of {@link Component} for unit tests.
+ */
public class DumbComponent implements Component {
public static final Component DUMB_PROJECT = new DumbComponent(Type.PROJECT, 1, "PROJECT_KEY", "PROJECT_UUID");
- private static final String UNSUPPORTED_OPERATION_ERROR = "This node has no repository nor context";
-
- @CheckForNull
- private final ComputationContext context;
private final Type type;
private final int ref;
private final String uuid;
private final String key;
private final List<Component> children;
- public DumbComponent(Type type, int ref, String uuid, String key, @Nullable Component... children) {
- this(null, type, ref, uuid, key, children);
- }
-
- public DumbComponent(@Nullable ComputationContext context, Type type, int ref, String uuid, String key, @Nullable Component... children) {
- this.context = context;
+ public DumbComponent(Type type, int ref, @Nullable String uuid, @Nullable String key, @Nullable Component... children) {
this.type = type;
this.ref = ref;
this.uuid = uuid;
@@ -78,12 +70,4 @@ public class DumbComponent implements Component {
return children;
}
- @Override
- public ComputationContext getContext() {
- if (context == null) {
- throw new UnsupportedOperationException(UNSUPPORTED_OPERATION_ERROR);
- }
- return context;
- }
-
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/step/QualityProfileEventsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/step/QualityProfileEventsStepTest.java
index 08816b98030..201a6f85e80 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/computation/step/QualityProfileEventsStepTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/computation/step/QualityProfileEventsStepTest.java
@@ -295,8 +295,8 @@ public class QualityProfileEventsStepTest {
private ComputationContext newNoChildRootContext() {
return new ComputationContext(new ComponentTreeBuilder() {
@Override
- public Component build(ComputationContext context) {
- return new DumbComponent(context, Component.Type.PROJECT, 1, "uuid", "key");
+ public Component build() {
+ return new DumbComponent(Component.Type.PROJECT, 1, "uuid", "key");
}
});
}