Merge branch 'pr-826'

This commit is contained in:
Juan Martín Sotuyo Dodero
2018-01-07 18:17:31 -03:00
4 changed files with 92 additions and 1 deletions

View File

@ -19,6 +19,26 @@ This is a bug fixing release.
### New and noteworthy
#### Additional information about the new introduced rule categories
With the release of PMD 6.0.0, all rules have been sorted into one of the following eight categories:
1. **Best Practices**: These are rules which enforce generally accepted best practices.
2. **Code Style**: These rules enforce a specific coding style.
3. **Design**: Rules that help you discover design issues.
4. **Documentation**: These rules are related to code documentation.
5. **Error Prone**: Rules to detect constructs that are either broken, extremely confusing or prone to runtime errors.
6. **Multithreading**: These are rules that flag issues when dealing with multiple threads of execution.
7. **Performance**: Rules that flag suboptimal code.
8. **Security**: Rules that flag potential security flaws.
Please note, that not every category in every language may have a rule. There might be categories with no
rules at all, such as `category/java/security.xml`, which has currently no rules.
There are even languages, which only have rules of one category (e.g. `category/xml/errorprone.xml`).
You can find the information about available rules in the generated rule documentation, available
at <https://pmd.github.io/latest/>.
### Fixed Issues
* apex-errorprone
@ -26,6 +46,7 @@ This is a bug fixing release.
* apex-security
* [#788](https://github.com/pmd/pmd/issues/788): \[apex] Method chaining breaks ApexCRUDViolation
* doc
* [#782](https://github.com/pmd/pmd/issues/782): \[doc] Wrong information in the Release Notes about the Security ruleset
* [#794](https://github.com/pmd/pmd/issues/794): \[doc] Broken documentation links for 6.0.0
* java
* [#783](https://github.com/pmd/pmd/issues/783): \[java] GuardLogStatement regression

View File

@ -520,7 +520,7 @@ public class RuleSetFactory {
}
boolean rulesetDeprecated = false;
if (potentialRules.size() == countDeprecated) {
if (!potentialRules.isEmpty() && potentialRules.size() == countDeprecated) {
// all rules in the ruleset have been deprecated - the ruleset itself is considered to be deprecated
rulesetDeprecated = true;
LOG.warning("The RuleSet " + ref + " has been deprecated.");

View File

@ -14,10 +14,15 @@ import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.logging.Handler;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@ -575,6 +580,59 @@ public class RuleSetFactoryTest {
assertEquals(0, ruleset.getRules().size());
}
private static class InMemoryLogHandler extends Handler {
private List<LogRecord> records = Collections.synchronizedList(new ArrayList<LogRecord>());
@Override
public void close() throws SecurityException {
}
@Override
public void flush() {
records.clear();
}
@Override
public void publish(LogRecord record) {
records.add(record);
}
public List<LogRecord> getLogRecords() {
return new ArrayList<>(records);
}
}
/**
* See https://github.com/pmd/pmd/issues/782
* Empty ruleset should be interpreted as deprecated.
*
* @throws Exception
* any error
*/
@Test
public void testEmptyRuleSetReferencedShouldNotBeDeprecated() throws Exception {
InMemoryLogHandler logHandler = new InMemoryLogHandler();
Logger logger = Logger.getLogger(RuleSetFactory.class.getName());
try {
logger.addHandler(logHandler);
RuleSetReferenceId ref = createRuleSetReferenceId("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "\n"
+ "<ruleset name=\"Custom ruleset\" xmlns=\"http://pmd.sourceforge.net/ruleset/2.0.0\"\n"
+ " xmlns:xsi=\"http:www.w3.org/2001/XMLSchema-instance\"\n"
+ " xsi:schemaLocation=\"http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd\">\n"
+ " <description>Ruleset which references a empty ruleset</description>\n" + "\n"
+ " <rule ref=\"rulesets/dummy/empty-ruleset.xml\" />\n"
+ "</ruleset>\n");
RuleSetFactory ruleSetFactory = new RuleSetFactory(new ResourceLoader(), RulePriority.LOW, true, true);
RuleSet ruleset = ruleSetFactory.createRuleSet(ref);
assertEquals(0, ruleset.getRules().size());
assertEquals(0, logHandler.getLogRecords().size());
} finally {
logger.removeHandler(logHandler);
}
}
/**
* See https://sourceforge.net/p/pmd/bugs/1231/
*

View File

@ -0,0 +1,12 @@
<?xml version="1.0"?>
<ruleset name="Test Ruleset which is empty" xmlns="http://pmd.sourceforge.net/ruleset/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd">
<description>
Empty Ruleset which contains no rules.
Although it is empty, it should not be marked as deprecated, just because it has no rules (yet).
</description>
<!-- Deliberately empty, no rules. -->
</ruleset>