@@ -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 |
@@ -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(); | |||
/** |
@@ -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; | |||
} | |||
} |
@@ -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(); | |||
} |
@@ -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)); | |||
} | |||
} | |||
); |
@@ -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); |
@@ -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; | |||
} |
@@ -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); | |||
} | |||
} | |||
@@ -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; |
@@ -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); | |||
} | |||
} | |||
@@ -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); | |||
} | |||
} | |||
@@ -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); | |||
} | |||
} | |||
@@ -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; | |||
} | |||
} |
@@ -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"); | |||
} | |||
}); | |||
} |