MNG-582: generate an index.html

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@218981 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Vincent Siveton 2005-07-14 04:07:08 +00:00
parent 99c8250b8f
commit 64a704b7b7
3 changed files with 187 additions and 3 deletions

View File

@ -37,10 +37,12 @@ import org.codehaus.plexus.siterenderer.sink.SiteRendererSink;
import org.codehaus.plexus.util.DirectoryScanner;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.SelectorUtils;
import org.codehaus.plexus.util.StringInputStream;
import org.codehaus.plexus.util.StringUtils;
import java.io.File;
import java.io.FileFilter;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
@ -75,6 +77,26 @@ 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[] {
// Miscellaneous typical temporary files
"**/*~", "**/#*#", "**/.#*", "**/%*%", "**/._*",
// CVS
"**/CVS", "**/CVS/**", "**/.cvsignore",
// SCCS
"**/SCCS", "**/SCCS/**",
// Visual SourceSafe
"**/vssver.scc",
// Subversion
"**/.svn", "**/.svn/**",
// Mac
"**/.DS_Store" };
/**
* @parameter expression="${settings}"
* @required
@ -227,6 +249,12 @@ public class DoxiaMojo
File localeOutputDirectory = getOuputDirectory( locale );
// Safety
if ( !localeOutputDirectory.exists() )
{
localeOutputDirectory.mkdirs();
}
//Generate reports
if ( reports != null )
{
@ -283,14 +311,14 @@ public class DoxiaMojo
}
}
// Generated Site Directory
// 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;
@ -305,6 +333,17 @@ public class DoxiaMojo
siteDirectoryFile = new File( siteDirectory, locale.getLanguage() );
}
// Try to generate the index.html
if ( !indexExists( siteDirectoryFile ) )
{
getLog().info( "Generate an index file." );
generateIndexPage( getSiteDescriptor( reports, locale ), locale );
}
else
{
getLog().info( "Ignoring the index file generation." );
}
siteRenderer.render( siteDirectoryFile, localeOutputDirectory,
getSiteDescriptor( reports, locale ), template, attributes, locale );
@ -484,6 +523,115 @@ public class DoxiaMojo
return new StringInputStream( siteDescriptorContent );
}
/**
* Try to find a file called "index" in each sub-directory from the site directory.
* We don't care about the extension.
*
* @param siteDirectoryFile the site directory
* @return true if an index file was found, false otherwise
* @throws Exception if any
*/
private boolean indexExists( File siteDirectoryFile )
throws Exception
{
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() ) ) {
return false;
}
}
return file.isDirectory();
}
});
List indexFound = new ArrayList();
for ( int i = 0; i < directories.length; i++ )
{
List indexes = FileUtils.getFiles( directories[i], "index.*", null, true );
if ( indexes.size() > 1 )
{
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) + "]" );
indexFound.add(indexes.get(0));
}
}
if ( indexFound.size() > 1 )
{
// TODO throw an Exception?
getLog().warn( "More than one index file exists in the project site directory. Checks the result." );
return true;
}
if ( indexFound.size() == 1 )
{
getLog().warn( "One index file was found in the project site directory." );
return true;
}
return false;
}
/**
* Generated an index page.
*
* @param siteDescriptor
* @param locale
* @throws Exception
*/
private void generateIndexPage( InputStream siteDescriptor, Locale locale )
throws Exception
{
String outputFileName = "index.html";
SiteRendererSink sink = siteRenderer.createSink( new File( siteDirectory ), outputFileName, siteDescriptor );
String title = i18n.getString( "site-plugin", locale, "report.index.title" ).trim() + " " + project.getName();
sink.head();
sink.title();
sink.text( title );
sink.title_();
sink.head_();
sink.body();
sink.section1();
sink.sectionTitle1();
sink.text( title );
sink.sectionTitle1_();
sink.paragraph();
if ( project.getDescription() != null )
{
// TODO How to handle i18n?
sink.text( project.getDescription() );
}
else
{
sink.text( i18n.getString( "site-plugin", locale, "report.index.nodescription" ) );
}
sink.paragraph_();
sink.body_();
sink.flush();
sink.close();
siteRenderer.generateDocument( new FileWriter( new File( getOuputDirectory( locale ), outputFileName ) ),
template, attributes, sink, locale );
}
private void generateProjectInfoPage( InputStream siteDescriptor, Locale locale )
throws Exception
{

View File

@ -1,3 +1,19 @@
# -------------------------------------------------------------------
# Copyright 2001-2005 The Apache Software Foundation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# -------------------------------------------------------------------
template.lastpublished=Last Published
template.builtby=Built by
report.project.title=Maven Generated Reports
@ -15,3 +31,5 @@ report.information.column.document=Document
report.menu.about=About
report.menu.projectinformation=Project Info
report.menu.projectreports=Project Reports
report.index.title=Welcome to
report.index.nodescription=There are no description currently associated with this project.

View File

@ -1,3 +1,19 @@
# -------------------------------------------------------------------
# Copyright 2001-2005 The Apache Software Foundation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# -------------------------------------------------------------------
template.lastpublished=Dernière publication
template.builtby=Produit par
report.project.title=Rapport générés par Maven
@ -8,10 +24,12 @@ 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.description2=le projet lui-même.
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
report.index.title=Bienvenue dans le projet
report.index.nodescription=Il n'y a aucune description actuellement liée à ce projet.