]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-11549 Remove code that load old scanner reports with modules (MMF-365)
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Tue, 5 Mar 2019 20:00:25 +0000 (14:00 -0600)
committerSonarTech <sonartech@sonarsource.com>
Fri, 15 Mar 2019 19:20:55 +0000 (20:20 +0100)
12 files changed:
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/ComponentTreeBuilder.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/ReportModulesPath.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/container/ProjectAnalysisTaskContainerPopulator.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/IssueRelocationToRoot.java [deleted file]
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/TrackerRawInputFactory.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/BuildComponentTreeStep.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ComponentTreeBuilderTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ReportModulesPathTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/IntegrateIssuesVisitorTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/IssueRelocationToRootTest.java [deleted file]
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/TrackerRawInputFactoryTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/BuildComponentTreeStepTest.java

index 811412b777923c6cdb52d8d52621b9271fc457b9..688b514ab5eee2c8673b469b2c820265a9e8132f 100644 (file)
@@ -32,7 +32,6 @@ import javax.annotation.Nullable;
 import org.apache.commons.io.FilenameUtils;
 import org.apache.commons.lang.StringUtils;
 import org.sonar.ce.task.projectanalysis.analysis.Branch;
-import org.sonar.ce.task.projectanalysis.issue.IssueRelocationToRoot;
 import org.sonar.core.util.stream.MoreCollectors;
 import org.sonar.scanner.protocol.output.ScannerReport;
 import org.sonar.scanner.protocol.output.ScannerReport.Component.FileStatus;
