You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sl...@apache.org on 2019/12/15 23:56:59 UTC

[maven-project-info-reports-plugin] 01/01: [MPIR-385] - Emails in mailing list section of pom are improperly handled

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

slachiewicz pushed a commit to branch MPIR-385
in repository https://gitbox.apache.org/repos/asf/maven-project-info-reports-plugin.git

commit a15271a904bc768b50ea751e0b363cfa042289f3
Author: Sylwester Lachiewicz <sl...@apache.org>
AuthorDate: Mon Dec 16 00:55:02 2019 +0100

    [MPIR-385] - Emails in mailing list section of pom are improperly handled
    
    
    
    - Corrected the generated link for emails in the mailing-list report.
    - Added asserts in the testReport() UT to avoid future regressions.
    Corrected as it was not showing exactly the same output than before when the emails were null.
    
    Factored out method createEmailLinkPatternedText() to render email links with a default value.
---
 .../report/projectinfo/MailingListsReport.java     | 32 +++++++++++++++-------
 .../report/projectinfo/MailingListsReportTest.java |  8 ++++++
 2 files changed, 30 insertions(+), 10 deletions(-)

diff --git a/src/main/java/org/apache/maven/report/projectinfo/MailingListsReport.java b/src/main/java/org/apache/maven/report/projectinfo/MailingListsReport.java
index 1b6411b..39b415f 100644
--- a/src/main/java/org/apache/maven/report/projectinfo/MailingListsReport.java
+++ b/src/main/java/org/apache/maven/report/projectinfo/MailingListsReport.java
@@ -161,18 +161,11 @@ public class MailingListsReport
                 // Validate here subsribe/unsubsribe lists and archives?
                 textRow.add( mailingList.getName() );
 
-                textRow.add( createLinkPatternedText( subscribe, mailingList.getSubscribe() ) );
+                textRow.add( createEmailLinkPatternedText( subscribe, mailingList.getSubscribe(), null ) );
 
-                textRow.add( createLinkPatternedText( unsubscribe, mailingList.getUnsubscribe() ) );
+                textRow.add( createEmailLinkPatternedText( unsubscribe, mailingList.getUnsubscribe(), null ) );
 
-                if ( mailingList.getPost() != null && mailingList.getPost().length() > 0 )
-                {
-                    textRow.add( createLinkPatternedText( post, mailingList.getPost() ) );
-                }
-                else
-                {
-                    textRow.add( "-" );
-                }
+                textRow.add( createEmailLinkPatternedText( post, mailingList.getPost(), "-" ) );
 
                 if ( mailingList.getArchive() != null && mailingList.getArchive().length() > 0 )
                 {
@@ -239,6 +232,25 @@ public class MailingListsReport
         }
 
         /**
+         * Create a link pattern text for email addresses defined by <code>{text, mailto:href}</code>. If href is null,
+         * then <code>defaultHref</code> is used instead.
+         *
+         * @param text a text.
+         * @param href the email address to use.
+         * @param defaultHref the String to use in case href is null.
+         * @return an email link pattern.
+         * @see #createLinkPatternedText(String,String)
+         */
+        private String createEmailLinkPatternedText( String text, String href, String defaultHref )
+        {
+            if ( href == null || href.isEmpty() )
+            {
+                return createLinkPatternedText( text, defaultHref );
+            }
+            return createLinkPatternedText( text, "mailto:" + href );
+        }
+
+        /**
          * Convenience method to return the name of a web-based mailing list archive server. <br>
          * For instance, if the archive uri is <code>http://www.mail-archive.com/dev@maven.apache.org</code>, this
          * method return <code>www.mail-archive.com</code>
diff --git a/src/test/java/org/apache/maven/report/projectinfo/MailingListsReportTest.java b/src/test/java/org/apache/maven/report/projectinfo/MailingListsReportTest.java
index 27dd5c5..112eb06 100644
--- a/src/test/java/org/apache/maven/report/projectinfo/MailingListsReportTest.java
+++ b/src/test/java/org/apache/maven/report/projectinfo/MailingListsReportTest.java
@@ -76,6 +76,14 @@ public class MailingListsReportTest
         TextBlock[] textBlocks = response.getTextBlocks();
         assertEquals( getString( "report.mailing-lists.title" ), textBlocks[0].getText() );
         assertEquals( getString( "report.mailing-lists.intro" ), textBlocks[1].getText() );
+
+        // MPIR-385: Test emails starts with 'mailto:'
+        String post = getString("report.mailing-lists.column.post");
+        assertEquals( "mailto:test@maven.apache.org", response.getLinkWith( post ).getAttribute( "href" ) );
+        String subscribe = getString("report.mailing-lists.column.subscribe");
+        assertEquals( "mailto:test-subscribe@maven.apache.org", response.getLinkWith( subscribe ).getAttribute( "href" ) );
+        String unsubscribe = getString("report.mailing-lists.column.unsubscribe");
+        assertNull( response.getLinkWith( unsubscribe ) );
     }
 
     /**