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);
}
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();
}
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();
}
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);
}
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();
}
Aggregations