]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2011:
authorGodin <mandrikov@gmail.com>
Mon, 6 Dec 2010 11:15:36 +0000 (11:15 +0000)
committerGodin <mandrikov@gmail.com>
Mon, 6 Dec 2010 11:15:36 +0000 (11:15 +0000)
* Deprecate Project.getPom()
* Decrease scope of dependency on maven-project from provided to test for sonar-findbugs-plugin

plugins/sonar-findbugs-plugin/pom.xml
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
sonar-plugin-api/src/main/java/org/sonar/api/resources/Project.java

index accafae3a9c37b06f8a1a59fbc8cdea3b7b22eab..e437710f1babe4c4f2b583abd93ff8da4f874884 100644 (file)
       <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>
index 1a64cfab16d245f386c53fbbbf51992ad1280cd9..e14a15df1c3486acd32790053a838c20c356d013 100644 (file)
@@ -19,9 +19,6 @@
  */
 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;
@@ -34,6 +31,9 @@ import org.sonar.api.rules.RuleFinder;
 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;
@@ -47,8 +47,8 @@ public class FindbugsSensor implements Sensor {
 
   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) {
index a35c8fc3c4f2f21e003a49036668a36d02e75145..d436502634ab109d88478c0fc8fcff50f5a8803a 100644 (file)
@@ -20,7 +20,6 @@
 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;
@@ -53,22 +52,22 @@ public class FindbugsSensorTest extends FindbugsTests {
   @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));
   }
@@ -151,10 +150,8 @@ public class FindbugsSensorTest extends FindbugsTests {
     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;
   }
 
index 9f7dcbaac7147873995e21eab07ecda0ac235b7a..b5a42df74fa6716a03f19d1fa93c49e2bdfcdaa4 100644 (file)
@@ -376,8 +376,10 @@ public class Project extends Resource {
   }
 
   /**
-   * @return the underlying maven project
+   * @return the underlying Maven project
+   * @deprecated since 2.5. See http://jira.codehaus.org/browse/SONAR-2011
    */
+  @Deprecated
   public MavenProject getPom() {
     return pom;
   }