forked from phoedos/pmd
Merge branch '7.0.x' into master-ant-script
This commit is contained in:
@ -29,7 +29,7 @@ public class CycloMetric extends AbstractApexOperationMetric {
|
||||
public double computeFor(ASTMethod node, MetricOptions options) {
|
||||
return ((MutableInt) node.jjtAccept(new StandardCycloVisitor(), new MutableInt(1))).doubleValue();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Computes the number of control flow paths through that expression, which is the number of {@code ||} and {@code
|
||||
|
@ -12,7 +12,7 @@ import apex.jorje.services.Version;
|
||||
|
||||
/**
|
||||
* Do special checks for apex unit test classes and methods
|
||||
*
|
||||
*
|
||||
* @author a.subramanian
|
||||
*/
|
||||
public abstract class AbstractApexUnitTestRule extends AbstractApexRule {
|
||||
|
@ -32,7 +32,7 @@ public class MethodNamingConventionsRule extends AbstractNamingConventionsRule {
|
||||
.desc("deprecated! Skip underscores in test methods")
|
||||
.defaultValue(false)
|
||||
.build();
|
||||
|
||||
|
||||
public MethodNamingConventionsRule() {
|
||||
definePropertyDescriptor(SKIP_TEST_METHOD_UNDERSCORES_DESCRIPTOR);
|
||||
definePropertyDescriptor(TEST_REGEX);
|
||||
|
@ -23,7 +23,7 @@ import net.sourceforge.pmd.properties.PropertyFactory;
|
||||
|
||||
/**
|
||||
* Cyclomatic complexity rule using metrics. Uses Wmc to report classes.
|
||||
*
|
||||
*
|
||||
* @author Clément Fournier
|
||||
*/
|
||||
public class CyclomaticComplexityRule extends AbstractApexRule {
|
||||
|
@ -8,7 +8,7 @@ import net.sourceforge.pmd.lang.apex.ast.ASTMethod;
|
||||
|
||||
/**
|
||||
* Non-commented source statement counter for constructors.
|
||||
*
|
||||
*
|
||||
* @author ported from Java original by Jason Bennett
|
||||
*/
|
||||
public class NcssConstructorCountRule extends AbstractNcssCountRule<ASTMethod> {
|
||||
|
@ -8,7 +8,7 @@ import net.sourceforge.pmd.lang.apex.ast.ASTMethod;
|
||||
|
||||
/**
|
||||
* Non-commented source statement counter for methods.
|
||||
*
|
||||
*
|
||||
* @author ported from Java original of Jason Bennett
|
||||
*/
|
||||
public class NcssMethodCountRule extends AbstractNcssCountRule<ASTMethod> {
|
||||
|
@ -8,7 +8,7 @@ import net.sourceforge.pmd.lang.apex.ast.ASTUserClass;
|
||||
|
||||
/**
|
||||
* Non-commented source statement counter for type declarations.
|
||||
*
|
||||
*
|
||||
* @author ported from Java original of Jason Bennett
|
||||
*/
|
||||
public class NcssTypeCountRule extends AbstractNcssCountRule {
|
||||
|
@ -32,10 +32,10 @@ import net.sourceforge.pmd.properties.PropertyFactory;
|
||||
* <p>
|
||||
* Standard rules: +1 for each decision point, but not including boolean
|
||||
* operators unlike CyclomaticComplexityRule.
|
||||
*
|
||||
*
|
||||
* @author ported on Java version of Alan Hohn, based on work by Donald A.
|
||||
* Leckie
|
||||
*
|
||||
*
|
||||
* @since June 18, 2014
|
||||
*/
|
||||
public class StdCyclomaticComplexityRule extends AbstractApexRule {
|
||||
|
@ -15,18 +15,18 @@ import net.sourceforge.pmd.lang.apex.rule.AbstractApexRule;
|
||||
public class AvoidHardcodingIdRule extends AbstractApexRule {
|
||||
private static final Pattern PATTERN = Pattern.compile("^[a-zA-Z0-9]{5}0[a-zA-Z0-9]{9}([a-zA-Z0-5]{3})?$");
|
||||
private static final Map<String, Character> CHECKSUM_LOOKUP;
|
||||
|
||||
|
||||
static {
|
||||
final Map<String, Character> lookup = new HashMap<>();
|
||||
final char[] chartable = "ABCDEFGHIJKLMNOPQRSTUVWXYZ012345".toCharArray();
|
||||
|
||||
|
||||
for (int i = 0; i < chartable.length; i++) {
|
||||
lookup.put(String.format("%5s", Integer.toBinaryString(i)).replace(' ', '0'), chartable[i]);
|
||||
}
|
||||
|
||||
|
||||
CHECKSUM_LOOKUP = Collections.unmodifiableMap(lookup);
|
||||
}
|
||||
|
||||
|
||||
public AvoidHardcodingIdRule() {
|
||||
addRuleChainVisit(ASTLiteralExpression.class);
|
||||
}
|
||||
@ -55,11 +55,11 @@ public class AvoidHardcodingIdRule extends AbstractApexRule {
|
||||
final String part1 = literal.substring(0, 5);
|
||||
final String part2 = literal.substring(5, 10);
|
||||
final String part3 = literal.substring(10, 15);
|
||||
|
||||
|
||||
final char checksum1 = checksum(part1);
|
||||
final char checksum2 = checksum(part2);
|
||||
final char checksum3 = checksum(part3);
|
||||
|
||||
|
||||
return literal.charAt(15) == checksum1 && literal.charAt(16) == checksum2
|
||||
&& literal.charAt(17) == checksum3;
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ import apex.jorje.semantic.ast.statement.VariableDeclaration;
|
||||
|
||||
/**
|
||||
* Helper methods
|
||||
*
|
||||
*
|
||||
* @author sergey.gorbaty
|
||||
*
|
||||
*/
|
||||
@ -73,9 +73,9 @@ public final class Helper {
|
||||
|
||||
/**
|
||||
* Finds DML operations in a given node descendants' path
|
||||
*
|
||||
*
|
||||
* @param node
|
||||
*
|
||||
*
|
||||
* @return true if found DML operations in node descendants
|
||||
*/
|
||||
public static boolean foundAnyDML(final ApexNode<?> node) {
|
||||
@ -165,7 +165,7 @@ public final class Helper {
|
||||
.append(n.getFieldInfo().getName());
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
public static String getFQVariableName(final ASTFieldDeclaration variable) {
|
||||
StringBuilder sb = new StringBuilder()
|
||||
.append(variable.getNode().getDefiningType().getApexName()).append(":")
|
||||
|
@ -22,7 +22,7 @@ import net.sourceforge.pmd.lang.apex.rule.internal.Helper;
|
||||
/**
|
||||
* Insecure HTTP endpoints passed to (req.setEndpoint)
|
||||
* req.setHeader('Authorization') should use named credentials
|
||||
*
|
||||
*
|
||||
* @author sergey.gorbaty
|
||||
*
|
||||
*/
|
||||
|
@ -30,7 +30,7 @@ import net.sourceforge.pmd.lang.apex.rule.internal.Helper;
|
||||
/**
|
||||
* Detects if variables in Database.query(variable) is escaped with
|
||||
* String.escapeSingleQuotes
|
||||
*
|
||||
*
|
||||
* @author sergey.gorbaty
|
||||
*
|
||||
*/
|
||||
|
@ -16,7 +16,7 @@ import net.sourceforge.pmd.lang.apex.rule.internal.Helper;
|
||||
|
||||
/**
|
||||
* Finds Apex class that do not define sharing
|
||||
*
|
||||
*
|
||||
* @author sergey.gorbaty
|
||||
*/
|
||||
public class ApexSharingViolationsRule extends AbstractApexRule {
|
||||
@ -43,7 +43,7 @@ public class ApexSharingViolationsRule extends AbstractApexRule {
|
||||
/**
|
||||
* Check if class contains any Database.query / Database.insert [ Database.*
|
||||
* ] methods
|
||||
*
|
||||
*
|
||||
* @param node
|
||||
* @param data
|
||||
*/
|
||||
@ -73,7 +73,7 @@ public class ApexSharingViolationsRule extends AbstractApexRule {
|
||||
|
||||
/**
|
||||
* Check if class has no sharing declared
|
||||
*
|
||||
*
|
||||
* @param node
|
||||
* @param data
|
||||
*/
|
||||
@ -86,7 +86,7 @@ public class ApexSharingViolationsRule extends AbstractApexRule {
|
||||
|
||||
/**
|
||||
* Does class have sharing keyword declared?
|
||||
*
|
||||
*
|
||||
* @param node
|
||||
* @return
|
||||
*/
|
||||
|
@ -23,7 +23,7 @@ import net.sourceforge.pmd.lang.apex.rule.internal.Helper;
|
||||
* Flags usage of http request.setHeader('Authorization',..) and suggests using
|
||||
* named credentials which helps store credentials for the callout in a safe
|
||||
* place.
|
||||
*
|
||||
*
|
||||
* @author sergey.gorbaty
|
||||
*
|
||||
*/
|
||||
|
@ -24,7 +24,7 @@ import net.sourceforge.pmd.lang.apex.rule.internal.Helper;
|
||||
/**
|
||||
* Detects potential XSS when controller extracts a variable from URL query and
|
||||
* uses it without escaping first
|
||||
*
|
||||
*
|
||||
* @author sergey.gorbaty
|
||||
*
|
||||
*/
|
||||
|
@ -38,7 +38,7 @@ import apex.jorje.semantic.ast.statement.VariableDeclaration;
|
||||
|
||||
/**
|
||||
* Helper methods
|
||||
*
|
||||
*
|
||||
* @author sergey.gorbaty
|
||||
*
|
||||
* @deprecated Use {@link net.sourceforge.pmd.lang.apex.rule.internal.Helper} instead.
|
||||
@ -72,9 +72,9 @@ public final class Helper {
|
||||
|
||||
/**
|
||||
* Finds DML operations in a given node descendants' path
|
||||
*
|
||||
*
|
||||
* @param node
|
||||
*
|
||||
*
|
||||
* @return true if found DML operations in node descendants
|
||||
*/
|
||||
static boolean foundAnyDML(final ApexNode<?> node) {
|
||||
@ -166,7 +166,7 @@ public final class Helper {
|
||||
.append(n.getFieldInfo().getName());
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
static String getFQVariableName(final ASTFieldDeclaration variable) {
|
||||
StringBuilder sb = new StringBuilder()
|
||||
.append(variable.getNode().getDefiningType().getApexName()).append(":")
|
||||
|
@ -92,7 +92,7 @@ public class Complicated {
|
||||
class="net.sourceforge.pmd.lang.apex.rule.design.ExcessiveClassLengthRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_design.html#excessiveclasslength">
|
||||
<description>
|
||||
Excessive class file lengths are usually indications that the class may be burdened with excessive
|
||||
Excessive class file lengths are usually indications that the class may be burdened with excessive
|
||||
responsibilities that could be provided by external classes or functions. In breaking these methods
|
||||
apart the code becomes more managable and ripe for reuse.
|
||||
</description>
|
||||
@ -133,7 +133,7 @@ same datatype. These situations usually denote the need for new objects to wrap
|
||||
public void addPerson(int birthYear, int birthMonth, int birthDate, int height, int weight, int ssn) {
|
||||
// ...
|
||||
}
|
||||
// preferred approach
|
||||
// preferred approach
|
||||
public void addPerson(Date birthdate, BodyMeasurements measurements, int ssn) {
|
||||
// ...
|
||||
}
|
||||
@ -260,8 +260,8 @@ public class Foo extends Bar {
|
||||
class="net.sourceforge.pmd.lang.apex.rule.design.StdCyclomaticComplexityRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_design.html#stdcyclomaticcomplexity">
|
||||
<description>
|
||||
Complexity directly affects maintenance costs is determined by the number of decision points in a method
|
||||
plus one for the method entry. The decision points include 'if', 'while', 'for', and 'case labels' calls.
|
||||
Complexity directly affects maintenance costs is determined by the number of decision points in a method
|
||||
plus one for the method entry. The decision points include 'if', 'while', 'for', and 'case labels' calls.
|
||||
Generally, numbers ranging from 1-4 denote low complexity, 5-7 denote moderate complexity, 8-10 denote
|
||||
high complexity, and 11+ is very high complexity.
|
||||
</description>
|
||||
@ -315,7 +315,7 @@ public class Foo {
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_design.html#toomanyfields">
|
||||
<description>
|
||||
Classes that have too many fields can become unwieldy and could be redesigned to have fewer fields,
|
||||
possibly through grouping related fields in new objects. For example, a class with individual
|
||||
possibly through grouping related fields in new objects. For example, a class with individual
|
||||
city/state/zip fields could park them within a single Address field.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
|
@ -71,8 +71,8 @@ Avoid directly accessing Trigger.old and Trigger.new as it can lead to a bug. Tr
|
||||
<![CDATA[
|
||||
trigger AccountTrigger on Account (before insert, before update) {
|
||||
Account a = Trigger.new[0]; //Bad: Accessing the trigger array directly is not recommended.
|
||||
|
||||
foreach ( Account a : Trigger.new ){
|
||||
|
||||
foreach ( Account a : Trigger.new ){
|
||||
//Good: Iterate through the trigger.new array instead.
|
||||
}
|
||||
}
|
||||
@ -114,8 +114,8 @@ public without sharing class Foo {
|
||||
class="net.sourceforge.pmd.lang.apex.rule.ApexXPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_errorprone.html#emptycatchblock">
|
||||
<description>
|
||||
Empty Catch Block finds instances where an exception is caught, but nothing is done.
|
||||
In most circumstances, this swallows an exception which should either be acted on
|
||||
Empty Catch Block finds instances where an exception is caught, but nothing is done.
|
||||
In most circumstances, this swallows an exception which should either be acted on
|
||||
or reported.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
@ -261,7 +261,7 @@ public class Foo {
|
||||
class="net.sourceforge.pmd.lang.apex.rule.ApexXPathRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_errorprone.html#emptywhilestmt">
|
||||
<description>
|
||||
Empty While Statement finds all instances where a while statement does nothing.
|
||||
Empty While Statement finds all instances where a while statement does nothing.
|
||||
If it is a timing loop, then you should use Thread.sleep() for it; if it is
|
||||
a while loop that does a lot in the exit expression, rewrite it to make it clearer.
|
||||
</description>
|
||||
|
@ -21,7 +21,7 @@ Avoid DML statements inside loops to avoid hitting the DML governor limit. Inste
|
||||
<example>
|
||||
<![CDATA[
|
||||
public class Something {
|
||||
public void foo() {
|
||||
public void foo() {
|
||||
for (Integer i = 0; i < 151; i++) {
|
||||
Account account;
|
||||
// ...
|
||||
|
@ -38,7 +38,7 @@ public without sharing class Foo {
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_security.html#apexcrudviolation">
|
||||
<description>
|
||||
The rule validates you are checking for access permissions before a SOQL/SOSL/DML operation.
|
||||
Since Apex runs in system mode not having proper permissions checks results in escalation of
|
||||
Since Apex runs in system mode not having proper permissions checks results in escalation of
|
||||
privilege and may produce runtime errors. This check forces you to handle such scenarios.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
|
@ -27,7 +27,7 @@ public class ApexLexerTest {
|
||||
public void testLexer() throws Exception {
|
||||
CharStream in = new ANTLRStringStream(CODE);
|
||||
ApexLexer lexer = new ApexLexer(in);
|
||||
|
||||
|
||||
Token token = lexer.nextToken();
|
||||
int tokenCount = 0;
|
||||
while (token.getType() != Token.EOF) {
|
||||
|
@ -101,8 +101,8 @@
|
||||
<artifactId>antlr4-runtime</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.beust</groupId>
|
||||
<artifactId>jcommander</artifactId>
|
||||
<groupId>com.beust</groupId>
|
||||
<artifactId>jcommander</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
@ -196,14 +196,14 @@
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>m2e</id>
|
||||
<!-- This profile is only activated when building in Eclipse with m2e -->
|
||||
<activation>
|
||||
<property>
|
||||
<name>m2e.version</name>
|
||||
</property>
|
||||
</activation>
|
||||
<dependencies>
|
||||
<id>m2e</id>
|
||||
<!-- This profile is only activated when building in Eclipse with m2e -->
|
||||
<activation>
|
||||
<property>
|
||||
<name>m2e.version</name>
|
||||
</property>
|
||||
</activation>
|
||||
<dependencies>
|
||||
<!--
|
||||
the maven-shade-plugin runs during package phase,
|
||||
but inside eclipse, this phase is not executed during development.
|
||||
@ -214,24 +214,24 @@
|
||||
<artifactId>jaxen</artifactId>
|
||||
<optional>false</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencies>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>idea</id>
|
||||
<!-- This profile is only activated when building in IntelliJ -->
|
||||
<!-- It serves the same purpose as the above for eclipse-->
|
||||
<activation>
|
||||
<property>
|
||||
<name>idea.maven.embedder.version</name>
|
||||
</property>
|
||||
</activation>
|
||||
<dependencies>
|
||||
<id>idea</id>
|
||||
<!-- This profile is only activated when building in IntelliJ -->
|
||||
<!-- It serves the same purpose as the above for eclipse-->
|
||||
<activation>
|
||||
<property>
|
||||
<name>idea.maven.embedder.version</name>
|
||||
</property>
|
||||
</activation>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>jaxen</groupId>
|
||||
<artifactId>jaxen</artifactId>
|
||||
<optional>false</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencies>
|
||||
</profile>
|
||||
</profiles>
|
||||
</project>
|
||||
|
@ -460,11 +460,11 @@ public class PMD {
|
||||
*/
|
||||
public static int run(final String[] args) {
|
||||
final PMDParameters params = PMDCommandLineInterface.extractParameters(new PMDParameters(), args, "pmd");
|
||||
|
||||
|
||||
if (params.isBenchmark()) {
|
||||
TimeTracker.startGlobalTracking();
|
||||
}
|
||||
|
||||
|
||||
int status = PMDCommandLineInterface.NO_ERRORS_STATUS;
|
||||
final PMDConfiguration configuration = params.toConfiguration();
|
||||
|
||||
@ -490,7 +490,7 @@ public class PMD {
|
||||
} finally {
|
||||
logHandlerManager.close();
|
||||
LOG.setLevel(oldLogLevel);
|
||||
|
||||
|
||||
if (params.isBenchmark()) {
|
||||
final TimingReport timingReport = TimeTracker.stopGlobalTracking();
|
||||
|
||||
|
@ -581,7 +581,7 @@ public class PMDConfiguration extends AbstractConfiguration {
|
||||
|
||||
/**
|
||||
* Retrieves the currently used analysis cache. Will never be null.
|
||||
*
|
||||
*
|
||||
* @return The currently used analysis cache. Never null.
|
||||
*/
|
||||
public AnalysisCache getAnalysisCache() {
|
||||
@ -593,7 +593,7 @@ public class PMDConfiguration extends AbstractConfiguration {
|
||||
|
||||
return analysisCache;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the analysis cache to be used. Setting a
|
||||
* value of {@code null} will cause a Noop AnalysisCache to be used.
|
||||
@ -611,7 +611,7 @@ public class PMDConfiguration extends AbstractConfiguration {
|
||||
/**
|
||||
* Sets the location of the analysis cache to be used. This will automatically configure
|
||||
* and appropriate AnalysisCache implementation.
|
||||
*
|
||||
*
|
||||
* @param cacheLocation The location of the analysis cache to be used.
|
||||
*/
|
||||
public void setAnalysisCacheLocation(final String cacheLocation) {
|
||||
|
@ -16,14 +16,14 @@ import java.util.logging.Logger;
|
||||
public final class PMDVersion {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(PMDVersion.class.getName());
|
||||
|
||||
|
||||
/**
|
||||
* Constant that contains always the current version of PMD.
|
||||
*/
|
||||
public static final String VERSION;
|
||||
|
||||
|
||||
private static final String UNKNOWN_VERSION = "unknown";
|
||||
|
||||
|
||||
/**
|
||||
* Determines the version from maven's generated pom.properties file.
|
||||
*/
|
||||
@ -34,33 +34,33 @@ public final class PMDVersion {
|
||||
final Properties properties = new Properties();
|
||||
properties.load(stream);
|
||||
pmdVersion = properties.getProperty("version");
|
||||
}
|
||||
}
|
||||
} catch (final IOException e) {
|
||||
LOG.log(Level.FINE, "Couldn't determine version of PMD", e);
|
||||
}
|
||||
|
||||
|
||||
VERSION = pmdVersion;
|
||||
}
|
||||
|
||||
|
||||
private PMDVersion() {
|
||||
throw new AssertionError("Can't instantiate utility classes");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the next major release to be expected.
|
||||
* Useful when logging deprecation messages to indicate when support will be removed.
|
||||
*
|
||||
*
|
||||
* @return The next major release to be expected.
|
||||
*/
|
||||
public static String getNextMajorRelease() {
|
||||
if (isUnknown()) {
|
||||
return UNKNOWN_VERSION;
|
||||
}
|
||||
|
||||
|
||||
final int major = Integer.parseInt(VERSION.split("\\.")[0]);
|
||||
return (major + 1) + ".0.0";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if the current version is unknown.
|
||||
* @return True if an unknown version, false otherwise
|
||||
@ -68,7 +68,7 @@ public final class PMDVersion {
|
||||
public static boolean isUnknown() {
|
||||
return UNKNOWN_VERSION.equals(VERSION);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if the current version is a snapshot.
|
||||
* @return True if a snapshot release, false otherwise
|
||||
|
@ -454,21 +454,21 @@ public class RuleSetFactory {
|
||||
// This is the PRIMARY defense. If DTDs (doctypes) are disallowed, almost all XML entity attacks are prevented
|
||||
// Xerces 2 only - http://xerces.apache.org/xerces2-j/features.html#disallow-doctype-decl
|
||||
dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
|
||||
|
||||
|
||||
// If you can't completely disable DTDs, then at least do the following:
|
||||
// Xerces 1 - http://xerces.apache.org/xerces-j/features.html#external-general-entities
|
||||
// Xerces 2 - http://xerces.apache.org/xerces2-j/features.html#external-general-entities
|
||||
// JDK7+ - http://xml.org/sax/features/external-general-entities
|
||||
// JDK7+ - http://xml.org/sax/features/external-general-entities
|
||||
dbf.setFeature("http://xml.org/sax/features/external-general-entities", false);
|
||||
|
||||
|
||||
// Xerces 1 - http://xerces.apache.org/xerces-j/features.html#external-parameter-entities
|
||||
// Xerces 2 - http://xerces.apache.org/xerces2-j/features.html#external-parameter-entities
|
||||
// JDK7+ - http://xml.org/sax/features/external-parameter-entities
|
||||
// JDK7+ - http://xml.org/sax/features/external-parameter-entities
|
||||
dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
|
||||
|
||||
|
||||
// Disable external DTDs as well
|
||||
dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
|
||||
|
||||
|
||||
// and these as well, per Timothy Morgan's 2014 paper: "XML Schema, DTD, and Entity Attacks"
|
||||
dbf.setXIncludeAware(false);
|
||||
dbf.setExpandEntityReferences(false);
|
||||
@ -476,7 +476,7 @@ public class RuleSetFactory {
|
||||
// an unsupported feature... too bad, but won't fail execution due to this
|
||||
LOG.log(Level.WARNING, "Ignored unsupported XML Parser Feature for parsing rulesets", e);
|
||||
}
|
||||
|
||||
|
||||
return dbf.newDocumentBuilder();
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,7 @@ public class RuleSetFactoryCompatibility {
|
||||
addFilterRuleMoved("java", "basic", "unnecessary", "UselessOperationOnImmutable");
|
||||
addFilterRuleMoved("java", "basic", "unnecessary", "UnusedNullCheckInEquals");
|
||||
addFilterRuleMoved("java", "basic", "unnecessary", "UselessParentheses");
|
||||
|
||||
|
||||
// PMD 5.6.0
|
||||
addFilterRuleRenamed("java", "design", "AvoidConstantsInterface", "ConstantsInInterface");
|
||||
// unused/UnusedModifier moved AND renamed, order is important!
|
||||
|
@ -258,7 +258,7 @@ public class RuleSets {
|
||||
/**
|
||||
* Retrieves a checksum of the rulesets being used. Any change to any rule
|
||||
* of any ruleset should trigger a checksum change.
|
||||
*
|
||||
*
|
||||
* @return The checksum for this ruleset collection.
|
||||
*/
|
||||
public long getChecksum() {
|
||||
|
@ -7,7 +7,7 @@ package net.sourceforge.pmd;
|
||||
/**
|
||||
* Marker interface for report listeners that, being thread-safe, need not
|
||||
* extra synchronization.
|
||||
*
|
||||
*
|
||||
* Thread-safety is required only for concurrently notifying about different files.
|
||||
* Same file violations are guaranteed to be reported serially.
|
||||
*/
|
||||
|
@ -23,16 +23,16 @@ import net.sourceforge.pmd.benchmark.TimeTracker.TimedResult;
|
||||
* @author Juan Martín Sotuyo Dodero
|
||||
*/
|
||||
public class TextTimingReportRenderer implements TimingReportRenderer {
|
||||
|
||||
|
||||
private static final String TIME_FORMAT = "{0,number,0.0000}";
|
||||
private static final String CUSTOM_COUNTER_FORMAT = "{0,number,###,###,###}";
|
||||
|
||||
|
||||
private static final int LABEL_COLUMN_WIDTH = 50;
|
||||
private static final int TIME_COLUMN_WIDTH = 12;
|
||||
private static final int SELF_TIME_COLUMN_WIDTH = 17;
|
||||
private static final int CALL_COLUMN_WIDTH = 9;
|
||||
private static final int COUNTER_COLUMN_WIDTH = 12;
|
||||
|
||||
|
||||
private static final int COLUMNS = LABEL_COLUMN_WIDTH + TIME_COLUMN_WIDTH
|
||||
+ SELF_TIME_COLUMN_WIDTH + CALL_COLUMN_WIDTH + COUNTER_COLUMN_WIDTH;
|
||||
|
||||
@ -44,63 +44,63 @@ public class TextTimingReportRenderer implements TimingReportRenderer {
|
||||
renderCategoryMeasurements(category, labeledMeasurements, writer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
renderHeader("Summary", writer);
|
||||
|
||||
|
||||
for (final TimedOperationCategory category : TimedOperationCategory.values()) {
|
||||
final TimedResult timedResult = report.getUnlabeledMeasurements(category);
|
||||
if (timedResult != null) {
|
||||
renderMeasurement(category.displayName(), timedResult, writer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
writer.write(PMD.EOL);
|
||||
renderHeader("Total", writer);
|
||||
|
||||
|
||||
writer.write(StringUtils.rightPad("Wall Clock Time", LABEL_COLUMN_WIDTH));
|
||||
final String wallClockTime = MessageFormat.format(TIME_FORMAT, report.getWallClockMillis() / 1000.0);
|
||||
writer.write(StringUtils.leftPad(wallClockTime, TIME_COLUMN_WIDTH));
|
||||
writer.write(PMD.EOL);
|
||||
|
||||
|
||||
writer.flush();
|
||||
}
|
||||
|
||||
private void renderMeasurement(final String label, final TimedResult timedResult,
|
||||
final Writer writer) throws IOException {
|
||||
writer.write(StringUtils.rightPad(label, LABEL_COLUMN_WIDTH));
|
||||
|
||||
|
||||
final String time = MessageFormat.format(TIME_FORMAT, timedResult.totalTimeNanos.get() / 1000000000.0);
|
||||
writer.write(StringUtils.leftPad(time, TIME_COLUMN_WIDTH));
|
||||
|
||||
|
||||
final String selfTime = MessageFormat.format(TIME_FORMAT, timedResult.selfTimeNanos.get() / 1000000000.0);
|
||||
writer.write(StringUtils.leftPad(selfTime, SELF_TIME_COLUMN_WIDTH));
|
||||
|
||||
|
||||
if (timedResult.callCount.get() > 0) {
|
||||
final String callCount = MessageFormat.format(CUSTOM_COUNTER_FORMAT, timedResult.callCount.get());
|
||||
writer.write(StringUtils.leftPad(callCount, CALL_COLUMN_WIDTH));
|
||||
|
||||
|
||||
if (timedResult.extraDataCounter.get() > 0) {
|
||||
final String counter = MessageFormat.format(CUSTOM_COUNTER_FORMAT, timedResult.extraDataCounter.get());
|
||||
writer.write(StringUtils.leftPad(counter, COUNTER_COLUMN_WIDTH));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
writer.write(PMD.EOL);
|
||||
}
|
||||
|
||||
private void renderCategoryMeasurements(final TimedOperationCategory category,
|
||||
final Map<String, TimedResult> labeledMeasurements, final Writer writer) throws IOException {
|
||||
renderHeader(category.displayName(), writer);
|
||||
|
||||
|
||||
final TimedResult grandTotal = new TimedResult();
|
||||
final Set<Entry<String, TimedResult>> sortedKeySet = new TreeSet<>(Comparator.comparingLong(o -> o.getValue().selfTimeNanos.get()));
|
||||
sortedKeySet.addAll(labeledMeasurements.entrySet());
|
||||
|
||||
|
||||
for (final Map.Entry<String, TimedResult> entry : sortedKeySet) {
|
||||
renderMeasurement(entry.getKey(), entry.getValue(), writer);
|
||||
grandTotal.mergeTimes(entry.getValue());
|
||||
}
|
||||
|
||||
|
||||
writer.write(PMD.EOL);
|
||||
renderMeasurement("Total " + category.displayName(), grandTotal, writer);
|
||||
writer.write(PMD.EOL);
|
||||
@ -109,23 +109,23 @@ public class TextTimingReportRenderer implements TimingReportRenderer {
|
||||
private void renderHeader(final String displayName, final Writer writer) throws IOException {
|
||||
final StringBuilder sb = new StringBuilder(COLUMNS)
|
||||
.append(displayName);
|
||||
|
||||
|
||||
// Make sure we have an even-length string
|
||||
if (displayName.length() % 2 == 1) {
|
||||
sb.append(' ');
|
||||
}
|
||||
|
||||
|
||||
// Surround with <<< and >>>
|
||||
sb.insert(0, "<<< ").append(" >>>");
|
||||
|
||||
|
||||
// Create the ruler
|
||||
while (sb.length() < COLUMNS) {
|
||||
sb.insert(0, '-').append('-');
|
||||
}
|
||||
|
||||
|
||||
writer.write(sb.toString());
|
||||
writer.write(PMD.EOL);
|
||||
|
||||
|
||||
// Write table titles
|
||||
writer.write(StringUtils.rightPad("Label", LABEL_COLUMN_WIDTH));
|
||||
writer.write(StringUtils.leftPad("Time (secs)", TIME_COLUMN_WIDTH));
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user