Search in sources :

Example 46 with DefaultInputModule

use of org.sonar.api.batch.fs.internal.DefaultInputModule in project sonarqube by SonarSource.

the class DefaultIssueTest method move_submodule_issue_to_project_root.

@Test
public void move_submodule_issue_to_project_root() {
    File subModuleDirectory = new File(project.getBaseDir().toString(), "bar");
    subModuleDirectory.mkdir();
    ProjectDefinition subModuleDefinition = ProjectDefinition.create().setKey("foo/bar").setBaseDir(subModuleDirectory).setWorkDir(subModuleDirectory);
    project.definition().addSubProject(subModuleDefinition);
    DefaultInputModule subModule = new DefaultInputModule(subModuleDefinition);
    SensorStorage storage = mock(SensorStorage.class);
    DefaultIssue issue = new DefaultIssue(project, storage).at(new DefaultIssueLocation().on(subModule).message("Wrong way!")).forRule(RuleKey.of("repo", "rule")).overrideSeverity(Severity.BLOCKER);
    assertThat(issue.primaryLocation().inputComponent()).isEqualTo(project);
    assertThat(issue.ruleKey()).isEqualTo(RuleKey.of("repo", "rule"));
    assertThat(issue.primaryLocation().textRange()).isNull();
    assertThat(issue.primaryLocation().message()).isEqualTo("[bar] Wrong way!");
    assertThat(issue.overriddenSeverity()).isEqualTo(Severity.BLOCKER);
    issue.save();
    verify(storage).store(issue);
}
Also used : DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition) SensorStorage(org.sonar.api.batch.sensor.internal.SensorStorage) Test(org.junit.Test)

Example 47 with DefaultInputModule

use of org.sonar.api.batch.fs.internal.DefaultInputModule in project sonarqube by SonarSource.

the class DefaultInputModuleTest method working_directory_should_be_hidden.

@Test
public void working_directory_should_be_hidden() throws IOException {
    ProjectDefinition def = ProjectDefinition.create();
    File workDir = temp.newFolder(".sonar");
    def.setWorkDir(workDir);
    File baseDir = temp.newFolder();
    def.setBaseDir(baseDir);
    DefaultInputModule module = new DefaultInputModule(def);
    assertThat(workDir.isHidden()).isTrue();
}
Also used : DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) File(java.io.File) ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition) Test(org.junit.Test)

Example 48 with DefaultInputModule

use of org.sonar.api.batch.fs.internal.DefaultInputModule in project sonarqube by SonarSource.

the class DefaultInputModuleHierarchyTest method testRelativePathToRoot.

@Test
public void testRelativePathToRoot() throws IOException {
    File rootBaseDir = temp.newFolder();
    File mod1BaseDir = new File(rootBaseDir, "mod1");
    File mod2BaseDir = new File(rootBaseDir, "mod2");
    FileUtils.forceMkdir(mod1BaseDir);
    FileUtils.forceMkdir(mod2BaseDir);
    DefaultInputModule root = new DefaultInputModule(ProjectDefinition.create().setKey("root").setBaseDir(rootBaseDir).setWorkDir(rootBaseDir));
    DefaultInputModule mod1 = new DefaultInputModule(ProjectDefinition.create().setKey("mod1").setBaseDir(mod1BaseDir).setWorkDir(temp.newFolder()));
    DefaultInputModule mod2 = new DefaultInputModule(ProjectDefinition.create().setKey("mod2").setBaseDir(mod2BaseDir).setWorkDir(temp.newFolder()));
    DefaultInputModule mod3 = new DefaultInputModule(ProjectDefinition.create().setKey("mod2").setBaseDir(temp.newFolder()).setWorkDir(temp.newFolder()));
    Map<DefaultInputModule, DefaultInputModule> parents = new HashMap<>();
    parents.put(mod1, root);
    parents.put(mod2, mod1);
    parents.put(mod3, mod1);
    moduleHierarchy = new DefaultInputModuleHierarchy(root, parents);
    assertThat(moduleHierarchy.relativePathToRoot(root)).isEmpty();
    assertThat(moduleHierarchy.relativePathToRoot(mod1)).isEqualTo("mod1");
    assertThat(moduleHierarchy.relativePathToRoot(mod2)).isEqualTo("mod2");
    assertThat(moduleHierarchy.relativePathToRoot(mod3)).isNull();
}
Also used : HashMap(java.util.HashMap) DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) File(java.io.File) Test(org.junit.Test)

Example 49 with DefaultInputModule

use of org.sonar.api.batch.fs.internal.DefaultInputModule in project sonarqube by SonarSource.

the class ModuleIndexerTest method testIndex.

@Test
public void testIndex() {
    ProjectDefinition rootDef = mock(ProjectDefinition.class);
    ProjectDefinition def = mock(ProjectDefinition.class);
    when(rootDef.getParent()).thenReturn(null);
    when(def.getParent()).thenReturn(rootDef);
    DefaultInputModule root = mock(DefaultInputModule.class);
    DefaultInputModule mod1 = mock(DefaultInputModule.class);
    DefaultInputModule mod2 = mock(DefaultInputModule.class);
    DefaultInputModule mod3 = mock(DefaultInputModule.class);
    when(root.key()).thenReturn("root");
    when(mod1.key()).thenReturn("mod1");
    when(mod2.key()).thenReturn("mod2");
    when(mod3.key()).thenReturn("mod3");
    when(root.definition()).thenReturn(rootDef);
    when(mod1.definition()).thenReturn(def);
    when(mod2.definition()).thenReturn(def);
    when(mod3.definition()).thenReturn(def);
    createIndexer();
    when(moduleHierarchy.root()).thenReturn(root);
    when(moduleHierarchy.children(root)).thenReturn(Arrays.asList(mod1, mod2, mod3));
    indexer.start();
    DefaultInputModule rootModule = moduleHierarchy.root();
    assertThat(rootModule).isNotNull();
    assertThat(moduleHierarchy.children(rootModule)).hasSize(3);
}
Also used : DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) ProjectDefinition(org.sonar.api.batch.bootstrap.ProjectDefinition) Test(org.junit.Test)

Example 50 with DefaultInputModule

use of org.sonar.api.batch.fs.internal.DefaultInputModule in project sonarqube by SonarSource.

the class WorkDirectoriesInitializerTest method execute_on_hierarchy_should_clean_submodules.

@Test
public void execute_on_hierarchy_should_clean_submodules() throws IOException {
    DefaultInputModule moduleA = mock(DefaultInputModule.class);
    DefaultInputModule moduleB = mock(DefaultInputModule.class);
    when(hierarchy.children(root)).thenReturn(Arrays.asList(moduleA));
    when(hierarchy.children(moduleA)).thenReturn(Arrays.asList(moduleB));
    File moduleAWorkdir = new File(rootWorkDir, "moduleA");
    File moduleBWorkdir = new File(moduleAWorkdir, "moduleB");
    when(moduleA.getWorkDir()).thenReturn(moduleAWorkdir.toPath());
    when(moduleB.getWorkDir()).thenReturn(moduleBWorkdir.toPath());
    moduleAWorkdir.mkdir();
    moduleBWorkdir.mkdir();
    new File(moduleAWorkdir, "fooA.txt").createNewFile();
    new File(moduleBWorkdir, "fooB.txt").createNewFile();
    initializer.execute(project);
    initializer.execute(hierarchy);
    assertThat(rootWorkDir).exists();
    assertThat(lock).exists();
    assertThat(rootWorkDir.list()).containsOnly(DirectoryLock.LOCK_FILE_NAME, "moduleA");
    assertThat(moduleAWorkdir).exists();
    assertThat(moduleBWorkdir).exists();
    assertThat(moduleAWorkdir.list()).containsOnly("moduleB");
    assertThat(moduleBWorkdir).isEmptyDirectory();
}
Also used : DefaultInputModule(org.sonar.api.batch.fs.internal.DefaultInputModule) File(java.io.File) Test(org.junit.Test)

Aggregations

DefaultInputModule (org.sonar.api.batch.fs.internal.DefaultInputModule)57 Test (org.junit.Test)34 ProjectDefinition (org.sonar.api.batch.bootstrap.ProjectDefinition)17 File (java.io.File)9 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)9 ScannerReportWriter (org.sonar.scanner.protocol.output.ScannerReportWriter)9 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)8 Path (java.nio.file.Path)6 InputFile (org.sonar.api.batch.fs.InputFile)6 DefaultInputDir (org.sonar.api.batch.fs.internal.DefaultInputDir)6 InputModuleHierarchy (org.sonar.api.batch.fs.internal.InputModuleHierarchy)5 Before (org.junit.Before)4 InputComponent (org.sonar.api.batch.fs.InputComponent)4 SensorStorage (org.sonar.api.batch.sensor.internal.SensorStorage)4 DefaultMeasure (org.sonar.api.batch.sensor.measure.internal.DefaultMeasure)4 ProjectAnalysisInfo (org.sonar.scanner.ProjectAnalysisInfo)4 CheckForNull (javax.annotation.CheckForNull)3 InputDir (org.sonar.api.batch.fs.InputDir)3 DefaultInputComponent (org.sonar.api.batch.fs.internal.DefaultInputComponent)3 InputModuleHierarchy (org.sonar.scanner.fs.InputModuleHierarchy)3