[ 
https://issues.apache.org/jira/browse/MPMD-379?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17843504#comment-17843504
 ] 

ASF GitHub Bot commented on MPMD-379:
-------------------------------------

michael-o commented on code in PR #144:
URL: https://github.com/apache/maven-pmd-plugin/pull/144#discussion_r1590128034


##########
src/main/java/org/apache/maven/plugins/pmd/exec/CpdExecutor.java:
##########
@@ -155,46 +149,50 @@ private CpdResult run() throws MavenReportException {
 
         CPDConfiguration cpdConfiguration = new CPDConfiguration();
         cpdConfiguration.setMinimumTileSize(request.getMinimumTokens());
+        cpdConfiguration.setIgnoreAnnotations(request.isIgnoreAnnotations());
+        cpdConfiguration.setIgnoreLiterals(request.isIgnoreLiterals());
+        cpdConfiguration.setIgnoreIdentifiers(request.isIgnoreIdentifiers());
 
-        Language cpdLanguage;
-        if ("java".equals(request.getLanguage()) || null == 
request.getLanguage()) {
-            cpdLanguage = new JavaLanguage(request.getLanguageProperties());
-        } else if ("javascript".equals(request.getLanguage())) {
-            cpdLanguage = new EcmascriptLanguage();
-        } else if ("jsp".equals(request.getLanguage())) {
-            cpdLanguage = new JSPLanguage();
-        } else {
-            cpdLanguage = 
LanguageFactory.createLanguage(request.getLanguage(), 
request.getLanguageProperties());
+        String languageId = request.getLanguage();
+        if ("javascript".equals(languageId)) {
+            languageId = "ecmascript";
+        } else if (languageId == null) {
+            languageId = "java"; // default
         }
+        Language cpdLanguage = 
cpdConfiguration.getLanguageRegistry().getLanguageById(languageId);
 
-        cpdConfiguration.setLanguage(cpdLanguage);
-        cpdConfiguration.setSourceEncoding(request.getSourceEncoding());
+        cpdConfiguration.setOnlyRecognizeLanguage(cpdLanguage);
+        
cpdConfiguration.setSourceEncoding(Charset.forName(request.getSourceEncoding()));
 
-        CPD cpd = new CPD(cpdConfiguration);
-        try {
-            cpd.add(request.getFiles());
-        } catch (IOException e) {
-            throw new MavenReportException(e.getMessage(), e);
-        }
+        request.getFiles().forEach(f -> 
cpdConfiguration.addInputPath(f.toPath()));
 
         LOG.debug("Executing CPD...");
-        cpd.go();
-        LOG.debug("CPD finished.");
 
         // always create XML format. we need to output it even if the file 
list is empty or we have no duplications
         // so the "check" goals can check for violations
-        writeXmlReport(cpd);
+        try (CpdAnalysis cpd = CpdAnalysis.create(cpdConfiguration)) {
+            cpd.performAnalysis(report -> {
+                try {
+                    writeXmlReport(report);
 
-        // html format is handled by maven site report, xml format has already 
been rendered
-        String format = request.getFormat();
-        if (!"html".equals(format) && !"xml".equals(format)) {
-            writeFormattedReport(cpd);
+                    // html format is handled by maven site report, xml format 
has already been rendered
+                    String format = request.getFormat();
+                    if (!"html".equals(format) && !"xml".equals(format)) {
+                        writeFormattedReport(report);
+                    }
+                } catch (MavenReportException e) {
+                    LOG.error("Error while writing CPD report", e);
+                }
+            });
+        } catch (IOException e) {
+            LOG.error("Error while executing CPD", e);

Review Comment:
   This is a bad change 

> Upgrade to use PMD 7.0.0 by default
> -----------------------------------
>
>                 Key: MPMD-379
>                 URL: https://issues.apache.org/jira/browse/MPMD-379
>             Project: Maven PMD Plugin
>          Issue Type: Improvement
>          Components: CPD, PMD
>            Reporter: Andreas Dangel
>            Assignee: Andreas Dangel
>            Priority: Major
>             Fix For: 3.22.0
>
>
> Add support for the new major version of PMD.
> This gives support for analyzing Java 21 code.
> The upgrade from PMD 6 to PMD 7 is a major upgrade, that might impact 
> end-users, if they use custom rulesets (see 
> [https://maven.apache.org/plugins/maven-pmd-plugin/examples/usingRuleSets.html])
>  or if they override the dependencies to upgrade PMD at runtime and currently 
> use PMD 6.x (see 
> [https://maven.apache.org/plugins/maven-pmd-plugin/examples/upgrading-PMD-at-runtime.html]).
>  
> Most likely, end-users have to review their rulesets and migrate them to PMD 
> 7. Rules might have been renamed or replaced. See 
> [https://docs.pmd-code.org/latest/pmd_release_notes_pmd7.html] and 
> [https://docs.pmd-code.org/latest/pmd_userdocs_migrating_to_pmd7.html] .
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to