diff options
author | Evgeny Mandrikov <mandrikov@gmail.com> | 2011-02-02 15:17:10 +0300 |
---|---|---|
committer | Evgeny Mandrikov <mandrikov@gmail.com> | 2011-02-02 15:21:55 +0300 |
commit | b054b6a871861db92348b555f3296976f74d1ee9 (patch) | |
tree | 1181958cdc861991464a9cc0770a491951f5ad23 /plugins | |
parent | d5d6d99b766bf32448b9544d80a5cabe242196c5 (diff) | |
download | sonarqube-b054b6a871861db92348b555f3296976f74d1ee9.tar.gz sonarqube-b054b6a871861db92348b555f3296976f74d1ee9.zip |
SONAR-2161: Normalize Java version for PMD
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdExecutor.java | 20 | ||||
-rw-r--r-- | plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdExecutorTest.java | 14 |
2 files changed, 26 insertions, 8 deletions
diff --git a/plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdExecutor.java b/plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdExecutor.java index d68e61ddddd..5c613c42448 100644 --- a/plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdExecutor.java +++ b/plugins/sonar-pmd-plugin/src/main/java/org/sonar/plugins/pmd/PmdExecutor.java @@ -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 +} diff --git a/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdExecutorTest.java b/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdExecutorTest.java index eabaddb6abb..07e9fb3a677 100644 --- a/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdExecutorTest.java +++ b/plugins/sonar-pmd-plugin/src/test/java/org/sonar/plugins/pmd/PmdExecutorTest.java @@ -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")); + } + } |