mirror of https://github.com/apache/maven.git
Cleaning up the code a bit: replace static array of all reports file name generated by Maven by a list (more dynamic); the first token in the locales variable is the default locale (set in the VM); create createDuplicateExceptionMsg() to handle the exception msg when some files are duplicated; move code to generate reports in a new method called generateReportsPages(); improve logging.
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@240444 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
4ccb9068fb
commit
9ef6cc7f50
|
@ -77,10 +77,9 @@ public class DoxiaMojo
|
|||
private static final String DEFAULT_TEMPLATE = RESOURCE_DIR + "/maven-site.vm";
|
||||
|
||||
/**
|
||||
* OutputName of all project info report files generated by Maven
|
||||
* OutputName of all reports files generated by Maven
|
||||
*/
|
||||
private static final String[] PROJECT_INFO_FILES = new String[]{"integration", "dependencies", "issue-tracking",
|
||||
"license", "mail-lists", "source-repository", "team-list"};
|
||||
private static List generatedReportsFileName = new ArrayList();
|
||||
|
||||
/**
|
||||
* Patterns which should be excluded by default.
|
||||
|
@ -160,7 +159,7 @@ public class DoxiaMojo
|
|||
* default-value="ISO-8859-1"
|
||||
*/
|
||||
private String outputEncoding;
|
||||
|
||||
|
||||
/**
|
||||
* @parameter expression="${component.org.codehaus.plexus.siterenderer.Renderer}"
|
||||
* @required
|
||||
|
@ -259,14 +258,19 @@ public class DoxiaMojo
|
|||
}
|
||||
else
|
||||
{
|
||||
// The first token is the default locale
|
||||
StringTokenizer st = new StringTokenizer( locales, "," );
|
||||
|
||||
while ( st.hasMoreTokens() )
|
||||
{
|
||||
localesList.add( new Locale( st.nextToken().trim() ) );
|
||||
}
|
||||
|
||||
defaultLocale = (Locale) localesList.get( 0 );
|
||||
}
|
||||
|
||||
Locale.setDefault( defaultLocale );
|
||||
|
||||
for ( Iterator iterator = localesList.iterator(); iterator.hasNext(); )
|
||||
{
|
||||
Locale locale = (Locale) iterator.next();
|
||||
|
@ -279,37 +283,50 @@ public class DoxiaMojo
|
|||
localeOutputDirectory.mkdirs();
|
||||
}
|
||||
|
||||
// Handle the GeneratedSite Directory
|
||||
File generatedSiteFile = new File( generatedSiteDirectory );
|
||||
if ( generatedSiteFile.exists() )
|
||||
{
|
||||
InputStream siteDescriptor = getSiteDescriptor( reports, locale );
|
||||
siteRenderer.render( generatedSiteFile, localeOutputDirectory, siteDescriptor, template,
|
||||
attributes, locale );
|
||||
}
|
||||
|
||||
// Generate static site
|
||||
File siteDirectoryFile = new File( siteDirectory );
|
||||
if ( !locale.getLanguage().equals( defaultLocale.getLanguage() ) )
|
||||
{
|
||||
siteDirectoryFile = new File( siteDirectory, locale.getLanguage() );
|
||||
}
|
||||
|
||||
// Try to find duplicate files
|
||||
Map duplicate = new LinkedHashMap();
|
||||
if ( siteDirectoryFile.exists() )
|
||||
{
|
||||
tryToFindDuplicates( siteDirectoryFile, duplicate );
|
||||
}
|
||||
if ( generatedSiteFile.exists() )
|
||||
{
|
||||
tryToFindDuplicates( generatedSiteFile, duplicate );
|
||||
}
|
||||
|
||||
// Exception if a file is duplicate
|
||||
String msg = createDuplicateExceptionMsg( duplicate, locale );
|
||||
if ( msg != null )
|
||||
{
|
||||
throw new MavenReportException( msg );
|
||||
}
|
||||
|
||||
//Generate reports
|
||||
if ( reports != null )
|
||||
{
|
||||
for ( Iterator j = reports.iterator(); j.hasNext(); )
|
||||
try
|
||||
{
|
||||
MavenReport report = (MavenReport) j.next();
|
||||
|
||||
getLog().info( "Generate \"" + report.getName( locale ) + "\" report." );
|
||||
|
||||
report.setReportOutputDirectory( localeOutputDirectory );
|
||||
|
||||
String outputFileName = report.getOutputName() + ".html";
|
||||
|
||||
SiteRendererSink sink = siteRenderer.createSink( new File( siteDirectory ), outputFileName,
|
||||
getSiteDescriptor( reports, locale ) );
|
||||
|
||||
report.generate( sink, locale );
|
||||
|
||||
if ( !report.isExternalReport() )
|
||||
{
|
||||
File outputFile = new File( localeOutputDirectory, outputFileName );
|
||||
|
||||
if ( !outputFile.getParentFile().exists() )
|
||||
{
|
||||
outputFile.getParentFile().mkdirs();
|
||||
}
|
||||
|
||||
siteRenderer.generateDocument( new OutputStreamWriter( new FileOutputStream( outputFile ),
|
||||
outputEncoding ), template,
|
||||
attributes, sink, locale );
|
||||
}
|
||||
generateReportsPages( reports, locale, localeOutputDirectory );
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
throw new MojoExecutionException( "An error is occurred in reports pages generation.", e );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -334,109 +351,34 @@ public class DoxiaMojo
|
|||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
throw new MojoExecutionException( "An error is occurred in project reports page generation.",
|
||||
e );
|
||||
}
|
||||
}
|
||||
|
||||
// Handle the GeneratedSite Directory
|
||||
File generatedSiteFile = new File( generatedSiteDirectory );
|
||||
if ( generatedSiteFile.exists() )
|
||||
{
|
||||
siteRenderer.render( generatedSiteFile, localeOutputDirectory, getSiteDescriptor( reports, locale ),
|
||||
template, attributes, locale );
|
||||
}
|
||||
|
||||
// Generate static site
|
||||
File siteDirectoryFile;
|
||||
|
||||
Locale firstLocale = (Locale) localesList.get( 0 );
|
||||
|
||||
if ( locale.equals( firstLocale ) )
|
||||
{
|
||||
siteDirectoryFile = new File( siteDirectory );
|
||||
}
|
||||
else
|
||||
{
|
||||
siteDirectoryFile = new File( siteDirectory, locale.getLanguage() );
|
||||
}
|
||||
|
||||
// Try to find duplicate files
|
||||
Map duplicate = new LinkedHashMap();
|
||||
if ( siteDirectoryFile.exists() )
|
||||
{
|
||||
tryToFindDuplicates( siteDirectoryFile, duplicate );
|
||||
}
|
||||
if ( generatedSiteFile.exists() )
|
||||
{
|
||||
tryToFindDuplicates( generatedSiteFile, duplicate );
|
||||
}
|
||||
|
||||
// Exception if a file is duplicate
|
||||
if ( duplicate.size() > 0 )
|
||||
{
|
||||
StringBuffer sb = null;
|
||||
|
||||
for ( Iterator it = duplicate.entrySet().iterator(); it.hasNext(); )
|
||||
{
|
||||
Map.Entry entry = (Map.Entry) it.next();
|
||||
Collection values = (Collection) entry.getValue();
|
||||
|
||||
if ( values.size() > 1 )
|
||||
{
|
||||
if ( sb == null )
|
||||
{
|
||||
sb = new StringBuffer(
|
||||
"Some files are duplicates in the site directory or in the generated-site directory. " +
|
||||
"Review the following files:" );
|
||||
}
|
||||
|
||||
sb.append( "\n" ).append( entry.getKey() ).append( "\n" );
|
||||
|
||||
for ( Iterator it2 = values.iterator(); it2.hasNext(); )
|
||||
{
|
||||
String current = (String) it2.next();
|
||||
sb.append( "\t" ).append( current );
|
||||
if ( it2.hasNext() )
|
||||
{
|
||||
sb.append( "\n" );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( sb != null )
|
||||
{
|
||||
throw new MavenReportException( sb.toString() );
|
||||
throw new MojoExecutionException( "An error is occurred in project reports page generation.", e );
|
||||
}
|
||||
}
|
||||
|
||||
// Try to generate the index.html
|
||||
if ( duplicate.get( "index" ) != null )
|
||||
{
|
||||
getLog().info( "Ignoring the index file generation." );
|
||||
getLog().info( "Ignoring the index file generation for the \"" + getDisplayLanguage( locale )
|
||||
+ "\" version." );
|
||||
}
|
||||
else
|
||||
{
|
||||
getLog().info( "Generate an index file." );
|
||||
getLog().info( "Generate an index file for the \"" + getDisplayLanguage( locale ) + "\" version." );
|
||||
generateIndexPage( getSiteDescriptor( reports, locale ), locale );
|
||||
}
|
||||
|
||||
// Log if a user override a project info report file
|
||||
for ( int i = 0; i < PROJECT_INFO_FILES.length; i++ )
|
||||
// Log if a user override a report file
|
||||
for ( Iterator it = generatedReportsFileName.iterator(); it.hasNext(); )
|
||||
{
|
||||
if ( projectInfos.size() > 0 )
|
||||
String reportFileName = (String) it.next();
|
||||
|
||||
if ( duplicate.get( reportFileName ) != null )
|
||||
{
|
||||
if ( duplicate.get( PROJECT_INFO_FILES[i] ) != null )
|
||||
{
|
||||
getLog().info( "Override the generated files \"" + PROJECT_INFO_FILES[i] + "\"." );
|
||||
}
|
||||
getLog().info( "Override the generated file \"" + reportFileName + "\" for the \""
|
||||
+ getDisplayLanguage( locale ) + "\" version." );
|
||||
}
|
||||
}
|
||||
|
||||
siteRenderer.render( siteDirectoryFile, localeOutputDirectory, getSiteDescriptor( reports, locale ),
|
||||
template, attributes, locale );
|
||||
|
||||
siteRenderer.render( siteDirectoryFile, localeOutputDirectory, getSiteDescriptor( reports, locale ),
|
||||
template, attributes, locale );
|
||||
|
||||
|
@ -517,8 +459,8 @@ subprojects...
|
|||
}
|
||||
else
|
||||
{
|
||||
throw new MojoExecutionException( "'" + report.getCategoryName() + "' category define for " +
|
||||
report.getName( defaultLocale ) + " mojo isn't valid." );
|
||||
throw new MojoExecutionException( "'" + report.getCategoryName() + "' category define for "
|
||||
+ report.getName( defaultLocale ) + " mojo isn't valid." );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -543,8 +485,7 @@ subprojects...
|
|||
return buffer.toString();
|
||||
}
|
||||
|
||||
private void writeReportSubMenu( List reports, StringBuffer buffer, Locale locale, String key,
|
||||
String indexFilename )
|
||||
private void writeReportSubMenu( List reports, StringBuffer buffer, Locale locale, String key, String indexFilename )
|
||||
{
|
||||
if ( reports.size() > 0 )
|
||||
{
|
||||
|
@ -673,14 +614,15 @@ subprojects...
|
|||
|
||||
if ( project.getParent() != null )
|
||||
{
|
||||
props.put( "parentProject", getProjectParentMenu( locale ) );
|
||||
/* See the Not working section*/
|
||||
//props.put( "parentProject", getProjectParentMenu( locale ) );
|
||||
}
|
||||
|
||||
if ( addModules )
|
||||
{
|
||||
if ( project.getModules() != null && project.getModules().size() > 0 )
|
||||
{
|
||||
/* See the Not working section, around line 460*/
|
||||
/* See the Not working section*/
|
||||
//props.put( "modules", getModulesMenu( locale ) );
|
||||
}
|
||||
}
|
||||
|
@ -757,11 +699,66 @@ subprojects...
|
|||
sink.close();
|
||||
|
||||
File outputFile = new File( getOuputDirectory( locale ), outputFileName );
|
||||
|
||||
|
||||
siteRenderer.generateDocument( new OutputStreamWriter( new FileOutputStream( outputFile ), outputEncoding ),
|
||||
template, attributes, sink, locale );
|
||||
}
|
||||
|
||||
// Generate specific pages
|
||||
|
||||
/**
|
||||
* Generate reports pages
|
||||
*
|
||||
* @param reports
|
||||
* @param locale
|
||||
* @param localeOutputDirectory
|
||||
* @throws Exception
|
||||
*/
|
||||
private void generateReportsPages( List reports, Locale locale, File localeOutputDirectory )
|
||||
throws Exception
|
||||
{
|
||||
for ( Iterator j = reports.iterator(); j.hasNext(); )
|
||||
{
|
||||
MavenReport report = (MavenReport) j.next();
|
||||
|
||||
getLog().info( "Generate \"" + report.getName( locale ) + "\" report." );
|
||||
|
||||
report.setReportOutputDirectory( localeOutputDirectory );
|
||||
|
||||
String reportFileName = report.getOutputName();
|
||||
|
||||
if ( locale.equals( defaultLocale ) )
|
||||
{
|
||||
generatedReportsFileName.add( reportFileName );
|
||||
}
|
||||
else
|
||||
{
|
||||
generatedReportsFileName.add( locale.getLanguage() + File.separator + reportFileName );
|
||||
}
|
||||
|
||||
String outputFileName = reportFileName + ".html";
|
||||
|
||||
SiteRendererSink sink = siteRenderer.createSink( new File( siteDirectory ), outputFileName,
|
||||
getSiteDescriptor( reports, locale ) );
|
||||
|
||||
report.generate( sink, locale );
|
||||
|
||||
if ( !report.isExternalReport() )
|
||||
{
|
||||
File outputFile = new File( localeOutputDirectory, outputFileName );
|
||||
|
||||
if ( !outputFile.getParentFile().exists() )
|
||||
{
|
||||
outputFile.getParentFile().mkdirs();
|
||||
}
|
||||
|
||||
siteRenderer.generateDocument( new OutputStreamWriter( new FileOutputStream( outputFile ),
|
||||
outputEncoding ), template, attributes, sink,
|
||||
locale );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void generateProjectInfoPage( InputStream siteDescriptor, Locale locale )
|
||||
throws Exception
|
||||
{
|
||||
|
@ -838,8 +835,8 @@ subprojects...
|
|||
|
||||
File outputFile = new File( getOuputDirectory( locale ), outputFileName );
|
||||
|
||||
siteRenderer.generateDocument( new OutputStreamWriter( new FileOutputStream( outputFile ) ), template,
|
||||
attributes, sink, locale );
|
||||
siteRenderer.generateDocument( new OutputStreamWriter( new FileOutputStream( outputFile ), outputEncoding ),
|
||||
template, attributes, sink, locale );
|
||||
}
|
||||
|
||||
private void generateProjectReportsPage( InputStream siteDescriptor, Locale locale )
|
||||
|
@ -914,8 +911,8 @@ subprojects...
|
|||
|
||||
File outputFile = new File( getOuputDirectory( locale ), outputFileName );
|
||||
|
||||
siteRenderer.generateDocument( new OutputStreamWriter( new FileOutputStream( outputFile ) ), template,
|
||||
attributes, sink, locale );
|
||||
siteRenderer.generateDocument( new OutputStreamWriter( new FileOutputStream( outputFile ), outputEncoding ),
|
||||
template, attributes, sink, locale );
|
||||
}
|
||||
|
||||
private void copyResources( File outputDir )
|
||||
|
@ -935,8 +932,8 @@ subprojects...
|
|||
|
||||
if ( is == null )
|
||||
{
|
||||
throw new IOException(
|
||||
"The resource " + line + " doesn't exists in " + DEFAULT_TEMPLATE + " template." );
|
||||
throw new IOException( "The resource " + line + " doesn't exists in " + DEFAULT_TEMPLATE
|
||||
+ " template." );
|
||||
}
|
||||
|
||||
File outputFile = new File( outputDir, line );
|
||||
|
@ -970,7 +967,7 @@ subprojects...
|
|||
{
|
||||
DirectoryScanner scanner = new DirectoryScanner();
|
||||
|
||||
String[] includedResources = {"**/**"};
|
||||
String[] includedResources = { "**/**" };
|
||||
|
||||
scanner.setIncludes( includedResources );
|
||||
|
||||
|
@ -1002,8 +999,7 @@ subprojects...
|
|||
return new File( outputDirectory );
|
||||
}
|
||||
|
||||
Locale firstLocale = (Locale) localesList.get( 0 );
|
||||
if ( locale.equals( firstLocale ) )
|
||||
if ( locale.getLanguage().equals( defaultLocale.getLanguage() ) )
|
||||
{
|
||||
return new File( outputDirectory );
|
||||
}
|
||||
|
@ -1020,8 +1016,7 @@ subprojects...
|
|||
|
||||
if ( project.getModel().getReports() != null )
|
||||
{
|
||||
getLog().error(
|
||||
"DEPRECATED: Plugin contains a <reports/> section: this is IGNORED - please use <reporting/> instead." );
|
||||
getLog().error( "DEPRECATED: Plugin contains a <reports/> section: this is IGNORED - please use <reporting/> instead." );
|
||||
}
|
||||
|
||||
List reports = new ArrayList();
|
||||
|
@ -1104,8 +1099,8 @@ subprojects...
|
|||
continue;
|
||||
}
|
||||
|
||||
String key = currentFile.substring( currentFile.indexOf( File.separator ) + 1,
|
||||
currentFile.lastIndexOf( "." ) );
|
||||
String key = currentFile.substring( currentFile.indexOf( File.separator ) + 1, currentFile
|
||||
.lastIndexOf( "." ) );
|
||||
|
||||
List tmp = (List) duplicate.get( key.toLowerCase() );
|
||||
if ( tmp == null )
|
||||
|
@ -1116,4 +1111,76 @@ subprojects...
|
|||
tmp.add( currentFile );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an <code>Exception</code> message if a file is duplicate.
|
||||
*
|
||||
* @param duplicate a map of duplicate files
|
||||
* @param locale the current locale
|
||||
* @return the Message to throw
|
||||
*/
|
||||
private String createDuplicateExceptionMsg( Map duplicate, Locale locale )
|
||||
{
|
||||
if ( duplicate.size() > 0 )
|
||||
{
|
||||
StringBuffer sb = null;
|
||||
|
||||
for ( Iterator it = duplicate.entrySet().iterator(); it.hasNext(); )
|
||||
{
|
||||
Map.Entry entry = (Map.Entry) it.next();
|
||||
Collection values = (Collection) entry.getValue();
|
||||
|
||||
if ( values.size() > 1 )
|
||||
{
|
||||
if ( sb == null )
|
||||
{
|
||||
sb = new StringBuffer( "Some files are duplicates in the site directory or in the generated-site directory. " );
|
||||
sb.append( "\n" );
|
||||
sb.append( "Review the following files for the \"" + getDisplayLanguage( locale )
|
||||
+ "\" version:" );
|
||||
}
|
||||
|
||||
sb.append( "\n" );
|
||||
sb.append( entry.getKey() );
|
||||
sb.append( "\n" );
|
||||
|
||||
for ( Iterator it2 = values.iterator(); it2.hasNext(); )
|
||||
{
|
||||
String current = (String) it2.next();
|
||||
|
||||
sb.append( "\t" );
|
||||
sb.append( current );
|
||||
|
||||
if ( it2.hasNext() )
|
||||
{
|
||||
sb.append( "\n" );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( sb != null )
|
||||
{
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the <code>display language</code> for the given locale or "Default"
|
||||
*
|
||||
* @param locale
|
||||
* @return the display language in English or "Default" if the locale is the same of the default locale
|
||||
*/
|
||||
private String getDisplayLanguage( Locale locale )
|
||||
{
|
||||
if ( !locale.getLanguage().equals( defaultLocale.getLanguage() ) )
|
||||
{
|
||||
return locale.getDisplayLanguage( Locale.ENGLISH );
|
||||
}
|
||||
|
||||
return "Default";
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue