public interface Component {
enum Type {
- PROJECT(0), MODULE(1), DIRECTORY(2), FILE(3), VIEW(0), SUBVIEW(1), PROJECT_VIEW(2);
+ PROJECT(0), DIRECTORY(2), FILE(3), VIEW(0), SUBVIEW(1), PROJECT_VIEW(2);
- private static final Set<Type> REPORT_TYPES = EnumSet.of(PROJECT, MODULE, DIRECTORY, FILE);
+ private static final Set<Type> REPORT_TYPES = EnumSet.of(PROJECT, DIRECTORY, FILE);
private static final Set<Type> VIEWS_TYPES = EnumSet.of(VIEW, SUBVIEW, PROJECT_VIEW);
private final int depth;
*/
package org.sonar.ce.task.projectanalysis.component;
-import com.google.common.base.Function;
+import java.util.function.Function;
import javax.annotation.Nonnull;
public final class ComponentFunctions {
// prevents instantiation
}
- public static Function<Component, Integer> toReportRef() {
- return ToReportRef.INSTANCE;
+ public static Function<Component, String> toComponentUuid() {
+ return ToComponentUuid.INSTANCE;
}
- private enum ToReportRef implements Function<Component, Integer> {
+ private enum ToComponentUuid implements Function<Component, String> {
INSTANCE;
@Override
@Nonnull
- public Integer apply(@Nonnull Component input) {
- return input.getReportAttributes().getRef();
+ public String apply(@Nonnull Component input) {
+ return input.getUuid();
}
}
@FunctionalInterface
public interface ComponentKeyGenerator {
- String generateKey(ScannerReport.Component module, @Nullable ScannerReport.Component fileOrDir);
+ String generateKey(ScannerReport.Component project, @Nullable String fileOrDirPath);
}
*/
package org.sonar.ce.task.projectanalysis.component;
+import com.google.common.base.Preconditions;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
+import org.sonar.api.internal.apachecommons.lang.StringUtils;
import org.sonar.ce.task.projectanalysis.analysis.Branch;
import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.component.SnapshotDto;
@Nullable
private final SnapshotDto baseAnalysis;
+ private ScannerReport.Component rootComponent;
+ private String scmBasePath;
+
public ComponentTreeBuilder(
ComponentKeyGenerator keyGenerator,
ComponentKeyGenerator publicKeyGenerator,
}
public Component buildProject(ScannerReport.Component project, String scmBasePath) {
- return buildComponent(project, project, trimToNull(scmBasePath));
+ this.rootComponent = project;
+ this.scmBasePath = trimToNull(scmBasePath);
+
+ Node root = buildFolderHierarchy(project);
+ return buildNode(root, "");
}
- private List<Component> buildChildren(ScannerReport.Component component, ScannerReport.Component parentModule,
- String projectScmPath) {
- return component.getChildRefList()
+ private Node buildFolderHierarchy(ScannerReport.Component rootComponent) {
+ Preconditions.checkArgument(rootComponent.getType() == ScannerReport.Component.ComponentType.PROJECT, "Expected root component of type 'PROJECT'");
+
+ LinkedList<ScannerReport.Component> queue = new LinkedList<>();
+ rootComponent.getChildRefList()
.stream()
- .map(scannerComponentSupplier::apply)
- .map(c -> buildComponent(c, parentModule, projectScmPath))
- .collect(MoreCollectors.toList(component.getChildRefCount()));
+ .map(scannerComponentSupplier)
+ .forEach(queue::addLast);
+
+ Node root = new Node();
+ root.reportComponent = rootComponent;
+
+ while (!queue.isEmpty()) {
+ ScannerReport.Component component = queue.removeFirst();
+ switch (component.getType()) {
+ case FILE:
+ addFileOrDirectory(root, component);
+ break;
+ case MODULE:
+
+ component.getChildRefList().stream()
+ .map(scannerComponentSupplier)
+ .forEach(queue::addLast);
+ break;
+ case DIRECTORY:
+ addFileOrDirectory(root, component);
+ component.getChildRefList().stream()
+ .map(scannerComponentSupplier)
+ .forEach(queue::addLast);
+ break;
+ default:
+ throw new IllegalArgumentException(format("Unsupported component type '%s'", component.getType()));
+ }
+ }
+ return root;
}
- private ComponentImpl buildComponent(ScannerReport.Component component, ScannerReport.Component closestModule,
- @Nullable String scmBasePath) {
- switch (component.getType()) {
- case PROJECT:
- String projectKey = keyGenerator.generateKey(component, null);
- String uuid = uuidSupplier.apply(projectKey);
- String projectPublicKey = publicKeyGenerator.generateKey(component, null);
- ComponentImpl.Builder builder = ComponentImpl.builder(Component.Type.PROJECT)
- .setUuid(uuid)
- .setDbKey(projectKey)
- .setKey(projectPublicKey)
- .setStatus(convertStatus(component.getStatus()))
- .setProjectAttributes(new ProjectAttributes(createProjectVersion(component)))
- .setReportAttributes(createAttributesBuilder(component, scmBasePath).build())
- .addChildren(buildChildren(component, component, scmBasePath));
- setNameAndDescription(component, builder);
- return builder.build();
-
- case MODULE:
- String moduleKey = keyGenerator.generateKey(component, null);
- String modulePublicKey = publicKeyGenerator.generateKey(component, null);
- return ComponentImpl.builder(Component.Type.MODULE)
- .setUuid(uuidSupplier.apply(moduleKey))
- .setDbKey(moduleKey)
- .setKey(modulePublicKey)
- .setName(nameOfOthers(component, modulePublicKey))
- .setStatus(convertStatus(component.getStatus()))
- .setDescription(trimToNull(component.getDescription()))
- .setReportAttributes(createAttributesBuilder(component, scmBasePath).build())
- .addChildren(buildChildren(component, component, scmBasePath))
- .build();
+ private static void addFileOrDirectory(Node root, ScannerReport.Component file) {
+ Preconditions.checkArgument(file.getType() != ScannerReport.Component.ComponentType.FILE || !StringUtils.isEmpty(file.getProjectRelativePath()),
+ "Files should have a relative path: " + file);
+ String[] split = StringUtils.split(file.getProjectRelativePath(), '/');
+ Node currentNode = root.children().computeIfAbsent("", k -> new Node());
- case DIRECTORY:
- case FILE:
- String key = keyGenerator.generateKey(closestModule, component);
- String publicKey = publicKeyGenerator.generateKey(closestModule, component);
- return ComponentImpl.builder(convertDirOrFileType(component.getType()))
- .setUuid(uuidSupplier.apply(key))
- .setDbKey(key)
- .setKey(publicKey)
- .setName(nameOfOthers(component, publicKey))
- .setStatus(convertStatus(component.getStatus()))
- .setDescription(trimToNull(component.getDescription()))
- .setReportAttributes(createAttributesBuilder(component, scmBasePath).build())
- .setFileAttributes(createFileAttributes(component))
- .addChildren(buildChildren(component, closestModule, scmBasePath))
- .build();
+ for (int i = 0; i < split.length; i++) {
+ currentNode = currentNode.children().computeIfAbsent(split[i], k -> new Node());
+ }
+ currentNode.reportComponent = file;
+ }
- default:
- throw new IllegalArgumentException(format("Unsupported component type '%s'", component.getType()));
+ private Component buildNode(Node node, String currentPath) {
+ List<Component> childComponents = buildChildren(node, currentPath);
+ ScannerReport.Component component = node.reportComponent();
+
+ if (component != null) {
+ if (component.getType() == ScannerReport.Component.ComponentType.FILE) {
+ return buildFile(component);
+ } else if (component.getType() == ScannerReport.Component.ComponentType.PROJECT) {
+ return buildProject(childComponents);
+ }
+ }
+
+ return buildDirectory(currentPath, component, childComponents);
+ }
+
+ private List<Component> buildChildren(Node node, String currentPath) {
+ List<Component> children = new ArrayList<>();
+
+ for (Map.Entry<String, Node> e : node.children().entrySet()) {
+ String path = buildPath(currentPath, e.getKey());
+ Node n = e.getValue();
+
+ while (n.children().size() == 1 && n.children().values().iterator().next().children().size() > 0) {
+ Map.Entry<String, Node> childEntry = n.children().entrySet().iterator().next();
+ path = buildPath(path, childEntry.getKey());
+ n = childEntry.getValue();
+ }
+ children.add(buildNode(n, path));
+ }
+ return children;
+ }
+
+ private static String buildPath(String currentPath, String file) {
+ if (currentPath.isEmpty()) {
+ return file;
}
+ return currentPath + "/" + file;
+ }
+
+ private Component buildProject(List<Component> children) {
+ String projectKey = keyGenerator.generateKey(rootComponent, null);
+ String uuid = uuidSupplier.apply(projectKey);
+ String projectPublicKey = publicKeyGenerator.generateKey(rootComponent, null);
+ ComponentImpl.Builder builder = ComponentImpl.builder(Component.Type.PROJECT)
+ .setUuid(uuid)
+ .setDbKey(projectKey)
+ .setKey(projectPublicKey)
+ .setStatus(convertStatus(rootComponent.getStatus()))
+ .setProjectAttributes(new ProjectAttributes(createProjectVersion(rootComponent)))
+ .setReportAttributes(createAttributesBuilder(rootComponent.getRef(), rootComponent.getProjectRelativePath(), scmBasePath,
+ rootComponent.getProjectRelativePath()).build())
+ .addChildren(children);
+ setNameAndDescription(rootComponent, builder);
+ return builder.build();
+ }
+
+ private ComponentImpl buildFile(ScannerReport.Component component) {
+ String key = keyGenerator.generateKey(rootComponent, component.getProjectRelativePath());
+ String publicKey = publicKeyGenerator.generateKey(rootComponent, component.getProjectRelativePath());
+ return ComponentImpl.builder(Component.Type.FILE)
+ .setUuid(uuidSupplier.apply(key))
+ .setDbKey(key)
+ .setKey(publicKey)
+ .setName(nameOfOthers(component, publicKey))
+ .setStatus(convertStatus(component.getStatus()))
+ .setDescription(trimToNull(component.getDescription()))
+ .setReportAttributes(createAttributesBuilder(component.getRef(), component.getProjectRelativePath(), scmBasePath, component.getProjectRelativePath()).build())
+ .setFileAttributes(createFileAttributes(component))
+ .build();
+ }
+
+ private ComponentImpl buildDirectory(String path, @Nullable ScannerReport.Component scannerComponent, List<Component> children) {
+ String nonEmptyPath = path.isEmpty() ? "/" : path;
+ String key = keyGenerator.generateKey(rootComponent, nonEmptyPath);
+ String publicKey = publicKeyGenerator.generateKey(rootComponent, nonEmptyPath);
+ Integer ref = scannerComponent != null ? scannerComponent.getRef() : null;
+ return ComponentImpl.builder(Component.Type.DIRECTORY)
+ .setUuid(uuidSupplier.apply(key))
+ .setDbKey(key)
+ .setKey(publicKey)
+ .setName(publicKey)
+ .setStatus(convertStatus(FileStatus.UNAVAILABLE))
+ .setReportAttributes(createAttributesBuilder(ref, nonEmptyPath, scmBasePath, path).build())
+ .addChildren(children)
+ .build();
}
public Component buildChangedComponentTreeRoot(Component project) {
switch (component.getType()) {
case PROJECT:
return buildChangedProject(component);
-
- case MODULE:
case DIRECTORY:
return buildChangedIntermediate(component);
-
case FILE:
return buildChangedFile(component);
return DEFAULT_PROJECT_VERSION;
}
- private static ReportAttributes.Builder createAttributesBuilder(ScannerReport.Component component, @Nullable String scmBasePath) {
- return ReportAttributes.newBuilder(component.getRef())
- .setPath(trimToNull(component.getPath()))
- .setScmPath(computeScmPath(scmBasePath, component.getProjectRelativePath()));
+ private static ReportAttributes.Builder createAttributesBuilder(@Nullable Integer ref, String path, @Nullable String scmBasePath, String scmRelativePath) {
+ return ReportAttributes.newBuilder(ref)
+ .setPath(trimToNull(path))
+ .setScmPath(computeScmPath(scmBasePath, scmRelativePath));
}
@CheckForNull
if (scmBasePath == null) {
return scmRelativePath;
}
+
return scmBasePath + '/' + scmRelativePath;
}
- @CheckForNull
private static FileAttributes createFileAttributes(ScannerReport.Component component) {
- if (component.getType() != ScannerReport.Component.ComponentType.FILE) {
- return null;
- }
-
- checkArgument(component.getLines() > 0, "File '%s' has no line", component.getPath());
+ checkArgument(component.getType() == ScannerReport.Component.ComponentType.FILE);
+ checkArgument(component.getLines() > 0, "File '%s' has no line", component.getProjectRelativePath());
return new FileAttributes(
component.getIsTest(),
trimToNull(component.getLanguage()),
component.getLines());
}
- private static Component.Type convertDirOrFileType(ScannerReport.Component.ComponentType type) {
- switch (type) {
- case DIRECTORY:
- return Component.Type.DIRECTORY;
- case FILE:
- return Component.Type.FILE;
- default:
- throw new IllegalArgumentException("Unsupported ComponentType value " + type);
+ private static class Node {
+ private final Map<String, Node> children = new LinkedHashMap<>();
+ private ScannerReport.Component reportComponent;
+
+ private Map<String, Node> children() {
+ return children;
+ }
+
+ @CheckForNull
+ private ScannerReport.Component reportComponent() {
+ return reportComponent;
}
}
}
*
* 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.).
+ * Constants are provided for limits specific to a component tree (see {@link #PROJECT}).
*
* Limits for both trees can be created using the {@link #reportMaxDepth(Component.Type)} static method.
*/
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);
*/
package org.sonar.ce.task.projectanalysis.component;
-import static org.sonar.ce.task.projectanalysis.component.ComponentFunctions.toReportRef;
+import static org.sonar.ce.task.projectanalysis.component.ComponentFunctions.toComponentUuid;
/**
* Cache of persisted component (component id and snapshot id) that can be used in the persistence steps
*/
public class DbIdsRepositoryImpl implements MutableDbIdsRepository {
- private final MapBasedDbIdsRepository<Integer> delegate = new MapBasedDbIdsRepository<>(toReportRef());
+ private final MapBasedDbIdsRepository<String> delegate = new MapBasedDbIdsRepository<>(toComponentUuid());
@Override
public DbIdsRepository setComponentId(Component component, long componentId) {
import java.util.Optional;
import javax.annotation.Nullable;
import org.sonar.api.utils.MessageException;
+import org.sonar.ce.task.projectanalysis.analysis.Branch;
import org.sonar.core.component.ComponentKeys;
import org.sonar.db.component.BranchDto;
import org.sonar.db.component.BranchType;
import org.sonar.scanner.protocol.output.ScannerReport;
-import org.sonar.ce.task.projectanalysis.analysis.Branch;
import static java.lang.String.format;
import static org.apache.commons.lang.StringUtils.isEmpty;
}
@Override
- public String generateKey(ScannerReport.Component module, @Nullable ScannerReport.Component fileOrDir) {
- String moduleWithBranch = module.getKey();
+ public String generateKey(ScannerReport.Component project, @Nullable String fileOrDirPath) {
+ String projectWithBranch = project.getKey();
if (isLegacyBranch) {
- moduleWithBranch = ComponentKeys.createKey(module.getKey(), branchName);
+ projectWithBranch = ComponentKeys.createKey(project.getKey(), branchName);
}
- if (fileOrDir == null || isEmpty(fileOrDir.getPath())) {
- return moduleWithBranch;
+ if (isEmpty(fileOrDirPath)) {
+ return projectWithBranch;
}
- return ComponentKeys.createEffectiveKey(moduleWithBranch, trimToNull(fileOrDir.getPath()));
+ return ComponentKeys.createEffectiveKey(projectWithBranch, trimToNull(fileOrDirPath));
}
}
case PROJECT:
this.visitor.visitProject(component);
break;
- case MODULE:
- this.visitor.visitModule(component);
- break;
case DIRECTORY:
this.visitor.visitDirectory(component);
break;
*/
package org.sonar.ce.task.projectanalysis.component;
-import com.google.common.base.Function;
import java.util.HashMap;
import java.util.Map;
+import java.util.function.Function;
import static com.google.common.base.Preconditions.checkState;
case PROJECT:
this.visitor.visitProject(component, stack);
break;
- case MODULE:
- this.visitor.visitModule(component, stack);
- break;
case DIRECTORY:
this.visitor.visitDirectory(component, stack);
break;
switch (component.getType()) {
case PROJECT:
return this.visitor.getFactory().createForProject(component);
- case MODULE:
- return this.visitor.getFactory().createForModule(component);
case DIRECTORY:
return this.visitor.getFactory().createForDirectory(component);
case FILE:
*/
void visitProject(Component project, Path<T> path);
- /**
- * Called when encountering a Component of type {@link Component.Type#MODULE}
- */
- void visitModule(Component module, Path<T> path);
-
/**
* Called when encountering a Component of type {@link Component.Type#DIRECTORY}
*/
interface StackElementFactory<T> {
T createForProject(Component project);
- T createForModule(Component module);
-
T createForDirectory(Component directory);
T createForFile(Component file);
// empty implementation, meant to be override at will by subclasses
}
- @Override
- public void visitModule(Component module, Path<T> path) {
- // empty implementation, meant to be override at will by subclasses
- }
-
@Override
public void visitDirectory(Component directory, Path<T> path) {
// empty implementation, meant to be override at will by subclasses
return createForAny(project);
}
- @Override
- public T createForModule(Component module) {
- return createForAny(module);
- }
-
@Override
public T createForDirectory(Component directory) {
return createForAny(directory);
delegate.visitProject(tree, stack);
}
- @Override
- public void visitModule(Component tree) {
- delegate.visitModule(tree, stack);
- }
-
@Override
public void visitDirectory(Component tree) {
delegate.visitDirectory(tree, stack);
switch (component.getType()) {
case PROJECT:
return delegate.getFactory().createForProject(component);
- case MODULE:
- return delegate.getFactory().createForModule(component);
case DIRECTORY:
return delegate.getFactory().createForDirectory(component);
case FILE:
*/
@Immutable
public class ReportAttributes {
- private final int ref;
+ @CheckForNull
+ private final Integer ref;
@CheckForNull
private final String path;
@CheckForNull
this.scmPath = builder.scmPath;
}
- public static Builder newBuilder(int ref) {
+ public static Builder newBuilder(@Nullable Integer ref) {
return new Builder(ref);
}
public static class Builder {
- private final int ref;
+ @CheckForNull
+ private final Integer ref;
@CheckForNull
private String path;
@CheckForNull
private String scmPath;
- private Builder(int ref) {
+ private Builder(@Nullable Integer ref) {
this.ref = ref;
}
/**
* The component ref in the batch report.
+ * Will be null for directories.
*/
- public int getRef() {
+ @CheckForNull
+ public Integer getRef() {
return ref;
}
/**
- * The path of the report component, must be non null for module, directories and files.
+ * The path of the report component, must be non null for directories and files.
*/
@CheckForNull
public String getPath() {
@CheckForNull
private Map<Integer, Component> extendedComponentsByRef;
+ private int size;
private Component root;
private Component extendedTreeRoot;
public int getSize() {
checkInitialized();
ensureComponentByRefIsPopulated();
- return componentsByRef.size();
+ return size;
}
private void ensureExtendedComponentByRefIsPopulated() {
new TypeAwareVisitorAdapter(CrawlerDepthLimit.FILE, POST_ORDER) {
@Override
public void visitAny(Component component) {
- builder.put(component.getReportAttributes().getRef(), component);
+ if (component.getReportAttributes().getRef() != null) {
+ builder.put(component.getReportAttributes().getRef(), component);
+ }
}
}).visit(this.extendedTreeRoot);
this.extendedComponentsByRef = builder.build();
new TypeAwareVisitorAdapter(CrawlerDepthLimit.FILE, POST_ORDER) {
@Override
public void visitAny(Component component) {
- builder.put(component.getReportAttributes().getRef(), component);
+ size++;
+ if (component.getReportAttributes().getRef() != null) {
+ builder.put(component.getReportAttributes().getRef(), component);
+ }
}
}).visit(this.root);
this.componentsByRef = builder.build();
*/
void visitProject(Component project);
- /**
- * Called when encountering a Component of type {@link Component.Type#MODULE}
- */
- void visitModule(Component module);
-
/**
* Called when encountering a Component of type {@link Component.Type#DIRECTORY}
*/
// empty implementation, meant to be override at will by subclasses
}
- /**
- * Called when encountering a Component of type {@link Component.Type#MODULE}
- */
- @Override
- public void visitModule(Component module) {
- // empty implementation, meant to be override at will by subclasses
- }
-
/**
* Called when encountering a Component of type {@link Component.Type#DIRECTORY}
*/
}
@Override
- public void beforeComponent(Component component){
+ public void beforeComponent(Component component) {
// Nothing to do
}
@Override
- public void afterComponent(Component component){
+ public void afterComponent(Component component) {
// Nothing to do
}
delegate.visitProject(tree);
}
- @Override
- public void visitModule(Component tree) {
- delegate.visitModule(tree);
- }
-
@Override
public void visitDirectory(Component tree) {
delegate.visitDirectory(tree);
public Map<ComponentVisitor, Long> getCumulativeDurations() {
if (computeDuration) {
return ImmutableMap.copyOf(
- Maps.transformValues(this.visitorCumulativeDurations, VisitorDurationToDuration.INSTANCE)
+ Maps.transformValues(this.visitorCumulativeDurations, VisitorDurationToDuration.INSTANCE)
);
}
return Collections.emptyMap();
case PROJECT:
visitor.visitProject(component);
break;
- case MODULE:
- visitor.visitModule(component);
- break;
case DIRECTORY:
visitor.visitDirectory(component);
break;
import static java.util.Objects.requireNonNull;
public class EventRepositoryImpl implements EventRepository {
- private final Multimap<Integer, Event> events = HashMultimap.create();
+ private final Multimap<String, Event> events = HashMultimap.create();
@Override
public void add(Component component, Event event) {
checkArgument(component.getType() == Component.Type.PROJECT, "Component must be of type PROJECT");
- events.put(component.getReportAttributes().getRef(), requireNonNull(event));
+ events.put(component.getUuid(), requireNonNull(event));
}
@Override
public Iterable<Event> getEvents(Component component) {
- return this.events.get(component.getReportAttributes().getRef());
+ return this.events.get(component.getUuid());
}
}
process(project, path);
}
- @Override
- public void visitModule(Component module, Path<FormulaExecutorComponentVisitor.Counters> path) {
- process(module, path);
- }
-
@Override
public void visitDirectory(Component directory, Path<FormulaExecutorComponentVisitor.Counters> path) {
process(directory, path);
import java.util.Map;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.ce.task.projectanalysis.component.Component;
-import org.sonar.core.issue.DefaultIssue;
-import org.sonar.ce.task.projectanalysis.component.Component;
import org.sonar.ce.task.projectanalysis.measure.Measure;
import org.sonar.ce.task.projectanalysis.measure.MeasureRepository;
import org.sonar.ce.task.projectanalysis.metric.Metric;
import org.sonar.ce.task.projectanalysis.metric.MetricRepository;
+import org.sonar.core.issue.DefaultIssue;
import static org.sonar.api.measures.CoreMetrics.RELIABILITY_REMEDIATION_EFFORT_KEY;
import static org.sonar.api.measures.CoreMetrics.SECURITY_REMEDIATION_EFFORT_KEY;
public class EffortAggregator extends IssueVisitor {
private final MeasureRepository measureRepository;
+ private final Map<String, EffortCounter> effortsByComponentUuid = new HashMap<>();
private final Metric maintainabilityEffortMetric;
private final Metric reliabilityEffortMetric;
private final Metric securityEffortMetric;
- private final Map<Integer, EffortCounter> effortsByComponentRef = new HashMap<>();
private EffortCounter effortCounter;
public EffortAggregator(MetricRepository metricRepository, MeasureRepository measureRepository) {
@Override
public void beforeComponent(Component component) {
effortCounter = new EffortCounter();
- effortsByComponentRef.put(component.getReportAttributes().getRef(), effortCounter);
+ effortsByComponentUuid.put(component.getUuid(), effortCounter);
// aggregate children counters
for (Component child : component.getChildren()) {
// no need to keep the children in memory. They can be garbage-collected.
- EffortCounter childEffortCounter = effortsByComponentRef.remove(child.getReportAttributes().getRef());
+ EffortCounter childEffortCounter = effortsByComponentUuid.remove(child.getUuid());
if (childEffortCounter != null) {
effortCounter.add(childEffortCounter);
}
measureRepository.add(component, securityEffortMetric, Measure.newMeasureBuilder().create(effortCounter.securityEffort));
}
- private class EffortCounter {
+ private static class EffortCounter {
private long maintainabilityEffort = 0L;
private long reliabilityEffort = 0L;
private long securityEffort = 0L;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.rules.RuleType;
import org.sonar.ce.task.projectanalysis.component.Component;
-import org.sonar.core.issue.DefaultIssue;
import org.sonar.ce.task.projectanalysis.measure.Measure;
import org.sonar.ce.task.projectanalysis.measure.MeasureRepository;
import org.sonar.ce.task.projectanalysis.metric.Metric;
import org.sonar.ce.task.projectanalysis.metric.MetricRepository;
import org.sonar.ce.task.projectanalysis.period.Period;
import org.sonar.ce.task.projectanalysis.period.PeriodHolder;
+import org.sonar.core.issue.DefaultIssue;
import static org.sonar.api.issue.Issue.RESOLUTION_FALSE_POSITIVE;
import static org.sonar.api.issue.Issue.RESOLUTION_WONT_FIX;
private final PeriodHolder periodHolder;
private final MetricRepository metricRepository;
private final MeasureRepository measureRepository;
+ private final Map<String, Counters> countersByComponentUuid = new HashMap<>();
- private final Map<Integer, Counters> countersByComponentRef = new HashMap<>();
private Counters currentCounters;
public IssueCounter(PeriodHolder periodHolder,
@Override
public void beforeComponent(Component component) {
- // TODO optimization no need to instantiate counter if no open issues
currentCounters = new Counters();
- countersByComponentRef.put(component.getReportAttributes().getRef(), currentCounters);
+ countersByComponentUuid.put(component.getUuid(), currentCounters);
// aggregate children counters
for (Component child : component.getChildren()) {
// no need to keep the children in memory. They can be garbage-collected.
- Counters childCounters = countersByComponentRef.remove(child.getReportAttributes().getRef());
+ Counters childCounters = countersByComponentUuid.remove(child.getUuid());
currentCounters.add(childCounters);
}
}
import org.sonar.ce.task.projectanalysis.component.Component;
import org.sonar.core.issue.DefaultIssue;
-import org.sonar.ce.task.projectanalysis.component.Component;
public abstract class IssueVisitor {
import org.sonar.ce.task.projectanalysis.component.Component;
import org.sonar.core.issue.DefaultIssue;
-import org.sonar.ce.task.projectanalysis.component.Component;
/**
* Saves issues in the ComponentIssuesRepository
* {@link CoreMetrics#NEW_SECURITY_REMEDIATION_EFFORT_KEY}
*/
public class NewEffortAggregator extends IssueVisitor {
-
+ private final Map<String, NewEffortCounter> counterByComponentUuid = new HashMap<>();
private final PeriodHolder periodHolder;
private final MeasureRepository measureRepository;
private final Metric newReliabilityEffortMetric;
private final Metric newSecurityEffortMetric;
- private Map<Integer, NewEffortCounter> counterByComponentRef = new HashMap<>();
private NewEffortCounter counter = null;
public NewEffortAggregator(PeriodHolder periodHolder, MetricRepository metricRepository, MeasureRepository measureRepository) {
@Override
public void beforeComponent(Component component) {
counter = new NewEffortCounter();
- counterByComponentRef.put(component.getReportAttributes().getRef(), counter);
+ counterByComponentUuid.put(component.getUuid(), counter);
for (Component child : component.getChildren()) {
- NewEffortCounter childSum = counterByComponentRef.remove(child.getReportAttributes().getRef());
+ NewEffortCounter childSum = counterByComponentUuid.remove(child.getUuid());
if (childSum != null) {
counter.add(childSum);
}
result.add(init(commonRuleIssue));
}
}
+
+ if (component.getReportAttributes().getRef() == null) {
+ return result;
+ }
+
try (CloseableIterator<ScannerReport.Issue> reportIssues = reportReader.readComponentIssues(component.getReportAttributes().getRef())) {
// optimization - do not load line hashes if there are no issues -> getLineHashSequence() is executed
// as late as possible
*/
package org.sonar.ce.task.projectanalysis.measure;
-import com.google.common.base.Function;
-import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableSetMultimap;
import com.google.common.collect.SetMultimap;
import java.util.Collections;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.sonar.ce.task.projectanalysis.component.Component;
import org.sonar.ce.task.projectanalysis.metric.Metric;
import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.collect.FluentIterable.from;
import static java.lang.String.format;
import static java.util.Objects.requireNonNull;
if (rawMeasures == null) {
return Collections.emptySet();
}
- return from(rawMeasures.entrySet()).filter(new MatchMetric(metric)).transform(ToMeasure.INSTANCE).toSet();
+ return rawMeasures.entrySet().stream()
+ .filter(new MatchMetric(metric))
+ .map(ToMeasure.INSTANCE)
+ .collect(Collectors.toSet());
}
@Override
}
@Override
- public boolean apply(@Nonnull Map.Entry<MeasureKey, Measure> input) {
+ public boolean test(@Nonnull Map.Entry<MeasureKey, Measure> input) {
return input.getKey().getMetricKey().equals(metric.getKey());
}
}
import org.sonar.scanner.protocol.output.ScannerReport;
import static java.util.Objects.requireNonNull;
-import static org.sonar.ce.task.projectanalysis.component.ComponentFunctions.toReportRef;
+import static org.sonar.ce.task.projectanalysis.component.ComponentFunctions.toComponentUuid;
public class MeasureRepositoryImpl implements MeasureRepository {
- private final MapBasedRawMeasureRepository<Integer> delegate = new MapBasedRawMeasureRepository<>(toReportRef());
+ private final MapBasedRawMeasureRepository<String> delegate = new MapBasedRawMeasureRepository<>(toComponentUuid());
private final DbClient dbClient;
private final BatchReportReader reportReader;
private final BatchMeasureToMeasure batchMeasureToMeasure;
private final ReportMetricValidator reportMetricValidator;
private MeasureDtoToMeasure measureTransformer = new MeasureDtoToMeasure();
- private final Set<Integer> loadedComponents = new HashSet<>();
+ private final Set<String> loadedComponents = new HashSet<>();
public MeasureRepositoryImpl(DbClient dbClient, BatchReportReader reportReader, MetricRepository metricRepository,
ReportMetricValidator reportMetricValidator) {
}
private void loadBatchMeasuresForComponent(Component component) {
- if (loadedComponents.contains(component.getReportAttributes().getRef())) {
+ if (component.getReportAttributes().getRef() == null || loadedComponents.contains(component.getUuid())) {
return;
}
}
}
}
- loadedComponents.add(component.getReportAttributes().getRef());
+ loadedComponents.add(component.getUuid());
}
}
computeAndSaveMeasures(directory, path);
}
- @Override
- public void visitModule(Component module, Path<Counter> path) {
- computeAndSaveMeasures(module, path);
- }
-
@Override
public void visitFile(Component file, Path<Counter> path) {
path.current().addDevCosts(computeDevelopmentCost(file));
computeAndSaveNewDebtRatioMeasure(project, path);
}
- @Override
- public void visitModule(Component module, Path<Counter> path) {
- computeAndSaveNewDebtRatioMeasure(module, path);
- increaseNewDebtAndDevCostOfParent(path);
- }
-
@Override
public void visitDirectory(Component directory, Path<Counter> path) {
computeAndSaveNewDebtRatioMeasure(directory, path);
computeAndSaveMeasures(directory, path);
}
- @Override
- public void visitModule(Component module, Path<Counter> path) {
- computeAndSaveMeasures(module, path);
- }
-
@Override
public void visitFile(Component file, Path<Counter> path) {
computeAndSaveMeasures(file, path);
import org.sonar.api.measures.CoreMetrics;
import org.sonar.ce.task.projectanalysis.component.Component;
import org.sonar.ce.task.projectanalysis.component.PathAwareVisitorAdapter;
-import org.sonar.ce.task.projectanalysis.issue.ComponentIssuesRepository;
-import org.sonar.ce.task.projectanalysis.metric.Metric;
-import org.sonar.ce.task.projectanalysis.metric.MetricRepository;
-import org.sonar.ce.task.projectanalysis.component.Component;
-import org.sonar.ce.task.projectanalysis.component.PathAwareVisitorAdapter;
import org.sonar.ce.task.projectanalysis.formula.counter.RatingValue;
import org.sonar.ce.task.projectanalysis.issue.ComponentIssuesRepository;
import org.sonar.ce.task.projectanalysis.measure.MeasureRepository;
import static org.sonar.api.measures.CoreMetrics.SECURITY_RATING_KEY;
import static org.sonar.api.rules.RuleType.BUG;
import static org.sonar.api.rules.RuleType.VULNERABILITY;
-import static org.sonar.ce.task.projectanalysis.component.ComponentVisitor.Order.POST_ORDER;
import static org.sonar.ce.task.projectanalysis.component.CrawlerDepthLimit.FILE;
import static org.sonar.ce.task.projectanalysis.measure.Measure.newMeasureBuilder;
import static org.sonar.server.measure.Rating.RATING_BY_SEVERITY;
computeAndSaveMeasures(project, path);
}
- @Override
- public void visitModule(Component module, Path<Counter> path) {
- computeAndSaveMeasures(module, path);
- }
-
@Override
public void visitDirectory(Component directory, Path<Counter> path) {
computeAndSaveMeasures(directory, path);
saveAndAggregate(directory, path);
}
- @Override
- public void visitModule(Component module, Path<LastCommit> path) {
- saveAndAggregate(module, path);
- }
-
@Override
public void visitFile(Component file, Path<LastCommit> path) {
// load SCM blame information from report. It can be absent when the file was not touched
// since previous analysis (optimization to decrease execution of blame commands). In this case
// the date is loaded from database, as it did not change from previous analysis.
- java.util.Optional<ScmInfo> scmInfoOptional = scmInfoRepository.getScmInfo(file);
+ Optional<ScmInfo> scmInfoOptional = scmInfoRepository.getScmInfo(file);
if (scmInfoOptional.isPresent()) {
ScmInfo scmInfo = scmInfoOptional.get();
path.current().addDate(scmInfo.getLatestChangeset().getDate());
addMeasure(project, path.current());
}
- @Override
- public void visitModule(Component module, Path<QProfiles> path) {
- QProfiles qProfiles = path.current();
- addMeasure(module, path.current());
- path.parent().add(qProfiles);
- }
-
private void addMeasure(Component component, QProfiles qProfiles) {
if (!qProfiles.profilesByKey.isEmpty()) {
measureRepository.add(component, qProfilesMetric, qProfiles.createMeasure());
@Override
public void execute(ComputationStep.Context context) {
try (DbSession session = dbClient.openSession(false)) {
- CrawlerDepthLimit depthLimit = new CrawlerDepthLimit.Builder(Component.Type.MODULE)
+ CrawlerDepthLimit depthLimit = new CrawlerDepthLimit.Builder(Component.Type.PROJECT)
.withViewsMaxDepth(Component.Type.PROJECT_VIEW);
new DepthTraversalTypeAwareCrawler(
new TypeAwareVisitorAdapter(depthLimit, ComponentVisitor.Order.PRE_ORDER) {
path.current().setDto(persistAndPopulateCache(project, dto));
}
- @Override
- public void visitModule(Component module, Path<ComponentDtoHolder> path) {
- ComponentDto dto = createForModule(module, path);
- path.current().setDto(persistAndPopulateCache(module, dto));
- }
-
@Override
public void visitDirectory(Component directory, Path<ComponentDtoHolder> path) {
ComponentDto dto = createForDirectory(directory, path);
return res;
}
- public ComponentDto createForModule(Component module, PathAwareVisitor.Path<ComponentDtoHolder> path) {
- ComponentDto res = createBase(module);
-
- res.setScope(Scopes.PROJECT);
- res.setQualifier(Qualifiers.MODULE);
- res.setName(module.getName());
- res.setLongName(res.name());
- res.setPath(module.getReportAttributes().getPath());
- res.setDescription(module.getDescription());
-
- setRootAndParentModule(res, path);
-
- return res;
- }
-
public ComponentDto createForDirectory(Component directory, PathAwareVisitor.Path<ComponentDtoHolder> path) {
ComponentDto res = createBase(directory);
@Override
public boolean apply(@Nonnull PathAwareVisitor.PathElement<ComponentDtoHolder> input) {
- return input.getComponent().getType() == Component.Type.MODULE
- || input.getComponent().getType() == Component.Type.PROJECT;
+ return input.getComponent().getType() == Component.Type.PROJECT;
}
}
persistMeasures(project);
}
- @Override
- public void visitModule(Component module) {
- persistMeasures(module);
- }
-
@Override
public void visitDirectory(Component directory) {
if (persistDirectories) {
createMeasures(project, path.current());
}
- @Override
- public void visitModule(Component module, Path<Counter> path) {
- createMeasures(module, path.current());
- path.parent().aggregate(path.current());
- }
-
@Override
public void visitDirectory(Component directory, Path<Counter> path) {
int fileCount = path.current().files;
import java.util.Optional;
import org.sonar.api.utils.MessageException;
import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolder;
-import org.sonar.ce.task.projectanalysis.batch.BatchReportReader;
import org.sonar.ce.task.projectanalysis.component.Component;
import org.sonar.ce.task.projectanalysis.component.ComponentVisitor;
import org.sonar.ce.task.projectanalysis.component.CrawlerDepthLimit;
import org.sonar.ce.task.projectanalysis.component.TreeRootHolder;
import org.sonar.ce.task.projectanalysis.component.TypeAwareVisitorAdapter;
import org.sonar.ce.task.step.ComputationStep;
-import org.sonar.core.component.ComponentKeys;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.ComponentDao;
private static final Joiner MESSAGES_JOINER = Joiner.on("\n o ");
private final DbClient dbClient;
- private final BatchReportReader reportReader;
private final TreeRootHolder treeRootHolder;
private final AnalysisMetadataHolder analysisMetadataHolder;
- public ValidateProjectStep(DbClient dbClient, BatchReportReader reportReader, TreeRootHolder treeRootHolder,
- AnalysisMetadataHolder analysisMetadataHolder) {
+ public ValidateProjectStep(DbClient dbClient, TreeRootHolder treeRootHolder, AnalysisMetadataHolder analysisMetadataHolder) {
this.dbClient = dbClient;
- this.reportReader = reportReader;
this.treeRootHolder = treeRootHolder;
this.analysisMetadataHolder = analysisMetadataHolder;
}
private final Map<String, ComponentDto> baseModulesByKey;
private final List<String> validationMessages = new ArrayList<>();
- private Component rawProject;
-
public ValidateProjectsVisitor(DbSession session, ComponentDao componentDao, Map<String, ComponentDto> baseModulesByKey) {
- super(CrawlerDepthLimit.MODULE, ComponentVisitor.Order.PRE_ORDER);
+ super(CrawlerDepthLimit.PROJECT, ComponentVisitor.Order.PRE_ORDER);
this.session = session;
this.componentDao = componentDao;
@Override
public void visitProject(Component rawProject) {
- this.rawProject = rawProject;
String rawProjectKey = rawProject.getDbKey();
Optional<ComponentDto> baseProject = loadBaseComponent(rawProjectKey);
Long lastAnalysisDate = snapshotDto.map(SnapshotDto::getCreatedAt).orElse(null);
if (lastAnalysisDate != null && currentAnalysisDate <= lastAnalysisDate) {
validationMessages.add(format("Date of analysis cannot be older than the date of the last known analysis on this project. Value: \"%s\". " +
- "Latest analysis: \"%s\". It's only possible to rebuild the past in a chronological order.",
+ "Latest analysis: \"%s\". It's only possible to rebuild the past in a chronological order.",
formatDateTime(new Date(currentAnalysisDate)), formatDateTime(new Date(lastAnalysisDate))));
}
}
}
- @Override
- public void visitModule(Component rawModule) {
- String rawProjectKey = rawProject.getDbKey();
- String rawModuleKey = rawModule.getDbKey();
- validateBatchKey(rawModule);
-
- Optional<ComponentDto> baseModule = loadBaseComponent(rawModuleKey);
- if (!baseModule.isPresent()) {
- return;
- }
- validateModuleIsNotAlreadyUsedAsProject(baseModule.get(), rawProjectKey, rawModuleKey);
- validateModuleKeyIsNotAlreadyUsedInAnotherProject(baseModule.get(), rawModuleKey);
- }
-
- private void validateModuleIsNotAlreadyUsedAsProject(ComponentDto baseModule, String rawProjectKey, String rawModuleKey) {
- if (baseModule.projectUuid().equals(baseModule.uuid())) {
- // module is actually a project
- validationMessages.add(format("The project \"%s\" is already defined in SonarQube but not as a module of project \"%s\". "
- + "If you really want to stop directly analysing project \"%s\", please first delete it from SonarQube and then relaunch the analysis of project \"%s\".",
- rawModuleKey, rawProjectKey, rawModuleKey, rawProjectKey));
- }
- }
-
- private void validateModuleKeyIsNotAlreadyUsedInAnotherProject(ComponentDto baseModule, String rawModuleKey) {
- if (!baseModule.projectUuid().equals(baseModule.uuid()) && !baseModule.projectUuid().equals(rawProject.getUuid())) {
- ComponentDto projectModule = componentDao.selectOrFailByUuid(session, baseModule.projectUuid());
- validationMessages.add(format("Module \"%s\" is already part of project \"%s\"", rawModuleKey, projectModule.getDbKey()));
- }
- }
-
- private void validateBatchKey(Component rawComponent) {
- String batchKey = reportReader.readComponent(rawComponent.getReportAttributes().getRef()).getKey();
- if (!ComponentKeys.isValidModuleKey(batchKey)) {
- validationMessages.add(format("\"%s\" is not a valid project or module key. "
- + "Allowed characters are alphanumeric, '-', '_', '.' and ':', with at least one non-digit.", batchKey));
- }
- }
-
private Optional<ComponentDto> loadBaseComponent(String rawComponentKey) {
ComponentDto baseComponent = baseModulesByKey.get(rawComponentKey);
if (baseComponent == null) {
}
@Override
- public String generateKey(ScannerReport.Component module, @Nullable ScannerReport.Component fileOrDir) {
+ public String generateKey(ScannerReport.Component project, @Nullable String fileOrDirPath) {
throw new UnsupportedOperationException();
}
});
callsRecords.add(reportCallRecord(project, path, "visitProject"));
}
- @Override
- public void visitModule(Component module, Path<Integer> path) {
- callsRecords.add(reportCallRecord(module, path, "visitModule"));
- }
-
@Override
public void visitDirectory(Component directory, Path<Integer> path) {
callsRecords.add(reportCallRecord(directory, path, "visitDirectory"));
callsRecords.add(reportCallRecord(project, "visitProject"));
}
- @Override
- public void visitModule(Component module) {
- callsRecords.add(reportCallRecord(module, "visitModule"));
- }
-
@Override
public void visitDirectory(Component directory) {
callsRecords.add(reportCallRecord(directory, "visitDirectory"));
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT;
-import static org.sonar.ce.task.projectanalysis.component.Component.Type.VIEW;
-import static org.sonar.ce.task.projectanalysis.component.ComponentFunctions.toReportRef;
+import static org.sonar.ce.task.projectanalysis.component.ComponentFunctions.toComponentUuid;
public class ComponentFunctionsTest {
private static final int SOME_INT = new Random().nextInt();
- @Test(expected = IllegalStateException.class)
- public void toReportRef_throws_ISE_if_Component_has_no_ReportAttributes() {
- toReportRef().apply(ViewsComponent.builder(VIEW, 1).build());
- }
-
@Test
- public void toReportRef_returns_the_ref_of_the_Component() {
- assertThat(toReportRef().apply(ReportComponent.builder(PROJECT, SOME_INT).build())).isEqualTo(SOME_INT);
+ public void toComponentUuid_returns_the_ref_of_the_Component() {
+ assertThat(toComponentUuid().apply(ReportComponent.builder(PROJECT, SOME_INT).setUuid("uuid_" + SOME_INT).build())).isEqualTo("uuid_" + SOME_INT);
}
}
*/
package org.sonar.ce.task.projectanalysis.component;
-import com.google.common.collect.ImmutableList;
+import java.util.Arrays;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.DIRECTORY;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.FILE;
-import static org.sonar.ce.task.projectanalysis.component.Component.Type.MODULE;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT_VIEW;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.SUBVIEW;
@Test
public void FILE_type_is_deeper_than_all_other_types() {
assertThat(Component.Type.FILE.isDeeperThan(DIRECTORY)).isTrue();
- assertThat(Component.Type.FILE.isDeeperThan(MODULE)).isTrue();
assertThat(Component.Type.FILE.isDeeperThan(PROJECT)).isTrue();
}
@Test
- public void DIRECTORY_type_is_deeper_than_MODULE_and_PROJECT() {
- assertThat(Component.Type.DIRECTORY.isDeeperThan(MODULE)).isTrue();
+ public void DIRECTORY_type_is_deeper_than_PROJECT() {
assertThat(Component.Type.DIRECTORY.isDeeperThan(PROJECT)).isTrue();
}
- @Test
- public void MODULE_type_is_deeper_than_PROJECT() {
- assertThat(Component.Type.MODULE.isDeeperThan(PROJECT)).isTrue();
- }
-
@Test
public void FILE_type_is_higher_than_no_other_types() {
assertThat(Component.Type.FILE.isHigherThan(DIRECTORY)).isFalse();
- assertThat(Component.Type.FILE.isHigherThan(MODULE)).isFalse();
assertThat(Component.Type.FILE.isHigherThan(PROJECT)).isFalse();
}
assertThat(Component.Type.DIRECTORY.isHigherThan(FILE)).isTrue();
}
- @Test
- public void MODULE_type_is_higher_than_FILE_AND_DIRECTORY() {
- assertThat(Component.Type.MODULE.isHigherThan(FILE)).isTrue();
- assertThat(Component.Type.MODULE.isHigherThan(DIRECTORY)).isTrue();
- }
-
@Test
public void PROJECT_type_is_higher_than_all_other_types() {
assertThat(Component.Type.PROJECT.isHigherThan(FILE)).isTrue();
assertThat(Component.Type.PROJECT.isHigherThan(DIRECTORY)).isTrue();
- assertThat(Component.Type.PROJECT.isHigherThan(MODULE)).isTrue();
}
@Test
public void any_type_is_not_higher_than_itself() {
assertThat(Component.Type.FILE.isHigherThan(FILE)).isFalse();
assertThat(Component.Type.DIRECTORY.isHigherThan(DIRECTORY)).isFalse();
- assertThat(Component.Type.MODULE.isHigherThan(MODULE)).isFalse();
assertThat(Component.Type.PROJECT.isHigherThan(PROJECT)).isFalse();
}
@Test
public void PROJECT_MODULE_DIRECTORY_and_FILE_are_report_types_and_not_views_types() {
- for (Component.Type type : ImmutableList.of(PROJECT, MODULE, DIRECTORY, FILE)) {
+ for (Component.Type type : Arrays.asList(PROJECT, DIRECTORY, FILE)) {
assertThat(type.isReportType()).isTrue();
assertThat(type.isViewsType()).isFalse();
}
@Test
public void VIEW_SUBVIEW_and_PROJECT_VIEW_are_views_types_and_not_report_types() {
- for (Component.Type type : ImmutableList.of(VIEW, SUBVIEW, PROJECT_VIEW)) {
+ for (Component.Type type : Arrays.asList(VIEW, SUBVIEW, PROJECT_VIEW)) {
assertThat(type.isViewsType()).isTrue();
assertThat(type.isReportType()).isFalse();
}
import java.util.Arrays;
import java.util.EnumSet;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.ExternalResource;
-import org.mockito.Mockito;
import org.sonar.ce.task.projectanalysis.analysis.Branch;
+import org.sonar.ce.task.projectanalysis.issue.IssueRelocationToRoot;
import org.sonar.core.component.ComponentKeys;
import org.sonar.db.component.SnapshotDto;
import org.sonar.scanner.protocol.output.ScannerReport;
import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.sonar.ce.task.projectanalysis.component.ComponentVisitor.Order.PRE_ORDER;
import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
import static org.sonar.db.organization.OrganizationTesting.newOrganizationDto;
-import static org.sonar.scanner.protocol.output.ScannerReport.Component.newBuilder;
import static org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType.DIRECTORY;
import static org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType.FILE;
import static org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType.MODULE;
import static org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType.PROJECT;
import static org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType.UNRECOGNIZED;
+import static org.sonar.scanner.protocol.output.ScannerReport.Component.newBuilder;
public class ComponentTreeBuilderTest {
- private static final ComponentKeyGenerator KEY_GENERATOR = (module, component) -> "generated_"
- + ComponentKeys.createEffectiveKey(module.getKey(), component != null ? component.getPath() : null);
- private static final ComponentKeyGenerator PUBLIC_KEY_GENERATOR = (module, component) -> "public_"
- + ComponentKeys.createEffectiveKey(module.getKey(), component != null ? component.getPath() : null);
+ private static final ComponentKeyGenerator KEY_GENERATOR = (project, path) -> "generated_"
+ + ComponentKeys.createEffectiveKey(project.getKey(), path);
+ private static final ComponentKeyGenerator PUBLIC_KEY_GENERATOR = (project, path) -> "public_"
+ + ComponentKeys.createEffectiveKey(project.getKey(), path);
private static final Function<String, String> UUID_SUPPLIER = (componentKey) -> componentKey + "_uuid";
private static final EnumSet<ScannerReport.Component.ComponentType> REPORT_TYPES = EnumSet.of(PROJECT, MODULE, DIRECTORY, FILE);
private static final String NO_SCM_BASE_PATH = "";
private Project projectInDb = Project.from(newPrivateProjectDto(newOrganizationDto(), UUID_SUPPLIER.apply("K1")).setDbKey("K1").setDescription(null));
@Test
- public void build_throws_IAE_for_all_types_but_PROJECT_MODULE_DIRECTORY_FILE() {
+ public void build_throws_IAE_for_all_types_except_PROJECT_MODULE_DIRECTORY_FILE() {
+ Arrays.stream(ScannerReport.Component.ComponentType.values())
+ .filter((type) -> type != UNRECOGNIZED)
+ .filter((type) -> !REPORT_TYPES.contains(type))
+ .forEach(
+ (type) -> {
+ ScannerReport.Component project = newBuilder()
+ .setType(PROJECT)
+ .setKey(projectInDb.getKey())
+ .setRef(1)
+ .addChildRef(2)
+ .setProjectRelativePath("root")
+ .build();
+ scannerComponentProvider.add(newBuilder()
+ .setRef(2)
+ .setType(type)
+ .setProjectRelativePath("src")
+ .setLines(1));
+ try {
+ call(project);
+ fail("Should have thrown a IllegalArgumentException");
+ } catch (IllegalArgumentException e) {
+ assertThat(e).hasMessage("Unsupported component type '" + type + "'");
+ }
+ });
+ }
+
+ @Test
+ public void build_throws_IAE_if_root_is_not_PROJECT() {
Arrays.stream(ScannerReport.Component.ComponentType.values())
.filter((type) -> type != UNRECOGNIZED)
.filter((type) -> !REPORT_TYPES.contains(type))
call(component);
fail("Should have thrown a IllegalArgumentException");
} catch (IllegalArgumentException e) {
- assertThat(e).hasMessage("Unsupported component type '" + type + "'");
+ assertThat(e).hasMessage("Expected root component of type 'PROJECT'");
}
});
}
@Test
public void any_component_with_projectRelativePath_has_this_value_as_scmPath_if_scmBasePath_is_empty() {
- String[] projectRelativePaths = {
- randomAlphabetic(4),
- randomAlphabetic(5),
- randomAlphabetic(6),
- randomAlphabetic(7)
- };
ScannerReport.Component project = newBuilder()
.setType(PROJECT)
.setKey(projectInDb.getKey())
.setRef(1)
.addChildRef(2)
- .setProjectRelativePath(projectRelativePaths[0])
+ .setProjectRelativePath("root")
.build();
scannerComponentProvider.add(newBuilder()
.setRef(2)
- .setType(MODULE)
- .setKey("M")
- .setProjectRelativePath(projectRelativePaths[1])
- .addChildRef(3));
- scannerComponentProvider.add(newBuilder()
- .setRef(3)
- .setType(DIRECTORY)
- .setPath("src/js")
- .setProjectRelativePath(projectRelativePaths[2])
- .addChildRef(4));
- scannerComponentProvider.add(newBuilder()
- .setRef(4)
.setType(FILE)
- .setPath("src/js/Foo.js")
- .setProjectRelativePath(projectRelativePaths[3])
+ .setProjectRelativePath("src/js/Foo.js")
.setLines(1));
Component root = call(project, NO_SCM_BASE_PATH);
assertThat(root.getReportAttributes().getScmPath())
- .contains(projectRelativePaths[0]);
- Component module = root.getChildren().iterator().next();
- assertThat(module.getReportAttributes().getScmPath())
- .contains(projectRelativePaths[1]);
- Component directory = module.getChildren().iterator().next();
+ .contains("root");
+ Component directory = root.getChildren().iterator().next();
assertThat(directory.getReportAttributes().getScmPath())
- .contains(projectRelativePaths[2]);
+ .contains("src/js");
Component file = directory.getChildren().iterator().next();
assertThat(file.getReportAttributes().getScmPath())
- .contains(projectRelativePaths[3]);
+ .contains("src/js/Foo.js");
}
@Test
public void any_component_with_projectRelativePath_has_this_value_appended_to_scmBasePath_and_a_slash_as_scmPath_if_scmBasePath_is_not_empty() {
- String[] projectRelativePaths = {
- randomAlphabetic(4),
- randomAlphabetic(5),
- randomAlphabetic(6),
- randomAlphabetic(7)
- };
+ ScannerReport.Component project = createProject();
+ String scmBasePath = randomAlphabetic(10);
+
+ Component root = call(project, scmBasePath);
+ assertThat(root.getReportAttributes().getScmPath())
+ .contains(scmBasePath);
+ Component directory = root.getChildren().iterator().next();
+ assertThat(directory.getReportAttributes().getScmPath())
+ .contains(scmBasePath + "/src/js");
+ Component file = directory.getChildren().iterator().next();
+ assertThat(file.getReportAttributes().getScmPath())
+ .contains(scmBasePath + "/src/js/Foo.js");
+ }
+
+ private ScannerReport.Component createProject() {
+ ScannerReport.Component project = newBuilder()
+ .setType(PROJECT)
+ .setKey(projectInDb.getKey())
+ .setRef(1)
+ .addChildRef(2)
+ .build();
+ scannerComponentProvider.add(newBuilder()
+ .setRef(2)
+ .setType(FILE)
+ .setProjectRelativePath("src/js/Foo.js")
+ .setLines(1));
+ return project;
+ }
+
+ @Test
+ public void keys_of_directory_and_file_are_generated() {
+ ScannerReport.Component project = createProject();
+
+ Component root = call(project);
+ assertThat(root.getDbKey()).isEqualTo("generated_" + projectInDb.getKey());
+ assertThat(root.getKey()).isEqualTo("public_" + projectInDb.getKey());
+ assertThat(root.getChildren()).hasSize(1);
+
+ Component directory = root.getChildren().iterator().next();
+ assertThat(directory.getDbKey()).isEqualTo("generated_" + projectInDb.getKey() + ":src/js");
+ assertThat(directory.getKey()).isEqualTo("public_" + projectInDb.getKey() + ":src/js");
+ assertThat(directory.getChildren()).hasSize(1);
+
+ Component file = directory.getChildren().iterator().next();
+ assertThat(file.getDbKey()).isEqualTo("generated_" + projectInDb.getKey() + ":src/js/Foo.js");
+ assertThat(file.getKey()).isEqualTo("public_" + projectInDb.getKey() + ":src/js/Foo.js");
+ assertThat(file.getChildren()).isEmpty();
+ }
+
+ @Test
+ public void modules_are_not_created() {
ScannerReport.Component project = newBuilder()
.setType(PROJECT)
.setKey(projectInDb.getKey())
.setRef(1)
.addChildRef(2)
- .setProjectRelativePath(projectRelativePaths[0])
.build();
scannerComponentProvider.add(newBuilder()
.setRef(2)
.setType(MODULE)
.setKey("M")
- .setProjectRelativePath(projectRelativePaths[1])
.addChildRef(3));
scannerComponentProvider.add(newBuilder()
.setRef(3)
.setType(DIRECTORY)
- .setPath("src/js")
- .setProjectRelativePath(projectRelativePaths[2])
+ .setProjectRelativePath("src/js")
.addChildRef(4));
scannerComponentProvider.add(newBuilder()
.setRef(4)
.setType(FILE)
- .setPath("src/js/Foo.js")
- .setProjectRelativePath(projectRelativePaths[3])
+ .setProjectRelativePath("src/js/Foo.js")
.setLines(1));
- String scmBasePath = randomAlphabetic(10);
- Component root = call(project, scmBasePath);
+ Component root = call(project);
- assertThat(root.getReportAttributes().getScmPath())
- .contains(scmBasePath + "/" + projectRelativePaths[0]);
- Component module = root.getChildren().iterator().next();
- assertThat(module.getReportAttributes().getScmPath())
- .contains(scmBasePath + "/" + projectRelativePaths[1]);
- Component directory = module.getChildren().iterator().next();
- assertThat(directory.getReportAttributes().getScmPath())
- .contains(scmBasePath + "/" + projectRelativePaths[2]);
- Component file = directory.getChildren().iterator().next();
- assertThat(file.getReportAttributes().getScmPath())
- .contains(scmBasePath + "/" + projectRelativePaths[3]);
+ List<Component> components = root.getChildren();
+ assertThat(components).extracting("type").containsOnly(Component.Type.DIRECTORY);
}
@Test
- public void keys_of_module_directory_and_file_are_generated() {
+ public void folder_hierarchy_is_created() {
ScannerReport.Component project = newBuilder()
.setType(PROJECT)
.setKey(projectInDb.getKey())
.setRef(1)
.addChildRef(2)
+ .addChildRef(3)
.build();
scannerComponentProvider.add(newBuilder()
.setRef(2)
- .setType(MODULE)
- .setKey("M")
- .addChildRef(3));
+ .setType(DIRECTORY)
+ .setProjectRelativePath("src/main/xoo")
+ .addChildRef(4));
scannerComponentProvider.add(newBuilder()
.setRef(3)
.setType(DIRECTORY)
- .setPath("src/js")
- .addChildRef(4));
+ .setProjectRelativePath("src/test/xoo/org/sonar")
+ .addChildRef(5));
scannerComponentProvider.add(newBuilder()
.setRef(4)
.setType(FILE)
- .setPath("src/js/Foo.js")
+ .setProjectRelativePath("src/main/xoo/Foo1.js")
+ .setLines(1));
+ scannerComponentProvider.add(newBuilder()
+ .setRef(5)
+ .setType(FILE)
+ .setProjectRelativePath("src/test/xoo/org/sonar/Foo2.js")
.setLines(1));
Component root = call(project);
- assertThat(root.getDbKey()).isEqualTo("generated_" + projectInDb.getKey());
- assertThat(root.getKey()).isEqualTo("public_" + projectInDb.getKey());
- assertThat(root.getChildren()).hasSize(1);
- Component module = root.getChildren().iterator().next();
- assertThat(module.getDbKey()).isEqualTo("generated_M");
- assertThat(module.getKey()).isEqualTo("public_M");
- assertThat(module.getChildren()).hasSize(1);
+ Component directory = root.getChildren().iterator().next();
+ assertThat(directory.getName()).isEqualTo("public_K1:src");
- Component directory = module.getChildren().iterator().next();
- assertThat(directory.getDbKey()).isEqualTo("generated_M:src/js");
- assertThat(directory.getKey()).isEqualTo("public_M:src/js");
- assertThat(directory.getChildren()).hasSize(1);
+ // folders are collapsed and they only contain one directory
+ Component d1 = directory.getChildren().get(0);
+ assertThat(d1.getName()).isEqualTo("public_K1:src/main/xoo");
- Component file = directory.getChildren().iterator().next();
- assertThat(file.getDbKey()).isEqualTo("generated_M:src/js/Foo.js");
- assertThat(file.getKey()).isEqualTo("public_M:src/js/Foo.js");
- assertThat(file.getChildren()).isEmpty();
+ Component d2 = directory.getChildren().get(1);
+ assertThat(d2.getName()).isEqualTo("public_K1:src/test/xoo/org/sonar");
}
@Test
- public void names_of_module_directory_and_file_are_public_keys_if_names_are_absent_from_report() {
+ public void directories_are_collapsed() {
ScannerReport.Component project = newBuilder()
.setType(PROJECT)
.setKey(projectInDb.getKey())
.build();
scannerComponentProvider.add(newBuilder()
.setRef(2)
- .setType(MODULE)
- .setKey("M")
+ .setType(DIRECTORY)
+ .setPath("/")
.addChildRef(3));
scannerComponentProvider.add(newBuilder()
.setRef(3)
- .setType(DIRECTORY)
- .setPath("src/js")
- .addChildRef(4));
- scannerComponentProvider.add(newBuilder()
- .setRef(4)
.setType(FILE)
- .setPath("src/js/Foo.js")
+ .setProjectRelativePath("src/js/Foo.js")
.setLines(1));
Component root = call(project);
- Component module = root.getChildren().iterator().next();
- assertThat(module.getName()).isEqualTo("public_M");
-
- Component directory = module.getChildren().iterator().next();
- assertThat(directory.getName()).isEqualTo("public_M:src/js");
+ Component directory = root.getChildren().iterator().next();
+ assertThat(directory.getName()).isEqualTo("public_K1:src/js");
Component file = directory.getChildren().iterator().next();
- assertThat(file.getName()).isEqualTo("public_M:src/js/Foo.js");
+ assertThat(file.getName()).isEqualTo("public_K1:src/js/Foo.js");
}
@Test
- public void names_of_module_directory_and_file_are_public_keys_if_names_are_empty_in_report() {
+ public void names_of_directory_and_file_are_public_keys_if_names_are_empty_in_report() {
ScannerReport.Component project = newBuilder()
.setType(PROJECT)
.setKey(projectInDb.getKey())
.build();
scannerComponentProvider.add(newBuilder()
.setRef(2)
- .setType(MODULE)
- .setKey("M")
+ .setType(DIRECTORY)
+ .setProjectRelativePath("src/js")
.setName("")
.addChildRef(3));
scannerComponentProvider.add(newBuilder()
.setRef(3)
- .setType(DIRECTORY)
- .setPath("src/js")
+ .setType(FILE)
+ .setProjectRelativePath("src/js/Foo.js")
.setName("")
- .addChildRef(4));
+ .setLines(1));
+
+ Component root = call(project);
+
+ Component directory = root.getChildren().iterator().next();
+ assertThat(directory.getName()).isEqualTo("public_K1:src/js");
+
+ Component file = directory.getChildren().iterator().next();
+ assertThat(file.getName()).isEqualTo("public_K1:src/js/Foo.js");
+ }
+
+ @Test
+ public void create_full_hierarchy_of_directories() {
+ ScannerReport.Component project = newBuilder()
+ .setType(PROJECT)
+ .setKey(projectInDb.getKey())
+ .setRef(1)
+ .addChildRef(2)
+ .addChildRef(3)
+ .build();
scannerComponentProvider.add(newBuilder()
- .setRef(4)
+ .setRef(2)
+ .setType(FILE)
+ .setProjectRelativePath("src/java/Bar.java")
+ .setName("")
+ .setLines(2));
+ scannerComponentProvider.add(newBuilder()
+ .setRef(3)
.setType(FILE)
- .setPath("src/js/Foo.js")
+ .setProjectRelativePath("src/js/Foo.js")
.setName("")
.setLines(1));
Component root = call(project);
- Component module = root.getChildren().iterator().next();
- assertThat(module.getName()).isEqualTo("public_M");
+ Component directory = root.getChildren().iterator().next();
+ assertThat(directory.getName()).isEqualTo("public_K1:src");
- Component directory = module.getChildren().iterator().next();
- assertThat(directory.getName()).isEqualTo("public_M:src/js");
+ Component directoryJava = directory.getChildren().get(0);
+ assertThat(directoryJava.getName()).isEqualTo("public_K1:src/java");
- Component file = directory.getChildren().iterator().next();
- assertThat(file.getName()).isEqualTo("public_M:src/js/Foo.js");
+ Component directoryJs = directory.getChildren().get(1);
+ assertThat(directoryJs.getName()).isEqualTo("public_K1:src/js");
+
+ Component file = directoryJs.getChildren().iterator().next();
+ assertThat(file.getName()).isEqualTo("public_K1:src/js/Foo.js");
}
private void assertThatFileAttributesAreNotSet(Component root) {
}
@Test
- public void keys_of_module_directory_and_files_includes_name_of_closest_module() {
+ public void keys_of_directory_and_files_includes_always_root_project() {
ScannerReport.Component project = newBuilder()
.setType(PROJECT)
.setKey("project 1")
scannerComponentProvider.add(newBuilder().setRef(11).setType(MODULE).setKey("module 1").addChildRef(12).addChildRef(22).addChildRef(32));
scannerComponentProvider.add(newBuilder().setRef(12).setType(MODULE).setKey("module 2").addChildRef(13).addChildRef(23).addChildRef(33));
scannerComponentProvider.add(newBuilder().setRef(13).setType(MODULE).setKey("module 3").addChildRef(24).addChildRef(34));
- scannerComponentProvider.add(newBuilder().setRef(21).setType(DIRECTORY).setPath("directory in project").addChildRef(35));
- scannerComponentProvider.add(newBuilder().setRef(22).setType(DIRECTORY).setPath("directory in module 1").addChildRef(36));
- scannerComponentProvider.add(newBuilder().setRef(23).setType(DIRECTORY).setPath("directory in module 2").addChildRef(37));
- scannerComponentProvider.add(newBuilder().setRef(24).setType(DIRECTORY).setPath("directory in module 3").addChildRef(38));
- scannerComponentProvider.add(newBuilder().setRef(31).setType(FILE).setPath("file in project").setLines(1));
- scannerComponentProvider.add(newBuilder().setRef(32).setType(FILE).setPath("file in module 1").setLines(1));
- scannerComponentProvider.add(newBuilder().setRef(33).setType(FILE).setPath("file in module 2").setLines(1));
- scannerComponentProvider.add(newBuilder().setRef(34).setType(FILE).setPath("file in module 3").setLines(1));
- scannerComponentProvider.add(newBuilder().setRef(35).setType(FILE).setPath("file in directory in project").setLines(1));
- scannerComponentProvider.add(newBuilder().setRef(36).setType(FILE).setPath("file in directory in module 1").setLines(1));
- scannerComponentProvider.add(newBuilder().setRef(37).setType(FILE).setPath("file in directory in module 2").setLines(1));
- scannerComponentProvider.add(newBuilder().setRef(38).setType(FILE).setPath("file in directory in module 3").setLines(1));
+ scannerComponentProvider.add(newBuilder().setRef(21).setType(DIRECTORY).setProjectRelativePath("directory in project").addChildRef(35));
+ scannerComponentProvider.add(newBuilder().setRef(22).setType(DIRECTORY).setProjectRelativePath("directory in module 1").addChildRef(36));
+ scannerComponentProvider.add(newBuilder().setRef(23).setType(DIRECTORY).setProjectRelativePath("directory in module 2").addChildRef(37));
+ scannerComponentProvider.add(newBuilder().setRef(24).setType(DIRECTORY).setProjectRelativePath("directory in module 3").addChildRef(38));
+ scannerComponentProvider.add(newBuilder().setRef(31).setType(FILE).setProjectRelativePath("file in project").setLines(1));
+ scannerComponentProvider.add(newBuilder().setRef(32).setType(FILE).setProjectRelativePath("file in module 1").setLines(1));
+ scannerComponentProvider.add(newBuilder().setRef(33).setType(FILE).setProjectRelativePath("file in module 2").setLines(1));
+ scannerComponentProvider.add(newBuilder().setRef(34).setType(FILE).setProjectRelativePath("file in module 3").setLines(1));
+ scannerComponentProvider.add(newBuilder().setRef(35).setType(FILE).setProjectRelativePath("file in directory in project").setLines(1));
+ scannerComponentProvider.add(newBuilder().setRef(36).setType(FILE).setProjectRelativePath("file in directory in module 1").setLines(1));
+ scannerComponentProvider.add(newBuilder().setRef(37).setType(FILE).setProjectRelativePath("file in directory in module 2").setLines(1));
+ scannerComponentProvider.add(newBuilder().setRef(38).setType(FILE).setProjectRelativePath("file in directory in module 3").setLines(1));
Component root = call(project);
- Map<Integer, Component> componentsByRef = indexComponentByRef(root);
- assertThat(componentsByRef.get(11).getDbKey()).isEqualTo("generated_module 1");
- assertThat(componentsByRef.get(11).getKey()).isEqualTo("public_module 1");
- assertThat(componentsByRef.get(12).getDbKey()).isEqualTo("generated_module 2");
- assertThat(componentsByRef.get(12).getKey()).isEqualTo("public_module 2");
- assertThat(componentsByRef.get(13).getDbKey()).isEqualTo("generated_module 3");
- assertThat(componentsByRef.get(13).getKey()).isEqualTo("public_module 3");
- assertThat(componentsByRef.get(21).getDbKey()).startsWith("generated_project 1:");
- assertThat(componentsByRef.get(21).getKey()).startsWith("public_project 1:");
- assertThat(componentsByRef.get(22).getDbKey()).startsWith("generated_module 1:");
- assertThat(componentsByRef.get(22).getKey()).startsWith("public_module 1:");
- assertThat(componentsByRef.get(23).getDbKey()).startsWith("generated_module 2:");
- assertThat(componentsByRef.get(23).getKey()).startsWith("public_module 2:");
- assertThat(componentsByRef.get(24).getDbKey()).startsWith("generated_module 3:");
- assertThat(componentsByRef.get(24).getKey()).startsWith("public_module 3:");
- assertThat(componentsByRef.get(31).getDbKey()).startsWith("generated_project 1:");
- assertThat(componentsByRef.get(31).getKey()).startsWith("public_project 1:");
- assertThat(componentsByRef.get(32).getDbKey()).startsWith("generated_module 1:");
- assertThat(componentsByRef.get(32).getKey()).startsWith("public_module 1:");
- assertThat(componentsByRef.get(33).getDbKey()).startsWith("generated_module 2:");
- assertThat(componentsByRef.get(33).getKey()).startsWith("public_module 2:");
- assertThat(componentsByRef.get(34).getDbKey()).startsWith("generated_module 3:");
- assertThat(componentsByRef.get(34).getKey()).startsWith("public_module 3:");
- assertThat(componentsByRef.get(35).getDbKey()).startsWith("generated_project 1:");
- assertThat(componentsByRef.get(35).getKey()).startsWith("public_project 1:");
- assertThat(componentsByRef.get(36).getDbKey()).startsWith("generated_module 1:");
- assertThat(componentsByRef.get(36).getKey()).startsWith("public_module 1:");
- assertThat(componentsByRef.get(37).getDbKey()).startsWith("generated_module 2:");
- assertThat(componentsByRef.get(37).getKey()).startsWith("public_module 2:");
- assertThat(componentsByRef.get(38).getDbKey()).startsWith("generated_module 3:");
- assertThat(componentsByRef.get(38).getKey()).startsWith("public_module 3:");
+ Map<String, Component> componentsByKey = indexComponentByKey(root);
+
+ assertThat(componentsByKey.values()).extracting("key").startsWith("public_project 1");
+ assertThat(componentsByKey.values()).extracting("dbKey").startsWith("generated_project 1");
}
@Test
scannerComponentProvider.add(newBuilder()
.setRef(3)
.setType(DIRECTORY)
- .setPath("src/js")
+ .setProjectRelativePath("src/js")
.addChildRef(4));
scannerComponentProvider.add(newBuilder()
.setRef(4)
.setType(FILE)
- .setPath("src/js/Foo.js")
+ .setProjectRelativePath("src/js/Foo.js")
.setLines(1));
Component root = call(project);
assertThat(root.getUuid()).isEqualTo("generated_c1_uuid");
- Component module = root.getChildren().iterator().next();
- assertThat(module.getUuid()).isEqualTo("generated_c2_uuid");
-
- Component directory = module.getChildren().iterator().next();
- assertThat(directory.getUuid()).isEqualTo("generated_c2:src/js_uuid");
+ Component directory = root.getChildren().iterator().next();
+ assertThat(directory.getUuid()).isEqualTo("generated_c1:src/js_uuid");
Component file = directory.getChildren().iterator().next();
- assertThat(file.getUuid()).isEqualTo("generated_c2:src/js/Foo.js_uuid");
+ assertThat(file.getUuid()).isEqualTo("generated_c1:src/js/Foo.js_uuid");
}
@Test
scannerComponentProvider.add(newBuilder()
.setRef(3)
.setType(DIRECTORY)
- .setPath("src/js")
+ .setProjectRelativePath("src/js")
.addChildRef(4));
scannerComponentProvider.add(newBuilder()
.setRef(4)
.setType(FILE)
- .setPath("src/js/Foo.js")
+ .setProjectRelativePath("src/js/Foo.js")
.setLines(1));
Component root = call(project);
- Component module = root.getChildren().iterator().next();
- assertThat(module.getDescription()).isNull();
-
- Component directory = module.getChildren().iterator().next();
+ Component directory = root.getChildren().iterator().next();
assertThat(directory.getDescription()).isNull();
Component file = directory.getChildren().iterator().next();
.setRef(3)
.setType(DIRECTORY)
.setDescription("")
- .setPath("src/js")
+ .setProjectRelativePath("src/js")
.addChildRef(4));
scannerComponentProvider.add(newBuilder()
.setRef(4)
.setType(FILE)
.setDescription("")
- .setPath("src/js/Foo.js")
+ .setProjectRelativePath("src/js/Foo.js")
.setLines(1));
Component root = call(project);
- Component module = root.getChildren().iterator().next();
- assertThat(module.getDescription()).isNull();
-
- Component directory = module.getChildren().iterator().next();
+ Component directory = root.getChildren().iterator().next();
assertThat(directory.getDescription()).isNull();
Component file = directory.getChildren().iterator().next();
.build();
scannerComponentProvider.add(newBuilder()
.setRef(2)
- .setType(MODULE)
- .setDescription("b")
- .addChildRef(3));
- scannerComponentProvider.add(newBuilder()
- .setRef(3)
.setType(DIRECTORY)
.setDescription("c")
- .setPath("src/js")
- .addChildRef(4));
+ .setProjectRelativePath("src/js")
+ .addChildRef(3));
scannerComponentProvider.add(newBuilder()
- .setRef(4)
+ .setRef(3)
.setType(FILE)
.setDescription("d")
- .setPath("src/js/Foo.js")
+ .setProjectRelativePath("src/js/Foo.js")
.setLines(1));
Component root = call(project);
-
- Component module = root.getChildren().iterator().next();
- assertThat(module.getDescription()).isEqualTo("b");
-
- Component directory = module.getChildren().iterator().next();
- assertThat(directory.getDescription()).isEqualTo("c");
+ Component directory = root.getChildren().iterator().next();
+ assertThat(directory.getDescription()).isNull();
Component file = directory.getChildren().iterator().next();
assertThat(file.getDescription()).isEqualTo("d");
scannerComponentProvider.add(newBuilder()
.setRef(2)
.setType(FILE)
- .setPath("src/js/Foo.js")
+ .setProjectRelativePath("src/js/Foo.js")
.setLines(1));
Component root = call(project);
- Component file = root.getChildren().iterator().next();
+ Component dir = root.getChildren().iterator().next();
+ Component file = dir.getChildren().iterator().next();
assertThat(file.getFileAttributes().getLines()).isEqualTo(1);
assertThat(file.getFileAttributes().getLanguageKey()).isNull();
assertThat(file.getFileAttributes().isUnitTest()).isFalse();
scannerComponentProvider.add(newBuilder()
.setRef(2)
.setType(FILE)
- .setPath("src/js/Foo.js")
+ .setProjectRelativePath("src/js/Foo.js")
.setLines(1)
.setLanguage(""));
Component root = call(project);
- Component file = root.getChildren().iterator().next();
+ Component dir2 = root.getChildren().iterator().next();
+
+ Component file = dir2.getChildren().iterator().next();
assertThat(file.getFileAttributes().getLanguageKey()).isNull();
}
scannerComponentProvider.add(newBuilder()
.setRef(2)
.setType(FILE)
- .setPath("src/js/Foo.js")
+ .setProjectRelativePath("src/js/Foo.js")
.setLines(1)
.setLanguage("js")
.setIsTest(true));
Component root = call(project);
- Component file = root.getChildren().iterator().next();
+ Component dir = root.getChildren().iterator().next();
+ Component file = dir.getChildren().iterator().next();
assertThat(file.getFileAttributes().getLines()).isEqualTo(1);
assertThat(file.getFileAttributes().getLanguageKey()).isEqualTo("js");
assertThat(file.getFileAttributes().isUnitTest()).isTrue();
scannerComponentProvider.add(newBuilder()
.setRef(2)
.setType(FILE)
- .setPath("src/js/Foo.js"));
+ .setProjectRelativePath("src/js/Foo.js"));
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("File 'src/js/Foo.js' has no line");
scannerComponentProvider.add(newBuilder()
.setRef(2)
.setType(FILE)
- .setPath("src/js/Foo.js")
+ .setProjectRelativePath("src/js/Foo.js")
.setLines(0));
expectedException.expect(IllegalArgumentException.class);
scannerComponentProvider.add(newBuilder()
.setRef(2)
.setType(FILE)
- .setPath("src/js/Foo.js")
+ .setProjectRelativePath("src/js/Foo.js")
.setLines(-10));
expectedException.expect(IllegalArgumentException.class);
}
private ComponentTreeBuilder newUnderTest(@Nullable SnapshotDto baseAnalysis, boolean mainBranch) {
- Branch branch = Mockito.mock(Branch.class);
+ Branch branch = mock(Branch.class);
when(branch.isMain()).thenReturn(mainBranch);
- return new ComponentTreeBuilder(KEY_GENERATOR, PUBLIC_KEY_GENERATOR, UUID_SUPPLIER, scannerComponentProvider, projectInDb, branch, baseAnalysis);
+ return new ComponentTreeBuilder(KEY_GENERATOR, PUBLIC_KEY_GENERATOR, UUID_SUPPLIER, scannerComponentProvider, projectInDb, branch, baseAnalysis,
+ mock(IssueRelocationToRoot.class));
}
private static Map<Integer, Component> indexComponentByRef(Component root) {
}).visit(root);
return componentsByRef;
}
+
+ private static Map<String, Component> indexComponentByKey(Component root) {
+ Map<String, Component> componentsByKey = new HashMap<>();
+ new DepthTraversalTypeAwareCrawler(
+ new TypeAwareVisitorAdapter(CrawlerDepthLimit.FILE, PRE_ORDER) {
+ @Override
+ public void visitAny(Component any) {
+ componentsByKey.put(any.getDbKey(), any);
+ }
+ }).visit(root);
+ return componentsByKey;
+ }
}
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_only_PROJECT_and_MODULE_report_types() {
- assertIsDeeperThanReportType(CrawlerDepthLimit.DIRECTORY, Type.PROJECT, Type.MODULE);
+ public void DIRECTORY_isDeeper_than_only_PROJECT_report_type() {
+ assertIsDeeperThanReportType(CrawlerDepthLimit.DIRECTORY, Type.PROJECT);
}
@Test
@Test
public void FILE_isDeeper_than_only_PROJECT_MODULE_and_DIRECTORY_report_types() {
- assertIsDeeperThanReportType(CrawlerDepthLimit.FILE, Type.PROJECT, Type.MODULE, Type.DIRECTORY);
+ assertIsDeeperThanReportType(CrawlerDepthLimit.FILE, Type.PROJECT, Type.DIRECTORY);
}
@Test
@Test
public void LEAVES_isDeeper_than_PROJECT_MODULE_and_DIRECTORY_report_types() {
- assertIsDeeperThanReportType(CrawlerDepthLimit.LEAVES, Type.PROJECT, Type.MODULE, Type.DIRECTORY);
+ assertIsDeeperThanReportType(CrawlerDepthLimit.LEAVES, Type.PROJECT, Type.DIRECTORY);
}
@Test
public class DefaultBranchImplTest {
private static final ScannerReport.Component PROJECT = ScannerReport.Component.newBuilder().setType(ComponentType.PROJECT).setKey("P").build();
- private static final ScannerReport.Component MODULE = ScannerReport.Component.newBuilder().setType(ComponentType.MODULE).setKey("M").build();
- private static final ScannerReport.Component FILE = ScannerReport.Component.newBuilder().setType(ComponentType.FILE).setPath("src/Foo.js").build();
+ private static final ScannerReport.Component FILE = ScannerReport.Component.newBuilder().setType(ComponentType.FILE).setProjectRelativePath("src/Foo.js").build();
@Rule
public ExpectedException expectedException = ExpectedException.none();
assertThat(branch.supportsCrossProjectCpd()).isTrue();
assertThat(branch.generateKey(PROJECT, null)).isEqualTo("P");
- assertThat(branch.generateKey(MODULE, null)).isEqualTo("M");
- assertThat(branch.generateKey(MODULE, FILE)).isEqualTo("M:src/Foo.js");
+ assertThat(branch.generateKey(PROJECT, FILE.getProjectRelativePath())).isEqualTo("P:src/Foo.js");
}
@Test
assertThat(branch.supportsCrossProjectCpd()).isFalse();
assertThat(branch.generateKey(PROJECT, null)).isEqualTo("P:bar");
- assertThat(branch.generateKey(MODULE, null)).isEqualTo("M:bar");
- assertThat(branch.generateKey(MODULE, FILE)).isEqualTo("M:bar:src/Foo.js");
+ assertThat(branch.generateKey(PROJECT, FILE.getProjectRelativePath())).isEqualTo("P:bar:src/Foo.js");
}
private void assertThatNameIsCorrect(@Nullable String name) {
*/
package org.sonar.ce.task.projectanalysis.component;
-import com.google.common.base.Function;
+import java.util.function.Function;
import javax.annotation.Nullable;
import org.junit.rules.ExternalResource;
@Nullable
@Override
public String apply(Component input) {
- return input.getType().isReportType() ? String.valueOf(input.getReportAttributes().getRef()) : input.getDbKey();
+ return input.getType().isReportType() ? input.getUuid() : input.getDbKey();
}
});
}
return false;
}
ReportComponent that = (ReportComponent) o;
- return reportAttributes.getRef() == that.reportAttributes.getRef();
+ return uuid.equals(that.uuid);
}
@Override
public int hashCode() {
- return this.reportAttributes.getRef();
+ return uuid.hashCode();
}
@Override
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.DIRECTORY;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.FILE;
-import static org.sonar.ce.task.projectanalysis.component.Component.Type.MODULE;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT;
import static org.sonar.ce.task.projectanalysis.component.ComponentVisitor.Order.POST_ORDER;
import static org.sonar.ce.task.projectanalysis.component.ComponentVisitor.Order.PRE_ORDER;
public class ReportPathAwareVisitorTest {
private static final int ROOT_REF = 1;
- private static final ReportComponent SOME_TREE_ROOT = ReportComponent.builder(PROJECT, ROOT_REF)
- .addChildren(
- ReportComponent.builder(MODULE, 11)
- .addChildren(
- ReportComponent.builder(DIRECTORY, 111)
- .addChildren(
- ReportComponent.builder(FILE, 1111).build(),
- ReportComponent.builder(FILE, 1112).build())
- .build(),
- ReportComponent.builder(DIRECTORY, 112)
- .addChildren(
- ReportComponent.builder(FILE, 1121).build())
- .build())
- .build(),
- ReportComponent.builder(MODULE, 12)
- .addChildren(
- ReportComponent.builder(MODULE, 121)
- .addChildren(
- ReportComponent.builder(DIRECTORY, 1211)
- .addChildren(
- ReportComponent.builder(FILE, 12111).build())
- .build())
- .build())
+ private static final ReportComponent SOME_TREE_ROOT = ReportComponent.builder(PROJECT, ROOT_REF).addChildren(
+ ReportComponent.builder(DIRECTORY, 11).addChildren(
+ ReportComponent.builder(FILE, 111).build(),
+ ReportComponent.builder(FILE, 112).build())
+ .build(),
+ ReportComponent.builder(DIRECTORY, 12).addChildren(
+ ReportComponent.builder(DIRECTORY, 121).addChildren(
+ ReportComponent.builder(FILE, 1211).build())
.build())
+ .build())
.build();
@Test
newCallRecord("visitAny", 1, null, of(1)),
newCallRecord("visitProject", 1, null, of(1)),
newCallRecord("visitAny", 11, 1, of(11, 1)),
- newCallRecord("visitModule", 11, 1, of(11, 1)),
+ newCallRecord("visitDirectory", 11, 1, of(11, 1)),
newCallRecord("visitAny", 111, 11, of(111, 11, 1)),
- newCallRecord("visitDirectory", 111, 11, of(111, 11, 1)),
- newCallRecord("visitAny", 1111, 111, of(1111, 111, 11, 1)),
- newCallRecord("visitFile", 1111, 111, of(1111, 111, 11, 1)),
- newCallRecord("visitAny", 1112, 111, of(1112, 111, 11, 1)),
- newCallRecord("visitFile", 1112, 111, of(1112, 111, 11, 1)),
+ newCallRecord("visitFile", 111, 11, of(111, 11, 1)),
newCallRecord("visitAny", 112, 11, of(112, 11, 1)),
- newCallRecord("visitDirectory", 112, 11, of(112, 11, 1)),
- newCallRecord("visitAny", 1121, 112, of(1121, 112, 11, 1)),
- newCallRecord("visitFile", 1121, 112, of(1121, 112, 11, 1)),
+ newCallRecord("visitFile", 112, 11, of(112, 11, 1)),
newCallRecord("visitAny", 12, 1, of(12, 1)),
- newCallRecord("visitModule", 12, 1, of(12, 1)),
+ newCallRecord("visitDirectory", 12, 1, of(12, 1)),
newCallRecord("visitAny", 121, 12, of(121, 12, 1)),
- newCallRecord("visitModule", 121, 12, of(121, 12, 1)),
+ newCallRecord("visitDirectory", 121, 12, of(121, 12, 1)),
newCallRecord("visitAny", 1211, 121, of(1211, 121, 12, 1)),
- newCallRecord("visitDirectory", 1211, 121, of(1211, 121, 12, 1)),
- newCallRecord("visitAny", 12111, 1211, of(12111, 1211, 121, 12, 1)),
- newCallRecord("visitFile", 12111, 1211, of(12111, 1211, 121, 12, 1))).iterator();
+ newCallRecord("visitFile", 1211, 121, of(1211, 121, 12, 1))).iterator();
verifyCallRecords(expected, underTest.callsRecords.iterator());
}
newCallRecord("visitAny", 1, null, of(1)),
newCallRecord("visitProject", 1, null, of(1)),
newCallRecord("visitAny", 11, 1, of(11, 1)),
- newCallRecord("visitModule", 11, 1, of(11, 1)),
- newCallRecord("visitAny", 111, 11, of(111, 11, 1)),
- newCallRecord("visitDirectory", 111, 11, of(111, 11, 1)),
- newCallRecord("visitAny", 112, 11, of(112, 11, 1)),
- newCallRecord("visitDirectory", 112, 11, of(112, 11, 1)),
- newCallRecord("visitAny", 12, 1, of(12, 1)),
- newCallRecord("visitModule", 12, 1, of(12, 1)),
- newCallRecord("visitAny", 121, 12, of(121, 12, 1)),
- newCallRecord("visitModule", 121, 12, of(121, 12, 1)),
- newCallRecord("visitAny", 1211, 121, of(1211, 121, 12, 1)),
- newCallRecord("visitDirectory", 1211, 121, of(1211, 121, 12, 1))).iterator();
- verifyCallRecords(expected, underTest.callsRecords.iterator());
- }
-
- @Test
- public void verify_preOrder_visit_call_when_visit_tree_with_depth_MODULE() {
- CallRecorderPathAwareVisitor underTest = new CallRecorderPathAwareVisitor(CrawlerDepthLimit.MODULE, PRE_ORDER);
- new PathAwareCrawler<>(underTest).visit(SOME_TREE_ROOT);
-
- Iterator<PathAwareCallRecord> expected = of(
- newCallRecord("visitAny", 1, null, of(1)),
- newCallRecord("visitProject", 1, null, of(1)),
- newCallRecord("visitAny", 11, 1, of(11, 1)),
- newCallRecord("visitModule", 11, 1, of(11, 1)),
+ newCallRecord("visitDirectory", 11, 1, of(11, 1)),
newCallRecord("visitAny", 12, 1, of(12, 1)),
- newCallRecord("visitModule", 12, 1, of(12, 1)),
+ newCallRecord("visitDirectory", 12, 1, of(12, 1)),
newCallRecord("visitAny", 121, 12, of(121, 12, 1)),
- newCallRecord("visitModule", 121, 12, of(121, 12, 1))).iterator();
+ newCallRecord("visitDirectory", 121, 12, of(121, 12, 1))).iterator();
verifyCallRecords(expected, underTest.callsRecords.iterator());
}
new PathAwareCrawler<>(underTest).visit(SOME_TREE_ROOT);
Iterator<PathAwareCallRecord> expected = of(
- newCallRecord("visitAny", 1111, 111, of(1111, 111, 11, 1)),
- newCallRecord("visitFile", 1111, 111, of(1111, 111, 11, 1)),
- newCallRecord("visitAny", 1112, 111, of(1112, 111, 11, 1)),
- newCallRecord("visitFile", 1112, 111, of(1112, 111, 11, 1)),
newCallRecord("visitAny", 111, 11, of(111, 11, 1)),
- newCallRecord("visitDirectory", 111, 11, of(111, 11, 1)),
- newCallRecord("visitAny", 1121, 112, of(1121, 112, 11, 1)),
- newCallRecord("visitFile", 1121, 112, of(1121, 112, 11, 1)),
+ newCallRecord("visitFile", 111, 11, of(111, 11, 1)),
newCallRecord("visitAny", 112, 11, of(112, 11, 1)),
- newCallRecord("visitDirectory", 112, 11, of(112, 11, 1)),
+ newCallRecord("visitFile", 112, 11, of(112, 11, 1)),
newCallRecord("visitAny", 11, 1, of(11, 1)),
- newCallRecord("visitModule", 11, 1, of(11, 1)),
- newCallRecord("visitAny", 12111, 1211, of(12111, 1211, 121, 12, 1)),
- newCallRecord("visitFile", 12111, 1211, of(12111, 1211, 121, 12, 1)),
+ newCallRecord("visitDirectory", 11, 1, of(11, 1)),
newCallRecord("visitAny", 1211, 121, of(1211, 121, 12, 1)),
- newCallRecord("visitDirectory", 1211, 121, of(1211, 121, 12, 1)),
+ newCallRecord("visitFile", 1211, 121, of(1211, 121, 12, 1)),
newCallRecord("visitAny", 121, 12, of(121, 12, 1)),
- newCallRecord("visitModule", 121, 12, of(121, 12, 1)),
+ newCallRecord("visitDirectory", 121, 12, of(121, 12, 1)),
newCallRecord("visitAny", 12, 1, of(12, 1)),
- newCallRecord("visitModule", 12, 1, of(12, 1)),
+ newCallRecord("visitDirectory", 12, 1, of(12, 1)),
newCallRecord("visitAny", 1, null, of(1)),
newCallRecord("visitProject", 1, null, of(1))).iterator();
verifyCallRecords(expected, underTest.callsRecords.iterator());
CallRecorderPathAwareVisitor underTest = new CallRecorderPathAwareVisitor(CrawlerDepthLimit.DIRECTORY, POST_ORDER);
new PathAwareCrawler<>(underTest).visit(SOME_TREE_ROOT);
- Iterator<PathAwareCallRecord> expected = of(
- newCallRecord("visitAny", 111, 11, of(111, 11, 1)),
- newCallRecord("visitDirectory", 111, 11, of(111, 11, 1)),
- newCallRecord("visitAny", 112, 11, of(112, 11, 1)),
- newCallRecord("visitDirectory", 112, 11, of(112, 11, 1)),
- newCallRecord("visitAny", 11, 1, of(11, 1)),
- newCallRecord("visitModule", 11, 1, of(11, 1)),
- newCallRecord("visitAny", 1211, 121, of(1211, 121, 12, 1)),
- newCallRecord("visitDirectory", 1211, 121, of(1211, 121, 12, 1)),
- newCallRecord("visitAny", 121, 12, of(121, 12, 1)),
- newCallRecord("visitModule", 121, 12, of(121, 12, 1)),
- newCallRecord("visitAny", 12, 1, of(12, 1)),
- newCallRecord("visitModule", 12, 1, of(12, 1)),
- newCallRecord("visitAny", 1, null, of(1)),
- newCallRecord("visitProject", 1, null, of(1))).iterator();
- verifyCallRecords(expected, underTest.callsRecords.iterator());
- }
-
- @Test
- public void verify_postOrder_visit_call_when_visit_tree_with_depth_MODULE() {
- CallRecorderPathAwareVisitor underTest = new CallRecorderPathAwareVisitor(CrawlerDepthLimit.MODULE, POST_ORDER);
- new PathAwareCrawler<>(underTest).visit(SOME_TREE_ROOT);
-
Iterator<PathAwareCallRecord> expected = of(
newCallRecord("visitAny", 11, 1, of(11, 1)),
- newCallRecord("visitModule", 11, 1, of(11, 1)),
+ newCallRecord("visitDirectory", 11, 1, of(11, 1)),
newCallRecord("visitAny", 121, 12, of(121, 12, 1)),
- newCallRecord("visitModule", 121, 12, of(121, 12, 1)),
+ newCallRecord("visitDirectory", 121, 12, of(121, 12, 1)),
newCallRecord("visitAny", 12, 1, of(12, 1)),
- newCallRecord("visitModule", 12, 1, of(12, 1)),
+ newCallRecord("visitDirectory", 12, 1, of(12, 1)),
newCallRecord("visitAny", 1, null, of(1)),
newCallRecord("visitProject", 1, null, of(1))).iterator();
verifyCallRecords(expected, underTest.callsRecords.iterator());
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.DIRECTORY;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.FILE;
-import static org.sonar.ce.task.projectanalysis.component.Component.Type.MODULE;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT;
import static org.sonar.ce.task.projectanalysis.component.ComponentVisitor.Order.POST_ORDER;
private static final Component FILE_5 = component(FILE, 5);
private static final Component FILE_6 = component(FILE, 6);
private static final Component DIRECTORY_4 = component(DIRECTORY, 4, FILE_5, FILE_6);
- private static final Component MODULE_3 = component(MODULE, 3, DIRECTORY_4);
- private static final Component MODULE_2 = component(MODULE, 2, MODULE_3);
- private static final Component COMPONENT_TREE = component(PROJECT, 1, MODULE_2);
+ private static final Component COMPONENT_TREE = component(PROJECT, 1, DIRECTORY_4);
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);
private final DepthTraversalTypeAwareCrawler fileCrawler = new DepthTraversalTypeAwareCrawler(fileVisitor);
reportCallRecord("visitFile", component));
}
- @Test
- public void visit_module_with_depth_FILE_calls_visit_module() {
- Component component = component(MODULE, 1);
- fileCrawler.visit(component);
-
- assertThat(fileVisitor.callsRecords).containsExactly(
- reportCallRecord("visitAny", component),
- reportCallRecord("visitModule", component));
- }
-
@Test
public void visit_directory_with_depth_FILE_calls_visit_directory() {
Component component = component(DIRECTORY, 1);
reportCallRecord("visitDirectory", component));
}
- @Test
- public void visit_module_with_depth_DIRECTORY_calls_visit_module() {
- Component component = component(MODULE, 1);
- directoryCrawler.visit(component);
-
- assertThat(directoryVisitor.callsRecords).containsExactly(
- reportCallRecord("visitAny", component),
- reportCallRecord("visitModule", component));
- }
-
@Test
public void visit_project_with_depth_DIRECTORY_calls_visit_project() {
Component component = component(PROJECT, 1);
reportCallRecord("visitProject", component));
}
- @Test
- public void visit_file_with_depth_MODULE_does_not_call_visit_file_nor_visitAny() {
- Component component = component(FILE, 1);
- moduleCrawler.visit(component);
-
- assertThat(moduleVisitor.callsRecords).isEmpty();
- }
-
- @Test
- public void visit_directory_with_depth_MODULE_does_not_call_visit_directory_nor_visitAny() {
- Component component = component(DIRECTORY, 1);
- moduleCrawler.visit(component);
-
- assertThat(moduleVisitor.callsRecords).isEmpty();
- }
-
- @Test
- public void visit_module_with_depth_MODULE_calls_visit_module() {
- Component component = component(MODULE, 1);
- moduleCrawler.visit(component);
-
- assertThat(moduleVisitor.callsRecords).containsExactly(
- reportCallRecord("visitAny", component),
- reportCallRecord("visitModule", component));
- }
-
- @Test
- public void visit_project_with_depth_MODULE_calls_visit_project() {
- Component component = component(MODULE, 1);
- moduleCrawler.visit(component);
-
- assertThat(moduleVisitor.callsRecords).containsExactly(
- reportCallRecord("visitAny", component),
- reportCallRecord("visitModule", component));
- }
-
@Test
public void visit_file_with_depth_PROJECT_does_not_call_visit_file_nor_visitAny() {
Component component = component(FILE, 1);
assertThat(projectVisitor.callsRecords).isEmpty();
}
- @Test
- public void visit_module_with_depth_PROJECT_does_not_call_visit_module_nor_visitAny() {
- Component component = component(MODULE, 1);
- projectCrawler.visit(component);
-
- assertThat(projectVisitor.callsRecords).isEmpty();
- }
-
@Test
public void visit_project_with_depth_PROJECT_calls_visit_project() {
Component component = component(PROJECT, 1);
reportCallRecord("visitFile", FILE_6),
reportCallRecord("visitAny", DIRECTORY_4),
reportCallRecord("visitDirectory", DIRECTORY_4),
- reportCallRecord("visitAny", MODULE_3),
- reportCallRecord("visitModule", MODULE_3),
- reportCallRecord("visitAny", MODULE_2),
- reportCallRecord("visitModule", MODULE_2),
reportCallRecord("visitAny", COMPONENT_TREE),
reportCallRecord("visitProject", COMPONENT_TREE));
}
assertThat(directoryVisitor.callsRecords).containsExactly(
reportCallRecord("visitAny", DIRECTORY_4),
reportCallRecord("visitDirectory", DIRECTORY_4),
- reportCallRecord("visitAny", MODULE_3),
- reportCallRecord("visitModule", MODULE_3),
- reportCallRecord("visitAny", MODULE_2),
- reportCallRecord("visitModule", MODULE_2),
- reportCallRecord("visitAny", COMPONENT_TREE),
- reportCallRecord("visitProject", COMPONENT_TREE));
- }
-
- @Test
- public void verify_visit_call_when_visit_tree_with_depth_MODULE() {
- moduleCrawler.visit(COMPONENT_TREE);
-
- assertThat(moduleVisitor.callsRecords).containsExactly(
- reportCallRecord("visitAny", MODULE_3),
- reportCallRecord("visitModule", MODULE_3),
- reportCallRecord("visitAny", MODULE_2),
- reportCallRecord("visitModule", MODULE_2),
reportCallRecord("visitAny", COMPONENT_TREE),
reportCallRecord("visitProject", COMPONENT_TREE));
}
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.DIRECTORY;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.FILE;
-import static org.sonar.ce.task.projectanalysis.component.Component.Type.MODULE;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT;
import static org.sonar.ce.task.projectanalysis.component.ComponentVisitor.Order.PRE_ORDER;
private static final Component FILE_5 = component(FILE, 5);
private static final Component FILE_6 = component(FILE, 6);
private static final Component DIRECTORY_4 = component(DIRECTORY, 4, FILE_5, FILE_6);
- private static final Component MODULE_3 = component(MODULE, 3, DIRECTORY_4);
- private static final Component MODULE_2 = component(MODULE, 2, MODULE_3);
- private static final Component COMPONENT_TREE = component(PROJECT, 1, MODULE_2);
+ private static final Component COMPONENT_TREE = component(PROJECT, 1, DIRECTORY_4);
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);
private final DepthTraversalTypeAwareCrawler directoryCrawler = new DepthTraversalTypeAwareCrawler(directoryVisitor);
private final DepthTraversalTypeAwareCrawler fileCrawler = new DepthTraversalTypeAwareCrawler(fileVisitor);
reportCallRecord("visitFile", component));
}
- @Test
- public void visit_module_with_depth_FILE_calls_visit_module() {
- Component component = component(MODULE, 1);
- fileCrawler.visit(component);
-
- assertThat(fileVisitor.callsRecords).containsExactly(
- reportCallRecord("visitAny", component),
- reportCallRecord("visitModule", component));
- }
-
@Test
public void visit_directory_with_depth_FILE_calls_visit_directory() {
Component component = component(DIRECTORY, 1);
reportCallRecord("visitDirectory", component));
}
- @Test
- public void visit_module_with_depth_DIRECTORY_calls_visit_module() {
- Component component = component(MODULE, 1);
- directoryCrawler.visit(component);
-
- assertThat(directoryVisitor.callsRecords).containsExactly(
- reportCallRecord("visitAny", component),
- reportCallRecord("visitModule", component));
- }
-
@Test
public void visit_project_with_depth_DIRECTORY_calls_visit_project() {
Component component = component(PROJECT, 1);
reportCallRecord("visitProject", component));
}
- @Test
- public void visit_file_with_depth_MODULE_does_not_call_visit_file_nor_visit_any() {
- Component component = component(FILE, 1);
- moduleCrawler.visit(component);
-
- assertThat(moduleVisitor.callsRecords).isEmpty();
- }
-
- @Test
- public void visit_directory_with_depth_MODULE_does_not_call_visit_directory_not_visit_any() {
- Component component = component(DIRECTORY, 1);
- moduleCrawler.visit(component);
-
- assertThat(moduleVisitor.callsRecords).isEmpty();
- }
-
- @Test
- public void visit_module_with_depth_MODULE_calls_visit_module() {
- Component component = component(MODULE, 1);
- moduleCrawler.visit(component);
-
- assertThat(moduleVisitor.callsRecords).containsExactly(
- reportCallRecord("visitAny", component),
- reportCallRecord("visitModule", component));
- }
-
- @Test
- public void visit_project_with_depth_MODULE_calls_visit_project() {
- Component component = component(MODULE, 1);
- moduleCrawler.visit(component);
-
- assertThat(moduleVisitor.callsRecords).containsExactly(
- reportCallRecord("visitAny", component),
- reportCallRecord("visitModule", component));
- }
-
@Test
public void visit_file_with_depth_PROJECT_does_not_call_visit_file_nor_visitAny() {
Component component = component(FILE, 1);
assertThat(projectVisitor.callsRecords).isEmpty();
}
- @Test
- public void visit_module_with_depth_PROJECT_does_not_call_visit_module_nor_visitAny() {
- Component component = component(MODULE, 1);
- projectCrawler.visit(component);
-
- assertThat(projectVisitor.callsRecords).isEmpty();
- }
-
@Test
public void visit_project_with_depth_PROJECT_calls_visit_project_nor_visitAny() {
Component component = component(PROJECT, 1);
assertThat(fileVisitor.callsRecords).containsExactly(
reportCallRecord("visitAny", COMPONENT_TREE),
reportCallRecord("visitProject", COMPONENT_TREE),
- reportCallRecord("visitAny", MODULE_2),
- reportCallRecord("visitModule", MODULE_2),
- reportCallRecord("visitAny", MODULE_3),
- reportCallRecord("visitModule", MODULE_3),
reportCallRecord("visitAny", DIRECTORY_4),
reportCallRecord("visitDirectory", DIRECTORY_4),
reportCallRecord("visitAny", FILE_5),
assertThat(directoryVisitor.callsRecords).containsExactly(
reportCallRecord("visitAny", COMPONENT_TREE),
reportCallRecord("visitProject", COMPONENT_TREE),
- reportCallRecord("visitAny", MODULE_2),
- reportCallRecord("visitModule", MODULE_2),
- reportCallRecord("visitAny", MODULE_3),
- reportCallRecord("visitModule", MODULE_3),
reportCallRecord("visitAny", DIRECTORY_4),
reportCallRecord("visitDirectory", DIRECTORY_4));
}
- @Test
- public void verify_visit_call_when_visit_tree_with_depth_MODULE() {
- moduleCrawler.visit(COMPONENT_TREE);
-
- assertThat(moduleVisitor.callsRecords).containsExactly(
- reportCallRecord("visitAny", COMPONENT_TREE),
- reportCallRecord("visitProject", COMPONENT_TREE),
- reportCallRecord("visitAny", MODULE_2),
- reportCallRecord("visitModule", MODULE_2),
- reportCallRecord("visitAny", MODULE_3),
- reportCallRecord("visitModule", MODULE_3));
- }
-
@Test
public void verify_visit_call_when_visit_tree_with_depth_PROJECT() {
projectCrawler.visit(COMPONENT_TREE);
import static org.mockito.Mockito.spy;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.DIRECTORY;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.FILE;
-import static org.sonar.ce.task.projectanalysis.component.Component.Type.MODULE;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT;
import static org.sonar.ce.task.projectanalysis.component.ComponentVisitor.Order.POST_ORDER;
import static org.sonar.ce.task.projectanalysis.component.ComponentVisitor.Order.PRE_ORDER;
private static final Component FILE_5 = component(FILE, 5);
private static final Component DIRECTORY_4 = component(DIRECTORY, 4, FILE_5);
- private static final Component MODULE_3 = component(MODULE, 3, DIRECTORY_4);
- private static final Component MODULE_2 = component(MODULE, 2, MODULE_3);
- private static final Component COMPONENT_TREE = component(PROJECT, 1, MODULE_2);
+ private static final Component COMPONENT_TREE = component(PROJECT, 1, DIRECTORY_4);
private final TypeAwareVisitor spyPreOrderTypeAwareVisitor = spy(new TestTypeAwareVisitor(CrawlerDepthLimit.FILE, PRE_ORDER));
private final TypeAwareVisitor spyPostOrderTypeAwareVisitor = spy(new TestTypeAwareVisitor(CrawlerDepthLimit.FILE, POST_ORDER));
inOrder.verify(spyPathAwareVisitor).visitAny(eq(DIRECTORY_4), any(PathAwareVisitor.Path.class));
inOrder.verify(spyPathAwareVisitor).visitDirectory(eq(DIRECTORY_4), any(PathAwareVisitor.Path.class));
- inOrder.verify(spyPostOrderTypeAwareVisitor).visitAny(MODULE_3);
- inOrder.verify(spyPostOrderTypeAwareVisitor).visitModule(MODULE_3);
- inOrder.verify(spyPathAwareVisitor).visitAny(eq(MODULE_3), any(PathAwareVisitor.Path.class));
- inOrder.verify(spyPathAwareVisitor).visitModule(eq(MODULE_3), any(PathAwareVisitor.Path.class));
-
- inOrder.verify(spyPostOrderTypeAwareVisitor).visitAny(MODULE_2);
- inOrder.verify(spyPostOrderTypeAwareVisitor).visitModule(MODULE_2);
- inOrder.verify(spyPathAwareVisitor).visitAny(eq(MODULE_2), any(PathAwareVisitor.Path.class));
- inOrder.verify(spyPathAwareVisitor).visitModule(eq(MODULE_2), any(PathAwareVisitor.Path.class));
-
inOrder.verify(spyPostOrderTypeAwareVisitor).visitAny(COMPONENT_TREE);
inOrder.verify(spyPostOrderTypeAwareVisitor).visitProject(COMPONENT_TREE);
inOrder.verify(spyPathAwareVisitor).visitAny(eq(COMPONENT_TREE), any(PathAwareVisitor.Path.class));
underTest.visit(COMPONENT_TREE);
inOrder.verify(spyPreOrderTypeAwareVisitor).visitProject(COMPONENT_TREE);
- inOrder.verify(spyPreOrderTypeAwareVisitor).visitModule(MODULE_2);
- inOrder.verify(spyPreOrderTypeAwareVisitor).visitModule(MODULE_3);
inOrder.verify(spyPreOrderTypeAwareVisitor).visitDirectory(DIRECTORY_4);
inOrder.verify(spyPreOrderTypeAwareVisitor).visitFile(FILE_5);
inOrder.verify(spyPostOrderTypeAwareVisitor).visitFile(FILE_5);
inOrder.verify(spyPostOrderTypeAwareVisitor).visitDirectory(DIRECTORY_4);
- inOrder.verify(spyPostOrderTypeAwareVisitor).visitModule(MODULE_3);
- inOrder.verify(spyPostOrderTypeAwareVisitor).visitModule(MODULE_2);
inOrder.verify(spyPostOrderTypeAwareVisitor).visitProject(COMPONENT_TREE);
}
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.DIRECTORY;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.FILE;
-import static org.sonar.ce.task.projectanalysis.component.Component.Type.MODULE;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT;
import static org.sonar.ce.task.projectanalysis.component.ComponentVisitor.Order.POST_ORDER;
import static org.sonar.ce.task.projectanalysis.component.ComponentVisitor.Order.PRE_ORDER;
private static final int ROOT_REF = 1;
private static final ReportComponent SOME_TREE_ROOT = ReportComponent.builder(PROJECT, ROOT_REF)
.addChildren(
- ReportComponent.builder(MODULE, 11)
+ ReportComponent.builder(DIRECTORY, 11)
.addChildren(
- ReportComponent.builder(DIRECTORY, 111)
- .addChildren(
- ReportComponent.builder(FILE, 1111).build(),
- ReportComponent.builder(FILE, 1112).build())
- .build(),
- ReportComponent.builder(DIRECTORY, 112)
- .addChildren(
- ReportComponent.builder(FILE, 1121).build())
- .build())
+ ReportComponent.builder(FILE, 111).build(),
+ ReportComponent.builder(FILE, 112).build())
.build(),
- ReportComponent.builder(MODULE, 12)
+ ReportComponent.builder(DIRECTORY, 12)
.addChildren(
- ReportComponent.builder(MODULE, 121)
+ ReportComponent.builder(FILE, 121).build(),
+ ReportComponent.builder(DIRECTORY, 122)
.addChildren(
- ReportComponent.builder(DIRECTORY, 1211)
- .addChildren(
- ReportComponent.builder(FILE, 12111).build())
- .build())
+ ReportComponent.builder(FILE, 1221).build())
.build())
.build())
.build();
reportCallRecord("visitAny", 1, null, of(1)),
reportCallRecord("visitProject", 1, null, of(1)),
reportCallRecord("visitAny", 11, 1, of(11, 1)),
- reportCallRecord("visitModule", 11, 1, of(11, 1)),
+ reportCallRecord("visitDirectory", 11, 1, of(11, 1)),
reportCallRecord("visitAny", 111, 11, of(111, 11, 1)),
- reportCallRecord("visitDirectory", 111, 11, of(111, 11, 1)),
- reportCallRecord("visitAny", 1111, 111, of(1111, 111, 11, 1)),
- reportCallRecord("visitFile", 1111, 111, of(1111, 111, 11, 1)),
- reportCallRecord("visitAny", 1112, 111, of(1112, 111, 11, 1)),
- reportCallRecord("visitFile", 1112, 111, of(1112, 111, 11, 1)),
+ reportCallRecord("visitFile", 111, 11, of(111, 11, 1)),
reportCallRecord("visitAny", 112, 11, of(112, 11, 1)),
- reportCallRecord("visitDirectory", 112, 11, of(112, 11, 1)),
- reportCallRecord("visitAny", 1121, 112, of(1121, 112, 11, 1)),
- reportCallRecord("visitFile", 1121, 112, of(1121, 112, 11, 1)),
+ reportCallRecord("visitFile", 112, 11, of(112, 11, 1)),
reportCallRecord("visitAny", 12, 1, of(12, 1)),
- reportCallRecord("visitModule", 12, 1, of(12, 1)),
+ reportCallRecord("visitDirectory", 12, 1, of(12, 1)),
reportCallRecord("visitAny", 121, 12, of(121, 12, 1)),
- reportCallRecord("visitModule", 121, 12, of(121, 12, 1)),
- reportCallRecord("visitAny", 1211, 121, of(1211, 121, 12, 1)),
- reportCallRecord("visitDirectory", 1211, 121, of(1211, 121, 12, 1)),
- reportCallRecord("visitAny", 12111, 1211, of(12111, 1211, 121, 12, 1)),
- reportCallRecord("visitFile", 12111, 1211, of(12111, 1211, 121, 12, 1))).iterator();
+ reportCallRecord("visitFile", 121, 12, of(121, 12, 1)),
+ reportCallRecord("visitAny", 122, 12, of(122, 12, 1)),
+ reportCallRecord("visitDirectory", 122, 12, of(122, 12, 1)),
+ reportCallRecord("visitAny", 1221, 122, of(1221, 122, 12, 1)),
+ reportCallRecord("visitFile", 1221, 122, of(1221, 122, 12, 1))).iterator();
verifyCallRecords(expected, visitor.callsRecords.iterator());
}
reportCallRecord("visitAny", 1, null, of(1)),
reportCallRecord("visitProject", 1, null, of(1)),
reportCallRecord("visitAny", 11, 1, of(11, 1)),
- reportCallRecord("visitModule", 11, 1, of(11, 1)),
- reportCallRecord("visitAny", 111, 11, of(111, 11, 1)),
- reportCallRecord("visitDirectory", 111, 11, of(111, 11, 1)),
- reportCallRecord("visitAny", 112, 11, of(112, 11, 1)),
- reportCallRecord("visitDirectory", 112, 11, of(112, 11, 1)),
+ reportCallRecord("visitDirectory", 11, 1, of(11, 1)),
reportCallRecord("visitAny", 12, 1, of(12, 1)),
- reportCallRecord("visitModule", 12, 1, of(12, 1)),
- reportCallRecord("visitAny", 121, 12, of(121, 12, 1)),
- reportCallRecord("visitModule", 121, 12, of(121, 12, 1)),
- reportCallRecord("visitAny", 1211, 121, of(1211, 121, 12, 1)),
- reportCallRecord("visitDirectory", 1211, 121, of(1211, 121, 12, 1))).iterator();
- verifyCallRecords(expected, visitor.callsRecords.iterator());
- }
-
- @Test
- public void verify_preOrder_visit_call_when_visit_tree_with_depth_MODULE() {
- CallRecorderPathAwareVisitor visitor = new CallRecorderPathAwareVisitor(CrawlerDepthLimit.MODULE, PRE_ORDER);
- VisitorsCrawler underTest = newVisitorsCrawler(visitor);
- underTest.visit(SOME_TREE_ROOT);
-
- Iterator<PathAwareCallRecord> expected = of(
- reportCallRecord("visitAny", 1, null, of(1)),
- reportCallRecord("visitProject", 1, null, of(1)),
- reportCallRecord("visitAny", 11, 1, of(11, 1)),
- reportCallRecord("visitModule", 11, 1, of(11, 1)),
- reportCallRecord("visitAny", 12, 1, of(12, 1)),
- reportCallRecord("visitModule", 12, 1, of(12, 1)),
- reportCallRecord("visitAny", 121, 12, of(121, 12, 1)),
- reportCallRecord("visitModule", 121, 12, of(121, 12, 1))).iterator();
+ reportCallRecord("visitDirectory", 12, 1, of(12, 1)),
+ reportCallRecord("visitAny", 122, 12, of(122, 12, 1)),
+ reportCallRecord("visitDirectory", 122, 12, of(122, 12, 1))).iterator();
verifyCallRecords(expected, visitor.callsRecords.iterator());
}
underTest.visit(SOME_TREE_ROOT);
Iterator<PathAwareCallRecord> expected = of(
- reportCallRecord("visitAny", 1111, 111, of(1111, 111, 11, 1)),
- reportCallRecord("visitFile", 1111, 111, of(1111, 111, 11, 1)),
- reportCallRecord("visitAny", 1112, 111, of(1112, 111, 11, 1)),
- reportCallRecord("visitFile", 1112, 111, of(1112, 111, 11, 1)),
reportCallRecord("visitAny", 111, 11, of(111, 11, 1)),
- reportCallRecord("visitDirectory", 111, 11, of(111, 11, 1)),
- reportCallRecord("visitAny", 1121, 112, of(1121, 112, 11, 1)),
- reportCallRecord("visitFile", 1121, 112, of(1121, 112, 11, 1)),
+ reportCallRecord("visitFile", 111, 11, of(111, 11, 1)),
reportCallRecord("visitAny", 112, 11, of(112, 11, 1)),
- reportCallRecord("visitDirectory", 112, 11, of(112, 11, 1)),
+ reportCallRecord("visitFile", 112, 11, of(112, 11, 1)),
reportCallRecord("visitAny", 11, 1, of(11, 1)),
- reportCallRecord("visitModule", 11, 1, of(11, 1)),
- reportCallRecord("visitAny", 12111, 1211, of(12111, 1211, 121, 12, 1)),
- reportCallRecord("visitFile", 12111, 1211, of(12111, 1211, 121, 12, 1)),
- reportCallRecord("visitAny", 1211, 121, of(1211, 121, 12, 1)),
- reportCallRecord("visitDirectory", 1211, 121, of(1211, 121, 12, 1)),
+ reportCallRecord("visitDirectory", 11, 1, of(11, 1)),
reportCallRecord("visitAny", 121, 12, of(121, 12, 1)),
- reportCallRecord("visitModule", 121, 12, of(121, 12, 1)),
+ reportCallRecord("visitFile", 121, 12, of(121, 12, 1)),
+ reportCallRecord("visitAny", 1221, 122, of(1221, 122, 12, 1)),
+ reportCallRecord("visitFile", 1221, 122, of(1221, 122, 12, 1)),
+ reportCallRecord("visitAny", 122, 12, of(122, 12, 1)),
+ reportCallRecord("visitDirectory", 122, 12, of(122, 12, 1)),
reportCallRecord("visitAny", 12, 1, of(12, 1)),
- reportCallRecord("visitModule", 12, 1, of(12, 1)),
+ reportCallRecord("visitDirectory", 12, 1, of(12, 1)),
reportCallRecord("visitAny", 1, null, of(1)),
reportCallRecord("visitProject", 1, null, of(1))).iterator();
verifyCallRecords(expected, visitor.callsRecords.iterator());
underTest.visit(SOME_TREE_ROOT);
Iterator<PathAwareCallRecord> expected = of(
- reportCallRecord("visitAny", 111, 11, of(111, 11, 1)),
- reportCallRecord("visitDirectory", 111, 11, of(111, 11, 1)),
- reportCallRecord("visitAny", 112, 11, of(112, 11, 1)),
- reportCallRecord("visitDirectory", 112, 11, of(112, 11, 1)),
reportCallRecord("visitAny", 11, 1, of(11, 1)),
- reportCallRecord("visitModule", 11, 1, of(11, 1)),
- reportCallRecord("visitAny", 1211, 121, of(1211, 121, 12, 1)),
- reportCallRecord("visitDirectory", 1211, 121, of(1211, 121, 12, 1)),
- reportCallRecord("visitAny", 121, 12, of(121, 12, 1)),
- reportCallRecord("visitModule", 121, 12, of(121, 12, 1)),
- reportCallRecord("visitAny", 12, 1, of(12, 1)),
- reportCallRecord("visitModule", 12, 1, of(12, 1)),
- reportCallRecord("visitAny", 1, null, of(1)),
- reportCallRecord("visitProject", 1, null, of(1))).iterator();
- verifyCallRecords(expected, visitor.callsRecords.iterator());
- }
-
- @Test
- public void verify_postOrder_visit_call_when_visit_tree_with_depth_MODULE() {
- CallRecorderPathAwareVisitor visitor = new CallRecorderPathAwareVisitor(CrawlerDepthLimit.MODULE, POST_ORDER);
- VisitorsCrawler underTest = newVisitorsCrawler(visitor);
- underTest.visit(SOME_TREE_ROOT);
-
- Iterator<PathAwareCallRecord> expected = of(
- reportCallRecord("visitAny", 11, 1, of(11, 1)),
- reportCallRecord("visitModule", 11, 1, of(11, 1)),
- reportCallRecord("visitAny", 121, 12, of(121, 12, 1)),
- reportCallRecord("visitModule", 121, 12, of(121, 12, 1)),
+ reportCallRecord("visitDirectory", 11, 1, of(11, 1)),
+ reportCallRecord("visitAny", 122, 12, of(122, 12, 1)),
+ reportCallRecord("visitDirectory", 122, 12, of(122, 12, 1)),
reportCallRecord("visitAny", 12, 1, of(12, 1)),
- reportCallRecord("visitModule", 12, 1, of(12, 1)),
+ reportCallRecord("visitDirectory", 12, 1, of(12, 1)),
reportCallRecord("visitAny", 1, null, of(1)),
reportCallRecord("visitProject", 1, null, of(1))).iterator();
verifyCallRecords(expected, visitor.callsRecords.iterator());
import static org.mockito.Mockito.spy;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.DIRECTORY;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.FILE;
-import static org.sonar.ce.task.projectanalysis.component.Component.Type.MODULE;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT;
import static org.sonar.ce.task.projectanalysis.component.ComponentVisitor.Order.POST_ORDER;
private static final Component FILE_5 = component(FILE, 5);
private static final Component FILE_6 = component(FILE, 6);
private static final Component DIRECTORY_4 = component(DIRECTORY, 4, FILE_5, FILE_6);
- private static final Component MODULE_3 = component(MODULE, 3, DIRECTORY_4);
- private static final Component MODULE_2 = component(MODULE, 2, MODULE_3);
- private static final Component COMPONENT_TREE = component(PROJECT, 1, MODULE_2);
+ private static final Component COMPONENT_TREE = component(PROJECT, 1, DIRECTORY_4);
private final TypeAwareVisitor spyProjectVisitor = spy(new TypeAwareVisitorAdapter(CrawlerDepthLimit.PROJECT, POST_ORDER) {
});
- private final TypeAwareVisitor spyModuleVisitor = spy(new TypeAwareVisitorAdapter(CrawlerDepthLimit.MODULE, POST_ORDER) {
- });
private final TypeAwareVisitor spyDirectoryVisitor = spy(new TypeAwareVisitorAdapter(CrawlerDepthLimit.DIRECTORY, POST_ORDER) {
});
private final TypeAwareVisitor spyFileVisitor = spy(new TypeAwareVisitorAdapter(CrawlerDepthLimit.FILE, POST_ORDER) {
});
- private final InOrder inOrder = inOrder(spyProjectVisitor, spyModuleVisitor, spyDirectoryVisitor, spyFileVisitor);
+ private final InOrder inOrder = inOrder(spyProjectVisitor, spyDirectoryVisitor, spyFileVisitor);
@Test(expected = NullPointerException.class)
public void visit_null_Component_throws_NPE() {
inOrder.verifyNoMoreInteractions();
}
- @Test
- public void visit_module_with_depth_FILE_calls_visit_module() {
- Component component = component(MODULE, 1);
- VisitorsCrawler underTest = newVisitorsCrawler(spyFileVisitor);
- underTest.visit(component);
-
- inOrder.verify(spyFileVisitor).visitAny(component);
- inOrder.verify(spyFileVisitor).visitModule(component);
- inOrder.verifyNoMoreInteractions();
- }
-
@Test
public void visit_directory_with_depth_FILE_calls_visit_directory() {
Component component = component(DIRECTORY, 1);
inOrder.verifyNoMoreInteractions();
}
- @Test
- public void visit_module_with_depth_DIRECTORY_calls_visit_module() {
- Component component = component(MODULE, 1);
- VisitorsCrawler underTest = newVisitorsCrawler(spyDirectoryVisitor);
- underTest.visit(component);
-
- inOrder.verify(spyDirectoryVisitor).visitAny(component);
- inOrder.verify(spyDirectoryVisitor).visitModule(component);
- inOrder.verifyNoMoreInteractions();
- }
-
@Test
public void visit_project_with_depth_DIRECTORY_calls_visit_project() {
Component component = component(PROJECT, 1);
inOrder.verifyNoMoreInteractions();
}
- @Test
- public void visit_file_with_depth_MODULE_does_not_call_visit_file_nor_visitAny() {
- Component component = component(FILE, 1);
- VisitorsCrawler underTest = newVisitorsCrawler(spyModuleVisitor);
- underTest.visit(component);
-
- inOrder.verify(spyModuleVisitor, never()).visitFile(component);
- inOrder.verify(spyModuleVisitor, never()).visitAny(component);
- }
-
- @Test
- public void visit_directory_with_depth_MODULE_does_not_call_visit_directory_nor_visitAny() {
- Component component = component(DIRECTORY, 1);
- VisitorsCrawler underTest = newVisitorsCrawler(spyModuleVisitor);
- underTest.visit(component);
-
- inOrder.verify(spyModuleVisitor, never()).visitDirectory(component);
- inOrder.verify(spyModuleVisitor, never()).visitFile(component);
- inOrder.verify(spyModuleVisitor, never()).visitAny(component);
- }
-
- @Test
- public void visit_module_with_depth_MODULE_calls_visit_module() {
- Component component = component(MODULE, 1);
- VisitorsCrawler underTest = newVisitorsCrawler(spyModuleVisitor);
- underTest.visit(component);
-
- inOrder.verify(spyModuleVisitor).visitAny(component);
- inOrder.verify(spyModuleVisitor).visitModule(component);
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void visit_project_with_depth_MODULE_calls_visit_project() {
- Component component = component(MODULE, 1);
- VisitorsCrawler underTest = newVisitorsCrawler(spyModuleVisitor);
- underTest.visit(component);
-
- inOrder.verify(spyModuleVisitor).visitAny(component);
- inOrder.verify(spyModuleVisitor).visitModule(component);
- inOrder.verifyNoMoreInteractions();
- }
-
@Test
public void visit_file_with_depth_PROJECT_does_not_call_visit_file_nor_visitAny() {
Component component = component(FILE, 1);
inOrder.verify(spyProjectVisitor, never()).visitAny(component);
}
- @Test
- public void visit_module_with_depth_PROJECT_does_not_call_visit_module_nor_visitAny() {
- Component component = component(MODULE, 1);
- VisitorsCrawler underTest = newVisitorsCrawler(spyProjectVisitor);
- underTest.visit(component);
-
- inOrder.verify(spyProjectVisitor, never()).visitModule(component);
- inOrder.verify(spyProjectVisitor, never()).visitDirectory(component);
- inOrder.verify(spyProjectVisitor, never()).visitFile(component);
- inOrder.verify(spyProjectVisitor, never()).visitAny(component);
- }
-
@Test
public void visit_project_with_depth_PROJECT_calls_visit_project() {
Component component = component(PROJECT, 1);
inOrder.verify(spyFileVisitor).visitFile(FILE_6);
inOrder.verify(spyFileVisitor).visitAny(DIRECTORY_4);
inOrder.verify(spyFileVisitor).visitDirectory(DIRECTORY_4);
- inOrder.verify(spyFileVisitor).visitAny(MODULE_3);
- inOrder.verify(spyFileVisitor).visitModule(MODULE_3);
- inOrder.verify(spyFileVisitor).visitAny(MODULE_2);
- inOrder.verify(spyFileVisitor).visitModule(MODULE_2);
inOrder.verify(spyFileVisitor).visitAny(COMPONENT_TREE);
inOrder.verify(spyFileVisitor).visitProject(COMPONENT_TREE);
inOrder.verifyNoMoreInteractions();
inOrder.verify(spyDirectoryVisitor).visitAny(DIRECTORY_4);
inOrder.verify(spyDirectoryVisitor).visitDirectory(DIRECTORY_4);
- inOrder.verify(spyDirectoryVisitor).visitAny(MODULE_3);
- inOrder.verify(spyDirectoryVisitor).visitModule(MODULE_3);
- inOrder.verify(spyDirectoryVisitor).visitAny(MODULE_2);
- inOrder.verify(spyDirectoryVisitor).visitModule(MODULE_2);
inOrder.verify(spyDirectoryVisitor).visitAny(COMPONENT_TREE);
inOrder.verify(spyDirectoryVisitor).visitProject(COMPONENT_TREE);
inOrder.verifyNoMoreInteractions();
}
- @Test
- public void verify_visit_call_when_visit_tree_with_depth_MODULE() {
- VisitorsCrawler underTest = newVisitorsCrawler(spyModuleVisitor);
- underTest.visit(COMPONENT_TREE);
-
- inOrder.verify(spyModuleVisitor).visitAny(MODULE_3);
- inOrder.verify(spyModuleVisitor).visitModule(MODULE_3);
- inOrder.verify(spyModuleVisitor).visitAny(MODULE_2);
- inOrder.verify(spyModuleVisitor).visitModule(MODULE_2);
- inOrder.verify(spyModuleVisitor).visitAny(COMPONENT_TREE);
- inOrder.verify(spyModuleVisitor).visitProject(COMPONENT_TREE);
- inOrder.verifyNoMoreInteractions();
- }
-
@Test
public void verify_visit_call_when_visit_tree_with_depth_PROJECT() {
VisitorsCrawler underTest = newVisitorsCrawler(spyProjectVisitor);
import static org.mockito.Mockito.spy;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.DIRECTORY;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.FILE;
-import static org.sonar.ce.task.projectanalysis.component.Component.Type.MODULE;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT;
import static org.sonar.ce.task.projectanalysis.component.ComponentVisitor.Order.PRE_ORDER;
private static final Component FILE_5 = component(FILE, 5);
private static final Component FILE_6 = component(FILE, 6);
private static final Component DIRECTORY_4 = component(DIRECTORY, 4, FILE_5, FILE_6);
- private static final Component MODULE_3 = component(MODULE, 3, DIRECTORY_4);
- private static final Component MODULE_2 = component(MODULE, 2, MODULE_3);
- private static final Component COMPONENT_TREE = component(PROJECT, 1, MODULE_2);
+ private static final Component COMPONENT_TREE = component(PROJECT, 1, DIRECTORY_4);
private final TypeAwareVisitor spyProjectVisitor = spy(new TypeAwareVisitorAdapter(CrawlerDepthLimit.PROJECT, PRE_ORDER) {
});
- private final TypeAwareVisitor spyModuleVisitor = spy(new TypeAwareVisitorAdapter(CrawlerDepthLimit.MODULE, PRE_ORDER) {
- });
private final TypeAwareVisitor spyDirectoryVisitor = spy(new TypeAwareVisitorAdapter(CrawlerDepthLimit.DIRECTORY, PRE_ORDER) {
});
private final TypeAwareVisitor spyFileVisitor = spy(new TypeAwareVisitorAdapter(CrawlerDepthLimit.FILE, PRE_ORDER) {
});
- private final InOrder inOrder = inOrder(spyProjectVisitor, spyModuleVisitor, spyDirectoryVisitor, spyFileVisitor);
+ private final InOrder inOrder = inOrder(spyProjectVisitor, spyDirectoryVisitor, spyFileVisitor);
@Test(expected = NullPointerException.class)
public void visit_null_Component_throws_NPE() {
inOrder.verifyNoMoreInteractions();
}
- @Test
- public void visit_module_with_depth_FILE_calls_visit_module() {
- Component component = component(MODULE, 1);
- VisitorsCrawler underTest = newVisitorsCrawler(spyFileVisitor);
- underTest.visit(component);
-
- inOrder.verify(spyFileVisitor).visitAny(component);
- inOrder.verify(spyFileVisitor).visitModule(component);
- inOrder.verifyNoMoreInteractions();
- }
-
@Test
public void visit_directory_with_depth_FILE_calls_visit_directory() {
Component component = component(DIRECTORY, 1);
inOrder.verifyNoMoreInteractions();
}
- @Test
- public void visit_module_with_depth_DIRECTORY_calls_visit_module() {
- Component component = component(MODULE, 1);
- VisitorsCrawler underTest = newVisitorsCrawler(spyDirectoryVisitor);
- underTest.visit(component);
-
- inOrder.verify(spyDirectoryVisitor).visitAny(component);
- inOrder.verify(spyDirectoryVisitor).visitModule(component);
- inOrder.verifyNoMoreInteractions();
- }
-
@Test
public void visit_project_with_depth_DIRECTORY_calls_visit_project() {
Component component = component(PROJECT, 1);
inOrder.verifyNoMoreInteractions();
}
- @Test
- public void visit_file_with_depth_MODULE_does_not_call_visit_file_nor_visit_any() {
- Component component = component(FILE, 1);
- VisitorsCrawler underTest = newVisitorsCrawler(spyModuleVisitor);
- underTest.visit(component);
-
- inOrder.verify(spyModuleVisitor, never()).visitFile(component);
- inOrder.verify(spyModuleVisitor, never()).visitAny(component);
- }
-
- @Test
- public void visit_directory_with_depth_MODULE_does_not_call_visit_directory_not_visit_any() {
- Component component = component(DIRECTORY, 1);
- VisitorsCrawler underTest = newVisitorsCrawler(spyModuleVisitor);
- underTest.visit(component);
-
- inOrder.verify(spyModuleVisitor, never()).visitFile(component);
- inOrder.verify(spyModuleVisitor, never()).visitAny(component);
- }
-
- @Test
- public void visit_module_with_depth_MODULE_calls_visit_module() {
- Component component = component(MODULE, 1);
- VisitorsCrawler underTest = newVisitorsCrawler(spyModuleVisitor);
- underTest.visit(component);
-
- inOrder.verify(spyModuleVisitor).visitAny(component);
- inOrder.verify(spyModuleVisitor).visitModule(component);
- inOrder.verifyNoMoreInteractions();
- }
-
- @Test
- public void visit_project_with_depth_MODULE_calls_visit_project() {
- Component component = component(MODULE, 1);
- VisitorsCrawler underTest = newVisitorsCrawler(spyModuleVisitor);
- underTest.visit(component);
-
- inOrder.verify(spyModuleVisitor).visitAny(component);
- inOrder.verify(spyModuleVisitor).visitModule(component);
- inOrder.verifyNoMoreInteractions();
- }
-
@Test
public void visit_file_with_depth_PROJECT_does_not_call_visit_file_nor_visitAny() {
Component component = component(FILE, 1);
inOrder.verify(spyProjectVisitor, never()).visitAny(component);
}
- @Test
- public void visit_module_with_depth_PROJECT_does_not_call_visit_module_nor_visitAny() {
- Component component = component(MODULE, 1);
- VisitorsCrawler underTest = newVisitorsCrawler(spyProjectVisitor);
- underTest.visit(component);
-
- inOrder.verify(spyProjectVisitor, never()).visitFile(component);
- inOrder.verify(spyProjectVisitor, never()).visitAny(component);
- }
-
@Test
public void visit_project_with_depth_PROJECT_calls_visit_project_nor_visitAny() {
Component component = component(PROJECT, 1);
inOrder.verify(spyFileVisitor).visitAny(COMPONENT_TREE);
inOrder.verify(spyFileVisitor).visitProject(COMPONENT_TREE);
- inOrder.verify(spyFileVisitor).visitAny(MODULE_2);
- inOrder.verify(spyFileVisitor).visitModule(MODULE_2);
- inOrder.verify(spyFileVisitor).visitAny(MODULE_3);
- inOrder.verify(spyFileVisitor).visitModule(MODULE_3);
inOrder.verify(spyFileVisitor).visitAny(DIRECTORY_4);
inOrder.verify(spyFileVisitor).visitDirectory(DIRECTORY_4);
inOrder.verify(spyFileVisitor).visitAny(FILE_5);
underTest.visit(COMPONENT_TREE);
inOrder.verify(spyDirectoryVisitor).visitProject(COMPONENT_TREE);
- inOrder.verify(spyDirectoryVisitor).visitModule(MODULE_2);
- inOrder.verify(spyDirectoryVisitor).visitModule(MODULE_3);
inOrder.verify(spyDirectoryVisitor).visitDirectory(DIRECTORY_4);
inOrder.verify(spyProjectVisitor, never()).visitFile(FILE_5);
inOrder.verify(spyProjectVisitor, never()).visitFile(FILE_6);
}
- @Test
- public void verify_visit_call_when_visit_tree_with_depth_MODULE() {
- VisitorsCrawler underTest = newVisitorsCrawler(spyModuleVisitor);
- underTest.visit(COMPONENT_TREE);
-
- inOrder.verify(spyModuleVisitor).visitAny(COMPONENT_TREE);
- inOrder.verify(spyModuleVisitor).visitProject(COMPONENT_TREE);
- inOrder.verify(spyModuleVisitor).visitAny(MODULE_2);
- inOrder.verify(spyModuleVisitor).visitModule(MODULE_2);
- inOrder.verify(spyModuleVisitor).visitAny(MODULE_3);
- inOrder.verify(spyModuleVisitor).visitModule(MODULE_3);
- inOrder.verify(spyProjectVisitor, never()).visitDirectory(DIRECTORY_4);
- }
-
@Test
public void verify_visit_call_when_visit_tree_with_depth_PROJECT() {
VisitorsCrawler underTest = newVisitorsCrawler(spyProjectVisitor);
inOrder.verify(spyProjectVisitor).visitAny(COMPONENT_TREE);
inOrder.verify(spyProjectVisitor).visitProject(COMPONENT_TREE);
- inOrder.verify(spyProjectVisitor, never()).visitModule(MODULE_2);
- inOrder.verify(spyProjectVisitor, never()).visitModule(MODULE_3);
}
private static Component component(final Component.Type type, final int ref, final Component... children) {
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.DIRECTORY;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.FILE;
-import static org.sonar.ce.task.projectanalysis.component.Component.Type.MODULE;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT_VIEW;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.VIEW;
public class TreeRootHolderImplTest {
private static final ReportComponent SOME_REPORT_COMPONENT_TREE = ReportComponent.builder(PROJECT, 1)
- .addChildren(
- ReportComponent.builder(MODULE, 2)
- .addChildren(ReportComponent.builder(DIRECTORY, 3)
- .addChildren(
- ReportComponent.builder(FILE, 4).build())
- .build())
- .build())
+ .addChildren(ReportComponent.builder(DIRECTORY, 2)
+ .addChildren(
+ ReportComponent.builder(FILE, 3).build())
+ .build())
.build();
private static final ViewsComponent SOME_VIEWS_COMPONENT_TREE = ViewsComponent.builder(VIEW, 1)
.addChildren(
public void getComponentByRef_returns_any_report_component_in_the_tree() {
underTest.setRoots(SOME_REPORT_COMPONENT_TREE, DUMB_PROJECT);
- for (int i = 1; i <= 4; i++) {
+ for (int i = 1; i <= 3; i++) {
assertThat(underTest.getComponentByRef(i).getReportAttributes().getRef()).isEqualTo(i);
}
}
public void getOptionalComponentByRef_returns_any_report_component_in_the_tree() {
underTest.setRoots(SOME_REPORT_COMPONENT_TREE, DUMB_PROJECT);
- for (int i = 1; i <= 4; i++) {
+ for (int i = 1; i <= 3; i++) {
assertThat(underTest.getOptionalComponentByRef(i).get().getReportAttributes().getRef()).isEqualTo(i);
}
}
@Test
public void getSize_counts_number_of_components() {
underTest.setRoots(SOME_REPORT_COMPONENT_TREE, DUMB_PROJECT);
- assertThat(underTest.getSize()).isEqualTo(4);
+ assertThat(underTest.getSize()).isEqualTo(3);
}
private void expectNotInitialized_ISE() {
import static org.sonar.api.measures.CoreMetrics.DUPLICATED_LINES_KEY;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.DIRECTORY;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.FILE;
-import static org.sonar.ce.task.projectanalysis.component.Component.Type.MODULE;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT;
import static org.sonar.ce.task.projectanalysis.component.ReportComponent.builder;
import static org.sonar.ce.task.projectanalysis.measure.Measure.newMeasureBuilder;
public class DuplicationMeasuresTest {
private static final int ROOT_REF = 1;
- private static final int MODULE_REF = 12;
- private static final int SUB_MODULE_1_REF = 123;
- private static final int SUB_MODULE_2_REF = 126;
private static final int DIRECTORY_REF = 1234;
private static final int FILE_1_REF = 12341;
private static final int FILE_2_REF = 12342;
.setRoot(
builder(PROJECT, ROOT_REF)
.addChildren(
- builder(MODULE, MODULE_REF)
+ builder(DIRECTORY, DIRECTORY_REF)
.addChildren(
- builder(MODULE, SUB_MODULE_1_REF)
- .addChildren(
- builder(DIRECTORY, DIRECTORY_REF)
- .addChildren(
- builder(FILE, FILE_1_REF).setFileAttributes(FILE_1_ATTRS).build(),
- builder(FILE, FILE_2_REF).setFileAttributes(FILE_2_ATTRS).build())
- .build())
- .build(),
- builder(MODULE, SUB_MODULE_2_REF)
- .addChildren(
- builder(FILE, FILE_3_REF).setFileAttributes(FILE_3_ATTRS).build(),
- builder(FILE, FILE_4_REF).setFileAttributes(FILE_4_ATTRS).build())
- .build())
- .build())
+ builder(FILE, FILE_1_REF).setFileAttributes(FILE_1_ATTRS).build(),
+ builder(FILE, FILE_2_REF).setFileAttributes(FILE_2_ATTRS).build())
+ .build(),
+ builder(FILE, FILE_3_REF).setFileAttributes(FILE_3_ATTRS).build(),
+ builder(FILE, FILE_4_REF).setFileAttributes(FILE_4_ATTRS).build())
.build());
@Rule
public MetricRepositoryRule metricRepository = new MetricRepositoryRule()
assertRawMeasureValue(FILE_3_REF, DUPLICATED_BLOCKS_KEY, 0);
assertRawMeasureValue(FILE_4_REF, DUPLICATED_BLOCKS_KEY, 5);
assertRawMeasureValue(DIRECTORY_REF, DUPLICATED_BLOCKS_KEY, 50);
- assertRawMeasureValue(SUB_MODULE_1_REF, DUPLICATED_BLOCKS_KEY, 50);
- assertRawMeasureValue(SUB_MODULE_2_REF, DUPLICATED_BLOCKS_KEY, 5);
- assertRawMeasureValue(MODULE_REF, DUPLICATED_BLOCKS_KEY, 55);
assertRawMeasureValue(ROOT_REF, DUPLICATED_BLOCKS_KEY, 55);
}
assertRawMeasureValue(FILE_3_REF, DUPLICATED_FILES_KEY, 1);
assertRawMeasureValue(FILE_4_REF, DUPLICATED_FILES_KEY, 1);
assertRawMeasureValue(DIRECTORY_REF, DUPLICATED_FILES_KEY, 1);
- assertRawMeasureValue(SUB_MODULE_1_REF, DUPLICATED_FILES_KEY, 1);
- assertRawMeasureValue(SUB_MODULE_2_REF, DUPLICATED_FILES_KEY, 2);
- assertRawMeasureValue(MODULE_REF, DUPLICATED_FILES_KEY, 3);
assertRawMeasureValue(ROOT_REF, DUPLICATED_FILES_KEY, 3);
}
assertRawMeasureValue(FILE_3_REF, DUPLICATED_LINES_KEY, 0);
assertRawMeasureValue(FILE_4_REF, DUPLICATED_LINES_KEY, 7);
assertRawMeasureValue(DIRECTORY_REF, DUPLICATED_LINES_KEY, 19);
- assertRawMeasureValue(SUB_MODULE_1_REF, DUPLICATED_LINES_KEY, 19);
- assertRawMeasureValue(SUB_MODULE_2_REF, DUPLICATED_LINES_KEY, 7);
- assertRawMeasureValue(MODULE_REF, DUPLICATED_LINES_KEY, 26);
assertRawMeasureValue(ROOT_REF, DUPLICATED_LINES_KEY, 26);
}
assertNoRawMeasure(FILE_3_REF, DUPLICATED_LINES_DENSITY_KEY);
assertNoRawMeasure(FILE_4_REF, DUPLICATED_LINES_DENSITY_KEY);
assertRawMeasureValue(DIRECTORY_REF, DUPLICATED_LINES_DENSITY_KEY, 10d);
- assertRawMeasureValue(SUB_MODULE_1_REF, DUPLICATED_LINES_DENSITY_KEY, 10d);
- assertNoRawMeasure(SUB_MODULE_2_REF, DUPLICATED_LINES_DENSITY_KEY);
- assertRawMeasureValue(MODULE_REF, DUPLICATED_LINES_DENSITY_KEY, 10d);
assertRawMeasureValue(ROOT_REF, DUPLICATED_LINES_DENSITY_KEY, 10d);
}
assertNoRawMeasure(FILE_3_REF, DUPLICATED_LINES_DENSITY_KEY);
assertNoRawMeasure(FILE_4_REF, DUPLICATED_LINES_DENSITY_KEY);
assertRawMeasureValue(DIRECTORY_REF, DUPLICATED_LINES_DENSITY_KEY, 0d);
- assertRawMeasureValue(SUB_MODULE_1_REF, DUPLICATED_LINES_DENSITY_KEY, 0d);
- assertNoRawMeasure(SUB_MODULE_2_REF, DUPLICATED_LINES_DENSITY_KEY);
- assertRawMeasureValue(MODULE_REF, DUPLICATED_LINES_DENSITY_KEY, 0d);
assertRawMeasureValue(ROOT_REF, DUPLICATED_LINES_DENSITY_KEY, 0d);
}
assertNoRawMeasure(FILE_3_REF, DUPLICATED_LINES_DENSITY_KEY);
assertNoRawMeasure(FILE_4_REF, DUPLICATED_LINES_DENSITY_KEY);
assertRawMeasureValue(DIRECTORY_REF, DUPLICATED_LINES_DENSITY_KEY, 100d);
- assertRawMeasureValue(SUB_MODULE_1_REF, DUPLICATED_LINES_DENSITY_KEY, 100d);
- assertNoRawMeasure(SUB_MODULE_2_REF, DUPLICATED_LINES_DENSITY_KEY);
- assertRawMeasureValue(MODULE_REF, DUPLICATED_LINES_DENSITY_KEY, 100d);
assertRawMeasureValue(ROOT_REF, DUPLICATED_LINES_DENSITY_KEY, 100d);
}
assertThat(measureRepository.getAddedRawMeasures(FILE_1_REF).get(metricKey)).isEmpty();
assertThat(measureRepository.getAddedRawMeasures(FILE_2_REF).get(metricKey)).isEmpty();
assertThat(measureRepository.getAddedRawMeasures(DIRECTORY_REF).get(metricKey)).isEmpty();
- assertThat(measureRepository.getAddedRawMeasures(SUB_MODULE_1_REF).get(metricKey)).isEmpty();
- assertThat(measureRepository.getAddedRawMeasures(MODULE_REF).get(metricKey)).isEmpty();
assertThat(measureRepository.getAddedRawMeasures(ROOT_REF).get(metricKey)).isEmpty();
}
assertRawMeasureValue(FILE_3_REF, metricKey, 0);
assertRawMeasureValue(FILE_4_REF, metricKey, 0);
assertRawMeasureValue(DIRECTORY_REF, metricKey, 0);
- assertRawMeasureValue(SUB_MODULE_1_REF, metricKey, 0);
- assertRawMeasureValue(SUB_MODULE_2_REF, metricKey, 0);
- assertRawMeasureValue(MODULE_REF, metricKey, 0);
assertRawMeasureValue(ROOT_REF, metricKey, 0);
}
public class MutableMovedFilesRepositoryImplTest {
private static final Component SOME_FILE = builder(Component.Type.FILE, 1).build();
- private static final Component[] COMPONENTS_BUT_FILE = {
+ private static final Component[] COMPONENTS_EXCEPT_FILE = {
builder(Component.Type.PROJECT, 1).build(),
- builder(Component.Type.MODULE, 1).build(),
builder(Component.Type.DIRECTORY, 1).build(),
ViewsComponent.builder(Component.Type.VIEW, 1).build(),
ViewsComponent.builder(Component.Type.SUBVIEW, 1).build(),
@Test
public void setOriginalFile_throws_IAE_when_type_is_no_FILE() {
- for (Component component : COMPONENTS_BUT_FILE) {
+ for (Component component : COMPONENTS_EXCEPT_FILE) {
try {
underTest.setOriginalFile(component, SOME_ORIGINAL_FILE);
fail("should have raised a NPE");
@Test
public void getOriginalFile_returns_absent_for_any_component_type_when_empty() {
assertThat(underTest.getOriginalFile(SOME_FILE)).isAbsent();
- for (Component component : COMPONENTS_BUT_FILE) {
+ for (Component component : COMPONENTS_EXCEPT_FILE) {
assertThat(underTest.getOriginalFile(component)).isAbsent();
}
}
public void getOriginalFile_returns_absent_for_any_type_of_Component_but_file_when_non_empty() {
underTest.setOriginalFile(SOME_FILE, SOME_ORIGINAL_FILE);
- for (Component component : COMPONENTS_BUT_FILE) {
+ for (Component component : COMPONENTS_EXCEPT_FILE) {
assertThat(underTest.getOriginalFile(component)).isAbsent();
}
assertThat(underTest.getOriginalFile(SOME_FILE)).contains(SOME_ORIGINAL_FILE);
import static org.sonar.api.measures.CoreMetrics.FUNCTIONS_KEY;
import static org.sonar.api.measures.CoreMetrics.FUNCTION_COMPLEXITY_KEY;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.DIRECTORY;
-import static org.sonar.ce.task.projectanalysis.component.Component.Type.MODULE;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT;
import static org.sonar.ce.task.projectanalysis.component.ReportComponent.builder;
import static org.sonar.ce.task.projectanalysis.measure.Measure.newMeasureBuilder;
public void add_measures() {
ReportComponent project = builder(PROJECT, 1)
.addChildren(
- builder(MODULE, 11)
+ builder(DIRECTORY, 111)
.addChildren(
- builder(DIRECTORY, 111)
- .addChildren(
- builder(Component.Type.FILE, 1111).build(),
- builder(Component.Type.FILE, 1112).build())
- .build())
+ builder(Component.Type.FILE, 1111).build(),
+ builder(Component.Type.FILE, 1112).build())
.build(),
- builder(MODULE, 12)
+ builder(DIRECTORY, 121)
.addChildren(
- builder(DIRECTORY, 121)
- .addChildren(
- builder(Component.Type.FILE, 1211).build())
- .build())
+ builder(Component.Type.FILE, 1211).build())
.build())
.build();
new PathAwareCrawler<>(underTest).visit(project);
assertThat(toEntries(measureRepository.getAddedRawMeasures(1))).containsOnly(entryOf(FUNCTION_COMPLEXITY_KEY, newMeasureBuilder().create(3d, 1)));
- assertThat(toEntries(measureRepository.getAddedRawMeasures(11))).containsOnly(entryOf(FUNCTION_COMPLEXITY_KEY, newMeasureBuilder().create(2d, 1)));
assertThat(toEntries(measureRepository.getAddedRawMeasures(111))).containsOnly(entryOf(FUNCTION_COMPLEXITY_KEY, newMeasureBuilder().create(2d, 1)));
assertThat(toEntries(measureRepository.getAddedRawMeasures(1111))).containsOnly(entryOf(FUNCTION_COMPLEXITY_KEY, newMeasureBuilder().create(2.5d, 1)));
assertThat(toEntries(measureRepository.getAddedRawMeasures(1112))).containsOnly(entryOf(FUNCTION_COMPLEXITY_KEY, newMeasureBuilder().create(1d, 1)));
- assertThat(toEntries(measureRepository.getAddedRawMeasures(12))).containsOnly(entryOf(FUNCTION_COMPLEXITY_KEY, newMeasureBuilder().create(4.5d, 1)));
assertThat(toEntries(measureRepository.getAddedRawMeasures(121))).containsOnly(entryOf(FUNCTION_COMPLEXITY_KEY, newMeasureBuilder().create(4.5d, 1)));
assertThat(toEntries(measureRepository.getAddedRawMeasures(1211))).containsOnly(entryOf(FUNCTION_COMPLEXITY_KEY, newMeasureBuilder().create(4.5d, 1)));
}
public void not_add_measures_when_no_data_on_file() {
ReportComponent project = builder(PROJECT, 1)
.addChildren(
- builder(MODULE, 11)
+ builder(DIRECTORY, 111)
.addChildren(
- builder(DIRECTORY, 111)
- .addChildren(
- builder(Component.Type.FILE, 1111).build())
- .build())
+ builder(Component.Type.FILE, 1111).build())
.build())
.build();
new PathAwareCrawler<>(underTest).visit(project);
assertThat(measureRepository.getAddedRawMeasures(1)).isEmpty();
- assertThat(measureRepository.getAddedRawMeasures(11)).isEmpty();
assertThat(measureRepository.getAddedRawMeasures(111)).isEmpty();
assertThat(measureRepository.getAddedRawMeasures(1111)).isEmpty();
}
import static org.assertj.guava.api.Assertions.assertThat;
import static org.sonar.api.measures.CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION_KEY;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.DIRECTORY;
-import static org.sonar.ce.task.projectanalysis.component.Component.Type.MODULE;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT;
import static org.sonar.ce.task.projectanalysis.component.ReportComponent.builder;
import static org.sonar.ce.task.projectanalysis.measure.Measure.newMeasureBuilder;
public void add_measures() {
ReportComponent project = builder(PROJECT, 1)
.addChildren(
- builder(MODULE, 11)
+ builder(DIRECTORY, 11)
.addChildren(
builder(DIRECTORY, 111)
.addChildren(
builder(Component.Type.FILE, 1112).build())
.build())
.build(),
- builder(MODULE, 12)
+ builder(DIRECTORY, 12)
.addChildren(
builder(DIRECTORY, 121)
.addChildren(
public void not_add_measures_when_no_data_on_file() {
ReportComponent project = builder(PROJECT, 1)
.addChildren(
- builder(MODULE, 11)
+ builder(DIRECTORY, 11)
.addChildren(
builder(DIRECTORY, 111)
.addChildren(
import static org.sonar.api.measures.CoreMetrics.NEW_COVERAGE_KEY;
import static org.sonar.api.measures.CoreMetrics.NEW_LINES_TO_COVER_KEY;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.DIRECTORY;
-import static org.sonar.ce.task.projectanalysis.component.Component.Type.MODULE;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT;
import static org.sonar.ce.task.projectanalysis.component.ReportComponent.builder;
import static org.sonar.ce.task.projectanalysis.measure.Measure.newMeasureBuilder;
public class ReportFormulaExecutorComponentVisitorTest {
private static final int ROOT_REF = 1;
- private static final int MODULE_1_REF = 11;
private static final int DIRECTORY_1_REF = 111;
private static final int FILE_1_REF = 1111;
private static final int FILE_2_REF = 1112;
- private static final int MODULE_2_REF = 12;
private static final int DIRECTORY_2_REF = 121;
private static final int FILE_3_REF = 1211;
private static final ReportComponent BALANCED_COMPONENT_TREE = ReportComponent.builder(PROJECT, ROOT_REF)
.addChildren(
- ReportComponent.builder(MODULE, MODULE_1_REF)
+ ReportComponent.builder(DIRECTORY, DIRECTORY_1_REF)
.addChildren(
- ReportComponent.builder(DIRECTORY, DIRECTORY_1_REF)
- .addChildren(
- builder(Component.Type.FILE, FILE_1_REF).build(),
- builder(Component.Type.FILE, FILE_2_REF).build())
- .build())
+ builder(Component.Type.FILE, FILE_1_REF).build(),
+ builder(Component.Type.FILE, FILE_2_REF).build())
.build(),
- ReportComponent.builder(MODULE, MODULE_2_REF)
+ ReportComponent.builder(DIRECTORY, DIRECTORY_2_REF)
.addChildren(
- ReportComponent.builder(DIRECTORY, DIRECTORY_2_REF)
- .addChildren(
- builder(Component.Type.FILE, FILE_3_REF).build())
- .build())
+ builder(Component.Type.FILE, FILE_3_REF).build())
.build())
.build();
.visit(BALANCED_COMPONENT_TREE);
assertAddedRawMeasure(ROOT_REF, 20);
- assertAddedRawMeasure(MODULE_1_REF, 18);
assertAddedRawMeasure(111, 18);
assertAddedRawMeasure(FILE_1_REF, 10);
assertAddedRawMeasure(FILE_2_REF, 8);
- assertAddedRawMeasure(MODULE_2_REF, 2);
assertAddedRawMeasure(DIRECTORY_2_REF, 2);
assertAddedRawMeasure(FILE_3_REF, 2);
}
assertThat(toEntries(measureRepository.getAddedRawMeasures(ROOT_REF))).containsOnly(
entryOf(NEW_LINES_TO_COVER_KEY, newMeasureBuilder().create(30)),
entryOf(NEW_COVERAGE_KEY, newMeasureBuilder().create(120)));
- assertThat(toEntries(measureRepository.getAddedRawMeasures(MODULE_1_REF))).containsOnly(
- entryOf(NEW_LINES_TO_COVER_KEY, newMeasureBuilder().create(28)),
- entryOf(NEW_COVERAGE_KEY, newMeasureBuilder().create(118)));
assertThat(toEntries(measureRepository.getAddedRawMeasures(111))).containsOnly(
entryOf(NEW_LINES_TO_COVER_KEY, newMeasureBuilder().create(28)),
entryOf(NEW_COVERAGE_KEY, newMeasureBuilder().create(118)));
assertThat(toEntries(measureRepository.getAddedRawMeasures(FILE_2_REF))).containsOnly(
entryOf(NEW_LINES_TO_COVER_KEY, newMeasureBuilder().create(18)),
entryOf(NEW_COVERAGE_KEY, newMeasureBuilder().create(108)));
- assertThat(toEntries(measureRepository.getAddedRawMeasures(MODULE_2_REF))).containsOnly(
- entryOf(NEW_LINES_TO_COVER_KEY, newMeasureBuilder().create(MODULE_2_REF)),
- entryOf(NEW_COVERAGE_KEY, newMeasureBuilder().create(102)));
assertThat(toEntries(measureRepository.getAddedRawMeasures(DIRECTORY_2_REF))).containsOnly(
- entryOf(NEW_LINES_TO_COVER_KEY, newMeasureBuilder().create(MODULE_2_REF)),
+ entryOf(NEW_LINES_TO_COVER_KEY, newMeasureBuilder().create(12)),
entryOf(NEW_COVERAGE_KEY, newMeasureBuilder().create(102)));
assertThat(toEntries(measureRepository.getAddedRawMeasures(FILE_3_REF))).containsOnly(
- entryOf(NEW_LINES_TO_COVER_KEY, newMeasureBuilder().create(MODULE_2_REF)),
+ entryOf(NEW_LINES_TO_COVER_KEY, newMeasureBuilder().create(12)),
entryOf(NEW_COVERAGE_KEY, newMeasureBuilder().create(102)));
}
.visit(BALANCED_COMPONENT_TREE);
assertAddedRawMeasureVariation(ROOT_REF, 20);
- assertAddedRawMeasureVariation(MODULE_1_REF, 18);
assertAddedRawMeasureVariation(DIRECTORY_1_REF, 18);
assertAddedRawMeasureVariation(FILE_1_REF, 10);
assertAddedRawMeasureVariation(FILE_2_REF, 8);
- assertAddedRawMeasureVariation(MODULE_2_REF, 2);
assertAddedRawMeasureVariation(DIRECTORY_2_REF, 2);
assertAddedRawMeasureVariation(FILE_3_REF, 2);
}
public void measures_are_0_when_there_is_no_input_measure() {
ReportComponent project = ReportComponent.builder(PROJECT, ROOT_REF)
.addChildren(
- ReportComponent.builder(MODULE, MODULE_1_REF)
+ ReportComponent.builder(DIRECTORY, DIRECTORY_1_REF)
.addChildren(
- ReportComponent.builder(DIRECTORY, DIRECTORY_1_REF)
- .addChildren(
- builder(Component.Type.FILE, FILE_1_REF).build())
- .build())
+ builder(Component.Type.FILE, FILE_1_REF).build())
.build())
.build();
treeRootHolder.setRoot(project);
.visit(project);
assertAddedRawMeasure(ROOT_REF, 0);
- assertAddedRawMeasure(MODULE_1_REF, 0);
assertAddedRawMeasure(DIRECTORY_1_REF, 0);
assertAddedRawMeasure(FILE_1_REF, 0);
}
public void add_measure_even_when_leaf_is_not_FILE() {
ReportComponent project = ReportComponent.builder(PROJECT, ROOT_REF)
.addChildren(
- ReportComponent.builder(MODULE, MODULE_1_REF)
- .addChildren(
- ReportComponent.builder(DIRECTORY, 111).build())
- .build())
+ ReportComponent.builder(DIRECTORY, 111).build())
.build();
treeRootHolder.setRoot(project);
new PathAwareCrawler<>(formulaExecutorComponentVisitor(new FakeFormula()))
.visit(project);
- assertAddedRawMeasure(MODULE_1_REF, 0);
assertAddedRawMeasure(DIRECTORY_1_REF, 0);
}
.visit(root);
}
- @Test
- public void fail_on_project_containing_module_without_children_already_having_computed_measure() {
- ReportComponent root = builder(PROJECT, ROOT_REF)
- .addChildren(
- ReportComponent.builder(MODULE, MODULE_1_REF).build(),
- builder(Component.Type.FILE, FILE_1_REF).build())
- .build();
- treeRootHolder.setRoot(root);
- measureRepository.addRawMeasure(FILE_1_REF, LINES_KEY, newMeasureBuilder().create(10));
- // Ncloc is already computed on module
- measureRepository.addRawMeasure(MODULE_1_REF, NCLOC_KEY, newMeasureBuilder().create(3));
-
- expectedException.expectCause(hasType(UnsupportedOperationException.class)
- .andMessage(String.format("A measure can only be set once for Component (ref=%s), Metric (key=%s)", MODULE_1_REF, NCLOC_KEY)));
-
- new PathAwareCrawler<>(formulaExecutorComponentVisitor(new FakeFormula()))
- .visit(root);
- }
-
private FormulaExecutorComponentVisitor formulaExecutorComponentVisitor(Formula formula) {
return FormulaExecutorComponentVisitor.newBuilder(metricRepository, measureRepository)
.buildFor(ImmutableList.of(formula));
import static org.assertj.guava.api.Assertions.assertThat;
import static org.sonar.api.measures.CoreMetrics.LINES_KEY;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.DIRECTORY;
-import static org.sonar.ce.task.projectanalysis.component.Component.Type.MODULE;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT;
import static org.sonar.ce.task.projectanalysis.component.ReportComponent.builder;
import static org.sonar.ce.task.projectanalysis.formula.SumFormula.createIntSumFormula;
public void add_measures() {
ReportComponent project = builder(PROJECT, 1)
.addChildren(
- builder(MODULE, 11)
+ builder(DIRECTORY, 111)
.addChildren(
- builder(DIRECTORY, 111)
- .addChildren(
- builder(Component.Type.FILE, 1111).build(),
- builder(Component.Type.FILE, 1112).build())
- .build())
+ builder(Component.Type.FILE, 1111).build(),
+ builder(Component.Type.FILE, 1112).build())
.build(),
- builder(MODULE, 12)
+ builder(DIRECTORY, 121)
.addChildren(
- builder(DIRECTORY, 121)
- .addChildren(
- builder(Component.Type.FILE, 1211).build())
- .build())
+ builder(Component.Type.FILE, 1211).build())
.build())
.build();
new PathAwareCrawler<>(underTest).visit(project);
assertThat(toEntries(measureRepository.getAddedRawMeasures(1))).containsOnly(entryOf(LINES_KEY, newMeasureBuilder().create(20)));
- assertThat(toEntries(measureRepository.getAddedRawMeasures(11))).containsOnly(entryOf(LINES_KEY, newMeasureBuilder().create(18)));
assertThat(toEntries(measureRepository.getAddedRawMeasures(111))).containsOnly(entryOf(LINES_KEY, newMeasureBuilder().create(18)));
assertThat(measureRepository.getAddedRawMeasures(1111)).isEmpty();
assertThat(measureRepository.getAddedRawMeasures(1112)).isEmpty();
- assertThat(toEntries(measureRepository.getAddedRawMeasures(12))).containsOnly(entryOf(LINES_KEY, newMeasureBuilder().create(2)));
assertThat(toEntries(measureRepository.getAddedRawMeasures(121))).containsOnly(entryOf(LINES_KEY, newMeasureBuilder().create(2)));
assertThat(measureRepository.getAddedRawMeasures(1211)).isEmpty();
}
public void not_add_measures_when_no_data_on_file() {
ReportComponent project = builder(PROJECT, 1)
.addChildren(
- builder(MODULE, 11)
+ builder(DIRECTORY, 111)
.addChildren(
- builder(DIRECTORY, 111)
- .addChildren(
- builder(Component.Type.FILE, 1111).build())
- .build())
+ builder(Component.Type.FILE, 1111).build())
.build())
.build();
new PathAwareCrawler<>(underTest).visit(project);
assertThat(measureRepository.getAddedRawMeasures(1)).isEmpty();
- assertThat(measureRepository.getAddedRawMeasures(11)).isEmpty();
assertThat(measureRepository.getAddedRawMeasures(111)).isEmpty();
assertThat(measureRepository.getAddedRawMeasures(1111)).isEmpty();
}
import static org.mockito.Mockito.when;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.DIRECTORY;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.FILE;
-import static org.sonar.ce.task.projectanalysis.component.Component.Type.MODULE;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT;
public class CloseIssuesOnRemovedComponentsVisitorTest {
assertThat(issues.hasNext()).isFalse();
}
- @Test
- public void do_nothing_on_module() {
- underTest.visit(ReportComponent.builder(MODULE, 1).build());
-
- verifyZeroInteractions(issueLifecycle);
- CloseableIterator<DefaultIssue> issues = issueCache.traverse();
- assertThat(issues.hasNext()).isFalse();
- }
-
@Test
public void do_nothing_on_directory() {
underTest.visit(ReportComponent.builder(DIRECTORY, 1).build());
private ShortBranchIssueMerger issueStatusCopier = mock(ShortBranchIssueMerger.class);
private MergeBranchComponentUuids mergeBranchComponentUuids = mock(MergeBranchComponentUuids.class);
private SourceLinesHashRepository sourceLinesHash = mock(SourceLinesHashRepository.class);
+ private IssueRelocationToRoot issueRelocationToRoot = mock(IssueRelocationToRoot.class);
private ArgumentCaptor<DefaultIssue> defaultIssueCaptor;
when(movedFilesRepository.getOriginalFile(any(Component.class))).thenReturn(Optional.absent());
DbClient dbClient = dbTester.getDbClient();
- TrackerRawInputFactory rawInputFactory = new TrackerRawInputFactory(treeRootHolder, reportReader, sourceLinesHash, new CommonRuleEngineImpl(), issueFilter, ruleRepositoryRule,
- activeRulesHolder);
+ TrackerRawInputFactory rawInputFactory = new TrackerRawInputFactory(treeRootHolder, reportReader, sourceLinesHash, new CommonRuleEngineImpl(),
+ issueFilter, ruleRepositoryRule, activeRulesHolder, issueRelocationToRoot);
TrackerBaseInputFactory baseInputFactory = new TrackerBaseInputFactory(issuesLoader, dbClient, movedFilesRepository);
TrackerMergeBranchInputFactory mergeInputFactory = new TrackerMergeBranchInputFactory(issuesLoader, mergeBranchComponentsUuids, dbClient);
ClosedIssuesInputFactory closedIssuesInputFactory = new ClosedIssuesInputFactory(issuesLoader, dbClient, movedFilesRepository);
import static org.mockito.Mockito.when;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.DIRECTORY;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.FILE;
-import static org.sonar.ce.task.projectanalysis.component.Component.Type.MODULE;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT;
public class LoadComponentUuidsHavingOpenIssuesVisitorTest {
public void do_nothing_on_not_project_level() {
when(baseIssuesLoader.loadUuidsOfComponentsWithOpenIssues()).thenReturn(newHashSet("FILE1", "FILE2"));
- underTest.visit(ReportComponent.builder(MODULE, 1).build());
underTest.visit(ReportComponent.builder(DIRECTORY, 1).build());
underTest.visit(ReportComponent.builder(FILE, 1).build());
private SourceLinesHashRepository sourceLinesHash = mock(SourceLinesHashRepository.class);
private CommonRuleEngine commonRuleEngine = mock(CommonRuleEngine.class);
private IssueFilter issueFilter = mock(IssueFilter.class);
+ private IssueRelocationToRoot issueRelocationToRoot = mock(IssueRelocationToRoot.class);
private TrackerRawInputFactory underTest = new TrackerRawInputFactory(treeRootHolder, reportReader, sourceLinesHash,
- commonRuleEngine, issueFilter, ruleRepository, activeRulesHolder);
+ commonRuleEngine, issueFilter, ruleRepository, activeRulesHolder, issueRelocationToRoot);
@Test
public void load_source_hash_sequences() {
public class BestValueOptimizationTest {
private static final ReportComponent FILE_COMPONENT = ReportComponent.builder(Component.Type.FILE, 1).build();
- private static final ReportComponent SOME_NON_FILE_COMPONENT = ReportComponent.builder(Component.Type.MODULE, 2).build();
+ private static final ReportComponent SOME_NON_FILE_COMPONENT = ReportComponent.builder(Component.Type.DIRECTORY, 2).build();
private static final String SOME_DATA = "some_data";
private static final MetricImpl METRIC_BOOLEAN_FALSE = createMetric(Metric.MetricType.BOOL, 6d);
private static final MetricImpl METRIC_BOOLEAN_TRUE = createMetric(Metric.MetricType.BOOL, 1d);
*/
package org.sonar.ce.task.projectanalysis.measure;
-import com.google.common.base.Function;
-import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList;
import com.tngtech.java.junit.dataprovider.DataProvider;
import com.tngtech.java.junit.dataprovider.DataProviderRunner;
import java.util.List;
import java.util.Optional;
import java.util.Set;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.db.DbTester;
import org.sonar.db.rule.RuleDto;
-import static com.google.common.collect.FluentIterable.from;
import static java.lang.String.format;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
public ExpectedException expectedException = ExpectedException.none();
private static final String FILE_COMPONENT_KEY = "file cpt key";
- private static final ReportComponent FILE_COMPONENT = ReportComponent.builder(Component.Type.FILE, 1).setKey(FILE_COMPONENT_KEY).build();
- private static final ReportComponent OTHER_COMPONENT = ReportComponent.builder(Component.Type.FILE, 2).setKey("some other key").build();
+ private static final ReportComponent FILE_COMPONENT = ReportComponent.builder(Component.Type.FILE, 1)
+ .setKey(FILE_COMPONENT_KEY)
+ .setUuid("1")
+ .build();
+ private static final ReportComponent OTHER_COMPONENT = ReportComponent.builder(Component.Type.FILE, 2)
+ .setKey("some other key")
+ .setUuid("2")
+ .build();
private static final String METRIC_KEY_1 = "metric 1";
private static final String METRIC_KEY_2 = "metric 2";
private ReportMetricValidator reportMetricValidator = mock(ReportMetricValidator.class);
private MetricRepository metricRepository = mock(MetricRepository.class);
- private MapBasedRawMeasureRepository<Integer> underTest = new MapBasedRawMeasureRepository<>(new Function<Component, Integer>() {
- @Override
- public Integer apply(Component component) {
- return component.getReportAttributes().getRef();
- }
- });
-
+ private MapBasedRawMeasureRepository<Integer> underTest = new MapBasedRawMeasureRepository<>(component -> component.getReportAttributes().getRef());
private DbClient mockedDbClient = mock(DbClient.class);
private BatchReportReader mockBatchReportReader = mock(BatchReportReader.class);
private MeasureRepositoryImpl underTestWithMock = new MeasureRepositoryImpl(mockedDbClient, mockBatchReportReader, metricRepository, reportMetricValidator);
@DataProvider
public static Object[][] measures() {
- return from(MEASURES).transform(new Function<Measure, Object[]>() {
- @Nullable
- @Override
- public Object[] apply(Measure input) {
- return new Measure[] {input};
- }
- }).toArray(Object[].class);
+ return MEASURES.stream()
+ .map(c -> new Measure[] {c})
+ .toArray(i -> new Object[i][]);
}
@Test
}
private Measure getSomeMeasureByValueType(final Metric.MetricType metricType) {
- return from(MEASURES).filter(new Predicate<Measure>() {
- @Override
- public boolean apply(@Nonnull Measure input) {
- return input.getValueType() == metricType.getValueType();
- }
- }).first().get();
+ return MEASURES.stream()
+ .filter(measure -> measure.getValueType() == metricType.getValueType())
+ .findFirst().get();
}
@Test
import static org.sonar.api.measures.CoreMetrics.NCLOC_KEY;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.DIRECTORY;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.FILE;
-import static org.sonar.ce.task.projectanalysis.component.Component.Type.MODULE;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT;
import static org.sonar.ce.task.projectanalysis.component.ReportComponent.builder;
import static org.sonar.ce.task.projectanalysis.measure.Measure.newMeasureBuilder;
private static final org.sonar.api.measures.Metric<Integer> NEW_METRIC = new org.sonar.api.measures.Metric.Builder(NEW_METRIC_KEY, NEW_METRIC_NAME,
org.sonar.api.measures.Metric.ValueType.INT)
- .create();
+ .create();
private static final int ROOT_REF = 1;
- private static final int MODULE_REF = 12;
private static final int DIRECTORY_REF = 123;
private static final int FILE_1_REF = 1231;
private static final int FILE_2_REF = 1232;
private static final Component ROOT = builder(PROJECT, ROOT_REF).setKey("project")
.addChildren(
- builder(MODULE, MODULE_REF).setKey("module")
+ builder(DIRECTORY, DIRECTORY_REF).setKey("directory")
.addChildren(
- builder(DIRECTORY, DIRECTORY_REF).setKey("directory")
- .addChildren(
- builder(FILE, FILE_1_REF).setKey("file1").build(),
- builder(FILE, FILE_2_REF).setKey("file2").build())
- .build())
+ builder(FILE, FILE_1_REF).setKey("file1").build(),
+ builder(FILE, FILE_2_REF).setKey("file2").build())
.build())
.build();
addRawMeasure(FILE_2_REF, COMMENT_LINES_KEY, 5);
addRawMeasure(DIRECTORY_REF, NCLOC_KEY, 50);
addRawMeasure(DIRECTORY_REF, COMMENT_LINES_KEY, 7);
- addRawMeasure(MODULE_REF, NCLOC_KEY, 50);
- addRawMeasure(MODULE_REF, COMMENT_LINES_KEY, 7);
addRawMeasure(ROOT_REF, NCLOC_KEY, 50);
addRawMeasure(ROOT_REF, COMMENT_LINES_KEY, 7);
assertAddedRawMeasure(12, FILE_1_REF, NEW_METRIC_KEY);
assertAddedRawMeasure(45, FILE_2_REF, NEW_METRIC_KEY);
assertAddedRawMeasure(57, DIRECTORY_REF, NEW_METRIC_KEY);
- assertAddedRawMeasure(57, MODULE_REF, NEW_METRIC_KEY);
assertAddedRawMeasure(57, ROOT_REF, NEW_METRIC_KEY);
}
addRawMeasure(FILE_2_REF, COMMENT_LINES_KEY, 5);
addRawMeasure(DIRECTORY_REF, NCLOC_KEY, 50);
addRawMeasure(DIRECTORY_REF, COMMENT_LINES_KEY, 7);
- addRawMeasure(MODULE_REF, NCLOC_KEY, 50);
- addRawMeasure(MODULE_REF, COMMENT_LINES_KEY, 7);
addRawMeasure(ROOT_REF, NCLOC_KEY, 50);
addRawMeasure(ROOT_REF, COMMENT_LINES_KEY, 7);
assertNoAddedRawMeasure(FILE_1_REF);
assertNoAddedRawMeasure(FILE_2_REF);
assertNoAddedRawMeasure(DIRECTORY_REF);
- assertNoAddedRawMeasure(MODULE_REF);
assertNoAddedRawMeasure(ROOT_REF);
}
import static org.sonar.api.measures.CoreMetrics.TECHNICAL_DEBT_KEY;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.DIRECTORY;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.FILE;
-import static org.sonar.ce.task.projectanalysis.component.Component.Type.MODULE;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT;
import static org.sonar.ce.task.projectanalysis.component.ReportComponent.builder;
import static org.sonar.ce.task.projectanalysis.measure.Measure.newMeasureBuilder;
static final long DEV_COST_LANGUAGE_2 = 42;
static final int PROJECT_REF = 1;
- static final int MODULE_REF = 12;
static final int DIRECTORY_REF = 123;
static final int FILE_1_REF = 1231;
static final int FILE_2_REF = 1232;
static final Component ROOT_PROJECT = builder(Component.Type.PROJECT, PROJECT_REF).setKey("project")
.addChildren(
- builder(MODULE, MODULE_REF).setKey("module")
+ builder(DIRECTORY, DIRECTORY_REF).setKey("directory")
.addChildren(
- builder(DIRECTORY, DIRECTORY_REF).setKey("directory")
- .addChildren(
- builder(FILE, FILE_1_REF).setFileAttributes(new FileAttributes(false, LANGUAGE_KEY_1, 1)).setKey("file1").build(),
- builder(FILE, FILE_2_REF).setFileAttributes(new FileAttributes(false, LANGUAGE_KEY_1, 1)).setKey("file2").build())
- .build())
+ builder(FILE, FILE_1_REF).setFileAttributes(new FileAttributes(false, LANGUAGE_KEY_1, 1)).setKey("file1").build(),
+ builder(FILE, FILE_2_REF).setFileAttributes(new FileAttributes(false, LANGUAGE_KEY_1, 1)).setKey("file2").build())
.build())
.build();
@Test
public void compute_development_cost() {
- ReportComponent root = builder(PROJECT, 1)
- .addChildren(
- builder(MODULE, 11)
- .addChildren(
- builder(DIRECTORY, 111)
- .addChildren(
- createFileComponent(LANGUAGE_KEY_1, 1111),
- createFileComponent(LANGUAGE_KEY_2, 1112),
- // Unit test should not be ignored
- builder(FILE, 1113).setFileAttributes(new FileAttributes(true, LANGUAGE_KEY_1, 1)).build())
- .build(),
- builder(DIRECTORY, 112)
- .addChildren(
- createFileComponent(LANGUAGE_KEY_2, 1121))
- .build())
- .build(),
- builder(MODULE, 12)
- .addChildren(
- builder(DIRECTORY, 121)
- .addChildren(
- createFileComponent(LANGUAGE_KEY_1, 1211))
- .build(),
- builder(DIRECTORY, 122).build())
- .build(),
- builder(MODULE, 13).build())
+ ReportComponent root = builder(PROJECT, 1).addChildren(
+ builder(DIRECTORY, 111).addChildren(
+ createFileComponent(LANGUAGE_KEY_1, 1111),
+ createFileComponent(LANGUAGE_KEY_2, 1112),
+ // Unit test should not be ignored
+ builder(FILE, 1113).setFileAttributes(new FileAttributes(true, LANGUAGE_KEY_1, 1)).build())
+ .build(),
+ builder(DIRECTORY, 112).addChildren(
+ createFileComponent(LANGUAGE_KEY_2, 1121))
+ .build(),
+ builder(DIRECTORY, 121).addChildren(
+ createFileComponent(LANGUAGE_KEY_1, 1211))
+ .build(),
+ builder(DIRECTORY, 122).build())
.build();
treeRootHolder.setRoot(root);
- int ncloc1111 = 10;
- addRawMeasure(NCLOC_KEY, 1111, ncloc1111);
-
int ncloc1112 = 12;
addRawMeasure(NCLOC_KEY, 1112, ncloc1112);
underTest.visit(root);
// verify measures on files
- verifyAddedRawMeasure(1111, DEVELOPMENT_COST_KEY, Long.toString(ncloc1111 * DEV_COST_LANGUAGE_1));
verifyAddedRawMeasure(1112, DEVELOPMENT_COST_KEY, Long.toString(ncloc1112 * DEV_COST_LANGUAGE_2));
verifyAddedRawMeasure(1113, DEVELOPMENT_COST_KEY, Long.toString(ncloc1113 * DEV_COST_LANGUAGE_1));
verifyAddedRawMeasure(1121, DEVELOPMENT_COST_KEY, Long.toString(nclocValue1121 * DEV_COST_LANGUAGE_2));
// directory has children => dev cost is aggregated
verifyAddedRawMeasure(111, DEVELOPMENT_COST_KEY, Long.toString(
- ncloc1111 * DEV_COST_LANGUAGE_1 +
- ncloc1112 * DEV_COST_LANGUAGE_2 +
+ ncloc1112 * DEV_COST_LANGUAGE_2 +
ncloc1113 * DEV_COST_LANGUAGE_1));
verifyAddedRawMeasure(112, DEVELOPMENT_COST_KEY, Long.toString(nclocValue1121 * DEV_COST_LANGUAGE_2));
verifyAddedRawMeasure(121, DEVELOPMENT_COST_KEY, Long.toString(ncloc1211 * DEV_COST_LANGUAGE_1));
- // just for fun, we didn't define any debt on module => they must all have rating A
- verifyAddedRawMeasure(11, DEVELOPMENT_COST_KEY, Long.toString(
- ncloc1111 * DEV_COST_LANGUAGE_1 +
- ncloc1112 * DEV_COST_LANGUAGE_2 +
- ncloc1113 * DEV_COST_LANGUAGE_1 +
- nclocValue1121 * DEV_COST_LANGUAGE_2));
- verifyAddedRawMeasure(12, DEVELOPMENT_COST_KEY, Long.toString(ncloc1211 * DEV_COST_LANGUAGE_1));
- verifyAddedRawMeasure(13, DEVELOPMENT_COST_KEY, "0");
verifyAddedRawMeasure(1, DEVELOPMENT_COST_KEY, Long.toString(
- ncloc1111 * DEV_COST_LANGUAGE_1 +
- ncloc1112 * DEV_COST_LANGUAGE_2 +
+ ncloc1112 * DEV_COST_LANGUAGE_2 +
ncloc1113 * DEV_COST_LANGUAGE_1 +
nclocValue1121 * DEV_COST_LANGUAGE_2 +
ncloc1211 * DEV_COST_LANGUAGE_1));
long directoryMaintainabilityCost = 100L;
addRawMeasure(TECHNICAL_DEBT_KEY, DIRECTORY_REF, directoryMaintainabilityCost);
- long moduleMaintainabilityCost = 100L;
- addRawMeasure(TECHNICAL_DEBT_KEY, MODULE_REF, moduleMaintainabilityCost);
-
long projectMaintainabilityCost = 1000L;
addRawMeasure(TECHNICAL_DEBT_KEY, PROJECT_REF, projectMaintainabilityCost);
verifyAddedRawMeasure(FILE_1_REF, SQALE_DEBT_RATIO_KEY, file1MaintainabilityCost * 1d / (file1Ncloc * DEV_COST_LANGUAGE_1) * 100);
verifyAddedRawMeasure(FILE_2_REF, SQALE_DEBT_RATIO_KEY, file2MaintainabilityCost * 1d / (file2Ncloc * DEV_COST_LANGUAGE_1) * 100);
verifyAddedRawMeasure(DIRECTORY_REF, SQALE_DEBT_RATIO_KEY, directoryMaintainabilityCost * 1d / ((file1Ncloc + file2Ncloc) * DEV_COST_LANGUAGE_1) * 100);
- verifyAddedRawMeasure(MODULE_REF, SQALE_DEBT_RATIO_KEY, moduleMaintainabilityCost * 1d / ((file1Ncloc + file2Ncloc) * DEV_COST_LANGUAGE_1) * 100);
verifyAddedRawMeasure(PROJECT_REF, SQALE_DEBT_RATIO_KEY, projectMaintainabilityCost * 1d / ((file1Ncloc + file2Ncloc) * DEV_COST_LANGUAGE_1) * 100);
}
addRawMeasure(TECHNICAL_DEBT_KEY, FILE_2_REF, 1L);
addRawMeasure(TECHNICAL_DEBT_KEY, DIRECTORY_REF, 100L);
- addRawMeasure(TECHNICAL_DEBT_KEY, MODULE_REF, 100L);
addRawMeasure(TECHNICAL_DEBT_KEY, PROJECT_REF, 1000L);
underTest.visit(ROOT_PROJECT);
verifyAddedRawMeasure(FILE_1_REF, SQALE_RATING_KEY, C);
verifyAddedRawMeasure(FILE_2_REF, SQALE_RATING_KEY, A);
verifyAddedRawMeasure(DIRECTORY_REF, SQALE_RATING_KEY, C);
- verifyAddedRawMeasure(MODULE_REF, SQALE_RATING_KEY, C);
verifyAddedRawMeasure(PROJECT_REF, SQALE_RATING_KEY, E);
}
long dirEffort = 120L;
addRawMeasure(TECHNICAL_DEBT_KEY, DIRECTORY_REF, dirEffort);
- long moduleEffort = 120L;
- addRawMeasure(TECHNICAL_DEBT_KEY, MODULE_REF, moduleEffort);
-
long projectEffort = 150L;
addRawMeasure(TECHNICAL_DEBT_KEY, PROJECT_REF, projectEffort);
(long) (file2Effort - RATING_GRID[0] * file2Ncloc * DEV_COST_LANGUAGE_1));
verifyAddedRawMeasure(DIRECTORY_REF, EFFORT_TO_REACH_MAINTAINABILITY_RATING_A_KEY,
(long) (dirEffort - RATING_GRID[0] * (file1Ncloc + file2Ncloc) * DEV_COST_LANGUAGE_1));
- verifyAddedRawMeasure(MODULE_REF, EFFORT_TO_REACH_MAINTAINABILITY_RATING_A_KEY,
- (long) (moduleEffort - RATING_GRID[0] * (file1Ncloc + file2Ncloc) * DEV_COST_LANGUAGE_1));
verifyAddedRawMeasure(PROJECT_REF, EFFORT_TO_REACH_MAINTAINABILITY_RATING_A_KEY,
(long) (projectEffort - RATING_GRID[0] * (file1Ncloc + file2Ncloc) * DEV_COST_LANGUAGE_1));
}
import static org.sonar.api.measures.CoreMetrics.NEW_TECHNICAL_DEBT_KEY;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.DIRECTORY;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.FILE;
-import static org.sonar.ce.task.projectanalysis.component.Component.Type.MODULE;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT;
import static org.sonar.ce.task.projectanalysis.measure.Measure.newMeasureBuilder;
import static org.sonar.ce.task.projectanalysis.measure.MeasureAssert.assertThat;
treeRootHolder.setRoot(
builder(PROJECT, ROOT_REF)
.addChildren(
- builder(MODULE, 11)
- .addChildren(
- builder(DIRECTORY, 111)
- .addChildren(file)
- .build())
+ builder(DIRECTORY, 111)
+ .addChildren(file)
.build())
.build());
Measure newDebtMeasure = createNewDebtMeasure(50);
measureRepository.addRawMeasure(LANGUAGE_1_FILE_REF, NEW_TECHNICAL_DEBT_KEY, newDebtMeasure);
measureRepository.addRawMeasure(111, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(150));
- measureRepository.addRawMeasure(11, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(200));
measureRepository.addRawMeasure(ROOT_REF, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(250));
// 4 lines file, only first one is not ncloc
measureRepository.addRawMeasure(LANGUAGE_1_FILE_REF, NCLOC_DATA_KEY, createNclocDataMeasure(2, 3, 4));
assertNewDebtRatioValues(LANGUAGE_1_FILE_REF, 83.33);
assertNewDebtRatioValues(111, 83.33);
- assertNewDebtRatioValues(11, 83.33);
assertNewDebtRatioValues(ROOT_REF, 83.33);
}
treeRootHolder.setRoot(
builder(PROJECT, ROOT_REF)
.addChildren(
- builder(MODULE, 11)
- .addChildren(
- builder(DIRECTORY, 111)
- .addChildren(file)
- .build())
+ builder(DIRECTORY, 111)
+ .addChildren(file)
.build())
.build());
Measure newDebtMeasure = createNewDebtMeasure(50);
measureRepository.addRawMeasure(LANGUAGE_1_FILE_REF, NEW_TECHNICAL_DEBT_KEY, newDebtMeasure);
measureRepository.addRawMeasure(111, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(150));
- measureRepository.addRawMeasure(11, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(200));
measureRepository.addRawMeasure(ROOT_REF, NEW_TECHNICAL_DEBT_KEY, createNewDebtMeasure(250));
// 4 lines file, only first one is not ncloc
measureRepository.addRawMeasure(LANGUAGE_1_FILE_REF, NCLOC_DATA_KEY, createNclocDataMeasure(2, 3, 4));
assertNewMaintainability(LANGUAGE_1_FILE_REF, D);
assertNewMaintainability(111, D);
- assertNewMaintainability(11, D);
assertNewMaintainability(ROOT_REF, D);
}
treeRootHolder.setRoot(
builder(PROJECT, ROOT_REF)
.addChildren(
- builder(MODULE, 11)
- .addChildren(
- builder(DIRECTORY, 111)
- .addChildren(file1, file2)
- .build())
+ builder(DIRECTORY, 111)
+ .addChildren(file1, file2)
.build())
.build());
treeRootHolder.setRoot(
builder(PROJECT, ROOT_REF)
.addChildren(
- builder(MODULE, 11)
+ builder(DIRECTORY, 111)
.addChildren(
- builder(DIRECTORY, 111)
- .addChildren(
- builder(FILE, LANGUAGE_1_FILE_REF).setFileAttributes(new FileAttributes(false, LANGUAGE_1_KEY, 1)).build())
- .build())
+ builder(FILE, LANGUAGE_1_FILE_REF).setFileAttributes(new FileAttributes(false, LANGUAGE_1_KEY, 1)).build())
.build())
.build());
assertNewMaintainability(LANGUAGE_1_FILE_REF, A);
assertNewMaintainability(111, A);
- assertNewMaintainability(11, A);
assertNewMaintainability(ROOT_REF, A);
}
import static org.sonar.api.rules.RuleType.VULNERABILITY;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.DIRECTORY;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.FILE;
-import static org.sonar.ce.task.projectanalysis.component.Component.Type.MODULE;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT;
import static org.sonar.ce.task.projectanalysis.component.ReportComponent.builder;
import static org.sonar.server.measure.Rating.A;
static final String LANGUAGE_KEY_1 = "lKey1";
static final int PROJECT_REF = 1;
- static final int MODULE_REF = 12;
+ static final int DIR_REF = 12;
static final int DIRECTORY_REF = 123;
static final int FILE_1_REF = 1231;
static final int FILE_2_REF = 1232;
static final Component ROOT_PROJECT = builder(Component.Type.PROJECT, PROJECT_REF).setKey("project")
.addChildren(
- builder(MODULE, MODULE_REF).setKey("module")
+ builder(DIRECTORY, DIR_REF).setKey("dir")
.addChildren(
builder(DIRECTORY, DIRECTORY_REF).setKey("directory")
.addChildren(
newVulnerabilityIssue(3L, MINOR).setCreationDate(AFTER_LEAK_PERIOD_DATE),
// Should not be taken into account
newVulnerabilityIssue(10L, BLOCKER).setCreationDate(AFTER_LEAK_PERIOD_DATE).setResolution(RESOLUTION_FIXED));
- fillComponentIssuesVisitorRule.setIssues(MODULE_REF,
+ fillComponentIssuesVisitorRule.setIssues(DIR_REF,
newVulnerabilityIssue(7L, BLOCKER).setCreationDate(AFTER_LEAK_PERIOD_DATE));
underTest.visit(ROOT_PROJECT);
verifyAddedRawMeasureOnLeakPeriod(FILE_1_REF, NEW_SECURITY_RATING_KEY, C);
verifyAddedRawMeasureOnLeakPeriod(FILE_2_REF, NEW_SECURITY_RATING_KEY, D);
verifyAddedRawMeasureOnLeakPeriod(DIRECTORY_REF, NEW_SECURITY_RATING_KEY, D);
- verifyAddedRawMeasureOnLeakPeriod(MODULE_REF, NEW_SECURITY_RATING_KEY, E);
+ verifyAddedRawMeasureOnLeakPeriod(DIR_REF, NEW_SECURITY_RATING_KEY, E);
verifyAddedRawMeasureOnLeakPeriod(PROJECT_REF, NEW_SECURITY_RATING_KEY, E);
}
verifyAddedRawMeasureOnLeakPeriod(FILE_1_REF, NEW_SECURITY_RATING_KEY, A);
verifyAddedRawMeasureOnLeakPeriod(FILE_2_REF, NEW_SECURITY_RATING_KEY, A);
verifyAddedRawMeasureOnLeakPeriod(DIRECTORY_REF, NEW_SECURITY_RATING_KEY, A);
- verifyAddedRawMeasureOnLeakPeriod(MODULE_REF, NEW_SECURITY_RATING_KEY, A);
+ verifyAddedRawMeasureOnLeakPeriod(DIR_REF, NEW_SECURITY_RATING_KEY, A);
verifyAddedRawMeasureOnLeakPeriod(PROJECT_REF, NEW_SECURITY_RATING_KEY, A);
}
verifyAddedRawMeasureOnLeakPeriod(FILE_1_REF, NEW_SECURITY_RATING_KEY, A);
verifyAddedRawMeasureOnLeakPeriod(FILE_2_REF, NEW_SECURITY_RATING_KEY, A);
verifyAddedRawMeasureOnLeakPeriod(DIRECTORY_REF, NEW_SECURITY_RATING_KEY, A);
- verifyAddedRawMeasureOnLeakPeriod(MODULE_REF, NEW_SECURITY_RATING_KEY, A);
+ verifyAddedRawMeasureOnLeakPeriod(DIR_REF, NEW_SECURITY_RATING_KEY, A);
verifyAddedRawMeasureOnLeakPeriod(PROJECT_REF, NEW_SECURITY_RATING_KEY, A);
}
newBugIssue(3L, MINOR).setCreationDate(AFTER_LEAK_PERIOD_DATE),
// Should not be taken into account
newBugIssue(10L, BLOCKER).setCreationDate(AFTER_LEAK_PERIOD_DATE).setResolution(RESOLUTION_FIXED));
- fillComponentIssuesVisitorRule.setIssues(MODULE_REF,
+ fillComponentIssuesVisitorRule.setIssues(DIR_REF,
newBugIssue(7L, BLOCKER).setCreationDate(AFTER_LEAK_PERIOD_DATE));
underTest.visit(ROOT_PROJECT);
verifyAddedRawMeasureOnLeakPeriod(FILE_1_REF, NEW_RELIABILITY_RATING_KEY, C);
verifyAddedRawMeasureOnLeakPeriod(FILE_2_REF, NEW_RELIABILITY_RATING_KEY, D);
verifyAddedRawMeasureOnLeakPeriod(DIRECTORY_REF, NEW_RELIABILITY_RATING_KEY, D);
- verifyAddedRawMeasureOnLeakPeriod(MODULE_REF, NEW_RELIABILITY_RATING_KEY, E);
+ verifyAddedRawMeasureOnLeakPeriod(DIR_REF, NEW_RELIABILITY_RATING_KEY, E);
verifyAddedRawMeasureOnLeakPeriod(PROJECT_REF, NEW_RELIABILITY_RATING_KEY, E);
}
verifyAddedRawMeasureOnLeakPeriod(FILE_1_REF, NEW_RELIABILITY_RATING_KEY, A);
verifyAddedRawMeasureOnLeakPeriod(FILE_2_REF, NEW_RELIABILITY_RATING_KEY, A);
verifyAddedRawMeasureOnLeakPeriod(DIRECTORY_REF, NEW_RELIABILITY_RATING_KEY, A);
- verifyAddedRawMeasureOnLeakPeriod(MODULE_REF, NEW_RELIABILITY_RATING_KEY, A);
+ verifyAddedRawMeasureOnLeakPeriod(DIR_REF, NEW_RELIABILITY_RATING_KEY, A);
verifyAddedRawMeasureOnLeakPeriod(PROJECT_REF, NEW_RELIABILITY_RATING_KEY, A);
}
verifyAddedRawMeasureOnLeakPeriod(FILE_1_REF, NEW_RELIABILITY_RATING_KEY, A);
verifyAddedRawMeasureOnLeakPeriod(FILE_2_REF, NEW_RELIABILITY_RATING_KEY, A);
verifyAddedRawMeasureOnLeakPeriod(DIRECTORY_REF, NEW_RELIABILITY_RATING_KEY, A);
- verifyAddedRawMeasureOnLeakPeriod(MODULE_REF, NEW_RELIABILITY_RATING_KEY, A);
+ verifyAddedRawMeasureOnLeakPeriod(DIR_REF, NEW_RELIABILITY_RATING_KEY, A);
verifyAddedRawMeasureOnLeakPeriod(PROJECT_REF, NEW_RELIABILITY_RATING_KEY, A);
}
import static org.sonar.api.rules.RuleType.VULNERABILITY;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.DIRECTORY;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.FILE;
-import static org.sonar.ce.task.projectanalysis.component.Component.Type.MODULE;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT;
import static org.sonar.ce.task.projectanalysis.component.ReportComponent.builder;
import static org.sonar.ce.task.projectanalysis.measure.Measure.newMeasureBuilder;
static final String LANGUAGE_KEY_1 = "lKey1";
static final int PROJECT_REF = 1;
- static final int MODULE_REF = 12;
static final int DIRECTORY_REF = 123;
static final int FILE_1_REF = 1231;
static final int FILE_2_REF = 1232;
static final Component ROOT_PROJECT = builder(Component.Type.PROJECT, PROJECT_REF).setKey("project")
.addChildren(
- builder(MODULE, MODULE_REF).setKey("module")
+ builder(DIRECTORY, DIRECTORY_REF).setKey("directory")
.addChildren(
- builder(DIRECTORY, DIRECTORY_REF).setKey("directory")
- .addChildren(
- builder(FILE, FILE_1_REF).setFileAttributes(new FileAttributes(false, LANGUAGE_KEY_1, 1)).setKey("file1").build(),
- builder(FILE, FILE_2_REF).setFileAttributes(new FileAttributes(false, LANGUAGE_KEY_1, 1)).setKey("file2").build())
- .build())
+ builder(FILE, FILE_1_REF).setFileAttributes(new FileAttributes(false, LANGUAGE_KEY_1, 1)).setKey("file1").build(),
+ builder(FILE, FILE_2_REF).setFileAttributes(new FileAttributes(false, LANGUAGE_KEY_1, 1)).setKey("file2").build())
.build())
.build();
fillComponentIssuesVisitorRule.setIssues(FILE_2_REF, newBugIssue(2L, CRITICAL), newBugIssue(3L, MINOR),
// Should not be taken into account
newBugIssue(10L, BLOCKER).setResolution(RESOLUTION_FIXED));
- fillComponentIssuesVisitorRule.setIssues(MODULE_REF, newBugIssue(7L, BLOCKER));
+ fillComponentIssuesVisitorRule.setIssues(PROJECT_REF, newBugIssue(7L, BLOCKER));
underTest.visit(ROOT_PROJECT);
verifyAddedRawMeasure(FILE_1_REF, RELIABILITY_RATING_KEY, C);
verifyAddedRawMeasure(FILE_2_REF, RELIABILITY_RATING_KEY, D);
verifyAddedRawMeasure(DIRECTORY_REF, RELIABILITY_RATING_KEY, D);
- verifyAddedRawMeasure(MODULE_REF, RELIABILITY_RATING_KEY, E);
verifyAddedRawMeasure(PROJECT_REF, RELIABILITY_RATING_KEY, E);
}
fillComponentIssuesVisitorRule.setIssues(FILE_2_REF, newVulnerabilityIssue(2L, CRITICAL), newVulnerabilityIssue(3L, MINOR),
// Should not be taken into account
newVulnerabilityIssue(10L, BLOCKER).setResolution(RESOLUTION_FIXED));
- fillComponentIssuesVisitorRule.setIssues(MODULE_REF, newVulnerabilityIssue(7L, BLOCKER));
+ fillComponentIssuesVisitorRule.setIssues(PROJECT_REF, newVulnerabilityIssue(7L, BLOCKER));
underTest.visit(ROOT_PROJECT);
verifyAddedRawMeasure(FILE_1_REF, SECURITY_RATING_KEY, C);
verifyAddedRawMeasure(FILE_2_REF, SECURITY_RATING_KEY, D);
verifyAddedRawMeasure(DIRECTORY_REF, SECURITY_RATING_KEY, D);
- verifyAddedRawMeasure(MODULE_REF, SECURITY_RATING_KEY, E);
verifyAddedRawMeasure(PROJECT_REF, SECURITY_RATING_KEY, E);
}
import static org.sonar.api.measures.CoreMetrics.LAST_COMMIT_DATE_KEY;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.DIRECTORY;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.FILE;
-import static org.sonar.ce.task.projectanalysis.component.Component.Type.MODULE;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT_VIEW;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.SUBVIEW;
public class LastCommitVisitorTest {
private static final int PROJECT_REF = 1;
- private static final int MODULE_REF = 2;
+ private static final int DIR_REF = 2;
private static final int FILE_1_REF = 1_111;
private static final int FILE_2_REF = 1_112;
private static final int FILE_3_REF = 1_121;
// project with 1 module, 2 directories and 3 files
ReportComponent project = ReportComponent.builder(PROJECT, PROJECT_REF)
.addChildren(
- ReportComponent.builder(MODULE, MODULE_REF)
+ ReportComponent.builder(DIRECTORY, DIR_REF)
.addChildren(
ReportComponent.builder(DIRECTORY, DIR_1_REF)
.addChildren(
assertDate(DIR_1_REF, FILE_2_DATE);
assertDate(DIR_2_REF, FILE_3_DATE);
- // module = most recent commit date of directories
- assertDate(MODULE_REF, FILE_3_DATE);
+ assertDate(DIR_REF, FILE_3_DATE);
// project
assertDate(PROJECT_REF, FILE_3_DATE);
DbFileSources.Line.newBuilder().setSource("line1").setLine(1).build(),
DbFileSources.Line.newBuilder().setSource("line2").setLine(2).build()))
.build();
- when(fileSourceDataComputer.compute(fileComponent(), fileSourceDataWarnings)).thenReturn(new FileSourceDataComputer.Data(fileSourceData, lineHashes, sourceHash, null));
+ when(fileSourceDataComputer.compute(fileComponent().build(), fileSourceDataWarnings))
+ .thenReturn(new FileSourceDataComputer.Data(fileSourceData, lineHashes, sourceHash, null));
underTest.execute(new TestComputationStepContext());
verify(fileSourceDataWarnings).commitWarnings();
}
- private Component fileComponent() {
- return ReportComponent.builder(Component.Type.FILE, FILE1_REF).build();
+ private ReportComponent.Builder fileComponent() {
+ return ReportComponent.builder(Component.Type.FILE, FILE1_REF).setUuid(FILE1_UUID).setKey("PROJECT_KEY" + ":src/Foo.java");
}
@Test
private void setComputedData(DbFileSources.Data data, List<String> lineHashes, String sourceHash, Changeset latestChangeWithRevision) {
FileSourceDataComputer.Data computedData = new FileSourceDataComputer.Data(data, lineHashes, sourceHash, latestChangeWithRevision);
- when(fileSourceDataComputer.compute(fileComponent(), fileSourceDataWarnings)).thenReturn(computedData);
+ when(fileSourceDataComputer.compute(fileComponent().build(), fileSourceDataWarnings)).thenReturn(computedData);
}
private void setComputedData(DbFileSources.Data data) {
FileSourceDataComputer.Data computedData = new FileSourceDataComputer.Data(data, Collections.emptyList(), "", null);
- when(fileSourceDataComputer.compute(fileComponent(), fileSourceDataWarnings)).thenReturn(computedData);
+ when(fileSourceDataComputer.compute(fileComponent().build(), fileSourceDataWarnings)).thenReturn(computedData);
}
private void initBasicReport(int numberOfLines) {
ReportComponent root = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid(PROJECT_UUID).setKey(PROJECT_KEY).addChildren(
- ReportComponent.builder(Component.Type.MODULE, 2).setUuid("MODULE").setKey("MODULE_KEY").addChildren(
- ReportComponent.builder(Component.Type.FILE, FILE1_REF).setUuid(FILE1_UUID).setKey("MODULE_KEY:src/Foo.java")
- .setFileAttributes(new FileAttributes(false, null, numberOfLines)).build())
- .build())
+ fileComponent().setFileAttributes(new FileAttributes(false, null, numberOfLines)).build())
.build();
treeRootHolder.setRoots(root, root);
}
private void initBasicReport(int numberOfLines) {
treeRootHolder.setRoot(ReportComponent.builder(Component.Type.PROJECT, 1).setUuid(PROJECT_UUID).setKey(PROJECT_KEY).addChildren(
- ReportComponent.builder(Component.Type.MODULE, 2).setUuid("MODULE").setKey("MODULE_KEY").addChildren(
+ ReportComponent.builder(Component.Type.DIRECTORY, 2).setUuid("MODULE").setKey("MODULE_KEY").addChildren(
ReportComponent.builder(Component.Type.FILE, FILE1_REF).setUuid(FILE1_UUID).setKey("MODULE_KEY:src/Foo.java")
.setFileAttributes(new FileAttributes(false, null, numberOfLines)).build())
.build())
import org.sonar.ce.task.projectanalysis.component.Component;
import org.sonar.ce.task.projectanalysis.component.DefaultBranchImpl;
import org.sonar.ce.task.projectanalysis.component.MutableTreeRootHolderRule;
+import org.sonar.ce.task.projectanalysis.issue.IssueRelocationToRoot;
import org.sonar.ce.task.step.TestComputationStepContext;
import org.sonar.db.DbClient;
import org.sonar.db.DbTester;
import org.sonar.scanner.protocol.output.ScannerReport.Component.FileStatus;
import org.sonar.server.project.Project;
-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;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType.FILE;
import static org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType.MODULE;
import static org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType.PROJECT;
-import static org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType.UNRECOGNIZED;
-import static org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType.UNSET;
@RunWith(DataProviderRunner.class)
public class BuildComponentTreeStepTest {
private static final String REPORT_PROJECT_KEY = "REPORT_PROJECT_KEY";
private static final String REPORT_MODULE_KEY = "MODULE_KEY";
- private static final String REPORT_DIR_KEY_1 = "src/main/java/dir1";
- private static final String REPORT_FILE_KEY_1 = "src/main/java/dir1/File1.java";
- private static final String REPORT_DIR_KEY_2 = "src/main/java/dir2";
- private static final String REPORT_FILE_KEY_2 = "src/main/java/dir2/File2.java";
+ private static final String REPORT_DIR_PATH_1 = "src/main/java/dir1";
+ private static final String REPORT_FILE_PATH_1 = "src/main/java/dir1/File1.java";
+ private static final String REPORT_DIR_PATH_2 = "src/main/java/dir2";
+ private static final String REPORT_FILE_PATH_2 = "src/main/java/dir2/File2.java";
+ private static final String REPORT_FILE_PATH_3 = "src/main/java/dir2/File3.java";
private static final String REPORT_LEAFLESS_MODULE_KEY = "LEAFLESS_MODULE_KEY";
- private static final String REPORT_LEAFLESS_DIR_KEY = "src/main/java/leafless";
- private static final String REPORT_UNCHANGED_FILE_KEY = "src/main/java/leafless/File3.java";
+ private static final String REPORT_LEAFLESS_DIR_PATH = "src/main/java/leafless";
+ private static final String REPORT_UNCHANGED_FILE_PATH = "src/main/java/leafless/File3.java";
private static final long ANALYSIS_DATE = 123456789L;
@Rule
public MutableAnalysisMetadataHolderRule analysisMetadataHolder = new MutableAnalysisMetadataHolderRule();
+ private IssueRelocationToRoot issueRelocationToRoot = mock(IssueRelocationToRoot.class);
+
private DbClient dbClient = dbTester.getDbClient();
- private BuildComponentTreeStep underTest = new BuildComponentTreeStep(dbClient, reportReader, treeRootHolder, analysisMetadataHolder);
+ private BuildComponentTreeStep underTest = new BuildComponentTreeStep(dbClient, reportReader, treeRootHolder, analysisMetadataHolder, issueRelocationToRoot);
@Test(expected = NullPointerException.class)
public void fails_if_root_component_does_not_exist_in_reportReader() {
underTest.execute(new TestComputationStepContext());
}
- @DataProvider
- public static Object[][] allComponentTypes() {
- Object[][] res = new Object[ComponentType.values().length - 2][1];
- int i = 0;
- for (ComponentType componentType : from(asList(ComponentType.values())).filter(not(in(asList(UNSET, UNRECOGNIZED))))) {
- res[i][0] = componentType;
- i++;
- }
- return res;
- }
-
- @Test
- @UseDataProvider("allComponentTypes")
- public void verify_ref_and_type(ComponentType componentType) {
- setAnalysisMetadataHolder();
- int componentRef = 1;
- reportReader.putComponent(component(componentRef, componentType));
-
- underTest.execute(new TestComputationStepContext());
-
- Component root = treeRootHolder.getRoot();
- assertThat(root).isNotNull();
- assertThat(root.getType()).isEqualTo(Component.Type.valueOf(componentType.name()));
- assertThat(root.getReportAttributes().getRef()).isEqualTo(ROOT_REF);
- assertThat(root.getChildren()).isEmpty();
- }
-
@Test
public void verify_tree_is_correctly_built() {
setAnalysisMetadataHolder();
- reportReader.putComponent(component(ROOT_REF, PROJECT, MODULE_REF));
- reportReader.putComponent(component(MODULE_REF, MODULE, DIR_REF_1, DIR_REF_2));
- reportReader.putComponent(component(DIR_REF_1, DIRECTORY, FILE_1_REF, FILE_2_REF));
- reportReader.putComponent(component(FILE_1_REF, FILE));
- reportReader.putComponent(component(FILE_2_REF, FILE));
- reportReader.putComponent(component(DIR_REF_2, DIRECTORY, FILE_3_REF));
- reportReader.putComponent(component(FILE_3_REF, FILE));
+ reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY, MODULE_REF));
+ reportReader.putComponent(component(MODULE_REF, MODULE, REPORT_MODULE_KEY, DIR_REF_1, DIR_REF_2));
+ reportReader.putComponent(componentWithPath(DIR_REF_1, DIRECTORY, REPORT_DIR_PATH_1, FILE_1_REF, FILE_2_REF));
+ reportReader.putComponent(componentWithPath(FILE_1_REF, FILE, REPORT_FILE_PATH_1));
+ reportReader.putComponent(componentWithPath(FILE_2_REF, FILE, REPORT_FILE_PATH_2));
+ reportReader.putComponent(componentWithPath(DIR_REF_2, DIRECTORY, REPORT_DIR_PATH_2, FILE_3_REF));
+ reportReader.putComponent(componentWithPath(FILE_3_REF, FILE, REPORT_FILE_PATH_3));
TestComputationStepContext context = new TestComputationStepContext();
underTest.execute(context);
Component root = treeRootHolder.getRoot();
assertThat(root).isNotNull();
verifyComponent(root, Component.Type.PROJECT, ROOT_REF, 1);
- Component module = root.getChildren().iterator().next();
- verifyComponent(module, Component.Type.MODULE, MODULE_REF, 2);
- Component dir1 = module.getChildren().get(0);
- verifyComponent(dir1, Component.Type.DIRECTORY, DIR_REF_1, 2);
+
+ Component dir = root.getChildren().iterator().next();
+ verifyComponent(dir, Component.Type.DIRECTORY, null, 2);
+
+ Component dir1 = dir.getChildren().get(0);
+ verifyComponent(dir1, Component.Type.DIRECTORY, null, 1);
verifyComponent(dir1.getChildren().get(0), Component.Type.FILE, FILE_1_REF, 0);
- verifyComponent(dir1.getChildren().get(1), Component.Type.FILE, FILE_2_REF, 0);
- Component dir2 = module.getChildren().get(1);
- verifyComponent(dir2, Component.Type.DIRECTORY, DIR_REF_2, 1);
- verifyComponent(dir2.getChildren().iterator().next(), Component.Type.FILE, FILE_3_REF, 0);
+
+ Component dir2 = dir.getChildren().get(1);
+ verifyComponent(dir2, Component.Type.DIRECTORY, null, 2);
+ verifyComponent(dir2.getChildren().get(0), Component.Type.FILE, FILE_2_REF, 0);
+ verifyComponent(dir2.getChildren().get(1), Component.Type.FILE, FILE_3_REF, 0);
context.getStatistics().assertValue("components", 7);
}
@Test
public void compute_keys_and_uuids() {
setAnalysisMetadataHolder();
- reportReader.putComponent(componentWithKey(ROOT_REF, PROJECT, REPORT_PROJECT_KEY, MODULE_REF));
- reportReader.putComponent(componentWithKey(MODULE_REF, MODULE, REPORT_MODULE_KEY, DIR_REF_1));
- reportReader.putComponent(componentWithPath(DIR_REF_1, DIRECTORY, REPORT_DIR_KEY_1, FILE_1_REF));
- reportReader.putComponent(componentWithPath(FILE_1_REF, FILE, REPORT_FILE_KEY_1));
+ reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY, MODULE_REF));
+ reportReader.putComponent(component(MODULE_REF, MODULE, REPORT_MODULE_KEY, DIR_REF_1));
+ reportReader.putComponent(componentWithPath(DIR_REF_1, DIRECTORY, REPORT_DIR_PATH_1, FILE_1_REF));
+ reportReader.putComponent(componentWithPath(FILE_1_REF, FILE, REPORT_FILE_PATH_1));
underTest.execute(new TestComputationStepContext());
- verifyComponent(ROOT_REF, REPORT_PROJECT_KEY);
- verifyComponent(MODULE_REF, REPORT_MODULE_KEY);
- verifyComponent(DIR_REF_1, REPORT_MODULE_KEY + ":" + REPORT_DIR_KEY_1);
- verifyComponent(FILE_1_REF, REPORT_MODULE_KEY + ":" + REPORT_FILE_KEY_1);
+ verifyComponentByRef(ROOT_REF, REPORT_PROJECT_KEY);
+ verifyComponentByKey(REPORT_PROJECT_KEY + ":" + REPORT_DIR_PATH_1);
+ verifyComponentByRef(FILE_1_REF, REPORT_PROJECT_KEY + ":" + REPORT_FILE_PATH_1);
}
@Test
OrganizationDto organizationDto = dbTester.organizations().insert();
ComponentDto project = insertComponent(newPrivateProjectDto(organizationDto, "ABCD").setDbKey(REPORT_PROJECT_KEY));
ComponentDto module = insertComponent(newModuleDto("BCDE", project).setDbKey(REPORT_MODULE_KEY));
- ComponentDto directory = newDirectory(module, "CDEF", REPORT_DIR_KEY_1);
- insertComponent(directory.setDbKey(REPORT_MODULE_KEY + ":" + REPORT_DIR_KEY_1));
- insertComponent(newFileDto(module, directory, "DEFG").setDbKey(REPORT_MODULE_KEY + ":" + REPORT_FILE_KEY_1));
+ ComponentDto directory = newDirectory(module, "CDEF", REPORT_DIR_PATH_1);
+ insertComponent(directory.setDbKey(REPORT_MODULE_KEY + ":" + REPORT_DIR_PATH_1));
+ insertComponent(newFileDto(module, directory, "DEFG").setDbKey(REPORT_MODULE_KEY + ":" + REPORT_FILE_PATH_1));
- reportReader.putComponent(componentWithKey(ROOT_REF, PROJECT, REPORT_PROJECT_KEY, MODULE_REF));
- reportReader.putComponent(componentWithKey(MODULE_REF, MODULE, REPORT_MODULE_KEY, DIR_REF_1));
- reportReader.putComponent(componentWithPath(DIR_REF_1, DIRECTORY, REPORT_DIR_KEY_1, FILE_1_REF));
- reportReader.putComponent(componentWithPath(FILE_1_REF, FILE, REPORT_FILE_KEY_1));
+ reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY, MODULE_REF));
+ reportReader.putComponent(component(MODULE_REF, MODULE, REPORT_MODULE_KEY, DIR_REF_1));
+ reportReader.putComponent(componentWithPath(DIR_REF_1, DIRECTORY, REPORT_DIR_PATH_1, FILE_1_REF));
+ reportReader.putComponent(componentWithPath(FILE_1_REF, FILE, REPORT_FILE_PATH_1));
underTest.execute(new TestComputationStepContext());
- verifyComponent(ROOT_REF, REPORT_PROJECT_KEY, "ABCD");
- verifyComponent(MODULE_REF, REPORT_MODULE_KEY, "BCDE");
- verifyComponent(DIR_REF_1, REPORT_MODULE_KEY + ":" + REPORT_DIR_KEY_1, "CDEF");
- verifyComponent(FILE_1_REF, REPORT_MODULE_KEY + ":" + REPORT_FILE_KEY_1, "DEFG");
+ verifyComponentByRef(ROOT_REF, REPORT_PROJECT_KEY, "ABCD");
+ // TODO migrate modules
+ // verifyComponentByRef(DIR_REF_1, REPORT_PROJECT_KEY + ":" + REPORT_DIR_PATH_1, "CDEF");
+ // verifyComponentByRef(FILE_1_REF, REPORT_PROJECT_KEY + ":" + REPORT_FILE_PATH_1, "DEFG");
}
@Test
.setAnalysisDate(ANALYSIS_DATE)
.setProject(Project.from(newPrivateProjectDto(newOrganizationDto()).setDbKey(REPORT_PROJECT_KEY)))
.setBranch(branch);
- BuildComponentTreeStep underTest = new BuildComponentTreeStep(dbClient, reportReader, treeRootHolder, analysisMetadataHolder);
- reportReader.putComponent(componentWithKey(ROOT_REF, PROJECT, REPORT_PROJECT_KEY, MODULE_REF));
- reportReader.putComponent(componentWithKey(MODULE_REF, MODULE, REPORT_MODULE_KEY, DIR_REF_1));
- reportReader.putComponent(componentWithPath(DIR_REF_1, DIRECTORY, REPORT_DIR_KEY_1, FILE_1_REF));
- reportReader.putComponent(componentWithPath(FILE_1_REF, FILE, REPORT_FILE_KEY_1));
+ BuildComponentTreeStep underTest = new BuildComponentTreeStep(dbClient, reportReader, treeRootHolder, analysisMetadataHolder, issueRelocationToRoot);
+ reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY, MODULE_REF));
+ reportReader.putComponent(component(MODULE_REF, MODULE, REPORT_MODULE_KEY, DIR_REF_1));
+ reportReader.putComponent(componentWithPath(DIR_REF_1, DIRECTORY, REPORT_DIR_PATH_1, FILE_1_REF));
+ reportReader.putComponent(componentWithPath(FILE_1_REF, FILE, REPORT_FILE_PATH_1));
underTest.execute(new TestComputationStepContext());
- verifyComponent(ROOT_REF, "generated", REPORT_PROJECT_KEY, null);
- verifyComponent(MODULE_REF, "generated", REPORT_MODULE_KEY, null);
- verifyComponent(DIR_REF_1, "generated", REPORT_MODULE_KEY + ":" + REPORT_DIR_KEY_1, null);
- verifyComponent(FILE_1_REF, "generated", REPORT_MODULE_KEY + ":" + REPORT_FILE_KEY_1, null);
+ verifyComponentByRef(ROOT_REF, "generated", REPORT_PROJECT_KEY, null);
+
+ verifyComponentByKey(REPORT_PROJECT_KEY + ":" + REPORT_DIR_PATH_1, "generated");
+ verifyComponentByRef(FILE_1_REF, "generated", REPORT_PROJECT_KEY + ":" + REPORT_FILE_PATH_1, null);
}
@Test
.setAnalysisDate(ANALYSIS_DATE)
.setProject(Project.from(newPrivateProjectDto(newOrganizationDto()).setDbKey(REPORT_PROJECT_KEY)))
.setBranch(branch);
- BuildComponentTreeStep underTest = new BuildComponentTreeStep(dbClient, reportReader, treeRootHolder, analysisMetadataHolder);
- reportReader.putComponent(componentWithKey(ROOT_REF, PROJECT, REPORT_PROJECT_KEY, MODULE_REF, LEAFLESS_MODULE_REF));
- reportReader.putComponent(componentWithKey(MODULE_REF, MODULE, REPORT_MODULE_KEY, DIR_REF_1));
- reportReader.putComponent(componentWithPath(DIR_REF_1, DIRECTORY, REPORT_DIR_KEY_1, FILE_1_REF));
- reportReader.putComponent(componentWithPath(FILE_1_REF, FILE, REPORT_FILE_KEY_1));
-
- reportReader.putComponent(componentWithKey(LEAFLESS_MODULE_REF, MODULE, REPORT_LEAFLESS_MODULE_KEY, LEAFLESS_DIR_REF));
- reportReader.putComponent(componentWithPath(LEAFLESS_DIR_REF, DIRECTORY, REPORT_LEAFLESS_DIR_KEY, UNCHANGED_FILE_REF));
+ BuildComponentTreeStep underTest = new BuildComponentTreeStep(dbClient, reportReader, treeRootHolder, analysisMetadataHolder, issueRelocationToRoot);
+ reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY, MODULE_REF, LEAFLESS_MODULE_REF));
+ reportReader.putComponent(component(MODULE_REF, MODULE, REPORT_MODULE_KEY, DIR_REF_1));
+ reportReader.putComponent(componentWithPath(DIR_REF_1, DIRECTORY, REPORT_DIR_PATH_1, FILE_1_REF));
+ reportReader.putComponent(componentWithPath(FILE_1_REF, FILE, REPORT_FILE_PATH_1));
+
+ reportReader.putComponent(component(LEAFLESS_MODULE_REF, MODULE, REPORT_LEAFLESS_MODULE_KEY, LEAFLESS_DIR_REF));
+ reportReader.putComponent(componentWithPath(LEAFLESS_DIR_REF, DIRECTORY, REPORT_LEAFLESS_DIR_PATH, UNCHANGED_FILE_REF));
ScannerReport.Component unchangedFile = ScannerReport.Component.newBuilder()
.setType(FILE)
.setRef(UNCHANGED_FILE_REF)
- .setPath(REPORT_UNCHANGED_FILE_KEY)
+ .setProjectRelativePath(REPORT_UNCHANGED_FILE_PATH)
.setStatus(FileStatus.SAME)
.setLines(1)
.build();
underTest.execute(new TestComputationStepContext());
- verifyComponent(ROOT_REF, "generated", REPORT_PROJECT_KEY, null);
- verifyComponent(MODULE_REF, "generated", REPORT_MODULE_KEY, null);
- verifyComponent(DIR_REF_1, "generated", REPORT_MODULE_KEY + ":" + REPORT_DIR_KEY_1, null);
- verifyComponent(FILE_1_REF, "generated", REPORT_MODULE_KEY + ":" + REPORT_FILE_KEY_1, null);
+ verifyComponentByRef(ROOT_REF, "generated", REPORT_PROJECT_KEY, null);
+ verifyComponentByKey(REPORT_PROJECT_KEY + ":" + REPORT_DIR_PATH_1, "generated");
+ verifyComponentByRef(FILE_1_REF, "generated", REPORT_PROJECT_KEY + ":" + REPORT_FILE_PATH_1, null);
- verifyComponentMissing(LEAFLESS_MODULE_REF);
- verifyComponentMissing(LEAFLESS_DIR_REF);
- verifyComponentMissing(UNCHANGED_FILE_REF);
+ verifyComponentMissingByRef(LEAFLESS_MODULE_REF);
+ verifyComponentMissingByRef(LEAFLESS_DIR_REF);
+ verifyComponentMissingByRef(UNCHANGED_FILE_REF);
}
@Test
.setAnalysisDate(ANALYSIS_DATE)
.setProject(Project.from(newPrivateProjectDto(newOrganizationDto()).setDbKey(REPORT_PROJECT_KEY)))
.setBranch(branch);
- BuildComponentTreeStep underTest = new BuildComponentTreeStep(dbClient, reportReader, treeRootHolder, analysisMetadataHolder);
- reportReader.putComponent(componentWithKey(ROOT_REF, PROJECT, REPORT_PROJECT_KEY, MODULE_REF, LEAFLESS_MODULE_REF));
- reportReader.putComponent(componentWithKey(MODULE_REF, MODULE, REPORT_MODULE_KEY, DIR_REF_1));
- reportReader.putComponent(componentWithPath(DIR_REF_1, DIRECTORY, REPORT_DIR_KEY_1, FILE_1_REF));
- reportReader.putComponent(componentWithPath(FILE_1_REF, FILE, REPORT_FILE_KEY_1));
-
- reportReader.putComponent(componentWithKey(LEAFLESS_MODULE_REF, MODULE, REPORT_LEAFLESS_MODULE_KEY, LEAFLESS_DIR_REF));
- reportReader.putComponent(componentWithPath(LEAFLESS_DIR_REF, DIRECTORY, REPORT_LEAFLESS_DIR_KEY, UNCHANGED_FILE_REF));
+ BuildComponentTreeStep underTest = new BuildComponentTreeStep(dbClient, reportReader, treeRootHolder, analysisMetadataHolder, issueRelocationToRoot);
+ reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY, MODULE_REF, LEAFLESS_MODULE_REF));
+ reportReader.putComponent(component(MODULE_REF, MODULE, REPORT_MODULE_KEY, DIR_REF_1));
+ reportReader.putComponent(componentWithPath(DIR_REF_1, DIRECTORY, REPORT_DIR_PATH_1, FILE_1_REF));
+ reportReader.putComponent(componentWithPath(FILE_1_REF, FILE, REPORT_FILE_PATH_1));
+
+ reportReader.putComponent(component(LEAFLESS_MODULE_REF, MODULE, REPORT_LEAFLESS_MODULE_KEY, LEAFLESS_DIR_REF));
+ reportReader.putComponent(componentWithPath(LEAFLESS_DIR_REF, DIRECTORY, REPORT_LEAFLESS_DIR_PATH, UNCHANGED_FILE_REF));
ScannerReport.Component unchangedFile = ScannerReport.Component.newBuilder()
.setType(FILE)
.setRef(UNCHANGED_FILE_REF)
- .setPath(REPORT_UNCHANGED_FILE_KEY)
+ .setProjectRelativePath(REPORT_UNCHANGED_FILE_PATH)
.setStatus(FileStatus.SAME)
.setLines(1)
.build();
underTest.execute(new TestComputationStepContext());
- verifyComponent(ROOT_REF, "generated", REPORT_PROJECT_KEY, null);
- verifyComponent(MODULE_REF, "generated", REPORT_MODULE_KEY, null);
- verifyComponent(DIR_REF_1, "generated", REPORT_MODULE_KEY + ":" + REPORT_DIR_KEY_1, null);
- verifyComponent(FILE_1_REF, "generated", REPORT_MODULE_KEY + ":" + REPORT_FILE_KEY_1, null);
+ verifyComponentByRef(ROOT_REF, "generated", REPORT_PROJECT_KEY, null);
+ verifyComponentMissingByRef(MODULE_REF);
+ verifyComponentByKey(REPORT_PROJECT_KEY + ":" + REPORT_DIR_PATH_1, "generated");
+ verifyComponentByRef(FILE_1_REF, "generated", REPORT_PROJECT_KEY + ":" + REPORT_FILE_PATH_1, null);
- verifyComponent(LEAFLESS_MODULE_REF, "generated", REPORT_LEAFLESS_MODULE_KEY, null);
- verifyComponent(LEAFLESS_DIR_REF, "generated", REPORT_LEAFLESS_MODULE_KEY + ":" + REPORT_LEAFLESS_DIR_KEY, null);
- verifyComponent(UNCHANGED_FILE_REF, "generated", REPORT_LEAFLESS_MODULE_KEY + ":" + REPORT_UNCHANGED_FILE_KEY, null);
+ verifyComponentMissingByRef(LEAFLESS_MODULE_REF);
+ verifyComponentByKey(REPORT_PROJECT_KEY + ":" + REPORT_LEAFLESS_DIR_PATH, "generated");
+ verifyComponentByRef(UNCHANGED_FILE_REF, "generated", REPORT_PROJECT_KEY + ":" + REPORT_UNCHANGED_FILE_PATH, null);
}
@DataProvider
.setAnalysisDate(ANALYSIS_DATE)
.setProject(Project.from(projectDto))
.setBranch(branch);
- BuildComponentTreeStep underTest = new BuildComponentTreeStep(dbClient, reportReader, treeRootHolder, analysisMetadataHolder);
- reportReader.putComponent(componentWithKey(ROOT_REF, PROJECT, branchDto.getKey()));
+ BuildComponentTreeStep underTest = new BuildComponentTreeStep(dbClient, reportReader, treeRootHolder, analysisMetadataHolder, issueRelocationToRoot);
+ reportReader.putComponent(component(ROOT_REF, PROJECT, branchDto.getKey()));
underTest.execute(new TestComputationStepContext());
- verifyComponent(ROOT_REF, branchDto.getDbKey(), branchDto.getKey(), branchDto.uuid());
+ verifyComponentByRef(ROOT_REF, branchDto.getDbKey(), branchDto.getKey(), branchDto.uuid());
}
@Test
.setAnalysisDate(ANALYSIS_DATE)
.setProject(Project.from(newPrivateProjectDto(newOrganizationDto()).setDbKey(REPORT_PROJECT_KEY)))
.setBranch(branch);
- BuildComponentTreeStep underTest = new BuildComponentTreeStep(dbClient, reportReader, treeRootHolder, analysisMetadataHolder);
- reportReader.putComponent(componentWithKey(ROOT_REF, PROJECT, REPORT_PROJECT_KEY, MODULE_REF));
- reportReader.putComponent(componentWithKey(MODULE_REF, MODULE, REPORT_MODULE_KEY, DIR_REF_1));
- reportReader.putComponent(componentWithPath(DIR_REF_1, DIRECTORY, REPORT_DIR_KEY_1, FILE_1_REF));
- reportReader.putComponent(componentWithPath(FILE_1_REF, FILE, REPORT_FILE_KEY_1));
+ BuildComponentTreeStep underTest = new BuildComponentTreeStep(dbClient, reportReader, treeRootHolder, analysisMetadataHolder, issueRelocationToRoot);
+ reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY, MODULE_REF));
+ reportReader.putComponent(component(MODULE_REF, MODULE, REPORT_MODULE_KEY, DIR_REF_1));
+ reportReader.putComponent(componentWithPath(DIR_REF_1, DIRECTORY, REPORT_DIR_PATH_1, FILE_1_REF));
+ reportReader.putComponent(componentWithPath(FILE_1_REF, FILE, REPORT_FILE_PATH_1));
underTest.execute(new TestComputationStepContext());
- verifyComponent(ROOT_REF, REPORT_PROJECT_KEY, REPORT_PROJECT_KEY, null);
- verifyComponent(MODULE_REF, REPORT_MODULE_KEY, REPORT_MODULE_KEY, null);
- verifyComponent(DIR_REF_1, REPORT_MODULE_KEY + ":" + REPORT_DIR_KEY_1, REPORT_MODULE_KEY + ":" + REPORT_DIR_KEY_1, null);
- verifyComponent(FILE_1_REF, REPORT_MODULE_KEY + ":" + REPORT_FILE_KEY_1, REPORT_MODULE_KEY + ":" + REPORT_FILE_KEY_1, null);
+ verifyComponentByRef(ROOT_REF, REPORT_PROJECT_KEY, REPORT_PROJECT_KEY, null);
+ verifyComponentMissingByRef(MODULE_REF);
+ verifyComponentByKey(REPORT_PROJECT_KEY + ":" + REPORT_DIR_PATH_1);
+ verifyComponentByRef(FILE_1_REF, REPORT_PROJECT_KEY + ":" + REPORT_FILE_PATH_1, REPORT_PROJECT_KEY + ":" + REPORT_FILE_PATH_1, null);
}
@Test
.setAnalysisDate(ANALYSIS_DATE)
.setProject(Project.from(newPrivateProjectDto(newOrganizationDto()).setDbKey(REPORT_PROJECT_KEY)))
.setBranch(new DefaultBranchImpl("origin/feature"));
- BuildComponentTreeStep underTest = new BuildComponentTreeStep(dbClient, reportReader, treeRootHolder, analysisMetadataHolder);
- reportReader.putComponent(componentWithKey(ROOT_REF, PROJECT, REPORT_PROJECT_KEY, MODULE_REF));
- reportReader.putComponent(componentWithKey(MODULE_REF, MODULE, REPORT_MODULE_KEY, DIR_REF_1));
- reportReader.putComponent(componentWithPath(DIR_REF_1, DIRECTORY, REPORT_DIR_KEY_1, FILE_1_REF));
- reportReader.putComponent(componentWithPath(FILE_1_REF, FILE, REPORT_FILE_KEY_1));
+ BuildComponentTreeStep underTest = new BuildComponentTreeStep(dbClient, reportReader, treeRootHolder, analysisMetadataHolder, issueRelocationToRoot);
+ reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY, MODULE_REF));
+ reportReader.putComponent(component(MODULE_REF, MODULE, REPORT_MODULE_KEY, DIR_REF_1));
+ reportReader.putComponent(componentWithPath(DIR_REF_1, DIRECTORY, REPORT_DIR_PATH_1, FILE_1_REF));
+ reportReader.putComponent(componentWithPath(FILE_1_REF, FILE, REPORT_FILE_PATH_1));
underTest.execute(new TestComputationStepContext());
- verifyComponent(ROOT_REF, REPORT_PROJECT_KEY + ":origin/feature", null);
- verifyComponent(MODULE_REF, REPORT_MODULE_KEY + ":origin/feature", null);
- verifyComponent(DIR_REF_1, REPORT_MODULE_KEY + ":origin/feature:" + REPORT_DIR_KEY_1, null);
- verifyComponent(FILE_1_REF, REPORT_MODULE_KEY + ":origin/feature:" + REPORT_FILE_KEY_1, null);
+ verifyComponentByRef(ROOT_REF, REPORT_PROJECT_KEY + ":origin/feature", null);
+ verifyComponentMissingByRef(MODULE_REF);
+ verifyComponentByKey(REPORT_PROJECT_KEY + ":origin/feature:" + REPORT_DIR_PATH_1);
+ verifyComponentByRef(FILE_1_REF, REPORT_PROJECT_KEY + ":origin/feature:" + REPORT_FILE_PATH_1, null);
}
@Test
public void compute_keys_and_uuids_on_project_having_module_and_directory() {
setAnalysisMetadataHolder();
- reportReader.putComponent(componentWithKey(ROOT_REF, PROJECT, REPORT_PROJECT_KEY, MODULE_REF, DIR_REF_2));
- reportReader.putComponent(componentWithKey(MODULE_REF, MODULE, REPORT_MODULE_KEY, DIR_REF_1));
- reportReader.putComponent(componentWithPath(DIR_REF_1, DIRECTORY, REPORT_DIR_KEY_1, FILE_1_REF));
- reportReader.putComponent(componentWithPath(FILE_1_REF, FILE, REPORT_FILE_KEY_1));
- reportReader.putComponent(componentWithPath(DIR_REF_2, DIRECTORY, REPORT_DIR_KEY_2, FILE_2_REF));
- reportReader.putComponent(componentWithPath(FILE_2_REF, FILE, REPORT_FILE_KEY_2));
+ reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY, MODULE_REF, DIR_REF_2));
+ reportReader.putComponent(component(MODULE_REF, MODULE, REPORT_MODULE_KEY, DIR_REF_1));
+ reportReader.putComponent(componentWithPath(DIR_REF_1, DIRECTORY, REPORT_DIR_PATH_1, FILE_1_REF));
+ reportReader.putComponent(componentWithPath(FILE_1_REF, FILE, REPORT_FILE_PATH_1));
+ reportReader.putComponent(componentWithPath(DIR_REF_2, DIRECTORY, REPORT_DIR_PATH_2, FILE_2_REF));
+ reportReader.putComponent(componentWithPath(FILE_2_REF, FILE, REPORT_FILE_PATH_2));
underTest.execute(new TestComputationStepContext());
- verifyComponent(ROOT_REF, REPORT_PROJECT_KEY);
- verifyComponent(MODULE_REF, REPORT_MODULE_KEY);
- verifyComponent(DIR_REF_1, REPORT_MODULE_KEY + ":" + REPORT_DIR_KEY_1);
- verifyComponent(FILE_1_REF, REPORT_MODULE_KEY + ":" + REPORT_FILE_KEY_1);
- verifyComponent(DIR_REF_2, REPORT_PROJECT_KEY + ":" + REPORT_DIR_KEY_2);
- verifyComponent(FILE_2_REF, REPORT_PROJECT_KEY + ":" + REPORT_FILE_KEY_2);
+ verifyComponentByRef(ROOT_REF, REPORT_PROJECT_KEY);
+ verifyComponentMissingByRef(MODULE_REF);
+ verifyComponentByKey(REPORT_PROJECT_KEY + ":" + REPORT_DIR_PATH_1);
+ verifyComponentByRef(FILE_1_REF, REPORT_PROJECT_KEY + ":" + REPORT_FILE_PATH_1);
+ verifyComponentByKey(REPORT_PROJECT_KEY + ":" + REPORT_DIR_PATH_2);
+ verifyComponentByRef(FILE_2_REF, REPORT_PROJECT_KEY + ":" + REPORT_FILE_PATH_2);
}
@Test
public void compute_keys_and_uuids_on_multi_modules() {
setAnalysisMetadataHolder();
- reportReader.putComponent(componentWithKey(ROOT_REF, PROJECT, REPORT_PROJECT_KEY, MODULE_REF));
- reportReader.putComponent(componentWithKey(MODULE_REF, MODULE, REPORT_MODULE_KEY, 100));
- reportReader.putComponent(componentWithKey(100, MODULE, "SUB_MODULE_KEY", DIR_REF_1));
- reportReader.putComponent(componentWithPath(DIR_REF_1, DIRECTORY, REPORT_DIR_KEY_1, FILE_1_REF));
- reportReader.putComponent(componentWithPath(FILE_1_REF, FILE, REPORT_FILE_KEY_1));
+ reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY, MODULE_REF));
+ reportReader.putComponent(component(MODULE_REF, MODULE, REPORT_MODULE_KEY, 100));
+ reportReader.putComponent(component(100, MODULE, "SUB_MODULE_KEY", DIR_REF_1));
+ reportReader.putComponent(componentWithPath(DIR_REF_1, DIRECTORY, REPORT_DIR_PATH_1, FILE_1_REF));
+ reportReader.putComponent(componentWithPath(FILE_1_REF, FILE, REPORT_FILE_PATH_1));
underTest.execute(new TestComputationStepContext());
- verifyComponent(ROOT_REF, REPORT_PROJECT_KEY);
- verifyComponent(MODULE_REF, REPORT_MODULE_KEY);
- verifyComponent(100, "SUB_MODULE_KEY");
- verifyComponent(DIR_REF_1, "SUB_MODULE_KEY" + ":" + REPORT_DIR_KEY_1);
- verifyComponent(FILE_1_REF, "SUB_MODULE_KEY" + ":" + REPORT_FILE_KEY_1);
+ verifyComponentByRef(ROOT_REF, REPORT_PROJECT_KEY);
+ verifyComponentMissingByRef(MODULE_REF);
+ verifyComponentMissingByKey(REPORT_MODULE_KEY);
+ verifyComponentMissingByRef(100);
+ verifyComponentMissingByKey("SUB_MODULE_KEY");
+ verifyComponentByKey(REPORT_PROJECT_KEY + ":" + REPORT_DIR_PATH_1);
+ verifyComponentByRef(FILE_1_REF, REPORT_PROJECT_KEY + ":" + REPORT_FILE_PATH_1);
}
@Test
OrganizationDto organizationDto = dbTester.organizations().insert();
ComponentDto project = insertComponent(newPrivateProjectDto(organizationDto, "ABCD").setDbKey(REPORT_PROJECT_KEY));
ComponentDto removedModule = insertComponent(newModuleDto("BCDE", project).setDbKey(REPORT_MODULE_KEY).setEnabled(false));
- ComponentDto removedDirectory = insertComponent(newDirectory(removedModule, "CDEF", REPORT_DIR_KEY_1).setDbKey(REPORT_MODULE_KEY + ":" + REPORT_DIR_KEY_1).setEnabled(false));
- insertComponent(newFileDto(removedModule, removedDirectory, "DEFG").setDbKey(REPORT_MODULE_KEY + ":" + REPORT_FILE_KEY_1).setEnabled(false));
+ ComponentDto removedDirectory = insertComponent(newDirectory(removedModule, "CDEF", REPORT_DIR_PATH_1).setDbKey(REPORT_MODULE_KEY + ":" + REPORT_DIR_PATH_1).setEnabled(false));
+ insertComponent(newFileDto(removedModule, removedDirectory, "DEFG").setDbKey(REPORT_MODULE_KEY + ":" + REPORT_FILE_PATH_1).setEnabled(false));
- reportReader.putComponent(componentWithKey(ROOT_REF, PROJECT, REPORT_PROJECT_KEY, MODULE_REF));
- reportReader.putComponent(componentWithKey(MODULE_REF, MODULE, REPORT_MODULE_KEY, DIR_REF_1));
- reportReader.putComponent(componentWithPath(DIR_REF_1, DIRECTORY, REPORT_DIR_KEY_1, FILE_1_REF));
- reportReader.putComponent(componentWithPath(FILE_1_REF, FILE, REPORT_FILE_KEY_1));
+ reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY, MODULE_REF));
+ reportReader.putComponent(component(MODULE_REF, MODULE, REPORT_MODULE_KEY, DIR_REF_1));
+ reportReader.putComponent(componentWithPath(DIR_REF_1, DIRECTORY, REPORT_DIR_PATH_1, FILE_1_REF));
+ reportReader.putComponent(componentWithPath(FILE_1_REF, FILE, REPORT_FILE_PATH_1));
underTest.execute(new TestComputationStepContext());
- verifyComponent(ROOT_REF, REPORT_PROJECT_KEY, "ABCD");
+ verifyComponentByRef(ROOT_REF, REPORT_PROJECT_KEY, "ABCD");
// No new UUID is generated on removed components
- verifyComponent(MODULE_REF, REPORT_MODULE_KEY, "BCDE");
- verifyComponent(DIR_REF_1, REPORT_MODULE_KEY + ":" + REPORT_DIR_KEY_1, "CDEF");
- verifyComponent(FILE_1_REF, REPORT_MODULE_KEY + ":" + REPORT_FILE_KEY_1, "DEFG");
+ verifyComponentMissingByRef(MODULE_REF);
+ // TODO migrate modules
+ //verifyComponentByRef(DIR_REF_1, REPORT_PROJECT_KEY + ":" + REPORT_DIR_PATH_1, REPORT_PROJECT_KEY + ":" + REPORT_DIR_PATH_1, "CDEF");
+ //verifyComponentByRef(FILE_1_REF, REPORT_PROJECT_KEY + ":" + REPORT_FILE_PATH_1, "DEFG");
}
@Test
public void set_no_base_project_snapshot_when_no_snapshot() {
setAnalysisMetadataHolder();
- reportReader.putComponent(componentWithKey(ROOT_REF, PROJECT, REPORT_PROJECT_KEY));
+ reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY));
underTest.execute(new TestComputationStepContext());
assertThat(analysisMetadataHolder.isFirstAnalysis()).isTrue();
ComponentDto project = insertComponent(newPrivateProjectDto(organizationDto, "ABCD").setDbKey(REPORT_PROJECT_KEY));
insertSnapshot(newAnalysis(project).setLast(false));
- reportReader.putComponent(componentWithKey(ROOT_REF, PROJECT, REPORT_PROJECT_KEY));
+ reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY));
underTest.execute(new TestComputationStepContext());
assertThat(analysisMetadataHolder.isFirstAnalysis()).isTrue();
ComponentDto project = insertComponent(newPrivateProjectDto(organizationDto, "ABCD").setDbKey(REPORT_PROJECT_KEY));
insertSnapshot(newAnalysis(project).setLast(true));
- reportReader.putComponent(componentWithKey(ROOT_REF, PROJECT, REPORT_PROJECT_KEY));
+ reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY));
underTest.execute(new TestComputationStepContext());
assertThat(analysisMetadataHolder.isFirstAnalysis()).isFalse();
}
- private void verifyComponent(Component component, Component.Type type, int componentRef, int size) {
+ private void verifyComponent(Component component, Component.Type type, @Nullable Integer componentRef, int size) {
assertThat(component.getType()).isEqualTo(type);
assertThat(component.getReportAttributes().getRef()).isEqualTo(componentRef);
assertThat(component.getChildren()).hasSize(size);
}
- private void verifyComponent(int ref, String key) {
- verifyComponent(ref, key, key, null);
+ private void verifyComponentByRef(int ref, String key) {
+ verifyComponentByRef(ref, key, key, null);
+ }
+
+ private void verifyComponentByRef(int ref, String key, @Nullable String uuid) {
+ verifyComponentByRef(ref, key, key, uuid);
}
- private void verifyComponent(int ref, String key, @Nullable String uuid) {
- verifyComponent(ref, key, key, uuid);
+ private void verifyComponentByKey(String publicKey) {
+ verifyComponentByKey(publicKey, publicKey, null);
}
- private void verifyComponent(int ref, String key, String publicKey, @Nullable String uuid) {
+ private void verifyComponentByKey(String publicKey, String key) {
+ verifyComponentByKey(publicKey, key, null);
+ }
+
+ private void verifyComponentByKey(String publicKey, String key, @Nullable String uuid) {
+ Map<String, Component> componentsByKey = indexAllComponentsInTreeByKey(treeRootHolder.getRoot());
+ Component component = componentsByKey.get(publicKey);
+ assertThat(component.getDbKey()).isEqualTo(key);
+ assertThat(component.getReportAttributes().getRef()).isNull();
+ assertThat(component.getKey()).isEqualTo(publicKey);
+ if (uuid != null) {
+ assertThat(component.getUuid()).isEqualTo(uuid);
+ } else {
+ assertThat(component.getUuid()).isNotNull();
+ }
+ }
+
+ private void verifyComponentByRef(int ref, String key, String publicKey, @Nullable String uuid) {
Map<Integer, Component> componentsByRef = indexAllComponentsInTreeByRef(treeRootHolder.getRoot());
Component component = componentsByRef.get(ref);
assertThat(component.getDbKey()).isEqualTo(key);
}
}
- private void verifyComponentMissing(int ref) {
+ private void verifyComponentMissingByRef(int ref) {
Map<Integer, Component> componentsByRef = indexAllComponentsInTreeByRef(treeRootHolder.getRoot());
assertThat(componentsByRef.get(ref)).isNull();
}
- private static ScannerReport.Component component(int componentRef, ComponentType componentType, int... children) {
- return component(componentRef, componentType, null, null, children);
+ private void verifyComponentMissingByKey(String key) {
+ Map<String, Component> componentsByKey = indexAllComponentsInTreeByKey(treeRootHolder.getRoot());
+ assertThat(componentsByKey.get(key)).isNull();
}
- private static ScannerReport.Component componentWithKey(int componentRef, ComponentType componentType, String key, int... children) {
+ private static ScannerReport.Component component(int componentRef, ComponentType componentType, String key, int... children) {
return component(componentRef, componentType, key, null, children);
}
private static ScannerReport.Component componentWithPath(int componentRef, ComponentType componentType, String path, int... children) {
- return component(componentRef, componentType, null, path, children);
+ return component(componentRef, componentType, REPORT_PROJECT_KEY + ":" + path, path, children);
}
- private static ScannerReport.Component component(int componentRef, ComponentType componentType, @Nullable String key, @Nullable String path, int... children) {
+ private static ScannerReport.Component component(int componentRef, ComponentType componentType, String key, @Nullable String path, int... children) {
ScannerReport.Component.Builder builder = ScannerReport.Component.newBuilder()
.setType(componentType)
.setRef(componentRef)
.setStatus(FileStatus.UNAVAILABLE)
- .setLines(1);
- if (key != null) {
- builder.setKey(key);
- }
+ .setLines(1)
+ .setKey(key);
if (path != null) {
- builder.setPath(path);
+ builder.setProjectRelativePath(path);
}
for (int child : children) {
builder.addChildRef(child);
return componentsByRef;
}
+ private static Map<String, Component> indexAllComponentsInTreeByKey(Component root) {
+ Map<String, Component> componentsByKey = new HashMap<>();
+ feedComponentByKey(root, componentsByKey);
+ return componentsByKey;
+ }
+
+ private static void feedComponentByKey(Component component, Map<String, Component> map) {
+ map.put(component.getKey(), component);
+ for (Component child : component.getChildren()) {
+ feedComponentByKey(child, map);
+ }
+ }
+
private static void feedComponentByRef(Component component, Map<Integer, Component> map) {
map.put(component.getReportAttributes().getRef(), component);
for (Component child : component.getChildren()) {
import static org.sonar.api.measures.CoreMetrics.QUALITY_PROFILES_KEY;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.DIRECTORY;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.FILE;
-import static org.sonar.ce.task.projectanalysis.component.Component.Type.MODULE;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT;
public class ComputeQProfileMeasureStepTest {
private static final String PROJECT_KEY = "PROJECT KEY";
private static final int PROJECT_REF = 1;
- private static final int MODULE_REF = 11;
- private static final int SUB_MODULE_REF = 111;
private static final int FOLDER_1_REF = 1111;
private static final int FOLDER_2_REF = 1112;
private static final int FILE_1_1_REF = 11111;
private static final int FILE_2_2_REF = 11122;
private static final Component MULTI_MODULE_PROJECT = ReportComponent.builder(PROJECT, PROJECT_REF).setKey(PROJECT_KEY)
- .addChildren(
- ReportComponent.builder(MODULE, MODULE_REF)
+ .addChildren(ReportComponent.builder(DIRECTORY, FOLDER_1_REF)
.addChildren(
- ReportComponent.builder(MODULE, SUB_MODULE_REF)
- .addChildren(ReportComponent.builder(DIRECTORY, FOLDER_1_REF)
- .addChildren(
- ReportComponent.builder(FILE, FILE_1_1_REF).setFileAttributes(new FileAttributes(false, "java", 1)).build(),
- ReportComponent.builder(FILE, FILE_1_2_REF).setFileAttributes(new FileAttributes(false, "java", 1)).build())
- .build(),
- ReportComponent.builder(DIRECTORY, FOLDER_2_REF)
- .addChildren(
- ReportComponent.builder(FILE, FILE_2_1_REF).setFileAttributes(new FileAttributes(false, null, 1)).build(),
- ReportComponent.builder(FILE, FILE_2_2_REF).setFileAttributes(new FileAttributes(false, "php", 1)).build())
- .build())
- .build())
+ ReportComponent.builder(FILE, FILE_1_1_REF).setFileAttributes(new FileAttributes(false, "java", 1)).build(),
+ ReportComponent.builder(FILE, FILE_1_2_REF).setFileAttributes(new FileAttributes(false, "java", 1)).build())
+ .build(),
+ ReportComponent.builder(DIRECTORY, FOLDER_2_REF)
+ .addChildren(
+ ReportComponent.builder(FILE, FILE_2_1_REF).setFileAttributes(new FileAttributes(false, null, 1)).build(),
+ ReportComponent.builder(FILE, FILE_2_2_REF).setFileAttributes(new FileAttributes(false, "php", 1)).build())
.build())
.build();
import static org.assertj.guava.api.Assertions.assertThat;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.DIRECTORY;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.FILE;
-import static org.sonar.ce.task.projectanalysis.component.Component.Type.MODULE;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT_VIEW;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.SUBVIEW;
public class CustomMeasuresCopyStepTest {
private static final int PROJECT_REF = 1;
- private static final int MODULE_REF = 11;
- private static final int MODULE2_REF = 12;
- private static final int SUB_MODULE_REF = 111;
private static final int DIR_REF = 1111;
private static final int FILE1_REF = 11111;
private static final int FILE2_REF = 11112;
private static final String PROJECT_UUID = "PROJECT";
- private static final String MODULE_UUID = "MODULE";
- private static final String MODULE2_UUID = "MODULE2";
- private static final String SUB_MODULE_UUID = "SUB_MODULE";
private static final String DIR_UUID = "DIR";
private static final String FILE1_UUID = "FILE1";
private static final String FILE2_UUID = "FILE2";
public void copy_custom_measures_on_report() {
insertCustomMeasure(FILE1_UUID, FLOAT_METRIC, 3.14);
insertCustomMeasure(DIR_UUID, FLOAT_METRIC, 123d);
- insertCustomMeasure(SUB_MODULE_UUID, STRING_METRIC, "sub-module");
- insertCustomMeasure(MODULE_UUID, STRING_METRIC, "module");
insertCustomMeasure(PROJECT_UUID, STRING_METRIC, "project");
// Module2 has no custom measure
treeRootHolder.setRoot(
builder(PROJECT, PROJECT_REF).setUuid(PROJECT_UUID)
.addChildren(
- ReportComponent.builder(MODULE, MODULE_REF).setUuid(MODULE_UUID)
+ ReportComponent.builder(DIRECTORY, DIR_REF).setUuid(DIR_UUID)
.addChildren(
- ReportComponent.builder(MODULE, SUB_MODULE_REF).setUuid(SUB_MODULE_UUID)
- .addChildren(
- ReportComponent.builder(DIRECTORY, DIR_REF).setUuid(DIR_UUID)
- .addChildren(
- ReportComponent.builder(FILE, FILE1_REF).setUuid(FILE1_UUID).build(),
- ReportComponent.builder(FILE, FILE2_REF).setUuid(FILE2_UUID).build())
- .build())
- .build())
- .build(),
- ReportComponent.builder(MODULE, MODULE2_REF).setUuid(MODULE2_UUID).build())
+ ReportComponent.builder(FILE, FILE1_REF).setUuid(FILE1_UUID).build(),
+ ReportComponent.builder(FILE, FILE2_REF).setUuid(FILE2_UUID).build())
+ .build())
.build());
underTest.execute(new TestComputationStepContext());
assertNoRawMeasureValue(FILE1_REF);
assertNoRawMeasureValue(FILE2_REF);
assertNoRawMeasureValue(DIR_REF);
- assertRawMeasureValue(SUB_MODULE_REF, STRING_METRIC.getKey(), "sub-module");
- assertRawMeasureValue(MODULE_REF, STRING_METRIC.getKey(), "module");
assertRawMeasureValue(PROJECT_REF, STRING_METRIC.getKey(), "project");
- assertNoRawMeasureValue(MODULE2_REF);
}
import static org.sonar.api.measures.CoreMetrics.NCLOC_KEY;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.DIRECTORY;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.FILE;
-import static org.sonar.ce.task.projectanalysis.component.Component.Type.MODULE;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT;
import static org.sonar.ce.task.projectanalysis.component.ReportComponent.builder;
import static org.sonar.ce.task.projectanalysis.measure.Measure.newMeasureBuilder;
private static final String TEST_METRIC_KEY = "test";
private static final int ROOT_REF = 1;
- private static final int MODULE_REF = 12;
private static final int DIRECTORY_REF = 123;
private static final int FILE_1_REF = 1231;
private static final int FILE_2_REF = 1232;
treeRootHolder.setRoot(
builder(PROJECT, ROOT_REF).setKey("project")
.addChildren(
- builder(MODULE, MODULE_REF).setKey("module")
+ builder(DIRECTORY, DIRECTORY_REF).setKey("directory")
.addChildren(
- builder(DIRECTORY, DIRECTORY_REF).setKey("directory")
- .addChildren(
- builder(FILE, FILE_1_REF).setKey("file1").build(),
- builder(FILE, FILE_2_REF).setKey("file2").build())
- .build())
+ builder(FILE, FILE_1_REF).setKey("file1").build(),
+ builder(FILE, FILE_2_REF).setKey("file2").build())
.build())
.build());
}
measureRepository.addRawMeasure(FILE_1_REF, NCLOC_KEY, newMeasureBuilder().create(1));
measureRepository.addRawMeasure(FILE_2_REF, NCLOC_KEY, newMeasureBuilder().create(2));
measureRepository.addRawMeasure(DIRECTORY_REF, NCLOC_KEY, newMeasureBuilder().create(3));
- measureRepository.addRawMeasure(MODULE_REF, NCLOC_KEY, newMeasureBuilder().create(3));
measureRepository.addRawMeasure(ROOT_REF, NCLOC_KEY, newMeasureBuilder().create(3));
underStep.execute(new TestComputationStepContext());
assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, TEST_METRIC_KEY).get().getIntValue()).isEqualTo(2);
assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, TEST_METRIC_KEY).get().getIntValue()).isEqualTo(3);
assertThat(measureRepository.getAddedRawMeasure(DIRECTORY_REF, TEST_METRIC_KEY).get().getIntValue()).isEqualTo(4);
- assertThat(measureRepository.getAddedRawMeasure(MODULE_REF, TEST_METRIC_KEY).get().getIntValue()).isEqualTo(4);
assertThat(measureRepository.getAddedRawMeasure(ROOT_REF, TEST_METRIC_KEY).get().getIntValue()).isEqualTo(4);
}
assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, TEST_METRIC_KEY).get().getIntValue()).isEqualTo(1);
assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, TEST_METRIC_KEY).get().getIntValue()).isEqualTo(1);
assertThat(measureRepository.getAddedRawMeasure(DIRECTORY_REF, TEST_METRIC_KEY).get().getIntValue()).isEqualTo(2);
- assertThat(measureRepository.getAddedRawMeasure(MODULE_REF, TEST_METRIC_KEY).get().getIntValue()).isEqualTo(2);
assertThat(measureRepository.getAddedRawMeasure(ROOT_REF, TEST_METRIC_KEY).get().getIntValue()).isEqualTo(2);
}
computeAndSaveMeasures(project, path);
}
- @Override
- public void visitModule(Component module, Path<Counter> path) {
- computeAndSaveMeasures(module, path);
- }
-
@Override
public void visitDirectory(Component directory, Path<Counter> path) {
computeAndSaveMeasures(directory, path);
import static org.sonar.api.measures.CoreMetrics.NEW_LINES_KEY;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.DIRECTORY;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.FILE;
-import static org.sonar.ce.task.projectanalysis.component.Component.Type.MODULE;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT;
import static org.sonar.ce.task.projectanalysis.component.ReportComponent.builder;
private static final Offset<Double> DEFAULT_OFFSET = Offset.offset(0.1d);
private static final int ROOT_REF = 1;
- private static final int MODULE_REF = 12;
- private static final int SUB_MODULE_1_REF = 123;
- private static final int SUB_MODULE_2_REF = 126;
private static final int DIRECTORY_REF = 1234;
private static final int DIRECTORY_2_REF = 1235;
private static final int FILE_1_REF = 12341;
.setRoot(
builder(PROJECT, ROOT_REF)
.addChildren(
- builder(MODULE, MODULE_REF)
- .addChildren(
- builder(MODULE, SUB_MODULE_1_REF)
- .addChildren(
- builder(DIRECTORY, DIRECTORY_REF)
- .addChildren(FILE_1, FILE_2)
- .build(),
- builder(DIRECTORY, DIRECTORY_2_REF).build())
- .build(),
- builder(MODULE, SUB_MODULE_2_REF)
- .addChildren(FILE_3, FILE_4)
- .build())
- .build())
+ builder(DIRECTORY, DIRECTORY_REF)
+ .addChildren(FILE_1, FILE_2)
+ .build(),
+ builder(DIRECTORY, DIRECTORY_2_REF).build(),
+ FILE_3, FILE_4)
.build());
@Rule
assertRawMeasureValueOnPeriod(FILE_4_REF, NEW_LINES_KEY, 11);
assertRawMeasureValueOnPeriod(DIRECTORY_REF, NEW_LINES_KEY, 22);
assertNoRawMeasure(DIRECTORY_2_REF, NEW_LINES_KEY);
- assertRawMeasureValueOnPeriod(SUB_MODULE_1_REF, NEW_LINES_KEY, 22);
- assertRawMeasureValueOnPeriod(SUB_MODULE_2_REF, NEW_LINES_KEY, 11);
- assertRawMeasureValueOnPeriod(MODULE_REF, NEW_LINES_KEY, 33);
assertRawMeasureValueOnPeriod(ROOT_REF, NEW_LINES_KEY, 33);
}
assertRawMeasureValueOnPeriod(FILE_4_REF, NEW_LINES_KEY, 2);
assertRawMeasureValueOnPeriod(DIRECTORY_REF, NEW_LINES_KEY, 4);
assertNoRawMeasure(DIRECTORY_2_REF, NEW_LINES_KEY);
- assertRawMeasureValueOnPeriod(SUB_MODULE_1_REF, NEW_LINES_KEY, 4);
- assertRawMeasureValueOnPeriod(SUB_MODULE_2_REF, NEW_LINES_KEY, 2);
- assertRawMeasureValueOnPeriod(MODULE_REF, NEW_LINES_KEY, 6);
assertRawMeasureValueOnPeriod(ROOT_REF, NEW_LINES_KEY, 6);
}
assertRawMeasureValueOnPeriod(FILE_4_REF, NEW_DUPLICATED_LINES_KEY, 11d);
assertRawMeasureValueOnPeriod(DIRECTORY_REF, NEW_DUPLICATED_LINES_KEY, 2d);
assertNoRawMeasure(DIRECTORY_2_REF, NEW_DUPLICATED_LINES_KEY);
- assertRawMeasureValueOnPeriod(SUB_MODULE_1_REF, NEW_DUPLICATED_LINES_KEY, 2d);
- assertRawMeasureValueOnPeriod(SUB_MODULE_2_REF, NEW_DUPLICATED_LINES_KEY, 20d);
- assertRawMeasureValueOnPeriod(MODULE_REF, NEW_DUPLICATED_LINES_KEY, 22d);
assertRawMeasureValueOnPeriod(ROOT_REF, NEW_DUPLICATED_LINES_KEY, 22d);
}
assertRawMeasureValueOnPeriod(FILE_4_REF, NEW_DUPLICATED_LINES_KEY, 2d);
assertRawMeasureValueOnPeriod(DIRECTORY_REF, NEW_DUPLICATED_LINES_KEY, 2d);
assertNoRawMeasure(DIRECTORY_2_REF, NEW_DUPLICATED_LINES_KEY);
- assertRawMeasureValueOnPeriod(SUB_MODULE_1_REF, NEW_DUPLICATED_LINES_KEY, 2d);
- assertRawMeasureValueOnPeriod(SUB_MODULE_2_REF, NEW_DUPLICATED_LINES_KEY, 4d);
- assertRawMeasureValueOnPeriod(MODULE_REF, NEW_DUPLICATED_LINES_KEY, 6d);
assertRawMeasureValueOnPeriod(ROOT_REF, NEW_DUPLICATED_LINES_KEY, 6d);
}
assertRawMeasureValueOnPeriod(FILE_3_REF, NEW_BLOCKS_DUPLICATED_KEY, 0);
assertRawMeasureValueOnPeriod(FILE_4_REF, NEW_BLOCKS_DUPLICATED_KEY, 6);
assertRawMeasureValueOnPeriod(DIRECTORY_REF, NEW_BLOCKS_DUPLICATED_KEY, 12);
- assertRawMeasureValueOnPeriod(SUB_MODULE_1_REF, NEW_BLOCKS_DUPLICATED_KEY, 12);
- assertRawMeasureValueOnPeriod(SUB_MODULE_2_REF, NEW_BLOCKS_DUPLICATED_KEY, 6);
- assertRawMeasureValueOnPeriod(MODULE_REF, NEW_BLOCKS_DUPLICATED_KEY, 18);
assertRawMeasureValueOnPeriod(ROOT_REF, NEW_BLOCKS_DUPLICATED_KEY, 18);
}
assertRawMeasureValue(FILE_4_REF, NEW_DUPLICATED_LINES_DENSITY_KEY, 100d);
assertRawMeasureValue(DIRECTORY_REF, NEW_DUPLICATED_LINES_DENSITY_KEY, 9.1d);
assertNoRawMeasure(DIRECTORY_2_REF, NEW_DUPLICATED_LINES_DENSITY_KEY);
- assertRawMeasureValue(SUB_MODULE_1_REF, NEW_DUPLICATED_LINES_DENSITY_KEY, 9.1d);
- assertRawMeasureValue(SUB_MODULE_2_REF, NEW_DUPLICATED_LINES_DENSITY_KEY, 100d);
- assertRawMeasureValue(MODULE_REF, NEW_DUPLICATED_LINES_DENSITY_KEY, 39.4d);
assertRawMeasureValue(ROOT_REF, NEW_DUPLICATED_LINES_DENSITY_KEY, 39.4d);
}
assertRawMeasureValueOnPeriod(FILE_3_REF, metricKey, 0);
assertRawMeasureValueOnPeriod(FILE_4_REF, metricKey, 0);
assertRawMeasureValueOnPeriod(DIRECTORY_REF, metricKey, 0);
- assertRawMeasureValueOnPeriod(SUB_MODULE_1_REF, metricKey, 0);
- assertRawMeasureValueOnPeriod(SUB_MODULE_2_REF, metricKey, 0);
- assertRawMeasureValueOnPeriod(MODULE_REF, metricKey, 0);
assertRawMeasureValueOnPeriod(ROOT_REF, metricKey, 0);
}
assertThat(measureRepository.getAddedRawMeasures(FILE_3_REF).get(metricKey)).isEmpty();
assertThat(measureRepository.getAddedRawMeasures(FILE_4_REF).get(metricKey)).isEmpty();
assertThat(measureRepository.getAddedRawMeasures(DIRECTORY_REF).get(metricKey)).isEmpty();
- assertThat(measureRepository.getAddedRawMeasures(SUB_MODULE_1_REF).get(metricKey)).isEmpty();
- assertThat(measureRepository.getAddedRawMeasures(SUB_MODULE_2_REF).get(metricKey)).isEmpty();
- assertThat(measureRepository.getAddedRawMeasures(MODULE_REF).get(metricKey)).isEmpty();
assertThat(measureRepository.getAddedRawMeasures(ROOT_REF).get(metricKey)).isEmpty();
}
}
import static org.mockito.Mockito.when;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.DIRECTORY;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.FILE;
-import static org.sonar.ce.task.projectanalysis.component.Component.Type.MODULE;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT;
import static org.sonar.ce.task.projectanalysis.component.ReportComponent.builder;
import static org.sonar.db.event.EventDto.CATEGORY_ALERT;
.setUuid("ABCD")
.setProjectVersion("version_1")
.addChildren(
- builder(MODULE, 2)
+ builder(DIRECTORY, 2)
.setUuid("BCDE")
.addChildren(
builder(DIRECTORY, 3)
.setUuid("ABCD")
.setProjectVersion("1.0")
.addChildren(
- builder(MODULE, 2)
+ builder(DIRECTORY, 2)
.setUuid("BCDE")
.addChildren(
builder(DIRECTORY, 3)
.setUuid(projectDto.uuid())
.setProjectVersion("1.5-SNAPSHOT")
.addChildren(
- builder(MODULE, 2)
+ builder(DIRECTORY, 2)
.setUuid("BCDE")
.addChildren(
builder(DIRECTORY, 3)
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.DIRECTORY;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.FILE;
-import static org.sonar.ce.task.projectanalysis.component.Component.Type.MODULE;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT_VIEW;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.SUBVIEW;
// the computed measures
measureRepository.addRawMeasure(REF_1, STRING_METRIC.getKey(), newMeasureBuilder().create("project-value"));
- measureRepository.addRawMeasure(REF_2, STRING_METRIC.getKey(), newMeasureBuilder().create("module-value"));
measureRepository.addRawMeasure(REF_3, STRING_METRIC.getKey(), newMeasureBuilder().create("dir-value"));
measureRepository.addRawMeasure(REF_4, STRING_METRIC.getKey(), newMeasureBuilder().create("file-value"));
step().execute(context);
// all measures are persisted, from project to file
- assertThat(db.countRowsOfTable("live_measures")).isEqualTo(4);
+ assertThat(db.countRowsOfTable("live_measures")).isEqualTo(3);
assertThat(selectMeasure("project-uuid", STRING_METRIC).get().getDataAsString()).isEqualTo("project-value");
- assertThat(selectMeasure("module-uuid", STRING_METRIC).get().getDataAsString()).isEqualTo("module-value");
assertThat(selectMeasure("dir-uuid", STRING_METRIC).get().getDataAsString()).isEqualTo("dir-value");
assertThat(selectMeasure("file-uuid", STRING_METRIC).get().getDataAsString()).isEqualTo("file-value");
- verifyStatistics(context, 4);
+ verifyStatistics(context, 3);
}
@Test
private void assertThatMeasureDoesNotExist(LiveMeasureDto template) {
assertThat(dbClient.liveMeasureDao().selectMeasure(db.getSession(),
template.getComponentUuid(), metricRepository.getById(template.getMetricId()).getKey()))
- .isEmpty();
+ .isEmpty();
}
private void prepareProject() {
// tree of components as defined by scanner report
Component project = ReportComponent.builder(PROJECT, REF_1).setUuid("project-uuid")
.addChildren(
- ReportComponent.builder(MODULE, REF_2).setUuid("module-uuid")
+ ReportComponent.builder(DIRECTORY, REF_3).setUuid("dir-uuid")
.addChildren(
- ReportComponent.builder(DIRECTORY, REF_3).setUuid("dir-uuid")
- .addChildren(
- ReportComponent.builder(FILE, REF_4).setUuid("file-uuid")
- .build())
+ ReportComponent.builder(FILE, REF_4).setUuid("file-uuid")
.build())
.build())
.build();
// components as persisted in db
ComponentDto projectDto = insertComponent("project-key", "project-uuid");
- ComponentDto moduleDto = insertComponent("module-key", "module-uuid");
ComponentDto dirDto = insertComponent("dir-key", "dir-uuid");
ComponentDto fileDto = insertComponent("file-key", "file-uuid");
}
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.DIRECTORY;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.FILE;
-import static org.sonar.ce.task.projectanalysis.component.Component.Type.MODULE;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT_VIEW;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.SUBVIEW;
// the computed measures
measureRepository.addRawMeasure(REF_1, STRING_METRIC.getKey(), newMeasureBuilder().create("project-value"));
- measureRepository.addRawMeasure(REF_2, STRING_METRIC.getKey(), newMeasureBuilder().create("module-value"));
measureRepository.addRawMeasure(REF_3, STRING_METRIC.getKey(), newMeasureBuilder().create("dir-value"));
measureRepository.addRawMeasure(REF_4, STRING_METRIC.getKey(), newMeasureBuilder().create("file-value"));
TestComputationStepContext context = execute(true);
- // project, module and dir measures are persisted, but not file measures
- assertThat(db.countRowsOfTable("project_measures")).isEqualTo(3);
+ // project and dir measures are persisted, but not file measures
+ assertThat(db.countRowsOfTable("project_measures")).isEqualTo(2);
assertThat(selectMeasure("project-uuid", STRING_METRIC).get().getData()).isEqualTo("project-value");
- assertThat(selectMeasure("module-uuid", STRING_METRIC).get().getData()).isEqualTo("module-value");
assertThat(selectMeasure("dir-uuid", STRING_METRIC).get().getData()).isEqualTo("dir-value");
assertThatMeasuresAreNotPersisted("file-uuid");
- assertNbOfInserts(context, 3);
+ assertNbOfInserts(context, 2);
}
@Test
// the computed measures
measureRepository.addRawMeasure(REF_1, STRING_METRIC.getKey(), newMeasureBuilder().create("project-value"));
- measureRepository.addRawMeasure(REF_2, STRING_METRIC.getKey(), newMeasureBuilder().create("module-value"));
measureRepository.addRawMeasure(REF_3, STRING_METRIC.getKey(), newMeasureBuilder().create("dir-value"));
measureRepository.addRawMeasure(REF_4, STRING_METRIC.getKey(), newMeasureBuilder().create("file-value"));
TestComputationStepContext context = execute(false);
- // project, module and dir measures are persisted, but not file measures
- assertThat(db.countRowsOfTable("project_measures")).isEqualTo(2);
+ // project and dir measures are persisted, but not file measures
+ assertThat(db.countRowsOfTable("project_measures")).isEqualTo(1);
assertThat(selectMeasure("project-uuid", STRING_METRIC).get().getData()).isEqualTo("project-value");
- assertThat(selectMeasure("module-uuid", STRING_METRIC).get().getData()).isEqualTo("module-value");
assertThatMeasuresAreNotPersisted("dir-uuid");
assertThatMeasuresAreNotPersisted("file-uuid");
- assertNbOfInserts(context, 2);
+ assertNbOfInserts(context, 1);
}
@Test
measureRepository.addRawMeasure(REF_1, STRING_METRIC.getKey(), newMeasureBuilder().createNoValue());
measureRepository.addRawMeasure(REF_1, INT_METRIC.getKey(), newMeasureBuilder().createNoValue());
- TestComputationStepContext context = execute(false);
+ TestComputationStepContext context = execute(false);
assertThatMeasureIsNotPersisted("project-uuid", STRING_METRIC);
assertThatMeasureIsNotPersisted("project-uuid", INT_METRIC);
measureRepository.addRawMeasure(REF_2, STRING_METRIC.getKey(), newMeasureBuilder().create("subview-value"));
measureRepository.addRawMeasure(REF_3, STRING_METRIC.getKey(), newMeasureBuilder().create("project-value"));
- TestComputationStepContext context = execute(true);
+ TestComputationStepContext context = execute(true);
assertThat(db.countRowsOfTable("project_measures")).isEqualTo(2);
assertThat(selectMeasure("view-uuid", STRING_METRIC).get().getData()).isEqualTo("view-value");
// tree of components as defined by scanner report
Component project = ReportComponent.builder(PROJECT, REF_1).setUuid("project-uuid")
.addChildren(
- ReportComponent.builder(MODULE, REF_2).setUuid("module-uuid")
+ ReportComponent.builder(DIRECTORY, REF_3).setUuid("dir-uuid")
.addChildren(
- ReportComponent.builder(DIRECTORY, REF_3).setUuid("dir-uuid")
- .addChildren(
- ReportComponent.builder(FILE, REF_4).setUuid("file-uuid")
- .build())
+ ReportComponent.builder(FILE, REF_4).setUuid("file-uuid")
.build())
.build())
.build();
// components as persisted in db
ComponentDto projectDto = insertComponent("project-key", "project-uuid");
- ComponentDto moduleDto = insertComponent("module-key", "module-uuid");
ComponentDto dirDto = insertComponent("dir-key", "dir-uuid");
ComponentDto fileDto = insertComponent("file-key", "file-uuid");
db.components().insertSnapshot(projectDto, s -> s.setUuid(ANALYSIS_UUID));
@Test
public void add_links_on_project() {
mockBranch(true);
- treeRootHolder.setRoot(ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").addChildren(
- ReportComponent.builder(Component.Type.MODULE, 2).setUuid("BCDE").build())
- .build());
+ treeRootHolder.setRoot(ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").build());
// project
reportReader.putComponent(ScannerReport.Component.newBuilder()
@Test
public void do_not_add_links_on_module() {
mockBranch(true);
- treeRootHolder.setRoot(ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").addChildren(
- ReportComponent.builder(Component.Type.MODULE, 2).setUuid("BCDE").build())
- .build());
+ treeRootHolder.setRoot(ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").build());
reportReader.putComponent(ScannerReport.Component.newBuilder()
.setRef(1)
.setType(ComponentType.PROJECT)
underTest = new PersistTestsStep(dbClient, system2, reportReader, treeRootHolder);
root = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid(PROJECT_UUID).setKey(PROJECT_KEY).addChildren(
- ReportComponent.builder(Component.Type.MODULE, 2).setUuid("MODULE_UUID").setKey("MODULE_KEY").addChildren(
- ReportComponent.builder(Component.Type.FILE, 3).setUuid(TEST_FILE_UUID_1).setKey("TEST_FILE1_KEY").setFileAttributes(new FileAttributes(true, null, 1)).build(),
- ReportComponent.builder(Component.Type.FILE, 4).setUuid(TEST_FILE_UUID_2).setKey("TEST_FILE2_KEY").setFileAttributes(new FileAttributes(true, null, 1)).build(),
- ReportComponent.builder(Component.Type.FILE, 5).setUuid(MAIN_FILE_UUID_1).setKey("MAIN_FILE1_KEY").build(),
- ReportComponent.builder(Component.Type.FILE, 6).setUuid(MAIN_FILE_UUID_2).setKey("MAIN_FILE2_KEY").build()).build())
+ ReportComponent.builder(Component.Type.FILE, 3).setUuid(TEST_FILE_UUID_1).setKey("TEST_FILE1_KEY").setFileAttributes(new FileAttributes(true, null, 1)).build(),
+ ReportComponent.builder(Component.Type.FILE, 4).setUuid(TEST_FILE_UUID_2).setKey("TEST_FILE2_KEY").setFileAttributes(new FileAttributes(true, null, 1)).build(),
+ ReportComponent.builder(Component.Type.FILE, 5).setUuid(MAIN_FILE_UUID_1).setKey("MAIN_FILE1_KEY").build(),
+ ReportComponent.builder(Component.Type.FILE, 6).setUuid(MAIN_FILE_UUID_2).setKey("MAIN_FILE2_KEY").build())
.build();
treeRootHolder.setRoot(root);
}
.setUuid("uuid 1")
.setKey("key 1")
.setProjectVersion("V1.9")
- .addChildren(ReportComponent.builder(Component.Type.MODULE, 2).build())
+ .addChildren(ReportComponent.builder(Component.Type.DIRECTORY, 2).build())
.build();
private static final String INVALID_ALERT_STATUS = "trololo";
private static final String ALERT_TEXT = "alert text";
*/
package org.sonar.ce.task.projectanalysis.step;
-import java.util.Optional;
import java.util.Collections;
import java.util.Map;
import java.util.Objects;
+import java.util.Optional;
import javax.annotation.Nullable;
import org.assertj.core.api.AbstractAssert;
import org.junit.Before;
@Test
public void no_measure_if_tree_has_no_project() {
- ReportComponent notAProjectComponent = ReportComponent.builder(Component.Type.MODULE, 1).build();
+ ReportComponent notAProjectComponent = ReportComponent.builder(Component.Type.DIRECTORY, 1).build();
treeRootHolder.setRoot(notAProjectComponent);
import static org.sonar.api.measures.CoreMetrics.PUBLIC_UNDOCUMENTED_API_KEY;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.DIRECTORY;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.FILE;
-import static org.sonar.ce.task.projectanalysis.component.Component.Type.MODULE;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT;
import static org.sonar.ce.task.projectanalysis.component.ReportComponent.builder;
import static org.sonar.ce.task.projectanalysis.measure.Measure.newMeasureBuilder;
public class ReportCommentMeasuresStepTest {
private static final int ROOT_REF = 1;
- private static final int MODULE_REF = 12;
- private static final int SUB_MODULE_REF = 123;
private static final int DIRECTORY_REF = 1234;
private static final int FILE_1_REF = 12341;
private static final int FILE_2_REF = 12342;
treeRootHolder.setRoot(
builder(PROJECT, ROOT_REF)
.addChildren(
- builder(MODULE, MODULE_REF)
+ builder(DIRECTORY, DIRECTORY_REF)
.addChildren(
- builder(MODULE, SUB_MODULE_REF)
- .addChildren(
- builder(DIRECTORY, DIRECTORY_REF)
- .addChildren(
- builder(FILE, FILE_1_REF).build(),
- builder(FILE, FILE_2_REF).build())
- .build())
- .build())
+ builder(FILE, FILE_1_REF).build(),
+ builder(FILE, FILE_2_REF).build())
.build())
.build());
}
assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, COMMENTED_OUT_CODE_LINES_KEY)).isNotPresent();
assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, COMMENTED_OUT_CODE_LINES_KEY)).isNotPresent();
assertThat(measureRepository.getAddedRawMeasure(DIRECTORY_REF, COMMENTED_OUT_CODE_LINES_KEY).get().getIntValue()).isEqualTo(500);
- assertThat(measureRepository.getAddedRawMeasure(SUB_MODULE_REF, COMMENTED_OUT_CODE_LINES_KEY).get().getIntValue()).isEqualTo(500);
- assertThat(measureRepository.getAddedRawMeasure(MODULE_REF, COMMENTED_OUT_CODE_LINES_KEY).get().getIntValue()).isEqualTo(500);
assertThat(measureRepository.getAddedRawMeasure(ROOT_REF, COMMENTED_OUT_CODE_LINES_KEY).get().getIntValue()).isEqualTo(500);
}
assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, COMMENT_LINES_KEY)).isNotPresent();
assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, COMMENT_LINES_KEY)).isNotPresent();
assertThat(measureRepository.getAddedRawMeasure(DIRECTORY_REF, COMMENT_LINES_KEY).get().getIntValue()).isEqualTo(500);
- assertThat(measureRepository.getAddedRawMeasure(SUB_MODULE_REF, COMMENT_LINES_KEY).get().getIntValue()).isEqualTo(500);
- assertThat(measureRepository.getAddedRawMeasure(MODULE_REF, COMMENT_LINES_KEY).get().getIntValue()).isEqualTo(500);
assertThat(measureRepository.getAddedRawMeasure(ROOT_REF, COMMENT_LINES_KEY).get().getIntValue()).isEqualTo(500);
}
measureRepository.addRawMeasure(FILE_2_REF, COMMENT_LINES_KEY, newMeasureBuilder().create(50));
measureRepository.addRawMeasure(DIRECTORY_REF, NCLOC_KEY, newMeasureBuilder().create(300));
- measureRepository.addRawMeasure(SUB_MODULE_REF, NCLOC_KEY, newMeasureBuilder().create(300));
- measureRepository.addRawMeasure(MODULE_REF, NCLOC_KEY, newMeasureBuilder().create(300));
measureRepository.addRawMeasure(ROOT_REF, NCLOC_KEY, newMeasureBuilder().create(300));
underTest.execute(new TestComputationStepContext());
assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, COMMENT_LINES_DENSITY_KEY).get().getDoubleValue()).isEqualTo(60d);
assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, COMMENT_LINES_DENSITY_KEY).get().getDoubleValue()).isEqualTo(20d);
assertThat(measureRepository.getAddedRawMeasure(DIRECTORY_REF, COMMENT_LINES_DENSITY_KEY).get().getDoubleValue()).isEqualTo(40d);
- assertThat(measureRepository.getAddedRawMeasure(SUB_MODULE_REF, COMMENT_LINES_DENSITY_KEY).get().getDoubleValue()).isEqualTo(40d);
- assertThat(measureRepository.getAddedRawMeasure(MODULE_REF, COMMENT_LINES_DENSITY_KEY).get().getDoubleValue()).isEqualTo(40d);
assertThat(measureRepository.getAddedRawMeasure(ROOT_REF, COMMENT_LINES_DENSITY_KEY).get().getDoubleValue()).isEqualTo(40d);
}
measureRepository.addRawMeasure(FILE_2_REF, COMMENT_LINES_KEY, newMeasureBuilder().create(0));
measureRepository.addRawMeasure(DIRECTORY_REF, NCLOC_KEY, newMeasureBuilder().create(300));
- measureRepository.addRawMeasure(SUB_MODULE_REF, NCLOC_KEY, newMeasureBuilder().create(300));
- measureRepository.addRawMeasure(MODULE_REF, NCLOC_KEY, newMeasureBuilder().create(300));
measureRepository.addRawMeasure(ROOT_REF, NCLOC_KEY, newMeasureBuilder().create(300));
underTest.execute(new TestComputationStepContext());
assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, COMMENT_LINES_DENSITY_KEY).get().getDoubleValue()).isEqualTo(0d);
assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, COMMENT_LINES_DENSITY_KEY).get().getDoubleValue()).isEqualTo(0d);
assertThat(measureRepository.getAddedRawMeasure(DIRECTORY_REF, COMMENT_LINES_DENSITY_KEY).get().getDoubleValue()).isEqualTo(0d);
- assertThat(measureRepository.getAddedRawMeasure(SUB_MODULE_REF, COMMENT_LINES_DENSITY_KEY).get().getDoubleValue()).isEqualTo(0d);
- assertThat(measureRepository.getAddedRawMeasure(MODULE_REF, COMMENT_LINES_DENSITY_KEY).get().getDoubleValue()).isEqualTo(0d);
assertThat(measureRepository.getAddedRawMeasure(ROOT_REF, COMMENT_LINES_DENSITY_KEY).get().getDoubleValue()).isEqualTo(0d);
}
measureRepository.addRawMeasure(FILE_2_REF, COMMENT_LINES_KEY, newMeasureBuilder().create(0));
measureRepository.addRawMeasure(DIRECTORY_REF, NCLOC_KEY, newMeasureBuilder().create(0));
- measureRepository.addRawMeasure(SUB_MODULE_REF, NCLOC_KEY, newMeasureBuilder().create(0));
- measureRepository.addRawMeasure(MODULE_REF, NCLOC_KEY, newMeasureBuilder().create(0));
measureRepository.addRawMeasure(ROOT_REF, NCLOC_KEY, newMeasureBuilder().create(0));
underTest.execute(new TestComputationStepContext());
measureRepository.addRawMeasure(FILE_1_REF, NCLOC_KEY, newMeasureBuilder().create(100));
measureRepository.addRawMeasure(FILE_2_REF, NCLOC_KEY, newMeasureBuilder().create(100));
measureRepository.addRawMeasure(DIRECTORY_REF, NCLOC_KEY, newMeasureBuilder().create(200));
- measureRepository.addRawMeasure(SUB_MODULE_REF, NCLOC_KEY, newMeasureBuilder().create(200));
- measureRepository.addRawMeasure(MODULE_REF, NCLOC_KEY, newMeasureBuilder().create(200));
measureRepository.addRawMeasure(ROOT_REF, NCLOC_KEY, newMeasureBuilder().create(200));
underTest.execute(new TestComputationStepContext());
assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, PUBLIC_API_KEY)).isNotPresent();
assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, PUBLIC_API_KEY)).isNotPresent();
assertThat(measureRepository.getAddedRawMeasure(DIRECTORY_REF, PUBLIC_API_KEY).get().getIntValue()).isEqualTo(500);
- assertThat(measureRepository.getAddedRawMeasure(SUB_MODULE_REF, PUBLIC_API_KEY).get().getIntValue()).isEqualTo(500);
- assertThat(measureRepository.getAddedRawMeasure(MODULE_REF, PUBLIC_API_KEY).get().getIntValue()).isEqualTo(500);
assertThat(measureRepository.getAddedRawMeasure(ROOT_REF, PUBLIC_API_KEY).get().getIntValue()).isEqualTo(500);
}
assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, PUBLIC_UNDOCUMENTED_API_KEY)).isNotPresent();
assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, PUBLIC_UNDOCUMENTED_API_KEY)).isNotPresent();
assertThat(measureRepository.getAddedRawMeasure(DIRECTORY_REF, PUBLIC_UNDOCUMENTED_API_KEY).get().getIntValue()).isEqualTo(500);
- assertThat(measureRepository.getAddedRawMeasure(SUB_MODULE_REF, PUBLIC_UNDOCUMENTED_API_KEY).get().getIntValue()).isEqualTo(500);
- assertThat(measureRepository.getAddedRawMeasure(MODULE_REF, PUBLIC_UNDOCUMENTED_API_KEY).get().getIntValue()).isEqualTo(500);
assertThat(measureRepository.getAddedRawMeasure(ROOT_REF, PUBLIC_UNDOCUMENTED_API_KEY).get().getIntValue()).isEqualTo(500);
}
assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, PUBLIC_DOCUMENTED_API_DENSITY_KEY).get().getDoubleValue()).isEqualTo(50d);
assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, PUBLIC_DOCUMENTED_API_DENSITY_KEY).get().getDoubleValue()).isEqualTo(75d);
assertThat(measureRepository.getAddedRawMeasure(DIRECTORY_REF, PUBLIC_DOCUMENTED_API_DENSITY_KEY).get().getDoubleValue()).isEqualTo(70d);
- assertThat(measureRepository.getAddedRawMeasure(SUB_MODULE_REF, PUBLIC_DOCUMENTED_API_DENSITY_KEY).get().getDoubleValue()).isEqualTo(70d);
- assertThat(measureRepository.getAddedRawMeasure(MODULE_REF, PUBLIC_DOCUMENTED_API_DENSITY_KEY).get().getDoubleValue()).isEqualTo(70d);
assertThat(measureRepository.getAddedRawMeasure(ROOT_REF, PUBLIC_DOCUMENTED_API_DENSITY_KEY).get().getDoubleValue()).isEqualTo(70d);
}
assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, PUBLIC_DOCUMENTED_API_DENSITY_KEY).get().getDoubleValue()).isEqualTo(100d);
assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, PUBLIC_DOCUMENTED_API_DENSITY_KEY).get().getDoubleValue()).isEqualTo(100d);
assertThat(measureRepository.getAddedRawMeasure(DIRECTORY_REF, PUBLIC_DOCUMENTED_API_DENSITY_KEY).get().getDoubleValue()).isEqualTo(100d);
- assertThat(measureRepository.getAddedRawMeasure(SUB_MODULE_REF, PUBLIC_DOCUMENTED_API_DENSITY_KEY).get().getDoubleValue()).isEqualTo(100d);
- assertThat(measureRepository.getAddedRawMeasure(MODULE_REF, PUBLIC_DOCUMENTED_API_DENSITY_KEY).get().getDoubleValue()).isEqualTo(100d);
assertThat(measureRepository.getAddedRawMeasure(ROOT_REF, PUBLIC_DOCUMENTED_API_DENSITY_KEY).get().getDoubleValue()).isEqualTo(100d);
}
assertThat(measureRepository.getAddedRawMeasures(FILE_1_REF)).isEmpty();
assertThat(measureRepository.getAddedRawMeasures(FILE_2_REF)).isEmpty();
assertThat(measureRepository.getAddedRawMeasures(DIRECTORY_REF)).isEmpty();
- assertThat(measureRepository.getAddedRawMeasures(SUB_MODULE_REF)).isEmpty();
- assertThat(measureRepository.getAddedRawMeasures(MODULE_REF)).isEmpty();
assertThat(measureRepository.getAddedRawMeasures(ROOT_REF)).isEmpty();
}
assertThat(measureRepository.getAddedRawMeasures(FILE_1_REF).get(metric)).isEmpty();
assertThat(measureRepository.getAddedRawMeasures(FILE_2_REF).get(metric)).isEmpty();
assertThat(measureRepository.getAddedRawMeasures(DIRECTORY_REF).get(metric)).isEmpty();
- assertThat(measureRepository.getAddedRawMeasures(SUB_MODULE_REF).get(metric)).isEmpty();
- assertThat(measureRepository.getAddedRawMeasures(MODULE_REF).get(metric)).isEmpty();
assertThat(measureRepository.getAddedRawMeasures(ROOT_REF).get(metric)).isEmpty();
}
}
import static org.sonar.api.measures.CoreMetrics.FUNCTION_COMPLEXITY_KEY;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.DIRECTORY;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.FILE;
-import static org.sonar.ce.task.projectanalysis.component.Component.Type.MODULE;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT;
import static org.sonar.ce.task.projectanalysis.component.ReportComponent.builder;
import static org.sonar.ce.task.projectanalysis.measure.Measure.newMeasureBuilder;
public class ReportComplexityMeasuresStepTest {
private static final int ROOT_REF = 1;
- private static final int MODULE_REF = 11;
- private static final int SUB_MODULE_REF = 111;
private static final int DIRECTORY_REF = 1111;
private static final int FILE_1_REF = 11111;
private static final int FILE_2_REF = 11121;
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule()
.setRoot(builder(PROJECT, ROOT_REF)
.addChildren(
- builder(MODULE, MODULE_REF)
+ builder(DIRECTORY, DIRECTORY_REF)
.addChildren(
- builder(MODULE, SUB_MODULE_REF)
- .addChildren(
- builder(DIRECTORY, DIRECTORY_REF)
- .addChildren(
- builder(FILE, FILE_1_REF).build(),
- builder(FILE, FILE_2_REF).build())
- .build())
- .build())
+ builder(FILE, FILE_1_REF).build(),
+ builder(FILE, FILE_2_REF).build())
.build())
.build());
@Rule
int expectedNonFileValue = 50;
assertThat(toEntries(measureRepository.getAddedRawMeasures(DIRECTORY_REF))).contains(entryOf(metricKey, newMeasureBuilder().create(expectedNonFileValue)));
- assertThat(toEntries(measureRepository.getAddedRawMeasures(SUB_MODULE_REF))).contains(entryOf(metricKey, newMeasureBuilder().create(expectedNonFileValue)));
- assertThat(toEntries(measureRepository.getAddedRawMeasures(MODULE_REF))).contains(entryOf(metricKey, newMeasureBuilder().create(expectedNonFileValue)));
assertThat(toEntries(measureRepository.getAddedRawMeasures(ROOT_REF))).contains(entryOf(metricKey, newMeasureBuilder().create(expectedNonFileValue)));
}
String expectedNonFileValue = "0.5=3;3.5=7;6.5=10";
assertThat(toEntries(measureRepository.getAddedRawMeasures(DIRECTORY_REF))).contains(entryOf(metricKey, newMeasureBuilder().create(expectedNonFileValue)));
- assertThat(toEntries(measureRepository.getAddedRawMeasures(SUB_MODULE_REF))).contains(entryOf(metricKey, newMeasureBuilder().create(expectedNonFileValue)));
- assertThat(toEntries(measureRepository.getAddedRawMeasures(MODULE_REF))).contains(entryOf(metricKey, newMeasureBuilder().create(expectedNonFileValue)));
assertThat(toEntries(measureRepository.getAddedRawMeasures(ROOT_REF))).contains(entryOf(metricKey, newMeasureBuilder().create(expectedNonFileValue)));
}
double expectedNonFileValue = 2d;
assertThat(toEntries(measureRepository.getAddedRawMeasures(DIRECTORY_REF))).contains(entryOf(metricKey, newMeasureBuilder().create(expectedNonFileValue, 1)));
- assertThat(toEntries(measureRepository.getAddedRawMeasures(SUB_MODULE_REF))).contains(entryOf(metricKey, newMeasureBuilder().create(expectedNonFileValue, 1)));
- assertThat(toEntries(measureRepository.getAddedRawMeasures(MODULE_REF))).contains(entryOf(metricKey, newMeasureBuilder().create(expectedNonFileValue, 1)));
assertThat(toEntries(measureRepository.getAddedRawMeasures(ROOT_REF))).contains(entryOf(metricKey, newMeasureBuilder().create(expectedNonFileValue, 1)));
}
import static org.assertj.core.api.Assertions.assertThat;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.DIRECTORY;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.FILE;
-import static org.sonar.ce.task.projectanalysis.component.Component.Type.MODULE;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT;
import static org.sonar.ce.task.projectanalysis.component.ReportComponent.builder;
import static org.sonar.ce.task.projectanalysis.measure.Measure.newMeasureBuilder;
public class ReportCoverageMeasuresStepTest {
private static final int ROOT_REF = 1;
- private static final int MODULE_REF = 12;
- private static final int SUB_MODULE_REF = 123;
private static final int DIRECTORY_REF = 1234;
private static final int FILE_1_REF = 12341;
private static final int UNIT_TEST_FILE_REF = 12342;
treeRootHolder.setRoot(
builder(PROJECT, ROOT_REF)
.addChildren(
- builder(MODULE, MODULE_REF)
+ builder(DIRECTORY, DIRECTORY_REF)
.addChildren(
- builder(MODULE, SUB_MODULE_REF)
- .addChildren(
- builder(DIRECTORY, DIRECTORY_REF)
- .addChildren(
- builder(FILE, FILE_1_REF).build(),
- builder(FILE, UNIT_TEST_FILE_REF).setFileAttributes(new FileAttributes(true, "some language", 1)).build(),
- builder(FILE, FILE_2_REF).build())
- .build())
- .build())
+ builder(FILE, FILE_1_REF).build(),
+ builder(FILE, UNIT_TEST_FILE_REF).setFileAttributes(new FileAttributes(true, "some language", 1)).build(),
+ builder(FILE, FILE_2_REF).build())
.build())
.build());
}
};
assertThat(toEntries(measureRepository.getAddedRawMeasures(DIRECTORY_REF))).contains(nonFileRepoEntries);
- assertThat(toEntries(measureRepository.getAddedRawMeasures(SUB_MODULE_REF))).contains(nonFileRepoEntries);
- assertThat(toEntries(measureRepository.getAddedRawMeasures(MODULE_REF))).contains(nonFileRepoEntries);
assertThat(toEntries(measureRepository.getAddedRawMeasures(ROOT_REF))).contains(nonFileRepoEntries);
}
};
assertThat(toEntries(measureRepository.getAddedRawMeasures(DIRECTORY_REF))).contains(nonFileRepoEntries);
- assertThat(toEntries(measureRepository.getAddedRawMeasures(SUB_MODULE_REF))).contains(nonFileRepoEntries);
- assertThat(toEntries(measureRepository.getAddedRawMeasures(MODULE_REF))).contains(nonFileRepoEntries);
assertThat(toEntries(measureRepository.getAddedRawMeasures(ROOT_REF))).contains(nonFileRepoEntries);
}
import static org.sonar.api.measures.CoreMetrics.NCLOC_LANGUAGE_DISTRIBUTION_KEY;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.DIRECTORY;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.FILE;
-import static org.sonar.ce.task.projectanalysis.component.Component.Type.MODULE;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT;
import static org.sonar.ce.task.projectanalysis.component.ReportComponent.builder;
import static org.sonar.ce.task.projectanalysis.measure.Measure.newMeasureBuilder;
private static final String JAVA_LANGUAGE = "java";
private static final int ROOT_REF = 1;
- private static final int MODULE_REF = 12;
- private static final int SUB_MODULE_REF = 123;
private static final int DIRECTORY_REF = 1234;
private static final int FILE_1_REF = 12341;
private static final int FILE_2_REF = 12342;
treeRootHolder.setRoot(
builder(PROJECT, ROOT_REF)
.addChildren(
- builder(MODULE, MODULE_REF)
+ builder(DIRECTORY, DIRECTORY_REF)
.addChildren(
- builder(MODULE, SUB_MODULE_REF)
- .addChildren(
- builder(DIRECTORY, DIRECTORY_REF)
- .addChildren(
- builder(FILE, FILE_1_REF).setFileAttributes(new FileAttributes(false, XOO_LANGUAGE, 1)).build(),
- builder(FILE, FILE_2_REF).setFileAttributes(new FileAttributes(false, XOO_LANGUAGE, 1)).build(),
- builder(FILE, FILE_3_REF).setFileAttributes(new FileAttributes(false, JAVA_LANGUAGE, 1)).build(),
- builder(FILE, FILE_4_REF).setFileAttributes(new FileAttributes(false, null, 1)).build())
- .build())
- .build())
+ builder(FILE, FILE_1_REF).setFileAttributes(new FileAttributes(false, XOO_LANGUAGE, 1)).build(),
+ builder(FILE, FILE_2_REF).setFileAttributes(new FileAttributes(false, XOO_LANGUAGE, 1)).build(),
+ builder(FILE, FILE_3_REF).setFileAttributes(new FileAttributes(false, JAVA_LANGUAGE, 1)).build(),
+ builder(FILE, FILE_4_REF).setFileAttributes(new FileAttributes(false, null, 1)).build())
.build())
.build());
}
assertThat(measureRepository.getAddedRawMeasure(FILE_4_REF, NCLOC_LANGUAGE_DISTRIBUTION_KEY).get().getStringValue()).isEqualTo("<null>=2");
assertThat(measureRepository.getAddedRawMeasure(DIRECTORY_REF, NCLOC_LANGUAGE_DISTRIBUTION_KEY).get().getStringValue()).isEqualTo("<null>=2;java=6;xoo=18");
- assertThat(measureRepository.getAddedRawMeasure(SUB_MODULE_REF, NCLOC_LANGUAGE_DISTRIBUTION_KEY).get().getStringValue()).isEqualTo("<null>=2;java=6;xoo=18");
- assertThat(measureRepository.getAddedRawMeasure(MODULE_REF, NCLOC_LANGUAGE_DISTRIBUTION_KEY).get().getStringValue()).isEqualTo("<null>=2;java=6;xoo=18");
assertThat(measureRepository.getAddedRawMeasure(ROOT_REF, NCLOC_LANGUAGE_DISTRIBUTION_KEY).get().getStringValue()).isEqualTo("<null>=2;java=6;xoo=18");
}
assertThat(measureRepository.getAddedRawMeasure(FILE_4_REF, NCLOC_LANGUAGE_DISTRIBUTION_KEY)).isNotPresent();
assertThat(measureRepository.getAddedRawMeasure(DIRECTORY_REF, NCLOC_LANGUAGE_DISTRIBUTION_KEY)).isNotPresent();
- assertThat(measureRepository.getAddedRawMeasure(SUB_MODULE_REF, NCLOC_LANGUAGE_DISTRIBUTION_KEY)).isNotPresent();
- assertThat(measureRepository.getAddedRawMeasure(MODULE_REF, NCLOC_LANGUAGE_DISTRIBUTION_KEY)).isNotPresent();
assertThat(measureRepository.getAddedRawMeasure(ROOT_REF, NCLOC_LANGUAGE_DISTRIBUTION_KEY)).isNotPresent();
}
import org.sonar.ce.task.projectanalysis.measure.MeasureRepoEntry;
import org.sonar.ce.task.projectanalysis.measure.MeasureRepositoryRule;
import org.sonar.ce.task.projectanalysis.metric.MetricRepositoryRule;
-import org.sonar.ce.task.projectanalysis.scm.Changeset;
import org.sonar.ce.task.projectanalysis.source.NewLinesRepository;
import org.sonar.ce.task.step.TestComputationStepContext;
import static org.sonar.api.measures.CoreMetrics.NEW_LINES_TO_COVER_KEY;
import static org.sonar.api.measures.CoreMetrics.NEW_UNCOVERED_CONDITIONS_KEY;
import static org.sonar.api.measures.CoreMetrics.NEW_UNCOVERED_LINES_KEY;
-import static org.sonar.api.utils.DateUtils.parseDate;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.DIRECTORY;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.FILE;
-import static org.sonar.ce.task.projectanalysis.component.Component.Type.MODULE;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT;
import static org.sonar.ce.task.projectanalysis.component.ReportComponent.builder;
import static org.sonar.ce.task.projectanalysis.measure.Measure.newMeasureBuilder;
public class ReportNewCoverageMeasuresStepTest {
private static final int ROOT_REF = 1;
- private static final int MODULE_REF = 11;
- private static final int SUB_MODULE_REF = 111;
private static final int DIRECTORY_1_REF = 1111;
private static final int FILE_1_REF = 11111;
private static final int DIRECTORY_2_REF = 1112;
private static final ReportComponent MULTIPLE_FILES_TREE = builder(PROJECT, ROOT_REF)
.addChildren(
- builder(MODULE, MODULE_REF)
- .addChildren(
- builder(MODULE, SUB_MODULE_REF)
- .addChildren(
- builder(DIRECTORY, DIRECTORY_1_REF)
- .addChildren(FILE_1)
- .build(),
- builder(DIRECTORY, DIRECTORY_2_REF)
- .addChildren(FILE_2, FILE_3)
- .build())
- .build())
+ builder(DIRECTORY, DIRECTORY_1_REF)
+ .addChildren(FILE_1)
+ .build(),
+ builder(DIRECTORY, DIRECTORY_2_REF)
+ .addChildren(FILE_2, FILE_3)
.build())
.build();
assertThat(measureRepository.isEmpty()).isTrue();
}
- @Test
- public void no_measure_for_MODULE_component() {
- treeRootHolder.setRoot(ReportComponent.builder(Component.Type.MODULE, MODULE_REF).build());
-
- underTest.execute(new TestComputationStepContext());
-
- assertThat(measureRepository.isEmpty()).isTrue();
- }
-
@Test
public void no_measure_for_DIRECTORY_component() {
treeRootHolder.setRoot(ReportComponent.builder(Component.Type.DIRECTORY, DIRECTORY_1_REF).build());
@Test
public void zero_measures_for_FILE_component_without_CoverageData() {
- treeRootHolder.setRoot(FILE_COMPONENT);
+ treeRootHolder.setRoot(FILE_1);
setNewLines(FILE_1);
underTest.execute(new TestComputationStepContext());
- verify_only_zero_measures_on_new_lines_and_conditions_measures(FILE_COMPONENT);
+ verify_only_zero_measures_on_new_lines_and_conditions_measures(FILE_1);
}
@Test
entryOf(metricKeys.newConditionsToCover, createMeasure(44d)),
entryOf(metricKeys.newUncoveredConditions, createMeasure(23d)));
// submodule
- MeasureRepoEntry[] repoEntriesFromSubModuleUp = {entryOf(metricKeys.newLinesToCover, createMeasure(15d)),
+ MeasureRepoEntry[] repoEntriesFromProject = {entryOf(metricKeys.newLinesToCover, createMeasure(15d)),
entryOf(metricKeys.newUncoveredLines, createMeasure(9d)),
entryOf(metricKeys.newConditionsToCover, createMeasure(51d)),
entryOf(metricKeys.newUncoveredConditions, createMeasure(27d))};
- assertThat(toEntries(measureRepository.getAddedRawMeasures(SUB_MODULE_REF))).contains(repoEntriesFromSubModuleUp);
- // module
- assertThat(toEntries(measureRepository.getAddedRawMeasures(MODULE_REF))).contains(repoEntriesFromSubModuleUp);
// project
- assertThat(toEntries(measureRepository.getAddedRawMeasures(ROOT_REF))).contains(repoEntriesFromSubModuleUp);
+ assertThat(toEntries(measureRepository.getAddedRawMeasures(ROOT_REF))).contains(repoEntriesFromProject);
}
@Test
entryOf(branchCoverageKey, createMeasure(96.4d))
};
- assertThat(toEntries(measureRepository.getAddedRawMeasures(SUB_MODULE_REF))).containsOnly(modulesAndProjectEntries);
- assertThat(toEntries(measureRepository.getAddedRawMeasures(MODULE_REF))).containsOnly(modulesAndProjectEntries);
assertThat(toEntries(measureRepository.getAddedRawMeasures(ROOT_REF))).containsOnly(modulesAndProjectEntries);
}
}
private void defineNewLinesAndMeasures(Component c, MetricKeys metricKeys, MeasureValues line4, MeasureValues line6) {
- setNewLines(c, 1, 2, 4,5,6,7);
- measureRepository.addRawMeasure(c.getReportAttributes().getRef(), metricKeys.coverageLineHitsData, newMeasureBuilder().create("2=0;3=2;4=" + line4.lineHits + ";5=1;6=" + line6.lineHits + ";7=0"));
- measureRepository.addRawMeasure(c.getReportAttributes().getRef(), metricKeys.conditionsByLine, newMeasureBuilder().create("4=" + line4.coveredConditions + ";6=" + line6.coveredConditions));
+ setNewLines(c, 1, 2, 4, 5, 6, 7);
+ measureRepository.addRawMeasure(c.getReportAttributes().getRef(), metricKeys.coverageLineHitsData,
+ newMeasureBuilder().create("2=0;3=2;4=" + line4.lineHits + ";5=1;6=" + line6.lineHits + ";7=0"));
+ measureRepository
+ .addRawMeasure(c.getReportAttributes().getRef(), metricKeys.conditionsByLine, newMeasureBuilder().create("4=" + line4.coveredConditions + ";6=" + line6.coveredConditions));
measureRepository.addRawMeasure(c.getReportAttributes().getRef(), metricKeys.coveredConditionsByLine,
newMeasureBuilder().create("4=" + line4.uncoveredConditions + ";6=" + line6.uncoveredConditions));
}
dbClient.componentDao().insert(dbTester.getSession(), fileDto);
dbTester.getSession().commit();
- Component file = ReportComponent.builder(Component.Type.FILE, 4).setUuid("DEFG").setKey("MODULE_KEY:src/main/java/dir/Foo.java").build();
- Component directory = ReportComponent.builder(Component.Type.DIRECTORY, 3).setUuid("CDEF").setKey("MODULE_KEY:src/main/java/dir").addChildren(file).build();
- Component module = ReportComponent.builder(Component.Type.MODULE, 2).setUuid("BCDE").setKey("MODULE_KEY").addChildren(directory).build();
- Component project = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").setKey(PROJECT_KEY).setProjectVersion("1.0").addChildren(module).build();
+ Component file = ReportComponent.builder(Component.Type.FILE, 3).setUuid("DEFG").setKey("MODULE_KEY:src/main/java/dir/Foo.java").build();
+ Component directory = ReportComponent.builder(Component.Type.DIRECTORY, 2).setUuid("CDEF").setKey("MODULE_KEY:src/main/java/dir").addChildren(file).build();
+ Component project = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").setKey(PROJECT_KEY).setProjectVersion("1.0").addChildren(directory).build();
treeRootHolder.setRoot(project);
dbIdsRepository.setComponentId(project, projectDto.getId());
- dbIdsRepository.setComponentId(module, moduleDto.getId());
dbIdsRepository.setComponentId(directory, directoryDto.getId());
dbIdsRepository.setComponentId(file, fileDto.getId());
assertThat(projectSnapshot.getCreatedAt()).isEqualTo(analysisDate);
assertThat(projectSnapshot.getBuildDate()).isEqualTo(now);
- assertThat(dbIdsRepository.getComponentId(module)).isEqualTo(moduleDto.getId());
assertThat(dbIdsRepository.getComponentId(directory)).isEqualTo(directoryDto.getId());
assertThat(dbIdsRepository.getComponentId(file)).isEqualTo(fileDto.getId());
}
dbTester.getSession().commit();
- Component file = ReportComponent.builder(Component.Type.FILE, 4).setUuid("DEFG").setKey("MODULE_KEY:src/main/java/dir/Foo.java").build();
- Component directory = ReportComponent.builder(Component.Type.DIRECTORY, 3).setUuid("CDEF").setKey("MODULE_KEY:src/main/java/dir").addChildren(file).build();
- Component module = ReportComponent.builder(Component.Type.MODULE, 2).setUuid("BCDE").setKey("MODULE_KEY").addChildren(directory).build();
- Component project = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").setKey(PROJECT_KEY).addChildren(module).build();
+ Component file = ReportComponent.builder(Component.Type.FILE, 3).setUuid("DEFG").setKey("MODULE_KEY:src/main/java/dir/Foo.java").build();
+ Component directory = ReportComponent.builder(Component.Type.DIRECTORY, 2).setUuid("CDEF").setKey("MODULE_KEY:src/main/java/dir").addChildren(file).build();
+ Component project = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").setKey(PROJECT_KEY).addChildren(directory).build();
treeRootHolder.setRoot(project);
dbIdsRepository.setComponentId(project, projectDto.getId());
- dbIdsRepository.setComponentId(module, moduleDto.getId());
dbIdsRepository.setComponentId(directory, directoryDto.getId());
dbIdsRepository.setComponentId(file, fileDto.getId());
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
private static final String PROJECT_KEY = "PROJECT_KEY";
- private static final String MODULE_KEY = "MODULE_KEY";
private static final String ORGANIZATION_UUID = "org1";
private static final String QUALITY_GATE_UUID = "gg1";
@Test
public void persist_components() {
ComponentDto projectDto = prepareProject();
- Component file = builder(FILE, 4).setUuid("DEFG").setKey("MODULE_KEY:src/main/java/dir/Foo.java")
+ Component file = builder(FILE, 4).setUuid("DEFG").setKey("PROJECT_KEY:src/main/java/dir/Foo.java")
.setPath("src/main/java/dir/Foo.java")
.setFileAttributes(new FileAttributes(false, "java", 1))
.build();
- Component directory = builder(DIRECTORY, 3).setUuid("CDEF").setKey("MODULE_KEY:src/main/java/dir")
+ Component directory = builder(DIRECTORY, 3).setUuid("CDEF").setKey("PROJECT_KEY:src/main/java/dir")
.setPath("src/main/java/dir")
.addChildren(file)
.build();
- Component module = builder(Component.Type.MODULE, 2).setUuid("BCDE").setKey(MODULE_KEY)
- .setPath("module")
- .setName("Module")
- .setDescription("Module description")
- .addChildren(directory)
- .build();
Component treeRoot = asTreeRoot(projectDto)
- .addChildren(module)
+ .addChildren(directory)
.build();
treeRootHolder.setRoot(treeRoot);
underTest.execute(new TestComputationStepContext());
- assertThat(db.countRowsOfTable("projects")).isEqualTo(4);
-
- ComponentDto moduleDto = dbClient.componentDao().selectByKey(db.getSession(), MODULE_KEY).get();
- assertThat(moduleDto.getOrganizationUuid()).isEqualTo(ORGANIZATION_UUID);
- assertThat(moduleDto.name()).isEqualTo("Module");
- assertThat(moduleDto.description()).isEqualTo("Module description");
- assertThat(moduleDto.path()).isEqualTo("module");
- assertThat(moduleDto.uuid()).isEqualTo("BCDE");
- assertThat(moduleDto.getUuidPath()).isEqualTo(projectDto.getUuidPath() + projectDto.uuid() + UUID_PATH_SEPARATOR);
- assertThat(moduleDto.moduleUuid()).isEqualTo(projectDto.uuid());
- assertThat(moduleDto.moduleUuidPath()).isEqualTo(projectDto.moduleUuidPath() + moduleDto.uuid() + ".");
- assertThat(moduleDto.getMainBranchProjectUuid()).isNull();
- assertThat(moduleDto.projectUuid()).isEqualTo(projectDto.uuid());
- assertThat(moduleDto.qualifier()).isEqualTo("BRC");
- assertThat(moduleDto.scope()).isEqualTo("PRJ");
- assertThat(moduleDto.getRootUuid()).isEqualTo(projectDto.uuid());
- assertThat(moduleDto.getCreatedAt()).isEqualTo(now);
-
- ComponentDto directoryDto = dbClient.componentDao().selectByKey(db.getSession(), "MODULE_KEY:src/main/java/dir").get();
+ assertThat(db.countRowsOfTable("projects")).isEqualTo(3);
+
+ ComponentDto directoryDto = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir").get();
assertThat(directoryDto.getOrganizationUuid()).isEqualTo(ORGANIZATION_UUID);
assertThat(directoryDto.name()).isEqualTo("src/main/java/dir");
assertThat(directoryDto.description()).isNull();
assertThat(directoryDto.path()).isEqualTo("src/main/java/dir");
assertThat(directoryDto.uuid()).isEqualTo("CDEF");
- assertThat(directoryDto.getUuidPath()).isEqualTo(moduleDto.getUuidPath() + moduleDto.uuid() + UUID_PATH_SEPARATOR);
- assertThat(directoryDto.moduleUuid()).isEqualTo(moduleDto.uuid());
- assertThat(directoryDto.moduleUuidPath()).isEqualTo(moduleDto.moduleUuidPath());
+ assertThat(directoryDto.getUuidPath()).isEqualTo(UUID_PATH_SEPARATOR + projectDto.uuid() + UUID_PATH_SEPARATOR);
+ assertThat(directoryDto.moduleUuid()).isEqualTo(projectDto.uuid());
+ assertThat(directoryDto.moduleUuidPath()).isEqualTo(projectDto.moduleUuidPath());
assertThat(directoryDto.getMainBranchProjectUuid()).isNull();
assertThat(directoryDto.projectUuid()).isEqualTo(projectDto.uuid());
assertThat(directoryDto.qualifier()).isEqualTo("DIR");
assertThat(directoryDto.scope()).isEqualTo("DIR");
- assertThat(directoryDto.getRootUuid()).isEqualTo(moduleDto.uuid());
+ assertThat(directoryDto.getRootUuid()).isEqualTo(projectDto.uuid());
assertThat(directoryDto.getCreatedAt()).isEqualTo(now);
- ComponentDto fileDto = dbClient.componentDao().selectByKey(db.getSession(), "MODULE_KEY:src/main/java/dir/Foo.java").get();
+ ComponentDto fileDto = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir/Foo.java").get();
assertThat(fileDto.getOrganizationUuid()).isEqualTo(ORGANIZATION_UUID);
assertThat(fileDto.name()).isEqualTo("Foo.java");
assertThat(fileDto.description()).isNull();
assertThat(fileDto.language()).isEqualTo("java");
assertThat(fileDto.uuid()).isEqualTo("DEFG");
assertThat(fileDto.getUuidPath()).isEqualTo(directoryDto.getUuidPath() + directoryDto.uuid() + UUID_PATH_SEPARATOR);
- assertThat(fileDto.moduleUuid()).isEqualTo(moduleDto.uuid());
- assertThat(fileDto.moduleUuidPath()).isEqualTo(moduleDto.moduleUuidPath());
+ assertThat(fileDto.moduleUuid()).isEqualTo(projectDto.uuid());
+ assertThat(fileDto.moduleUuidPath()).isEqualTo(projectDto.moduleUuidPath());
assertThat(fileDto.getMainBranchProjectUuid()).isNull();
assertThat(fileDto.projectUuid()).isEqualTo(projectDto.uuid());
assertThat(fileDto.qualifier()).isEqualTo("FIL");
assertThat(fileDto.scope()).isEqualTo("FIL");
- assertThat(fileDto.getRootUuid()).isEqualTo(moduleDto.uuid());
+ assertThat(fileDto.getRootUuid()).isEqualTo(projectDto.uuid());
assertThat(fileDto.getCreatedAt()).isEqualTo(now);
- assertThat(dbIdsRepository.getComponentId(module)).isEqualTo(moduleDto.getId());
assertThat(dbIdsRepository.getComponentId(directory)).isEqualTo(directoryDto.getId());
assertThat(dbIdsRepository.getComponentId(file)).isEqualTo(fileDto.getId());
}
@Test
public void persist_components_of_existing_branch() {
ComponentDto project = prepareBranch("feature/foo");
- Component file = builder(FILE, 4).setUuid("DEFG").setKey("MODULE_KEY:src/main/java/dir/Foo.java")
+ Component file = builder(FILE, 4).setUuid("DEFG").setKey("PROJECT_KEY:src/main/java/dir/Foo.java")
.setPath("src/main/java/dir/Foo.java")
.setFileAttributes(new FileAttributes(false, "java", 1))
.build();
- Component directory = builder(DIRECTORY, 3).setUuid("CDEF").setKey("MODULE_KEY:src/main/java/dir")
+ Component directory = builder(DIRECTORY, 3).setUuid("CDEF").setKey("PROJECT_KEY:src/main/java/dir")
.setPath("src/main/java/dir")
.addChildren(file)
.build();
- Component module = builder(Component.Type.MODULE, 2).setUuid("BCDE").setKey(MODULE_KEY)
- .setPath("module")
- .setName("Module")
- .setDescription("Module description")
- .addChildren(directory)
- .build();
Component treeRoot = asTreeRoot(project)
- .addChildren(module)
+ .addChildren(directory)
.build();
treeRootHolder.setRoot(treeRoot);
underTest.execute(new TestComputationStepContext());
- assertThat(db.countRowsOfTable("projects")).isEqualTo(4);
-
- ComponentDto moduleDto = dbClient.componentDao().selectByKey(db.getSession(), MODULE_KEY).get();
- assertThat(moduleDto.getOrganizationUuid()).isEqualTo(ORGANIZATION_UUID);
- assertThat(moduleDto.name()).isEqualTo("Module");
- assertThat(moduleDto.description()).isEqualTo("Module description");
- assertThat(moduleDto.path()).isEqualTo("module");
- assertThat(moduleDto.uuid()).isEqualTo("BCDE");
- assertThat(moduleDto.getUuidPath()).isEqualTo(project.getUuidPath() + project.uuid() + UUID_PATH_SEPARATOR);
- assertThat(moduleDto.moduleUuid()).isEqualTo(project.uuid());
- assertThat(moduleDto.moduleUuidPath()).isEqualTo(project.moduleUuidPath() + moduleDto.uuid() + ".");
- assertThat(moduleDto.getMainBranchProjectUuid()).isEqualTo(project.uuid());
- assertThat(moduleDto.projectUuid()).isEqualTo(project.uuid());
- assertThat(moduleDto.qualifier()).isEqualTo("BRC");
- assertThat(moduleDto.scope()).isEqualTo("PRJ");
- assertThat(moduleDto.getRootUuid()).isEqualTo(project.uuid());
- assertThat(moduleDto.getCreatedAt()).isEqualTo(now);
-
- ComponentDto directoryDto = dbClient.componentDao().selectByKey(db.getSession(), "MODULE_KEY:src/main/java/dir").get();
+ assertThat(db.countRowsOfTable("projects")).isEqualTo(3);
+
+ ComponentDto directoryDto = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir").get();
assertThat(directoryDto.getOrganizationUuid()).isEqualTo(ORGANIZATION_UUID);
assertThat(directoryDto.name()).isEqualTo("src/main/java/dir");
assertThat(directoryDto.description()).isNull();
assertThat(directoryDto.path()).isEqualTo("src/main/java/dir");
assertThat(directoryDto.uuid()).isEqualTo("CDEF");
- assertThat(directoryDto.getUuidPath()).isEqualTo(moduleDto.getUuidPath() + moduleDto.uuid() + UUID_PATH_SEPARATOR);
- assertThat(directoryDto.moduleUuid()).isEqualTo(moduleDto.uuid());
- assertThat(directoryDto.moduleUuidPath()).isEqualTo(moduleDto.moduleUuidPath());
+ assertThat(directoryDto.getUuidPath()).isEqualTo(UUID_PATH_SEPARATOR + project.uuid() + UUID_PATH_SEPARATOR);
+ assertThat(directoryDto.moduleUuid()).isEqualTo(project.uuid());
+ assertThat(directoryDto.moduleUuidPath()).isEqualTo(project.moduleUuidPath());
assertThat(directoryDto.getMainBranchProjectUuid()).isEqualTo(project.uuid());
assertThat(directoryDto.projectUuid()).isEqualTo(project.uuid());
assertThat(directoryDto.qualifier()).isEqualTo("DIR");
assertThat(directoryDto.scope()).isEqualTo("DIR");
- assertThat(directoryDto.getRootUuid()).isEqualTo(moduleDto.uuid());
+ assertThat(directoryDto.getRootUuid()).isEqualTo(project.uuid());
assertThat(directoryDto.getCreatedAt()).isEqualTo(now);
- ComponentDto fileDto = dbClient.componentDao().selectByKey(db.getSession(), "MODULE_KEY:src/main/java/dir/Foo.java").get();
+ ComponentDto fileDto = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir/Foo.java").get();
assertThat(fileDto.getOrganizationUuid()).isEqualTo(ORGANIZATION_UUID);
assertThat(fileDto.name()).isEqualTo("Foo.java");
assertThat(fileDto.description()).isNull();
assertThat(fileDto.language()).isEqualTo("java");
assertThat(fileDto.uuid()).isEqualTo("DEFG");
assertThat(fileDto.getUuidPath()).isEqualTo(directoryDto.getUuidPath() + directoryDto.uuid() + UUID_PATH_SEPARATOR);
- assertThat(fileDto.moduleUuid()).isEqualTo(moduleDto.uuid());
- assertThat(fileDto.moduleUuidPath()).isEqualTo(moduleDto.moduleUuidPath());
+ assertThat(fileDto.moduleUuid()).isEqualTo(project.uuid());
+ assertThat(fileDto.moduleUuidPath()).isEqualTo(project.moduleUuidPath());
assertThat(fileDto.getMainBranchProjectUuid()).isEqualTo(project.uuid());
assertThat(fileDto.projectUuid()).isEqualTo(project.uuid());
assertThat(fileDto.qualifier()).isEqualTo("FIL");
assertThat(fileDto.scope()).isEqualTo("FIL");
- assertThat(fileDto.getRootUuid()).isEqualTo(moduleDto.uuid());
+ assertThat(fileDto.getRootUuid()).isEqualTo(project.uuid());
assertThat(fileDto.getCreatedAt()).isEqualTo(now);
- assertThat(dbIdsRepository.getComponentId(module)).isEqualTo(moduleDto.getId());
assertThat(dbIdsRepository.getComponentId(directory)).isEqualTo(directoryDto.getId());
assertThat(dbIdsRepository.getComponentId(file)).isEqualTo(fileDto.getId());
}
public void persist_only_new_components() {
// Project and module already exists
ComponentDto project = prepareProject();
- ComponentDto module = ComponentTesting.newModuleDto("BCDE", project).setDbKey(MODULE_KEY).setName("Module");
- dbClient.componentDao().insert(db.getSession(), module);
db.getSession().commit();
treeRootHolder.setRoot(
builder(PROJECT, 1).setUuid(project.uuid()).setKey(project.getDbKey())
.setName("Project")
.addChildren(
- builder(Component.Type.MODULE, 2).setUuid("BCDE").setKey(MODULE_KEY)
- .setName("Module")
+ builder(DIRECTORY, 3).setUuid("CDEF").setKey("PROJECT_KEY:src/main/java/dir")
+ .setPath("src/main/java/dir")
.addChildren(
- builder(DIRECTORY, 3).setUuid("CDEF").setKey("MODULE_KEY:src/main/java/dir")
- .setPath("src/main/java/dir")
- .addChildren(
- builder(FILE, 4).setUuid("DEFG").setKey("MODULE_KEY:src/main/java/dir/Foo.java")
- .setPath("src/main/java/dir/Foo.java")
- .build())
+ builder(FILE, 4).setUuid("DEFG").setKey("PROJECT_KEY:src/main/java/dir/Foo.java")
+ .setPath("src/main/java/dir/Foo.java")
.build())
.build())
.build());
underTest.execute(new TestComputationStepContext());
- assertThat(db.countRowsOfTable("projects")).isEqualTo(4);
+ assertThat(db.countRowsOfTable("projects")).isEqualTo(3);
ComponentDto projectReloaded = dbClient.componentDao().selectByKey(db.getSession(), project.getDbKey()).get();
assertThat(projectReloaded.getId()).isEqualTo(project.getId());
assertThat(projectReloaded.getUuidPath()).isEqualTo(UUID_PATH_OF_ROOT);
assertThat(projectReloaded.getMainBranchProjectUuid()).isNull();
- ComponentDto moduleReloaded = dbClient.componentDao().selectByKey(db.getSession(), MODULE_KEY).get();
- assertThat(moduleReloaded.getId()).isEqualTo(module.getId());
- assertThat(moduleReloaded.uuid()).isEqualTo(module.uuid());
- assertThat(moduleReloaded.getUuidPath()).isEqualTo(module.getUuidPath());
- assertThat(moduleReloaded.moduleUuid()).isEqualTo(module.moduleUuid());
- assertThat(moduleReloaded.moduleUuidPath()).isEqualTo(module.moduleUuidPath());
- assertThat(moduleReloaded.projectUuid()).isEqualTo(module.projectUuid());
- assertThat(moduleReloaded.getRootUuid()).isEqualTo(module.getRootUuid());
- assertThat(moduleReloaded.getMainBranchProjectUuid()).isNull();
-
- ComponentDto directory = dbClient.componentDao().selectByKey(db.getSession(), "MODULE_KEY:src/main/java/dir").get();
+ ComponentDto directory = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir").get();
assertThat(directory.getUuidPath()).isEqualTo(directory.getUuidPath());
- assertThat(directory.moduleUuid()).isEqualTo(module.uuid());
- assertThat(directory.moduleUuidPath()).isEqualTo(module.moduleUuidPath());
+ assertThat(directory.moduleUuid()).isEqualTo(project.uuid());
+ assertThat(directory.moduleUuidPath()).isEqualTo(project.moduleUuidPath());
assertThat(directory.projectUuid()).isEqualTo(project.uuid());
- assertThat(directory.getRootUuid()).isEqualTo(module.uuid());
+ assertThat(directory.getRootUuid()).isEqualTo(project.uuid());
assertThat(directory.getMainBranchProjectUuid()).isNull();
- ComponentDto file = dbClient.componentDao().selectByKey(db.getSession(), "MODULE_KEY:src/main/java/dir/Foo.java").get();
+ ComponentDto file = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir/Foo.java").get();
assertThat(file.getUuidPath()).isEqualTo(file.getUuidPath());
- assertThat(file.moduleUuid()).isEqualTo(module.uuid());
- assertThat(file.moduleUuidPath()).isEqualTo(module.moduleUuidPath());
+ assertThat(file.moduleUuid()).isEqualTo(project.uuid());
+ assertThat(file.moduleUuidPath()).isEqualTo(project.moduleUuidPath());
assertThat(file.projectUuid()).isEqualTo(project.uuid());
- assertThat(file.getRootUuid()).isEqualTo(module.uuid());
+ assertThat(file.getRootUuid()).isEqualTo(project.uuid());
assertThat(file.getMainBranchProjectUuid()).isNull();
}
- @Test
- public void compute_root_uuid() {
- ComponentDto project = prepareProject();
- treeRootHolder.setRoot(
- asTreeRoot(project)
- .addChildren(
- builder(Component.Type.MODULE, 2).setUuid("BCDE").setKey(MODULE_KEY)
- .setName("Module")
- .addChildren(
- builder(Component.Type.MODULE, 3).setUuid("CDEF").setKey("SUB_MODULE_1_KEY")
- .setName("Sub Module 1")
- .addChildren(
- builder(Component.Type.MODULE, 4).setUuid("DEFG").setKey("SUB_MODULE_2_KEY")
- .setName("Sub Module 2")
- .addChildren(
- builder(DIRECTORY, 5).setUuid("EFGH").setKey("SUB_MODULE_2_KEY:src/main/java/dir")
- .setPath("src/main/java/dir")
- .build())
- .build())
- .build())
- .build())
- .build());
-
- underTest.execute(new TestComputationStepContext());
-
- assertThat(db.countRowsOfTable("projects")).isEqualTo(5);
-
- Optional<ComponentDto> module = dbClient.componentDao().selectByKey(db.getSession(), MODULE_KEY);
- assertThat(module).isPresent();
- assertThat(module.get().getRootUuid()).isEqualTo(project.uuid());
-
- Optional<ComponentDto> subModule1 = dbClient.componentDao().selectByKey(db.getSession(), "SUB_MODULE_1_KEY");
- assertThat(subModule1).isPresent();
- assertThat(subModule1.get().getRootUuid()).isEqualTo(project.uuid());
-
- Optional<ComponentDto> subModule2 = dbClient.componentDao().selectByKey(db.getSession(), "SUB_MODULE_2_KEY");
- assertThat(subModule2).isPresent();
- assertThat(subModule2.get().getRootUuid()).isEqualTo(project.uuid());
-
- Optional<ComponentDto> directory = dbClient.componentDao().selectByKey(db.getSession(), "SUB_MODULE_2_KEY:src/main/java/dir");
- assertThat(directory).isPresent();
- assertThat(directory.get().getRootUuid()).isEqualTo(subModule2.get().uuid());
- }
-
- @Test
- public void persist_multi_modules() {
- ComponentDto project = prepareProject();
- treeRootHolder.setRoot(
- asTreeRoot(project)
- .setName("Project")
- .addChildren(
- builder(Component.Type.MODULE, 2).setUuid("BCDE").setKey("MODULE_A")
- .setName("Module A")
- .addChildren(
- builder(Component.Type.MODULE, 3).setUuid("DEFG").setKey("SUB_MODULE_A")
- .setName("Sub Module A")
- .build())
- .build(),
- builder(Component.Type.MODULE, 4).setUuid("CDEF").setKey("MODULE_B")
- .setName("Module B")
- .build())
- .build());
-
- underTest.execute(new TestComputationStepContext());
-
- assertThat(db.countRowsOfTable("projects")).isEqualTo(4);
-
- ComponentDto moduleA = dbClient.componentDao().selectByKey(db.getSession(), "MODULE_A").get();
- assertThat(moduleA.getUuidPath()).isEqualTo(project.getUuidPath() + project.uuid() + UUID_PATH_SEPARATOR);
- assertThat(moduleA.moduleUuid()).isEqualTo(project.uuid());
- assertThat(moduleA.moduleUuidPath()).isEqualTo(project.moduleUuidPath() + moduleA.uuid() + ".");
- assertThat(moduleA.getRootUuid()).isEqualTo(project.uuid());
-
- ComponentDto subModuleA = dbClient.componentDao().selectByKey(db.getSession(), "SUB_MODULE_A").get();
- assertThat(subModuleA.getUuidPath()).isEqualTo(moduleA.getUuidPath() + moduleA.uuid() + UUID_PATH_SEPARATOR);
- assertThat(subModuleA.moduleUuid()).isEqualTo(moduleA.uuid());
- assertThat(subModuleA.moduleUuidPath()).isEqualTo(moduleA.moduleUuidPath() + subModuleA.uuid() + ".");
- assertThat(subModuleA.getRootUuid()).isEqualTo(project.uuid());
-
- ComponentDto moduleB = dbClient.componentDao().selectByKey(db.getSession(), "MODULE_B").get();
- assertThat(moduleB.getUuidPath()).isEqualTo(project.getUuidPath() + project.uuid() + UUID_PATH_SEPARATOR);
- assertThat(moduleB.moduleUuid()).isEqualTo(project.uuid());
- assertThat(moduleB.moduleUuidPath()).isEqualTo(project.moduleUuidPath() + moduleB.uuid() + ".");
- assertThat(moduleB.getRootUuid()).isEqualTo(project.uuid());
- }
-
@Test
public void nothing_to_persist() {
ComponentDto project = prepareProject();
- ComponentDto module = ComponentTesting.newModuleDto("BCDE", project).setDbKey(MODULE_KEY).setName("Module");
- dbClient.componentDao().insert(db.getSession(), module);
- ComponentDto directory = ComponentTesting.newDirectory(module, "src/main/java/dir").setUuid("CDEF").setDbKey("MODULE_KEY:src/main/java/dir");
- ComponentDto file = ComponentTesting.newFileDto(module, directory, "DEFG").setPath("src/main/java/dir/Foo.java").setName("Foo.java")
- .setDbKey("MODULE_KEY:src/main/java/dir/Foo.java");
+ ComponentDto directory = ComponentTesting.newDirectory(project, "src/main/java/dir").setUuid("CDEF").setDbKey("PROJECT_KEY:src/main/java/dir");
+ ComponentDto file = ComponentTesting.newFileDto(project, directory, "DEFG").setPath("src/main/java/dir/Foo.java").setName("Foo.java")
+ .setDbKey("PROJECT_KEY:src/main/java/dir/Foo.java");
dbClient.componentDao().insert(db.getSession(), directory, file);
db.getSession().commit();
builder(PROJECT, 1).setUuid(project.uuid()).setKey(project.getDbKey())
.setName("Project")
.addChildren(
- builder(Component.Type.MODULE, 2).setUuid("BCDE").setKey(MODULE_KEY)
- .setName("Module")
+ builder(DIRECTORY, 3).setUuid("CDEF").setKey("PROJECT_KEY:src/main/java/dir")
+ .setPath("src/main/java/dir")
.addChildren(
- builder(DIRECTORY, 3).setUuid("CDEF").setKey("MODULE_KEY:src/main/java/dir")
- .setPath("src/main/java/dir")
- .addChildren(
- builder(FILE, 4).setUuid("DEFG").setKey("MODULE_KEY:src/main/java/dir/Foo.java")
- .setPath("src/main/java/dir/Foo.java")
- .build())
+ builder(FILE, 4).setUuid("DEFG").setKey("PROJECT_KEY:src/main/java/dir/Foo.java")
+ .setPath("src/main/java/dir/Foo.java")
.build())
.build())
.build());
underTest.execute(new TestComputationStepContext());
- assertThat(db.countRowsOfTable("projects")).isEqualTo(4);
+ assertThat(db.countRowsOfTable("projects")).isEqualTo(3);
assertThat(dbClient.componentDao().selectByKey(db.getSession(), project.getDbKey()).get().getId()).isEqualTo(project.getId());
- assertThat(dbClient.componentDao().selectByKey(db.getSession(), MODULE_KEY).get().getId()).isEqualTo(module.getId());
- assertThat(dbClient.componentDao().selectByKey(db.getSession(), "MODULE_KEY:src/main/java/dir").get().getId()).isEqualTo(directory.getId());
- assertThat(dbClient.componentDao().selectByKey(db.getSession(), "MODULE_KEY:src/main/java/dir/Foo.java").get().getId()).isEqualTo(file.getId());
+ assertThat(dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir").get().getId()).isEqualTo(directory.getId());
+ assertThat(dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir/Foo.java").get().getId()).isEqualTo(file.getId());
ComponentDto projectReloaded = dbClient.componentDao().selectByKey(db.getSession(), project.getDbKey()).get();
assertThat(projectReloaded.getId()).isEqualTo(project.getId());
assertThat(projectReloaded.projectUuid()).isEqualTo(project.projectUuid());
assertThat(projectReloaded.getRootUuid()).isEqualTo(project.getRootUuid());
- ComponentDto moduleReloaded = dbClient.componentDao().selectByKey(db.getSession(), MODULE_KEY).get();
- assertThat(moduleReloaded.getId()).isEqualTo(module.getId());
- assertThat(moduleReloaded.uuid()).isEqualTo(module.uuid());
- assertThat(moduleReloaded.getUuidPath()).isEqualTo(module.getUuidPath());
- assertThat(moduleReloaded.moduleUuid()).isEqualTo(module.moduleUuid());
- assertThat(moduleReloaded.moduleUuidPath()).isEqualTo(module.moduleUuidPath());
- assertThat(moduleReloaded.projectUuid()).isEqualTo(module.projectUuid());
- assertThat(moduleReloaded.getRootUuid()).isEqualTo(module.getRootUuid());
-
- ComponentDto directoryReloaded = dbClient.componentDao().selectByKey(db.getSession(), "MODULE_KEY:src/main/java/dir").get();
+ ComponentDto directoryReloaded = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir").get();
assertThat(directoryReloaded.uuid()).isEqualTo(directory.uuid());
assertThat(directoryReloaded.getUuidPath()).isEqualTo(directory.getUuidPath());
assertThat(directoryReloaded.moduleUuid()).isEqualTo(directory.moduleUuid());
assertThat(directoryReloaded.name()).isEqualTo(directory.name());
assertThat(directoryReloaded.path()).isEqualTo(directory.path());
- ComponentDto fileReloaded = dbClient.componentDao().selectByKey(db.getSession(), "MODULE_KEY:src/main/java/dir/Foo.java").get();
+ ComponentDto fileReloaded = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir/Foo.java").get();
assertThat(fileReloaded.uuid()).isEqualTo(file.uuid());
assertThat(fileReloaded.getUuidPath()).isEqualTo(file.getUuidPath());
assertThat(fileReloaded.moduleUuid()).isEqualTo(file.moduleUuid());
assertThat(fileReloaded.path()).isEqualTo(file.path());
}
- @Test
- public void update_module_name_and_description() {
- ComponentDto project = prepareProject(p -> p.setName("Project").setDescription("Project description"));
- ComponentDto module = ComponentTesting.newModuleDto("BCDE", project).setDbKey(MODULE_KEY).setName("Module");
- dbClient.componentDao().insert(db.getSession(), module);
- db.getSession().commit();
-
- treeRootHolder.setRoot(
- builder(PROJECT, 1)
- .setUuid(project.uuid())
- .setKey(project.getDbKey())
- .setName("New Project")
- .setDescription("New project description")
- .addChildren(
- builder(Component.Type.MODULE, 2)
- .setUuid("BCDE")
- .setKey(MODULE_KEY)
- .setName("New Module")
- .setDescription("New module description")
- .build())
- .build());
-
- underTest.execute(new TestComputationStepContext());
-
- // functional transaction not finished, "A-fields" are not updated yet
- assertNameAndDescription(project.getDbKey(), "Project", "Project description");
- assertNameAndDescription(MODULE_KEY, "Module", null);
-
- // commit functional transaction -> copies B-fields to A-fields
- dbClient.componentDao().applyBChangesForRootComponentUuid(db.getSession(), project.uuid());
- assertNameAndDescription(project.getDbKey(), "New Project", "New project description");
- assertNameAndDescription(MODULE_KEY, "New Module", "New module description");
- }
-
- private void assertNameAndDescription(String key, String expectedName, String expectedDescription) {
- ComponentDto dto = dbClient.componentDao().selectByKey(db.getSession(), key).get();
- assertThat(dto.name()).isEqualTo(expectedName);
- assertThat(dto.description()).isEqualTo(expectedDescription);
- }
-
- @Test
- public void update_module_path() {
- ComponentDto project = prepareProject();
- ComponentDto module = ComponentTesting.newModuleDto("BCDE", project).setDbKey(MODULE_KEY).setName("Module").setPath("path");
- dbClient.componentDao().insert(db.getSession(), module);
- db.getSession().commit();
-
- treeRootHolder.setRoot(
- builder(PROJECT, 1).setUuid(project.uuid()).setKey(project.getDbKey())
- .setName("Project")
- .addChildren(
- builder(Component.Type.MODULE, 2).setUuid("BCDE").setKey(MODULE_KEY)
- .setName("Module")
- .setPath("New path")
- .build())
- .build());
-
- underTest.execute(new TestComputationStepContext());
-
- assertThat(dbClient.componentDao().selectByKey(db.getSession(), MODULE_KEY).get().path()).isEqualTo("path");
-
- // commit the functional transaction
- dbClient.componentDao().applyBChangesForRootComponentUuid(db.getSession(), project.uuid());
- assertThat(dbClient.componentDao().selectByKey(db.getSession(), MODULE_KEY).get().path()).isEqualTo("New path");
- }
-
@Test
public void update_module_uuid_when_moving_a_module() {
ComponentDto project = prepareProject();
- ComponentDto moduleA = ComponentTesting.newModuleDto("EDCB", project)
- .setDbKey("MODULE_A")
- .setName("Module A");
- ComponentDto moduleB = ComponentTesting.newModuleDto("BCDE", project)
- .setDbKey("MODULE_B")
- .setName("Module B");
- dbClient.componentDao().insert(db.getSession(), moduleA, moduleB);
- ComponentDto directory = ComponentTesting.newDirectory(moduleB, "src/main/java/dir").setUuid("CDEF").setDbKey("MODULE_B:src/main/java/dir");
- ComponentDto file = ComponentTesting.newFileDto(moduleB, directory, "DEFG").setPath("src/main/java/dir/Foo.java").setName("Foo.java")
- .setDbKey("MODULE_B:src/main/java/dir/Foo.java");
+ ComponentDto directory = ComponentTesting.newDirectory(project, "src/main/java/dir").setUuid("CDEF").setDbKey("PROJECT_KEY:src/main/java/dir");
+ ComponentDto file = ComponentTesting.newFileDto(project, directory, "DEFG").setPath("src/main/java/dir/Foo.java").setName("Foo.java")
+ .setDbKey("PROJECT_KEY:src/main/java/dir/Foo.java");
dbClient.componentDao().insert(db.getSession(), directory, file);
db.getSession().commit();
builder(PROJECT, 1).setUuid(project.uuid()).setKey(project.getDbKey())
.setName("Project")
.addChildren(
- builder(Component.Type.MODULE, 2).setUuid("EDCB").setKey("MODULE_A")
- .setName("Module A")
+ builder(DIRECTORY, 4).setUuid("CDEF").setKey("PROJECT_KEY:src/main/java/dir")
+ .setPath("src/main/java/dir")
.addChildren(
- builder(Component.Type.MODULE, 3).setUuid("BCDE").setKey("MODULE_B")
- .setName("Module B")
- .addChildren(
- builder(DIRECTORY, 4).setUuid("CDEF").setKey("MODULE_B:src/main/java/dir")
- .setPath("src/main/java/dir")
- .addChildren(
- builder(FILE, 5).setUuid("DEFG").setKey("MODULE_B:src/main/java/dir/Foo.java")
- .setPath("src/main/java/dir/Foo.java")
- .build())
- .build())
+ builder(FILE, 5).setUuid("DEFG").setKey("PROJECT_KEY:src/main/java/dir/Foo.java")
+ .setPath("src/main/java/dir/Foo.java")
.build())
.build())
.build());
dbClient.componentDao().applyBChangesForRootComponentUuid(db.getSession(), project.uuid());
db.commit();
- assertThat(db.countRowsOfTable("projects")).isEqualTo(5);
-
- ComponentDto moduleAreloaded = dbClient.componentDao().selectByKey(db.getSession(), "MODULE_A").get();
-
- ComponentDto moduleBReloaded = dbClient.componentDao().selectByKey(db.getSession(), "MODULE_B").get();
- assertThat(moduleBReloaded).isNotNull();
- assertThat(moduleBReloaded.uuid()).isEqualTo(moduleB.uuid());
- assertThat(moduleBReloaded.getUuidPath()).isEqualTo(moduleBReloaded.getUuidPath());
- assertThat(moduleBReloaded.moduleUuid()).isEqualTo(moduleAreloaded.uuid());
- assertThat(moduleBReloaded.moduleUuidPath()).isEqualTo(moduleAreloaded.moduleUuidPath() + moduleBReloaded.uuid() + ".");
- assertThat(moduleBReloaded.projectUuid()).isEqualTo(project.uuid());
- assertThat(moduleBReloaded.getRootUuid()).isEqualTo(project.uuid());
+ assertThat(db.countRowsOfTable("projects")).isEqualTo(3);
- ComponentDto directoryReloaded = dbClient.componentDao().selectByKey(db.getSession(), "MODULE_B:src/main/java/dir").get();
+ ComponentDto directoryReloaded = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir").get();
assertThat(directoryReloaded).isNotNull();
assertThat(directoryReloaded.uuid()).isEqualTo(directory.uuid());
assertThat(directoryReloaded.getUuidPath()).isEqualTo(directoryReloaded.getUuidPath());
- assertThat(directoryReloaded.moduleUuid()).isEqualTo(moduleBReloaded.uuid());
- assertThat(directoryReloaded.moduleUuidPath()).isEqualTo(moduleBReloaded.moduleUuidPath());
+ assertThat(directoryReloaded.moduleUuid()).isEqualTo(project.uuid());
+ assertThat(directoryReloaded.moduleUuidPath()).isEqualTo(project.moduleUuidPath());
assertThat(directoryReloaded.projectUuid()).isEqualTo(project.uuid());
- assertThat(directoryReloaded.getRootUuid()).isEqualTo(moduleBReloaded.uuid());
+ assertThat(directoryReloaded.getRootUuid()).isEqualTo(project.uuid());
- ComponentDto fileReloaded = dbClient.componentDao().selectByKey(db.getSession(), "MODULE_B:src/main/java/dir/Foo.java").get();
+ ComponentDto fileReloaded = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir/Foo.java").get();
assertThat(fileReloaded).isNotNull();
assertThat(fileReloaded.uuid()).isEqualTo(file.uuid());
assertThat(fileReloaded.getUuidPath()).isEqualTo(fileReloaded.getUuidPath());
- assertThat(fileReloaded.moduleUuid()).isEqualTo(moduleBReloaded.uuid());
- assertThat(fileReloaded.moduleUuidPath()).isEqualTo(moduleBReloaded.moduleUuidPath());
+ assertThat(fileReloaded.moduleUuid()).isEqualTo(project.uuid());
+ assertThat(fileReloaded.moduleUuidPath()).isEqualTo(project.moduleUuidPath());
assertThat(fileReloaded.projectUuid()).isEqualTo(project.uuid());
- assertThat(fileReloaded.getRootUuid()).isEqualTo(moduleBReloaded.uuid());
+ assertThat(fileReloaded.getRootUuid()).isEqualTo(project.uuid());
}
@Test
public void do_not_update_created_at_on_existing_component() {
Date oldDate = DateUtils.parseDate("2015-01-01");
ComponentDto project = prepareProject(p -> p.setCreatedAt(oldDate));
- ComponentDto module = ComponentTesting.newModuleDto("BCDE", project).setDbKey(MODULE_KEY).setName("Module").setPath("path").setCreatedAt(oldDate);
- dbClient.componentDao().insert(db.getSession(), module);
db.getSession().commit();
treeRootHolder.setRoot(
@Test
public void persist_components_that_were_previously_removed() {
ComponentDto project = prepareProject();
- ComponentDto removedModule = ComponentTesting.newModuleDto("BCDE", project)
- .setDbKey(MODULE_KEY)
- .setName("Module")
- .setEnabled(false);
- dbClient.componentDao().insert(db.getSession(), removedModule);
- ComponentDto removedDirectory = ComponentTesting.newDirectory(removedModule, "src/main/java/dir")
+ ComponentDto removedDirectory = ComponentTesting.newDirectory(project, "src/main/java/dir")
.setUuid("CDEF")
- .setDbKey("MODULE_KEY:src/main/java/dir")
+ .setDbKey("PROJECT_KEY:src/main/java/dir")
.setEnabled(false);
- ComponentDto removedFile = ComponentTesting.newFileDto(removedModule, removedDirectory, "DEFG")
+ ComponentDto removedFile = ComponentTesting.newFileDto(project, removedDirectory, "DEFG")
.setPath("src/main/java/dir/Foo.java")
.setName("Foo.java")
- .setDbKey("MODULE_KEY:src/main/java/dir/Foo.java")
+ .setDbKey("PROJECT_KEY:src/main/java/dir/Foo.java")
.setEnabled(false);
dbClient.componentDao().insert(db.getSession(), removedDirectory, removedFile);
db.getSession().commit();
builder(PROJECT, 1).setUuid(project.uuid()).setKey(project.getDbKey())
.setName("Project")
.addChildren(
- builder(Component.Type.MODULE, 2).setUuid("BCDE").setKey(MODULE_KEY)
- .setName("Module")
+ builder(DIRECTORY, 3).setUuid("CDEF").setKey("PROJECT_KEY:src/main/java/dir")
+ .setPath("src/main/java/dir")
.addChildren(
- builder(DIRECTORY, 3).setUuid("CDEF").setKey("MODULE_KEY:src/main/java/dir")
- .setPath("src/main/java/dir")
- .addChildren(
- builder(FILE, 4).setUuid("DEFG").setKey("MODULE_KEY:src/main/java/dir/Foo.java")
- .setPath("src/main/java/dir/Foo.java")
- .build())
+ builder(FILE, 4).setUuid("DEFG").setKey("PROJECT_KEY:src/main/java/dir/Foo.java")
+ .setPath("src/main/java/dir/Foo.java")
.build())
.build())
.build());
underTest.execute(new TestComputationStepContext());
- assertThat(db.countRowsOfTable("projects")).isEqualTo(4);
+ assertThat(db.countRowsOfTable("projects")).isEqualTo(3);
assertThat(dbClient.componentDao().selectByKey(db.getSession(), project.getDbKey()).get().getId()).isEqualTo(project.getId());
- assertThat(dbClient.componentDao().selectByKey(db.getSession(), MODULE_KEY).get().getId()).isEqualTo(removedModule.getId());
- assertThat(dbClient.componentDao().selectByKey(db.getSession(), "MODULE_KEY:src/main/java/dir").get().getId()).isEqualTo(removedDirectory.getId());
- assertThat(dbClient.componentDao().selectByKey(db.getSession(), "MODULE_KEY:src/main/java/dir/Foo.java").get().getId()).isEqualTo(removedFile.getId());
- assertExistButDisabled(removedModule.getDbKey(), removedDirectory.getDbKey(), removedFile.getDbKey());
+ assertThat(dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir").get().getId()).isEqualTo(removedDirectory.getId());
+ assertThat(dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir/Foo.java").get().getId()).isEqualTo(removedFile.getId());
+ assertExistButDisabled(removedDirectory.getDbKey(), removedFile.getDbKey());
// commit the functional transaction
dbClient.componentDao().applyBChangesForRootComponentUuid(db.getSession(), project.uuid());
assertThat(projectReloaded.getRootUuid()).isEqualTo(project.getRootUuid());
assertThat(projectReloaded.isEnabled()).isTrue();
- ComponentDto moduleReloaded = dbClient.componentDao().selectByKey(db.getSession(), MODULE_KEY).get();
- assertThat(moduleReloaded.getId()).isEqualTo(removedModule.getId());
- assertThat(moduleReloaded.uuid()).isEqualTo(removedModule.uuid());
- assertThat(moduleReloaded.getUuidPath()).isEqualTo(removedModule.getUuidPath());
- assertThat(moduleReloaded.moduleUuid()).isEqualTo(removedModule.moduleUuid());
- assertThat(moduleReloaded.moduleUuidPath()).isEqualTo(removedModule.moduleUuidPath());
- assertThat(moduleReloaded.projectUuid()).isEqualTo(removedModule.projectUuid());
- assertThat(moduleReloaded.getRootUuid()).isEqualTo(removedModule.getRootUuid());
- assertThat(moduleReloaded.isEnabled()).isTrue();
-
- ComponentDto directoryReloaded = dbClient.componentDao().selectByKey(db.getSession(), "MODULE_KEY:src/main/java/dir").get();
+ ComponentDto directoryReloaded = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir").get();
assertThat(directoryReloaded.getId()).isEqualTo(removedDirectory.getId());
assertThat(directoryReloaded.uuid()).isEqualTo(removedDirectory.uuid());
assertThat(directoryReloaded.getUuidPath()).isEqualTo(removedDirectory.getUuidPath());
assertThat(directoryReloaded.path()).isEqualTo(removedDirectory.path());
assertThat(directoryReloaded.isEnabled()).isTrue();
- ComponentDto fileReloaded = dbClient.componentDao().selectByKey(db.getSession(), "MODULE_KEY:src/main/java/dir/Foo.java").get();
+ ComponentDto fileReloaded = dbClient.componentDao().selectByKey(db.getSession(), "PROJECT_KEY:src/main/java/dir/Foo.java").get();
assertThat(fileReloaded.getId()).isEqualTo(fileReloaded.getId());
assertThat(fileReloaded.uuid()).isEqualTo(removedFile.uuid());
assertThat(fileReloaded.getUuidPath()).isEqualTo(removedFile.getUuidPath());
}
}
- @Test
- public void update_module_uuid_when_reactivating_removed_component() {
- ComponentDto project = prepareProject();
- ComponentDto module = ComponentTesting.newModuleDto("BCDE", project).setDbKey(MODULE_KEY).setName("Module");
- ComponentDto removedModule = ComponentTesting.newModuleDto("EDCD", project).setDbKey("REMOVED_MODULE_KEY").setName("Removed Module").setEnabled(false);
- dbClient.componentDao().insert(db.getSession(), module, removedModule);
- ComponentDto directory = ComponentTesting.newDirectory(module, "src/main/java/dir").setUuid("CDEF").setDbKey("MODULE_KEY:src/main/java/dir");
- // The file was attached to another module
- ComponentDto removedFile = ComponentTesting.newFileDto(removedModule, directory, "DEFG").setPath("src/main/java/dir/Foo.java").setName("Foo.java")
- .setDbKey("MODULE_KEY:src/main/java/dir/Foo.java").setEnabled(false);
- dbClient.componentDao().insert(db.getSession(), directory, removedFile);
- db.getSession().commit();
-
- treeRootHolder.setRoot(
- builder(PROJECT, 1).setUuid(project.uuid()).setKey(project.getDbKey())
- .setName("Project")
- .addChildren(
- builder(Component.Type.MODULE, 2).setUuid("BCDE").setKey(MODULE_KEY)
- .setName("Module")
- .addChildren(
- builder(DIRECTORY, 3).setUuid("CDEF").setKey("MODULE_KEY:src/main/java/dir")
- .setPath("src/main/java/dir")
- .addChildren(
- builder(FILE, 4).setUuid("DEFG").setKey("MODULE_KEY:src/main/java/dir/Foo.java")
- .setPath("src/main/java/dir/Foo.java")
- .build())
- .build())
- .build())
- .build());
-
- underTest.execute(new TestComputationStepContext());
-
- // commit the functional transaction
- dbClient.componentDao().applyBChangesForRootComponentUuid(db.getSession(), project.uuid());
- db.commit();
-
- // Projects contains 4 components from the report + one removed module
- assertThat(db.countRowsOfTable("projects")).isEqualTo(5);
-
- ComponentDto moduleReloaded = dbClient.componentDao().selectByKey(db.getSession(), MODULE_KEY).get();
-
- ComponentDto fileReloaded = dbClient.componentDao().selectByKey(db.getSession(), "MODULE_KEY:src/main/java/dir/Foo.java").get();
- assertThat(fileReloaded.getId()).isEqualTo(removedFile.getId());
- assertThat(fileReloaded.uuid()).isEqualTo(removedFile.uuid());
- assertThat(fileReloaded.getUuidPath()).isEqualTo(fileReloaded.getUuidPath());
- assertThat(fileReloaded.moduleUuid()).isEqualTo(moduleReloaded.uuid());
- assertThat(fileReloaded.moduleUuidPath()).isEqualTo(moduleReloaded.moduleUuidPath());
- assertThat(fileReloaded.projectUuid()).isEqualTo(moduleReloaded.projectUuid());
- assertThat(fileReloaded.name()).isEqualTo(removedFile.name());
- assertThat(fileReloaded.path()).isEqualTo(removedFile.path());
- assertThat(fileReloaded.isEnabled()).isTrue();
- }
-
@Test
public void persists_existing_components_with_visibility_of_root_in_db_out_of_functional_transaction() {
ComponentDto project = prepareProject(p -> p.setPrivate(true));
return builder(PROJECT, 1).setUuid(projectUuid).setKey(projectKey)
.setName("Project")
.addChildren(
- builder(Component.Type.MODULE, 2).setUuid("BCDE").setKey("MODULE")
- .setName("Module")
+ builder(Component.Type.DIRECTORY, 3).setUuid("DEFG").setKey("DIR")
+ .setPath("Directory")
.addChildren(
- builder(Component.Type.DIRECTORY, 3).setUuid("DEFG").setKey("DIR")
- .setPath("Directory")
- .addChildren(
- builder(FILE, 4).setUuid("CDEF").setKey("FILE")
- .setPath("file")
- .build())
+ builder(FILE, 4).setUuid("CDEF").setKey("FILE")
+ .setPath("file")
.build())
.build())
.build();
}
@Override
- public String generateKey(ScannerReport.Component module, @Nullable ScannerReport.Component fileOrDir) {
- String moduleKey = module.getKey();
- if (fileOrDir == null || isEmpty(fileOrDir.getPath())) {
- return moduleKey;
+ public String generateKey(ScannerReport.Component project, @Nullable String fileOrDirPath) {
+ String projectKey = project.getKey();
+ if (isEmpty(fileOrDirPath)) {
+ return projectKey;
}
- return ComponentKeys.createEffectiveKey(moduleKey, trimToNull(fileOrDir.getPath()));
+ return ComponentKeys.createEffectiveKey(projectKey, trimToNull(fileOrDirPath));
}
}
}
import static org.sonar.api.measures.CoreMetrics.STATEMENTS_KEY;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.DIRECTORY;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.FILE;
-import static org.sonar.ce.task.projectanalysis.component.Component.Type.MODULE;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT;
import static org.sonar.ce.task.projectanalysis.component.ReportComponent.builder;
import static org.sonar.ce.task.projectanalysis.measure.Measure.newMeasureBuilder;
private static final String LANGUAGE_DOES_NOT_MATTER_HERE = null;
private static final int ROOT_REF = 1;
- private static final int MODULE_REF = 12;
- private static final int SUB_MODULE_REF = 123;
private static final int DIRECTORY_1_REF = 1234;
private static final int DIRECTORY_2_REF = 1235;
private static final int DIRECTORY_3_REF = 1236;
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule().setRoot(
builder(PROJECT, ROOT_REF)
.addChildren(
- builder(MODULE, MODULE_REF)
+ builder(DIRECTORY, DIRECTORY_1_REF)
.addChildren(
- builder(MODULE, SUB_MODULE_REF)
- .addChildren(
- builder(DIRECTORY, DIRECTORY_1_REF)
- .addChildren(
- builder(FILE, FILE_1_REF).setFileAttributes(new FileAttributes(false, LANGUAGE_DOES_NOT_MATTER_HERE, 1)).build(),
- builder(FILE, FILE_2_REF).setFileAttributes(new FileAttributes(false, LANGUAGE_DOES_NOT_MATTER_HERE, 2)).build())
- .build(),
- builder(DIRECTORY, DIRECTORY_2_REF)
- .addChildren(
- builder(FILE, FILE_3_REF).setFileAttributes(new FileAttributes(false, LANGUAGE_DOES_NOT_MATTER_HERE, 7)).build(),
- builder(FILE, UNIT_TEST_1_REF).setFileAttributes(new FileAttributes(true, LANGUAGE_DOES_NOT_MATTER_HERE, 4)).build())
- .build(),
- builder(DIRECTORY, DIRECTORY_3_REF)
- .addChildren(
- builder(FILE, UNIT_TEST_2_REF).setFileAttributes(new FileAttributes(true, LANGUAGE_DOES_NOT_MATTER_HERE, 10)).build())
- .build())
- .build())
+ builder(FILE, FILE_1_REF).setFileAttributes(new FileAttributes(false, LANGUAGE_DOES_NOT_MATTER_HERE, 1)).build(),
+ builder(FILE, FILE_2_REF).setFileAttributes(new FileAttributes(false, LANGUAGE_DOES_NOT_MATTER_HERE, 2)).build())
+ .build(),
+ builder(DIRECTORY, DIRECTORY_2_REF)
+ .addChildren(
+ builder(FILE, FILE_3_REF).setFileAttributes(new FileAttributes(false, LANGUAGE_DOES_NOT_MATTER_HERE, 7)).build(),
+ builder(FILE, UNIT_TEST_1_REF).setFileAttributes(new FileAttributes(true, LANGUAGE_DOES_NOT_MATTER_HERE, 4)).build())
+ .build(),
+ builder(DIRECTORY, DIRECTORY_3_REF)
+ .addChildren(
+ builder(FILE, UNIT_TEST_2_REF).setFileAttributes(new FileAttributes(true, LANGUAGE_DOES_NOT_MATTER_HERE, 10)).build())
.build())
.build());
@Rule
verifyMeasuresOnOtherComponent(DIRECTORY_1_REF, 3, 2, 1);
verifyMeasuresOnOtherComponent(DIRECTORY_2_REF, 7, 1, 1);
verifyMeasuresOnOtherComponent(DIRECTORY_3_REF, NO_METRIC, NO_METRIC, NO_METRIC);
- verifyMeasuresOnOtherComponent(SUB_MODULE_REF, 10, 3, 2);
- verifyMeasuresOnOtherComponent(MODULE_REF, 10, 3, 2);
verifyMeasuresOnOtherComponent(ROOT_REF, 10, 3, 2);
}
verifyMeasuresOnOtherComponent(DIRECTORY_1_REF, 3, 2, 1, entryOf(metricKey, newMeasureBuilder().create(16)));
verifyMeasuresOnOtherComponent(DIRECTORY_2_REF, 7, 1, 1, entryOf(metricKey, newMeasureBuilder().create(3)));
verifyMeasuresOnOtherComponent(DIRECTORY_3_REF, NO_METRIC, NO_METRIC, NO_METRIC);
- verifyMeasuresOnOtherComponent(SUB_MODULE_REF, 10, 3, 2, entryOf(metricKey, newMeasureBuilder().create(19)));
- verifyMeasuresOnOtherComponent(MODULE_REF, 10, 3, 2, entryOf(metricKey, newMeasureBuilder().create(19)));
verifyMeasuresOnOtherComponent(ROOT_REF, 10, 3, 2, entryOf(metricKey, newMeasureBuilder().create(19)));
}
entryOf(metric2Key, newMeasureBuilder().create(100))
};
verifyMeasuresOnOtherComponent(DIRECTORY_3_REF, NO_METRIC, NO_METRIC, NO_METRIC);
- verifyMeasuresOnOtherComponent(SUB_MODULE_REF, 10, 3, 2, subModuleAndAboveEntries);
- verifyMeasuresOnOtherComponent(MODULE_REF, 10, 3, 2, subModuleAndAboveEntries);
verifyMeasuresOnOtherComponent(ROOT_REF, 10, 3, 2, subModuleAndAboveEntries);
}
return from(concat(
asList(otherMeasures),
from(asList(measureRepoEntries)).filter(notNull())))
- .toArray(MeasureRepoEntry.class);
+ .toArray(MeasureRepoEntry.class);
}
private void verifyNoMeasure(int componentRef) {
import static org.sonar.api.measures.CoreMetrics.TEST_SUCCESS_DENSITY_KEY;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.DIRECTORY;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.FILE;
-import static org.sonar.ce.task.projectanalysis.component.Component.Type.MODULE;
import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT;
import static org.sonar.ce.task.projectanalysis.component.ReportComponent.builder;
import static org.sonar.ce.task.projectanalysis.measure.Measure.newMeasureBuilder;
private static final Offset<Double> DEFAULT_OFFSET = Offset.offset(0.01d);
private static final int ROOT_REF = 1;
- private static final int MODULE_REF = 12;
- private static final int SUB_MODULE_REF = 123;
private static final int DIRECTORY_REF = 1234;
private static final int FILE_1_REF = 12341;
private static final int FILE_2_REF = 12342;
.setRoot(
builder(PROJECT, ROOT_REF)
.addChildren(
- builder(MODULE, MODULE_REF)
+ builder(DIRECTORY, DIRECTORY_REF)
.addChildren(
- builder(MODULE, SUB_MODULE_REF)
- .addChildren(
- builder(DIRECTORY, DIRECTORY_REF)
- .addChildren(
- builder(FILE, FILE_1_REF).setFileAttributes(new FileAttributes(true, null, 1)).build(),
- builder(FILE, FILE_2_REF).setFileAttributes(new FileAttributes(true, null, 1)).build())
- .build())
- .build())
+ builder(FILE, FILE_1_REF).setFileAttributes(new FileAttributes(true, null, 1)).build(),
+ builder(FILE, FILE_2_REF).setFileAttributes(new FileAttributes(true, null, 1)).build())
.build())
.build());
@Rule
assertThat(toEntries(measureRepository.getAddedRawMeasures(FILE_1_REF))).contains(entryOf(TEST_SUCCESS_DENSITY_KEY, newMeasureBuilder().create(40d, 1)));
assertThat(toEntries(measureRepository.getAddedRawMeasures(FILE_2_REF))).contains(entryOf(TEST_SUCCESS_DENSITY_KEY, newMeasureBuilder().create(70d, 1)));
assertThat(toEntries(measureRepository.getAddedRawMeasures(DIRECTORY_REF))).contains(entryOf(TEST_SUCCESS_DENSITY_KEY, newMeasureBuilder().create(60d, 1)));
- assertThat(toEntries(measureRepository.getAddedRawMeasures(SUB_MODULE_REF))).contains(entryOf(TEST_SUCCESS_DENSITY_KEY, newMeasureBuilder().create(60d, 1)));
- assertThat(toEntries(measureRepository.getAddedRawMeasures(MODULE_REF))).contains(entryOf(TEST_SUCCESS_DENSITY_KEY, newMeasureBuilder().create(60d, 1)));
assertThat(toEntries(measureRepository.getAddedRawMeasures(ROOT_REF))).contains(entryOf(TEST_SUCCESS_DENSITY_KEY, newMeasureBuilder().create(60d, 1)));
}
assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, TEST_SUCCESS_DENSITY_KEY).get().getDoubleValue()).isEqualTo(60d);
assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, TEST_SUCCESS_DENSITY_KEY).get().getDoubleValue()).isEqualTo(95d);
assertThat(measureRepository.getAddedRawMeasure(DIRECTORY_REF, TEST_SUCCESS_DENSITY_KEY).get().getDoubleValue()).isEqualTo(83.3d, DEFAULT_OFFSET);
- assertThat(measureRepository.getAddedRawMeasure(SUB_MODULE_REF, TEST_SUCCESS_DENSITY_KEY).get().getDoubleValue()).isEqualTo(83.3d, DEFAULT_OFFSET);
- assertThat(measureRepository.getAddedRawMeasure(MODULE_REF, TEST_SUCCESS_DENSITY_KEY).get().getDoubleValue()).isEqualTo(83.3d, DEFAULT_OFFSET);
assertThat(measureRepository.getAddedRawMeasure(ROOT_REF, TEST_SUCCESS_DENSITY_KEY).get().getDoubleValue()).isEqualTo(83.3d, DEFAULT_OFFSET);
}
assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, TEST_SUCCESS_DENSITY_KEY).get().getDoubleValue()).isEqualTo(80d);
assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, TEST_SUCCESS_DENSITY_KEY).get().getDoubleValue()).isEqualTo(75d);
assertThat(measureRepository.getAddedRawMeasure(DIRECTORY_REF, TEST_SUCCESS_DENSITY_KEY).get().getDoubleValue()).isEqualTo(76.7d, DEFAULT_OFFSET);
- assertThat(measureRepository.getAddedRawMeasure(SUB_MODULE_REF, TEST_SUCCESS_DENSITY_KEY).get().getDoubleValue()).isEqualTo(76.7d, DEFAULT_OFFSET);
- assertThat(measureRepository.getAddedRawMeasure(MODULE_REF, TEST_SUCCESS_DENSITY_KEY).get().getDoubleValue()).isEqualTo(76.7d, DEFAULT_OFFSET);
assertThat(measureRepository.getAddedRawMeasure(ROOT_REF, TEST_SUCCESS_DENSITY_KEY).get().getDoubleValue()).isEqualTo(76.7d, DEFAULT_OFFSET);
}
assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, TEST_SUCCESS_DENSITY_KEY).get().getDoubleValue()).isEqualTo(100d);
assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, TEST_SUCCESS_DENSITY_KEY).get().getDoubleValue()).isEqualTo(100d);
assertThat(measureRepository.getAddedRawMeasure(DIRECTORY_REF, TEST_SUCCESS_DENSITY_KEY).get().getDoubleValue()).isEqualTo(100d);
- assertThat(measureRepository.getAddedRawMeasure(SUB_MODULE_REF, TEST_SUCCESS_DENSITY_KEY).get().getDoubleValue()).isEqualTo(100d);
- assertThat(measureRepository.getAddedRawMeasure(MODULE_REF, TEST_SUCCESS_DENSITY_KEY).get().getDoubleValue()).isEqualTo(100d);
assertThat(measureRepository.getAddedRawMeasure(ROOT_REF, TEST_SUCCESS_DENSITY_KEY).get().getDoubleValue()).isEqualTo(100d);
}
assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, TEST_SUCCESS_DENSITY_KEY).get().getDoubleValue()).isEqualTo(0d);
assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, TEST_SUCCESS_DENSITY_KEY).get().getDoubleValue()).isEqualTo(0d);
assertThat(measureRepository.getAddedRawMeasure(DIRECTORY_REF, TEST_SUCCESS_DENSITY_KEY).get().getDoubleValue()).isEqualTo(0d);
- assertThat(measureRepository.getAddedRawMeasure(SUB_MODULE_REF, TEST_SUCCESS_DENSITY_KEY).get().getDoubleValue()).isEqualTo(0d);
- assertThat(measureRepository.getAddedRawMeasure(MODULE_REF, TEST_SUCCESS_DENSITY_KEY).get().getDoubleValue()).isEqualTo(0d);
assertThat(measureRepository.getAddedRawMeasure(ROOT_REF, TEST_SUCCESS_DENSITY_KEY).get().getDoubleValue()).isEqualTo(0d);
}
assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, TEST_SUCCESS_DENSITY_KEY)).isNotPresent();
assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, TEST_SUCCESS_DENSITY_KEY)).isNotPresent();
assertThat(measureRepository.getAddedRawMeasure(DIRECTORY_REF, TEST_SUCCESS_DENSITY_KEY)).isNotPresent();
- assertThat(measureRepository.getAddedRawMeasure(SUB_MODULE_REF, TEST_SUCCESS_DENSITY_KEY)).isNotPresent();
- assertThat(measureRepository.getAddedRawMeasure(MODULE_REF, TEST_SUCCESS_DENSITY_KEY)).isNotPresent();
assertThat(measureRepository.getAddedRawMeasure(ROOT_REF, TEST_SUCCESS_DENSITY_KEY)).isNotPresent();
}
assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, TEST_SUCCESS_DENSITY_KEY)).isNotPresent();
assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, TEST_SUCCESS_DENSITY_KEY)).isNotPresent();
assertThat(measureRepository.getAddedRawMeasure(DIRECTORY_REF, TEST_SUCCESS_DENSITY_KEY)).isNotPresent();
- assertThat(measureRepository.getAddedRawMeasure(SUB_MODULE_REF, TEST_SUCCESS_DENSITY_KEY)).isNotPresent();
- assertThat(measureRepository.getAddedRawMeasure(MODULE_REF, TEST_SUCCESS_DENSITY_KEY)).isNotPresent();
assertThat(measureRepository.getAddedRawMeasure(ROOT_REF, TEST_SUCCESS_DENSITY_KEY)).isNotPresent();
}
public void aggregate_measures_when_tests_measures_are_defined_on_directory() {
treeRootHolder.setRoot(builder(PROJECT, ROOT_REF)
.addChildren(
- builder(MODULE, MODULE_REF)
- .addChildren(
- builder(DIRECTORY, DIRECTORY_REF).build())
- .build())
+ builder(DIRECTORY, DIRECTORY_REF).build())
.build());
measureRepository.addRawMeasure(DIRECTORY_REF, TESTS_KEY, newMeasureBuilder().create(10));
measureRepository.addRawMeasure(DIRECTORY_REF, TEST_ERRORS_KEY, newMeasureBuilder().create(2));
underTest.execute(new TestComputationStepContext());
- assertThat(toEntries(measureRepository.getAddedRawMeasures(MODULE_REF))).containsOnly(
- entryOf(TESTS_KEY, newMeasureBuilder().create(10)),
- entryOf(TEST_ERRORS_KEY, newMeasureBuilder().create(2)),
- entryOf(TEST_FAILURES_KEY, newMeasureBuilder().create(1)),
- entryOf(SKIPPED_TESTS_KEY, newMeasureBuilder().create(5)),
- entryOf(TEST_EXECUTION_TIME_KEY, newMeasureBuilder().create(100L)),
- entryOf(TEST_SUCCESS_DENSITY_KEY, newMeasureBuilder().create(70d, 1)));
assertThat(toEntries(measureRepository.getAddedRawMeasures(ROOT_REF))).containsOnly(
entryOf(TESTS_KEY, newMeasureBuilder().create(10)),
entryOf(TEST_ERRORS_KEY, newMeasureBuilder().create(2)),
assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, metricKey)).isNotPresent();
assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, metricKey)).isNotPresent();
assertThat(toEntries(measureRepository.getAddedRawMeasures(DIRECTORY_REF))).containsOnly(entryOf(metricKey, newMeasureBuilder().create(expectedValue)));
- assertThat(toEntries(measureRepository.getAddedRawMeasures(SUB_MODULE_REF))).containsOnly(entryOf(metricKey, newMeasureBuilder().create(expectedValue)));
- assertThat(toEntries(measureRepository.getAddedRawMeasures(MODULE_REF))).containsOnly(entryOf(metricKey, newMeasureBuilder().create(expectedValue)));
assertThat(toEntries(measureRepository.getAddedRawMeasures(ROOT_REF))).containsOnly(entryOf(metricKey, newMeasureBuilder().create(expectedValue)));
}
assertThat(measureRepository.getAddedRawMeasure(FILE_1_REF, metricKey)).isNotPresent();
assertThat(measureRepository.getAddedRawMeasure(FILE_2_REF, metricKey)).isNotPresent();
assertThat(toEntries(measureRepository.getAddedRawMeasures(DIRECTORY_REF))).containsOnly(entryOf(metricKey, newMeasureBuilder().create(expectedValue)));
- assertThat(toEntries(measureRepository.getAddedRawMeasures(SUB_MODULE_REF))).containsOnly(entryOf(metricKey, newMeasureBuilder().create(expectedValue)));
- assertThat(toEntries(measureRepository.getAddedRawMeasures(MODULE_REF))).containsOnly(entryOf(metricKey, newMeasureBuilder().create(expectedValue)));
assertThat(toEntries(measureRepository.getAddedRawMeasures(ROOT_REF))).containsOnly(entryOf(metricKey, newMeasureBuilder().create(expectedValue)));
}
}
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.ComponentTesting;
import org.sonar.db.component.SnapshotTesting;
-import org.sonar.db.organization.OrganizationDto;
import org.sonar.scanner.protocol.output.ScannerReport;
import org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType;
static long DEFAULT_ANALYSIS_TIME = 1433131200000L; // 2015-06-01
static final String PROJECT_KEY = "PROJECT_KEY";
- static final String MODULE_KEY = "MODULE_KEY";
static final Branch DEFAULT_BRANCH = new DefaultBranchImpl();
@Rule
ValidateProjectStep underTest = new ValidateProjectStep(dbClient, reportReader, treeRootHolder, analysisMetadataHolder);
- @Test
- public void fail_if_module_key_is_already_used_as_project_key() {
- reportReader.putComponent(ScannerReport.Component.newBuilder()
- .setRef(1)
- .setType(ComponentType.PROJECT)
- .setKey(PROJECT_KEY)
- .addChildRef(2)
- .build());
- reportReader.putComponent(ScannerReport.Component.newBuilder()
- .setRef(2)
- .setType(ComponentType.MODULE)
- .setKey(MODULE_KEY)
- .build());
-
- ComponentDto project = ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert(), "ABCD").setDbKey(MODULE_KEY);
- dbClient.componentDao().insert(dbTester.getSession(), project);
- dbTester.getSession().commit();
-
- treeRootHolder.setRoot(ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").setKey(PROJECT_KEY).addChildren(
- ReportComponent.builder(Component.Type.MODULE, 2).setUuid("BCDE").setKey(MODULE_KEY).build())
- .build());
-
- thrown.expect(MessageException.class);
- thrown.expectMessage("Validation of project failed:\n" +
- " o The project \"" + MODULE_KEY + "\" is already defined in SonarQube but not as a module of project \"" + PROJECT_KEY + "\". " +
- "If you really want to stop directly analysing project \"" + MODULE_KEY + "\", please first delete it from SonarQube and then relaunch the analysis of project \""
- + PROJECT_KEY + "\".");
-
- underTest.execute(new TestComputationStepContext());
- }
-
- @Test
- public void fail_if_module_key_already_exists_in_another_project() {
- String anotherProjectKey = "ANOTHER_PROJECT_KEY";
- reportReader.putComponent(ScannerReport.Component.newBuilder()
- .setRef(1)
- .setType(ComponentType.PROJECT)
- .setKey(PROJECT_KEY)
- .addChildRef(2)
- .build());
- reportReader.putComponent(ScannerReport.Component.newBuilder()
- .setRef(2)
- .setType(ComponentType.MODULE)
- .setKey(MODULE_KEY)
- .build());
-
- OrganizationDto organizationDto = dbTester.organizations().insert();
- ComponentDto project = ComponentTesting.newPrivateProjectDto(organizationDto, "ABCD").setDbKey(PROJECT_KEY);
- ComponentDto anotherProject = ComponentTesting.newPrivateProjectDto(organizationDto).setDbKey(anotherProjectKey);
- dbClient.componentDao().insert(dbTester.getSession(), project, anotherProject);
- ComponentDto module = ComponentTesting.newModuleDto("BCDE", anotherProject).setDbKey(MODULE_KEY);
- dbClient.componentDao().insert(dbTester.getSession(), module);
- dbTester.getSession().commit();
-
- treeRootHolder.setRoot(ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").setKey(PROJECT_KEY).addChildren(
- ReportComponent.builder(Component.Type.MODULE, 2).setUuid("BCDE").setKey(MODULE_KEY).build())
- .build());
-
- thrown.expect(MessageException.class);
- thrown.expectMessage("Validation of project failed:\n" +
- " o Module \"" + MODULE_KEY + "\" is already part of project \"" + anotherProjectKey + "\"");
-
- underTest.execute(new TestComputationStepContext());
- }
-
@Test
public void not_fail_if_analysis_date_is_after_last_analysis() {
reportReader.putComponent(ScannerReport.Component.newBuilder()
// only static stuff
}
- public static String createEffectiveKey(String moduleKey, InputPath inputPath) {
- return createEffectiveKey(moduleKey, inputPath.relativePath());
+ public static String createEffectiveKey(String projectKey, InputPath inputPath) {
+ return createEffectiveKey(projectKey, inputPath.relativePath());
}
- public static String createEffectiveKey(String moduleKey, @Nullable String path) {
+ public static String createEffectiveKey(String projectKey, @Nullable String path) {
StringBuilder sb = new StringBuilder(MAX_COMPONENT_KEY_LENGTH);
- sb.append(moduleKey);
+ sb.append(projectKey);
if (path != null) {
sb.append(':').append(path);
}