PR: MNG-411

Submitted By: Vincent Siveton
Reviewed By:  Brett Porter
clean up the mailing list report


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@179174 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-05-31 00:01:18 +00:00
parent b3d4163c60
commit ec805f988f
4 changed files with 258 additions and 10 deletions

View File

@ -6,6 +6,12 @@
<version>2.0-SNAPSHOT</version>
</parent>
<artifactId>maven-reporting-api</artifactId>
<contributors>
<contributor>
<name>Vincent Siveton</name>
<email>vincent.siveton@gmail.com</email>
</contributor>
</contributors>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
@ -22,5 +28,15 @@
<artifactId>maven-plugin-api</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>commons-validator</groupId>
<artifactId>commons-validator</artifactId>
<version>1.1.4</version>
</dependency>
<dependency>
<groupId>oro</groupId>
<artifactId>oro</artifactId>
<version>2.0.7</version>
</dependency>
</dependencies>
</project>

View File

@ -16,11 +16,14 @@ package org.apache.maven.reporting;
* limitations under the License.
*/
import org.apache.commons.validator.EmailValidator;
import org.apache.commons.validator.UrlValidator;
import org.codehaus.doxia.sink.Sink;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @author <a href="evenisse@apache.org">Emmanuel Venisse</a>
* @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
* @version $Id: AbstractMavenReportRenderer.java 163373 2005-02-22 03:37:00Z brett $
* @todo Later it may be appropriate to create something like a VelocityMavenReportRenderer that could take a velocity template and pipe that through Doxia rather than coding them up like this.
*/
@ -185,6 +188,53 @@ public abstract class AbstractMavenReportRenderer
sink.tableCell_();
}
/**
* Create a cell with a potential link.
*
* @param text the text
* @param href the href
*/
protected void tableCellWithLink( String text, String href )
{
sink.tableCell();
if ( text != null )
{
if ( href != null )
{
String[] schemes = {"http", "https"};
UrlValidator urlValidator = new UrlValidator( schemes );
if ( EmailValidator.getInstance().isValid( href ) )
{
link( "mailto:" + href, text );
}
else if ( href.toLowerCase().startsWith( "mailto:" ) )
{
link( href, text );
}
else if ( urlValidator.isValid( href ) )
{
link( href, text );
}
else
{
sink.text( text );
}
}
else
{
sink.text( text );
}
}
else
{
sink.nonBreakingSpace();
}
sink.tableCell_();
}
protected void tableRow( String[] content )
{
sink.tableRow();
@ -197,6 +247,31 @@ public abstract class AbstractMavenReportRenderer
sink.tableRow_();
}
/**
* Create a new row : each cell could have a link.
* <br>
* The arrays should have the same size.
*
* @param texts an array of text
* @param hrefs an array of href
*/
protected void tableRowWithLink( String[] texts, String[] hrefs )
{
if ( hrefs.length != texts.length )
{
throw new IllegalArgumentException( "The arrays should have the same size" );
}
sink.tableRow();
for ( int i = 0; i < texts.length; i++ )
{
tableCellWithLink( texts[i], hrefs[i] );
}
sink.tableRow_();
}
protected void tableHeader( String[] content )
{
sink.tableRow();
@ -209,10 +284,6 @@ public abstract class AbstractMavenReportRenderer
sink.tableRow_();
}
public abstract String getTitle();
protected abstract void renderBody();
protected void tableCaption( String caption )
{
sink.tableCaption();
@ -228,4 +299,17 @@ public abstract class AbstractMavenReportRenderer
sink.paragraph_();
}
protected void link( String href, String name )
{
sink.link( href );
sink.text( name );
sink.link_();
}
public abstract String getTitle();
protected abstract void renderBody();
}

View File

@ -10,4 +10,10 @@
<packaging>maven-plugin</packaging>
<name>Maven Project Info Reports Plugin</name>
<inceptionYear>2005</inceptionYear>
<contributors>
<contributor>
<name>Vincent Siveton</name>
<email>vincent.siveton@gmail.com</email>
</contributor>
</contributors>
</project>

View File

