use of org.sonar.api.batch.fs.internal.DefaultInputModule in project sonarqube by SonarSource.
the class InputComponentStoreTest method should_add_input_file.
@Test
public void should_add_input_file() throws Exception {
String rootModuleKey = "struts";
String subModuleKey = "struts-core";
File rootBaseDir = temp.newFolder();
ProjectDefinition moduleDef = ProjectDefinition.create().setKey(subModuleKey).setBaseDir(rootBaseDir).setWorkDir(temp.newFolder());
ProjectDefinition rootDef = ProjectDefinition.create().setKey(rootModuleKey).setBaseDir(rootBaseDir).setWorkDir(temp.newFolder()).addSubProject(moduleDef);
DefaultInputProject rootProject = TestInputFileBuilder.newDefaultInputProject(rootDef);
DefaultInputModule subModule = TestInputFileBuilder.newDefaultInputModule(moduleDef);
InputComponentStore store = new InputComponentStore(mock(BranchConfiguration.class), sonarRuntime);
store.put(subModule);
DefaultInputFile fooFile = new TestInputFileBuilder(rootModuleKey, "src/main/java/Foo.java").setModuleBaseDir(rootBaseDir.toPath()).setPublish(true).build();
store.put(rootProject.key(), fooFile);
store.put(subModuleKey, new TestInputFileBuilder(rootModuleKey, "src/main/java/Bar.java").setLanguage("bla").setPublish(false).setType(Type.MAIN).setStatus(Status.ADDED).setLines(2).setCharset(StandardCharsets.UTF_8).setModuleBaseDir(temp.newFolder().toPath()).build());
DefaultInputFile loadedFile = (DefaultInputFile) store.getFile(subModuleKey, "src/main/java/Bar.java");
assertThat(loadedFile.relativePath()).isEqualTo("src/main/java/Bar.java");
assertThat(loadedFile.charset()).isEqualTo(StandardCharsets.UTF_8);
assertThat(store.filesByModule(rootModuleKey)).hasSize(1);
assertThat(store.filesByModule(subModuleKey)).hasSize(1);
assertThat(store.inputFiles()).hasSize(2);
for (InputPath inputPath : store.inputFiles()) {
assertThat(inputPath.relativePath()).startsWith("src/main/java/");
}
List<InputFile> toPublish = new LinkedList<>();
store.allFilesToPublish().forEach(toPublish::add);
assertThat(toPublish).containsExactly(fooFile);
}
use of org.sonar.api.batch.fs.internal.DefaultInputModule in project sonarqube by SonarSource.
the class AnalysisContextReportPublisherTest method dumpServerSideProjectProps.
@Test
public void dumpServerSideProjectProps() throws Exception {
logTester.setLevel(LoggerLevel.DEBUG);
ScannerReportWriter writer = new ScannerReportWriter(temp.newFolder());
DefaultInputModule rootModule = new DefaultInputModule(ProjectDefinition.create().setBaseDir(temp.newFolder()).setWorkDir(temp.newFolder()).setProperty("sonar.projectKey", "foo"));
when(store.allModules()).thenReturn(singletonList(rootModule));
when(hierarchy.root()).thenReturn(rootModule);
when(projectServerSettings.properties()).thenReturn(ImmutableMap.of(COM_FOO, "bar", SONAR_SKIP, "true"));
publisher.init(writer);
List<String> lines = FileUtils.readLines(writer.getFileStructure().analysisLog(), StandardCharsets.UTF_8);
assertThat(lines).containsExactly("SonarQube plugins:", "Global server settings:", "Project server settings:", " - com.foo=bar", " - sonar.skip=true", "Project scanner properties:", " - sonar.projectKey=foo");
}
use of org.sonar.api.batch.fs.internal.DefaultInputModule in project sonarqube by SonarSource.
the class AnalysisContextReportPublisherTest method shouldOnlyDumpPluginsByDefault.
@Test
public void shouldOnlyDumpPluginsByDefault() throws Exception {
when(pluginRepo.getPluginInfos()).thenReturn(singletonList(new PluginInfo("xoo").setName("Xoo").setVersion(Version.create("1.0"))));
ScannerReportWriter writer = new ScannerReportWriter(temp.newFolder());
DefaultInputModule rootModule = new DefaultInputModule(ProjectDefinition.create().setBaseDir(temp.newFolder()).setWorkDir(temp.newFolder()));
when(store.allModules()).thenReturn(singletonList(rootModule));
when(hierarchy.root()).thenReturn(rootModule);
publisher.init(writer);
assertThat(writer.getFileStructure().analysisLog()).exists();
assertThat(FileUtils.readFileToString(writer.getFileStructure().analysisLog(), StandardCharsets.UTF_8)).contains("Xoo 1.0 (xoo)");
verifyZeroInteractions(system2);
}
use of org.sonar.api.batch.fs.internal.DefaultInputModule in project sonarqube by SonarSource.
the class AnalysisContextReportPublisherTest method shouldShortenModuleProperties.
@Test
public void shouldShortenModuleProperties() throws Exception {
File baseDir = temp.newFolder();
ScannerReportWriter writer = new ScannerReportWriter(temp.newFolder());
DefaultInputModule rootModule = new DefaultInputModule(ProjectDefinition.create().setBaseDir(baseDir).setWorkDir(temp.newFolder()).setProperty("sonar.projectKey", "foo").setProperty("sonar.projectBaseDir", baseDir.toString()).setProperty("sonar.aVeryLongProp", StringUtils.repeat("abcde", 1000)));
when(store.allModules()).thenReturn(singletonList(rootModule));
when(hierarchy.root()).thenReturn(rootModule);
publisher.init(writer);
assertThat(writer.getFileStructure().analysisLog()).exists();
assertThat(FileUtils.readFileToString(writer.getFileStructure().analysisLog(), StandardCharsets.UTF_8)).containsSubsequence("sonar.aVeryLongProp=" + StringUtils.repeat("abcde", 199) + "ab...", "sonar.projectBaseDir=" + baseDir.toString(), "sonar.projectKey=foo");
}
use of org.sonar.api.batch.fs.internal.DefaultInputModule in project sonarqube by SonarSource.
the class AbstractDefaultIssue method rewriteLocation.
private DefaultIssueLocation rewriteLocation(DefaultIssueLocation location) {
InputComponent component = location.inputComponent();
Optional<Path> dirOrModulePath = Optional.empty();
if (component instanceof DefaultInputDir) {
DefaultInputDir dirComponent = (DefaultInputDir) component;
dirOrModulePath = Optional.of(project.getBaseDir().relativize(dirComponent.path()));
} else if (component instanceof DefaultInputModule && !Objects.equals(project.key(), component.key())) {
DefaultInputModule moduleComponent = (DefaultInputModule) component;
dirOrModulePath = Optional.of(project.getBaseDir().relativize(moduleComponent.getBaseDir()));
}
if (dirOrModulePath.isPresent()) {
String path = PathUtils.sanitize(dirOrModulePath.get().toString());
DefaultIssueLocation fixedLocation = new DefaultIssueLocation();
fixedLocation.on(project);
StringBuilder fullMessage = new StringBuilder();
if (path != null && !path.isEmpty()) {
fullMessage.append("[").append(path).append("] ");
}
fullMessage.append(location.message());
fixedLocation.message(fullMessage.toString());
return fixedLocation;
} else {
return location;
}
}
Aggregations