]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2161: Normalize Java version for PMD
authorEvgeny Mandrikov <mandrikov@gmail.com>
Wed, 2 Feb 2011 12:17:10 +0000 (15:17 +0300)
committerEvgeny Mandrikov <mandrikov@gmail.com>
Wed, 2 Feb 2011 12:21:55 +0000 (15:21 +0300)
plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdExecutor.java
plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdExecutorTest.java

index d68e61ddddd59a6aa4f2136fd914b46945bc9f6e..5c613c42448f15f29e1b59b01ec578d495db15c0 100644 (file)
@@ -142,13 +142,19 @@ public class PmdExecutor implements BatchExtension {
     return xmlReport;
   }
 
-  private void setJavaVersion(PMD pmd, Project project) {
-    String javaVersion = JavaUtils.getSourceVersion(project);
-    if (StringUtils.isNotBlank(javaVersion)) {
-      if ("1.1".equals(javaVersion) || "1.2".equals(javaVersion)) {
-        javaVersion = "1.3";
-      }
+  static String getNormalizedJavaVersion(String javaVersion) {
+    if (StringUtils.equals("1.1", javaVersion) || StringUtils.equals("1.2", javaVersion)) {
+      javaVersion = "1.3";
+    } else if (StringUtils.equals("5", javaVersion)) {
+      javaVersion = "1.5";
+    } else if (StringUtils.equals("6", javaVersion)) {
+      javaVersion = "1.6";
     }
+    return javaVersion;
+  }
+
+  private void setJavaVersion(PMD pmd, Project project) {
+    String javaVersion = getNormalizedJavaVersion(JavaUtils.getSourceVersion(project));
     if (javaVersion != null) {
       SourceType sourceType = SourceType.getSourceTypeForId("java " + javaVersion);
       if (sourceType != null) {
@@ -159,4 +165,4 @@ public class PmdExecutor implements BatchExtension {
       }
     }
   }
-}
\ No newline at end of file
+}
index eabaddb6abbea50598b29e827b46e47fb6a8f8e9..07e9fb3a677d7d2c9e540d99e729d2a8d6d00584 100644 (file)
@@ -33,13 +33,13 @@ import java.net.URISyntaxException;
 import java.nio.charset.Charset;
 import java.util.Arrays;
 
+import static org.hamcrest.Matchers.nullValue;
 import static org.hamcrest.core.Is.is;
 import static org.hamcrest.number.OrderingComparisons.greaterThan;
 import static org.junit.Assert.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-
 public class PmdExecutorTest {
 
   @Test
@@ -85,4 +85,16 @@ public class PmdExecutorTest {
     File xmlReport = executor.execute();
     assertThat(xmlReport.exists(), is(true));
   }
+
+  @Test
+  public void shouldNormalizeJavaVersion() {
+    assertThat(PmdExecutor.getNormalizedJavaVersion(null), nullValue());
+    assertThat(PmdExecutor.getNormalizedJavaVersion(""), is(""));
+    assertThat(PmdExecutor.getNormalizedJavaVersion("1.1"), is("1.3"));
+    assertThat(PmdExecutor.getNormalizedJavaVersion("1.2"), is("1.3"));
+    assertThat(PmdExecutor.getNormalizedJavaVersion("1.4"), is("1.4"));
+    assertThat(PmdExecutor.getNormalizedJavaVersion("5"), is("1.5"));
+    assertThat(PmdExecutor.getNormalizedJavaVersion("6"), is("1.6"));
+  }
+
 }