diff options
author | Godin <mandrikov@gmail.com> | 2010-12-06 17:29:41 +0000 |
---|---|---|
committer | Godin <mandrikov@gmail.com> | 2010-12-06 17:29:41 +0000 |
commit | 0dccd3182e1c7c0220659e48936eac8edcc40826 (patch) | |
tree | d0a6ec7c7a60867a99717425640f97c752687100 /plugins | |
parent | 956f7537a0dd2365e60c1036bd95d53ff34861af (diff) | |
download | sonarqube-0dccd3182e1c7c0220659e48936eac8edcc40826.tar.gz sonarqube-0dccd3182e1c7c0220659e48936eac8edcc40826.zip |
SONAR-2011: Instead of deprecated project.getPom() use injected MavenProject in ProjectLinksSensor
Diffstat (limited to 'plugins')
2 files changed, 12 insertions, 8 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ProjectLinksSensor.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ProjectLinksSensor.java index 32e1503a991..e8170cbe4c6 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ProjectLinksSensor.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ProjectLinksSensor.java @@ -37,12 +37,17 @@ public class ProjectLinksSensor implements Sensor { public static final String KEY_SCM = "scm"; public static final String KEY_SCM_DEVELOPER_CONNECTION = "scm_dev"; + private MavenProject pom; + + public ProjectLinksSensor(MavenProject pom) { + this.pom = pom; + } + public boolean shouldExecuteOnProject(Project project) { return true; } public void analyse(Project project, SensorContext context) { - MavenProject pom = project.getPom(); updateLink(context, KEY_HOME, "Home", pom.getUrl()); Scm scm = pom.getScm(); @@ -52,7 +57,6 @@ public class ProjectLinksSensor implements Sensor { updateLink(context, KEY_SCM, "Sources", scm.getUrl()); updateLink(context, KEY_SCM_DEVELOPER_CONNECTION, "Developer connection", scm.getDeveloperConnection()); - CiManagement ci = pom.getCiManagement(); if (ci == null) { ci = new CiManagement(); diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ProjectLinksSensorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ProjectLinksSensorTest.java index 69b90dc466e..38f44eb001d 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ProjectLinksSensorTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ProjectLinksSensorTest.java @@ -24,13 +24,15 @@ import org.apache.maven.project.MavenProject; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; import org.junit.Test; -import static org.mockito.Matchers.argThat; -import static org.mockito.Mockito.*; import org.sonar.api.batch.SensorContext; import org.sonar.api.resources.Project; import org.sonar.api.resources.ProjectLink; import org.sonar.api.test.MavenTestUtils; +import static org.mockito.Matchers.argThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + public class ProjectLinksSensorTest { @Test @@ -38,9 +40,8 @@ public class ProjectLinksSensorTest { SensorContext context = mock(SensorContext.class); MavenProject pom = MavenTestUtils.loadPom("/org/sonar/plugins/core/sensors/ProjectLinksSensorTest/shouldSaveLinks.xml"); Project project = mock(Project.class); - when(project.getPom()).thenReturn(pom); - new ProjectLinksSensor().analyse(project, context); + new ProjectLinksSensor(pom).analyse(project, context); verify(context).saveLink(argThat(new MatchLink(ProjectLinksSensor.KEY_HOME, "Home", "http://sonar.codehaus.org"))); verify(context).saveLink(argThat(new MatchLink(ProjectLinksSensor.KEY_ISSUE_TRACKER, "Issues", "http://jira.codehaus.org/browse/SONAR"))); @@ -54,9 +55,8 @@ public class ProjectLinksSensorTest { SensorContext context = mock(SensorContext.class); MavenProject pom = MavenTestUtils.loadPom("/org/sonar/plugins/core/sensors/ProjectLinksSensorTest/shouldDeleteMissingLinks.xml"); Project project = mock(Project.class); - when(project.getPom()).thenReturn(pom); - new ProjectLinksSensor().analyse(project, context); + new ProjectLinksSensor(pom).analyse(project, context); verify(context).deleteLink(ProjectLinksSensor.KEY_HOME); verify(context).deleteLink(ProjectLinksSensor.KEY_ISSUE_TRACKER); |