Package net.sourceforge.pmd.cpd
Class CpdAnalysis
java.lang.Object
net.sourceforge.pmd.cpd.CpdAnalysis
- All Implemented Interfaces:
AutoCloseable
Main programmatic API of CPD. This is not a CLI entry point, see module
pmd-cli for that.
Usage overview
Create and configure a CPDConfiguration, then use create(CPDConfiguration) to
obtain an instance. You can perform additional configuration on the instance, e.g. adding
files to process or add a listener. Then call performAnalysis() or performAnalysis(Consumer)
in order to get the report directly.
Simple example
CPDConfiguration config = new CPDConfiguration();
config.setMinimumTileSize(100);
config.setOnlyRecognizeLanguage(config.getLanguageRegistry().getLanguageById("java"));
config.setSourceEncoding(StandardCharsets.UTF_8);
config.addInputPath(Path.of("src/main/java")
config.setIgnoreAnnotations(true);
config.setIgnoreLiterals(false);
config.setRendererName("text");
try (CpdAnalysis cpd = CpdAnalysis.create(config)) {
// note: don't use `config` once a CpdAnalysis has been created.
// optional: add more files
cpd.files().addFile(Paths.get("src", "main", "more-java", "ExtraSource.java"));
cpd.performAnalysis();
}
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()static CpdAnalysiscreate(CPDConfiguration config) Create a new instance from the given configuration.files()voidvoidperformAnalysis(Consumer<CPDReport> consumer) voidsetCpdListener(@Nullable CPDListener cpdListener)
-
Method Details
-
create
Create a new instance from the given configuration. The configuration should not be modified after this.- Parameters:
config- Configuration- Returns:
- A new analysis instance
-
files
-
setCpdListener
-
performAnalysis
public void performAnalysis() -
performAnalysis
-
close
- Specified by:
closein interfaceAutoCloseable- Throws:
IOException
-