You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by vs...@apache.org on 2005/07/29 13:52:46 UTC
svn commit: r226350 -
/maven/components/trunk/maven-plugins/maven-site-plugin/src/main/java/org/apache/maven/doxia/DoxiaMojo.java
Author: vsiveton
Date: Fri Jul 29 04:52:43 2005
New Revision: 226350
URL: http://svn.apache.org/viewcvs?rev=226350&view=rev
Log:
Throw an exception if files in the site directory or in the generated site directory are duplicates
Modified:
maven/components/trunk/maven-plugins/maven-site-plugin/src/main/java/org/apache/maven/doxia/DoxiaMojo.java
Modified: maven/components/trunk/maven-plugins/maven-site-plugin/src/main/java/org/apache/maven/doxia/DoxiaMojo.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-site-plugin/src/main/java/org/apache/maven/doxia/DoxiaMojo.java?rev=226350&r1=226349&r2=226350&view=diff
==============================================================================
--- maven/components/trunk/maven-plugins/maven-site-plugin/src/main/java/org/apache/maven/doxia/DoxiaMojo.java (original)
+++ maven/components/trunk/maven-plugins/maven-site-plugin/src/main/java/org/apache/maven/doxia/DoxiaMojo.java Fri Jul 29 04:52:43 2005
@@ -36,12 +36,10 @@
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;
@@ -55,6 +53,7 @@
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@@ -76,9 +75,19 @@
private static final String DEFAULT_TEMPLATE = RESOURCE_DIR + "/maven-site.vm";
+ /** OutputName of all project info report files generated by Maven */
+ private static final String[] PROJECT_INFO_FILES = new String[] { "integration",
+ "dependencies",
+ "issue-tracking",
+ "license",
+ "mail-lists",
+ "source-repository",
+ "team-list" };
+
/**
* Patterns which should be excluded by default.
*/
+ // TODO Push me in AbstractMojo class and remove me from AbstractMavenReport class
private static final String[] DEFAULT_EXCLUDES = new String[]{
// Miscellaneous typical temporary files
"**/*~", "**/#*#", "**/.#*", "**/%*%", "**/._*",
@@ -185,6 +194,9 @@
private List localesList = new ArrayList();
+ /**
+ * @see org.apache.maven.plugin.Mojo#execute()
+ */
public void execute()
throws MojoExecutionException
{
@@ -240,9 +252,9 @@
}
}
- for ( Iterator i = localesList.iterator(); i.hasNext(); )
+ for ( Iterator iterator = localesList.iterator(); iterator.hasNext(); )
{
- Locale locale = (Locale) i.next();
+ Locale locale = (Locale) iterator.next();
File localeOutputDirectory = getOuputDirectory( locale );
@@ -333,17 +345,78 @@
siteDirectoryFile = new File( siteDirectory, locale.getLanguage() );
}
+ // Try to find duplicate files
+ Map duplicate = new LinkedHashMap();
+ if ( siteDirectoryFile.exists() )
+ {
+ tryToFindDuplicates( siteDirectoryFile, duplicate );
+ }
+ if ( generatedSiteFile.exists() )
+ {
+ tryToFindDuplicates( generatedSiteFile, duplicate );
+ }
+
+ // Exception if a file is duplicate
+ if ( ( duplicate.entrySet() != null ) && ( duplicate.entrySet().size() > 0 ) )
+ {
+ StringBuffer sb = null;
+
+ for ( Iterator it = duplicate.entrySet().iterator(); it.hasNext(); )
+ {
+ Map.Entry entry = (Map.Entry) it.next();
+ List values = (List) entry.getValue();
+
+ if ( values != null && values.size() > 1 )
+ {
+ if ( sb == null )
+ {
+ sb = new StringBuffer( "Some files are duplicates in the site directory or in the generated-site directory. "
+ + "Review the following files:" );
+ }
+
+ sb.append( "\n" ).append( entry.getKey() ).append( "\n" );
+
+ for ( Iterator it2 = values.iterator(); it2.hasNext(); )
+ {
+ String current = (String) it2.next();
+ sb.append( "\t" ).append( current );
+ if ( it2.hasNext() )
+ {
+ sb.append( "\n" );
+ }
+ }
+ }
+ }
+
+ if ( sb != null )
+ {
+ throw new MavenReportException( sb.toString() );
+ }
+ }
+
// Try to generate the index.html
- if ( !indexExists( siteDirectoryFile ) )
+ if ( duplicate.get( "index" ) != null )
{
- getLog().info( "Generate an index file." );
- generateIndexPage( getSiteDescriptor( reports, locale ), locale );
+ getLog().info( "Ignoring the index file generation." );
}
else
{
- getLog().info( "Ignoring the index file generation." );
+ getLog().info( "Generate an index file." );
+ generateIndexPage( getSiteDescriptor( reports, locale ), locale );
}
+ // Log if a user override a project info report file
+ for ( int i = 0; i < PROJECT_INFO_FILES.length; i++)
+ {
+ if ( projectInfos.size() > 0 )
+ {
+ if ( duplicate.get( PROJECT_INFO_FILES[i] ) != null )
+ {
+ getLog().info( "Override the generated files \"" + PROJECT_INFO_FILES[i] + "\"." );
+ }
+ }
+ }
+
siteRenderer.render( siteDirectoryFile, localeOutputDirectory, getSiteDescriptor( reports, locale ),
template, attributes, locale );
@@ -411,6 +484,7 @@
private String getReportsMenu( Locale locale )
{
StringBuffer buffer = new StringBuffer();
+ // TODO i18n
buffer.append( "<menu name=\"Project Documentation\">\n" );
buffer.append( " <item name=\"" );
buffer.append( i18n.getString( "site-plugin", locale, "report.menu.about" ) );
@@ -518,85 +592,6 @@
}
/**
- * 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();
- }
- } );
-
- if ( directories == null || directories.length == 0 )
- {
- return false;
- }
-
- 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 )
- {
- StringBuffer sb = new StringBuffer( "\n" );
- for ( Iterator it = indexFound.iterator(); it.hasNext(); )
- {
- sb.append( " * " );
- sb.append( ( (File) it.next() ).getAbsolutePath() );
- if ( it.hasNext() )
- {
- sb.append( "\n" );
- }
- }
- throw new MavenReportException( "More than one index file exists in the project site directory. "
- + "You have to delete one of these files: " + sb.toString() );
- }
-
- 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
@@ -798,7 +793,7 @@
template, attributes, sink, locale );
}
- private void copyResources( File outputDirectory )
+ private void copyResources( File outputDir )
throws Exception
{
InputStream resourceList = getStream( RESOURCE_DIR + "/resources.txt" );
@@ -819,7 +814,7 @@
"The resource " + line + " doesn't exists in " + DEFAULT_TEMPLATE + " template." );
}
- File outputFile = new File( outputDirectory, line );
+ File outputFile = new File( outputDir, line );
if ( !outputFile.getParentFile().exists() )
{
@@ -881,18 +876,14 @@
{
return new File( outputDirectory );
}
- else
+
+ Locale firstLocale = (Locale) localesList.get( 0 );
+ if ( locale.equals( firstLocale ) )
{
- Locale firstLocale = (Locale) localesList.get( 0 );
- if ( locale.equals( firstLocale ) )
- {
- return new File( outputDirectory );
- }
- else
- {
- return new File( outputDirectory, locale.getLanguage() );
- }
+ return new File( outputDirectory );
}
+
+ return new File( outputDirectory, locale.getLanguage() );
}
private List getReports()
@@ -957,5 +948,68 @@
}
}
return reports;
+ }
+
+ /**
+ * Convenience method that try to find duplicate files in a given directory.
+ * <p>The scan is case unsensitive.</p>
+ *
+ * @param directory the directory to scan
+ * @param duplicate the map to update
+ * @throws IOException if any
+ **/
+ private static void tryToFindDuplicates( File directory, Map duplicate )
+ throws IOException
+ {
+ if ( duplicate == null )
+ {
+ duplicate = new HashMap();
+ }
+
+ // The pattern as comma separated
+ StringBuffer excludePattern = new StringBuffer();
+ for ( int i = 0; i < DEFAULT_EXCLUDES.length; i++ )
+ {
+ excludePattern.append( DEFAULT_EXCLUDES[i] ).append( "," );
+ }
+ excludePattern.deleteCharAt( excludePattern.length() - 1 );
+
+ List siteFiles = FileUtils.getFileNames( directory, null, excludePattern.toString(), false, false );
+ for ( Iterator it = siteFiles.iterator(); it.hasNext(); )
+ {
+ String currentFile = ( (String) it.next() );
+
+ if ( currentFile.lastIndexOf( File.separator ) == -1 )
+ {
+ // ignore files directly in the directory
+ continue;
+ }
+
+ if ( currentFile.lastIndexOf( "." ) == -1 )
+ {
+ // ignore files without extension
+ continue;
+ }
+
+ String key = currentFile.substring( currentFile.indexOf( File.separator ) + 1,
+ currentFile.lastIndexOf( "." ) );
+
+ String filePattern = "**/" + key + ".*";
+
+ List files = FileUtils.getFileNames( directory, filePattern, excludePattern.toString(), true, false );
+ if ( ( files != null ) && ( files.size() > 0 ) )
+ {
+ List tmp = (List) duplicate.get( key.toLowerCase() );
+ if ( tmp == null )
+ {
+ tmp = new ArrayList();
+ }
+ if ( !tmp.containsAll( files ) )
+ {
+ tmp.addAll( files );
+ }
+ duplicate.put( key.toLowerCase(), tmp );
+ }
+ }
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org