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) {
}
}
}
-}
\ No newline at end of file
+}
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
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"));
+ }
+
}