Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to latest PMD #51

Merged
merged 2 commits into from
Nov 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<properties>
<maven.test.redirectTestOutputToFile>true</maven.test.redirectTestOutputToFile>

<pmd.version>6.7.0</pmd.version>
<pmd.version>5.4.2</pmd.version>
<junit.jupiter.version>5.3.1</junit.jupiter.version>
</properties>
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/org/sonar/plugins/pmd/PmdTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
public class PmdTemplate {

private static final Logger LOG = Loggers.get(PmdTemplate.class);

private static final Map<String, String> JAVA_VERSIONS = prepareVersions();

private static Map<String, String> prepareVersions() {
Expand All @@ -50,7 +49,10 @@ private static Map<String, String> prepareVersions() {
versions.put("6", "1.6");
versions.put("7", "1.7");
versions.put("8", "1.8");

versions.put("9", "9");
versions.put("10", "10");
versions.put("11", "11");

return versions;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,12 @@ void should_fail_to_dump_xml_rule_set() {
@Test
void should_dump_xml_report() throws IOException {
when(fs.workDir()).thenReturn(WORK_DIR);

settings.setProperty(PmdConfiguration.PROPERTY_GENERATE_XML, true);
Path reportFile = configuration.dumpXmlReport(new Report());

assertThat(reportFile.toFile()).isEqualTo(new File(WORK_DIR, "pmd-result.xml"));
List<String> writtenLines = Files.readAllLines(reportFile, StandardCharsets.UTF_8);
assertThat(writtenLines).hasSize(3);
assertThat(writtenLines).hasSize(6);
assertThat(writtenLines.get(1)).contains("<pmd");
}

Expand Down
69 changes: 40 additions & 29 deletions src/test/java/org/sonar/plugins/pmd/PmdTemplateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,8 @@
import net.sourceforge.pmd.RuleContext;
import net.sourceforge.pmd.RuleSets;
import net.sourceforge.pmd.SourceCodeProcessor;
import net.sourceforge.pmd.lang.java.Java13Handler;
import net.sourceforge.pmd.lang.java.Java15Handler;
import net.sourceforge.pmd.lang.java.Java16Handler;
import net.sourceforge.pmd.lang.java.Java17Handler;
import net.sourceforge.pmd.lang.java.Java18Handler;
import net.sourceforge.pmd.lang.java.JavaLanguageHandler;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.mockito.stubbing.Answer;
import org.sonar.api.batch.fs.InputFile;
Expand Down Expand Up @@ -88,29 +85,44 @@ void should_ignore_PMD_error() throws PMDException {
}

@Test
void java12_version() {
assertThat(PmdTemplate.languageVersion("1.2").getLanguageVersionHandler()).isInstanceOf(Java13Handler.class);
}

@Test
void java5_version() {
assertThat(PmdTemplate.languageVersion("5").getLanguageVersionHandler()).isInstanceOf(Java15Handler.class);
}

@Test
void java6_version() {
assertThat(PmdTemplate.languageVersion("6").getLanguageVersionHandler()).isInstanceOf(Java16Handler.class);
}

@Test
void java7_version() {
assertThat(PmdTemplate.languageVersion("7").getLanguageVersionHandler()).isInstanceOf(Java17Handler.class);
}

@Test
void java8_version() {
assertThat(PmdTemplate.languageVersion("8").getLanguageVersionHandler()).isInstanceOf(Java18Handler.class);
}
public void java12_version() {
assertThat(PmdTemplate.languageVersion("1.2").getLanguageVersionHandler()).isInstanceOf(JavaLanguageHandler.class);
}

@Test
public void java5_version() {
assertThat(PmdTemplate.languageVersion("5").getLanguageVersionHandler()).isInstanceOf(JavaLanguageHandler.class);
}

@Test
public void java6_version() {
assertThat(PmdTemplate.languageVersion("6").getLanguageVersionHandler()).isInstanceOf(JavaLanguageHandler.class);
}

@Test
public void java7_version() {
assertThat(PmdTemplate.languageVersion("7").getLanguageVersionHandler()).isInstanceOf(JavaLanguageHandler.class);
}

@Test
public void java8_version() {
assertThat(PmdTemplate.languageVersion("8").getLanguageVersionHandler()).isInstanceOf(JavaLanguageHandler.class);
}

@Test
public void java9_version() {
assertThat(PmdTemplate.languageVersion("9").getLanguageVersionHandler()).isInstanceOf(JavaLanguageHandler.class);
}

@Test
public void java10_version() {
assertThat(PmdTemplate.languageVersion("10").getLanguageVersionHandler()).isInstanceOf(JavaLanguageHandler.class);
}

@Test
public void java11_version() {
assertThat(PmdTemplate.languageVersion("11").getLanguageVersionHandler()).isInstanceOf(JavaLanguageHandler.class);
}

@Test
void should_fail_on_invalid_java_version() {
Expand Down Expand Up @@ -138,5 +150,4 @@ void should_set_encoding() {
PmdTemplate pmdTemplate = PmdTemplate.create("6", mock(ClassLoader.class), StandardCharsets.UTF_16BE);
assertThat(pmdTemplate.configuration().getSourceEncoding()).isEqualTo("UTF-16BE");
}

}
34 changes: 16 additions & 18 deletions src/test/resources/org/sonar/plugins/pmd/simple.xml
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<ruleset>
<description>Sonar PMD rules</description>
<rule ref="rulesets/java/coupling.xml/CouplingBetweenObjects">
<priority>2</priority>
<properties>
<property name="threshold" value="20"/>
</properties>
</rule>
<rule ref="rulesets/java/coupling.xml/ExcessiveImports">
<properties>
<property name="minimum" value="30"/>
</properties>
</rule>
<rule ref="rulesets/java/design.xml/UseNotifyAllInsteadOfNotify">
<priority>4</priority>
</rule>
<rule class="net.sourceforge.pmd.lang.java.rule.design.UseCollectionIsEmptyRule">
<priority>3</priority>
</rule>
<description>Sonar PMD rules</description>
<rule name="Sample1" ref="rulesets/java/coupling.xml/CouplingBetweenObjects">
<priority>2</priority>
<properties>
<property name="threshold" value="20"/>
</properties>
</rule>
<rule name="Sample2" ref="rulesets/java/coupling.xml/ExcessiveImports">
<properties>
<property name="minimum" value="30"/>
</properties>
</rule>
<rule name="Sample3" ref="rulesets/java/design.xml/UseNotifyAllInsteadOfNotify">
<priority>4</priority>
</rule>
<rule name="Sample4" class="net.sourceforge.pmd.lang.java.rule.design.UseUtilityClassRule">
</ruleset>