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 2020/06/05 09:24:27 UTC
[maven-project-info-reports-plugin] 01/01: [MPIR-393] Cleanup
getArchiveServer
This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a commit to branch MPIR-393
in repository https://gitbox.apache.org/repos/asf/maven-project-info-reports-plugin.git
commit 113668f15faccd5543f9cbad97a2b1c9ef7543da
Author: Sylwester Lachiewicz <sl...@apache.org>
AuthorDate: Fri Jun 5 11:13:26 2020 +0200
[MPIR-393] Cleanup getArchiveServer
---
pom.xml | 6 ---
.../report/projectinfo/MailingListsReport.java | 48 ++++------------------
.../report/projectinfo/ProjectInfoReportUtils.java | 18 ++++++++
.../report/projectinfo/MailingListsReportTest.java | 39 ------------------
.../projectinfo/ProjectInfoReportUtilsTest.java | 27 ++++++++++++
5 files changed, 52 insertions(+), 86 deletions(-)
diff --git a/pom.xml b/pom.xml
index 26ab65c..ecb186c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -372,12 +372,6 @@ under the License.
<scope>test</scope>
</dependency>
<dependency>
- <groupId>junit-addons</groupId>
- <artifactId>junit-addons</artifactId>
- <version>1.4</version>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty</artifactId>
<version>6.1.26</version>
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 1e516cc..5c3336e 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.MailingList;
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 class MailingListsReport
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 class MailingListsReport
Iterator<String> 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 class MailingListsReport
// 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 @@ public class MailingListsReport
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. <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>
- *
- * @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 3cb22b9..d1c6bd9 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.IOException;
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;
@@ -277,6 +278,23 @@ public class ProjectInfoReportUtils
}
/**
+ * Convenience method to return the name of a web-based mailing list archive server.
+ * For instance, if the archive URI is <code>http://www.mail-archive.com/dev@maven.apache.org</code>, this
+ * method returns <code>www.mail-archive.com</code>
+ *
+ * @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
* @param settings 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 2c47857..f8237f9 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 @@ package org.apache.maven.report.projectinfo;
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 class MailingListsReportTest
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 03c71b9..822897b 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.SecurityHandler;
import org.mortbay.jetty.security.SslSocketConnector;
import org.mortbay.jetty.webapp.WebAppContext;
+import static org.apache.maven.report.projectinfo.ProjectInfoReportUtils.getArchiveServer;
+
/**
* @author <a href="mailto:vincent.siveton@crim.ca">Vincent Siveton</a>
* @version $Id$
@@ -191,6 +193,31 @@ public class ProjectInfoReportUtilsTest
// 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
{