o Internationalize site plugin generation.

o Add french translation

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@180168 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Emmanuel Venisse 2005-06-05 23:10:11 +00:00
parent 1330677e6e
commit 1218c92bd4
10 changed files with 225 additions and 131 deletions

View File

@ -23,6 +23,7 @@ import org.apache.maven.project.MavenProject;
import org.apache.maven.reporting.MavenReport;
import org.apache.maven.reporting.MavenReportConfiguration;
import org.apache.maven.reporting.MavenReportException;
import org.codehaus.plexus.i18n.I18N;
import org.codehaus.plexus.siterenderer.Renderer;
import org.codehaus.plexus.siterenderer.RendererException;
import org.codehaus.plexus.siterenderer.sink.SiteRendererSink;
@ -49,6 +50,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.StringTokenizer;
/**
* @goal site
@ -104,6 +106,11 @@ public class DoxiaMojo
*/
private Map attributes;
/**
* @parameter expression="${locales}
*/
private String locales;
/**
* @parameter expression="${component.org.codehaus.plexus.siterenderer.Renderer}"
* @required
@ -111,6 +118,13 @@ public class DoxiaMojo
*/
private Renderer siteRenderer;
/**
* @parameter expression="${component.org.codehaus.plexus.i18n.I18N}"
* @required
* @readonly
*/
private I18N i18n;
/**
* @parameter expression="${project}"
* @required
@ -143,6 +157,10 @@ public class DoxiaMojo
private List projectReports = new ArrayList();
private Locale defaultLocale = Locale.ENGLISH;
private List localesList = new ArrayList();
public void execute()
throws MojoExecutionException
{
@ -162,7 +180,7 @@ public class DoxiaMojo
siteRenderer.setTemplateClassLoader( urlClassloader );
}
catch( MalformedURLException e )
catch ( MalformedURLException e )
{
throw new MojoExecutionException( templateDirectory + " isn't a valid URL." );
}
@ -172,18 +190,38 @@ public class DoxiaMojo
{
categorizeReports();
if ( locales == null )
{
localesList.add( defaultLocale );
}
else
{
StringTokenizer st = new StringTokenizer( locales, "," );
while ( st.hasMoreTokens() )
{
localesList.add( new Locale( st.nextToken().trim() ) );
}
}
for ( Iterator i = localesList.iterator(); i.hasNext(); )
{
Locale locale = (Locale) i.next();
MavenReportConfiguration config = new MavenReportConfiguration();
config.setProject( project );
config.setReportOutputDirectory( new File( outputDirectory ) );
File localeOutputDirectory = getOuputDirectory( locale );
config.setReportOutputDirectory( localeOutputDirectory );
//Generate reports
if ( reports != null )
{
for ( Iterator i = reports.keySet().iterator(); i.hasNext(); )
for ( Iterator j = reports.keySet().iterator(); j.hasNext(); )
{
String reportKey = (String) i.next();
String reportKey = (String) j.next();
getLog().info( "Generate " + reportKey + " report." );
@ -194,19 +232,19 @@ public class DoxiaMojo
String outputFileName = report.getOutputName() + ".html";
SiteRendererSink sink = siteRenderer.createSink( new File( siteDirectory ), outputFileName,
getSiteDescriptor() );
getSiteDescriptor( locale ) );
//TODO: Use multiple locale with a loop
report.generate( sink, Locale.ENGLISH );
report.generate( sink, locale );
File outputFile = new File( outputDirectory, outputFileName );
File outputFile = new File( localeOutputDirectory, outputFileName );
if ( !outputFile.getParentFile().exists() )
{
outputFile.getParentFile().mkdirs();
}
siteRenderer.generateDocument( new FileWriter( outputFile ), template, attributes, sink, Locale.ENGLISH );
siteRenderer
.generateDocument( new FileWriter( outputFile ), template, attributes, sink, locale );
}
}
@ -215,7 +253,7 @@ public class DoxiaMojo
{
try
{
generateProjectInfoPage( getSiteDescriptor() );
generateProjectInfoPage( getSiteDescriptor( locale ), locale );
}
catch ( Exception e )
{
@ -227,7 +265,7 @@ public class DoxiaMojo
{
try
{
generateProjectReportsPage( getSiteDescriptor() );
generateProjectReportsPage( getSiteDescriptor( locale ), locale );
}
catch ( Exception e )
{
@ -235,6 +273,12 @@ public class DoxiaMojo
}
}
// Generate static site
siteRenderer.render( new File( siteDirectory ), localeOutputDirectory, getSiteDescriptor( locale ),
template, attributes );
siteRenderer.render( new File( generatedSiteDirectory ), localeOutputDirectory,
getSiteDescriptor( locale ), template, attributes );
File cssDirectory = new File( siteDirectory, "css" );
File imagesDirectory = new File( siteDirectory, "images" );
@ -243,24 +287,19 @@ public class DoxiaMojo
{
getLog().warn( "DEPRECATED: the css and images directories are deprecated, please use resources" );
copyDirectory( cssDirectory, new File( outputDirectory, "css" ) );
copyDirectory( cssDirectory, new File( localeOutputDirectory, "css" ) );
copyDirectory( imagesDirectory, new File( outputDirectory, "images" ) );
copyDirectory( imagesDirectory, new File( localeOutputDirectory, "images" ) );
}
// Generate static site
siteRenderer.render( new File( siteDirectory ), new File( outputDirectory ), getSiteDescriptor(), template,
attributes );
siteRenderer.render( new File( generatedSiteDirectory ), new File( outputDirectory ), getSiteDescriptor(),
template, attributes );
// Copy site resources
if ( resourcesDirectory != null && resourcesDirectory.exists() )
{
copyDirectory( resourcesDirectory, new File( outputDirectory ) );
copyDirectory( resourcesDirectory, localeOutputDirectory );
}
copyResources( outputDirectory );
copyResources( localeOutputDirectory );
}
}
catch ( MavenReportException e )
{
@ -293,28 +332,28 @@ public class DoxiaMojo
else
{
throw new MojoExecutionException( "'" + report.getCategoryName() + "' category define for "
+ report.getName() + " mojo isn't valid." );
+ report.getName( defaultLocale ) + " mojo isn't valid." );
}
}
}
private String getReportsMenu()
private String getReportsMenu( Locale locale )
throws MojoExecutionException
{
StringBuffer buffer = new StringBuffer();
buffer.append( "<menu name=\"Project Documentation\">\n" );
buffer.append( " <item name=\"About " + project.getName() + "\" href=\"/index.html\"/>\n" );
buffer.append( " <item name=\"" + i18n.getString( "site-plugin", locale, "report.menu.about") + " " + project.getName() + "\" href=\"/index.html\"/>\n" );
if ( projectInfos.size() > 0 )
{
buffer.append( " <item name=\"" + MavenReport.CATEGORY_PROJECT_INFORMATION
buffer.append( " <item name=\"" + i18n.getString( "site-plugin", locale, "report.menu.projectinformation")
+ "\" href=\"/project-info.html\" collapse=\"true\">\n" );
for ( Iterator i = projectInfos.iterator(); i.hasNext(); )
{
MavenReport report = (MavenReport) i.next();
buffer.append( " <item name=\"" + report.getName() + "\" href=\"/" + report.getOutputName()
+ ".html\"/>\n" );
buffer.append( " <item name=\"" + report.getName( locale ) + "\" href=\"/"
+ report.getOutputName() + ".html\"/>\n" );
}
buffer.append( " </item>\n" );
@ -322,14 +361,14 @@ public class DoxiaMojo
if ( projectReports.size() > 0 )
{
buffer.append( " <item name=\"" + MavenReport.CATEGORY_PROJECT_REPORTS
buffer.append( " <item name=\"" + i18n.getString( "site-plugin", locale, "report.menu.projectreports")
+ "\" href=\"/maven-reports.html\" collapse=\"true\">\n" );
for ( Iterator i = projectReports.iterator(); i.hasNext(); )
{
MavenReport report = (MavenReport) i.next();
buffer.append( " <item name=\"" + report.getName() + "\" href=\"/" + report.getOutputName()
+ ".html\"/>\n" );
buffer.append( " <item name=\"" + report.getName( locale ) + "\" href=\"/"
+ report.getOutputName() + ".html\"/>\n" );
}
buffer.append( " </item>\n" );
@ -340,7 +379,7 @@ public class DoxiaMojo
return buffer.toString();
}
private InputStream getSiteDescriptor()
private InputStream getSiteDescriptor( Locale locale )
throws MojoExecutionException
{
File siteDescriptor = new File( siteDirectory, "site.xml" );
@ -367,7 +406,7 @@ public class DoxiaMojo
if ( reports != null )
{
props.put( "reports", getReportsMenu() );
props.put( "reports", getReportsMenu( locale ) );
}
// TODO: interpolate ${project.*} in general
@ -395,15 +434,15 @@ public class DoxiaMojo
return new StringInputStream( siteDescriptorContent );
}
private void generateProjectInfoPage( InputStream siteDescriptor )
private void generateProjectInfoPage( InputStream siteDescriptor, Locale locale )
throws Exception
{
String outputFileName = "project-info.html";
SiteRendererSink sink = siteRenderer
.createSink( new File( siteDirectory ), outputFileName, getSiteDescriptor() );
SiteRendererSink sink = siteRenderer.createSink( new File( siteDirectory ), outputFileName,
getSiteDescriptor( locale ) );
String title = "General Project Information";
String title = i18n.getString( "site-plugin", locale, "report.information.title");
sink.head();
sink.title();
@ -418,28 +457,27 @@ public class DoxiaMojo
sink.sectionTitle1_();
sink.paragraph();
sink.text( "This document provides an overview of the various documents and links that are part "
+ "of this project's general information. All of this content is automatically generated by " );
sink.text( i18n.getString( "site-plugin", locale, "report.information.description1") + " " );
sink.link( "http://maven.apache.org" );
sink.text( "Maven" );
sink.link_();
sink.text( " on behalf of the project." );
sink.text( " " + i18n.getString( "site-plugin", locale, "report.information.description2") );
sink.paragraph_();
sink.section2();
sink.sectionTitle2();
sink.text( "Overview" );
sink.text( i18n.getString( "site-plugin", locale, "report.information.sectionTitle") );
sink.sectionTitle2_();
sink.table();
sink.tableRow();
sink.tableHeaderCell();
sink.text( "Document" );
sink.text( i18n.getString( "site-plugin", locale, "report.information.column.document") );
sink.tableHeaderCell_();
sink.tableHeaderCell();
sink.text( "Description" );
sink.text( i18n.getString( "site-plugin", locale, "report.information.column.description") );
sink.tableHeaderCell_();
sink.tableRow_();
@ -450,11 +488,11 @@ public class DoxiaMojo
sink.tableRow();
sink.tableCell();
sink.link( report.getOutputName() + ".html" );
sink.text( report.getName() );
sink.text( report.getName( locale ) );
sink.link_();
sink.tableCell_();
sink.tableCell();
sink.text( report.getDescription() );
sink.text( report.getDescription( locale ) );
sink.tableCell_();
sink.tableRow_();
}
@ -471,19 +509,19 @@ public class DoxiaMojo
sink.close();
siteRenderer.generateDocument( new FileWriter( new File( outputDirectory, outputFileName ) ), template,
attributes, sink, Locale.ENGLISH );
siteRenderer.generateDocument( new FileWriter( new File( getOuputDirectory( locale ), outputFileName ) ),
template, attributes, sink, locale );
}
private void generateProjectReportsPage( InputStream siteDescriptor )
private void generateProjectReportsPage( InputStream siteDescriptor, Locale locale )
throws Exception
{
String outputFileName = "maven-reports.html";
SiteRendererSink sink = siteRenderer
.createSink( new File( siteDirectory ), outputFileName, getSiteDescriptor() );
SiteRendererSink sink = siteRenderer.createSink( new File( siteDirectory ), outputFileName,
getSiteDescriptor( locale ) );
String title = "Maven Generated Reports";
String title = i18n.getString( "site-plugin", locale, "report.project.title");
sink.head();
sink.title();
@ -498,27 +536,27 @@ public class DoxiaMojo
sink.sectionTitle1_();
sink.paragraph();
sink.text( "This document provides an overview of the various reports that are automatically generated by " );
sink.text( i18n.getString( "site-plugin", locale, "report.project.description1") + " " );
sink.link( "http://maven.apache.org" );
sink.text( "Maven" );
sink.link_();
sink.text( ". Each report is briefly described below." );
sink.text( ". " + i18n.getString( "site-plugin", locale, "report.project.description2") );
sink.paragraph_();
sink.section2();
sink.sectionTitle2();
sink.text( "Overview" );
sink.text( i18n.getString( "site-plugin", locale, "report.project.sectionTitle") );
sink.sectionTitle2_();
sink.table();
sink.tableRow();
sink.tableHeaderCell();
sink.text( "Document" );
sink.text( i18n.getString( "site-plugin", locale, "report.project.column.document") );
sink.tableHeaderCell_();
sink.tableHeaderCell();
sink.text( "Description" );
sink.text( i18n.getString( "site-plugin", locale, "report.project.column.description") );
sink.tableHeaderCell_();
sink.tableRow_();
@ -529,11 +567,11 @@ public class DoxiaMojo
sink.tableRow();
sink.tableCell();
sink.link( report.getOutputName() + ".html" );
sink.text( report.getName() );
sink.text( report.getName( locale ) );
sink.link_();
sink.tableCell_();
sink.tableCell();
sink.text( report.getDescription() );
sink.text( report.getDescription( locale ) );
sink.tableCell_();
sink.tableRow_();
}
@ -546,11 +584,11 @@ public class DoxiaMojo
sink.body_();
siteRenderer.generateDocument( new FileWriter( new File( outputDirectory, outputFileName ) ), template,
attributes, sink, Locale.ENGLISH );
siteRenderer.generateDocument( new FileWriter( new File( getOuputDirectory( locale ), outputFileName ) ),
template, attributes, sink, locale );
}
private void copyResources( String outputDirectory )
private void copyResources( File outputDirectory )
throws Exception
{
InputStream resourceList = getStream( RESOURCE_DIR + "/resources.txt" );
@ -623,4 +661,24 @@ public class DoxiaMojo
FileUtils.copyFile( sourceFile, destinationFile );
}
}
private File getOuputDirectory( Locale locale )
{
if ( localesList.size() == 1 )
{
return new File( outputDirectory );
}
else
{
Locale firstLocale = (Locale) localesList.get( 0 );
if ( locale.equals( firstLocale ) )
{
return new File( outputDirectory );
}
else
{
return new File( outputDirectory, locale.getLanguage() );
}
}
}
}

View File

@ -0,0 +1,17 @@
template.lastpublished=Last Published
template.builtby=Built by
report.project.title=Maven Generated Reports
report.project.description1=This document provides an overview of the various reports that are automatically generated by
report.project.description2=Each report is briefly described below.
report.project.sectionTitle=Overview
report.project.column.description=Description
report.project.column.document=Document
report.information.title=General Project Information
report.information.description1=This document provides an overview of the various documents and links that are part of this project's general information. All of this content is automatically generated by
report.information.description2=on behalf of the project.
report.information.sectionTitle=Overview
report.information.column.description=Description
report.information.column.document=Document
report.menu.about=About
report.menu.projectinformation=Project Info
report.menu.projectreports=Project Reports

View File

@ -0,0 +1,17 @@
template.lastpublished=Dernière publication
template.builtby=Produit par
report.project.title=Rapport générés par Maven
report.project.description1=Ce document fournit une vue d'ensemble des divers rapports générés automatiquement par
report.project.description2=Chaque rapport est décrit brièvement ci-dessous.
report.project.sectionTitle=Vue d'ensemble
report.project.column.description=Description
report.project.column.document=Document
report.information.title=Information générale du projet
report.information.description1=Ce document fournit une vue d'ensemble des divers documents et liens qui font partis des informations générales du projet. Tous ces contenus sont générés automatiquement par
report.information.description2=on behalf of the project.
report.information.sectionTitle=Vue d'ensemble
report.information.column.description=Description
report.information.column.document=Document
report.menu.about=A propos de
report.menu.projectinformation=Info Projet
report.menu.projectreports=Rapports Projet

View File

@ -66,6 +66,8 @@ public abstract class AbstractMavenReport
private Sink sink;
private Locale locale = Locale.ENGLISH;
public MavenReportConfiguration getConfiguration()
{
return config;
@ -108,7 +110,7 @@ public abstract class AbstractMavenReport
}
catch ( Exception e )
{
throw new MojoExecutionException( "An error is occurred in " + getName() + " report generation." );
throw new MojoExecutionException( "An error is occurred in " + getName( locale ) + " report generation." );
}
}
@ -161,7 +163,7 @@ public abstract class AbstractMavenReport
StringBuffer buffer = new StringBuffer();
buffer.append( "<menu name=\"Project Documentation\">\n" );
buffer.append( " <item name=\"" + getName() + "\" href=\"/" + getOutputName() + ".html\"/>\n" );
buffer.append( " <item name=\"" + getName( locale ) + "\" href=\"/" + getOutputName() + ".html\"/>\n" );
buffer.append( "</menu>\n" );

View File

@ -45,11 +45,11 @@ public interface MavenReport
String getOutputName();
String getName();
String getName( Locale locale );
String getCategoryName();
String getDescription();
String getDescription( Locale locale );
Sink getSink()
throws IOException;

View File

@ -83,17 +83,17 @@ public class CheckstyleReport
private boolean failedOnError = false;
/**
* @see org.apache.maven.reporting.MavenReport#getName()
* @see org.apache.maven.reporting.MavenReport#getName(java.util.Locale)
*/
public String getName()
public String getName( Locale locale )
{
return "Checkstyle";
}
/**
* @see org.apache.maven.reporting.MavenReport#getDescription()
* @see org.apache.maven.reporting.MavenReport#getDescription(java.util.Locale)
*/
public String getDescription()
public String getDescription( Locale locale )
{
return "Report on coding style conventions.";
}

