Search in sources :

Example 31 with ProjectDefinition

use of org.sonar.api.batch.bootstrap.ProjectDefinition in project sonarqube by SonarSource.

the class ModuleSettings method getTopDownParentProjects.

/**
   * From root to given project
   */
static List<ProjectDefinition> getTopDownParentProjects(ProjectDefinition project) {
    List<ProjectDefinition> result = new ArrayList<>();
    ProjectDefinition p = project;
    while (p != null) {
        result.add(0, p);
        p = p.getParent();
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition)

Example 32 with ProjectDefinition

use of org.sonar.api.batch.bootstrap.ProjectDefinition in project sonarqube by SonarSource.

the class AnalysisTempFolderProviderTest method setUp.

@Before
public void setUp() {
    tempFolderProvider = new AnalysisTempFolderProvider();
    projectReactor = mock(ProjectReactor.class);
    ProjectDefinition projectDefinition = mock(ProjectDefinition.class);
    when(projectReactor.getRoot()).thenReturn(projectDefinition);
    when(projectDefinition.getWorkDir()).thenReturn(temp.getRoot());
}
Also used : AnalysisTempFolderProvider(org.sonar.scanner.analysis.AnalysisTempFolderProvider) ProjectReactor(org.sonar.api.batch.bootstrap.ProjectReactor) ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition) Before(org.junit.Before)

Example 33 with ProjectDefinition

use of org.sonar.api.batch.bootstrap.ProjectDefinition in project sonarqube by SonarSource.

the class ComponentsPublisherTest method add_components_to_report.

@Test
public void add_components_to_report() throws Exception {
    ProjectAnalysisInfo projectAnalysisInfo = mock(ProjectAnalysisInfo.class);
    when(projectAnalysisInfo.analysisDate()).thenReturn(DateUtils.parseDate("2012-12-12"));
    ProjectDefinition rootDef = ProjectDefinition.create().setKey("foo").setProperty(CoreProperties.PROJECT_VERSION_PROPERTY, "1.0").setName("Root project").setDescription("Root description");
    DefaultInputModule root = new DefaultInputModule(rootDef, 1);
    ProjectDefinition module1Def = ProjectDefinition.create().setKey("module1").setName("Module1").setDescription("Module description");
    rootDef.addSubProject(module1Def);
    DefaultInputModule module1 = new DefaultInputModule(module1Def, 2);
    moduleHierarchy = mock(InputModuleHierarchy.class);
    when(moduleHierarchy.root()).thenReturn(root);
    when(moduleHierarchy.children(root)).thenReturn(Collections.singleton(module1));
    tree.index(module1, root);
    DefaultInputDir dir = new DefaultInputDir("module1", "src", 3);
    tree.index(dir, module1);
    DefaultInputFile file = new TestInputFileBuilder("module1", "src/Foo.java", 4).setLines(2).build();
    tree.index(file, dir);
    DefaultInputFile file2 = new TestInputFileBuilder("module1", "src/Foo2.java", 5).setPublish(false).setLines(2).build();
    tree.index(file2, dir);
    DefaultInputFile fileWithoutLang = new TestInputFileBuilder("module1", "src/make", 6).setLines(10).build();
    tree.index(fileWithoutLang, dir);
    DefaultInputFile testFile = new TestInputFileBuilder("module1", "test/FooTest.java", 7).setType(Type.TEST).setLines(4).build();
    tree.index(testFile, dir);
    ComponentsPublisher publisher = new ComponentsPublisher(moduleHierarchy, tree);
    publisher.publish(writer);
    assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 1)).isTrue();
    assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 2)).isTrue();
    assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 3)).isTrue();
    assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 4)).isTrue();
    assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 6)).isTrue();
    assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 7)).isTrue();
    // not marked for publishing
    assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 5)).isFalse();
    // no such reference
    assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 8)).isFalse();
    ScannerReportReader reader = new ScannerReportReader(outputDir);
    Component rootProtobuf = reader.readComponent(1);
    assertThat(rootProtobuf.getKey()).isEqualTo("foo");
    assertThat(rootProtobuf.getDescription()).isEqualTo("Root description");
    assertThat(rootProtobuf.getVersion()).isEqualTo("1.0");
    assertThat(rootProtobuf.getLinkCount()).isEqualTo(0);
    Component module1Protobuf = reader.readComponent(2);
    assertThat(module1Protobuf.getKey()).isEqualTo("module1");
    assertThat(module1Protobuf.getDescription()).isEqualTo("Module description");
    assertThat(module1Protobuf.getVersion()).isEqualTo("1.0");
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) ScannerReportReader(org.sonar.scanner.protocol.output.ScannerReportReader) InputModuleHierarchy(org.sonar.api.batch.fs.internal.InputModuleHierarchy) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) ProjectAnalysisInfo(org.sonar.scanner.ProjectAnalysisInfo) ComponentsPublisher(org.sonar.scanner.report.ComponentsPublisher) Component(org.sonar.scanner.protocol.output.ScannerReport.Component) DefaultInputDir(org.sonar.api.batch.fs.internal.DefaultInputDir) ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition) Test(org.junit.Test)

