use of org.sonar.api.batch.fs.internal.DefaultInputModule in project sonarqube by SonarSource.
the class ComponentsPublisher method writeLinks.
private static void writeLinks(InputComponent c, ScannerReport.Component.Builder builder) {
if (c instanceof InputModule) {
DefaultInputModule inputModule = (DefaultInputModule) c;
ProjectDefinition def = inputModule.definition();
ComponentLink.Builder linkBuilder = ComponentLink.newBuilder();
writeProjectLink(builder, def, linkBuilder, CoreProperties.LINKS_HOME_PAGE, ComponentLinkType.HOME);
writeProjectLink(builder, def, linkBuilder, CoreProperties.LINKS_CI, ComponentLinkType.CI);
writeProjectLink(builder, def, linkBuilder, CoreProperties.LINKS_ISSUE_TRACKER, ComponentLinkType.ISSUE);
writeProjectLink(builder, def, linkBuilder, CoreProperties.LINKS_SOURCES, ComponentLinkType.SCM);
writeProjectLink(builder, def, linkBuilder, CoreProperties.LINKS_SOURCES_DEV, ComponentLinkType.SCM_DEV);
}
}
use of org.sonar.api.batch.fs.internal.DefaultInputModule in project sonarqube by SonarSource.
the class DeprecatedIssueAdapterForFilterTest method improve_coverage.
@Test
public void improve_coverage() {
DefaultInputModule module = new DefaultInputModule(PROJECT_KEY);
ProjectAnalysisInfo projectAnalysisInfo = mock(ProjectAnalysisInfo.class);
when(projectAnalysisInfo.analysisDate()).thenReturn(ANALYSIS_DATE);
DeprecatedIssueAdapterForFilter issue = new DeprecatedIssueAdapterForFilter(module, projectAnalysisInfo, org.sonar.scanner.protocol.output.ScannerReport.Issue.newBuilder().setRuleRepository("repo").setRuleKey("key").setSeverity(Severity.BLOCKER).setMsg("msg").build(), COMPONENT_KEY);
DeprecatedIssueAdapterForFilter issue2 = new DeprecatedIssueAdapterForFilter(module, projectAnalysisInfo, org.sonar.scanner.protocol.output.ScannerReport.Issue.newBuilder().setRuleRepository("repo").setRuleKey("key").setSeverity(Severity.BLOCKER).setMsg("msg").setTextRange(TextRange.newBuilder().setStartLine(1)).setGap(2.0).build(), COMPONENT_KEY);
try {
issue.key();
fail("Should be unsupported");
} catch (Exception e) {
assertThat(e).isExactlyInstanceOf(UnsupportedOperationException.class).hasMessage("Not available for issues filters");
}
assertThat(issue.componentKey()).isEqualTo(COMPONENT_KEY);
assertThat(issue.ruleKey()).isEqualTo(RuleKey.of("repo", "key"));
try {
issue.language();
fail("Should be unsupported");
} catch (Exception e) {
assertThat(e).isExactlyInstanceOf(UnsupportedOperationException.class).hasMessage("Not available for issues filters");
}
assertThat(issue.severity()).isEqualTo("BLOCKER");
assertThat(issue.message()).isEqualTo("msg");
assertThat(issue.line()).isNull();
assertThat(issue2.line()).isEqualTo(1);
assertThat(issue.effortToFix()).isNull();
assertThat(issue2.effortToFix()).isEqualTo(2.0);
assertThat(issue.status()).isEqualTo(Issue.STATUS_OPEN);
assertThat(issue.resolution()).isNull();
try {
issue.reporter();
fail("Should be unsupported");
} catch (Exception e) {
assertThat(e).isExactlyInstanceOf(UnsupportedOperationException.class).hasMessage("Not available for issues filters");
}
assertThat(issue.assignee()).isNull();
assertThat(issue.creationDate()).isEqualTo(ANALYSIS_DATE);
assertThat(issue.updateDate()).isNull();
assertThat(issue.closeDate()).isNull();
assertThat(issue.attribute(PROJECT_KEY)).isNull();
try {
issue.authorLogin();
fail("Should be unsupported");
} catch (Exception e) {
assertThat(e).isExactlyInstanceOf(UnsupportedOperationException.class).hasMessage("Not available for issues filters");
}
try {
issue.comments();
fail("Should be unsupported");
} catch (Exception e) {
assertThat(e).isExactlyInstanceOf(UnsupportedOperationException.class).hasMessage("Not available for issues filters");
}
try {
issue.isNew();
fail("Should be unsupported");
} catch (Exception e) {
assertThat(e).isExactlyInstanceOf(UnsupportedOperationException.class).hasMessage("Not available for issues filters");
}
try {
issue.debt();
fail("Should be unsupported");
} catch (Exception e) {
assertThat(e).isExactlyInstanceOf(UnsupportedOperationException.class).hasMessage("Not available for issues filters");
}
assertThat(issue.projectKey()).isEqualTo(PROJECT_KEY);
try {
issue.projectUuid();
fail("Should be unsupported");
} catch (Exception e) {
assertThat(e).isExactlyInstanceOf(UnsupportedOperationException.class).hasMessage("Not available for issues filters");
}
try {
issue.componentUuid();
fail("Should be unsupported");
} catch (Exception e) {
assertThat(e).isExactlyInstanceOf(UnsupportedOperationException.class).hasMessage("Not available for issues filters");
}
try {
issue.tags();
fail("Should be unsupported");
} catch (Exception e) {
assertThat(e).isExactlyInstanceOf(UnsupportedOperationException.class).hasMessage("Not available for issues filters");
}
}
use of org.sonar.api.batch.fs.internal.DefaultInputModule in project sonarqube by SonarSource.
the class ScannerExtensionDictionnaryTest method checkProject.
@Test
public void checkProject() {
BatchExtension ok = new CheckProjectOK();
BatchExtension ko = new CheckProjectKO();
ScannerExtensionDictionnary selector = newSelector(ok, ko);
List<BatchExtension> extensions = Lists.newArrayList(selector.select(BatchExtension.class, new DefaultInputModule("foo"), true, null));
assertThat(extensions).hasSize(1);
assertThat(extensions.get(0)).isInstanceOf(CheckProjectOK.class);
}
use of org.sonar.api.batch.fs.internal.DefaultInputModule in project sonarqube by SonarSource.
the class ComponentsPublisherTest method add_components_with_links_and_branch.
@Test
public void add_components_with_links_and_branch() 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").setProperty(CoreProperties.PROJECT_BRANCH_PROPERTY, "my_branch").setName("Root project").setProperty(CoreProperties.LINKS_HOME_PAGE, "http://home").setDescription("Root description");
DefaultInputModule root = new DefaultInputModule(rootDef, 1);
ProjectDefinition module1Def = ProjectDefinition.create().setKey("module1").setName("Module1").setProperty(CoreProperties.LINKS_CI, "http://ci").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);
ComponentsPublisher publisher = new ComponentsPublisher(moduleHierarchy, tree);
publisher.publish(writer);
ScannerReportReader reader = new ScannerReportReader(outputDir);
Component rootProtobuf = reader.readComponent(1);
assertThat(rootProtobuf.getVersion()).isEqualTo("1.0");
assertThat(rootProtobuf.getLinkCount()).isEqualTo(1);
assertThat(rootProtobuf.getLink(0).getType()).isEqualTo(ComponentLinkType.HOME);
assertThat(rootProtobuf.getLink(0).getHref()).isEqualTo("http://home");
Component module1Protobuf = reader.readComponent(2);
assertThat(module1Protobuf.getVersion()).isEqualTo("1.0");
assertThat(module1Protobuf.getLinkCount()).isEqualTo(1);
assertThat(module1Protobuf.getLink(0).getType()).isEqualTo(ComponentLinkType.CI);
assertThat(module1Protobuf.getLink(0).getHref()).isEqualTo("http://ci");
}
use of org.sonar.api.batch.fs.internal.DefaultInputModule in project sonarqube by SonarSource.
the class ComponentsPublisherTest method add_components_without_version_and_name.
@Test
public void add_components_without_version_and_name() throws IOException {
ProjectAnalysisInfo projectAnalysisInfo = mock(ProjectAnalysisInfo.class);
when(projectAnalysisInfo.analysisDate()).thenReturn(DateUtils.parseDate("2012-12-12"));
ProjectDefinition rootDef = ProjectDefinition.create().setKey("foo").setDescription("Root description");
DefaultInputModule root = new DefaultInputModule(rootDef, 1);
ProjectDefinition module1Def = ProjectDefinition.create().setKey("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 fileWithoutLang = new TestInputFileBuilder("module1", "src/make", 5).setLines(10).build();
tree.index(fileWithoutLang, dir);
DefaultInputFile testFile = new TestInputFileBuilder("module1", "test/FooTest.java", 6).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, 5)).isTrue();
assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 6)).isTrue();
// no such reference
assertThat(writer.hasComponentData(FileStructure.Domain.COMPONENT, 7)).isFalse();
ScannerReportReader reader = new ScannerReportReader(outputDir);
Component rootProtobuf = reader.readComponent(1);
assertThat(rootProtobuf.getKey()).isEqualTo("foo");
assertThat(rootProtobuf.getName()).isEqualTo("");
assertThat(rootProtobuf.getDescription()).isEqualTo("Root description");
assertThat(rootProtobuf.getVersion()).isEqualTo("");
assertThat(rootProtobuf.getLinkCount()).isEqualTo(0);
Component module1Protobuf = reader.readComponent(2);
assertThat(module1Protobuf.getKey()).isEqualTo("module1");
assertThat(module1Protobuf.getName()).isEqualTo("");
assertThat(module1Protobuf.getDescription()).isEqualTo("Module description");
assertThat(module1Protobuf.getVersion()).isEqualTo("");
}
Aggregations