Package net.sourceforge.pmd.cpd
Class CpdAnalysis
- java.lang.Object
-
- net.sourceforge.pmd.cpd.CpdAnalysis
-
- All Implemented Interfaces:
AutoCloseable
public final class CpdAnalysis extends Object implements AutoCloseable
Main programmatic API of CPD. This is not a CLI entry point, see modulepmd-cli
for that.Usage overview
Create and configure a
CPDConfiguration
, then usecreate(CPDConfiguration)
to obtain an instance. You can perform additional configuration on the instance, e.g. adding files to process or add a listener. Then callperformAnalysis()
orperformAnalysis(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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
static CpdAnalysis
create(CPDConfiguration config)
Create a new instance from the given configuration.FileCollector
files()
void
performAnalysis()
void
performAnalysis(Consumer<CPDReport> consumer)
void
setCpdListener(@Nullable CPDListener cpdListener)
-
-
-
Method Detail
-
create
public static CpdAnalysis create(CPDConfiguration config)
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
public FileCollector files()
-
setCpdListener
public void setCpdListener(@Nullable CPDListener cpdListener)
-
performAnalysis
public void performAnalysis()
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Throws:
IOException
-
-