From 113668f15faccd5543f9cbad97a2b1c9ef7543da Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Fri, 5 Jun 2020 11:13:26 +0200 Subject: [PATCH] [MPIR-393] Cleanup getArchiveServer --- pom.xml | 6 --- .../projectinfo/MailingListsReport.java | 48 +++---------------- .../projectinfo/ProjectInfoReportUtils.java | 18 +++++++ .../projectinfo/MailingListsReportTest.java | 39 --------------- .../ProjectInfoReportUtilsTest.java | 27 +++++++++++ 5 files changed, 52 insertions(+), 86 deletions(-) diff --git a/pom.xml b/pom.xml index 26ab65cb..ecb186c9 100644 --- a/pom.xml +++ b/pom.xml @@ -371,12 +371,6 @@ under the License. 2.28.2 test - - junit-addons - junit-addons - 1.4 - test - org.mortbay.jetty jetty 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 1e516ccc..5c3336eb 100644 --- a/src/main/java/org/apache/maven/report/projectinfo/MailingListsReport.java +++ b/src/main/java/org/apache/maven/report/projectinfo/MailingListsReport.java @@ -24,7 +24,6 @@ import org.apache.maven.model.Model; import org.apache.maven.plugins.annotations.Mojo; import org.codehaus.plexus.i18n.I18N; -import org.codehaus.plexus.util.StringUtils; import java.util.ArrayList; import java.util.Iterator; @@ -169,8 +168,9 @@ public void renderBody() if ( mailingList.getArchive() != null && mailingList.getArchive().length() > 0 ) { - textRow.add( createLinkPatternedText( getArchiveServer( mailingList.getArchive() ), - mailingList.getArchive() ) ); + textRow.add( createLinkPatternedText( + ProjectInfoReportUtils.getArchiveServer( mailingList.getArchive() ), + mailingList.getArchive() ) ); } else { @@ -183,7 +183,8 @@ public void renderBody() Iterator it = mailingList.getOtherArchives().iterator(); String otherArchive = it.next(); - textRow.add( createLinkPatternedText( getArchiveServer( otherArchive ), otherArchive ) ); + textRow.add( createLinkPatternedText( + ProjectInfoReportUtils.getArchiveServer( otherArchive ), otherArchive ) ); tableRow( textRow.toArray( new String[textRow.size()] ) ); @@ -210,7 +211,8 @@ public void renderBody() // Archive textRow.add( " " ); - textRow.add( createLinkPatternedText( getArchiveServer( otherArchive ), otherArchive ) ); + textRow.add( createLinkPatternedText( + ProjectInfoReportUtils.getArchiveServer( otherArchive ), otherArchive ) ); tableRow( textRow.toArray( new String[textRow.size()] ) ); } @@ -250,41 +252,5 @@ private String createEmailLinkPatternedText( String text, String href, String de return createLinkPatternedText( text, href.toLowerCase( Locale.ENGLISH ).startsWith( "mailto:" ) ? href : "mailto:" + href ); } - - /** - * Convenience method to return the name of a web-based mailing list archive server.
- * For instance, if the archive uri is http://www.mail-archive.com/dev@maven.apache.org, this - * method return www.mail-archive.com - * - * @param uri - * @return the server name of a web-based mailing list archive server - */ - private static String getArchiveServer( String uri ) - { - if ( StringUtils.isEmpty( uri ) ) - { - return "???UNKNOWN???"; - } - - int at = uri.indexOf( "//" ); - int fromIndex; - if ( at >= 0 ) - { - fromIndex = uri.lastIndexOf( '/', at - 1 ) >= 0 ? 0 : at + 2; - } - else - { - fromIndex = 0; - } - - int from = uri.indexOf( '/', fromIndex ); - - if ( from == -1 ) - { - return uri.substring( at + 2 ); - } - - return uri.substring( at + 2, from ); - } } } diff --git a/src/main/java/org/apache/maven/report/projectinfo/ProjectInfoReportUtils.java b/src/main/java/org/apache/maven/report/projectinfo/ProjectInfoReportUtils.java index 3cb22b95..d1c6bd9e 100644 --- a/src/main/java/org/apache/maven/report/projectinfo/ProjectInfoReportUtils.java +++ b/src/main/java/org/apache/maven/report/projectinfo/ProjectInfoReportUtils.java @@ -23,6 +23,7 @@ import java.io.InputStream; import java.net.Authenticator; import java.net.PasswordAuthentication; +import java.net.URI; import java.net.URL; import java.net.URLConnection; import java.security.KeyManagementException; @@ -276,6 +277,23 @@ public static boolean isArtifactUrlValid( String url ) return URL_VALIDATOR.isValid( url ); } + /** + * Convenience method to return the name of a web-based mailing list archive server. + * For instance, if the archive URI is http://www.mail-archive.com/dev@maven.apache.org, this + * method returns www.mail-archive.com + * + * @param uri the URI parse + * @return the server host of a web-based mailing list archive server + */ + public static String getArchiveServer( String uri ) + { + if ( uri == null ) + { + return "???UNKNOWN???"; + } + return URI.create( uri ).getHost(); + } + /** * @param url not null * @param project not null 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 2c47857f..f8237f9d 100644 --- a/src/test/java/org/apache/maven/report/projectinfo/MailingListsReportTest.java +++ b/src/test/java/org/apache/maven/report/projectinfo/MailingListsReportTest.java @@ -22,10 +22,6 @@ import java.net.URL; import java.util.Locale; -import org.apache.maven.report.projectinfo.MailingListsReport.MailingListsRenderer; - -import junitx.util.PrivateAccessor; - import com.meterware.httpunit.GetMethodWebRequest; import com.meterware.httpunit.TextBlock; import com.meterware.httpunit.WebConversation; @@ -108,39 +104,4 @@ public void testFrenchReport() Locale.setDefault( oldLocale ); } } - - /** - * @throws Throwable if any - */ - public void testGetArchiveServer() - throws Throwable - { - String server = "http://mail-archives.apache.org/mod_mbox/maven-announce/"; - assertEquals( "mail-archives.apache.org", invokeGetArchiveServer( server ) ); - - server = "http://mail-archives.apache.org/mod_mbox/maven-announce"; - assertEquals( "mail-archives.apache.org", invokeGetArchiveServer( server ) ); - - server = "http://www.mail-archive.com/announce@maven.apache.org"; - assertEquals( "www.mail-archive.com", invokeGetArchiveServer( server ) ); - - server = "http://www.nabble.com/Maven-Announcements-f15617.html"; - assertEquals( "www.nabble.com", invokeGetArchiveServer( server ) ); - - server = "http://maven.announce.markmail.org/"; - assertEquals( "maven.announce.markmail.org", invokeGetArchiveServer( server ) ); - - server = "http://maven.announce.markmail.org"; - assertEquals( "maven.announce.markmail.org", invokeGetArchiveServer( server ) ); - } - - /** - * @throws Throwable if any - */ - private static String invokeGetArchiveServer( String s ) - throws Throwable - { - return (String) PrivateAccessor.invoke( MailingListsRenderer.class, "getArchiveServer", - new Class[] { String.class }, new Object[] { s } ); - } } diff --git a/src/test/java/org/apache/maven/report/projectinfo/ProjectInfoReportUtilsTest.java b/src/test/java/org/apache/maven/report/projectinfo/ProjectInfoReportUtilsTest.java index 03c71b92..822897b7 100644 --- a/src/test/java/org/apache/maven/report/projectinfo/ProjectInfoReportUtilsTest.java +++ b/src/test/java/org/apache/maven/report/projectinfo/ProjectInfoReportUtilsTest.java @@ -43,6 +43,8 @@ import org.mortbay.jetty.security.SslSocketConnector; import org.mortbay.jetty.webapp.WebAppContext; +import static org.apache.maven.report.projectinfo.ProjectInfoReportUtils.getArchiveServer; + /** * @author Vincent Siveton * @version $Id$ @@ -191,6 +193,31 @@ public void testGetInputStreamURL() // TODO need to test with a proxy } + public void testGetArchiveServer() + { + assertEquals( "???UNKNOWN???", getArchiveServer( null ) ); + + assertNull( getArchiveServer( "" ) ); + + assertEquals( "mail-archives.apache.org", + getArchiveServer( "http://mail-archives.apache.org/mod_mbox/maven-announce/" ) ); + + assertEquals( "mail-archives.apache.org", + getArchiveServer( "https://mail-archives.apache.org/mod_mbox/maven-announce/" ) ); + + assertEquals( "mail-archives.apache.org", + getArchiveServer( "http://mail-archives.apache.org/mod_mbox/maven-announce" ) ); + + assertEquals( "www.mail-archive.com", + getArchiveServer( "http://www.mail-archive.com/announce@maven.apache.org" ) ); + + assertEquals( "www.nabble.com", getArchiveServer( "http://www.nabble.com/Maven-Announcements-f15617.html" ) ); + + assertEquals( "maven.announce.markmail.org", getArchiveServer( "http://maven.announce.markmail.org/" ) ); + + assertEquals( "maven.announce.markmail.org", getArchiveServer( "http://maven.announce.markmail.org" ) ); + } + private void startJetty( boolean isSSL, boolean withAuth ) throws Exception {