@@ -24,7 +24,7 @@ public interface ComponentVisitor { | |||
Order getOrder(); | |||
Component.Type getMaxDepth(); | |||
CrawlerDepthLimit getMaxDepth(); | |||
enum Order { | |||
/** |
@@ -0,0 +1,111 @@ | |||
/* | |||
* SonarQube, open source software quality management tool. | |||
* Copyright (C) 2008-2014 SonarSource | |||
* mailto:contact AT sonarsource DOT com | |||
* | |||
* SonarQube 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. | |||
* | |||
* SonarQube 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 this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonar.server.computation.component; | |||
import javax.annotation.CheckForNull; | |||
import javax.annotation.Nullable; | |||
import javax.annotation.concurrent.Immutable; | |||
import static com.google.common.base.Preconditions.checkArgument; | |||
/** | |||
* Represents the limit down a {@link Component} tree a {@link ComponentCrawler} can go to. | |||
* | |||
* A limit can be defined for a tree of Report components, a tree of Views components or both. | |||
* | |||
* Constants are provided for limits specific to a component tree (see {@link #PROJECT}, {@link #MODULE}, etc.). | |||
* | |||
* Limits for both trees can be created using the {@link #reportMaxDepth(Component.Type)} static method. | |||
*/ | |||
@Immutable | |||
public class CrawlerDepthLimit { | |||
private static final String UNSUPPORTED_TYPE_UOE_MSG = "Specified type is neither a report type nor a views type"; | |||
public static final CrawlerDepthLimit PROJECT = new CrawlerDepthLimit(Component.Type.PROJECT, null); | |||
public static final CrawlerDepthLimit MODULE = new CrawlerDepthLimit(Component.Type.MODULE, null); | |||
public static final CrawlerDepthLimit DIRECTORY = new CrawlerDepthLimit(Component.Type.DIRECTORY, null); | |||
public static final CrawlerDepthLimit FILE = new CrawlerDepthLimit(Component.Type.FILE, null); | |||
public static final CrawlerDepthLimit VIEW = new CrawlerDepthLimit(null, Component.Type.VIEW); | |||
public static final CrawlerDepthLimit SUBVIEW = new CrawlerDepthLimit(null, Component.Type.SUBVIEW); | |||
public static final CrawlerDepthLimit PROJECT_VIEW = new CrawlerDepthLimit(null, Component.Type.PROJECT_VIEW); | |||
@CheckForNull | |||
private final Component.Type reportMaxDepth; | |||
@CheckForNull | |||
private final Component.Type viewsMaxDepth; | |||
private CrawlerDepthLimit(@Nullable Component.Type reportMaxDepth, @Nullable Component.Type viewsMaxDepth) { | |||
checkArgument(reportMaxDepth != null || viewsMaxDepth != null, | |||
"At least one type must be non null"); | |||
checkArgument(reportMaxDepth == null || reportMaxDepth.isReportType()); | |||
checkArgument(viewsMaxDepth == null || viewsMaxDepth.isViewsType()); | |||
this.reportMaxDepth = reportMaxDepth; | |||
this.viewsMaxDepth = viewsMaxDepth; | |||
} | |||
public static Builder reportMaxDepth(Component.Type reportMaxDepth) { | |||
return new Builder(reportMaxDepth); | |||
} | |||
public static class Builder { | |||
private final Component.Type reportMaxDepth; | |||
public Builder(Component.Type reportMaxDepth) { | |||
checkArgument(reportMaxDepth.isReportType(), "A Report max depth must be a report type"); | |||
this.reportMaxDepth = reportMaxDepth; | |||
} | |||
public CrawlerDepthLimit withViewsMaxDepth(Component.Type viewsMaxDepth) { | |||
checkArgument(viewsMaxDepth.isViewsType(), "A Views max depth must be a views type"); | |||
return new CrawlerDepthLimit(reportMaxDepth, viewsMaxDepth); | |||
} | |||
} | |||
public boolean isDeeperThan(Component.Type otherType) { | |||
if (otherType.isViewsType()) { | |||
return this.viewsMaxDepth != null && this.viewsMaxDepth.isDeeperThan(otherType); | |||
} | |||
if (otherType.isReportType()) { | |||
return this.reportMaxDepth != null && this.reportMaxDepth.isDeeperThan(otherType); | |||
} | |||
throw new UnsupportedOperationException(UNSUPPORTED_TYPE_UOE_MSG); | |||
} | |||
public boolean isHigherThan(Component.Type otherType) { | |||
if (otherType.isViewsType()) { | |||
return this.viewsMaxDepth != null && this.viewsMaxDepth.isHigherThan(otherType); | |||
} | |||
if (otherType.isReportType()) { | |||
return this.reportMaxDepth != null && this.reportMaxDepth.isHigherThan(otherType); | |||
} | |||
throw new UnsupportedOperationException(UNSUPPORTED_TYPE_UOE_MSG); | |||
} | |||
public boolean isSameAs(Component.Type otherType) { | |||
if (otherType.isViewsType()) { | |||
return otherType == this.viewsMaxDepth; | |||
} | |||
if (otherType.isReportType()) { | |||
return otherType == this.reportMaxDepth; | |||
} | |||
throw new UnsupportedOperationException(UNSUPPORTED_TYPE_UOE_MSG); | |||
} | |||
} |
@@ -36,7 +36,7 @@ public final class DepthTraversalTypeAwareCrawler implements ComponentCrawler { | |||
@Override | |||
public void visit(Component component) { | |||
if (component.getType().isDeeperThan(this.visitor.getMaxDepth())) { | |||
if (!verifyDepth(component)) { | |||
return; | |||
} | |||
@@ -51,6 +51,11 @@ public final class DepthTraversalTypeAwareCrawler implements ComponentCrawler { | |||
} | |||
} | |||
private boolean verifyDepth(Component component) { | |||
CrawlerDepthLimit maxDepth = this.visitor.getMaxDepth(); | |||
return maxDepth.isSameAs(component.getType()) || maxDepth.isDeeperThan(component.getType()); | |||
} | |||
private void visitNode(Component component) { | |||
this.visitor.visitAny(component); | |||
switch (component.getType()) { | |||
@@ -82,7 +87,7 @@ public final class DepthTraversalTypeAwareCrawler implements ComponentCrawler { | |||
private void visitChildren(Component component) { | |||
for (Component child : component.getChildren()) { | |||
if (!child.getType().isDeeperThan(this.visitor.getMaxDepth())) { | |||
if (verifyDepth(child)) { | |||
visit(child); | |||
} | |||
} |
@@ -40,7 +40,7 @@ public final class PathAwareCrawler<T> implements ComponentCrawler { | |||
@Override | |||
public void visit(Component component) { | |||
if (component.getType().isDeeperThan(this.visitor.getMaxDepth())) { | |||
if (!verifyDepth(component)) { | |||
return; | |||
} | |||
@@ -59,9 +59,14 @@ public final class PathAwareCrawler<T> implements ComponentCrawler { | |||
stack.pop(); | |||
} | |||
private boolean verifyDepth(Component component) { | |||
CrawlerDepthLimit maxDepth = this.visitor.getMaxDepth(); | |||
return maxDepth.isSameAs(component.getType()) || maxDepth.isDeeperThan(component.getType()); | |||
} | |||
private void visitChildren(Component component) { | |||
for (Component child : component.getChildren()) { | |||
if (!child.getType().isDeeperThan(this.visitor.getMaxDepth())) { | |||
if (verifyDepth(component)) { | |||
visit(child); | |||
} | |||
} |
@@ -26,18 +26,18 @@ import static java.util.Objects.requireNonNull; | |||
* A adapter of the {@link PathAwareVisitor} to be able to visit only some component types | |||
*/ | |||
public abstract class PathAwareVisitorAdapter<T> implements PathAwareVisitor<T> { | |||
private final Component.Type maxDepth; | |||
private final CrawlerDepthLimit maxDepth; | |||
private final Order order; | |||
private final StackElementFactory<T> factory; | |||
public PathAwareVisitorAdapter(Component.Type maxDepth, Order order, StackElementFactory<T> factory) { | |||
public PathAwareVisitorAdapter(CrawlerDepthLimit maxDepth, Order order, StackElementFactory<T> factory) { | |||
this.maxDepth = requireNonNull(maxDepth); | |||
this.order = requireNonNull(order); | |||
this.factory = requireNonNull(factory, "Factory can not be null"); | |||
} | |||
@Override | |||
public Component.Type getMaxDepth() { | |||
public CrawlerDepthLimit getMaxDepth() { | |||
return maxDepth; | |||
} | |||
@@ -86,7 +86,7 @@ public class PathAwareVisitorWrapper<T> implements VisitorWrapper { | |||
} | |||
@Override | |||
public Component.Type getMaxDepth() { | |||
public CrawlerDepthLimit getMaxDepth() { | |||
return delegate.getMaxDepth(); | |||
} | |||
@@ -37,7 +37,7 @@ public class ReportTreeRootHolderImpl extends TreeRootHolderImpl implements Repo | |||
private void feedComponentsByRef(Component newRoot) { | |||
new DepthTraversalTypeAwareCrawler( | |||
new TypeAwareVisitorAdapter(Component.Type.FILE, POST_ORDER) { | |||
new TypeAwareVisitorAdapter(CrawlerDepthLimit.FILE, POST_ORDER) { | |||
@Override | |||
public void visitAny(Component component) { | |||
componentsByRef.put(component.getReportAttributes().getRef(), component); |
@@ -27,16 +27,16 @@ import static java.util.Objects.requireNonNull; | |||
*/ | |||
public abstract class TypeAwareVisitorAdapter implements TypeAwareVisitor { | |||
protected final Component.Type maxDepth; | |||
protected final CrawlerDepthLimit maxDepth; | |||
protected final Order order; | |||
public TypeAwareVisitorAdapter(Component.Type maxDepth, Order order) { | |||
public TypeAwareVisitorAdapter(CrawlerDepthLimit maxDepth, Order order) { | |||
this.maxDepth = requireNonNull(maxDepth); | |||
this.order = requireNonNull(order); | |||
} | |||
@Override | |||
public Component.Type getMaxDepth() { | |||
public CrawlerDepthLimit getMaxDepth() { | |||
return maxDepth; | |||
} | |||
@@ -84,7 +84,7 @@ public class TypeAwareVisitorWrapper implements VisitorWrapper { | |||
} | |||
@Override | |||
public Component.Type getMaxDepth() { | |||
public CrawlerDepthLimit getMaxDepth() { | |||
return delegate.getMaxDepth(); | |||
} | |||
@@ -146,7 +146,8 @@ public class VisitorsCrawler implements ComponentCrawler { | |||
@Override | |||
public boolean apply(@Nonnull VisitorWrapper visitorWrapper) { | |||
return !type.isDeeperThan(visitorWrapper.getMaxDepth()); | |||
CrawlerDepthLimit maxDepth = visitorWrapper.getMaxDepth(); | |||
return maxDepth.isSameAs(type) || maxDepth.isDeeperThan(type); | |||
} | |||
} | |||
@@ -27,6 +27,7 @@ import java.util.Map; | |||
import javax.annotation.CheckForNull; | |||
import org.sonar.server.computation.component.Component; | |||
import org.sonar.server.computation.component.ComponentVisitor; | |||
import org.sonar.server.computation.component.CrawlerDepthLimit; | |||
import org.sonar.server.computation.component.PathAwareVisitorAdapter; | |||
import org.sonar.server.computation.measure.Measure; | |||
import org.sonar.server.computation.measure.MeasureRepository; | |||
@@ -59,7 +60,7 @@ public class FormulaExecutorComponentVisitor extends PathAwareVisitorAdapter<For | |||
private final List<Formula> formulas; | |||
private FormulaExecutorComponentVisitor(Builder builder, List<Formula> formulas) { | |||
super(Component.Type.FILE, ComponentVisitor.Order.POST_ORDER, COUNTERS_FACTORY); | |||
super(CrawlerDepthLimit.FILE, ComponentVisitor.Order.POST_ORDER, COUNTERS_FACTORY); | |||
this.periodsHolder = builder.periodsHolder; | |||
this.measureRepository = builder.measureRepository; | |||
this.metricRepository = builder.metricRepository; |
@@ -21,12 +21,12 @@ | |||
package org.sonar.server.computation.measure; | |||
import org.sonar.api.ce.measure.MeasureComputer; | |||
import org.sonar.server.computation.component.CrawlerDepthLimit; | |||
import org.sonar.server.computation.component.SettingsRepository; | |||
import org.sonar.server.computation.component.TypeAwareVisitorAdapter; | |||
import org.sonar.server.computation.measure.api.MeasureComputerImplementationContext; | |||
import org.sonar.server.computation.metric.MetricRepository; | |||
import static org.sonar.server.computation.component.Component.Type.FILE; | |||
import static org.sonar.server.computation.component.ComponentVisitor.Order.PRE_ORDER; | |||
public class MeasureComputersVisitor extends TypeAwareVisitorAdapter { | |||
@@ -39,7 +39,7 @@ public class MeasureComputersVisitor extends TypeAwareVisitorAdapter { | |||
public MeasureComputersVisitor(MetricRepository metricRepository, MeasureRepository measureRepository, SettingsRepository settings, | |||
MeasureComputersHolder measureComputersHolder) { | |||
super(FILE, PRE_ORDER); | |||
super(CrawlerDepthLimit.FILE, PRE_ORDER); | |||
this.metricRepository = metricRepository; | |||
this.measureRepository = measureRepository; | |||
this.settings = settings; |
@@ -24,6 +24,7 @@ import com.google.common.base.Optional; | |||
import org.sonar.api.measures.CoreMetrics; | |||
import org.sonar.server.computation.component.Component; | |||
import org.sonar.server.computation.component.ComponentVisitor; | |||
import org.sonar.server.computation.component.CrawlerDepthLimit; | |||
import org.sonar.server.computation.component.PathAwareVisitorAdapter; | |||
import org.sonar.server.computation.measure.Measure; | |||
import org.sonar.server.computation.measure.MeasureRepository; | |||
@@ -44,7 +45,7 @@ public class SqaleMeasuresVisitor extends PathAwareVisitorAdapter<SqaleMeasuresV | |||
private final Metric sqaleRatingMetric; | |||
public SqaleMeasuresVisitor(MetricRepository metricRepository, MeasureRepository measureRepository, SqaleRatingSettings sqaleRatingSettings) { | |||
super(Component.Type.FILE, ComponentVisitor.Order.POST_ORDER, new SimpleStackElementFactory<DevelopmentCost>() { | |||
super(CrawlerDepthLimit.FILE, ComponentVisitor.Order.POST_ORDER, new SimpleStackElementFactory<DevelopmentCost>() { | |||
@Override | |||
public DevelopmentCost createForAny(Component component) { | |||
return new DevelopmentCost(); |
@@ -26,13 +26,13 @@ import org.sonar.db.DbSession; | |||
import org.sonar.db.MyBatis; | |||
import org.sonar.db.permission.PermissionRepository; | |||
import org.sonar.server.computation.component.Component; | |||
import org.sonar.server.computation.component.CrawlerDepthLimit; | |||
import org.sonar.server.computation.component.DbIdsRepository; | |||
import org.sonar.server.computation.component.DepthTraversalTypeAwareCrawler; | |||
import org.sonar.server.computation.component.TreeRootHolder; | |||
import org.sonar.server.computation.component.TypeAwareVisitorAdapter; | |||
import org.sonar.server.issue.index.IssueAuthorizationIndexer; | |||
import static org.sonar.server.computation.component.Component.Type.PROJECT; | |||
import static org.sonar.server.computation.component.ComponentVisitor.Order.PRE_ORDER; | |||
/** | |||
@@ -58,7 +58,7 @@ public class ApplyPermissionsStep implements ComputationStep { | |||
@Override | |||
public void execute() { | |||
new DepthTraversalTypeAwareCrawler( | |||
new TypeAwareVisitorAdapter(PROJECT, PRE_ORDER) { | |||
new TypeAwareVisitorAdapter(CrawlerDepthLimit.PROJECT, PRE_ORDER) { | |||
@Override | |||
public void visitProject(Component project) { | |||
execute(project); |
@@ -26,6 +26,7 @@ import java.util.Map; | |||
import org.sonar.api.measures.CoreMetrics; | |||
import org.sonar.api.utils.MessageException; | |||
import org.sonar.server.computation.component.Component; | |||
import org.sonar.server.computation.component.CrawlerDepthLimit; | |||
import org.sonar.server.computation.component.PathAwareCrawler; | |||
import org.sonar.server.computation.component.PathAwareVisitorAdapter; | |||
import org.sonar.server.computation.component.TreeRootHolder; | |||
@@ -36,7 +37,6 @@ import org.sonar.server.computation.metric.MetricRepository; | |||
import org.sonar.server.computation.qualityprofile.QPMeasureData; | |||
import org.sonar.server.computation.qualityprofile.QualityProfile; | |||
import static org.sonar.server.computation.component.Component.Type.MODULE; | |||
import static org.sonar.server.computation.component.ComponentVisitor.Order.POST_ORDER; | |||
/** | |||
@@ -66,7 +66,7 @@ public class ComputeQProfileMeasureStep implements ComputationStep { | |||
private final Metric qProfilesMetric; | |||
public NewCoverageAggregationComponentCrawler(Metric qProfilesMetric) { | |||
super(MODULE, POST_ORDER, new SimpleStackElementFactory<QProfiles>() { | |||
super(CrawlerDepthLimit.MODULE, POST_ORDER, new SimpleStackElementFactory<QProfiles>() { | |||
@Override | |||
public QProfiles createForAny(Component component) { | |||
return new QProfiles(); |
@@ -28,6 +28,7 @@ import org.sonar.db.MyBatis; | |||
import org.sonar.db.measure.custom.CustomMeasureDto; | |||
import org.sonar.server.computation.component.Component; | |||
import org.sonar.server.computation.component.ComponentVisitor; | |||
import org.sonar.server.computation.component.CrawlerDepthLimit; | |||
import org.sonar.server.computation.component.DepthTraversalTypeAwareCrawler; | |||
import org.sonar.server.computation.component.TreeRootHolder; | |||
import org.sonar.server.computation.component.TypeAwareVisitorAdapter; | |||
@@ -54,7 +55,7 @@ public class CustomMeasuresCopyStep implements ComputationStep { | |||
@Override | |||
public void execute() { | |||
new DepthTraversalTypeAwareCrawler( | |||
new TypeAwareVisitorAdapter(Component.Type.FILE, ComponentVisitor.Order.PRE_ORDER) { | |||
new TypeAwareVisitorAdapter(CrawlerDepthLimit.FILE, ComponentVisitor.Order.PRE_ORDER) { | |||
@Override | |||
public void visitAny(Component component) { | |||
copy(component); |
@@ -44,6 +44,7 @@ import org.sonar.db.component.SnapshotDto; | |||
import org.sonar.db.component.SnapshotQuery; | |||
import org.sonar.server.computation.analysis.AnalysisMetadataHolder; | |||
import org.sonar.server.computation.component.Component; | |||
import org.sonar.server.computation.component.CrawlerDepthLimit; | |||
import org.sonar.server.computation.component.DepthTraversalTypeAwareCrawler; | |||
import org.sonar.server.computation.component.SettingsRepository; | |||
import org.sonar.server.computation.component.TreeRootHolder; | |||
@@ -54,7 +55,6 @@ import org.sonar.server.computation.period.PeriodsHolderImpl; | |||
import static org.sonar.db.component.SnapshotQuery.SORT_FIELD.BY_DATE; | |||
import static org.sonar.db.component.SnapshotQuery.SORT_ORDER.ASC; | |||
import static org.sonar.db.component.SnapshotQuery.SORT_ORDER.DESC; | |||
import static org.sonar.server.computation.component.Component.Type.PROJECT; | |||
import static org.sonar.server.computation.component.ComponentVisitor.Order.PRE_ORDER; | |||
/** | |||
@@ -89,7 +89,7 @@ public class FeedPeriodsStep implements ComputationStep { | |||
@Override | |||
public void execute() { | |||
new DepthTraversalTypeAwareCrawler( | |||
new TypeAwareVisitorAdapter(PROJECT, PRE_ORDER) { | |||
new TypeAwareVisitorAdapter(CrawlerDepthLimit.PROJECT, PRE_ORDER) { | |||
@Override | |||
public void visitProject(Component project) { | |||
execute(project); |
@@ -35,6 +35,7 @@ import org.sonar.db.DbClient; | |||
import org.sonar.db.DbSession; | |||
import org.sonar.db.measure.PastMeasureDto; | |||
import org.sonar.server.computation.component.Component; | |||
import org.sonar.server.computation.component.CrawlerDepthLimit; | |||
import org.sonar.server.computation.component.DepthTraversalTypeAwareCrawler; | |||
import org.sonar.server.computation.component.TreeRootHolder; | |||
import org.sonar.server.computation.component.TypeAwareVisitorAdapter; | |||
@@ -86,22 +87,22 @@ public class FillMeasuresWithVariationsStep implements ComputationStep { | |||
DbSession dbSession = dbClient.openSession(false); | |||
try { | |||
Iterable<Metric> metrics = FluentIterable.from(metricRepository.getAll()).filter(NumericMetric.INSTANCE); | |||
new DepthTraversalTypeAwareCrawler(new VariationMeasuresCrawler(dbSession, metrics)) | |||
new DepthTraversalTypeAwareCrawler(new VariationMeasuresVisitor(dbSession, metrics)) | |||
.visit(treeRootHolder.getRoot()); | |||
} finally { | |||
dbSession.close(); | |||
} | |||
} | |||
private class VariationMeasuresCrawler extends TypeAwareVisitorAdapter { | |||
private class VariationMeasuresVisitor extends TypeAwareVisitorAdapter { | |||
private final DbSession session; | |||
private final Set<Integer> metricIds; | |||
private final Map<String, Metric> metricByKeys; | |||
public VariationMeasuresCrawler(DbSession session, Iterable<Metric> metrics) { | |||
public VariationMeasuresVisitor(DbSession session, Iterable<Metric> metrics) { | |||
// measures on files are currently purged, so past measures are not available on files | |||
super(Component.Type.DIRECTORY, PRE_ORDER); | |||
super(CrawlerDepthLimit.DIRECTORY, PRE_ORDER); | |||
this.session = session; | |||
this.metricIds = FluentIterable.from(metrics).transform(MetricDtoToMetricId.INSTANCE).toSet(); | |||
this.metricByKeys = FluentIterable.from(metrics).uniqueIndex(MetricToKey.INSTANCE); |
@@ -27,6 +27,7 @@ import org.sonar.api.utils.log.Loggers; | |||
import org.sonar.core.issue.DefaultIssue; | |||
import org.sonar.core.issue.tracking.Tracking; | |||
import org.sonar.server.computation.component.Component; | |||
import org.sonar.server.computation.component.CrawlerDepthLimit; | |||
import org.sonar.server.computation.component.DepthTraversalTypeAwareCrawler; | |||
import org.sonar.server.computation.component.TreeRootHolder; | |||
import org.sonar.server.computation.component.TypeAwareVisitorAdapter; | |||
@@ -65,7 +66,7 @@ public class IntegrateIssuesStep implements ComputationStep { | |||
final Set<String> unprocessedComponentUuids = Sets.newHashSet(baseIssuesLoader.loadUuidsOfComponentsWithOpenIssues()); | |||
new DepthTraversalTypeAwareCrawler( | |||
new TypeAwareVisitorAdapter(Component.Type.FILE, POST_ORDER) { | |||
new TypeAwareVisitorAdapter(CrawlerDepthLimit.FILE, POST_ORDER) { | |||
@Override | |||
public void visitAny(Component component) { | |||
processIssues(component); |
@@ -32,6 +32,7 @@ import org.sonar.db.measure.MeasureDto; | |||
import org.sonar.db.metric.MetricDto; | |||
import org.sonar.server.computation.batch.BatchReportReader; | |||
import org.sonar.server.computation.component.Component; | |||
import org.sonar.server.computation.component.CrawlerDepthLimit; | |||
import org.sonar.server.computation.component.DbIdsRepository; | |||
import org.sonar.server.computation.component.DepthTraversalTypeAwareCrawler; | |||
import org.sonar.server.computation.component.ReportTreeRootHolder; | |||
@@ -75,7 +76,7 @@ public class PersistDuplicationsStep implements ComputationStep { | |||
private final MetricDto duplicationMetric; | |||
private DuplicationVisitor(DbSession session, MetricDto duplicationMetric) { | |||
super(Component.Type.FILE, PRE_ORDER); | |||
super(CrawlerDepthLimit.FILE, PRE_ORDER); | |||
this.session = session; | |||
this.duplicationMetric = duplicationMetric; | |||
} |
@@ -30,6 +30,7 @@ import org.sonar.db.event.EventDto; | |||
import org.sonar.server.computation.analysis.AnalysisMetadataHolder; | |||
import org.sonar.server.computation.component.Component; | |||
import org.sonar.server.computation.component.ComponentVisitor; | |||
import org.sonar.server.computation.component.CrawlerDepthLimit; | |||
import org.sonar.server.computation.component.DbIdsRepository; | |||
import org.sonar.server.computation.component.DepthTraversalTypeAwareCrawler; | |||
import org.sonar.server.computation.component.TreeRootHolder; | |||
@@ -63,7 +64,7 @@ public class PersistEventsStep implements ComputationStep { | |||
final DbSession session = dbClient.openSession(false); | |||
try { | |||
long analysisDate = analysisMetadataHolder.getAnalysisDate().getTime(); | |||
new DepthTraversalTypeAwareCrawler(new PersistEventComponentCrawler(session, analysisDate)) | |||
new DepthTraversalTypeAwareCrawler(new PersistEventComponentVisitor(session, analysisDate)) | |||
.visit(treeRootHolder.getRoot()); | |||
session.commit(); | |||
} finally { | |||
@@ -135,12 +136,12 @@ public class PersistEventsStep implements ComputationStep { | |||
return "Persist component links"; | |||
} | |||
private class PersistEventComponentCrawler extends TypeAwareVisitorAdapter { | |||
private class PersistEventComponentVisitor extends TypeAwareVisitorAdapter { | |||
private final DbSession session; | |||
private final long analysisDate; | |||
public PersistEventComponentCrawler(DbSession session, long analysisDate) { | |||
super(Component.Type.FILE, ComponentVisitor.Order.PRE_ORDER); | |||
public PersistEventComponentVisitor(DbSession session, long analysisDate) { | |||
super(CrawlerDepthLimit.FILE, ComponentVisitor.Order.PRE_ORDER); | |||
this.session = session; | |||
this.analysisDate = analysisDate; | |||
} |
@@ -39,6 +39,7 @@ import org.sonar.db.source.FileSourceDto; | |||
import org.sonar.db.source.FileSourceDto.Type; | |||
import org.sonar.server.computation.batch.BatchReportReader; | |||
import org.sonar.server.computation.component.Component; | |||
import org.sonar.server.computation.component.CrawlerDepthLimit; | |||
import org.sonar.server.computation.component.DepthTraversalTypeAwareCrawler; | |||
import org.sonar.server.computation.component.TreeRootHolder; | |||
import org.sonar.server.computation.component.TypeAwareVisitorAdapter; | |||
@@ -71,22 +72,22 @@ public class PersistFileSourcesStep implements ComputationStep { | |||
// Don't use batch insert for file_sources since keeping all data in memory can produce OOM for big files | |||
DbSession session = dbClient.openSession(false); | |||
try { | |||
new DepthTraversalTypeAwareCrawler(new FileSourceCrawler(session)) | |||
new DepthTraversalTypeAwareCrawler(new FileSourceVisitor(session)) | |||
.visit(treeRootHolder.getRoot()); | |||
} finally { | |||
MyBatis.closeQuietly(session); | |||
} | |||
} | |||
private class FileSourceCrawler extends TypeAwareVisitorAdapter { | |||
private class FileSourceVisitor extends TypeAwareVisitorAdapter { | |||
private final DbSession session; | |||
private Map<String, FileSourceDto> previousFileSourcesByUuid = new HashMap<>(); | |||
private String projectUuid; | |||
private FileSourceCrawler(DbSession session) { | |||
super(Component.Type.FILE, PRE_ORDER); | |||
private FileSourceVisitor(DbSession session) { | |||
super(CrawlerDepthLimit.FILE, PRE_ORDER); | |||
this.session = session; | |||
} | |||
@@ -32,6 +32,7 @@ import org.sonar.db.DbClient; | |||
import org.sonar.db.DbSession; | |||
import org.sonar.db.measure.MeasureDto; | |||
import org.sonar.server.computation.component.Component; | |||
import org.sonar.server.computation.component.CrawlerDepthLimit; | |||
import org.sonar.server.computation.component.DbIdsRepository; | |||
import org.sonar.server.computation.component.DepthTraversalTypeAwareCrawler; | |||
import org.sonar.server.computation.component.TreeRootHolder; | |||
@@ -83,18 +84,18 @@ public class PersistMeasuresStep implements ComputationStep { | |||
public void execute() { | |||
DbSession dbSession = dbClient.openSession(true); | |||
try { | |||
new DepthTraversalTypeAwareCrawler(new MeasureCrawler(dbSession)).visit(treeRootHolder.getRoot()); | |||
new DepthTraversalTypeAwareCrawler(new MeasureVisitor(dbSession)).visit(treeRootHolder.getRoot()); | |||
dbSession.commit(); | |||
} finally { | |||
dbSession.close(); | |||
} | |||
} | |||
private class MeasureCrawler extends TypeAwareVisitorAdapter { | |||
private class MeasureVisitor extends TypeAwareVisitorAdapter { | |||
private final DbSession session; | |||
private MeasureCrawler(DbSession session) { | |||
super(Component.Type.FILE, PRE_ORDER); | |||
private MeasureVisitor(DbSession session) { | |||
super(CrawlerDepthLimit.FILE, PRE_ORDER); | |||
this.session = session; | |||
} | |||
@@ -32,6 +32,7 @@ import org.sonar.db.MyBatis; | |||
import org.sonar.db.measure.MeasureDto; | |||
import org.sonar.server.computation.batch.BatchReportReader; | |||
import org.sonar.server.computation.component.Component; | |||
import org.sonar.server.computation.component.CrawlerDepthLimit; | |||
import org.sonar.server.computation.component.DbIdsRepository; | |||
import org.sonar.server.computation.component.DepthTraversalTypeAwareCrawler; | |||
import org.sonar.server.computation.component.TreeRootHolder; | |||
@@ -72,7 +73,7 @@ public class PersistNumberOfDaysSinceLastCommitStep implements ComputationStep { | |||
@Override | |||
public void execute() { | |||
NumberOfDaysSinceLastCommitCrawler visitor = new NumberOfDaysSinceLastCommitCrawler(); | |||
NumberOfDaysSinceLastCommitVisitor visitor = new NumberOfDaysSinceLastCommitVisitor(); | |||
Component project = treeRootHolder.getRoot(); | |||
new DepthTraversalTypeAwareCrawler(visitor).visit(project); | |||
@@ -107,12 +108,12 @@ public class PersistNumberOfDaysSinceLastCommitStep implements ComputationStep { | |||
} | |||
} | |||
private class NumberOfDaysSinceLastCommitCrawler extends TypeAwareVisitorAdapter { | |||
private class NumberOfDaysSinceLastCommitVisitor extends TypeAwareVisitorAdapter { | |||
private long lastCommitTimestampFromReport = 0L; | |||
private NumberOfDaysSinceLastCommitCrawler() { | |||
super(Component.Type.FILE, PRE_ORDER); | |||
private NumberOfDaysSinceLastCommitVisitor() { | |||
super(CrawlerDepthLimit.FILE, PRE_ORDER); | |||
} | |||
@Override |
@@ -37,6 +37,7 @@ import org.sonar.db.MyBatis; | |||
import org.sonar.db.component.ComponentLinkDto; | |||
import org.sonar.server.computation.batch.BatchReportReader; | |||
import org.sonar.server.computation.component.Component; | |||
import org.sonar.server.computation.component.CrawlerDepthLimit; | |||
import org.sonar.server.computation.component.DepthTraversalTypeAwareCrawler; | |||
import org.sonar.server.computation.component.TreeRootHolder; | |||
import org.sonar.server.computation.component.TypeAwareVisitorAdapter; | |||
@@ -72,7 +73,7 @@ public class PersistProjectLinksStep implements ComputationStep { | |||
public void execute() { | |||
DbSession session = dbClient.openSession(false); | |||
try { | |||
new DepthTraversalTypeAwareCrawler(new PorjectLinkCrawler(session)) | |||
new DepthTraversalTypeAwareCrawler(new ProjectLinkVisitor(session)) | |||
.visit(treeRootHolder.getRoot()); | |||
session.commit(); | |||
} finally { | |||
@@ -80,12 +81,12 @@ public class PersistProjectLinksStep implements ComputationStep { | |||
} | |||
} | |||
private class PorjectLinkCrawler extends TypeAwareVisitorAdapter { | |||
private class ProjectLinkVisitor extends TypeAwareVisitorAdapter { | |||
private final DbSession session; | |||
private PorjectLinkCrawler(DbSession session) { | |||
super(Component.Type.FILE, PRE_ORDER); | |||
private ProjectLinkVisitor(DbSession session) { | |||
super(CrawlerDepthLimit.FILE, PRE_ORDER); | |||
this.session = session; | |||
} | |||
@@ -40,6 +40,10 @@ import org.sonar.server.computation.component.TreeRootHolder; | |||
import org.sonar.server.computation.period.Period; | |||
import org.sonar.server.computation.period.PeriodsHolder; | |||
import static org.sonar.server.computation.component.Component.Type.FILE; | |||
import static org.sonar.server.computation.component.Component.Type.PROJECT_VIEW; | |||
import static org.sonar.server.computation.component.CrawlerDepthLimit.reportMaxDepth; | |||
/** | |||
* Persist snapshots | |||
* Also feed the components cache {@link DbIdsRepositoryImpl} with snapshot ids | |||
@@ -68,7 +72,7 @@ public class PersistSnapshotsStep implements ComputationStep { | |||
DbSession session = dbClient.openSession(false); | |||
try { | |||
new PathAwareCrawler<>( | |||
new PersistSnapshotsPathAwareCrawler(session, analysisMetadataHolder.getAnalysisDate().getTime(), dbIdsRepository)) | |||
new PersistSnapshotsPathAwareVisitor(session, analysisMetadataHolder.getAnalysisDate().getTime(), dbIdsRepository)) | |||
.visit(treeRootHolder.getRoot()); | |||
session.commit(); | |||
} finally { | |||
@@ -76,7 +80,7 @@ public class PersistSnapshotsStep implements ComputationStep { | |||
} | |||
} | |||
private class PersistSnapshotsPathAwareCrawler extends PathAwareVisitorAdapter<SnapshotDtoHolder> { | |||
private class PersistSnapshotsPathAwareVisitor extends PathAwareVisitorAdapter<SnapshotDtoHolder> { | |||
private final DbSession dbSession; | |||
private final long analysisDate; | |||
@@ -84,8 +88,8 @@ public class PersistSnapshotsStep implements ComputationStep { | |||
private long rootId; | |||
public PersistSnapshotsPathAwareCrawler(DbSession dbSession, long analysisDate, DbIdsRepository dbIdsRepository) { | |||
super(Component.Type.FILE, Order.PRE_ORDER, SnapshotDtoHolderFactory.INSTANCE); | |||
public PersistSnapshotsPathAwareVisitor(DbSession dbSession, long analysisDate, DbIdsRepository dbIdsRepository) { | |||
super(reportMaxDepth(FILE).withViewsMaxDepth(PROJECT_VIEW), Order.PRE_ORDER, SnapshotDtoHolderFactory.INSTANCE); | |||
this.dbSession = dbSession; | |||
this.analysisDate = analysisDate; | |||
this.dbIdsRepository = dbIdsRepository; |
@@ -50,6 +50,7 @@ import org.sonar.db.source.FileSourceDto.Type; | |||
import org.sonar.server.computation.batch.BatchReportReader; | |||
import org.sonar.server.computation.component.Component; | |||
import org.sonar.server.computation.component.ComponentVisitor; | |||
import org.sonar.server.computation.component.CrawlerDepthLimit; | |||
import org.sonar.server.computation.component.DepthTraversalTypeAwareCrawler; | |||
import org.sonar.server.computation.component.ReportTreeRootHolder; | |||
import org.sonar.server.computation.component.TypeAwareVisitorAdapter; | |||
@@ -74,7 +75,7 @@ public class PersistTestsStep implements ComputationStep { | |||
public void execute() { | |||
DbSession session = dbClient.openSession(true); | |||
try { | |||
TestDepthTraversalTypeAwareCrawler visitor = new TestDepthTraversalTypeAwareCrawler(session); | |||
TestDepthTraversalTypeAwareVisitor visitor = new TestDepthTraversalTypeAwareVisitor(session); | |||
new DepthTraversalTypeAwareCrawler(visitor).visit(treeRootHolder.getRoot()); | |||
session.commit(); | |||
if (visitor.hasUnprocessedCoverageDetails) { | |||
@@ -90,15 +91,15 @@ public class PersistTestsStep implements ComputationStep { | |||
return "Persist tests"; | |||
} | |||
private class TestDepthTraversalTypeAwareCrawler extends TypeAwareVisitorAdapter { | |||
private class TestDepthTraversalTypeAwareVisitor extends TypeAwareVisitorAdapter { | |||
final DbSession session; | |||
final Map<String, FileSourceDto> existingFileSourcesByUuid; | |||
final String projectUuid; | |||
final String projectKey; | |||
boolean hasUnprocessedCoverageDetails = false; | |||
public TestDepthTraversalTypeAwareCrawler(DbSession session) { | |||
super(Component.Type.FILE, ComponentVisitor.Order.PRE_ORDER); | |||
public TestDepthTraversalTypeAwareVisitor(DbSession session) { | |||
super(CrawlerDepthLimit.FILE, ComponentVisitor.Order.PRE_ORDER); | |||
this.session = session; | |||
this.existingFileSourcesByUuid = new HashMap<>(); | |||
this.projectUuid = treeRootHolder.getRoot().getUuid(); |
@@ -27,6 +27,7 @@ import org.sonar.api.utils.log.Logger; | |||
import org.sonar.api.utils.log.Loggers; | |||
import org.sonar.server.computation.component.Component; | |||
import org.sonar.server.computation.component.ComponentVisitor; | |||
import org.sonar.server.computation.component.CrawlerDepthLimit; | |||
import org.sonar.server.computation.component.DepthTraversalTypeAwareCrawler; | |||
import org.sonar.server.computation.component.TreeRootHolder; | |||
import org.sonar.server.computation.component.TypeAwareVisitorAdapter; | |||
@@ -64,7 +65,7 @@ public class QualityGateEventsStep implements ComputationStep { | |||
@Override | |||
public void execute() { | |||
new DepthTraversalTypeAwareCrawler( | |||
new TypeAwareVisitorAdapter(Component.Type.PROJECT, ComponentVisitor.Order.PRE_ORDER) { | |||
new TypeAwareVisitorAdapter(CrawlerDepthLimit.PROJECT, ComponentVisitor.Order.PRE_ORDER) { | |||
@Override | |||
public void visitProject(Component project) { | |||
executeForProject(project); |
@@ -26,6 +26,7 @@ import org.sonar.api.utils.log.Logger; | |||
import org.sonar.api.utils.log.Loggers; | |||
import org.sonar.server.computation.ReportQueue; | |||
import org.sonar.server.computation.component.Component; | |||
import org.sonar.server.computation.component.CrawlerDepthLimit; | |||
import org.sonar.server.computation.component.DepthTraversalTypeAwareCrawler; | |||
import org.sonar.server.computation.component.SettingsRepository; | |||
import org.sonar.server.computation.component.TreeRootHolder; | |||
@@ -34,7 +35,6 @@ import org.sonar.server.computation.qualitygate.MutableQualityGateHolder; | |||
import org.sonar.server.computation.qualitygate.QualityGate; | |||
import org.sonar.server.computation.qualitygate.QualityGateService; | |||
import static org.sonar.server.computation.component.Component.Type.PROJECT; | |||
import static org.sonar.server.computation.component.ComponentVisitor.Order.PRE_ORDER; | |||
/** | |||
@@ -62,7 +62,7 @@ public class QualityGateLoadingStep implements ComputationStep { | |||
@Override | |||
public void execute() { | |||
new DepthTraversalTypeAwareCrawler( | |||
new TypeAwareVisitorAdapter(PROJECT, PRE_ORDER) { | |||
new TypeAwareVisitorAdapter(CrawlerDepthLimit.PROJECT, PRE_ORDER) { | |||
@Override | |||
public void visitProject(Component project) { | |||
executeForProject(project); |
@@ -27,6 +27,7 @@ import javax.annotation.Nullable; | |||
import org.apache.commons.lang.StringUtils; | |||
import org.sonar.api.measures.CoreMetrics; | |||
import org.sonar.server.computation.component.Component; | |||
import org.sonar.server.computation.component.CrawlerDepthLimit; | |||
import org.sonar.server.computation.component.DepthTraversalTypeAwareCrawler; | |||
import org.sonar.server.computation.component.TreeRootHolder; | |||
import org.sonar.server.computation.component.TypeAwareVisitorAdapter; | |||
@@ -44,7 +45,6 @@ import org.sonar.server.computation.qualitygate.EvaluationResultTextConverter; | |||
import org.sonar.server.computation.qualitygate.QualityGate; | |||
import org.sonar.server.computation.qualitygate.QualityGateHolder; | |||
import static org.sonar.server.computation.component.Component.Type.PROJECT; | |||
import static org.sonar.server.computation.component.ComponentVisitor.Order.PRE_ORDER; | |||
/** | |||
@@ -79,7 +79,7 @@ public class QualityGateMeasuresStep implements ComputationStep { | |||
@Override | |||
public void execute() { | |||
new DepthTraversalTypeAwareCrawler( | |||
new TypeAwareVisitorAdapter(PROJECT, PRE_ORDER) { | |||
new TypeAwareVisitorAdapter(CrawlerDepthLimit.PROJECT, PRE_ORDER) { | |||
@Override | |||
public void visitProject(Component project) { | |||
executeForProject(project); |
@@ -31,6 +31,7 @@ import org.sonar.api.resources.Language; | |||
import org.sonar.api.utils.KeyValueFormat; | |||
import org.sonar.core.util.UtcDateUtils; | |||
import org.sonar.server.computation.component.Component; | |||
import org.sonar.server.computation.component.CrawlerDepthLimit; | |||
import org.sonar.server.computation.component.DepthTraversalTypeAwareCrawler; | |||
import org.sonar.server.computation.component.TreeRootHolder; | |||
import org.sonar.server.computation.component.TypeAwareVisitorAdapter; | |||
@@ -70,7 +71,7 @@ public class QualityProfileEventsStep implements ComputationStep { | |||
@Override | |||
public void execute() { | |||
new DepthTraversalTypeAwareCrawler( | |||
new TypeAwareVisitorAdapter(Component.Type.PROJECT, POST_ORDER) { | |||
new TypeAwareVisitorAdapter(CrawlerDepthLimit.PROJECT, POST_ORDER) { | |||
@Override | |||
public void visitProject(Component tree) { | |||
executeForProject(tree); |
@@ -22,6 +22,7 @@ package org.sonar.server.computation.step; | |||
import com.google.common.collect.ImmutableList; | |||
import org.sonar.api.measures.CoreMetrics; | |||
import org.sonar.server.computation.component.Component; | |||
import org.sonar.server.computation.component.CrawlerDepthLimit; | |||
import org.sonar.server.computation.component.PathAwareCrawler; | |||
import org.sonar.server.computation.component.PathAwareVisitorAdapter; | |||
import org.sonar.server.computation.component.TreeRootHolder; | |||
@@ -40,7 +41,6 @@ import static org.sonar.api.measures.CoreMetrics.GENERATED_NCLOC_KEY; | |||
import static org.sonar.api.measures.CoreMetrics.LINES_KEY; | |||
import static org.sonar.api.measures.CoreMetrics.NCLOC_KEY; | |||
import static org.sonar.api.measures.CoreMetrics.STATEMENTS_KEY; | |||
import static org.sonar.server.computation.component.Component.Type.FILE; | |||
import static org.sonar.server.computation.component.ComponentVisitor.Order.POST_ORDER; | |||
import static org.sonar.server.computation.measure.Measure.newMeasureBuilder; | |||
@@ -75,7 +75,7 @@ public class SizeMeasuresStep implements ComputationStep { | |||
Metric fileMetric = metricRepository.getByKey(CoreMetrics.FILES_KEY); | |||
Metric directoryMetric = metricRepository.getByKey(CoreMetrics.DIRECTORIES_KEY); | |||
new PathAwareCrawler<>(new FileAndDirectoryMeasureCrawler(directoryMetric, fileMetric)) | |||
new PathAwareCrawler<>(new FileAndDirectoryMeasureVisitor(directoryMetric, fileMetric)) | |||
.visit(treeRootHolder.getRoot()); | |||
new PathAwareCrawler<>(FormulaExecutorComponentVisitor.newBuilder(metricRepository, measureRepository) | |||
.buildFor(AGGREGATED_SIZE_MEASURE_FORMULAS)) | |||
@@ -87,12 +87,12 @@ public class SizeMeasuresStep implements ComputationStep { | |||
return "File and Directory measures"; | |||
} | |||
private class FileAndDirectoryMeasureCrawler extends PathAwareVisitorAdapter<Counter> { | |||
private class FileAndDirectoryMeasureVisitor extends PathAwareVisitorAdapter<Counter> { | |||
private final Metric directoryMetric; | |||
private final Metric fileMetric; | |||
public FileAndDirectoryMeasureCrawler(Metric directoryMetric, Metric fileMetric) { | |||
super(FILE, POST_ORDER, COUNTER_STACK_ELEMENT_FACTORY); | |||
public FileAndDirectoryMeasureVisitor(Metric directoryMetric, Metric fileMetric) { | |||
super(CrawlerDepthLimit.FILE, POST_ORDER, COUNTER_STACK_ELEMENT_FACTORY); | |||
this.directoryMetric = directoryMetric; | |||
this.fileMetric = fileMetric; | |||
} |
@@ -43,6 +43,7 @@ import org.sonar.db.component.SnapshotDto; | |||
import org.sonar.server.computation.batch.BatchReportReader; | |||
import org.sonar.server.computation.component.Component; | |||
import org.sonar.server.computation.component.ComponentVisitor; | |||
import org.sonar.server.computation.component.CrawlerDepthLimit; | |||
import org.sonar.server.computation.component.DepthTraversalTypeAwareCrawler; | |||
import org.sonar.server.computation.component.TreeRootHolder; | |||
import org.sonar.server.computation.component.TypeAwareVisitorAdapter; | |||
@@ -82,7 +83,7 @@ public class ValidateProjectStep implements ComputationStep { | |||
try { | |||
List<ComponentDto> baseModules = dbClient.componentDao().selectEnabledModulesFromProjectKey(session, treeRootHolder.getRoot().getKey()); | |||
Map<String, ComponentDto> baseModulesByKey = FluentIterable.from(baseModules).uniqueIndex(ComponentDtoToKey.INSTANCE); | |||
ValidateProjectsCrawler visitor = new ValidateProjectsCrawler(session, dbClient.componentDao(), | |||
ValidateProjectsVisitor visitor = new ValidateProjectsVisitor(session, dbClient.componentDao(), | |||
settings.getBoolean(CoreProperties.CORE_PREVENT_AUTOMATIC_PROJECT_CREATION), baseModulesByKey); | |||
new DepthTraversalTypeAwareCrawler(visitor).visit(treeRootHolder.getRoot()); | |||
@@ -99,7 +100,7 @@ public class ValidateProjectStep implements ComputationStep { | |||
return "Validate project and modules keys"; | |||
} | |||
private class ValidateProjectsCrawler extends TypeAwareVisitorAdapter { | |||
private class ValidateProjectsVisitor extends TypeAwareVisitorAdapter { | |||
private final DbSession session; | |||
private final ComponentDao componentDao; | |||
private final boolean preventAutomaticProjectCreation; | |||
@@ -108,8 +109,8 @@ public class ValidateProjectStep implements ComputationStep { | |||
private Component rawProject; | |||
public ValidateProjectsCrawler(DbSession session, ComponentDao componentDao, boolean preventAutomaticProjectCreation, Map<String, ComponentDto> baseModulesByKey) { | |||
super(Component.Type.MODULE, ComponentVisitor.Order.PRE_ORDER); | |||
public ValidateProjectsVisitor(DbSession session, ComponentDao componentDao, boolean preventAutomaticProjectCreation, Map<String, ComponentDto> baseModulesByKey) { | |||
super(CrawlerDepthLimit.MODULE, ComponentVisitor.Order.PRE_ORDER); | |||
this.session = session; | |||
this.componentDao = componentDao; | |||
@@ -26,6 +26,7 @@ import org.junit.rules.TestRule; | |||
import org.junit.runner.Description; | |||
import org.junit.runners.model.Statement; | |||
import org.sonar.server.computation.component.Component; | |||
import org.sonar.server.computation.component.CrawlerDepthLimit; | |||
import org.sonar.server.computation.component.DepthTraversalTypeAwareCrawler; | |||
import org.sonar.server.computation.component.MutableTreeRootHolder; | |||
import org.sonar.server.computation.component.ReportTreeRootHolder; | |||
@@ -80,7 +81,7 @@ public class TreeRootHolderRule implements TestRule, MutableTreeRootHolder, Repo | |||
public TreeRootHolderRule setRoot(Component newRoot) { | |||
this.root = Objects.requireNonNull(newRoot); | |||
if (newRoot.getType().isReportType()) { | |||
new DepthTraversalTypeAwareCrawler(new TypeAwareVisitorAdapter(Component.Type.FILE, POST_ORDER) { | |||
new DepthTraversalTypeAwareCrawler(new TypeAwareVisitorAdapter(CrawlerDepthLimit.FILE, POST_ORDER) { | |||
@Override | |||
public void visitAny(Component component) { | |||
componentsByRef.put(component.getReportAttributes().getRef(), component); |
@@ -31,7 +31,7 @@ import static com.google.common.collect.FluentIterable.from; | |||
class CallRecorderPathAwareVisitor extends PathAwareVisitorAdapter<Integer> { | |||
final List<PathAwareCallRecord> callsRecords = new ArrayList<>(); | |||
public CallRecorderPathAwareVisitor(Component.Type maxDepth, Order order) { | |||
public CallRecorderPathAwareVisitor(CrawlerDepthLimit maxDepth, Order order) { | |||
super(maxDepth, order, new SimpleStackElementFactory<Integer>() { | |||
@Override | |||
public Integer createForAny(Component component) { |
@@ -25,7 +25,7 @@ import java.util.List; | |||
class CallRecorderTypeAwareVisitor extends TypeAwareVisitorAdapter { | |||
final List<CallRecord> callsRecords = new ArrayList<>(); | |||
public CallRecorderTypeAwareVisitor(Component.Type maxDepth, Order order) { | |||
public CallRecorderTypeAwareVisitor(CrawlerDepthLimit maxDepth, Order order) { | |||
super(maxDepth, order); | |||
} | |||
@@ -0,0 +1,333 @@ | |||
/* | |||
* SonarQube, open source software quality management tool. | |||
* Copyright (C) 2008-2014 SonarSource | |||
* mailto:contact AT sonarsource DOT com | |||
* | |||
* SonarQube 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. | |||
* | |||
* SonarQube 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 this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonar.server.computation.component; | |||
import com.google.common.base.Function; | |||
import com.google.common.base.Predicate; | |||
import com.tngtech.java.junit.dataprovider.DataProvider; | |||
import com.tngtech.java.junit.dataprovider.DataProviderRunner; | |||
import com.tngtech.java.junit.dataprovider.UseDataProvider; | |||
import java.util.Arrays; | |||
import java.util.Set; | |||
import javax.annotation.Nullable; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.junit.runner.RunWith; | |||
import org.sonar.server.computation.component.Component.Type; | |||
import static com.google.common.base.Predicates.equalTo; | |||
import static com.google.common.base.Predicates.in; | |||
import static com.google.common.base.Predicates.not; | |||
import static com.google.common.collect.FluentIterable.from; | |||
import static java.util.Arrays.asList; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
@RunWith(DataProviderRunner.class) | |||
public class CrawlerDepthLimitTest { | |||
private static final Set<Type> REPORT_TYPES = from(asList(Type.values())).filter(new Predicate<Type>() { | |||
@Override | |||
public boolean apply(Type input) { | |||
return input.isReportType(); | |||
} | |||
}).toSet(); | |||
private static final Set<Type> VIEWS_TYPES = from(asList(Type.values())).filter(new Predicate<Type>() { | |||
@Override | |||
public boolean apply(Type input) { | |||
return input.isViewsType(); | |||
} | |||
}).toSet(); | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
@Test | |||
public void PROJECT_isSameAs_only_PROJECT_type() { | |||
assertIsSameAs(CrawlerDepthLimit.PROJECT, Type.PROJECT); | |||
} | |||
@Test | |||
public void PROJECT_isDeeper_than_no_type() { | |||
for (Type type : Type.values()) { | |||
assertThat(CrawlerDepthLimit.PROJECT.isDeeperThan(type)).as("isHigherThan(%s)", type).isFalse(); | |||
} | |||
} | |||
@Test | |||
public void PROJECT_isHigher_than_all_report_types_but_PROJECT() { | |||
assertThat(CrawlerDepthLimit.PROJECT.isHigherThan(Type.PROJECT)).isFalse(); | |||
for (Type reportType : from(REPORT_TYPES).filter(not(equalTo(Type.PROJECT)))) { | |||
assertThat(CrawlerDepthLimit.PROJECT.isHigherThan(reportType)).as("isHigherThan(%s)", reportType).isTrue(); | |||
} | |||
} | |||
@Test | |||
public void PROJECT_isDeeper_than_no_views_types() { | |||
for (Type viewsType : VIEWS_TYPES) { | |||
assertThat(CrawlerDepthLimit.PROJECT.isDeeperThan(viewsType)).as("isDeeperThan(%s)", viewsType).isFalse(); | |||
} | |||
} | |||
@Test | |||
public void PROJECT_isHigher_than_no_views_types() { | |||
assertIsHigherThanViewsType(CrawlerDepthLimit.PROJECT); | |||
} | |||
@Test | |||
public void MODULE_isSameAs_only_MODULE_type() { | |||
assertIsSameAs(CrawlerDepthLimit.MODULE, Type.MODULE); | |||
} | |||
@Test | |||
public void MODULE_isDeeper_than_no_views_types() { | |||
assertIsDeeperThanViewsType(CrawlerDepthLimit.MODULE); | |||
} | |||
@Test | |||
public void MODULE_isDeeper_than_only_PROJECT_report_types() { | |||
assertIsDeeperThanReportType(CrawlerDepthLimit.MODULE, Type.PROJECT); | |||
} | |||
@Test | |||
public void MODULE_isHigher_than_no_views_types() { | |||
assertIsHigherThanViewsType(CrawlerDepthLimit.MODULE); | |||
} | |||
@Test | |||
public void MODULE_isHigher_than_only_DIRECTORY_and_FILE() { | |||
assertIsHigherThanReportType(CrawlerDepthLimit.MODULE, Type.DIRECTORY, Type.FILE); | |||
} | |||
@Test | |||
public void DIRECTORY_isSameAs_only_DIRECTORY_type() { | |||
assertIsSameAs(CrawlerDepthLimit.DIRECTORY, Type.DIRECTORY); | |||
} | |||
@Test | |||
public void DIRECTORY_isDeeper_than_no_views_types() { | |||
assertIsDeeperThanViewsType(CrawlerDepthLimit.DIRECTORY); | |||
} | |||
@Test | |||
public void DIRECTORY_isDeeper_than_only_PROJECT_and_MODULE_report_types() { | |||
assertIsDeeperThanReportType(CrawlerDepthLimit.DIRECTORY, Type.PROJECT, Type.MODULE); | |||
} | |||
@Test | |||
public void DIRECTORY_isHigher_than_only_FILE() { | |||
assertIsHigherThanReportType(CrawlerDepthLimit.DIRECTORY, Type.FILE); | |||
} | |||
@Test | |||
public void DIRECTORY_isHigher_than_no_views_type() { | |||
assertIsHigherThanViewsType(CrawlerDepthLimit.DIRECTORY); | |||
} | |||
@Test | |||
public void FILE_isSameAs_only_FILE_type() { | |||
assertIsSameAs(CrawlerDepthLimit.FILE, Type.FILE); | |||
} | |||
@Test | |||
public void FILE_isDeeper_than_no_views_types() { | |||
for (Type viewsType : VIEWS_TYPES) { | |||
assertThat(CrawlerDepthLimit.FILE.isDeeperThan(viewsType)).as("isDeeperThan(%s)", viewsType).isFalse(); | |||
} | |||
} | |||
@Test | |||
public void FILE_isHigher_than_no_views_types() { | |||
assertIsHigherThanViewsType(CrawlerDepthLimit.FILE); | |||
} | |||
@Test | |||
public void FILE_isHigher_than_no_report_types() { | |||
assertIsHigherThanReportType(CrawlerDepthLimit.FILE); | |||
} | |||
@Test | |||
public void FILE_isDeeper_than_only_PROJECT_MODULE_and_DIRECTORY_report_types() { | |||
assertIsDeeperThanReportType(CrawlerDepthLimit.FILE, Type.PROJECT, Type.MODULE, Type.DIRECTORY); | |||
} | |||
@Test | |||
public void VIEW_isSameAs_only_VIEW_type() { | |||
assertIsSameAs(CrawlerDepthLimit.VIEW, Type.VIEW); | |||
} | |||
@Test | |||
public void VIEW_isDeeper_than_no_type() { | |||
for (Type type : Type.values()) { | |||
assertThat(CrawlerDepthLimit.VIEW.isDeeperThan(type)).as("isDeeperThan(%s)", type).isFalse(); | |||
} | |||
} | |||
@Test | |||
public void VIEW_isHigher_than_all_views_types_but_VIEW() { | |||
assertThat(CrawlerDepthLimit.VIEW.isHigherThan(Type.VIEW)).isFalse(); | |||
for (Type viewsType : from(VIEWS_TYPES).filter(not(equalTo(Type.VIEW)))) { | |||
assertThat(CrawlerDepthLimit.VIEW.isHigherThan(viewsType)).as("isHigherThan(%s)", viewsType).isTrue(); | |||
} | |||
} | |||
@Test | |||
public void VIEW_isHigher_than_no_report_types() { | |||
assertIsHigherThanReportType(CrawlerDepthLimit.VIEW); | |||
} | |||
@Test | |||
public void VIEW_isDeeper_than_no_report_types() { | |||
assertIsDeeperThanReportType(CrawlerDepthLimit.VIEW); | |||
} | |||
@Test | |||
public void VIEW_isDeeper_than_no_views_types() { | |||
assertIsDeeperThanViewsType(CrawlerDepthLimit.VIEW); | |||
} | |||
@Test | |||
public void SUBVIEW_isSameAs_only_SUBVIEW_type() { | |||
assertIsSameAs(CrawlerDepthLimit.SUBVIEW, Type.SUBVIEW); | |||
} | |||
@Test | |||
public void SUBVIEW_isHigher_than_no_report_types() { | |||
assertIsHigherThanReportType(CrawlerDepthLimit.SUBVIEW); | |||
} | |||
@Test | |||
public void SUBVIEW_isDeeper_than_no_report_types() { | |||
assertIsDeeperThanReportType(CrawlerDepthLimit.SUBVIEW); | |||
} | |||
@Test | |||
public void SUBVIEW_isDeeper_than_only_VIEW_views_types() { | |||
assertIsDeeperThanReportType(CrawlerDepthLimit.SUBVIEW, Type.VIEW); | |||
} | |||
@Test | |||
public void PROJECT_VIEW_isSameAs_only_PROJECT_VIEW_type() { | |||
assertIsSameAs(CrawlerDepthLimit.PROJECT_VIEW, Type.PROJECT_VIEW); | |||
} | |||
@Test | |||
public void PROJECT_VIEW_isHigher_than_no_report_types() { | |||
assertIsHigherThanReportType(CrawlerDepthLimit.PROJECT_VIEW); | |||
} | |||
@Test | |||
public void PROJECT_VIEW_isDeeper_than_no_report_types() { | |||
assertIsDeeperThanReportType(CrawlerDepthLimit.PROJECT_VIEW); | |||
} | |||
@Test | |||
public void PROJECT_VIEW_isDeeper_than_VIEWS_and_SUBVIEWS_views_types() { | |||
assertIsDeeperThanViewsType(CrawlerDepthLimit.PROJECT_VIEW, Type.VIEW, Type.SUBVIEW); | |||
} | |||
private void assertIsSameAs(CrawlerDepthLimit crawlerDepthLimit, Type expectedType) { | |||
assertThat(crawlerDepthLimit.isSameAs(expectedType)).isTrue(); | |||
for (Type type : from(asList(Type.values())).filter(not(equalTo(expectedType)))) { | |||
assertThat(crawlerDepthLimit.isSameAs(type)).isFalse(); | |||
} | |||
} | |||
private void assertIsHigherThanReportType(CrawlerDepthLimit depthLimit, Type... types) { | |||
for (Type type : types) { | |||
assertThat(depthLimit.isHigherThan(type)).as("isHigherThan(%s)", type).isTrue(); | |||
} | |||
for (Type reportType : from(REPORT_TYPES).filter(not(in(Arrays.asList(types))))) { | |||
assertThat(depthLimit.isHigherThan(reportType)).as("isHigherThan(%s)", reportType).isFalse(); | |||
} | |||
} | |||
private void assertIsHigherThanViewsType(CrawlerDepthLimit depthLimit, Type... types) { | |||
for (Type type : types) { | |||
assertThat(depthLimit.isHigherThan(type)).as("isHigherThan(%s)", type).isTrue(); | |||
} | |||
for (Type reportType : from(VIEWS_TYPES).filter(not(in(Arrays.asList(types))))) { | |||
assertThat(depthLimit.isHigherThan(reportType)).as("isHigherThan(%s)", reportType).isFalse(); | |||
} | |||
} | |||
private void assertIsDeeperThanReportType(CrawlerDepthLimit depthLimit, Type... types) { | |||
for (Type type : types) { | |||
assertThat(depthLimit.isDeeperThan(type)).as("isDeeperThan(%s)", type).isTrue(); | |||
} | |||
for (Type reportType : from(REPORT_TYPES).filter(not(in(Arrays.asList(types))))) { | |||
assertThat(depthLimit.isDeeperThan(reportType)).as("isDeeperThan(%s)", reportType).isFalse(); | |||
} | |||
} | |||
private void assertIsDeeperThanViewsType(CrawlerDepthLimit depthLimit, Type... types) { | |||
for (Type type : types) { | |||
assertThat(depthLimit.isDeeperThan(type)).as("isDeeperThan(%s)", type).isTrue(); | |||
} | |||
for (Type reportType : from(VIEWS_TYPES).filter(not(in(Arrays.asList(types))))) { | |||
assertThat(depthLimit.isDeeperThan(reportType)).as("isDeeperThan(%s)", reportType).isFalse(); | |||
} | |||
} | |||
@Test | |||
@UseDataProvider("viewsTypes") | |||
public void reportMaxDepth_throws_IAE_if_type_is_views(Type viewsType) { | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("A Report max depth must be a report type"); | |||
CrawlerDepthLimit.reportMaxDepth(viewsType); | |||
} | |||
@Test | |||
@UseDataProvider("reportTypes") | |||
public void reportMaxDepth_accepts_type_if_report_type(Type reportType) { | |||
CrawlerDepthLimit.reportMaxDepth(reportType); | |||
} | |||
@Test | |||
@UseDataProvider("reportTypes") | |||
public void withViewsMaxDepth_throws_IAE_if_type_is_report(Type reportType) { | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("A Views max depth must be a views type"); | |||
CrawlerDepthLimit.reportMaxDepth(reportType).withViewsMaxDepth(reportType); | |||
} | |||
@DataProvider | |||
public static Object[][] viewsTypes() { | |||
return from(VIEWS_TYPES).transform(new Function<Type, Object[]>() { | |||
@Nullable | |||
@Override | |||
public Object[] apply(Type input) { | |||
return new Object[]{input}; | |||
} | |||
}).toArray(Object[].class); | |||
} | |||
@DataProvider | |||
public static Object[][] reportTypes() { | |||
return from(REPORT_TYPES).transform(new Function<Type, Object[]>() { | |||
@Nullable | |||
@Override | |||
public Object[] apply(Type input) { | |||
return new Object[]{input}; | |||
} | |||
}).toArray(Object[].class); | |||
} | |||
} |
@@ -67,7 +67,7 @@ public class ReportPathAwareVisitorTest { | |||
@Test | |||
public void verify_preOrder_visit_call_when_visit_tree_with_depth_FILE() { | |||
CallRecorderPathAwareVisitor underTest = new CallRecorderPathAwareVisitor(FILE, PRE_ORDER); | |||
CallRecorderPathAwareVisitor underTest = new CallRecorderPathAwareVisitor(CrawlerDepthLimit.FILE, PRE_ORDER); | |||
new PathAwareCrawler<>(underTest).visit(SOME_TREE_ROOT); | |||
Iterator<PathAwareCallRecord> expected = of( | |||
@@ -99,7 +99,7 @@ public class ReportPathAwareVisitorTest { | |||
@Test | |||
public void verify_preOrder_visit_call_when_visit_tree_with_depth_DIRECTORY() { | |||
CallRecorderPathAwareVisitor underTest = new CallRecorderPathAwareVisitor(DIRECTORY, PRE_ORDER); | |||
CallRecorderPathAwareVisitor underTest = new CallRecorderPathAwareVisitor(CrawlerDepthLimit.DIRECTORY, PRE_ORDER); | |||
new PathAwareCrawler<>(underTest).visit(SOME_TREE_ROOT); | |||
Iterator<PathAwareCallRecord> expected = of( | |||
@@ -123,7 +123,7 @@ public class ReportPathAwareVisitorTest { | |||
@Test | |||
public void verify_preOrder_visit_call_when_visit_tree_with_depth_MODULE() { | |||
CallRecorderPathAwareVisitor underTest = new CallRecorderPathAwareVisitor(MODULE, PRE_ORDER); | |||
CallRecorderPathAwareVisitor underTest = new CallRecorderPathAwareVisitor(CrawlerDepthLimit.MODULE, PRE_ORDER); | |||
new PathAwareCrawler<>(underTest).visit(SOME_TREE_ROOT); | |||
Iterator<PathAwareCallRecord> expected = of( | |||
@@ -141,7 +141,7 @@ public class ReportPathAwareVisitorTest { | |||
@Test | |||
public void verify_preOrder_visit_call_when_visit_tree_with_depth_PROJECT() { | |||
CallRecorderPathAwareVisitor underTest = new CallRecorderPathAwareVisitor(PROJECT, PRE_ORDER); | |||
CallRecorderPathAwareVisitor underTest = new CallRecorderPathAwareVisitor(CrawlerDepthLimit.PROJECT, PRE_ORDER); | |||
new PathAwareCrawler<>(underTest).visit(SOME_TREE_ROOT); | |||
Iterator<PathAwareCallRecord> expected = of( | |||
@@ -153,7 +153,7 @@ public class ReportPathAwareVisitorTest { | |||
@Test | |||
public void verify_postOrder_visit_call_when_visit_tree_with_depth_FILE() { | |||
CallRecorderPathAwareVisitor underTest = new CallRecorderPathAwareVisitor(FILE, POST_ORDER); | |||
CallRecorderPathAwareVisitor underTest = new CallRecorderPathAwareVisitor(CrawlerDepthLimit.FILE, POST_ORDER); | |||
new PathAwareCrawler<>(underTest).visit(SOME_TREE_ROOT); | |||
Iterator<PathAwareCallRecord> expected = of( | |||
@@ -185,7 +185,7 @@ public class ReportPathAwareVisitorTest { | |||
@Test | |||
public void verify_postOrder_visit_call_when_visit_tree_with_depth_DIRECTORY() { | |||
CallRecorderPathAwareVisitor underTest = new CallRecorderPathAwareVisitor(DIRECTORY, POST_ORDER); | |||
CallRecorderPathAwareVisitor underTest = new CallRecorderPathAwareVisitor(CrawlerDepthLimit.DIRECTORY, POST_ORDER); | |||
new PathAwareCrawler<>(underTest).visit(SOME_TREE_ROOT); | |||
Iterator<PathAwareCallRecord> expected = of( | |||
@@ -209,7 +209,7 @@ public class ReportPathAwareVisitorTest { | |||
@Test | |||
public void verify_postOrder_visit_call_when_visit_tree_with_depth_MODULE() { | |||
CallRecorderPathAwareVisitor underTest = new CallRecorderPathAwareVisitor(MODULE, POST_ORDER); | |||
CallRecorderPathAwareVisitor underTest = new CallRecorderPathAwareVisitor(CrawlerDepthLimit.MODULE, POST_ORDER); | |||
new PathAwareCrawler<>(underTest).visit(SOME_TREE_ROOT); | |||
Iterator<PathAwareCallRecord> expected = of( | |||
@@ -227,7 +227,7 @@ public class ReportPathAwareVisitorTest { | |||
@Test | |||
public void verify_postOrder_visit_call_when_visit_tree_with_depth_PROJECT() { | |||
CallRecorderPathAwareVisitor underTest = new CallRecorderPathAwareVisitor(PROJECT, POST_ORDER); | |||
CallRecorderPathAwareVisitor underTest = new CallRecorderPathAwareVisitor(CrawlerDepthLimit.PROJECT, POST_ORDER); | |||
new PathAwareCrawler<>(underTest).visit(SOME_TREE_ROOT); | |||
Iterator<PathAwareCallRecord> expected = of( |
@@ -38,10 +38,10 @@ public class ReportPostOrderDepthTraversalTypeAwareCrawlerTest { | |||
private static final Component MODULE_2 = component(MODULE, 2, MODULE_3); | |||
private static final Component COMPONENT_TREE = component(PROJECT, 1, MODULE_2); | |||
private final CallRecorderTypeAwareVisitor projectVisitor = new CallRecorderTypeAwareVisitor(PROJECT, POST_ORDER); | |||
private final CallRecorderTypeAwareVisitor moduleVisitor = new CallRecorderTypeAwareVisitor(MODULE, POST_ORDER); | |||
private final CallRecorderTypeAwareVisitor directoryVisitor = new CallRecorderTypeAwareVisitor(DIRECTORY, POST_ORDER); | |||
private final CallRecorderTypeAwareVisitor fileVisitor = new CallRecorderTypeAwareVisitor(FILE, POST_ORDER); | |||
private final CallRecorderTypeAwareVisitor projectVisitor = new CallRecorderTypeAwareVisitor(CrawlerDepthLimit.PROJECT, POST_ORDER); | |||
private final CallRecorderTypeAwareVisitor moduleVisitor = new CallRecorderTypeAwareVisitor(CrawlerDepthLimit.MODULE, POST_ORDER); | |||
private final CallRecorderTypeAwareVisitor directoryVisitor = new CallRecorderTypeAwareVisitor(CrawlerDepthLimit.DIRECTORY, POST_ORDER); | |||
private final CallRecorderTypeAwareVisitor fileVisitor = new CallRecorderTypeAwareVisitor(CrawlerDepthLimit.FILE, POST_ORDER); | |||
private final DepthTraversalTypeAwareCrawler projectCrawler = new DepthTraversalTypeAwareCrawler(projectVisitor); | |||
private final DepthTraversalTypeAwareCrawler moduleCrawler = new DepthTraversalTypeAwareCrawler(moduleVisitor); | |||
private final DepthTraversalTypeAwareCrawler directoryCrawler = new DepthTraversalTypeAwareCrawler(directoryVisitor); |
@@ -38,10 +38,10 @@ public class ReportPreOrderDepthTraversalTypeAwareCrawlerTest { | |||
private static final Component MODULE_2 = component(MODULE, 2, MODULE_3); | |||
private static final Component COMPONENT_TREE = component(PROJECT, 1, MODULE_2); | |||
private final CallRecorderTypeAwareVisitor projectVisitor = new CallRecorderTypeAwareVisitor(PROJECT, PRE_ORDER); | |||
private final CallRecorderTypeAwareVisitor moduleVisitor = new CallRecorderTypeAwareVisitor(MODULE, PRE_ORDER); | |||
private final CallRecorderTypeAwareVisitor directoryVisitor = new CallRecorderTypeAwareVisitor(DIRECTORY, PRE_ORDER); | |||
private final CallRecorderTypeAwareVisitor fileVisitor = new CallRecorderTypeAwareVisitor(FILE, PRE_ORDER); | |||
private final CallRecorderTypeAwareVisitor projectVisitor = new CallRecorderTypeAwareVisitor(CrawlerDepthLimit.PROJECT, PRE_ORDER); | |||
private final CallRecorderTypeAwareVisitor moduleVisitor = new CallRecorderTypeAwareVisitor(CrawlerDepthLimit.MODULE, PRE_ORDER); | |||
private final CallRecorderTypeAwareVisitor directoryVisitor = new CallRecorderTypeAwareVisitor(CrawlerDepthLimit.DIRECTORY, PRE_ORDER); | |||
private final CallRecorderTypeAwareVisitor fileVisitor = new CallRecorderTypeAwareVisitor(CrawlerDepthLimit.FILE, PRE_ORDER); | |||
private final DepthTraversalTypeAwareCrawler projectCrawler = new DepthTraversalTypeAwareCrawler(projectVisitor); | |||
private final DepthTraversalTypeAwareCrawler moduleCrawler = new DepthTraversalTypeAwareCrawler(moduleVisitor); |
@@ -48,9 +48,9 @@ public class ReportVisitorsCrawlerTest { | |||
private static final Component MODULE_2 = component(MODULE, 2, MODULE_3); | |||
private static final Component COMPONENT_TREE = component(PROJECT, 1, MODULE_2); | |||
private final TypeAwareVisitor spyPreOrderTypeAwareVisitor = spy(new TestTypeAwareVisitor(FILE, PRE_ORDER)); | |||
private final TypeAwareVisitor spyPostOrderTypeAwareVisitor = spy(new TestTypeAwareVisitor(FILE, POST_ORDER)); | |||
private final TestPathAwareVisitor spyPathAwareVisitor = spy(new TestPathAwareVisitor(FILE, POST_ORDER)); | |||
private final TypeAwareVisitor spyPreOrderTypeAwareVisitor = spy(new TestTypeAwareVisitor(CrawlerDepthLimit.FILE, PRE_ORDER)); | |||
private final TypeAwareVisitor spyPostOrderTypeAwareVisitor = spy(new TestTypeAwareVisitor(CrawlerDepthLimit.FILE, POST_ORDER)); | |||
private final TestPathAwareVisitor spyPathAwareVisitor = spy(new TestPathAwareVisitor(CrawlerDepthLimit.FILE, POST_ORDER)); | |||
@Test | |||
public void execute_each_visitor_on_each_level() throws Exception { | |||
@@ -115,8 +115,8 @@ public class ReportVisitorsCrawlerTest { | |||
} | |||
@Override | |||
public Component.Type getMaxDepth() { | |||
return FILE; | |||
public CrawlerDepthLimit getMaxDepth() { | |||
return CrawlerDepthLimit.FILE; | |||
} | |||
}; | |||
new VisitorsCrawler(Arrays.asList(componentVisitor)); | |||
@@ -128,14 +128,14 @@ public class ReportVisitorsCrawlerTest { | |||
private static class TestTypeAwareVisitor extends TypeAwareVisitorAdapter { | |||
public TestTypeAwareVisitor(Component.Type maxDepth, ComponentVisitor.Order order) { | |||
public TestTypeAwareVisitor(CrawlerDepthLimit maxDepth, ComponentVisitor.Order order) { | |||
super(maxDepth, order); | |||
} | |||
} | |||
private static class TestPathAwareVisitor extends PathAwareVisitorAdapter<Integer> { | |||
public TestPathAwareVisitor(Component.Type maxDepth, ComponentVisitor.Order order) { | |||
public TestPathAwareVisitor(CrawlerDepthLimit maxDepth, ComponentVisitor.Order order) { | |||
super(maxDepth, order, new SimpleStackElementFactory<Integer>() { | |||
@Override | |||
public Integer createForAny(Component component) { |
@@ -69,7 +69,7 @@ public class ReportVisitorsCrawlerWithPathAwareVisitorTest { | |||
@Test | |||
public void verify_preOrder_visit_call_when_visit_tree_with_depth_FILE() { | |||
CallRecorderPathAwareVisitor visitor = new CallRecorderPathAwareVisitor(FILE, PRE_ORDER); | |||
CallRecorderPathAwareVisitor visitor = new CallRecorderPathAwareVisitor(CrawlerDepthLimit.FILE, PRE_ORDER); | |||
VisitorsCrawler underTest = newVisitorsCrawler(visitor); | |||
underTest.visit(SOME_TREE_ROOT); | |||
@@ -102,7 +102,7 @@ public class ReportVisitorsCrawlerWithPathAwareVisitorTest { | |||
@Test | |||
public void verify_preOrder_visit_call_when_visit_tree_with_depth_DIRECTORY() { | |||
CallRecorderPathAwareVisitor visitor = new CallRecorderPathAwareVisitor(DIRECTORY, PRE_ORDER); | |||
CallRecorderPathAwareVisitor visitor = new CallRecorderPathAwareVisitor(CrawlerDepthLimit.DIRECTORY, PRE_ORDER); | |||
VisitorsCrawler underTest = newVisitorsCrawler(visitor); | |||
underTest.visit(SOME_TREE_ROOT); | |||
@@ -127,7 +127,7 @@ public class ReportVisitorsCrawlerWithPathAwareVisitorTest { | |||
@Test | |||
public void verify_preOrder_visit_call_when_visit_tree_with_depth_MODULE() { | |||
CallRecorderPathAwareVisitor visitor = new CallRecorderPathAwareVisitor(MODULE, PRE_ORDER); | |||
CallRecorderPathAwareVisitor visitor = new CallRecorderPathAwareVisitor(CrawlerDepthLimit.MODULE, PRE_ORDER); | |||
VisitorsCrawler underTest = newVisitorsCrawler(visitor); | |||
underTest.visit(SOME_TREE_ROOT); | |||
@@ -146,7 +146,7 @@ public class ReportVisitorsCrawlerWithPathAwareVisitorTest { | |||
@Test | |||
public void verify_preOrder_visit_call_when_visit_tree_with_depth_PROJECT() { | |||
CallRecorderPathAwareVisitor visitor = new CallRecorderPathAwareVisitor(PROJECT, PRE_ORDER); | |||
CallRecorderPathAwareVisitor visitor = new CallRecorderPathAwareVisitor(CrawlerDepthLimit.PROJECT, PRE_ORDER); | |||
VisitorsCrawler underTest = newVisitorsCrawler(visitor); | |||
underTest.visit(SOME_TREE_ROOT); | |||
@@ -159,7 +159,7 @@ public class ReportVisitorsCrawlerWithPathAwareVisitorTest { | |||
@Test | |||
public void verify_postOrder_visit_call_when_visit_tree_with_depth_FILE() { | |||
CallRecorderPathAwareVisitor visitor = new CallRecorderPathAwareVisitor(FILE, POST_ORDER); | |||
CallRecorderPathAwareVisitor visitor = new CallRecorderPathAwareVisitor(CrawlerDepthLimit.FILE, POST_ORDER); | |||
VisitorsCrawler underTest = newVisitorsCrawler(visitor); | |||
underTest.visit(SOME_TREE_ROOT); | |||
@@ -192,7 +192,7 @@ public class ReportVisitorsCrawlerWithPathAwareVisitorTest { | |||
@Test | |||
public void verify_postOrder_visit_call_when_visit_tree_with_depth_DIRECTORY() { | |||
CallRecorderPathAwareVisitor visitor = new CallRecorderPathAwareVisitor(DIRECTORY, POST_ORDER); | |||
CallRecorderPathAwareVisitor visitor = new CallRecorderPathAwareVisitor(CrawlerDepthLimit.DIRECTORY, POST_ORDER); | |||
VisitorsCrawler underTest = newVisitorsCrawler(visitor); | |||
underTest.visit(SOME_TREE_ROOT); | |||
@@ -217,7 +217,7 @@ public class ReportVisitorsCrawlerWithPathAwareVisitorTest { | |||
@Test | |||
public void verify_postOrder_visit_call_when_visit_tree_with_depth_MODULE() { | |||
CallRecorderPathAwareVisitor visitor = new CallRecorderPathAwareVisitor(MODULE, POST_ORDER); | |||
CallRecorderPathAwareVisitor visitor = new CallRecorderPathAwareVisitor(CrawlerDepthLimit.MODULE, POST_ORDER); | |||
VisitorsCrawler underTest = newVisitorsCrawler(visitor); | |||
underTest.visit(SOME_TREE_ROOT); | |||
@@ -236,7 +236,7 @@ public class ReportVisitorsCrawlerWithPathAwareVisitorTest { | |||
@Test | |||
public void verify_postOrder_visit_call_when_visit_tree_with_depth_PROJECT() { | |||
CallRecorderPathAwareVisitor visitor = new CallRecorderPathAwareVisitor(PROJECT, POST_ORDER); | |||
CallRecorderPathAwareVisitor visitor = new CallRecorderPathAwareVisitor(CrawlerDepthLimit.PROJECT, POST_ORDER); | |||
VisitorsCrawler underTest = newVisitorsCrawler(visitor); | |||
underTest.visit(SOME_TREE_ROOT); | |||
@@ -42,13 +42,13 @@ public class ReportVisitorsCrawlerWithPostOrderTypeAwareVisitorTest { | |||
private static final Component MODULE_2 = component(MODULE, 2, MODULE_3); | |||
private static final Component COMPONENT_TREE = component(PROJECT, 1, MODULE_2); | |||
private final TypeAwareVisitor spyProjectVisitor = spy(new TypeAwareVisitorAdapter(PROJECT, POST_ORDER) { | |||
private final TypeAwareVisitor spyProjectVisitor = spy(new TypeAwareVisitorAdapter(CrawlerDepthLimit.PROJECT, POST_ORDER) { | |||
}); | |||
private final TypeAwareVisitor spyModuleVisitor = spy(new TypeAwareVisitorAdapter(MODULE, POST_ORDER) { | |||
private final TypeAwareVisitor spyModuleVisitor = spy(new TypeAwareVisitorAdapter(CrawlerDepthLimit.MODULE, POST_ORDER) { | |||
}); | |||
private final TypeAwareVisitor spyDirectoryVisitor = spy(new TypeAwareVisitorAdapter(DIRECTORY, POST_ORDER) { | |||
private final TypeAwareVisitor spyDirectoryVisitor = spy(new TypeAwareVisitorAdapter(CrawlerDepthLimit.DIRECTORY, POST_ORDER) { | |||
}); | |||
private final TypeAwareVisitor spyFileVisitor = spy(new TypeAwareVisitorAdapter(FILE, POST_ORDER) { | |||
private final TypeAwareVisitor spyFileVisitor = spy(new TypeAwareVisitorAdapter(CrawlerDepthLimit.FILE, POST_ORDER) { | |||
}); | |||
private final InOrder inOrder = inOrder(spyProjectVisitor, spyModuleVisitor, spyDirectoryVisitor, spyFileVisitor); | |||
@@ -42,13 +42,13 @@ public class ReportVisitorsCrawlerWithPreOrderTypeAwareVisitorTest { | |||
private static final Component MODULE_2 = component(MODULE, 2, MODULE_3); | |||
private static final Component COMPONENT_TREE = component(PROJECT, 1, MODULE_2); | |||
private final TypeAwareVisitor spyProjectVisitor = spy(new TypeAwareVisitorAdapter(PROJECT, PRE_ORDER) { | |||
private final TypeAwareVisitor spyProjectVisitor = spy(new TypeAwareVisitorAdapter(CrawlerDepthLimit.PROJECT, PRE_ORDER) { | |||
}); | |||
private final TypeAwareVisitor spyModuleVisitor = spy(new TypeAwareVisitorAdapter(MODULE, PRE_ORDER) { | |||
private final TypeAwareVisitor spyModuleVisitor = spy(new TypeAwareVisitorAdapter(CrawlerDepthLimit.MODULE, PRE_ORDER) { | |||
}); | |||
private final TypeAwareVisitor spyDirectoryVisitor = spy(new TypeAwareVisitorAdapter(DIRECTORY, PRE_ORDER) { | |||
private final TypeAwareVisitor spyDirectoryVisitor = spy(new TypeAwareVisitorAdapter(CrawlerDepthLimit.DIRECTORY, PRE_ORDER) { | |||
}); | |||
private final TypeAwareVisitor spyFileVisitor = spy(new TypeAwareVisitorAdapter(FILE, PRE_ORDER) { | |||
private final TypeAwareVisitor spyFileVisitor = spy(new TypeAwareVisitorAdapter(CrawlerDepthLimit.FILE, PRE_ORDER) { | |||
}); | |||
private final InOrder inOrder = inOrder(spyProjectVisitor, spyModuleVisitor, spyDirectoryVisitor, spyFileVisitor); | |||
@@ -66,7 +66,7 @@ public class ViewsPathAwareVisitorTest { | |||
@Test | |||
public void verify_preOrder_visit_call_when_visit_tree_with_depth_PROJECT_VIEW() { | |||
CallRecorderPathAwareVisitor underTest = new CallRecorderPathAwareVisitor(PROJECT_VIEW, PRE_ORDER); | |||
CallRecorderPathAwareVisitor underTest = new CallRecorderPathAwareVisitor(CrawlerDepthLimit.PROJECT_VIEW, PRE_ORDER); | |||
new PathAwareCrawler<>(underTest).visit(SOME_TREE_ROOT); | |||
Iterator<PathAwareCallRecord> expected = of( | |||
@@ -98,7 +98,7 @@ public class ViewsPathAwareVisitorTest { | |||
@Test | |||
public void verify_preOrder_visit_call_when_visit_tree_with_depth_SUBVIEW() { | |||
CallRecorderPathAwareVisitor underTest = new CallRecorderPathAwareVisitor(SUBVIEW, PRE_ORDER); | |||
CallRecorderPathAwareVisitor underTest = new CallRecorderPathAwareVisitor(CrawlerDepthLimit.SUBVIEW, PRE_ORDER); | |||
new PathAwareCrawler<>(underTest).visit(SOME_TREE_ROOT); | |||
Iterator<PathAwareCallRecord> expected = of( | |||
@@ -122,7 +122,7 @@ public class ViewsPathAwareVisitorTest { | |||
@Test | |||
public void verify_preOrder_visit_call_when_visit_tree_with_depth_VIEW() { | |||
CallRecorderPathAwareVisitor underTest = new CallRecorderPathAwareVisitor(VIEW, PRE_ORDER); | |||
CallRecorderPathAwareVisitor underTest = new CallRecorderPathAwareVisitor(CrawlerDepthLimit.VIEW, PRE_ORDER); | |||
new PathAwareCrawler<>(underTest).visit(SOME_TREE_ROOT); | |||
Iterator<PathAwareCallRecord> expected = of( | |||
@@ -134,7 +134,7 @@ public class ViewsPathAwareVisitorTest { | |||
@Test | |||
public void verify_postOrder_visit_call_when_visit_tree_with_depth_PROJECT_VIEW() { | |||
CallRecorderPathAwareVisitor underTest = new CallRecorderPathAwareVisitor(PROJECT_VIEW, POST_ORDER); | |||
CallRecorderPathAwareVisitor underTest = new CallRecorderPathAwareVisitor(CrawlerDepthLimit.PROJECT_VIEW, POST_ORDER); | |||
new PathAwareCrawler<>(underTest).visit(SOME_TREE_ROOT); | |||
Iterator<PathAwareCallRecord> expected = of( | |||
@@ -166,7 +166,7 @@ public class ViewsPathAwareVisitorTest { | |||
@Test | |||
public void verify_postOrder_visit_call_when_visit_tree_with_depth_SUBVIEW() { | |||
CallRecorderPathAwareVisitor underTest = new CallRecorderPathAwareVisitor(SUBVIEW, POST_ORDER); | |||
CallRecorderPathAwareVisitor underTest = new CallRecorderPathAwareVisitor(CrawlerDepthLimit.SUBVIEW, POST_ORDER); | |||
new PathAwareCrawler<>(underTest).visit(SOME_TREE_ROOT); | |||
Iterator<PathAwareCallRecord> expected = of( | |||
@@ -190,7 +190,7 @@ public class ViewsPathAwareVisitorTest { | |||
@Test | |||
public void verify_postOrder_visit_call_when_visit_tree_with_depth_VIEW() { | |||
CallRecorderPathAwareVisitor underTest = new CallRecorderPathAwareVisitor(VIEW, POST_ORDER); | |||
CallRecorderPathAwareVisitor underTest = new CallRecorderPathAwareVisitor(CrawlerDepthLimit.VIEW, POST_ORDER); | |||
new PathAwareCrawler<>(underTest).visit(SOME_TREE_ROOT); | |||
Iterator<PathAwareCallRecord> expected = of( |
@@ -37,9 +37,9 @@ public class ViewsPostOrderDepthTraversalTypeAwareCrawlerTest { | |||
private static final Component SUBVIEW_2 = component(SUBVIEW, 2, SUBVIEW_3); | |||
private static final Component COMPONENT_TREE = component(VIEW, 1, SUBVIEW_2); | |||
private final CallRecorderTypeAwareVisitor viewVisitor = new CallRecorderTypeAwareVisitor(VIEW, POST_ORDER); | |||
private final CallRecorderTypeAwareVisitor subViewVisitor = new CallRecorderTypeAwareVisitor(SUBVIEW, POST_ORDER); | |||
private final CallRecorderTypeAwareVisitor projectViewVisitor = new CallRecorderTypeAwareVisitor(PROJECT_VIEW, POST_ORDER); | |||
private final CallRecorderTypeAwareVisitor viewVisitor = new CallRecorderTypeAwareVisitor(CrawlerDepthLimit.VIEW, POST_ORDER); | |||
private final CallRecorderTypeAwareVisitor subViewVisitor = new CallRecorderTypeAwareVisitor(CrawlerDepthLimit.SUBVIEW, POST_ORDER); | |||
private final CallRecorderTypeAwareVisitor projectViewVisitor = new CallRecorderTypeAwareVisitor(CrawlerDepthLimit.PROJECT_VIEW, POST_ORDER); | |||
private final DepthTraversalTypeAwareCrawler viewCrawler = new DepthTraversalTypeAwareCrawler(viewVisitor); | |||
private final DepthTraversalTypeAwareCrawler subViewCrawler = new DepthTraversalTypeAwareCrawler(subViewVisitor); |
@@ -37,9 +37,9 @@ public class ViewsPreOrderDepthTraversalTypeAwareCrawlerTest { | |||
private static final Component SUBVIEW_2 = component(SUBVIEW, 2, SUBVIEW_3); | |||
private static final Component COMPONENT_TREE = component(VIEW, 1, SUBVIEW_2); | |||
private final CallRecorderTypeAwareVisitor viewVisitor = new CallRecorderTypeAwareVisitor(VIEW, PRE_ORDER); | |||
private final CallRecorderTypeAwareVisitor subViewVisitor = new CallRecorderTypeAwareVisitor(SUBVIEW, PRE_ORDER); | |||
private final CallRecorderTypeAwareVisitor projectViewVisitor = new CallRecorderTypeAwareVisitor(PROJECT_VIEW, PRE_ORDER); | |||
private final CallRecorderTypeAwareVisitor viewVisitor = new CallRecorderTypeAwareVisitor(CrawlerDepthLimit.VIEW, PRE_ORDER); | |||
private final CallRecorderTypeAwareVisitor subViewVisitor = new CallRecorderTypeAwareVisitor(CrawlerDepthLimit.SUBVIEW, PRE_ORDER); | |||
private final CallRecorderTypeAwareVisitor projectViewVisitor = new CallRecorderTypeAwareVisitor(CrawlerDepthLimit.PROJECT_VIEW, PRE_ORDER); | |||
private final DepthTraversalTypeAwareCrawler viewCrawler = new DepthTraversalTypeAwareCrawler(viewVisitor); | |||
private final DepthTraversalTypeAwareCrawler subViewCrawler = new DepthTraversalTypeAwareCrawler(subViewVisitor); |
@@ -47,9 +47,9 @@ public class ViewsVisitorsCrawlerTest { | |||
private static final Component SUBVIEW_2 = component(SUBVIEW, 2, SUBVIEW_3); | |||
private static final Component COMPONENT_TREE = component(VIEW, 1, SUBVIEW_2); | |||
private final TypeAwareVisitor spyPreOrderTypeAwareVisitor = spy(new TestTypeAwareVisitor(PROJECT_VIEW, PRE_ORDER)); | |||
private final TypeAwareVisitor spyPostOrderTypeAwareVisitor = spy(new TestTypeAwareVisitor(PROJECT_VIEW, POST_ORDER)); | |||
private final TestPathAwareVisitor spyPathAwareVisitor = spy(new TestPathAwareVisitor(PROJECT_VIEW, POST_ORDER)); | |||
private final TypeAwareVisitor spyPreOrderTypeAwareVisitor = spy(new TestTypeAwareVisitor(CrawlerDepthLimit.PROJECT_VIEW, PRE_ORDER)); | |||
private final TypeAwareVisitor spyPostOrderTypeAwareVisitor = spy(new TestTypeAwareVisitor(CrawlerDepthLimit.PROJECT_VIEW, POST_ORDER)); | |||
private final TestPathAwareVisitor spyPathAwareVisitor = spy(new TestPathAwareVisitor(CrawlerDepthLimit.PROJECT_VIEW, POST_ORDER)); | |||
@Test | |||
public void execute_each_visitor_on_each_level() throws Exception { | |||
@@ -114,8 +114,8 @@ public class ViewsVisitorsCrawlerTest { | |||
} | |||
@Override | |||
public Component.Type getMaxDepth() { | |||
return PROJECT_VIEW; | |||
public CrawlerDepthLimit getMaxDepth() { | |||
return CrawlerDepthLimit.PROJECT_VIEW; | |||
} | |||
}; | |||
new VisitorsCrawler(Arrays.asList(componentVisitor)); | |||
@@ -127,14 +127,14 @@ public class ViewsVisitorsCrawlerTest { | |||
private static class TestTypeAwareVisitor extends TypeAwareVisitorAdapter { | |||
public TestTypeAwareVisitor(Component.Type maxDepth, Order order) { | |||
public TestTypeAwareVisitor(CrawlerDepthLimit maxDepth, Order order) { | |||
super(maxDepth, order); | |||
} | |||
} | |||
private static class TestPathAwareVisitor extends PathAwareVisitorAdapter<Integer> { | |||
public TestPathAwareVisitor(Component.Type maxDepth, Order order) { | |||
public TestPathAwareVisitor(CrawlerDepthLimit maxDepth, Order order) { | |||
super(maxDepth, order, new SimpleStackElementFactory<Integer>() { | |||
@Override | |||
public Integer createForAny(Component component) { |
@@ -68,7 +68,7 @@ public class ViewsVisitorsCrawlerWithPathAwareVisitorTest { | |||
@Test | |||
public void verify_preOrder_visit_call_when_visit_tree_with_depth_PROJECT_VIEW() { | |||
CallRecorderPathAwareVisitor visitor = new CallRecorderPathAwareVisitor(PROJECT_VIEW, PRE_ORDER); | |||
CallRecorderPathAwareVisitor visitor = new CallRecorderPathAwareVisitor(CrawlerDepthLimit.PROJECT_VIEW, PRE_ORDER); | |||
VisitorsCrawler underTest = newVisitorsCrawler(visitor); | |||
underTest.visit(SOME_TREE_ROOT); | |||
@@ -101,7 +101,7 @@ public class ViewsVisitorsCrawlerWithPathAwareVisitorTest { | |||
@Test | |||
public void verify_preOrder_visit_call_when_visit_tree_with_depth_SUBVIEW() { | |||
CallRecorderPathAwareVisitor visitor = new CallRecorderPathAwareVisitor(SUBVIEW, PRE_ORDER); | |||
CallRecorderPathAwareVisitor visitor = new CallRecorderPathAwareVisitor(CrawlerDepthLimit.SUBVIEW, PRE_ORDER); | |||
VisitorsCrawler underTest = newVisitorsCrawler(visitor); | |||
underTest.visit(SOME_TREE_ROOT); | |||
@@ -126,7 +126,7 @@ public class ViewsVisitorsCrawlerWithPathAwareVisitorTest { | |||
@Test | |||
public void verify_preOrder_visit_call_when_visit_tree_with_depth_VIEW() { | |||
CallRecorderPathAwareVisitor visitor = new CallRecorderPathAwareVisitor(VIEW, PRE_ORDER); | |||
CallRecorderPathAwareVisitor visitor = new CallRecorderPathAwareVisitor(CrawlerDepthLimit.VIEW, PRE_ORDER); | |||
VisitorsCrawler underTest = newVisitorsCrawler(visitor); | |||
underTest.visit(SOME_TREE_ROOT); | |||
@@ -139,7 +139,7 @@ public class ViewsVisitorsCrawlerWithPathAwareVisitorTest { | |||
@Test | |||
public void verify_postOrder_visit_call_when_visit_tree_with_depth_PROJECT_VIEW() { | |||
CallRecorderPathAwareVisitor visitor = new CallRecorderPathAwareVisitor(PROJECT_VIEW, POST_ORDER); | |||
CallRecorderPathAwareVisitor visitor = new CallRecorderPathAwareVisitor(CrawlerDepthLimit.PROJECT_VIEW, POST_ORDER); | |||
VisitorsCrawler underTest = newVisitorsCrawler(visitor); | |||
underTest.visit(SOME_TREE_ROOT); | |||
@@ -172,7 +172,7 @@ public class ViewsVisitorsCrawlerWithPathAwareVisitorTest { | |||
@Test | |||
public void verify_postOrder_visit_call_when_visit_tree_with_depth_SUBVIEW() { | |||
CallRecorderPathAwareVisitor visitor = new CallRecorderPathAwareVisitor(SUBVIEW, POST_ORDER); | |||
CallRecorderPathAwareVisitor visitor = new CallRecorderPathAwareVisitor(CrawlerDepthLimit.SUBVIEW, POST_ORDER); | |||
VisitorsCrawler underTest = newVisitorsCrawler(visitor); | |||
underTest.visit(SOME_TREE_ROOT); | |||
@@ -197,7 +197,7 @@ public class ViewsVisitorsCrawlerWithPathAwareVisitorTest { | |||
@Test | |||
public void verify_postOrder_visit_call_when_visit_tree_with_depth_VIEW() { | |||
CallRecorderPathAwareVisitor visitor = new CallRecorderPathAwareVisitor(VIEW, POST_ORDER); | |||
CallRecorderPathAwareVisitor visitor = new CallRecorderPathAwareVisitor(CrawlerDepthLimit.VIEW, POST_ORDER); | |||
VisitorsCrawler underTest = newVisitorsCrawler(visitor); | |||
underTest.visit(SOME_TREE_ROOT); | |||
@@ -41,11 +41,11 @@ public class ViewsVisitorsCrawlerWithPostOrderTypeAwareVisitorTest { | |||
private static final Component SUBVIEW_2 = component(SUBVIEW, 2, SUBVIEW_3); | |||
private static final Component COMPONENT_TREE = component(VIEW, 1, SUBVIEW_2); | |||
private final TypeAwareVisitor spyViewVisitor = spy(new TypeAwareVisitorAdapter(VIEW, POST_ORDER) { | |||
private final TypeAwareVisitor spyViewVisitor = spy(new TypeAwareVisitorAdapter(CrawlerDepthLimit.VIEW, POST_ORDER) { | |||
}); | |||
private final TypeAwareVisitor spySubViewVisitor = spy(new TypeAwareVisitorAdapter(SUBVIEW, POST_ORDER) { | |||
private final TypeAwareVisitor spySubViewVisitor = spy(new TypeAwareVisitorAdapter(CrawlerDepthLimit.SUBVIEW, POST_ORDER) { | |||
}); | |||
private final TypeAwareVisitor spyProjectViewVisitor = spy(new TypeAwareVisitorAdapter(PROJECT_VIEW, POST_ORDER) { | |||
private final TypeAwareVisitor spyProjectViewVisitor = spy(new TypeAwareVisitorAdapter(CrawlerDepthLimit.PROJECT_VIEW, POST_ORDER) { | |||
}); | |||
private final InOrder inOrder = inOrder(spyViewVisitor, spySubViewVisitor, spyProjectViewVisitor); | |||
@@ -41,11 +41,11 @@ public class ViewsVisitorsCrawlerWithPreOrderTypeAwareVisitorTest { | |||
private static final Component SUBVIEW_2 = component(SUBVIEW, 2, SUBVIEW_3); | |||
private static final Component COMPONENT_TREE = component(VIEW, 1, SUBVIEW_2); | |||
private final TypeAwareVisitor spyViewVisitor = spy(new TypeAwareVisitorAdapter(VIEW, PRE_ORDER) { | |||
private final TypeAwareVisitor spyViewVisitor = spy(new TypeAwareVisitorAdapter(CrawlerDepthLimit.VIEW, PRE_ORDER) { | |||
}); | |||
private final TypeAwareVisitor spySubViewVisitor = spy(new TypeAwareVisitorAdapter(SUBVIEW, PRE_ORDER) { | |||
private final TypeAwareVisitor spySubViewVisitor = spy(new TypeAwareVisitorAdapter(CrawlerDepthLimit.SUBVIEW, PRE_ORDER) { | |||
}); | |||
private final TypeAwareVisitor spyProjectViewVisitor = spy(new TypeAwareVisitorAdapter(PROJECT_VIEW, PRE_ORDER) { | |||
private final TypeAwareVisitor spyProjectViewVisitor = spy(new TypeAwareVisitorAdapter(CrawlerDepthLimit.PROJECT_VIEW, PRE_ORDER) { | |||
}); | |||
private final InOrder inOrder = inOrder(spyViewVisitor, spySubViewVisitor, spyProjectViewVisitor); | |||
@@ -34,6 +34,7 @@ import org.junit.rules.ExternalResource; | |||
import org.sonar.db.rule.RuleDto; | |||
import org.sonar.server.computation.component.Component; | |||
import org.sonar.server.computation.component.ComponentVisitor; | |||
import org.sonar.server.computation.component.CrawlerDepthLimit; | |||
import org.sonar.server.computation.component.DepthTraversalTypeAwareCrawler; | |||
import org.sonar.server.computation.component.TreeRootHolder; | |||
import org.sonar.server.computation.component.TypeAwareVisitorAdapter; | |||
@@ -389,7 +390,7 @@ public class MeasureRepositoryRule extends ExternalResource implements MeasureRe | |||
public TreeComponentProvider(Component root) { | |||
new DepthTraversalTypeAwareCrawler( | |||
new TypeAwareVisitorAdapter(Component.Type.FILE, ComponentVisitor.Order.PRE_ORDER) { | |||
new TypeAwareVisitorAdapter(CrawlerDepthLimit.FILE, ComponentVisitor.Order.PRE_ORDER) { | |||
@Override | |||
public void visitAny(Component component) { | |||
checkState(!componentsByRef.containsKey(component.getReportAttributes().getRef()), |
@@ -27,6 +27,7 @@ import org.junit.Test; | |||
import org.sonar.server.computation.batch.TreeRootHolderRule; | |||
import org.sonar.server.computation.component.Component; | |||
import org.sonar.server.computation.component.ComponentVisitor; | |||
import org.sonar.server.computation.component.CrawlerDepthLimit; | |||
import org.sonar.server.computation.component.PathAwareVisitorAdapter; | |||
import org.sonar.server.computation.component.TypeAwareVisitorAdapter; | |||
import org.sonar.server.computation.measure.MeasureRepositoryRule; | |||
@@ -125,7 +126,7 @@ public class ExecuteVisitorsStepTest { | |||
private class TestTypeAwareVisitor extends TypeAwareVisitorAdapter { | |||
public TestTypeAwareVisitor() { | |||
super(Component.Type.FILE, ComponentVisitor.Order.POST_ORDER); | |||
super(CrawlerDepthLimit.FILE, ComponentVisitor.Order.POST_ORDER); | |||
} | |||
@Override | |||
@@ -138,7 +139,7 @@ public class ExecuteVisitorsStepTest { | |||
private class TestPathAwareVisitor extends PathAwareVisitorAdapter<Counter> { | |||
public TestPathAwareVisitor() { | |||
super(Component.Type.FILE, ComponentVisitor.Order.POST_ORDER, new SimpleStackElementFactory<Counter>() { | |||
super(CrawlerDepthLimit.FILE, ComponentVisitor.Order.POST_ORDER, new SimpleStackElementFactory<Counter>() { | |||
@Override | |||
public Counter createForAny(Component component) { | |||
return new Counter(); |