mirror of https://github.com/apache/maven.git
refactor duplicate code
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@219990 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
82cc3271a2
commit
5565016f24
|
@ -19,6 +19,7 @@ package org.apache.maven.doxia;
|
|||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.apache.maven.model.ReportPlugin;
|
||||
import org.apache.maven.model.ReportSet;
|
||||
import org.apache.maven.plugin.AbstractMojo;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
|
@ -77,8 +78,10 @@ public class DoxiaMojo
|
|||
|
||||
private static final String DEFAULT_TEMPLATE = RESOURCE_DIR + "/maven-site.vm";
|
||||
|
||||
/** Patterns which should be excluded by default. */
|
||||
private static final String[] DEFAULT_EXCLUDES = new String[] {
|
||||
/**
|
||||
* Patterns which should be excluded by default.
|
||||
*/
|
||||
private static final String[] DEFAULT_EXCLUDES = new String[]{
|
||||
// Miscellaneous typical temporary files
|
||||
"**/*~", "**/#*#", "**/.#*", "**/%*%", "**/._*",
|
||||
|
||||
|
@ -95,7 +98,7 @@ public class DoxiaMojo
|
|||
"**/.svn", "**/.svn/**",
|
||||
|
||||
// Mac
|
||||
"**/.DS_Store" };
|
||||
"**/.DS_Store"};
|
||||
|
||||
/**
|
||||
* @parameter expression="${settings}"
|
||||
|
@ -219,7 +222,7 @@ public class DoxiaMojo
|
|||
}
|
||||
catch ( MalformedURLException e )
|
||||
{
|
||||
throw new MojoExecutionException( templateDirectory + " isn't a valid URL." );
|
||||
throw new MojoExecutionException( templateDirectory + " isn't a valid URL.", e );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -315,8 +318,8 @@ public class DoxiaMojo
|
|||
File generatedSiteFile = new File( generatedSiteDirectory );
|
||||
if ( generatedSiteFile.exists() )
|
||||
{
|
||||
siteRenderer.render( generatedSiteFile, localeOutputDirectory,
|
||||
getSiteDescriptor( reports, locale ), template, attributes, locale );
|
||||
siteRenderer.render( generatedSiteFile, localeOutputDirectory, getSiteDescriptor( reports, locale ),
|
||||
template, attributes, locale );
|
||||
}
|
||||
|
||||
// Generate static site
|
||||
|
@ -344,11 +347,11 @@ public class DoxiaMojo
|
|||
getLog().info( "Ignoring the index file generation." );
|
||||
}
|
||||
|
||||
siteRenderer.render( siteDirectoryFile, localeOutputDirectory,
|
||||
getSiteDescriptor( reports, locale ), template, attributes, locale );
|
||||
siteRenderer.render( siteDirectoryFile, localeOutputDirectory, getSiteDescriptor( reports, locale ),
|
||||
template, attributes, locale );
|
||||
|
||||
siteRenderer.render( siteDirectoryFile, localeOutputDirectory,
|
||||
getSiteDescriptor( reports, locale ), template, attributes, locale );
|
||||
siteRenderer.render( siteDirectoryFile, localeOutputDirectory, getSiteDescriptor( reports, locale ),
|
||||
template, attributes, locale );
|
||||
|
||||
File cssDirectory = new File( siteDirectory, "css" );
|
||||
File imagesDirectory = new File( siteDirectory, "images" );
|
||||
|
@ -402,9 +405,8 @@ public class DoxiaMojo
|
|||
}
|
||||
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." );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -413,49 +415,44 @@ public class DoxiaMojo
|
|||
{
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append( "<menu name=\"Project Documentation\">\n" );
|
||||
buffer.append(
|
||||
" <item name=\"" + i18n.getString( "site-plugin", locale, "report.menu.about" ) + " " +
|
||||
project.getName() + "\" href=\"/index.html\"/>\n" );
|
||||
buffer.append( " <item name=\"" );
|
||||
buffer.append( i18n.getString( "site-plugin", locale, "report.menu.about" ) );
|
||||
buffer.append( " " );
|
||||
buffer.append( project.getName() );
|
||||
buffer.append( "\" href=\"/index.html\"/>\n" );
|
||||
|
||||
if ( projectInfos.size() > 0 )
|
||||
{
|
||||
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( locale ) + "\" href=\"/" + report.getOutputName() +
|
||||
".html\"/>\n" );
|
||||
}
|
||||
|
||||
buffer.append( " </item>\n" );
|
||||
}
|
||||
|
||||
if ( projectReports.size() > 0 )
|
||||
{
|
||||
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( locale ) + "\" href=\"/" + report.getOutputName() +
|
||||
".html\"/>\n" );
|
||||
}
|
||||
|
||||
buffer.append( " </item>\n" );
|
||||
}
|
||||
writeReportSubMenu( projectInfos, buffer, locale, "report.menu.projectinformation", "project-info.html" );
|
||||
writeReportSubMenu( projectReports, buffer, locale, "report.menu.projectreports", "maven-reports.html" );
|
||||
|
||||
buffer.append( "</menu>\n" );
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
private void writeReportSubMenu( List reports, StringBuffer buffer, Locale locale, String key, String indexFilename )
|
||||
{
|
||||
if ( reports.size() > 0 )
|
||||
{
|
||||
buffer.append( " <item name=\"" );
|
||||
buffer.append( i18n.getString( "site-plugin", locale, key ) );
|
||||
buffer.append( "\" href=\"/" );
|
||||
buffer.append( indexFilename );
|
||||
buffer.append( "\" collapse=\"true\">\n" );
|
||||
|
||||
for ( Iterator i = reports.iterator(); i.hasNext(); )
|
||||
{
|
||||
MavenReport report = (MavenReport) i.next();
|
||||
buffer.append( " <item name=\"" );
|
||||
buffer.append( report.getName( locale ) );
|
||||
buffer.append( "\" href=\"/" );
|
||||
buffer.append( report.getOutputName() );
|
||||
buffer.append( ".html\"/>\n" );
|
||||
}
|
||||
|
||||
buffer.append( " </item>\n" );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo should only be needed once
|
||||
*/
|
||||
|
@ -464,7 +461,7 @@ public class DoxiaMojo
|
|||
{
|
||||
File siteDescriptor = new File( siteDirectory, "site_" + locale.getLanguage() + ".xml" );
|
||||
|
||||
String siteDescriptorContent = "";
|
||||
String siteDescriptorContent;
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -536,19 +533,23 @@ public class DoxiaMojo
|
|||
{
|
||||
getLog().debug( "Try to find an index file in the directory=[" + siteDirectoryFile + "]" );
|
||||
|
||||
File[] directories = siteDirectoryFile.listFiles( new FileFilter() {
|
||||
public boolean accept(File file) {
|
||||
for ( int i = 0; i < DEFAULT_EXCLUDES.length; i++) {
|
||||
if ( SelectorUtils.matchPath( DEFAULT_EXCLUDES[i], file.getName() ) ) {
|
||||
File[] directories = siteDirectoryFile.listFiles( new FileFilter()
|
||||
{
|
||||
public boolean accept( File file )
|
||||
{
|
||||
for ( int i = 0; i < DEFAULT_EXCLUDES.length; i++ )
|
||||
{
|
||||
if ( SelectorUtils.matchPath( DEFAULT_EXCLUDES[i], file.getName() ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return file.isDirectory();
|
||||
}
|
||||
});
|
||||
} );
|
||||
|
||||
if ( ( directories == null ) || ( directories.length == 0 ) )
|
||||
if ( directories == null || directories.length == 0 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -560,15 +561,16 @@ public class DoxiaMojo
|
|||
|
||||
if ( indexes.size() > 1 )
|
||||
{
|
||||
getLog().warn( "More than one index file exists in this directory [" + directories[i].getAbsolutePath() + "]." );
|
||||
getLog().warn(
|
||||
"More than one index file exists in this directory [" + directories[i].getAbsolutePath() + "]." );
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( indexes.size() == 1 )
|
||||
{
|
||||
getLog().debug( "Found [" + indexes.get(0) + "]" );
|
||||
getLog().debug( "Found [" + indexes.get( 0 ) + "]" );
|
||||
|
||||
indexFound.add(indexes.get(0));
|
||||
indexFound.add( indexes.get( 0 ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -904,7 +906,7 @@ public class DoxiaMojo
|
|||
{
|
||||
for ( Iterator it = reportPlugins.iterator(); it.hasNext(); )
|
||||
{
|
||||
org.apache.maven.model.ReportPlugin reportPlugin = (org.apache.maven.model.ReportPlugin) it.next();
|
||||
ReportPlugin reportPlugin = (ReportPlugin) it.next();
|
||||
|
||||
// try
|
||||
// {
|
||||
|
@ -927,11 +929,7 @@ public class DoxiaMojo
|
|||
|
||||
if ( reportSets == null || reportSets.isEmpty() )
|
||||
{
|
||||
reportsList = pluginManager.getReports( reportPlugin,
|
||||
null,
|
||||
project,
|
||||
session,
|
||||
localRepository );
|
||||
reportsList = pluginManager.getReports( reportPlugin, null, project, session, localRepository );
|
||||
|
||||
}
|
||||
else
|
||||
|
@ -940,10 +938,7 @@ public class DoxiaMojo
|
|||
{
|
||||
ReportSet reportSet = (ReportSet) j.next();
|
||||
|
||||
reportsList = pluginManager.getReports( reportPlugin,
|
||||
reportSet,
|
||||
project,
|
||||
session,
|
||||
reportsList = pluginManager.getReports( reportPlugin, reportSet, project, session,
|
||||
localRepository );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue