#1285 Prevent to modify the System environment
This commit is contained in:
@ -48,7 +48,6 @@ public class CPDConfiguration extends AbstractConfiguration {
|
|||||||
*/
|
*/
|
||||||
private Renderer renderer;
|
private Renderer renderer;
|
||||||
|
|
||||||
@Parameter(names = "--encoding", description = "Characterset to use when processing files", required = false)
|
|
||||||
private String encoding;
|
private String encoding;
|
||||||
|
|
||||||
@Parameter(names = "--ignore-literals", description = "Ignore number values and string contents when comparing text", required = false)
|
@Parameter(names = "--ignore-literals", description = "Ignore number values and string contents when comparing text", required = false)
|
||||||
@ -103,8 +102,10 @@ public class CPDConfiguration extends AbstractConfiguration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Parameter(names = "--encoding", description = "Characterset to use when processing files", required = false)
|
||||||
public void setEncoding(String encoding) {
|
public void setEncoding(String encoding) {
|
||||||
this.encoding = encoding;
|
this.encoding = encoding;
|
||||||
|
setSourceEncoding(encoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SourceCode sourceCodeFor(File file) {
|
public SourceCode sourceCodeFor(File file) {
|
||||||
@ -117,11 +118,6 @@ public class CPDConfiguration extends AbstractConfiguration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void postContruct() {
|
public void postContruct() {
|
||||||
if (getEncoding() != null) {
|
|
||||||
super.setSourceEncoding(getEncoding());
|
|
||||||
if (!getEncoding().equals(System.getProperty("file.encoding")))
|
|
||||||
System.setProperty("file.encoding", getEncoding());
|
|
||||||
}
|
|
||||||
if ( this.getLanguage() == null ) {
|
if ( this.getLanguage() == null ) {
|
||||||
this.setLanguage(CPDConfiguration.getLanguageFromString(DEFAULT_LANGUAGE));
|
this.setLanguage(CPDConfiguration.getLanguageFromString(DEFAULT_LANGUAGE));
|
||||||
}
|
}
|
||||||
@ -129,15 +125,15 @@ public class CPDConfiguration extends AbstractConfiguration {
|
|||||||
this.setRendererName(DEFAULT_RENDERER);
|
this.setRendererName(DEFAULT_RENDERER);
|
||||||
}
|
}
|
||||||
if ( this.getRenderer() == null ) {
|
if ( this.getRenderer() == null ) {
|
||||||
this.setRenderer(getRendererFromString(getRendererName()));
|
this.setRenderer(getRendererFromString(getRendererName(), this.getEncoding()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Renderer getRendererFromString(String name /* , String encoding */) {
|
public static Renderer getRendererFromString(String name, String encoding) {
|
||||||
if (name.equalsIgnoreCase(DEFAULT_RENDERER) || name.equals("")) {
|
if (name.equalsIgnoreCase(DEFAULT_RENDERER) || name.equals("")) {
|
||||||
return new SimpleRenderer();
|
return new SimpleRenderer();
|
||||||
} else if ("xml".equals(name)) {
|
} else if ("xml".equals(name)) {
|
||||||
return new XMLRenderer();
|
return new XMLRenderer(encoding);
|
||||||
} else if ("csv".equals(name)) {
|
} else if ("csv".equals(name)) {
|
||||||
return new CSVRenderer();
|
return new CSVRenderer();
|
||||||
} else if ("vs".equals(name)) {
|
} else if ("vs".equals(name)) {
|
||||||
@ -157,7 +153,7 @@ public class CPDConfiguration extends AbstractConfiguration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void setSystemProperties(CPDConfiguration configuration) {
|
public static void setSystemProperties(CPDConfiguration configuration) {
|
||||||
Properties properties = System.getProperties();
|
Properties properties = new Properties();
|
||||||
if (configuration.isIgnoreLiterals()) {
|
if (configuration.isIgnoreLiterals()) {
|
||||||
properties.setProperty(Tokenizer.IGNORE_LITERALS, "true");
|
properties.setProperty(Tokenizer.IGNORE_LITERALS, "true");
|
||||||
} else {
|
} else {
|
||||||
@ -173,7 +169,6 @@ public class CPDConfiguration extends AbstractConfiguration {
|
|||||||
} else {
|
} else {
|
||||||
properties.remove(Tokenizer.IGNORE_ANNOTATIONS);
|
properties.remove(Tokenizer.IGNORE_ANNOTATIONS);
|
||||||
}
|
}
|
||||||
System.setProperties(properties);
|
|
||||||
configuration.getLanguage().setProperties(properties);
|
configuration.getLanguage().setProperties(properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ public class CPDCommandLineInterfaceTest {
|
|||||||
runCPD("--minimum-tokens", "34", "--language", "java", "--files", "src/test/resources/net/sourceforge/pmd/cpd/clitest/", "--ignore-identifiers");
|
runCPD("--minimum-tokens", "34", "--language", "java", "--files", "src/test/resources/net/sourceforge/pmd/cpd/clitest/", "--ignore-identifiers");
|
||||||
|
|
||||||
String out = bufferStdout.toString("UTF-8");
|
String out = bufferStdout.toString("UTF-8");
|
||||||
Assert.assertTrue(out.contains("Found a 7 line (34 tokens) duplication"));
|
Assert.assertTrue(out.contains("Found a 7 line (36 tokens) duplication"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -84,6 +84,7 @@ public class CPDCommandLineInterfaceTest {
|
|||||||
|
|
||||||
String out = bufferStdout.toString("UTF-8");
|
String out = bufferStdout.toString("UTF-8");
|
||||||
Assert.assertTrue(out.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
|
Assert.assertTrue(out.startsWith("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
|
||||||
|
Assert.assertTrue(out.contains("System.out.println(i + \"ä\");"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
public class File1 {
|
public class File1 {
|
||||||
public void dup() {
|
public void dup() {
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
System.out.println(i);
|
System.out.println(i + "ä");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,7 +1,7 @@
|
|||||||
public class File2 {
|
public class File2 {
|
||||||
public void dup() {
|
public void dup() {
|
||||||
for (int j = 0; j < 10; j++) {
|
for (int j = 0; j < 10; j++) {
|
||||||
System.out.println(j);
|
System.out.println(j + "ä");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -15,3 +15,4 @@
|
|||||||
* [#1280](https://sourceforge.net/p/pmd/bugs/1280/): False Positive in UnusedImports when import used in javadoc
|
* [#1280](https://sourceforge.net/p/pmd/bugs/1280/): False Positive in UnusedImports when import used in javadoc
|
||||||
* [#1281](https://sourceforge.net/p/pmd/bugs/1281/): UnusedPrivateMethod incorrectly flagged for methods nested private classes
|
* [#1281](https://sourceforge.net/p/pmd/bugs/1281/): UnusedPrivateMethod incorrectly flagged for methods nested private classes
|
||||||
* [#1282](https://sourceforge.net/p/pmd/bugs/1282/): False Positive with implicit String.valuesOf() (Java)
|
* [#1282](https://sourceforge.net/p/pmd/bugs/1282/): False Positive with implicit String.valuesOf() (Java)
|
||||||
|
* [#1285](https://sourceforge.net/p/pmd/bugs/1285/): Prevent to modify the System environment
|
||||||
|
Reference in New Issue
Block a user