forked from phoedos/pmd
pmd: fix #1114 CPD - Tokenizer not initialized with requested properties
This commit is contained in:
@ -1,3 +1,8 @@
|
|||||||
|
????? ??, 2013 - 5.0.5:
|
||||||
|
|
||||||
|
Fixed bug 1114: CPD - Tokenizer not initialized with requested properties
|
||||||
|
|
||||||
|
|
||||||
May 1, 2013 - 5.0.4:
|
May 1, 2013 - 5.0.4:
|
||||||
|
|
||||||
Fixed bug 254: False+ : UnusedImport with Javadoc @throws
|
Fixed bug 254: False+ : UnusedImport with Javadoc @throws
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package net.sourceforge.pmd.cpd;
|
package net.sourceforge.pmd.cpd;
|
||||||
|
|
||||||
import java.io.FilenameFilter;
|
import java.io.FilenameFilter;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
import net.sourceforge.pmd.util.filter.Filters;
|
import net.sourceforge.pmd.util.filter.Filters;
|
||||||
|
|
||||||
@ -20,4 +21,8 @@ public abstract class AbstractLanguage implements Language {
|
|||||||
public Tokenizer getTokenizer() {
|
public Tokenizer getTokenizer() {
|
||||||
return tokenizer;
|
return tokenizer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setProperties(Properties properties) {
|
||||||
|
// needs to be implemented by subclasses.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,8 @@ public class CPD {
|
|||||||
private static final int MISSING_ARGS = 2;
|
private static final int MISSING_ARGS = 2;
|
||||||
private static final int DUPLICATE_CODE_FOUND = 4;
|
private static final int DUPLICATE_CODE_FOUND = 4;
|
||||||
|
|
||||||
|
static boolean dontExitForTests = false;
|
||||||
|
|
||||||
private CPDConfiguration configuration;
|
private CPDConfiguration configuration;
|
||||||
|
|
||||||
private Map<String, SourceCode> source = new TreeMap<String, SourceCode>();
|
private Map<String, SourceCode> source = new TreeMap<String, SourceCode>();
|
||||||
@ -111,7 +113,7 @@ public class CPD {
|
|||||||
source.put(sourceCode.getFileName(), sourceCode);
|
source.put(sourceCode.getFileName(), sourceCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setSystemProperties(String[] args) {
|
private static void setSystemProperties(String[] args, CPDConfiguration config) {
|
||||||
boolean ignoreLiterals = CPDConfiguration.findBooleanSwitch(args, "--ignore-literals");
|
boolean ignoreLiterals = CPDConfiguration.findBooleanSwitch(args, "--ignore-literals");
|
||||||
boolean ignoreIdentifiers = CPDConfiguration.findBooleanSwitch(args, "--ignore-identifiers");
|
boolean ignoreIdentifiers = CPDConfiguration.findBooleanSwitch(args, "--ignore-identifiers");
|
||||||
boolean ignoreAnnotations = CPDConfiguration.findBooleanSwitch(args, "--ignore-annotations");
|
boolean ignoreAnnotations = CPDConfiguration.findBooleanSwitch(args, "--ignore-annotations");
|
||||||
@ -126,6 +128,7 @@ public class CPD {
|
|||||||
properties.setProperty(JavaTokenizer.IGNORE_ANNOTATIONS, "true");
|
properties.setProperty(JavaTokenizer.IGNORE_ANNOTATIONS, "true");
|
||||||
}
|
}
|
||||||
System.setProperties(properties);
|
System.setProperties(properties);
|
||||||
|
config.language().setProperties(properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
@ -139,7 +142,7 @@ public class CPD {
|
|||||||
|
|
||||||
// Pass extra parameters as System properties to allow language
|
// Pass extra parameters as System properties to allow language
|
||||||
// implementation to retrieve their associate values...
|
// implementation to retrieve their associate values...
|
||||||
setSystemProperties(args);
|
setSystemProperties(args, config);
|
||||||
|
|
||||||
CPD cpd = new CPD(config);
|
CPD cpd = new CPD(config);
|
||||||
|
|
||||||
@ -163,7 +166,9 @@ public class CPD {
|
|||||||
cpd.go();
|
cpd.go();
|
||||||
if (cpd.getMatches().hasNext()) {
|
if (cpd.getMatches().hasNext()) {
|
||||||
System.out.println(config.renderer().render(cpd.getMatches()));
|
System.out.println(config.renderer().render(cpd.getMatches()));
|
||||||
System.exit(DUPLICATE_CODE_FOUND);
|
if (!dontExitForTests) {
|
||||||
|
System.exit(DUPLICATE_CODE_FOUND);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -12,7 +12,11 @@ public class JavaLanguage extends AbstractLanguage {
|
|||||||
|
|
||||||
public JavaLanguage(Properties properties) {
|
public JavaLanguage(Properties properties) {
|
||||||
super(new JavaTokenizer(), ".java");
|
super(new JavaTokenizer(), ".java");
|
||||||
JavaTokenizer tokenizer = (JavaTokenizer)getTokenizer();
|
setProperties(properties);
|
||||||
tokenizer.setProperties(properties);
|
}
|
||||||
|
|
||||||
|
public final void setProperties(Properties properties) {
|
||||||
|
JavaTokenizer tokenizer = (JavaTokenizer)getTokenizer();
|
||||||
|
tokenizer.setProperties(properties);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,10 +4,13 @@
|
|||||||
package net.sourceforge.pmd.cpd;
|
package net.sourceforge.pmd.cpd;
|
||||||
|
|
||||||
import java.io.FilenameFilter;
|
import java.io.FilenameFilter;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
public interface Language {
|
public interface Language {
|
||||||
|
|
||||||
Tokenizer getTokenizer();
|
Tokenizer getTokenizer();
|
||||||
|
|
||||||
FilenameFilter getFileFilter();
|
FilenameFilter getFileFilter();
|
||||||
|
|
||||||
|
void setProperties(Properties properties);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,51 @@
|
|||||||
|
/**
|
||||||
|
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||||
|
*/
|
||||||
|
package net.sourceforge.pmd.cpd;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.PrintStream;
|
||||||
|
|
||||||
|
import junit.framework.Assert;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unit test for {@link CPDCommandLineInterface}.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class CPDCommandLineInterfaceTest {
|
||||||
|
private ByteArrayOutputStream buffer;
|
||||||
|
private PrintStream originalStdout;
|
||||||
|
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup() {
|
||||||
|
originalStdout = System.out;
|
||||||
|
buffer = new ByteArrayOutputStream();
|
||||||
|
System.setOut(new PrintStream(buffer));
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void teardown() {
|
||||||
|
System.setOut(originalStdout);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test ignore identifiers argument.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testIgnoreIdentifiers() throws Exception {
|
||||||
|
runCPD("--minimum-tokens", "34", "--language", "java", "--files", "src/test/resources/net/sourceforge/pmd/cpd/clitest/", "--ignore-identifiers");
|
||||||
|
|
||||||
|
String out = buffer.toString("UTF-8");
|
||||||
|
Assert.assertTrue(out.contains("Found a 7 line (34 tokens) duplication"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void runCPD(String... args) {
|
||||||
|
CPD.dontExitForTests = true;
|
||||||
|
CPD.main(args);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
public class File1 {
|
||||||
|
public void dup() {
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
System.out.println(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
public class File2 {
|
||||||
|
public void dup() {
|
||||||
|
for (int j = 0; j < 10; j++) {
|
||||||
|
System.out.println(j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user