Search in sources :

Example 16 with Component

use of org.sonar.server.computation.task.projectanalysis.component.Component in project sonarqube by SonarSource.

the class DuplicationRepositoryRule method addDuplication.

public DuplicationRepositoryRule addDuplication(int fileRef, TextBlock original, String otherFileKey, TextBlock duplicate) {
    ensureComponentProviderInitialized();
    Component component = componentProvider.getByRef(fileRef);
    checkArgument(!componentRefsWithCrossProjectDuplications.containsEntry(component, original), "CrossProject duplications for file %s and original %s already set", fileRef);
    componentRefsWithCrossProjectDuplications.put(component, original);
    delegate.add(componentProvider.getByRef(fileRef), new Duplication(original, Arrays.<Duplicate>asList(new CrossProjectDuplicate(otherFileKey, duplicate))));
    return this;
}
Also used : Component(org.sonar.server.computation.task.projectanalysis.component.Component)

Example 17 with Component

use of org.sonar.server.computation.task.projectanalysis.component.Component in project sonarqube by SonarSource.

the class ComponentIssuesRepositoryRule method setIssues.

public void setIssues(int componentRef, List<DefaultIssue> issues) {
    this.issues = requireNonNull(issues, "issues cannot be null");
    Component component = treeRootHolder.getComponentByRef(componentRef);
    checkArgument(component != null, String.format("Component '%s' does not exists in the report ", componentRef));
    this.component = component;
}
Also used : Component(org.sonar.server.computation.task.projectanalysis.component.Component)

Example 18 with Component

use of org.sonar.server.computation.task.projectanalysis.component.Component in project sonarqube by SonarSource.

the class FillComponentIssuesVisitorRule method setIssues.

public void setIssues(int componentRef, DefaultIssue... issues) {
    Component component = treeRootHolder.getComponentByRef(componentRef);
    checkArgument(component != null, String.format("Component '%s' does not exists in the report ", componentRef));
    this.issues.get(component).clear();
    this.issues.putAll(component, asList(issues));
}
Also used : Component(org.sonar.server.computation.task.projectanalysis.component.Component)

Example 19 with Component

use of org.sonar.server.computation.task.projectanalysis.component.Component in project sonarqube by SonarSource.

the class LastCommitVisitorTest method aggregate_date_of_last_commit_to_directories_and_project.

@Test
public void aggregate_date_of_last_commit_to_directories_and_project() {
    final long FILE_1_DATE = 1_100_000_000_000L;
    // FILE_2 is the most recent file in DIR_1
    final long FILE_2_DATE = 1_200_000_000_000L;
    // FILE_3 is the most recent file in the project
    final long FILE_3_DATE = 1_300_000_000_000L;
    // simulate the output of visitFile()
    LastCommitVisitor visitor = new LastCommitVisitor(metricRepository, measureRepository, scmInfoRepository) {

        @Override
        public void visitFile(Component file, Path<LastCommit> path) {
            long fileDate;
            switch(file.getReportAttributes().getRef()) {
                case FILE_1_REF:
                    fileDate = FILE_1_DATE;
                    break;
                case FILE_2_REF:
                    fileDate = FILE_2_DATE;
                    break;
                case FILE_3_REF:
                    fileDate = FILE_3_DATE;
                    break;
                default:
                    throw new IllegalArgumentException();
            }
            path.parent().addDate(fileDate);
        }
    };
    // project with 1 module, 2 directories and 3 files
    ReportComponent project = ReportComponent.builder(PROJECT, PROJECT_REF).addChildren(ReportComponent.builder(MODULE, MODULE_REF).addChildren(ReportComponent.builder(DIRECTORY, DIR_1_REF).addChildren(createFileComponent(FILE_1_REF), createFileComponent(FILE_2_REF)).build(), ReportComponent.builder(DIRECTORY, DIR_2_REF).addChildren(createFileComponent(FILE_3_REF)).build()).build()).build();
    treeRootHolder.setRoot(project);
    VisitorsCrawler underTest = new VisitorsCrawler(Lists.<ComponentVisitor>newArrayList(visitor));
    underTest.visit(project);
    assertDate(DIR_1_REF, FILE_2_DATE);
    assertDate(DIR_2_REF, FILE_3_DATE);
    // module = most recent commit date of directories
    assertDate(MODULE_REF, FILE_3_DATE);
    // project
    assertDate(PROJECT_REF, FILE_3_DATE);
}
Also used : VisitorsCrawler(org.sonar.server.computation.task.projectanalysis.component.VisitorsCrawler) ReportComponent(org.sonar.server.computation.task.projectanalysis.component.ReportComponent) ViewsComponent(org.sonar.server.computation.task.projectanalysis.component.ViewsComponent) Component(org.sonar.server.computation.task.projectanalysis.component.Component) ReportComponent(org.sonar.server.computation.task.projectanalysis.component.ReportComponent) Test(org.junit.Test)

Example 20 with Component

use of org.sonar.server.computation.task.projectanalysis.component.Component in project sonarqube by SonarSource.

the class IndexAnalysisStepTest method call_indexByProjectUuid_of_indexer_for_view.

@Test
public void call_indexByProjectUuid_of_indexer_for_view() {
    Component view = ViewsComponent.builder(VIEW, PROJECT_KEY).setUuid(PROJECT_UUID).build();
    treeRootHolder.setRoot(view);
    underTest.execute();
    verify(componentIndexer).indexProject(PROJECT_UUID, ProjectIndexer.Cause.NEW_ANALYSIS);
}
Also used : ViewsComponent(org.sonar.server.computation.task.projectanalysis.component.ViewsComponent) Component(org.sonar.server.computation.task.projectanalysis.component.Component) ReportComponent(org.sonar.server.computation.task.projectanalysis.component.ReportComponent) Test(org.junit.Test)

Aggregations

Component (org.sonar.server.computation.task.projectanalysis.component.Component)55 Test (org.junit.Test)33 ReportComponent (org.sonar.server.computation.task.projectanalysis.component.ReportComponent)24 ViewsComponent (org.sonar.server.computation.task.projectanalysis.component.ViewsComponent)15 ComponentDto (org.sonar.db.component.ComponentDto)12 SnapshotDto (org.sonar.db.component.SnapshotDto)10 DbSession (org.sonar.db.DbSession)6 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)5 OrganizationDto (org.sonar.db.organization.OrganizationDto)5 DepthTraversalTypeAwareCrawler (org.sonar.server.computation.task.projectanalysis.component.DepthTraversalTypeAwareCrawler)4 Period (org.sonar.server.computation.task.projectanalysis.period.Period)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 FileAttributes (org.sonar.server.computation.task.projectanalysis.component.FileAttributes)2 TypeAwareVisitorAdapter (org.sonar.server.computation.task.projectanalysis.component.TypeAwareVisitorAdapter)2 InProjectDuplicate (org.sonar.server.computation.task.projectanalysis.duplication.InProjectDuplicate)2 InnerDuplicate (org.sonar.server.computation.task.projectanalysis.duplication.InnerDuplicate)2 File (org.sonar.server.computation.task.projectanalysis.filemove.FileSimilarity.File)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1