You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sj...@apache.org on 2025/05/11 08:31:55 UTC

(maven-changes-plugin) branch master updated: [MCHANGES-466] Add parameter escapeText (#113)

This is an automated email from the ASF dual-hosted git repository.

sjaranowski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-changes-plugin.git


The following commit(s) were added to refs/heads/master by this push:
     new f44830a  [MCHANGES-466] Add parameter escapeText (#113)
f44830a is described below

commit f44830aa4698c9504fa5fdbf25d58026f7df3089
Author: Stefan Seifert <st...@users.noreply.github.com>
AuthorDate: Sun May 11 10:31:51 2025 +0200

    [MCHANGES-466] Add parameter escapeText (#113)
    
    * [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
    
    * [MCHANGES-466] Make javadoc more generic, as the parameter can be used as raw markup output for other formats as well
    
    * [MCHANGES-466] add example in javadoc
    
    * [MCHANGES-466] Replace parameter "passRawText" with "escapeText"
    
    * [MCHANGES-466] update javadoc
    
    ---------
    
    Co-authored-by: Stefan Seifert <stefanseifertusers.noreply.github.com>
---
 .../pom.xml                                        | 107 +++++++++++++++++++++
 .../src/changes/changes.xml                        |  30 ++++++
 .../verify.groovy                                  |  27 ++++++
 .../src/changes/changes.xml                        |   3 +
 src/it/report-changes-generation/verify.groovy     |   3 +
 .../maven/plugins/changes/ChangesReport.java       |  16 +++
 .../plugins/changes/ChangesReportRenderer.java     |  12 ++-
 7 files changed, 197 insertions(+), 1 deletion(-)

diff --git a/src/it/report-changes-generation-notEscapeText/pom.xml b/src/it/report-changes-generation-notEscapeText/pom.xml
new file mode 100644
index 0000000..78ea18b
--- /dev/null
+++ b/src/it/report-changes-generation-notEscapeText/pom.xml
@@ -0,0 +1,107 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.maven.plugins</groupId>
+  <artifactId>maven-changes-plugin-test</artifactId>
+  <version>99.0</version>
+  <name>Maven</name>
+  <packaging>jar</packaging>
+  <description>Test report.</description>
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+  <issueManagement>
+    <system>jira</system>
+    <url>http://localhost/bla</url>
+  </issueManagement>
+  <properties>
+    <changesPluginVersion>@project.version@</changesPluginVersion>
+  </properties>
+  <build>
+    <pluginManagement>
+      <plugins>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-changes-plugin</artifactId>
+          <version>${changesPluginVersion}</version>
+          <configuration>
+            <escapeText>false</escapeText>
+          </configuration>
+        </plugin>
+      </plugins>
+    </pluginManagement>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-changes-plugin</artifactId>
+        <version>${changesPluginVersion}</version>   
+        <executions>
+          <execution>
+            <id>validate-changes</id>
+            <phase>pre-site</phase>
+            <goals>
+              <goal>changes-validate</goal>
+            </goals>
+            <configuration>
+              <failOnError>true</failOnError>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-site-plugin</artifactId>
+        <version>@sitePluginVersion@</version>
+      </plugin>      
+    </plugins>
+  </build>  
+  <reporting>
+    <excludeDefaults>true</excludeDefaults>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-changes-plugin</artifactId>
+        <version>@project.version@</version>
+        <configuration>
+          <issueLinkTemplatePerSystem>
+            <jira>http://myjira/browse/%ISSUE%</jira>
+          </issueLinkTemplatePerSystem>
+        </configuration>
+        <reportSets>
+          <reportSet>
+            <reports>
+              <report>changes</report>
+            </reports>
+          </reportSet>
+        </reportSets>
+      </plugin>
+    </plugins>
+  </reporting>
+  
+</project>
diff --git a/src/it/report-changes-generation-notEscapeText/src/changes/changes.xml b/src/it/report-changes-generation-notEscapeText/src/changes/changes.xml
new file mode 100644
index 0000000..c3740e7
--- /dev/null
+++ b/src/it/report-changes-generation-notEscapeText/src/changes/changes.xml
@@ -0,0 +1,30 @@
+<!--
+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.
+-->
+
+<document xmlns="http://maven.apache.org/changes/2.0.0"
+          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+          xsi:schemaLocation="http://maven.apache.org/changes/2.0.0 http://maven.apache.org/xsd/changes-2.0.0.xsd">
+  <body>
+    <release version="1.1" date="2005-03-01" description="Subsequent release">
+      <action type="update"><![CDATA[
+        <strong>HTML tags</strong> are not escaped, but passed as raw text.
+      ]]></action>
+    </release>
+  </body>
+</document>
\ No newline at end of file
diff --git a/src/it/report-changes-generation-notEscapeText/verify.groovy b/src/it/report-changes-generation-notEscapeText/verify.groovy
new file mode 100644
index 0000000..29894d8
--- /dev/null
+++ b/src/it/report-changes-generation-notEscapeText/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('<strong>HTML tags</strong> 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 05f523b..cbd5d5d 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.
       </action>
       <action type="update">No dev action</action>
+      <action type="update"><![CDATA[
+        <strong>HTML tags</strong> are escaped and not passed as raw text.
+      ]]></action>
     </release>
 
     <release version="1.0" date="2005-01-01" description="First release">
diff --git a/src/it/report-changes-generation/verify.groovy b/src/it/report-changes-generation/verify.groovy
index 669f6e4..44a6976 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('<a class="externalLink" href="mailto:others@users.com">others</a>')
 // no link to empty dev value
 assert content.contains('<td>-</td></tr>')
+
+// HTML tags in action text are escaped, and not passed as raw text
+assert content.contains('&lt;strong&gt;HTML tags&lt;/strong&gt; 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 6531dd4..eff5a0b 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 change description should be escaped (default), or passed as is to the report renderer.
+     *
+     * <p>
+     * <i>Example</i>: If you are generating the changes report as HTML, and want HTML tags included in your changes XML
+     * (like <code>&lt;b&gt;Bold&lt;/b&gt;</code>) to be interpreted correctly in the generated output, you have to set this
+     * parameter to <code>false</code>. You can use a <code>&lt;![CDATA[...]]&gt;</code> block in your changes XML to
+     * enclose descriptions with HTML tags.
+     * </p>
+     *
+     * @since 3.0
+     */
+    @Parameter(defaultValue = "true")
+    private boolean escapeText;
+
     /**
      * The directory for interpolated changes.xml.
      *
@@ -243,6 +258,7 @@ public class ChangesReport extends AbstractChangesReport {
         }
 
         report.setLinkToFeed(feedGenerated);
+        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 555dddf..95148f2 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 escapeText;
+
     public ChangesReportRenderer(Sink sink, ResourceBundle bundleName, ChangesXML changesXML) {
         super(sink, bundleName);
         this.issueLinksPerSystem = new HashMap<>();
@@ -106,6 +108,10 @@ public class ChangesReportRenderer extends AbstractIssuesReportRenderer {
         this.linkToFeed = generateLinkTofeed;
     }
 
+    public void setEscapeText(boolean escapeText) {
+        this.escapeText = escapeText;
+    }
+
     /**
      * Checks whether links to the issues can be generated for the given system.
      *
@@ -159,7 +165,11 @@ public class ChangesReportRenderer extends AbstractIssuesReportRenderer {
 
         String actionDescription = action.getAction();
 
-        text(actionDescription);
+        if (escapeText || StringUtils.isEmpty(actionDescription)) {
+            text(actionDescription);
+        } else {
+            sink.rawText(actionDescription);
+        }
 
         // no null check needed classes from modello return a new ArrayList
         if (StringUtils.isNotEmpty(action.getIssue())