diff --git a/docs/pages/pmd/userdocs/cpd/cpd.md b/docs/pages/pmd/userdocs/cpd/cpd.md index fc93959c4d..ce9a36471b 100644 --- a/docs/pages/pmd/userdocs/cpd/cpd.md +++ b/docs/pages/pmd/userdocs/cpd/cpd.md @@ -290,7 +290,7 @@ to be "debug". ## Available report formats * text : Default format -* xml +* xml (and xslt) * csv * csv_with_linecount_per_file * vs @@ -404,6 +404,8 @@ the CPD task as usual and right after it invoke the Ant XSLT script like this: ``` +See [section "xslt" in CPD Report Formats](pmd_userdocs_cpd_report_formats.html#xslt) for more examples. + ## GUI CPD also comes with a simple GUI. You can start it through the unified CLI interface provided in the `bin` folder: diff --git a/docs/pages/pmd/userdocs/cpd/cpd_report_formats.md b/docs/pages/pmd/userdocs/cpd/cpd_report_formats.md index f21bd5b448..7ba812383b 100644 --- a/docs/pages/pmd/userdocs/cpd/cpd_report_formats.md +++ b/docs/pages/pmd/userdocs/cpd/cpd_report_formats.md @@ -95,6 +95,7 @@ Starting at line 110 of /home/pmd/source/pmd-core/src/test/java/net/sourceforge/ ## xml This format uses XML to output the duplications in a more structured format. +The XML format can then further be processed using XSLT transformations. See [section xslt](#xslt) for examples. Example: @@ -220,3 +221,41 @@ Example: /home/pmd/source/pmd-core/src/test/java/net/sourceforge/pmd/lang/rule/xpath/JaxenXPathRuleQueryTest.java(88): Between lines 88 and 104 /home/pmd/source/pmd-core/src/test/java/net/sourceforge/pmd/lang/rule/xpath/JaxenXPathRuleQueryTest.java(110): Between lines 110 and 126 ``` + +## xslt + +This is not a direct report format. But you can use `xml` to generate an XML report and then use one of the following +XSLT stylesheets to convert the report into html. Or you can write your own stylesheet. + +You can either use [Ant's XSLT task](https://ant.apache.org/manual/Tasks/style.html) or use any other (CLI) xslt processor, +e.g. `xalan` (see ). + +### cpdhtml.xslt + +This stylesheet is available in the sources or from GitHub at: . + +```shell +xalan -in cpd-report-sample.xml -xsl cpdhtml.xslt -out cpd-report-sample-cpdhtml.html +``` + +[Example](report-examples/cpdhtml.html) + +This stylesheet by default only consideres duplications longer than 30 lines. You can change the default value with +the param `lines`: + +```shell +xalan -in cpd-report-sample.xml -xsl cpdhtml.xslt -out cpd-report-sample-cpdhtml.html -param lines 10 +``` + +### cpdhtml-v2.xslt + +This stylesheet is available in the sources or from GitHub at: . + +```shell +xalan -in pmd-core-cpd-report.xml -xsl etc/xslt/cpdhtml-v2.xslt -out pmd-core-cpd-report-v2.html +``` + +[Example](report-examples/cpdhtml-v2.html) + +It requires javascript enabled and uses [Bootstrap](https://getbootstrap.com/), +[jQuery](https://jquery.com/), and [DataTables](https://datatables.net/). diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index d5609e8ff0..40a27a2f68 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -39,6 +39,13 @@ for all.

