in src/main/java/org/apache/maven/doxia/plugin/DoxiaRenderBooksMojo.java [123:252]
public void execute()
throws MojoExecutionException, MojoFailureException
{
for ( Book book : books )
{
// ----------------------------------------------------------------------
// Validate
// ----------------------------------------------------------------------
if ( StringUtils.isEmpty( book.getDescriptor() ) )
{
throw new MojoFailureException( "Invalid configuration: "
+ "The book is required to have a descriptor set." );
}
if ( StringUtils.isEmpty( book.getDirectory() ) )
{
throw new MojoFailureException( "Invalid configuration: "
+ "The book is required to have a directory set." );
}
if ( book.getFormats() == null || book.getFormats().size() == 0 )
{
throw new MojoFailureException( "Invalid configuration: "
+ "The book is required to have at least one format set." );
}
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
File descriptor = new File( basedir, book.getDescriptor() );
String includes;
if ( book.getIncludes() != null )
{
includes = StringUtils.join( book.getIncludes().iterator(), "," );
}
else
{
includes = "**/*";
}
String excludes = "";
if ( book.getExcludes() != null )
{
excludes = StringUtils.join( book.getExcludes().iterator(), "," );
}
// ----------------------------------------------------------------------
// Find all the files to pass to the renderer.
// ----------------------------------------------------------------------
if ( getLog().isDebugEnabled() )
{
getLog().debug( "Locating files to include in the book:" );
getLog().debug( "Basedir: " + basedir );
getLog().debug( "Includes: " + includes );
getLog().debug( "Excludes: " + excludes );
}
List<File> files;
try
{
files = FileUtils.getFiles( new File( basedir, book.getDirectory() ), includes, excludes );
}
catch ( IOException e )
{
throw new MojoExecutionException( "Error while looking for input files. " + "Basedir="
+ basedir.getAbsolutePath() + ", " + "includes=" + includes + ", " + "excludes=" + excludes, e );
}
// -----------------------------------------------------------------------
// Load the model
// -----------------------------------------------------------------------
BookModel bookModel;
try
{
bookModel = bookDoxia.loadBook( descriptor );
}
catch ( InvalidBookDescriptorException e )
{
throw new MojoFailureException( "Invalid book descriptor: " + LINE_SEPARATOR
+ formatResult( e.getValidationResult() ) );
}
catch ( BookDoxiaException e )
{
throw new MojoExecutionException( "Error while loading the book descriptor", e );
}
// -----------------------------------------------------------------------
// Render the book in all the formats
// -----------------------------------------------------------------------
List<Locale> localesList = siteTool.getAvailableLocales( locales );
// Default is first in the list
Locale defaultLocale = localesList.get( 0 );
Locale.setDefault( defaultLocale );
for ( Locale locale : localesList )
{
for ( Format format : book.getFormats() )
{
File outputDirectory = new File( generatedDocs, format.getId() );
File directory = new File( outputDirectory + "/" + locale.toString(), bookModel.getId() );
if ( locale.equals( defaultLocale ) )
{
directory = new File( outputDirectory, bookModel.getId() );
}
try
{
bookDoxia.renderBook( bookModel, format.getId(), files, directory, locale,
getInputEncoding(), getOutputEncoding() );
}
catch ( BookDoxiaException e )
{
throw new MojoExecutionException( "Error while generating book in format '"
+ format.getId() + "'.", e );
}
}
}
}
}