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;
private final Branch branch;
@Nullable
private final ProjectAttributes projectAttributes;
- private final IssueRelocationToRoot issueRelocationToRoot;
private ScannerReport.Component rootComponent;
private String scmBasePath;
Function<Integer, ScannerReport.Component> scannerComponentSupplier,
Project project,
Branch branch,
- ProjectAttributes projectAttributes,
- IssueRelocationToRoot issueRelocationToRoot) {
+ ProjectAttributes projectAttributes) {
this.keyGenerator = keyGenerator;
this.publicKeyGenerator = publicKeyGenerator;
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) {
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()));
}
*/
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;
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;
- }
-
}
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;
ComponentsWithUnprocessedIssues.class,
ComponentIssuesRepositoryImpl.class,
IssueFilter.class,
- IssueRelocationToRoot.class,
// common rules
CommonRuleEngineImpl.class,
+++ /dev/null
-/*
- * 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();
- }
-}
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;
this.issueFilter = issueFilter;
this.ruleRepository = ruleRepository;
this.activeRulesHolder = activeRulesHolder;
- this.issueRelocationToRoot = issueRelocationToRoot;
}
public Input<DefaultIssue> create(Component component) {
}
}
- if (component.getType() == Component.Type.PROJECT) {
- // TODO apply filters?
- issueRelocationToRoot.getMovedIssues().stream()
- .map(i -> toIssue(getLineHashSequence(), i))
- .forEach(result::add);
- }
-
return result;
}
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;
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;
}
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);
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;
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 {
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();
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())
.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));
.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)
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");
.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));
.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("")
.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);
.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));
.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
.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));
.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")
.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")
@Override
protected void before() {
+ clear();
+ }
+
+ public void clear() {
components.clear();
}
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) {
*/
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;
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;
- }
}
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;
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);
+++ /dev/null
-/*
- * 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);
- }
-
-}
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() {
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;
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)
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";
@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() {
@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();
@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());
.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());
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);
.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(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}};
.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());
.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);
}
.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);
}
@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");
@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);
}
@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));
}
}
- 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);
}