Skip to content

Commit

Permalink
SONAR-6273 Really fix NPE when working on projects with branches
Browse files Browse the repository at this point in the history
  • Loading branch information
henryju committed Mar 12, 2015
1 parent 81694b1 commit d25ad7c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Expand Up @@ -92,7 +92,7 @@ private void recursiveWriteComponent(BatchResource batchResource, BatchReportWri
builder.addChildRefs(child.batchId()); builder.addChildRefs(child.batchId());
} }
if (ResourceUtils.isProject(r)) { if (ResourceUtils.isProject(r)) {
ProjectDefinition def = reactor.getProject(r.getKey()); ProjectDefinition def = getProjectDefinition(reactor, r.getKey());
ComponentLink.Builder linkBuilder = ComponentLink.newBuilder(); ComponentLink.Builder linkBuilder = ComponentLink.newBuilder();


writeProjectLink(builder, def, linkBuilder, CoreProperties.LINKS_HOME_PAGE, ComponentLinkType.HOME); writeProjectLink(builder, def, linkBuilder, CoreProperties.LINKS_HOME_PAGE, ComponentLinkType.HOME);
Expand All @@ -108,6 +108,15 @@ private void recursiveWriteComponent(BatchResource batchResource, BatchReportWri
} }
} }


private ProjectDefinition getProjectDefinition(ProjectReactor reactor, String keyWithBranch) {
for (ProjectDefinition p : reactor.getProjects()) {
if (keyWithBranch.equals(p.getKeyWithBranch())) {
return p;
}
}
return null;
}

private void writeProjectLink(BatchReport.Component.Builder componentBuilder, ProjectDefinition def, ComponentLink.Builder linkBuilder, String linkProp, private void writeProjectLink(BatchReport.Component.Builder componentBuilder, ProjectDefinition def, ComponentLink.Builder linkBuilder, String linkProp,
ComponentLinkType linkType) { ComponentLinkType linkType) {
String link = def.properties().get(linkProp); String link = def.properties().get(linkProp);
Expand Down
Expand Up @@ -113,15 +113,16 @@ public void add_components_to_report() throws Exception {
} }


@Test @Test
public void add_components_with_links() throws Exception { public void add_components_with_links_and_branch() throws Exception {
// inputs // inputs
Project root = new Project("foo").setName("Root project") Project root = new Project("foo:my_branch").setName("Root project")
.setAnalysisDate(DateUtils.parseDate(("2012-12-12"))); .setAnalysisDate(DateUtils.parseDate(("2012-12-12")));
root.setId(1).setUuid("PROJECT_UUID"); root.setId(1).setUuid("PROJECT_UUID");
resourceCache.add(root, null).setSnapshot(new Snapshot().setId(11)); resourceCache.add(root, null).setSnapshot(new Snapshot().setId(11));
reactor.getRoot().properties().put(CoreProperties.LINKS_HOME_PAGE, "http://home"); reactor.getRoot().properties().put(CoreProperties.LINKS_HOME_PAGE, "http://home");
reactor.getRoot().properties().put(CoreProperties.PROJECT_BRANCH_PROPERTY, "my_branch");


Project module1 = new Project("module1").setName("Module1"); Project module1 = new Project("module1:my_branch").setName("Module1");
module1.setParent(root); module1.setParent(root);
module1.setId(2).setUuid("MODULE_UUID"); module1.setId(2).setUuid("MODULE_UUID");
resourceCache.add(module1, root).setSnapshot(new Snapshot().setId(12)); resourceCache.add(module1, root).setSnapshot(new Snapshot().setId(12));
Expand Down

0 comments on commit d25ad7c

Please sign in to comment.