From 64a704b7b7e854c0af2b0094596929687b13a724 Mon Sep 17 00:00:00 2001 From: Vincent Siveton Date: Thu, 14 Jul 2005 04:07:08 +0000 Subject: [PATCH] MNG-582: generate an index.html git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@218981 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/maven/doxia/DoxiaMojo.java | 152 +++++++++++++++++- .../main/resources/site-plugin_en.properties | 18 +++ .../main/resources/site-plugin_fr.properties | 20 ++- 3 files changed, 187 insertions(+), 3 deletions(-) diff --git a/maven-plugins/maven-site-plugin/src/main/java/org/apache/maven/doxia/DoxiaMojo.java b/maven-plugins/maven-site-plugin/src/main/java/org/apache/maven/doxia/DoxiaMojo.java index 7f5dc8bd84..221a387f42 100644 --- a/maven-plugins/maven-site-plugin/src/main/java/org/apache/maven/doxia/DoxiaMojo.java +++ b/maven-plugins/maven-site-plugin/src/main/java/org/apache/maven/doxia/DoxiaMojo.java @@ -37,10 +37,12 @@ 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 void execute() File localeOutputDirectory = getOuputDirectory( locale ); + // Safety + if ( !localeOutputDirectory.exists() ) + { + localeOutputDirectory.mkdirs(); + } + //Generate reports if ( reports != null ) { @@ -283,14 +311,14 @@ public void execute() } } - // 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 void execute() 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 @@ private InputStream getSiteDescriptor( List reports, Locale locale ) 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 { diff --git a/maven-plugins/maven-site-plugin/src/main/resources/site-plugin_en.properties b/maven-plugins/maven-site-plugin/src/main/resources/site-plugin_en.properties index e72f7f18c5..2e65bd34e1 100644 --- a/maven-plugins/maven-site-plugin/src/main/resources/site-plugin_en.properties +++ b/maven-plugins/maven-site-plugin/src/main/resources/site-plugin_en.properties @@ -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. diff --git a/maven-plugins/maven-site-plugin/src/main/resources/site-plugin_fr.properties b/maven-plugins/maven-site-plugin/src/main/resources/site-plugin_fr.properties index e6a95ce1c4..7e3fa6daec 100644 --- a/maven-plugins/maven-site-plugin/src/main/resources/site-plugin_fr.properties +++ b/maven-plugins/maven-site-plugin/src/main/resources/site-plugin_fr.properties @@ -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.