This section lists the most important changes from the last release candidate. The remaining section describes the complete release notes for 7.0.0. +#### New CPD report format cpdhtml-v2.xslt + +Thanks to @mohan-chinnappan-n a new CPD report format has been added which features a data table. +It uses an XSLT stylesheet to convert CPD's XML format into HTML. + +See [the example report]({{ baseurl }}report-examples/cpdhtml-v2.html). + #### Fixed issues * java-codestyle @@ -58,6 +65,7 @@ The remaining section describes the complete release notes for 7.0.0. #### External Contributions +* [#4426](https://github.com/pmd/pmd/pull/4426): \[cpd] New XML to HTML XLST report format for PMD CPD - [mohan-chinnappan-n](https://github.com/mohan-chinnappan-n) (@mohan-chinnappan-n) * [#4540](https://github.com/pmd/pmd/pull/4540): \[java] Fix #4457: false negative about OverrideBothEqualsAndHashcode - [AnnaDev](https://github.com/LynnBroe) (@LynnBroe) ### 🚀 Major Features and Enhancements @@ -114,6 +122,13 @@ Contributors: [Lucas Soncini](https://github.com/lsoncini) (@lsoncini), This PMD release ships a new version of the pmd-designer. For the changes, see [PMD Designer Changelog](https://github.com/pmd/pmd-designer/releases/tag/7.0.0-rc1). +#### New CPD report format cpdhtml-v2.xslt + +Thanks to @mohan-chinnappan-n a new CPD report format has been added which features a data table. +It uses an XSLT stylesheet to convert CPD's XML format into HTML. + +See [the example report]({{ baseurl }}report-examples/cpdhtml-v2.html). + ### 🎉 Language Related Changes Note that this is just a concise listing of the highlight. @@ -554,6 +569,7 @@ Language specific fixes: * [#4402](https://github.com/pmd/pmd/pull/4402): \[javascript] CPD: add support for Typescript using antlr4 grammar - [Paul Guyot](https://github.com/pguyot) (@pguyot) * [#4403](https://github.com/pmd/pmd/pull/4403): \[julia] CPD: Add support for Julia code duplication - [Wener](https://github.com/wener-tiobe) (@wener-tiobe) * [#4412](https://github.com/pmd/pmd/pull/4412): \[doc] Added new error msg to ConstantsInInterface - [David Ljunggren](https://github.com/dague1) (@dague1) +* [#4426](https://github.com/pmd/pmd/pull/4426): \[cpd] New XML to HTML XLST report format for PMD CPD - [mohan-chinnappan-n](https://github.com/mohan-chinnappan-n) (@mohan-chinnappan-n) * [#4428](https://github.com/pmd/pmd/pull/4428): \[apex] ApexBadCrypto bug fix for #4427 - inline detection of hard coded values - [Steven Stearns](https://github.com/sfdcsteve) (@sfdcsteve) * [#4444](https://github.com/pmd/pmd/pull/4444): \[java] CommentDefaultAccessModifier - ignore org.junit.jupiter.api.extension.RegisterExtension by default - [Nirvik Patel](https://github.com/nirvikpatel) (@nirvikpatel) * [#4450](https://github.com/pmd/pmd/pull/4450): \[java] Fix #4449 AvoidAccessibilityAlteration: Correctly handle Lambda expressions in PrivilegedAction scenarios - [Seren](https://github.com/mohui1999) (@mohui1999) diff --git a/docs/pages/release_notes_pmd7.md b/docs/pages/release_notes_pmd7.md index eb8463d2a1..76df0bb2a0 100644 --- a/docs/pages/release_notes_pmd7.md +++ b/docs/pages/release_notes_pmd7.md @@ -446,6 +446,13 @@ Contributors: [Lucas Soncini](https://github.com/lsoncini) (@lsoncini), This PMD release ships a new version of the pmd-designer. For the changes, see [PMD Designer Changelog](https://github.com/pmd/pmd-designer/releases/tag/7.0.0-rc1). +#### New CPD report format cpdhtml-v2.xslt + +Thanks to @mohan-chinnappan-n a new CPD report format has been added which features a data table. +It uses an XSLT stylesheet to convert CPD's XML format into HTML. + +See [the example report](report-examples/cpdhtml-v2.html). + ## 🎉 Language Related Changes ### New: Swift support diff --git a/docs/report-examples/cpdhtml-v2.html b/docs/report-examples/cpdhtml-v2.html new file mode 100644 index 0000000000..0e3b43baf5 --- /dev/null +++ b/docs/report-examples/cpdhtml-v2.html @@ -0,0 +1,175 @@ + + + + + + + + + + + + +
+
+
+

Summary of duplicated code

+

This page summarizes the code fragments that have been found to be replicated in the code.

+ + + + + + + +
# DuplicationsTotal linesTotal tokensApproximate number of bytes
2493491396
+
+
+
+
+

Details of duplicated code