View File

@ -61,17 +61,17 @@ public class JavadocReport
private MavenProject project;
/**
* @see org.apache.maven.reporting.MavenReport#getName()
* @see org.apache.maven.reporting.MavenReport#getName(java.util.Locale)
*/
public String getName()
public String getName( Locale locale )
{
return "JavaDocs";
}
/**
* @see org.apache.maven.reporting.MavenReport#getDescription()
* @see org.apache.maven.reporting.MavenReport#getDescription(java.util.Locale)
*/
public String getDescription()
public String getDescription( Locale locale )
{
return "JavaDoc API documentation.";
}

View File

@ -74,17 +74,17 @@ public class PmdReport
private MavenProject project;
/**
* @see org.apache.maven.reporting.MavenReport#getName()
* @see org.apache.maven.reporting.MavenReport#getName(java.util.Locale)
*/
public String getName()
public String getName( Locale locale )
{
return "PMD report";
}
/**
* @see org.apache.maven.reporting.MavenReport#getDescription()
* @see org.apache.maven.reporting.MavenReport#getDescription(java.util.Locale)
*/
public String getDescription()
public String getDescription( Locale locale )
{
return "Verification of coding rules.";
}

View File

@ -60,9 +60,9 @@ public class DependenciesReport
private MavenProject project;
/**
* @see org.apache.maven.reporting.MavenReport#getName()
* @see org.apache.maven.reporting.MavenReport#getName(java.util.Locale)
*/
public String getName()
public String getName( Locale locale )
{
return "Dependencies";
}
@ -76,9 +76,9 @@ public class DependenciesReport
}
/**
* @see org.apache.maven.reporting.MavenReport#getDescription()
* @see org.apache.maven.reporting.MavenReport#getDescription(java.util.Locale)
*/
public String getDescription()
public String getDescription( Locale locale )
{
return "This document lists the projects dependencies and provides information on each dependency.";
}

View File

@ -61,9 +61,9 @@ public class MailingListsReport
private MavenProject project;
/**
* @see org.apache.maven.reporting.MavenReport#getName()
* @see org.apache.maven.reporting.MavenReport#getName(java.util.Locale)
*/
public String getName()
public String getName( Locale locale )
{
return "Mailing Lists";
}
@ -77,9 +77,9 @@ public class MailingListsReport
}
/**
* @see org.apache.maven.reporting.MavenReport#getDescription()
* @see org.apache.maven.reporting.MavenReport#getDescription(java.util.Locale)
*/
public String getDescription()
public String getDescription( Locale locale )
{
return "This document provides subscription and archive information for this project's mailing lists.";
}