Example 34 with ProjectDefinition

use of org.sonar.api.batch.bootstrap.ProjectDefinition in project sonarqube by SonarSource.

the class WorkDirectoryCleanerTest method setUp.

@Before
public void setUp() throws IOException {
    // create files to clean
    temp.newFile();
    File newFolder = temp.newFolder();
    File fileInFolder = new File(newFolder, "test");
    fileInFolder.createNewFile();
    File lock = new File(temp.getRoot(), DirectoryLock.LOCK_FILE_NAME);
    lock.createNewFile();
    // mock project
    ProjectReactor projectReactor = mock(ProjectReactor.class);
    ProjectDefinition projectDefinition = mock(ProjectDefinition.class);
    when(projectReactor.getRoot()).thenReturn(projectDefinition);
    when(projectDefinition.getWorkDir()).thenReturn(temp.getRoot());
    assertThat(temp.getRoot().list().length).isGreaterThan(1);
    cleaner = new WorkDirectoryCleaner(projectReactor);
}
Also used : File(java.io.File) WorkDirectoryCleaner(org.sonar.scanner.scan.WorkDirectoryCleaner) ProjectReactor(org.sonar.api.batch.bootstrap.ProjectReactor) ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition) Before(org.junit.Before)

Example 35 with ProjectDefinition

use of org.sonar.api.batch.bootstrap.ProjectDefinition in project sonarqube by SonarSource.

the class ModuleIndexerTest method testIndex.

@Test
public void testIndex() {
    ProjectDefinition root = ProjectDefinition.create().setKey("root");
    ProjectDefinition mod1 = ProjectDefinition.create().setKey("mod1");
    ProjectDefinition mod2 = ProjectDefinition.create().setKey("mod2");
    ProjectDefinition mod3 = ProjectDefinition.create().setKey("mod3");
    ProjectDefinition mod4 = ProjectDefinition.create().setKey("mod4");
    root.addSubProject(mod1);
    mod1.addSubProject(mod2);
    root.addSubProject(mod3);
    root.addSubProject(mod4);
    when(reactor.getRoot()).thenReturn(root);
    indexer.start();
    InputModule rootModule = moduleHierarchy.root();
    assertThat(rootModule).isNotNull();
    assertThat(moduleHierarchy.children(rootModule)).hasSize(3);
    assertThat(tree.getChildren(rootModule)).hasSize(3);
}
Also used : InputModule(org.sonar.api.batch.fs.InputModule) ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition) Test(org.junit.Test)

Aggregations

ProjectDefinition (org.sonar.api.batch.bootstrap.ProjectDefinition)52 Test (org.junit.Test)29 File (java.io.File)10 DefaultInputModule (org.sonar.api.batch.fs.internal.DefaultInputModule)8 ProjectReactor (org.sonar.api.batch.bootstrap.ProjectReactor)5 DefaultInputDir (org.sonar.api.batch.fs.internal.DefaultInputDir)4 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)4 InputModuleHierarchy (org.sonar.api.batch.fs.internal.InputModuleHierarchy)4 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)4 ProjectAnalysisInfo (org.sonar.scanner.ProjectAnalysisInfo)4 GlobalSettings (org.sonar.scanner.bootstrap.GlobalSettings)4 AnalysisContextReportPublisher (org.sonar.scanner.report.AnalysisContextReportPublisher)4 ComponentsPublisher (org.sonar.scanner.report.ComponentsPublisher)4 ProjectRepositories (org.sonar.scanner.repository.ProjectRepositories)4 HashMap (java.util.HashMap)3 Before (org.junit.Before)3 Component (org.sonar.scanner.protocol.output.ScannerReport.Component)3 ScannerReportReader (org.sonar.scanner.protocol.output.ScannerReportReader)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2