@@ -67,7 +66,6 @@ public class ComponentTreeBuilder {
   private final Branch branch;
   @Nullable
   private final ProjectAttributes projectAttributes;
-  private final IssueRelocationToRoot issueRelocationToRoot;
 
   private ScannerReport.Component rootComponent;
   private String scmBasePath;
@@ -79,8 +77,7 @@ public class ComponentTreeBuilder {
     Function<Integer, ScannerReport.Component> scannerComponentSupplier,
     Project project,
     Branch branch,
-    ProjectAttributes projectAttributes,
-    IssueRelocationToRoot issueRelocationToRoot) {
+    ProjectAttributes projectAttributes) {
 
     this.keyGenerator = keyGenerator;
     this.publicKeyGenerator = publicKeyGenerator;
@@ -89,7 +86,6 @@ public class ComponentTreeBuilder {
     this.project = project;
     this.branch = branch;
     this.projectAttributes = requireNonNull(projectAttributes, "projectAttributes can't be null");
-    this.issueRelocationToRoot = issueRelocationToRoot;
   }
 
   public Component buildProject(ScannerReport.Component project, String scmBasePath) {
@@ -118,13 +114,6 @@ public class ComponentTreeBuilder {
         case FILE:
           addFile(root, component);
           break;
-        case MODULE:
-        case DIRECTORY:
-          issueRelocationToRoot.relocate(rootComponent, component);
-          component.getChildRefList().stream()
-            .map(scannerComponentSupplier)
-            .forEach(queue::addLast);
-          break;
         default:
           throw new IllegalArgumentException(format("Unsupported component type '%s'", component.getType()));
       }
index ef7c23b97fcaa67bdd3c72e04e510518a879b455..a2a8f63beb0dde7b1ab64d8a25248c6d220c5d61 100644 (file)
@@ -19,8 +19,6 @@
  */
 package org.sonar.ce.task.projectanalysis.component;
 
-import java.util.LinkedHashMap;
-import java.util.LinkedList;
 import java.util.Map;
 import java.util.function.Supplier;
 import org.sonar.ce.task.projectanalysis.batch.BatchReportReader;
@@ -28,40 +26,17 @@ import org.sonar.scanner.protocol.output.ScannerReport;
 
 public class ReportModulesPath implements Supplier<Map<String, String>> {
   private final BatchReportReader reader;
+  private Map<String, String> cache;
 
   public ReportModulesPath(BatchReportReader reader) {
     this.reader = reader;
   }
 
   public Map<String, String> get() {
-    ScannerReport.Metadata metadata = reader.readMetadata();
-    Map<String, String> modulesProjectRelativePathByKey = metadata.getModulesProjectRelativePathByKeyMap();
-    if (modulesProjectRelativePathByKey.isEmpty()) {
-      return collectModulesPathFromHierarchy(metadata);
+    if (cache == null) {
+      ScannerReport.Metadata metadata = reader.readMetadata();
+      cache = metadata.getModulesProjectRelativePathByKeyMap();
     }
-    return modulesProjectRelativePathByKey;
+    return cache;
   }
-
-  /**
-   * This should only be needed if we receive a report of the previous version without the path per module explicitly set
-   * (due to blue/green deployment)
-   * Can be removed in any future version
-   */
-  private Map<String, String> collectModulesPathFromHierarchy(ScannerReport.Metadata metadata) {
-    ScannerReport.Component root = reader.readComponent(metadata.getRootComponentRef());
-    Map<String, String> modulesPathByKey = new LinkedHashMap<>();
-    LinkedList<Integer> queue = new LinkedList<>();
-    queue.addAll(root.getChildRefList());
-
-    while (!queue.isEmpty()) {
-      ScannerReport.Component component = reader.readComponent(queue.removeFirst());
-      if (component.getType() == ScannerReport.Component.ComponentType.MODULE) {
-        queue.addAll(component.getChildRefList());
-        modulesPathByKey.put(component.getKey(), component.getProjectRelativePath());
-      }
-    }
-
-    return modulesPathByKey;
-  }
-
 }
index 5013704bd6d630fb8e9d40fc8ea1d9778dee0ba5..b467ff75ecc2615cef4860de0f05b491af17706f 100644 (file)
@@ -65,7 +65,6 @@ import org.sonar.ce.task.projectanalysis.issue.IssueCache;
 import org.sonar.ce.task.projectanalysis.issue.IssueCounter;
 import org.sonar.ce.task.projectanalysis.issue.IssueCreationDateCalculator;
 import org.sonar.ce.task.projectanalysis.issue.IssueLifecycle;
-import org.sonar.ce.task.projectanalysis.issue.IssueRelocationToRoot;
 import org.sonar.ce.task.projectanalysis.issue.IssueTrackingDelegator;
 import org.sonar.ce.task.projectanalysis.issue.IssueVisitors;
 import org.sonar.ce.task.projectanalysis.issue.IssuesRepositoryVisitor;
@@ -234,7 +233,6 @@ public final class ProjectAnalysisTaskContainerPopulator implements ContainerPop
       ComponentsWithUnprocessedIssues.class,
       ComponentIssuesRepositoryImpl.class,
       IssueFilter.class,
-      IssueRelocationToRoot.class,
 
       // common rules
       CommonRuleEngineImpl.class,
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/IssueRelocationToRoot.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/IssueRelocationToRoot.java
deleted file mode 100644 (file)
index 00418db..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2019 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.ce.task.projectanalysis.issue;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.stream.Collectors;
-import org.sonar.ce.task.projectanalysis.batch.BatchReportReader;
-import org.sonar.core.util.CloseableIterator;
-import org.sonar.scanner.protocol.output.ScannerReport;
-
-public class IssueRelocationToRoot {
-  private final BatchReportReader reader;
-  private final List<ScannerReport.Issue> movedIssues = new ArrayList<>();
-
-  public IssueRelocationToRoot(BatchReportReader reader) {
-    this.reader = reader;
-  }
-
-  public List<ScannerReport.Issue> getMovedIssues() {
-    return Collections.unmodifiableList(movedIssues);
-  }
-
-  public void relocate(ScannerReport.Component root, ScannerReport.Component component) {
-    CloseableIterator<ScannerReport.Issue> issueIt = reader.readComponentIssues(component.getRef());
-    while (issueIt.hasNext()) {
-      ScannerReport.Issue issue = issueIt.next();
-      movedIssues.add(moveIssueToRoot(root, component, issue));
-    }
-  }
-
-  private static ScannerReport.Issue moveIssueToRoot(ScannerReport.Component root, ScannerReport.Component component, ScannerReport.Issue issue) {
-    return ScannerReport.Issue.newBuilder(issue)
-      .clearFlow()
-      .clearTextRange()
-      .addAllFlow(issue.getFlowList().stream()
-        .map(flow -> moveFlow(root, component, flow))
-        .collect(Collectors.toList()))
-      .build();
-  }
-
-  private static ScannerReport.IssueLocation moveLocation(ScannerReport.Component root, ScannerReport.Component component, ScannerReport.IssueLocation location) {
-    String msg = "[" + component.getProjectRelativePath() + "] " + location.getMsg();
-    return ScannerReport.IssueLocation.newBuilder()
-      .setComponentRef(root.getRef())
-      .setMsg(msg)
-      .build();
-  }
-
-  private static ScannerReport.Flow moveFlow(ScannerReport.Component root, ScannerReport.Component component, ScannerReport.Flow flow) {
-    return ScannerReport.Flow.newBuilder()
-      .addAllLocation(flow.getLocationList().stream()
-        .map(location -> moveLocation(root, component, location))
-        .collect(Collectors.toList()))
-      .build();
-  }
-}
index eb44e5e43d8eb5e085b8a320317c6a9d2fb2a634..2cd65c16a0a5c344d0018955ba5333330fb84bab 100644 (file)
@@ -61,11 +61,10 @@ public class TrackerRawInputFactory {
   private final SourceLinesHashRepository sourceLinesHash;
   private final RuleRepository ruleRepository;
   private final ActiveRulesHolder activeRulesHolder;
-  private final IssueRelocationToRoot issueRelocationToRoot;
 
   public TrackerRawInputFactory(TreeRootHolder treeRootHolder, BatchReportReader reportReader,
     SourceLinesHashRepository sourceLinesHash, CommonRuleEngine commonRuleEngine, IssueFilter issueFilter, RuleRepository ruleRepository,
-    ActiveRulesHolder activeRulesHolder, IssueRelocationToRoot issueRelocationToRoot) {
+    ActiveRulesHolder activeRulesHolder) {
     this.treeRootHolder = treeRootHolder;
     this.reportReader = reportReader;
     this.sourceLinesHash = sourceLinesHash;
@@ -73,7 +72,6 @@ public class TrackerRawInputFactory {
     this.issueFilter = issueFilter;
     this.ruleRepository = ruleRepository;
     this.activeRulesHolder = activeRulesHolder;
-    this.issueRelocationToRoot = issueRelocationToRoot;
   }
 
   public Input<DefaultIssue> create(Component component) {
@@ -146,13 +144,6 @@ public class TrackerRawInputFactory {
         }
       }
 
-      if (component.getType() == Component.Type.PROJECT) {
-        // TODO apply filters?
-        issueRelocationToRoot.getMovedIssues().stream()
-          .map(i -> toIssue(getLineHashSequence(), i))
-          .forEach(result::add);
-      }
-
       return result;
     }
 
index 807756a4233805c8ec35b3a880c9f1a006bcc6e2..1fd3bcaa91ecb3ad7bdc9425f010adc5ecc6283c 100644 (file)
@@ -34,7 +34,6 @@ import org.sonar.ce.task.projectanalysis.component.DefaultBranchImpl;
 import org.sonar.ce.task.projectanalysis.component.MutableTreeRootHolder;
 import org.sonar.ce.task.projectanalysis.component.ProjectAttributes;
 import org.sonar.ce.task.projectanalysis.component.ReportModulesPath;
-import org.sonar.ce.task.projectanalysis.issue.IssueRelocationToRoot;
 import org.sonar.ce.task.step.ComputationStep;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
@@ -55,16 +54,14 @@ public class BuildComponentTreeStep implements ComputationStep {
   private final BatchReportReader reportReader;
   private final MutableTreeRootHolder treeRootHolder;
   private final MutableAnalysisMetadataHolder analysisMetadataHolder;
-  private final IssueRelocationToRoot issueRelocationToRoot;
   private final ReportModulesPath reportModulesPath;
 
   public BuildComponentTreeStep(DbClient dbClient, BatchReportReader reportReader, MutableTreeRootHolder treeRootHolder,
-    MutableAnalysisMetadataHolder analysisMetadataHolder, IssueRelocationToRoot issueRelocationToRoot, ReportModulesPath reportModulesPath) {
+    MutableAnalysisMetadataHolder analysisMetadataHolder, ReportModulesPath reportModulesPath) {
     this.dbClient = dbClient;
     this.reportReader = reportReader;
     this.treeRootHolder = treeRootHolder;
     this.analysisMetadataHolder = analysisMetadataHolder;
-    this.issueRelocationToRoot = issueRelocationToRoot;
     this.reportModulesPath = reportModulesPath;
   }
 
@@ -95,8 +92,7 @@ public class BuildComponentTreeStep implements ComputationStep {
         reportReader::readComponent,
         analysisMetadataHolder.getProject(),
         analysisMetadataHolder.getBranch(),
-        createProjectAttributes(metadata, baseAnalysis.orElse(null)),
-        issueRelocationToRoot);
+        createProjectAttributes(metadata, baseAnalysis.orElse(null)));
       String relativePathFromScmRoot = metadata.getRelativePathFromScmRoot();
 
       Component reportTreeRoot = builder.buildProject(reportProject, relativePathFromScmRoot);
index aced5c23fa2f5607a450f31e7f69ec8c4d401c2a..2788ecd315a7ebfd63eb88c0f9083945f6470ace 100644 (file)
@@ -37,7 +37,6 @@ import org.junit.rules.ExpectedException;
 import org.junit.rules.ExternalResource;
 import org.junit.runner.RunWith;
 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.scanner.protocol.output.ScannerReport;
 import org.sonar.server.project.Project;
@@ -47,18 +46,16 @@ 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.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
 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;
 
 @RunWith(DataProviderRunner.class)
 public class ComponentTreeBuilderTest {
@@ -68,14 +65,13 @@ public class ComponentTreeBuilderTest {
   private static final ComponentKeyGenerator PUBLIC_KEY_GENERATOR = (projectKey, path) -> "public_"
     + ComponentKeys.createEffectiveKey(projectKey, 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 EnumSet<ScannerReport.Component.ComponentType> REPORT_TYPES = EnumSet.of(PROJECT, FILE);
   private static final String NO_SCM_BASE_PATH = "";
   // both no project as "" or null should be supported
   private static final ProjectAttributes SOME_PROJECT_ATTRIBUTES = new ProjectAttributes(
     new Random().nextBoolean() ? null : randomAlphabetic(12),
     randomAlphabetic(20));
 
-  private IssueRelocationToRoot issueRelocationToRoot = mock(IssueRelocationToRoot.class);
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
 
@@ -85,12 +81,13 @@ public class ComponentTreeBuilderTest {
   private Project projectInDb = Project.from(newPrivateProjectDto(newOrganizationDto(), UUID_SUPPLIER.apply("K1")).setDbKey("K1").setDescription(null));
 
   @Test
-  public void build_throws_IAE_for_all_types_except_PROJECT_MODULE_DIRECTORY_FILE() {
+  public void build_throws_IAE_for_all_types_except_PROJECT_and_FILE() {
     Arrays.stream(ScannerReport.Component.ComponentType.values())
       .filter((type) -> type != UNRECOGNIZED)
       .filter((type) -> !REPORT_TYPES.contains(type))
       .forEach(
         (type) -> {
+          scannerComponentProvider.clear();
           ScannerReport.Component project = newBuilder()
             .setType(PROJECT)
             .setKey(projectInDb.getKey())
@@ -344,16 +341,6 @@ public class ComponentTreeBuilderTest {
       .build();
     scannerComponentProvider.add(newBuilder()
       .setRef(2)
-      .setType(MODULE)
-      .setKey("M")
-      .addChildRef(3));
-    scannerComponentProvider.add(newBuilder()
-      .setRef(3)
-      .setType(DIRECTORY)
-      .setProjectRelativePath("src/js")
-      .addChildRef(4));
-    scannerComponentProvider.add(newBuilder()
-      .setRef(4)
       .setType(FILE)
       .setProjectRelativePath("src/js/Foo.js")
       .setLines(1));
@@ -370,20 +357,10 @@ public class ComponentTreeBuilderTest {
       .setType(PROJECT)
       .setKey(projectInDb.getKey())
       .setRef(1)
-      .addChildRef(2)
-      .addChildRef(3)
+      .addChildRef(4)
+      .addChildRef(5)
       .addChildRef(6)
       .build();
-    scannerComponentProvider.add(newBuilder()
-      .setRef(2)
-      .setType(DIRECTORY)
-      .setProjectRelativePath("src/main/xoo")
-      .addChildRef(4));
-    scannerComponentProvider.add(newBuilder()
-      .setRef(3)
-      .setType(DIRECTORY)
-      .setProjectRelativePath("src/test/xoo/org/sonar")
-      .addChildRef(5));
     scannerComponentProvider.add(newBuilder()
       .setRef(4)
       .setType(FILE)
@@ -403,11 +380,11 @@ public class ComponentTreeBuilderTest {
     Component root = call(project);
     assertThat(root.getChildren()).hasSize(2);
 
-    Component pom = root.getChildren().get(0);
+    Component pom = root.getChildren().get(1);
     assertThat(pom.getKey()).isEqualTo("public_K1:pom.xml");
     assertThat(pom.getName()).isEqualTo("pom.xml");
 
-    Component directory = root.getChildren().get(1);
+    Component directory = root.getChildren().get(0);
     assertThat(directory.getKey()).isEqualTo("public_K1:src");
     assertThat(directory.getName()).isEqualTo("src");
 
@@ -461,11 +438,6 @@ public class ComponentTreeBuilderTest {
       .build();
     scannerComponentProvider.add(newBuilder()
       .setRef(2)
-      .setType(DIRECTORY)
-      .setProjectRelativePath("/")
-      .addChildRef(3));
-    scannerComponentProvider.add(newBuilder()
-      .setRef(3)
       .setType(FILE)
       .setProjectRelativePath("src/js/Foo.js")
       .setLines(1));
@@ -493,12 +465,6 @@ public class ComponentTreeBuilderTest {
       .build();
     scannerComponentProvider.add(newBuilder()
       .setRef(2)
-      .setType(DIRECTORY)
-      .setProjectRelativePath("src/js")
-      .setName("")
-      .addChildRef(3));
-    scannerComponentProvider.add(newBuilder()
-      .setRef(3)
       .setType(FILE)
       .setProjectRelativePath("src/js/Foo.js")
       .setName("")
@@ -575,23 +541,8 @@ public class ComponentTreeBuilderTest {
       .setType(PROJECT)
       .setKey("project 1")
       .setRef(1)
-      .addChildRef(11).addChildRef(21).addChildRef(31).build();
-    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).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));
+      .addChildRef(31).build();
     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<String, Component> componentsByKey = indexComponentByKey(root);
 
@@ -609,16 +560,6 @@ public class ComponentTreeBuilderTest {
       .build();
     scannerComponentProvider.add(newBuilder()
       .setRef(2)
-      .setType(MODULE)
-      .setKey("c2")
-      .addChildRef(3));
-    scannerComponentProvider.add(newBuilder()
-      .setRef(3)
-      .setType(DIRECTORY)
-      .setProjectRelativePath("src/js")
-      .addChildRef(4));
-    scannerComponentProvider.add(newBuilder()
-      .setRef(4)
       .setType(FILE)
       .setProjectRelativePath("src/js/Foo.js")
       .setLines(1));
@@ -641,29 +582,14 @@ public class ComponentTreeBuilderTest {
       .setRef(1)
       .addChildRef(2)
       .build();
-    ScannerReport.Component.Builder module = newBuilder()
-      .setRef(2)
-      .setType(MODULE)
-      .setKey("c2")
-      .addChildRef(3);
-    scannerComponentProvider.add(module);
-    ScannerReport.Component.Builder directory = newBuilder()
-      .setRef(3)
-      .setType(DIRECTORY)
-      .setProjectRelativePath("src/js")
-      .addChildRef(4);
-    scannerComponentProvider.add(directory);
     ScannerReport.Component.Builder file = newBuilder()
-      .setRef(4)
+      .setRef(2)
       .setType(FILE)
       .setProjectRelativePath("src/js/Foo.js")
       .setLines(1);
     scannerComponentProvider.add(file);
 
     call(project);
-    verify(issueRelocationToRoot).relocate(project, module.build());
-    verify(issueRelocationToRoot).relocate(project, directory.build());
-    verifyNoMoreInteractions(issueRelocationToRoot);
   }
 
   @Test
@@ -675,15 +601,6 @@ public class ComponentTreeBuilderTest {
       .build();
     scannerComponentProvider.add(newBuilder()
       .setRef(2)
-      .setType(MODULE)
-      .addChildRef(3));
-    scannerComponentProvider.add(newBuilder()
-      .setRef(3)
-      .setType(DIRECTORY)
-      .setProjectRelativePath("src/js")
-      .addChildRef(4));
-    scannerComponentProvider.add(newBuilder()
-      .setRef(4)
       .setType(FILE)
       .setProjectRelativePath("src/js/Foo.js")
       .setLines(1));
@@ -707,17 +624,6 @@ public class ComponentTreeBuilderTest {
       .build();
     scannerComponentProvider.add(newBuilder()
       .setRef(2)
-      .setType(MODULE)
-      .setDescription("")
-      .addChildRef(3));
-    scannerComponentProvider.add(newBuilder()
-      .setRef(3)
-      .setType(DIRECTORY)
-      .setDescription("")
-      .setProjectRelativePath("src/js")
-      .addChildRef(4));
-    scannerComponentProvider.add(newBuilder()
-      .setRef(4)
       .setType(FILE)
       .setDescription("")
       .setProjectRelativePath("src/js/Foo.js")
@@ -741,12 +647,6 @@ public class ComponentTreeBuilderTest {
       .build();
     scannerComponentProvider.add(newBuilder()
       .setRef(2)
-      .setType(DIRECTORY)
-      .setDescription("c")
-      .setProjectRelativePath("src/js")
-      .addChildRef(3));
-    scannerComponentProvider.add(newBuilder()
-      .setRef(3)
       .setType(FILE)
       .setDescription("d")
       .setProjectRelativePath("src/js/Foo.js")
@@ -886,6 +786,10 @@ public class ComponentTreeBuilderTest {
 
     @Override
     protected void before() {
+      clear();
+    }
+
+    public void clear() {
       components.clear();
     }
 
@@ -914,8 +818,7 @@ public class ComponentTreeBuilderTest {
     Branch branch = mock(Branch.class);
     when(branch.isMain()).thenReturn(mainBranch);
     return new ComponentTreeBuilder(KEY_GENERATOR, PUBLIC_KEY_GENERATOR, UUID_SUPPLIER, scannerComponentProvider,
-      projectInDb, branch, projectAttributes,
-      issueRelocationToRoot);
+      projectInDb, branch, projectAttributes);
   }
 
   private static Map<String, Component> indexComponentByKey(Component root) {
index 751255360aaf3a4272725649165ddb0e072dbd70..72012a29cb8c1476586848f05443dc9f46f21e2f 100644 (file)
@@ -19,9 +19,7 @@
  */
 package org.sonar.ce.task.projectanalysis.component;
 
-import java.util.Arrays;
 import java.util.Map;
-import javax.annotation.Nullable;
 import org.junit.Test;
 import org.sonar.ce.task.projectanalysis.batch.BatchReportReader;
 import org.sonar.scanner.protocol.output.ScannerReport;
@@ -32,58 +30,24 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.verifyNoMoreInteractions;
 import static org.mockito.Mockito.when;
+import static org.mockito.internal.verification.VerificationModeFactory.times;
 
 public class ReportModulesPathTest {
   private BatchReportReader reader = mock(BatchReportReader.class);
   private ReportModulesPath reportModulesPath = new ReportModulesPath(reader);
-  private ScannerReport.Component root = addComponent(1, "project", ScannerReport.Component.ComponentType.PROJECT, null, 2);
 
   @Test
-  public void should_not_read_hierarchy_if_metadata_available() {
+  public void should_cache_report_data() {
     when(reader.readMetadata()).thenReturn(ScannerReport.Metadata.newBuilder()
       .putModulesProjectRelativePathByKey("module1", "path1")
       .setRootComponentRef(1)
       .build());
     Map<String, String> pathByModuleKey = reportModulesPath.get();
-
     assertThat(pathByModuleKey).containsExactly(entry("module1", "path1"));
-    verify(reader).readMetadata();
-    verifyNoMoreInteractions(reader);
-  }
-
-  @Test
-  public void should_read_hierarchy_if_metadata_not_available() {
-    when(reader.readMetadata()).thenReturn(ScannerReport.Metadata.newBuilder().setRootComponentRef(1).build());
-    addComponent(2, "project:module1", ScannerReport.Component.ComponentType.MODULE, "path1", 3);
-    addComponent(3, "project:module1:module2", ScannerReport.Component.ComponentType.MODULE, "path1/path2", 4);
-    addComponent(4, "project:module1:module2:dir", ScannerReport.Component.ComponentType.DIRECTORY, "path1/path2/dir");
-
-    Map<String, String> pathByModuleKey = reportModulesPath.get();
-
-    assertThat(pathByModuleKey).containsOnly(
-      entry("project:module1", "path1"),
-      entry("project:module1:module2", "path1/path2"));
-    verify(reader).readMetadata();
-    verify(reader).readComponent(1);
-    verify(reader).readComponent(2);
-    verify(reader).readComponent(3);
-    verify(reader).readComponent(4);
+    pathByModuleKey = reportModulesPath.get();
+    assertThat(pathByModuleKey).containsExactly(entry("module1", "path1"));
 
+    verify(reader, times(1)).readMetadata();
     verifyNoMoreInteractions(reader);
   }
-
-  private ScannerReport.Component addComponent(int ref, String key, ScannerReport.Component.ComponentType type, @Nullable String path, Integer... children) {
-    ScannerReport.Component.Builder builder = ScannerReport.Component.newBuilder()
-      .setRef(ref)
-      .setKey(key)
-      .addAllChildRef(Arrays.asList(children))
-      .setType(type);
-
-    if (path != null) {
-      builder.setProjectRelativePath(path);
-    }
-    ScannerReport.Component component = builder.build();
-    when(reader.readComponent(ref)).thenReturn(component);
-    return component;
-  }
 }
index 1fbad25ab55a67155dd7db7e50ed2d852c1cf7af..5bd063b8d16c414f850d06fce339a6d383fb484e 100644 (file)
@@ -120,7 +120,6 @@ public class IntegrateIssuesVisitorTest {
   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 NewLinesRepository newLinesRepository = mock(NewLinesRepository.class);
 
   private ArgumentCaptor<DefaultIssue> defaultIssueCaptor;
@@ -144,7 +143,7 @@ public class IntegrateIssuesVisitorTest {
 
     DbClient dbClient = dbTester.getDbClient();
     TrackerRawInputFactory rawInputFactory = new TrackerRawInputFactory(treeRootHolder, reportReader, sourceLinesHash, new CommonRuleEngineImpl(),
-      issueFilter, ruleRepositoryRule, activeRulesHolder, issueRelocationToRoot);
+      issueFilter, ruleRepositoryRule, activeRulesHolder);
     TrackerBaseInputFactory baseInputFactory = new TrackerBaseInputFactory(issuesLoader, dbClient, movedFilesRepository, mock(ReportModulesPath.class), analysisMetadataHolder, new IssueFieldsSetter(), mock(ComponentsWithUnprocessedIssues.class));
     TrackerMergeBranchInputFactory mergeInputFactory = new TrackerMergeBranchInputFactory(issuesLoader, mergeBranchComponentsUuids, dbClient);
     ClosedIssuesInputFactory closedIssuesInputFactory = new ClosedIssuesInputFactory(issuesLoader, dbClient, movedFilesRepository);
diff --git a/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/IssueRelocationToRootTest.java b/server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/IssueRelocationToRootTest.java
deleted file mode 100644 (file)
index 7c92a02..0000000
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2019 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.ce.task.projectanalysis.issue;
-
-import java.util.Collections;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.sonar.ce.task.projectanalysis.batch.BatchReportReaderRule;
-import org.sonar.scanner.protocol.output.ScannerReport;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class IssueRelocationToRootTest {
-  @Rule
-  public BatchReportReaderRule reader = new BatchReportReaderRule();
-  private IssueRelocationToRoot underTest = new IssueRelocationToRoot(reader);
-
-  private ScannerReport.Component root;
-  private ScannerReport.Component module;
-  private ScannerReport.Component directory;
-
-  @Before
-  public void createComponents() {
-    root = ScannerReport.Component.newBuilder()
-      .setType(ScannerReport.Component.ComponentType.PROJECT)
-      .setRef(1)
-      .setStatus(ScannerReport.Component.FileStatus.UNAVAILABLE)
-      .setKey("PROJECT")
-      .addChildRef(2)
-      .build();
-    module = ScannerReport.Component.newBuilder()
-      .setType(ScannerReport.Component.ComponentType.MODULE)
-      .setRef(2)
-      .setStatus(ScannerReport.Component.FileStatus.UNAVAILABLE)
-      .setKey("PROJECT:MODULE")
-      .addChildRef(3)
-      .build();
-    directory = ScannerReport.Component.newBuilder()
-      .setType(ScannerReport.Component.ComponentType.DIRECTORY)
-      .setRef(3)
-      .setStatus(ScannerReport.Component.FileStatus.UNAVAILABLE)
-      .setKey("PROJECT:MODULE:DIRECTORY")
-      .addChildRef(4)
-      .build();
-
-    reader.putComponent(root);
-    reader.putComponent(module);
-    reader.putComponent(directory);
-  }
-
-  private void createIssues() {
-    reader.putIssues(2, Collections.singletonList(ScannerReport.Issue.newBuilder().setRuleKey("module_issue").build()));
-    reader.putIssues(3, Collections.singletonList(ScannerReport.Issue.newBuilder().setRuleKey("directory_issue").build()));
-  }
-
-  @Test
-  public void move_module_and_directory_issues() {
-    createComponents();
-    createIssues();
-
-    underTest.relocate(root, module);
-    underTest.relocate(root, directory);
-
-    assertThat(underTest.getMovedIssues()).hasSize(2);
-    assertThat(underTest.getMovedIssues()).extracting(ScannerReport.Issue::getRuleKey).containsOnly("module_issue", "directory_issue");
-  }
-
-  @Test
-  public void do_nothing_if_no_issues() {
-    createComponents();
-    underTest.relocate(root, module);
-    underTest.relocate(root, directory);
-
-    assertThat(underTest.getMovedIssues()).hasSize(0);
-  }
-
-}
index b3b8e6164ace2a0c391014b8799c9f4abbbf1c6d..c6a612c5901cd0446cd2fe5157dbcc8ae735b0a7 100644 (file)
@@ -79,9 +79,8 @@ public class TrackerRawInputFactoryTest {
   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, issueRelocationToRoot);
+    commonRuleEngine, issueFilter, ruleRepository, activeRulesHolder);
 
   @Test
   public void load_source_hash_sequences() {
index bc8c85af43ea226a6d684be7cbdb31df31e84f5b..29d71d67d1f1b94fb50376f38c06502b95dd785e 100644 (file)
@@ -36,7 +36,6 @@ 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.component.ReportModulesPath;
-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;
@@ -57,13 +56,10 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 import static org.sonar.db.component.ComponentTesting.newDirectory;
 import static org.sonar.db.component.ComponentTesting.newFileDto;
-import static org.sonar.db.component.ComponentTesting.newModuleDto;
 import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
 import static org.sonar.db.component.SnapshotTesting.newAnalysis;
 import static org.sonar.db.organization.OrganizationTesting.newOrganizationDto;
-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;
 
 @RunWith(DataProviderRunner.class)
@@ -72,14 +68,9 @@ public class BuildComponentTreeStepTest {
   private static final String NO_SCANNER_CODE_PERIOD_VERSION = null;
 
   private static final int ROOT_REF = 1;
-  private static final int MODULE_REF = 2;
-  private static final int DIR_REF_1 = 3;
   private static final int FILE_1_REF = 4;
   private static final int FILE_2_REF = 5;
-  private static final int DIR_REF_2 = 6;
   private static final int FILE_3_REF = 7;
-  private static final int LEAFLESS_MODULE_REF = 8;
-  private static final int LEAFLESS_DIR_REF = 9;
   private static final int UNCHANGED_FILE_REF = 10;
 
   private static final String REPORT_PROJECT_KEY = "REPORT_PROJECT_KEY";
@@ -105,11 +96,9 @@ public class BuildComponentTreeStepTest {
   @Rule
   public MutableAnalysisMetadataHolderRule analysisMetadataHolder = new MutableAnalysisMetadataHolderRule();
   private ReportModulesPath reportModulesPath = new ReportModulesPath(reportReader);
-  private IssueRelocationToRoot issueRelocationToRoot = mock(IssueRelocationToRoot.class);
 
   private DbClient dbClient = dbTester.getDbClient();
-  private BuildComponentTreeStep underTest = new BuildComponentTreeStep(dbClient, reportReader, treeRootHolder, analysisMetadataHolder,
-    issueRelocationToRoot, reportModulesPath);
+  private BuildComponentTreeStep underTest = new BuildComponentTreeStep(dbClient, reportReader, treeRootHolder, analysisMetadataHolder, reportModulesPath);
 
   @Test(expected = NullPointerException.class)
   public void fails_if_root_component_does_not_exist_in_reportReader() {
@@ -121,12 +110,9 @@ public class BuildComponentTreeStepTest {
   @Test
   public void verify_tree_is_correctly_built() {
     setAnalysisMetadataHolder();
-    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(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY, FILE_1_REF, FILE_2_REF, FILE_3_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();
@@ -154,9 +140,7 @@ public class BuildComponentTreeStepTest {
   @Test
   public void compute_keys_and_uuids() {
     setAnalysisMetadataHolder();
-    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(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY, FILE_1_REF));
     reportReader.putComponent(componentWithPath(FILE_1_REF, FILE, REPORT_FILE_PATH_1));
 
     underTest.execute(new TestComputationStepContext());
@@ -178,8 +162,7 @@ public class BuildComponentTreeStepTest {
       .setPath(REPORT_FILE_PATH_1));
 
     // new structure, without modules
-    reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY, DIR_REF_1));
-    reportReader.putComponent(componentWithPath(DIR_REF_1, DIRECTORY, REPORT_DIR_PATH_1, FILE_1_REF));
+    reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY, FILE_1_REF));
     reportReader.putComponent(componentWithPath(FILE_1_REF, FILE, REPORT_FILE_PATH_1));
 
     underTest.execute(new TestComputationStepContext());
@@ -189,31 +172,6 @@ public class BuildComponentTreeStepTest {
     verifyComponentByRef(FILE_1_REF, REPORT_PROJECT_KEY + ":" + REPORT_FILE_PATH_1, REPORT_FILE_NAME_1, "DEFG");
   }
 
-  @Test
-  public void return_existing_uuids_with_modules() {
-    setAnalysisMetadataHolder();
-    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_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)
-      .setPath(REPORT_FILE_PATH_1));
-
-    // new structure, without modules
-    reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY, DIR_REF_1));
-    reportReader.putComponent(componentWithPath(DIR_REF_1, DIRECTORY, "module/" + REPORT_DIR_PATH_1, FILE_1_REF));
-    reportReader.putComponent(componentWithPath(FILE_1_REF, FILE, "module/" + REPORT_FILE_PATH_1));
-    reportReader.setMetadata(ScannerReport.Metadata.newBuilder().putModulesProjectRelativePathByKey(REPORT_MODULE_KEY,
-      "module").build());
-    underTest.execute(new TestComputationStepContext());
-
-    verifyComponentByRef(ROOT_REF, REPORT_PROJECT_KEY, analysisMetadataHolder.getProject().getName(), "ABCD");
-    verifyComponentByKey(REPORT_PROJECT_KEY + ":module/" + REPORT_DIR_PATH_1, REPORT_PROJECT_KEY + ":module/" + REPORT_DIR_PATH_1, "module/" + REPORT_DIR_PATH_1, "CDEF");
-    verifyComponentByRef(FILE_1_REF, REPORT_PROJECT_KEY + ":module/" + REPORT_FILE_PATH_1, REPORT_FILE_NAME_1, "DEFG");
-  }
-
   @Test
   public void generate_keys_when_using_new_branch() {
     Branch branch = mock(Branch.class);
@@ -225,11 +183,8 @@ public class BuildComponentTreeStepTest {
       .setAnalysisDate(ANALYSIS_DATE)
       .setProject(Project.from(newPrivateProjectDto(newOrganizationDto()).setDbKey(REPORT_PROJECT_KEY)))
       .setBranch(branch);
-    BuildComponentTreeStep underTest = new BuildComponentTreeStep(dbClient, reportReader, treeRootHolder, analysisMetadataHolder,
-      issueRelocationToRoot, reportModulesPath);
-    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));
+    BuildComponentTreeStep underTest = new BuildComponentTreeStep(dbClient, reportReader, treeRootHolder, analysisMetadataHolder, reportModulesPath);
+    reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY, FILE_1_REF));
     reportReader.putComponent(componentWithPath(FILE_1_REF, FILE, REPORT_FILE_PATH_1));
 
     underTest.execute(new TestComputationStepContext());
@@ -240,90 +195,6 @@ public class BuildComponentTreeStepTest {
     verifyComponentByRef(FILE_1_REF, "generated", REPORT_PROJECT_KEY + ":" + REPORT_FILE_PATH_1, REPORT_FILE_NAME_1, null);
   }
 
-  @Test
-  @UseDataProvider("shortLivingBranchAndPullRequest")
-  public void prune_modules_and_directories_without_leaf_descendants_on_non_long_branch(BranchType branchType) {
-    Branch branch = mock(Branch.class);
-    when(branch.getName()).thenReturn("origin/feature");
-    when(branch.isMain()).thenReturn(false);
-    when(branch.getType()).thenReturn(branchType);
-    when(branch.isLegacyFeature()).thenReturn(false);
-    when(branch.generateKey(any(), any())).thenReturn("generated");
-    analysisMetadataHolder.setRootComponentRef(ROOT_REF)
-      .setAnalysisDate(ANALYSIS_DATE)
-      .setProject(Project.from(newPrivateProjectDto(newOrganizationDto()).setDbKey(REPORT_PROJECT_KEY)))
-      .setBranch(branch);
-    BuildComponentTreeStep underTest = new BuildComponentTreeStep(dbClient, reportReader, treeRootHolder, analysisMetadataHolder,
-      issueRelocationToRoot, reportModulesPath);
-    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)
-      .setProjectRelativePath(REPORT_UNCHANGED_FILE_PATH)
-      .setStatus(FileStatus.SAME)
-      .setLines(1)
-      .build();
-    reportReader.putComponent(unchangedFile);
-
-    underTest.execute(new TestComputationStepContext());
-
-    verifyComponentByRef(ROOT_REF, "generated", REPORT_PROJECT_KEY, analysisMetadataHolder.getProject().getName(), null);
-    verifyComponentByKey(REPORT_PROJECT_KEY + ":" + REPORT_DIR_PATH_1, "generated", "dir1");
-    verifyComponentByRef(FILE_1_REF, "generated", REPORT_PROJECT_KEY + ":" + REPORT_FILE_PATH_1, REPORT_FILE_NAME_1, null);
-
-    verifyComponentMissingByRef(LEAFLESS_MODULE_REF);
-    verifyComponentMissingByRef(LEAFLESS_DIR_REF);
-    verifyComponentMissingByRef(UNCHANGED_FILE_REF);
-  }
-
-  @Test
-  public void do_not_prune_modules_and_directories_without_leaf_descendants_on_long_branch() {
-    Branch branch = mock(Branch.class);
-    when(branch.getName()).thenReturn("origin/feature");
-    when(branch.isMain()).thenReturn(false);
-    when(branch.getType()).thenReturn(BranchType.LONG);
-    when(branch.isLegacyFeature()).thenReturn(false);
-    when(branch.generateKey(any(), any())).thenReturn("generated");
-    analysisMetadataHolder.setRootComponentRef(ROOT_REF)
-      .setAnalysisDate(ANALYSIS_DATE)
-      .setProject(Project.from(newPrivateProjectDto(newOrganizationDto()).setDbKey(REPORT_PROJECT_KEY)))
-      .setBranch(branch);
-    BuildComponentTreeStep underTest = new BuildComponentTreeStep(dbClient, reportReader, treeRootHolder, analysisMetadataHolder,
-      issueRelocationToRoot, reportModulesPath);
-    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)
-      .setProjectRelativePath(REPORT_UNCHANGED_FILE_PATH)
-      .setStatus(FileStatus.SAME)
-      .setLines(1)
-      .build();
-    reportReader.putComponent(unchangedFile);
-
-    underTest.execute(new TestComputationStepContext());
-
-    verifyComponentByRef(ROOT_REF, "generated", REPORT_PROJECT_KEY, analysisMetadataHolder.getProject().getName(), null);
-    verifyComponentMissingByRef(MODULE_REF);
-    verifyComponentByKey(REPORT_PROJECT_KEY + ":" + REPORT_DIR_PATH_1, "generated", "dir1");
-    verifyComponentByRef(FILE_1_REF, "generated", REPORT_PROJECT_KEY + ":" + REPORT_FILE_PATH_1, REPORT_FILE_NAME_1, null);
-
-    verifyComponentMissingByRef(LEAFLESS_MODULE_REF);
-    verifyComponentByKey(REPORT_PROJECT_KEY + ":" + REPORT_LEAFLESS_DIR_PATH, "generated", "leafless");
-    verifyComponentByRef(UNCHANGED_FILE_REF, "generated", REPORT_PROJECT_KEY + ":" + REPORT_UNCHANGED_FILE_PATH, "File3.java", null);
-  }
-
   @DataProvider
   public static Object[][] shortLivingBranchAndPullRequest() {
     return new Object[][] {{BranchType.SHORT}, {BranchType.PULL_REQUEST}};
@@ -342,8 +213,7 @@ public class BuildComponentTreeStepTest {
       .setAnalysisDate(ANALYSIS_DATE)
       .setProject(Project.from(projectDto))
       .setBranch(branch);
-    BuildComponentTreeStep underTest = new BuildComponentTreeStep(dbClient, reportReader, treeRootHolder, analysisMetadataHolder,
-      issueRelocationToRoot, reportModulesPath);
+    BuildComponentTreeStep underTest = new BuildComponentTreeStep(dbClient, reportReader, treeRootHolder, analysisMetadataHolder, reportModulesPath);
     reportReader.putComponent(component(ROOT_REF, PROJECT, branchDto.getKey()));
 
     underTest.execute(new TestComputationStepContext());
@@ -358,17 +228,13 @@ public class BuildComponentTreeStepTest {
       .setAnalysisDate(ANALYSIS_DATE)
       .setProject(Project.from(newPrivateProjectDto(newOrganizationDto()).setDbKey(REPORT_PROJECT_KEY)))
       .setBranch(branch);
-    BuildComponentTreeStep underTest = new BuildComponentTreeStep(dbClient, reportReader, treeRootHolder, analysisMetadataHolder,
-      issueRelocationToRoot, reportModulesPath);
-    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));
+    BuildComponentTreeStep underTest = new BuildComponentTreeStep(dbClient, reportReader, treeRootHolder, analysisMetadataHolder, reportModulesPath);
+    reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY, FILE_1_REF));
     reportReader.putComponent(componentWithPath(FILE_1_REF, FILE, REPORT_FILE_PATH_1));
 
     underTest.execute(new TestComputationStepContext());
 
     verifyComponentByRef(ROOT_REF, REPORT_PROJECT_KEY, REPORT_PROJECT_KEY, analysisMetadataHolder.getProject().getName(), null);
-    verifyComponentMissingByRef(MODULE_REF);
     verifyComponentByKey(REPORT_PROJECT_KEY + ":" + REPORT_DIR_PATH_1, REPORT_DIR_PATH_1);
     verifyComponentByRef(FILE_1_REF, REPORT_PROJECT_KEY + ":" + REPORT_FILE_PATH_1, REPORT_PROJECT_KEY + ":" + REPORT_FILE_PATH_1, REPORT_FILE_NAME_1, null);
   }
@@ -379,17 +245,13 @@ public class BuildComponentTreeStepTest {
       .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,
-      issueRelocationToRoot, reportModulesPath);
-    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));
+    BuildComponentTreeStep underTest = new BuildComponentTreeStep(dbClient, reportReader, treeRootHolder, analysisMetadataHolder, reportModulesPath);
+    reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY, FILE_1_REF));
     reportReader.putComponent(componentWithPath(FILE_1_REF, FILE, REPORT_FILE_PATH_1));
 
     underTest.execute(new TestComputationStepContext());
 
     verifyComponentByRef(ROOT_REF, REPORT_PROJECT_KEY + ":origin/feature", analysisMetadataHolder.getProject().getName(), null);
-    verifyComponentMissingByRef(MODULE_REF);
     verifyComponentByKey(REPORT_PROJECT_KEY + ":origin/feature:" + REPORT_DIR_PATH_1, REPORT_DIR_PATH_1);
     verifyComponentByRef(FILE_1_REF, REPORT_PROJECT_KEY + ":origin/feature:" + REPORT_FILE_PATH_1, REPORT_FILE_NAME_1, null);
   }
@@ -397,17 +259,13 @@ public class BuildComponentTreeStepTest {
   @Test
   public void compute_keys_and_uuids_on_project_having_module_and_directory() {
     setAnalysisMetadataHolder();
-    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(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY, FILE_1_REF, FILE_2_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());
 
     verifyComponentByRef(ROOT_REF, REPORT_PROJECT_KEY, analysisMetadataHolder.getProject().getName());
-    verifyComponentMissingByRef(MODULE_REF);
     verifyComponentByKey(REPORT_PROJECT_KEY + ":" + REPORT_DIR_PATH_1, "dir1");
     verifyComponentByRef(FILE_1_REF, REPORT_PROJECT_KEY + ":" + REPORT_FILE_PATH_1, REPORT_FILE_NAME_1);
     verifyComponentByKey(REPORT_PROJECT_KEY + ":" + REPORT_DIR_PATH_2, "dir2");
@@ -417,19 +275,12 @@ public class BuildComponentTreeStepTest {
   @Test
   public void compute_keys_and_uuids_on_multi_modules() {
     setAnalysisMetadataHolder();
-    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(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY, FILE_1_REF));
     reportReader.putComponent(componentWithPath(FILE_1_REF, FILE, REPORT_FILE_PATH_1));
 
     underTest.execute(new TestComputationStepContext());
 
     verifyComponentByRef(ROOT_REF, REPORT_PROJECT_KEY, analysisMetadataHolder.getProject().getName());
-    verifyComponentMissingByRef(MODULE_REF);
-    verifyComponentMissingByKey(REPORT_MODULE_KEY);
-    verifyComponentMissingByRef(100);
-    verifyComponentMissingByKey("SUB_MODULE_KEY");
     verifyComponentByKey(REPORT_PROJECT_KEY + ":" + REPORT_DIR_PATH_1, REPORT_DIR_PATH_1);
     verifyComponentByRef(FILE_1_REF, REPORT_PROJECT_KEY + ":" + REPORT_FILE_PATH_1, REPORT_FILE_NAME_1);
   }
@@ -603,7 +454,8 @@ public class BuildComponentTreeStepTest {
 
   @Test
   @UseDataProvider("twoParametersNullNonNullCombinations")
-  public void set_projectVersion_to_projectVersion_when_projectVersion_is_set_on_later_analysis(@Nullable String codePeriodVersion, @Nullable String previousAnalysisCodePeriodVersion) {
+  public void set_projectVersion_to_projectVersion_when_projectVersion_is_set_on_later_analysis(@Nullable String codePeriodVersion,
+    @Nullable String previousAnalysisCodePeriodVersion) {
     String projectVersion = randomAlphabetic(7);
     setAnalysisMetadataHolder();
     reportReader.setMetadata(createReportMetadata(projectVersion, codePeriodVersion));
@@ -684,16 +536,6 @@ public class BuildComponentTreeStepTest {
     }
   }
 
-  private void verifyComponentMissingByRef(int ref) {
-    Map<Integer, Component> componentsByRef = indexAllComponentsInTreeByRef(treeRootHolder.getRoot());
-    assertThat(componentsByRef.get(ref)).isNull();
-  }
-
-  private void verifyComponentMissingByKey(String key) {
-    Map<String, Component> componentsByKey = indexAllComponentsInTreeByKey(treeRootHolder.getRoot());
-    assertThat(componentsByKey.get(key)).isNull();
-  }
-
   private static ScannerReport.Component component(int componentRef, ComponentType componentType, String key, int... children) {
     return component(componentRef, componentType, key, null, children);
   }