Skip to content

Commit

Permalink
[MPIR-393] Cleanup getArchiveServer
Browse files Browse the repository at this point in the history
  • Loading branch information
slachiewicz committed Jun 5, 2020
1 parent 3f71f5b commit 113668f
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 86 deletions.
6 changes: 0 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -371,12 +371,6 @@ under the License.
<version>2.28.2</version>
<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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
{
Expand All @@ -183,7 +183,8 @@ public void renderBody()
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()] ) );

Expand All @@ -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()] ) );
}
Expand Down Expand Up @@ -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. <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 );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 <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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 } );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href="mailto:vincent.siveton@crim.ca">Vincent Siveton</a>
* @version $Id$
Expand Down Expand Up @@ -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
{
Expand Down

0 comments on commit 113668f

Please sign in to comment.