Merge pull request #4798 from adangel:textcolor-renderer
[core] TextColorRenderer: Remove property color #4798
This commit is contained in:
6 files changed
+110
-126
No files matched your search
@@ -254,10 +254,6 @@ Was expecting one of:
|
||||
* warnings: 2
|
||||
</pre>
|
||||
|
||||
**Properties:**
|
||||
|
||||
* color: Enables colors with anything other than `false` or `0`. Default: yes.
|
||||
|
||||
## textpad
|
||||
|
||||
TextPad integration.
|
||||
|
||||
@@ -167,6 +167,7 @@ The rules have been moved into categories with PMD 6.
|
||||
* core
|
||||
* [#1027](https://github.com/pmd/pmd/issues/1027): \[core] Apply the new PropertyDescriptor<Pattern> type where applicable
|
||||
* [#4065](https://github.com/pmd/pmd/issues/4065): \[core] Rename TokenMgrError to LexException, Tokenizer to CpdLexer
|
||||
* [#4312](https://github.com/pmd/pmd/issues/4312): \[core] Remove unnecessary property `color` and system property `pmd.color` in `TextColorRenderer`
|
||||
* [#4313](https://github.com/pmd/pmd/issues/4313): \[core] Remove support for <lang>-<ruleset> hyphen notation for ruleset references
|
||||
* [#4314](https://github.com/pmd/pmd/issues/4314): \[core] Remove ruleset compatibility filter (RuleSetFactoryCompatibility) and CLI option `--no-ruleset-compatibility`
|
||||
* [#4378](https://github.com/pmd/pmd/issues/4378): \[core] Ruleset loading processes commented rules
|
||||
@@ -289,6 +290,9 @@ The following previously deprecated classes have been removed:
|
||||
The different ways to enable/disable this filter in {% jdoc core::PMDConfiguration %}
|
||||
(Property "RuleSetFactoryCompatibilityEnabled") and
|
||||
{% jdoc ant::ant.PMDTask %} (Property "noRuleSetCompatibility") have been removed as well.
|
||||
* `textcolor` renderer ({%jdoc core::renderers.TextColorRenderer %}) now renders always in color.
|
||||
The property `color` has been removed. The possibility to override this with the system property `pmd.color`
|
||||
has been removed as well. If you don't want colors, use `text` renderer ({%jdoc core::renderers.TextRenderer %}).
|
||||
|
||||
#### External Contributions
|
||||
* [#4640](https://github.com/pmd/pmd/pull/4640): \[cli] Launch script fails if run via "bash pmd" - [Shai Bennathan](https://github.com/shai-bennathan) (@shai-bennathan)
|
||||
@@ -699,6 +703,7 @@ See also [Detailed Release Notes for PMD 7]({{ baseurl }}pmd_release_notes_pmd7.
|
||||
* [#4204](https://github.com/pmd/pmd/issues/4204): \[core] Provide a CpdAnalysis class as a programmatic entry point into CPD
|
||||
* [#4301](https://github.com/pmd/pmd/issues/4301): \[core] Remove deprecated property concrete classes
|
||||
* [#4302](https://github.com/pmd/pmd/issues/4302): \[core] Migrate Property Framework API to Java 8
|
||||
* [#4312](https://github.com/pmd/pmd/issues/4312): \[core] Remove unnecessary property `color` and system property `pmd.color` in `TextColorRenderer`
|
||||
* [#4313](https://github.com/pmd/pmd/issues/4313): \[core] Remove support for <lang>-<ruleset> hyphen notation for ruleset references
|
||||
* [#4314](https://github.com/pmd/pmd/issues/4314): \[core] Remove ruleset compatibility filter (RuleSetFactoryCompatibility) and CLI option `--no-ruleset-compatibility`
|
||||
* [#4323](https://github.com/pmd/pmd/issues/4323): \[core] Refactor CPD integration
|
||||
|
||||
@@ -20,12 +20,10 @@ import net.sourceforge.pmd.Report;
|
||||
import net.sourceforge.pmd.Report.ConfigurationError;
|
||||
import net.sourceforge.pmd.Report.ProcessingError;
|
||||
import net.sourceforge.pmd.RuleViolation;
|
||||
import net.sourceforge.pmd.properties.PropertyDescriptor;
|
||||
import net.sourceforge.pmd.properties.PropertyFactory;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* A console renderer with optional color support under *nix systems.
|
||||
* A console renderer with color support for terminal supporting ansi color codes.
|
||||
* </p>
|
||||
*
|
||||
* <pre>
|
||||
@@ -47,45 +45,29 @@ import net.sourceforge.pmd.properties.PropertyFactory;
|
||||
* code: logger.error( "missing attribute 'app_arg' in rule '" + ((Element)element.getParent()).getAttributeValue( "name" ) + "'" );
|
||||
* * warnings: 3
|
||||
* </pre>
|
||||
* <p>
|
||||
* Colorization is turned on by supplying -D<b>pmd.color</b> - any value other
|
||||
* than '0' or 'false', enables color - including an empty value (''). <b>Nota
|
||||
* Bene:</b> colorization is atm only supported under *nix terminals accepting
|
||||
* ansi escape sequences, such as xterm, rxvt et cetera.
|
||||
* </p>
|
||||
*/
|
||||
public class TextColorRenderer extends AbstractAccumulatingRenderer {
|
||||
|
||||
public static final String NAME = "textcolor";
|
||||
|
||||
// What? TODO 7.0.0 Use a boolean property
|
||||
// TODO should the "textcolor" renderer really support "optional" colors?
|
||||
// either use text or textcolor...
|
||||
// This property is really weird, the standard boolean properties
|
||||
// are false unless value is exactly "true", this one is true unless
|
||||
// "false" or "0"...
|
||||
public static final PropertyDescriptor<String> COLOR = PropertyFactory.stringProperty("color").desc("Enables colors with anything other than 'false' or '0'.").defaultValue("yes").build();
|
||||
private static final String SYSTEM_PROPERTY_PMD_COLOR = "pmd.color";
|
||||
|
||||
/**
|
||||
* Directory from where java was invoked.
|
||||
*/
|
||||
private String pwd;
|
||||
|
||||
private String yellowBold = "";
|
||||
private String whiteBold = "";
|
||||
private String redBold = "";
|
||||
private String red = "";
|
||||
private String cyan = "";
|
||||
private String green = "";
|
||||
private String yellowBold = "\u001B[1;33m";
|
||||
private String whiteBold = "\u001B[1;37m";
|
||||
private String redBold = "\u001B[1;31m";
|
||||
private String red = "\u001B[0;31m";
|
||||
private String green = "\u001B[0;32m";
|
||||
private String cyan = "\u001B[0;36m";
|
||||
|
||||
private String colorReset = "";
|
||||
private String colorReset = "\u001B[0m";
|
||||
|
||||
public TextColorRenderer() {
|
||||
// This Renderer was originally submitted by Adrian Papari and was
|
||||
// called the "PapariTextRenderer" pre-PMD 5.0.
|
||||
super(NAME, "Text format, with color support (requires ANSI console support, e.g. xterm, rxvt, etc.).");
|
||||
definePropertyDescriptor(COLOR);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -93,36 +75,10 @@ public class TextColorRenderer extends AbstractAccumulatingRenderer {
|
||||
return "txt";
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables colors on *nix systems - not windows. Color support depends on
|
||||
* the pmd.color property, which should be set with the -D option during
|
||||
* execution - a set value other than 'false' or '0' enables color.
|
||||
* <p/>
|
||||
* btw, is it possible to do this on windows (ie; console colors)?
|
||||
*/
|
||||
private void initializeColorsIfSupported() {
|
||||
if (isPropertyEnabled(getProperty(COLOR)) || isPropertyEnabled(System.getProperty(SYSTEM_PROPERTY_PMD_COLOR))) {
|
||||
this.yellowBold = "\u001B[1;33m";
|
||||
this.whiteBold = "\u001B[1;37m";
|
||||
this.redBold = "\u001B[1;31m";
|
||||
this.red = "\u001B[0;31m";
|
||||
this.green = "\u001B[0;32m";
|
||||
this.cyan = "\u001B[0;36m";
|
||||
|
||||
this.colorReset = "\u001B[0m";
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isPropertyEnabled(String property) {
|
||||
return property != null && !("0".equals(property) || "false".equalsIgnoreCase(property));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void outputReport(Report report) throws IOException {
|
||||
StringBuilder buf = new StringBuilder(500);
|
||||
buf.append(System.lineSeparator());
|
||||
initializeColorsIfSupported();
|
||||
String lastFile = null;
|
||||
int numberOfErrors = 0;
|
||||
int numberOfWarnings = 0;
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.renderers;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
|
||||
import net.sourceforge.pmd.Report.ConfigurationError;
|
||||
import net.sourceforge.pmd.Report.ProcessingError;
|
||||
|
||||
class PapariTextRendererTest extends AbstractRendererTest {
|
||||
|
||||
@Override
|
||||
Renderer getRenderer() {
|
||||
TextColorRenderer result = new TextColorRenderer() {
|
||||
@Override
|
||||
protected Reader getReader(String sourceFile) throws FileNotFoundException {
|
||||
return new StringReader("public class Foo {}");
|
||||
}
|
||||
};
|
||||
result.setProperty(TextColorRenderer.COLOR, "false");
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
String getExpected() {
|
||||
return "* file: " + getSourceCodeFilename() + EOL + " src: " + getSourceCodeFilename() + ":1:1" + EOL + " rule: Foo" + EOL
|
||||
+ " msg: blah" + EOL + " code: public class Foo {}" + EOL + EOL + EOL + EOL
|
||||
+ "Summary:" + EOL + EOL + "* warnings: 1" + EOL;
|
||||
}
|
||||
|
||||
@Override
|
||||
String getExpectedEmpty() {
|
||||
return EOL + EOL + "Summary:" + EOL + EOL + "* warnings: 0" + EOL;
|
||||
}
|
||||
|
||||
@Override
|
||||
String getExpectedMultiple() {
|
||||
return "* file: " + getSourceCodeFilename() + EOL + " src: " + getSourceCodeFilename() + ":1:1" + EOL + " rule: Foo" + EOL
|
||||
+ " msg: blah" + EOL + " code: public class Foo {}" + EOL + EOL + " src: "
|
||||
+ getSourceCodeFilename() + ":1:1" + EOL + " rule: Boo" + EOL + " msg: blah" + EOL
|
||||
+ " code: public class Foo {}" + EOL + EOL + EOL + EOL + "Summary:" + EOL
|
||||
+ EOL + "* warnings: 2" + EOL;
|
||||
}
|
||||
|
||||
@Override
|
||||
String getExpectedError(ProcessingError error) {
|
||||
return EOL + EOL + "Summary:" + EOL + EOL + "* file: file" + EOL + " err: RuntimeException: Error" + EOL
|
||||
+ error.getDetail() + EOL + EOL
|
||||
+ "* errors: 1" + EOL + "* warnings: 0" + EOL;
|
||||
}
|
||||
|
||||
@Override
|
||||
String getExpectedErrorWithoutMessage(ProcessingError error) {
|
||||
return EOL + EOL + "Summary:" + EOL + EOL + "* file: file" + EOL + " err: NullPointerException: null" + EOL
|
||||
+ error.getDetail() + EOL + EOL
|
||||
+ "* errors: 1" + EOL + "* warnings: 0" + EOL;
|
||||
}
|
||||
|
||||
@Override
|
||||
String getExpectedError(ConfigurationError error) {
|
||||
return EOL + EOL + "Summary:" + EOL + EOL + "* rule: Foo" + EOL
|
||||
+ " err: a configuration error" + EOL + EOL
|
||||
+ "* errors: 1" + EOL + "* warnings: 0" + EOL;
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ import org.junit.platform.suite.api.Suite;
|
||||
HTMLRendererTest.class,
|
||||
IDEAJRendererTest.class,
|
||||
JsonRendererTest.class,
|
||||
PapariTextRendererTest.class,
|
||||
TextColorRendererTest.class,
|
||||
SarifRendererTest.class,
|
||||
SummaryHTMLRendererTest.class,
|
||||
TextPadRendererTest.class,
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.renderers;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
|
||||
import net.sourceforge.pmd.Report.ConfigurationError;
|
||||
import net.sourceforge.pmd.Report.ProcessingError;
|
||||
|
||||
class TextColorRendererTest extends AbstractRendererTest {
|
||||
|
||||
@Override
|
||||
Renderer getRenderer() {
|
||||
TextColorRenderer result = new TextColorRenderer() {
|
||||
@Override
|
||||
protected Reader getReader(String sourceFile) throws FileNotFoundException {
|
||||
return new StringReader("public class Foo {}");
|
||||
}
|
||||
};
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
String getExpected() {
|
||||
return "\u001B[1;33m*\u001B[0m file: \u001B[1;37m" + getSourceCodeFilename() + "\u001B[0m" + EOL
|
||||
+ "\u001B[0;32m src: \u001B[0;36m" + getSourceCodeFilename() + "\u001B[0m:\u001B[0;36m1:1\u001B[0m" + EOL
|
||||
+ "\u001B[0;32m rule: \u001B[0mFoo" + EOL
|
||||
+ "\u001B[0;32m msg: \u001B[0mblah" + EOL
|
||||
+ "\u001B[0;32m code: \u001B[0mpublic class Foo {}" + EOL
|
||||
+ EOL
|
||||
+ EOL
|
||||
+ EOL
|
||||
+ "Summary:" + EOL
|
||||
+ EOL
|
||||
+ "\u001B[1;33m*\u001B[0m warnings: \u001B[1;37m1\u001B[0m" + EOL;
|
||||
}
|
||||
|
||||
@Override
|
||||
String getExpectedEmpty() {
|
||||
return EOL + EOL + "Summary:" + EOL + EOL + "\u001B[1;33m*\u001B[0m warnings: \u001B[1;37m0\u001B[0m" + EOL;
|
||||
}
|
||||
|
||||
@Override
|
||||
String getExpectedMultiple() {
|
||||
return "\u001B[1;33m*\u001B[0m file: \u001B[1;37m" + getSourceCodeFilename() + "\u001B[0m" + EOL
|
||||
+ "\u001B[0;32m src: \u001B[0;36m" + getSourceCodeFilename() + "\u001B[0m:\u001B[0;36m1:1\u001B[0m" + EOL
|
||||
+ "\u001B[0;32m rule: \u001B[0mFoo" + EOL
|
||||
+ "\u001B[0;32m msg: \u001B[0mblah" + EOL
|
||||
+ "\u001B[0;32m code: \u001B[0mpublic class Foo {}" + EOL
|
||||
+ "" + EOL
|
||||
+ "\u001B[0;32m src: \u001B[0;36m" + getSourceCodeFilename() + "\u001B[0m:\u001B[0;36m1:1\u001B[0m" + EOL
|
||||
+ "\u001B[0;32m rule: \u001B[0mBoo" + EOL
|
||||
+ "\u001B[0;32m msg: \u001B[0mblah" + EOL
|
||||
+ "\u001B[0;32m code: \u001B[0mpublic class Foo {}" + EOL
|
||||
+ EOL
|
||||
+ EOL
|
||||
+ EOL
|
||||
+ "Summary:" + EOL
|
||||
+ EOL
|
||||
+ "\u001B[1;33m*\u001B[0m warnings: \u001B[1;37m2\u001B[0m" + EOL;
|
||||
}
|
||||
|
||||
@Override
|
||||
String getExpectedError(ProcessingError error) {
|
||||
return EOL + EOL + "Summary:" + EOL + EOL + "\u001B[1;31m*\u001B[0m file: \u001B[1;37mfile\u001B[0m" + EOL
|
||||
+ "\u001B[0;32m err: \u001B[0;36mRuntimeException: Error\u001B[0m" + EOL
|
||||
+ "\u001B[0;31m" + error.getDetail() + "\u001B[0m" + EOL + EOL
|
||||
+ "\u001B[1;31m*\u001B[0m errors: \u001B[1;37m1\u001B[0m" + EOL
|
||||
+ "\u001B[1;33m*\u001B[0m warnings: \u001B[1;37m0\u001B[0m" + EOL;
|
||||
}
|
||||
|
||||
@Override
|
||||
String getExpectedErrorWithoutMessage(ProcessingError error) {
|
||||
return EOL + EOL + "Summary:" + EOL + EOL + "\u001B[1;31m*\u001B[0m file: \u001B[1;37mfile\u001B[0m" + EOL
|
||||
+ "\u001B[0;32m err: \u001B[0;36mNullPointerException: null\u001B[0m" + EOL
|
||||
+ "\u001B[0;31m" + error.getDetail() + "\u001B[0m" + EOL + EOL
|
||||
+ "\u001B[1;31m*\u001B[0m errors: \u001B[1;37m1\u001B[0m" + EOL
|
||||
+ "\u001B[1;33m*\u001B[0m warnings: \u001B[1;37m0\u001B[0m" + EOL;
|
||||
}
|
||||
|
||||
@Override
|
||||
String getExpectedError(ConfigurationError error) {
|
||||
return EOL + EOL
|
||||
+ "Summary:" + EOL
|
||||
+ EOL
|
||||
+ "\u001B[1;31m*\u001B[0m rule: \u001B[1;37mFoo\u001B[0m" + EOL
|
||||
+ "\u001B[0;32m err: \u001B[0;36ma configuration error\u001B[0m" + EOL
|
||||
+ EOL
|
||||
+ "\u001B[1;31m*\u001B[0m errors: \u001B[1;37m1\u001B[0m" + EOL
|
||||
+ "\u001B[1;33m*\u001B[0m warnings: \u001B[1;37m0\u001B[0m" + EOL;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user