@ -19,20 +19,23 @@ package org.apache.maven.report.projectinfo;
import org.apache.maven.model.MailingList;
import org.apache.maven.model.Model;
import org.apache.maven.project.MavenProject;
import org.apache.maven.reporting.AbstractMavenReportRenderer;
import org.apache.maven.reporting.AbstractMavenReport;
import org.apache.maven.reporting.AbstractMavenReportRenderer;
import org.apache.maven.reporting.MavenReportException;
import org.codehaus.doxia.sink.Sink;
import org.codehaus.doxia.site.renderer.SiteRenderer;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
/**
* @goal mailing-list
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
* @version $Id: MailingListsReport.java,v 1.4 2005/02/23 00:08:03 brett Exp $
* @goal mailing-list
*/
public class MailingListsReport
extends AbstractMavenReport
@ -117,7 +120,7 @@ public class MailingListsReport
r.render();
}
catch( IOException e )
catch ( IOException e )
{
throw new MavenReportException( "Can't write the report " + getOutputName(), e );
}
@ -165,20 +168,159 @@ public class MailingListsReport
startTable();
// To beautify the display
boolean otherArchives = false;
for ( Iterator i = model.getMailingLists().iterator(); i.hasNext(); )
{
MailingList m = (MailingList) i.next();
if ( ( ( m.getOtherArchives() != null ) ) && ( m.getOtherArchives().size() > 0 ) )
{
otherArchives = true;
}
}
if ( otherArchives )
{
tableHeader( new String[]{"Name", "Subscribe", "Unsubscribe", "Archive", "Other Archives"} );
}
else
{
tableHeader( new String[]{"Name", "Subscribe", "Unsubscribe", "Archive"} );
}
for ( Iterator i = model.getMailingLists().iterator(); i.hasNext(); )
{
MailingList m = (MailingList) i.next();
// TODO: render otherArchives?
tableRow( new String[]{m.getName(), m.getSubscribe(), m.getUnsubscribe(), m.getArchive()} );
// Verify that subsribe and unsubsribe lists are valid?
// Same for archive?
if ( ( ( m.getOtherArchives() != null ) ) && ( m.getOtherArchives().size() > 0 ) )
{
List textRow = new ArrayList();
List hrefRow = new ArrayList();
textRow.add( m.getName() );
hrefRow.add( null );
textRow.add( "Subscribe" );
hrefRow.add( m.getSubscribe() );
textRow.add( "Unsubscribe" );
hrefRow.add( m.getUnsubscribe() );
textRow.add( getArchiveServer( m.getArchive() ) );
hrefRow.add( m.getArchive() );
// For the first line
Iterator it = m.getOtherArchives().iterator();
String otherArchive = (String) it.next();
textRow.add( getArchiveServer( otherArchive ) );
hrefRow.add( otherArchive );
tableRowWithLink( (String[]) textRow.toArray( new String[0] ),
(String[]) hrefRow.toArray( new String[0] ) );
// Other lines...
while ( it.hasNext() )
{
otherArchive = (String) it.next();
// Reinit the list to beautify the display
textRow = new ArrayList();
hrefRow = new ArrayList();
textRow.add( "" );
hrefRow.add( null );
textRow.add( "" );
hrefRow.add( null );
textRow.add( "" );
hrefRow.add( null );
textRow.add( "" );
hrefRow.add( null );
textRow.add( getArchiveServer( otherArchive ) );
hrefRow.add( otherArchive );
tableRowWithLink( (String[]) textRow.toArray( new String[0] ),
(String[]) hrefRow.toArray( new String[0] ) );
}
}
else
{
if ( otherArchives )
{
List textRow = new ArrayList();
List hrefRow = new ArrayList();
textRow.add( m.getName() );
hrefRow.add( null );
textRow.add( "Subscribe" );
hrefRow.add( m.getSubscribe() );
textRow.add( "Unsubscribe" );
hrefRow.add( m.getUnsubscribe() );
textRow.add( getArchiveServer( m.getArchive() ) );
hrefRow.add( m.getArchive() );
textRow.add( "" );
hrefRow.add( null );
tableRowWithLink( (String[]) textRow.toArray( new String[0] ),
(String[]) hrefRow.toArray( new String[0] ) );
}
else
{
List textRow = new ArrayList();
List hrefRow = new ArrayList();
textRow.add( m.getName() );
hrefRow.add( null );
textRow.add( "Subscribe" );
hrefRow.add( m.getSubscribe() );
textRow.add( "Unsubscribe" );
hrefRow.add( m.getUnsubscribe() );
textRow.add( getArchiveServer( m.getArchive() ) );
hrefRow.add( m.getArchive() );
tableRowWithLink( (String[]) textRow.toArray( new String[0] ),
(String[]) hrefRow.toArray( new String[0] ) );
}
}
}
endTable();
}
endSection();
}
}
/**
* 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 ( uri == null )
{
return "???UNKWOWN???";
}
int at = uri.indexOf( "//" );
int from = uri.indexOf( "/", at >= 0 ? ( uri.lastIndexOf( "/", at - 1 ) >= 0 ? 0 : at + 2 ) : 0 );
return uri.substring( at + 2, from );
}
}