From b88b3de1f4235640a4b529ea4082b4338f5c0549 Mon Sep 17 00:00:00 2001 From: Stefan Seifert Date: Mon, 24 Feb 2025 12:20:53 +0100 Subject: [PATCH 1/5] [MCHANGES-466] Add parameter passRawText Update IT report-changes-generation to validate that HTML tags are escaped by default Add IT report-changes-generation-passRawText to validate the new behavior when enabling passRawText --- .../pom.xml | 107 ++++++++++++++++++ .../src/changes/changes.xml | 30 +++++ .../verify.groovy | 27 +++++ .../src/changes/changes.xml | 3 + .../report-changes-generation/verify.groovy | 3 + .../maven/plugins/changes/ChangesReport.java | 16 +++ .../changes/ChangesReportRenderer.java | 12 +- 7 files changed, 197 insertions(+), 1 deletion(-) create mode 100644 src/it/report-changes-generation-passRawText/pom.xml create mode 100644 src/it/report-changes-generation-passRawText/src/changes/changes.xml create mode 100644 src/it/report-changes-generation-passRawText/verify.groovy diff --git a/src/it/report-changes-generation-passRawText/pom.xml b/src/it/report-changes-generation-passRawText/pom.xml new file mode 100644 index 00000000..d210e2a4 --- /dev/null +++ b/src/it/report-changes-generation-passRawText/pom.xml @@ -0,0 +1,107 @@ + + + + + 4.0.0 + org.apache.maven.plugins + maven-changes-plugin-test + 99.0 + Maven + jar + Test report. + + + junit + junit + 3.8.1 + test + + + + jira + http://localhost/bla + + + @project.version@ + + + + + + org.apache.maven.plugins + maven-changes-plugin + ${changesPluginVersion} + + true + + + + + + + org.apache.maven.plugins + maven-changes-plugin + ${changesPluginVersion} + + + validate-changes + pre-site + + changes-validate + + + true + + + + + + org.apache.maven.plugins + maven-site-plugin + @sitePluginVersion@ + + + + + true + + + org.apache.maven.plugins + maven-changes-plugin + @project.version@ + + + http://myjira/browse/%ISSUE% + + + + + + changes + + + + + + + + diff --git a/src/it/report-changes-generation-passRawText/src/changes/changes.xml b/src/it/report-changes-generation-passRawText/src/changes/changes.xml new file mode 100644 index 00000000..c3740e7b --- /dev/null +++ b/src/it/report-changes-generation-passRawText/src/changes/changes.xml @@ -0,0 +1,30 @@ + + + + + + HTML tags are not escaped, but passed as raw text. + ]]> + + + \ No newline at end of file diff --git a/src/it/report-changes-generation-passRawText/verify.groovy b/src/it/report-changes-generation-passRawText/verify.groovy new file mode 100644 index 00000000..29894d88 --- /dev/null +++ b/src/it/report-changes-generation-passRawText/verify.groovy @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + + +def report = new File(basedir, 'target/site/changes.html') +assert report.exists() + +def content = report.text + +// HTML tags in action text are escaped, and not passed as raw text +assert content.contains('HTML tags are not escaped, but passed as raw text.') diff --git a/src/it/report-changes-generation/src/changes/changes.xml b/src/it/report-changes-generation/src/changes/changes.xml index 05f523b1..cbd5d5d0 100644 --- a/src/it/report-changes-generation/src/changes/changes.xml +++ b/src/it/report-changes-generation/src/changes/changes.xml @@ -49,6 +49,9 @@ under the License. Updated dependencies. No dev action + HTML tags are escaped and not passed as raw text. + ]]> diff --git a/src/it/report-changes-generation/verify.groovy b/src/it/report-changes-generation/verify.groovy index 669f6e4d..44a6976b 100644 --- a/src/it/report-changes-generation/verify.groovy +++ b/src/it/report-changes-generation/verify.groovy @@ -40,3 +40,6 @@ assert content.contains('Thanks to External Submitter,') assert content.contains('others') // no link to empty dev value assert content.contains('-') + +// HTML tags in action text are escaped, and not passed as raw text +assert content.contains('<strong>HTML tags</strong> are escaped and not passed as raw text.') diff --git a/src/main/java/org/apache/maven/plugins/changes/ChangesReport.java b/src/main/java/org/apache/maven/plugins/changes/ChangesReport.java index ba98d6b3..774772e9 100644 --- a/src/main/java/org/apache/maven/plugins/changes/ChangesReport.java +++ b/src/main/java/org/apache/maven/plugins/changes/ChangesReport.java @@ -75,6 +75,21 @@ public class ChangesReport extends AbstractChangesReport { @Parameter(property = "changes.addActionDate", defaultValue = "false") private boolean addActionDate; + /** + * Whether the changelog action text should be passed as raw text to Doxia for rendering the output or not. + * By default, the text is passed as escaped text to Doxia to support any output format like HTML, PDF, etc. + * If you want to produce only HTML output, and want to use HTML markup in the changelog (e.g. anchor links) + * set this parameter to false. + * + *

+ * Note: Only enable this paramter if you are only using this plugin to produce HTML output. + *

+ * + * @since 3.0 + */ + @Parameter + private boolean passRawText; + /** * The directory for interpolated changes.xml. * @@ -243,6 +258,7 @@ public void executeReport(Locale locale) throws MavenReportException { } report.setLinkToFeed(feedGenerated); + report.setPassRawText(passRawText); report.render(); diff --git a/src/main/java/org/apache/maven/plugins/changes/ChangesReportRenderer.java b/src/main/java/org/apache/maven/plugins/changes/ChangesReportRenderer.java index 555dddf5..bee1fefd 100644 --- a/src/main/java/org/apache/maven/plugins/changes/ChangesReportRenderer.java +++ b/src/main/java/org/apache/maven/plugins/changes/ChangesReportRenderer.java @@ -73,6 +73,8 @@ public class ChangesReportRenderer extends AbstractIssuesReportRenderer { private boolean linkToFeed; + private boolean passRawText; + public ChangesReportRenderer(Sink sink, ResourceBundle bundleName, ChangesXML changesXML) { super(sink, bundleName); this.issueLinksPerSystem = new HashMap<>(); @@ -106,6 +108,10 @@ public void setLinkToFeed(boolean generateLinkTofeed) { this.linkToFeed = generateLinkTofeed; } + public void setPassRawText(boolean passRawText) { + this.passRawText = passRawText; + } + /** * Checks whether links to the issues can be generated for the given system. * @@ -159,7 +165,11 @@ private void constructAction(Action action) { String actionDescription = action.getAction(); - text(actionDescription); + if (passRawText && StringUtils.isNotEmpty(actionDescription)) { + sink.rawText(actionDescription); + } else { + text(actionDescription); + } // no null check needed classes from modello return a new ArrayList if (StringUtils.isNotEmpty(action.getIssue()) From 458d9709415bc851ea58dabba47dc6979b03304f Mon Sep 17 00:00:00 2001 From: Stefan Seifert Date: Thu, 27 Feb 2025 09:09:02 +0100 Subject: [PATCH 2/5] [MCHANGES-466] Make javadoc more generic, as the parameter can be used as raw markup output for other formats as well --- .../org/apache/maven/plugins/changes/ChangesReport.java | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/main/java/org/apache/maven/plugins/changes/ChangesReport.java b/src/main/java/org/apache/maven/plugins/changes/ChangesReport.java index 774772e9..5ba6febc 100644 --- a/src/main/java/org/apache/maven/plugins/changes/ChangesReport.java +++ b/src/main/java/org/apache/maven/plugins/changes/ChangesReport.java @@ -76,14 +76,7 @@ public class ChangesReport extends AbstractChangesReport { private boolean addActionDate; /** - * Whether the changelog action text should be passed as raw text to Doxia for rendering the output or not. - * By default, the text is passed as escaped text to Doxia to support any output format like HTML, PDF, etc. - * If you want to produce only HTML output, and want to use HTML markup in the changelog (e.g. anchor links) - * set this parameter to false. - * - *

- * Note: Only enable this paramter if you are only using this plugin to produce HTML output. - *

+ * Whether the changelog action text should be passed as raw text to the Doxia sink or not. * * @since 3.0 */ From a6bab360b72d6bf50b2b297291455a78c91cf80c Mon Sep 17 00:00:00 2001 From: Stefan Seifert Date: Fri, 28 Feb 2025 14:53:58 +0100 Subject: [PATCH 3/5] [MCHANGES-466] add example in javadoc --- .../org/apache/maven/plugins/changes/ChangesReport.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/apache/maven/plugins/changes/ChangesReport.java b/src/main/java/org/apache/maven/plugins/changes/ChangesReport.java index 5ba6febc..5b95168e 100644 --- a/src/main/java/org/apache/maven/plugins/changes/ChangesReport.java +++ b/src/main/java/org/apache/maven/plugins/changes/ChangesReport.java @@ -76,7 +76,14 @@ public class ChangesReport extends AbstractChangesReport { private boolean addActionDate; /** - * Whether the changelog action text should be passed as raw text to the Doxia sink or not. + * Whether the change description should be passed as raw text to the Doxia sink or not. + * + *

+ * Example: If you are generating the changes report as HTML, and want HTML tags included in your changes XML + * (like <b>Bold</b>) to be interpreted correctly in the generated output, you have to set this + * parameter to true. You can use a <![CDATA[...]]> block in your changes XML to + * enclose descriptions with HTML tags. + *

* * @since 3.0 */ From 02db248ee33e94aef90d5ada4db692733f9ef958 Mon Sep 17 00:00:00 2001 From: Stefan Seifert Date: Wed, 5 Mar 2025 14:50:16 +0100 Subject: [PATCH 4/5] [MCHANGES-466] Replace parameter "passRawText" with "escapeText" --- .../pom.xml | 8 ++++---- .../src/changes/changes.xml | 0 .../verify.groovy | 0 .../apache/maven/plugins/changes/ChangesReport.java | 10 +++++----- .../maven/plugins/changes/ChangesReportRenderer.java | 12 ++++++------ 5 files changed, 15 insertions(+), 15 deletions(-) rename src/it/{report-changes-generation-passRawText => report-changes-generation-notEscapeText}/pom.xml (95%) rename src/it/{report-changes-generation-passRawText => report-changes-generation-notEscapeText}/src/changes/changes.xml (100%) rename src/it/{report-changes-generation-passRawText => report-changes-generation-notEscapeText}/verify.groovy (100%) diff --git a/src/it/report-changes-generation-passRawText/pom.xml b/src/it/report-changes-generation-notEscapeText/pom.xml similarity index 95% rename from src/it/report-changes-generation-passRawText/pom.xml rename to src/it/report-changes-generation-notEscapeText/pom.xml index d210e2a4..78ea18bc 100644 --- a/src/it/report-changes-generation-passRawText/pom.xml +++ b/src/it/report-changes-generation-notEscapeText/pom.xml @@ -51,11 +51,11 @@ maven-changes-plugin ${changesPluginVersion} - true - + false + - + org.apache.maven.plugins @@ -72,7 +72,7 @@ true - + org.apache.maven.plugins diff --git a/src/it/report-changes-generation-passRawText/src/changes/changes.xml b/src/it/report-changes-generation-notEscapeText/src/changes/changes.xml similarity index 100% rename from src/it/report-changes-generation-passRawText/src/changes/changes.xml rename to src/it/report-changes-generation-notEscapeText/src/changes/changes.xml diff --git a/src/it/report-changes-generation-passRawText/verify.groovy b/src/it/report-changes-generation-notEscapeText/verify.groovy similarity index 100% rename from src/it/report-changes-generation-passRawText/verify.groovy rename to src/it/report-changes-generation-notEscapeText/verify.groovy diff --git a/src/main/java/org/apache/maven/plugins/changes/ChangesReport.java b/src/main/java/org/apache/maven/plugins/changes/ChangesReport.java index 5b95168e..be3ea30b 100644 --- a/src/main/java/org/apache/maven/plugins/changes/ChangesReport.java +++ b/src/main/java/org/apache/maven/plugins/changes/ChangesReport.java @@ -76,19 +76,19 @@ public class ChangesReport extends AbstractChangesReport { private boolean addActionDate; /** - * Whether the change description should be passed as raw text to the Doxia sink or not. + * Whether the change description should be escaped (default), or passed as raw text to the report renderer. * *

* Example: If you are generating the changes report as HTML, and want HTML tags included in your changes XML * (like <b>Bold</b>) to be interpreted correctly in the generated output, you have to set this - * parameter to true. You can use a <![CDATA[...]]> block in your changes XML to + * parameter to false. You can use a <![CDATA[...]]> block in your changes XML to * enclose descriptions with HTML tags. *

* * @since 3.0 */ - @Parameter - private boolean passRawText; + @Parameter(defaultValue = "true") + private boolean escapeText; /** * The directory for interpolated changes.xml. @@ -258,7 +258,7 @@ public void executeReport(Locale locale) throws MavenReportException { } report.setLinkToFeed(feedGenerated); - report.setPassRawText(passRawText); + report.setEscapeText(escapeText); report.render(); diff --git a/src/main/java/org/apache/maven/plugins/changes/ChangesReportRenderer.java b/src/main/java/org/apache/maven/plugins/changes/ChangesReportRenderer.java index bee1fefd..95148f2e 100644 --- a/src/main/java/org/apache/maven/plugins/changes/ChangesReportRenderer.java +++ b/src/main/java/org/apache/maven/plugins/changes/ChangesReportRenderer.java @@ -73,7 +73,7 @@ public class ChangesReportRenderer extends AbstractIssuesReportRenderer { private boolean linkToFeed; - private boolean passRawText; + private boolean escapeText; public ChangesReportRenderer(Sink sink, ResourceBundle bundleName, ChangesXML changesXML) { super(sink, bundleName); @@ -108,8 +108,8 @@ public void setLinkToFeed(boolean generateLinkTofeed) { this.linkToFeed = generateLinkTofeed; } - public void setPassRawText(boolean passRawText) { - this.passRawText = passRawText; + public void setEscapeText(boolean escapeText) { + this.escapeText = escapeText; } /** @@ -165,10 +165,10 @@ private void constructAction(Action action) { String actionDescription = action.getAction(); - if (passRawText && StringUtils.isNotEmpty(actionDescription)) { - sink.rawText(actionDescription); - } else { + if (escapeText || StringUtils.isEmpty(actionDescription)) { text(actionDescription); + } else { + sink.rawText(actionDescription); } // no null check needed classes from modello return a new ArrayList From 8edc3f0f9ecb4252b54290e1ab08bfce891fae45 Mon Sep 17 00:00:00 2001 From: Stefan Seifert Date: Wed, 5 Mar 2025 17:10:12 +0100 Subject: [PATCH 5/5] [MCHANGES-466] update javadoc --- .../java/org/apache/maven/plugins/changes/ChangesReport.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/apache/maven/plugins/changes/ChangesReport.java b/src/main/java/org/apache/maven/plugins/changes/ChangesReport.java index be3ea30b..fba4028c 100644 --- a/src/main/java/org/apache/maven/plugins/changes/ChangesReport.java +++ b/src/main/java/org/apache/maven/plugins/changes/ChangesReport.java @@ -76,7 +76,7 @@ public class ChangesReport extends AbstractChangesReport { private boolean addActionDate; /** - * Whether the change description should be escaped (default), or passed as raw text to the report renderer. + * Whether the change description should be escaped (default), or passed as is to the report renderer. * *

* Example: If you are generating the changes report as HTML, and want HTML tags included in your changes XML