]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2341 Deprecate Project.getPackaging and don't use it in findbugs plugin
authorEvgeny Mandrikov <mandrikov@gmail.com>
Wed, 20 Apr 2011 21:47:18 +0000 (01:47 +0400)
committerEvgeny Mandrikov <mandrikov@gmail.com>
Wed, 20 Apr 2011 21:48:34 +0000 (01:48 +0400)
plugins/sonar-findbugs-plugin/src/main/java/org/sonar/plugins/findbugs/FindbugsSensor.java
plugins/sonar-findbugs-plugin/src/test/java/org/sonar/plugins/findbugs/FindbugsSensorTest.java
plugins/sonar-surefire-plugin/src/test/java/org/sonar/plugins/surefire/SurefireSensorTest.java
sonar-plugin-api/src/main/java/org/sonar/api/resources/Project.java

index 5e23416870dd4e97135af9c259e205c751df5ca3..7a5b86c08309ccd554e8448cb60b2a7314df1e39 100644 (file)
@@ -47,8 +47,7 @@ public class FindbugsSensor implements Sensor {
 
   public boolean shouldExecuteOnProject(Project project) {
     return project.getFileSystem().hasJavaSourceFiles()
-        && !profile.getActiveRulesByRepository(FindbugsConstants.REPOSITORY_KEY).isEmpty()
-        && !StringUtils.equalsIgnoreCase(project.getPackaging(), "ear");
+        && !profile.getActiveRulesByRepository(FindbugsConstants.REPOSITORY_KEY).isEmpty();
   }
 
   public void analyse(Project project, SensorContext context) {
index 24b8e5c94133b5963eed8651bf1621cdc87db5dd..c7129175781280046cf0b7aeb253eb8ce1965001 100644 (file)
@@ -56,14 +56,6 @@ public class FindbugsSensorTest extends FindbugsTests {
     assertFalse(analyser.shouldExecuteOnProject(project));
   }
 
-  @Test
-  public void shouldNotExecuteOnEar() {
-    Project project = createProject();
-    when(project.getPackaging()).thenReturn("ear");
-    FindbugsSensor analyser = new FindbugsSensor(createRulesProfileWithActiveRules(), new FakeRuleFinder(), null);
-    assertFalse(analyser.shouldExecuteOnProject(project));
-  }
-
   @Test
   public void shouldExecuteFindbugsWhenNoReportProvided() throws Exception {
     Project project = createProject();
index 15b007f9018679ac3a5932499f1885617dbc4c7a..690603fc09164b17cf80c0f0d40e6c0f20cdff75 100644 (file)
@@ -73,7 +73,6 @@ public class SurefireSensorTest {
     new SurefireSensor().collect(project, mock(SensorContext.class), new File("unknown"));
   }
 
-
   private SensorContext mockContext() {
     SensorContext context = mock(SensorContext.class);
     when(context.isIndexed(any(Resource.class), eq(false))).thenReturn(true);
@@ -83,17 +82,17 @@ public class SurefireSensorTest {
   @Test
   public void shouldHandleTestSuiteDetails() throws URISyntaxException {
     SensorContext context = mockContext();
-    new SurefireSensor().collect(newJarProject(), context, new File(getClass().getResource(
+    new SurefireSensor().collect(new Project("key"), context, new File(getClass().getResource(
         "/org/sonar/plugins/surefire/SurefireSensorTest/shouldHandleTestSuiteDetails/").toURI()));
 
     // 3 classes, 6 measures by class
-    verify(context, times(3)).saveMeasure(argThat(new IsResource(JavaFile.SCOPE_ENTITY, Qualifiers.UNIT_TEST_FILE)),
+    verify(context, times(3)).saveMeasure(argThat(new IsResource(Scopes.FILE, Qualifiers.UNIT_TEST_FILE)),
         eq(CoreMetrics.SKIPPED_TESTS), anyDouble());
-    verify(context, times(3)).saveMeasure(argThat(new IsResource(JavaFile.SCOPE_ENTITY, Qualifiers.UNIT_TEST_FILE)),
+    verify(context, times(3)).saveMeasure(argThat(new IsResource(Scopes.FILE, Qualifiers.UNIT_TEST_FILE)),
         eq(CoreMetrics.TESTS), anyDouble());
-    verify(context, times(18)).saveMeasure(argThat(new IsResource(JavaFile.SCOPE_ENTITY, Qualifiers.UNIT_TEST_FILE)),
+    verify(context, times(18)).saveMeasure(argThat(new IsResource(Scopes.FILE, Qualifiers.UNIT_TEST_FILE)),
         (Metric) anyObject(), anyDouble());
-    verify(context, times(3)).saveMeasure(argThat(new IsResource(JavaFile.SCOPE_ENTITY, Qualifiers.UNIT_TEST_FILE)),
+    verify(context, times(3)).saveMeasure(argThat(new IsResource(Scopes.FILE, Qualifiers.UNIT_TEST_FILE)),
         argThat(new IsMeasure(CoreMetrics.TEST_DATA)));
 
     verify(context).saveMeasure(eq(new JavaFile("org.sonar.core.ExtensionsFinderTest", true)), eq(CoreMetrics.TESTS), eq(4d));
@@ -127,18 +126,18 @@ public class SurefireSensorTest {
   @Test
   public void shouldSaveErrorsAndFailuresInXML() throws URISyntaxException {
     SensorContext context = mockContext();
-    new SurefireSensor().collect(newJarProject(), context, new File(getClass().getResource(
+    new SurefireSensor().collect(new Project("key"), context, new File(getClass().getResource(
         "/org/sonar/plugins/surefire/SurefireSensorTest/shouldSaveErrorsAndFailuresInXML/").toURI()));
 
     // 1 classes, 6 measures by class
-    verify(context, times(1)).saveMeasure(argThat(new IsResource(JavaFile.SCOPE_ENTITY, Qualifiers.UNIT_TEST_FILE)),
+    verify(context, times(1)).saveMeasure(argThat(new IsResource(Scopes.FILE, Qualifiers.UNIT_TEST_FILE)),
         eq(CoreMetrics.SKIPPED_TESTS), anyDouble());
 
-    verify(context, times(1)).saveMeasure(argThat(new IsResource(JavaFile.SCOPE_ENTITY, Qualifiers.UNIT_TEST_FILE)),
+    verify(context, times(1)).saveMeasure(argThat(new IsResource(Scopes.FILE, Qualifiers.UNIT_TEST_FILE)),
         eq(CoreMetrics.TESTS), anyDouble());
-    verify(context, times(6)).saveMeasure(argThat(new IsResource(JavaFile.SCOPE_ENTITY, Qualifiers.UNIT_TEST_FILE)),
+    verify(context, times(6)).saveMeasure(argThat(new IsResource(Scopes.FILE, Qualifiers.UNIT_TEST_FILE)),
         (Metric) anyObject(), anyDouble());
-    verify(context, times(1)).saveMeasure(argThat(new IsResource(JavaFile.SCOPE_ENTITY, Qualifiers.UNIT_TEST_FILE)),
+    verify(context, times(1)).saveMeasure(argThat(new IsResource(Scopes.FILE, Qualifiers.UNIT_TEST_FILE)),
         argThat(new IsMeasure(CoreMetrics.TEST_DATA)));
 
     verify(context).saveMeasure(eq(new JavaFile("org.sonar.core.ExtensionsFinderTest", true)),
@@ -148,7 +147,7 @@ public class SurefireSensorTest {
   @Test
   public void shouldManageClassesWithDefaultPackage() throws URISyntaxException {
     SensorContext context = mockContext();
-    new SurefireSensor().collect(newJarProject(), context, new File(getClass().getResource(
+    new SurefireSensor().collect(new Project("key"), context, new File(getClass().getResource(
         "/org/sonar/plugins/surefire/SurefireSensorTest/shouldManageClassesWithDefaultPackage/").toURI()));
 
     verify(context).saveMeasure(new JavaFile("NoPackagesTest", true), CoreMetrics.TESTS, 2d);
@@ -157,7 +156,7 @@ public class SurefireSensorTest {
   @Test
   public void successRatioIsZeroWhenAllTestsFail() throws URISyntaxException {
     SensorContext context = mockContext();
-    new SurefireSensor().collect(newJarProject(), context, new File(getClass().getResource(
+    new SurefireSensor().collect(new Project("key"), context, new File(getClass().getResource(
         "/org/sonar/plugins/surefire/SurefireSensorTest/successRatioIsZeroWhenAllTestsFail/").toURI()));
 
     verify(context).saveMeasure(eq(new JavaFile("org.sonar.Foo", true)), eq(CoreMetrics.TESTS), eq(2d));
@@ -169,7 +168,7 @@ public class SurefireSensorTest {
   @Test
   public void measuresShouldNotIncludeSkippedTests() throws URISyntaxException {
     SensorContext context = mockContext();
-    new SurefireSensor().collect(newJarProject(), context, new File(getClass().getResource(
+    new SurefireSensor().collect(new Project("key"), context, new File(getClass().getResource(
         "/org/sonar/plugins/surefire/SurefireSensorTest/measuresShouldNotIncludeSkippedTests/").toURI()));
 
     verify(context).saveMeasure(eq(new JavaFile("org.sonar.Foo", true)), eq(CoreMetrics.TESTS), eq(2d));
@@ -182,7 +181,7 @@ public class SurefireSensorTest {
   @Test
   public void noSuccessRatioIfNoTests() throws URISyntaxException {
     SensorContext context = mockContext();
-    new SurefireSensor().collect(newJarProject(), context, new File(getClass().getResource(
+    new SurefireSensor().collect(new Project("key"), context, new File(getClass().getResource(
         "/org/sonar/plugins/surefire/SurefireSensorTest/noSuccessRatioIfNoTests/").toURI()));
 
     verify(context).saveMeasure(eq(new JavaFile("org.sonar.Foo", true)), eq(CoreMetrics.TESTS), eq(0d));
@@ -195,7 +194,7 @@ public class SurefireSensorTest {
   @Test
   public void ignoreSuiteAsInnerClass() throws URISyntaxException {
     SensorContext context = mockContext();
-    new SurefireSensor().collect(newJarProject(), context, new File(getClass().getResource(
+    new SurefireSensor().collect(new Project("key"), context, new File(getClass().getResource(
         "/org/sonar/plugins/surefire/SurefireSensorTest/ignoreSuiteAsInnerClass/").toURI()));
 
     // ignore TestHandler$Input.xml
@@ -232,12 +231,4 @@ public class SurefireSensorTest {
       }
     };
   }
-
-  private static Project newJarProject() {
-    return new Project("key").setPackaging("jar");
-  }
-
-  private static Project newPomProject() {
-    return new Project("key").setPackaging("pom");
-  }
 }
index c7eb9c416005a00bcd639bd05aafc31f83e6e145..8780c8b205ea6221c7f52f0ab32c01c497103e3a 100644 (file)
@@ -146,7 +146,9 @@ public class Project extends Resource {
 
   /**
    * @return the project's packaging
+   * @deprecated in 2.8. See http://jira.codehaus.org/browse/SONAR-2341
    */
+  @Deprecated
   public String getPackaging() {
     return packaging;
   }
@@ -181,7 +183,10 @@ public class Project extends Resource {
 
   /**
    * For internal use only.
+   * 
+   * @deprecated in 2.8. See http://jira.codehaus.org/browse/SONAR-2341
    */
+  @Deprecated
   public Project setPackaging(String packaging) {
     this.packaging = packaging;
     return this;