Author: hboutemy Date: Thu Apr 2 21:43:44 2015 New Revision: 1670982 URL: http://svn.apache.org/r1670982 Log: [DOXIASITETOOLS-102] Allow multiple extensions for given format Submitted by: Petar Tahchiev
Modified: maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/DefaultSiteRenderer.java maven/doxia/doxia-sitetools/trunk/pom.xml Modified: maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/DefaultSiteRenderer.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/DefaultSiteRenderer.java?rev=1670982&r1=1670981&r2=1670982&view=diff ============================================================================== --- maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/DefaultSiteRenderer.java (original) +++ maven/doxia/doxia-sitetools/trunk/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/DefaultSiteRenderer.java Thu Apr 2 21:43:44 2015 @@ -53,6 +53,8 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipException; import java.util.zip.ZipFile; +import org.apache.commons.lang.ArrayUtils; + import org.apache.maven.doxia.Doxia; import org.apache.maven.doxia.logging.PlexusLoggerWrapper; import org.apache.maven.doxia.parser.ParseException; @@ -194,86 +196,93 @@ public class DefaultSiteRenderer if ( moduleBasedir.exists() ) { List<String> allFiles = FileUtils.getFileNames( moduleBasedir, "**/*.*", excludes, false ); - - String fullExtension = "." + module.getExtension(); - List<String> docs = new LinkedList<String>( allFiles ); - // Take care of extension case - for ( Iterator<String> it = docs.iterator(); it.hasNext(); ) + if ( !ArrayUtils.isEmpty( module.getExtensions() ) ) { - String name = it.next(); - - if ( !endsWithIgnoreCase( name, fullExtension ) ) + for ( String extension : module.getExtensions() ) { - it.remove(); - } - } - List<String> velocityFiles = new LinkedList<String>( allFiles ); - // *.xml.vm - fullExtension += ".vm"; - for ( Iterator<String> it = velocityFiles.iterator(); it.hasNext(); ) - { - String name = it.next(); + String fullExtension = "." + extension; + List<String> docs = new LinkedList<String>( allFiles ); + // Take care of extension case + for ( Iterator<String> it = docs.iterator(); it.hasNext(); ) + { + String name = it.next(); - if ( !endsWithIgnoreCase( name, fullExtension ) ) - { - it.remove(); - } - } - docs.addAll( velocityFiles ); + if ( !endsWithIgnoreCase( name, fullExtension ) ) + { + it.remove(); + } + } - for ( String doc : docs ) - { - RenderingContext context = - new RenderingContext( moduleBasedir, doc, module.getParserId(), module.getExtension() ); + List<String> velocityFiles = new LinkedList<String>( allFiles ); + // *.xml.vm + fullExtension += ".vm"; + for ( Iterator<String> it = velocityFiles.iterator(); it.hasNext(); ) + { + String name = it.next(); - // TODO: DOXIA-111: we need a general filter here that knows how to alter the context - if ( doc.substring( doc.length() - 3 ).equalsIgnoreCase( ".vm" ) ) - { - context.setAttribute( "velocity", "true" ); - } + if ( !endsWithIgnoreCase( name, fullExtension ) ) + { + it.remove(); + } + } + docs.addAll( velocityFiles ); - String key = context.getOutputName(); - key = StringUtils.replace( key, "\\", "/" ); + for ( String doc : docs ) + { + RenderingContext context = + new RenderingContext( moduleBasedir, doc, module.getParserId(), extension ); - if ( files.containsKey( key ) ) - { - DocumentRenderer renderer = files.get( key ); + // TODO: DOXIA-111: we need a general filter here that knows how to alter the context + if ( doc.substring( doc.length() - 3 ).equalsIgnoreCase( ".vm" ) ) + { + context.setAttribute( "velocity", "true" ); + } - RenderingContext originalContext = renderer.getRenderingContext(); + String key = context.getOutputName(); + key = StringUtils.replace( key, "\\", "/" ); - File originalDoc = new File( originalContext.getBasedir(), originalContext.getInputName() ); + if ( files.containsKey( key ) ) + { + DocumentRenderer renderer = files.get( key ); - throw new RendererException( "File '" + module.getSourceDirectory() + File.separator + doc - + "' clashes with existing '" + originalDoc + "'." ); - } - // ----------------------------------------------------------------------- - // Handle key without case differences - // ----------------------------------------------------------------------- - for ( Map.Entry<String, DocumentRenderer> entry : files.entrySet() ) - { - if ( entry.getKey().equalsIgnoreCase( key ) ) - { - RenderingContext originalContext = entry.getValue().getRenderingContext(); + RenderingContext originalContext = renderer.getRenderingContext(); - File originalDoc = new File( originalContext.getBasedir(), originalContext.getInputName() ); + File originalDoc = new File( originalContext.getBasedir(), originalContext.getInputName() ); - if ( Os.isFamily( Os.FAMILY_WINDOWS ) ) - { - throw new RendererException( "File '" + module.getSourceDirectory() + File.separator - + doc + "' clashes with existing '" + originalDoc + "'." ); + throw new RendererException( "File '" + module.getSourceDirectory() + File.separator + doc + + "' clashes with existing '" + originalDoc + "'." ); } - - if ( getLogger().isWarnEnabled() ) + // ----------------------------------------------------------------------- + // Handle key without case differences + // ----------------------------------------------------------------------- + for ( Map.Entry<String, DocumentRenderer> entry : files.entrySet() ) { - getLogger().warn( - "File '" + module.getSourceDirectory() + File.separator + doc - + "' could clash with existing '" + originalDoc + "'." ); + if ( entry.getKey().equalsIgnoreCase( key ) ) + { + RenderingContext originalContext = entry.getValue().getRenderingContext(); + + File originalDoc = new File( originalContext.getBasedir(), + originalContext.getInputName() ); + + if ( Os.isFamily( Os.FAMILY_WINDOWS ) ) + { + throw new RendererException( "File '" + module.getSourceDirectory() + File.separator + + doc + "' clashes with existing '" + originalDoc + "'." ); + } + + if ( getLogger().isWarnEnabled() ) + { + getLogger().warn( + "File '" + module.getSourceDirectory() + File.separator + doc + + "' could clash with existing '" + originalDoc + "'." ); + } + } } + + files.put( key, new DoxiaDocumentRenderer( context ) ); } } - - files.put( key, new DoxiaDocumentRenderer( context ) ); } } } Modified: maven/doxia/doxia-sitetools/trunk/pom.xml URL: http://svn.apache.org/viewvc/maven/doxia/doxia-sitetools/trunk/pom.xml?rev=1670982&r1=1670981&r2=1670982&view=diff ============================================================================== --- maven/doxia/doxia-sitetools/trunk/pom.xml (original) +++ maven/doxia/doxia-sitetools/trunk/pom.xml Thu Apr 2 21:43:44 2015 @@ -181,7 +181,7 @@ under the License. </distributionManagement> <properties> - <doxiaVersion>1.6</doxiaVersion> + <doxiaVersion>1.7-SNAPSHOT</doxiaVersion> <maven.site.path>doxia-sitetools-archives/doxia-sitetools-LATEST</maven.site.path> </properties>