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 6c18f731..f0fef47f 100644
--- a/src/main/java/org/apache/maven/report/projectinfo/MailingListsReport.java
+++ b/src/main/java/org/apache/maven/report/projectinfo/MailingListsReport.java
@@ -26,6 +26,7 @@
import org.codehaus.plexus.i18n.I18N;
import org.codehaus.plexus.util.StringUtils;
+import java.net.URI;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -169,7 +170,7 @@ public void renderBody()
if ( StringUtils.isNotEmpty( mailingList.getSubscribe() ) )
{
- textRow.add( createEmailLinkPatternedText( subscribe, mailingList.getSubscribe(), null ) );
+ textRow.add( createURILinkPatternedText( subscribe, mailingList.getSubscribe(), null ) );
}
else
{
@@ -178,7 +179,7 @@ public void renderBody()
if ( StringUtils.isNotEmpty( mailingList.getUnsubscribe() ) )
{
- textRow.add( createEmailLinkPatternedText( unsubscribe, mailingList.getUnsubscribe(), null ) );
+ textRow.add( createURILinkPatternedText( unsubscribe, mailingList.getUnsubscribe(), null ) );
}
else
{
@@ -187,7 +188,7 @@ public void renderBody()
if ( StringUtils.isNotEmpty( mailingList.getPost() ) )
{
- textRow.add( createEmailLinkPatternedText( post, mailingList.getPost(), null ) );
+ textRow.add( createURILinkPatternedText( post, mailingList.getPost(), null ) );
}
else
{
@@ -262,23 +263,31 @@ public void renderBody()
}
/**
- * Create a link pattern text for email addresses defined by {text, mailto:href}
. If href is null,
- * then defaultHref
is used instead.
+ * Create a URI link pattern text for a mailing list. If no scheme is provided {@code mailto:}
+ * will be prepended by default. If href is null, then defaultHref
is used instead.
*
* @param text a text.
- * @param href the email address to use.
+ * @param href the potential URI to use.
* @param defaultHref the String to use in case href is null.
- * @return an email link pattern.
+ * @return a link pattern.
* @see #createLinkPatternedText(String,String)
*/
- private String createEmailLinkPatternedText( String text, String href, String defaultHref )
+ private String createURILinkPatternedText( String text, String href, String defaultHref )
{
if ( href == null || href.isEmpty() )
{
return createLinkPatternedText( text, defaultHref );
}
- return createLinkPatternedText( text,
- href.toLowerCase( Locale.ENGLISH ).startsWith( "mailto:" ) ? href : "mailto:" + href );
+
+ URI hrefUri = URI.create( href );
+ if ( StringUtils.isNotEmpty( hrefUri.getScheme() ) )
+ {
+ return createLinkPatternedText( text, href );
+ }
+ else
+ {
+ return createLinkPatternedText( text, "mailto:" + href );
+ }
}
}
}
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 f8237f9d..3437f88f 100644
--- a/src/test/java/org/apache/maven/report/projectinfo/MailingListsReportTest.java
+++ b/src/test/java/org/apache/maven/report/projectinfo/MailingListsReportTest.java
@@ -25,6 +25,7 @@
import com.meterware.httpunit.GetMethodWebRequest;
import com.meterware.httpunit.TextBlock;
import com.meterware.httpunit.WebConversation;
+import com.meterware.httpunit.WebLink;
import com.meterware.httpunit.WebRequest;
import com.meterware.httpunit.WebResponse;
@@ -73,13 +74,19 @@ public void testReport()
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:'
+ // MPIR-385 + MPIR-401: Test links are URIs otherwise assume a plain email address
String post = getString("report.mailing-lists.column.post");
- assertEquals( "mailto:test@maven.apache.org", response.getLinkWith( post ).getAttribute( "href" ) );
+ WebLink[] postLinks = response.getMatchingLinks( WebLink.MATCH_CONTAINED_TEXT, post );
+ assertEquals( "mailto:test@maven.apache.org", postLinks[0].getAttribute( "href" ) );
+ assertEquals( "mailto:test2@maven.apache.org", postLinks[1].getAttribute( "href" ) );
String subscribe = getString("report.mailing-lists.column.subscribe");
- assertEquals( "MAILTO:test-subscribe@maven.apache.org", response.getLinkWith( subscribe ).getAttribute( "href" ) );
+ WebLink[] subscribeLinks = response.getMatchingLinks( WebLink.MATCH_CONTAINED_TEXT, subscribe );
+ assertEquals( "MAILTO:test-subscribe@maven.apache.org", subscribeLinks[0].getAttribute( "href" ) );
+ assertEquals( "MAILTO:test-subscribe2@maven.apache.org", subscribeLinks[1].getAttribute( "href" ) );
String unsubscribe = getString("report.mailing-lists.column.unsubscribe");
- assertNull( response.getLinkWith( unsubscribe ) );
+ WebLink[] unsubscribeLinks = response.getMatchingLinks( WebLink.MATCH_CONTAINED_TEXT, unsubscribe );
+ assertTrue( unsubscribeLinks.length == 1 );
+ assertEquals( "https://example.com/unsubscribe", unsubscribeLinks[0].getAttribute( "href" ) );
}
/**
diff --git a/src/test/resources/plugin-configs/mailing-lists-plugin-config.xml b/src/test/resources/plugin-configs/mailing-lists-plugin-config.xml
index 036a99ab..2cd6e45b 100644
--- a/src/test/resources/plugin-configs/mailing-lists-plugin-config.xml
+++ b/src/test/resources/plugin-configs/mailing-lists-plugin-config.xml
@@ -38,6 +38,12 @@ under the License.
test@maven.apache.org
MAILTO:test-subscribe@maven.apache.org
+
+ Test List 2
+ test2@maven.apache.org
+ MAILTO:test-subscribe2@maven.apache.org
+ https://example.com/unsubscribe
+
@@ -51,4 +57,4 @@ under the License.
-
\ No newline at end of file
+