<scope>provided</scope>
</dependency>
+ <!-- unit tests -->
+ <dependency>
+ <groupId>org.codehaus.sonar</groupId>
+ <artifactId>sonar-testing-harness</artifactId>
+ <scope>test</scope>
+ </dependency>
+
<!-- TODO http://jira.codehaus.org/browse/SONAR-2011
- We need following dependency, otherwise we will receive compilation error
+ We need following dependency, otherwise we will receive
+ java.lang.NoClassDefFoundError: org/apache/maven/project/MavenProject
+ during call mock(org.sonar.api.resources.Project.class)
-->
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
- <scope>provided</scope>
- </dependency>
-
- <dependency>
- <groupId>org.codehaus.sonar</groupId>
- <artifactId>sonar-testing-harness</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
*/
package org.sonar.plugins.findbugs;
-import java.io.File;
-import java.util.List;
-
import org.apache.commons.lang.StringUtils;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.Sensor;
import org.sonar.api.rules.Violation;
import org.sonar.api.utils.Logs;
+import java.io.File;
+import java.util.List;
+
public class FindbugsSensor implements Sensor {
private RulesProfile profile;
private RuleFinder ruleFinder;
public boolean shouldExecuteOnProject(Project project) {
return project.getFileSystem().hasJavaSourceFiles()
- && ( !profile.getActiveRulesByRepository(FindbugsConstants.REPOSITORY_KEY).isEmpty() || project.getReuseExistingRulesConfig())
- && project.getPom() != null && !StringUtils.equalsIgnoreCase(project.getPom().getPackaging(), "ear");
+ && (!profile.getActiveRulesByRepository(FindbugsConstants.REPOSITORY_KEY).isEmpty() || project.getReuseExistingRulesConfig())
+ && !StringUtils.equalsIgnoreCase(project.getPackaging(), "ear");
}
public void analyse(Project project, SensorContext context) {
package org.sonar.plugins.findbugs;
import org.apache.commons.configuration.Configuration;
-import org.apache.maven.project.MavenProject;
import org.junit.Test;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.SensorContext;
@Test
public void shouldExecuteWhenReuseExistingRulesConfig() throws Exception {
FindbugsSensor analyser = new FindbugsSensor(RulesProfile.create(), new FakeRuleFinder(), null);
- Project pom = createProject();
- when(pom.getReuseExistingRulesConfig()).thenReturn(true);
- assertTrue(analyser.shouldExecuteOnProject(pom));
+ Project project = createProject();
+ when(project.getReuseExistingRulesConfig()).thenReturn(true);
+ assertTrue(analyser.shouldExecuteOnProject(project));
}
@Test
public void shouldNotExecuteWhenNoRulesAreActive() throws Exception {
FindbugsSensor analyser = new FindbugsSensor(RulesProfile.create(), new FakeRuleFinder(), null);
- Project pom = createProject();
- assertFalse(analyser.shouldExecuteOnProject(pom));
+ Project project = createProject();
+ assertFalse(analyser.shouldExecuteOnProject(project));
}
@Test
public void shouldNotExecuteOnEar() {
Project project = createProject();
- when(project.getPom().getPackaging()).thenReturn("ear");
+ when(project.getPackaging()).thenReturn("ear");
FindbugsSensor analyser = new FindbugsSensor(createRulesProfileWithActiveRules(), new FakeRuleFinder(), null);
assertFalse(analyser.shouldExecuteOnProject(project));
}
DefaultProjectFileSystem fileSystem = mock(DefaultProjectFileSystem.class);
when(fileSystem.hasJavaSourceFiles()).thenReturn(Boolean.TRUE);
- MavenProject mavenProject = mock(MavenProject.class);
Project project = mock(Project.class);
when(project.getFileSystem()).thenReturn(fileSystem);
- when(project.getPom()).thenReturn(mavenProject);
return project;
}