+
+ + + + + + + + + + + + + + +
linestokensfilescodefragment
33239 + + + + + + + + + + +
columnendcolumnlineendlinepath
29753264/home/pmd/source/pmd-core/src/test/java/net/sourceforge/pmd/RuleReferenceTest.java
377568100/home/pmd/source/pmd-core/src/test/java/net/sourceforge/pmd/RuleReferenceTest.java
+
+
    public void testOverride() {
+        final StringProperty PROPERTY1_DESCRIPTOR = new StringProperty("property1", "Test property", null, 0f);
+        MockRule rule = new MockRule();
+        rule.definePropertyDescriptor(PROPERTY1_DESCRIPTOR);
+        rule.setLanguage(LanguageRegistry.getLanguage(Dummy2LanguageModule.NAME));
+        rule.setName("name1");
+        rule.setProperty(PROPERTY1_DESCRIPTOR, "value1");
+        rule.setMessage("message1");
+        rule.setDescription("description1");
+        rule.addExample("example1");
+        rule.setExternalInfoUrl("externalInfoUrl1");
+        rule.setPriority(RulePriority.HIGH);
+
+        final StringProperty PROPERTY2_DESCRIPTOR = new StringProperty("property2", "Test property", null, 0f);
+        RuleReference ruleReference = new RuleReference();
+        ruleReference.setRule(rule);
+        ruleReference.definePropertyDescriptor(PROPERTY2_DESCRIPTOR);
+        ruleReference.setLanguage(LanguageRegistry.getLanguage(DummyLanguageModule.NAME));
+        ruleReference
+                .setMinimumLanguageVersion(LanguageRegistry.getLanguage(DummyLanguageModule.NAME).getVersion("1.3"));
+        ruleReference
+                .setMaximumLanguageVersion(LanguageRegistry.getLanguage(DummyLanguageModule.NAME).getVersion("1.7"));
+        ruleReference.setDeprecated(true);
+        ruleReference.setName("name2");
+        ruleReference.setProperty(PROPERTY1_DESCRIPTOR, "value2");
+        ruleReference.setProperty(PROPERTY2_DESCRIPTOR, "value3");
+        ruleReference.setMessage("message2");
+        ruleReference.setDescription("description2");
+        ruleReference.addExample("example2");
+        ruleReference.setExternalInfoUrl("externalInfoUrl2");
+        ruleReference.setPriority(RulePriority.MEDIUM_HIGH);
+
+        validateOverriddenValues(PROPERTY1_DESCRIPTOR, PROPERTY2_DESCRIPTOR, ruleReference);
+
16110 + + + + + + + + + + + + + +
columnendcolumnlineendlinepath
9286681/home/pmd/source/pmd-core/src/test/java/net/sourceforge/pmd/lang/rule/xpath/JaxenXPathRuleQueryTest.java
92888103/home/pmd/source/pmd-core/src/test/java/net/sourceforge/pmd/lang/rule/xpath/JaxenXPathRuleQueryTest.java
928110125/home/pmd/source/pmd-core/src/test/java/net/sourceforge/pmd/lang/rule/xpath/JaxenXPathRuleQueryTest.java
+
+
        JaxenXPathRuleQuery query = createQuery(xpath);
+        List<String> ruleChainVisits = query.getRuleChainVisits();
+        Assert.assertEquals(2, ruleChainVisits.size());
+        Assert.assertTrue(ruleChainVisits.contains("dummyNode"));
+        // Note: Having AST_ROOT in the rule chain visits is probably a mistake. But it doesn't hurt, it shouldn't
+        // match a real node name.
+        Assert.assertTrue(ruleChainVisits.contains(JaxenXPathRuleQuery.AST_ROOT));
+
+        DummyNodeWithListAndEnum dummy = new DummyNodeWithListAndEnum(1);
+        RuleContext data = new RuleContext();
+        data.setLanguageVersion(LanguageRegistry.findLanguageByTerseName("dummy").getDefaultVersion());
+
+        query.evaluate(dummy, data);
+        // note: the actual xpath queries are only available after evaluating
+        Assert.assertEquals(2, query.nodeNameToXPaths.size());
+        Assert.assertEquals("self::node()[(attribute::Test1 = \"false\")][(attribute::Test2 = \"true\")]", query.nodeNameToXPaths.get("dummyNode").get(0).toString());
+
+
+
+ + + diff --git a/docs/report-examples/cpdhtml.html b/docs/report-examples/cpdhtml.html new file mode 100644 index 0000000000..7cc527c602 --- /dev/null +++ b/docs/report-examples/cpdhtml.html @@ -0,0 +1,111 @@ + + + + + + + + + +

Summary of duplicated code

+ This page summarizes the code fragments that have been found to be replicated in the code. + Only those fragments longer than 30 lines of code are shown. +

+ + + + + + + +
# duplicationsTotal linesTotal tokensApprox # bytes
133239956
+

+ You expand and collapse the code fragments using the + buttons. You can also navigate to the source code by clicking + on the file names. +

+ + + + + + + + + + + + + +
IDFilesLines
1 + + + + + + + +
/home/pmd/source/pmd-core/src/test/java/net/sourceforge/pmd/RuleReferenceTest.java line 32
/home/pmd/source/pmd-core/src/test/java/net/sourceforge/pmd/RuleReferenceTest.java line 68
+
# lines : 33
+ + + + +
+
+
+
+ + diff --git a/pmd-core/etc/xslt/cpdhtml-v2.xslt b/pmd-core/etc/xslt/cpdhtml-v2.xslt new file mode 100644 index 0000000000..c1862d9cba --- /dev/null +++ b/pmd-core/etc/xslt/cpdhtml-v2.xslt @@ -0,0 +1,160 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
columnendcolumnlineendlinepath
+ +
+ +
+
+ +
diff --git a/pmd-core/etc/xslt/cpdhtml.xslt b/pmd-core/etc/xslt/cpdhtml.xslt index e298e17cdf..ef6e9ac94f 100644 --- a/pmd-core/etc/xslt/cpdhtml.xslt +++ b/pmd-core/etc/xslt/cpdhtml.xslt @@ -1,13 +1,14 @@ - + - + +30 + -