Author: vsiveton Date: Mon May 14 17:27:10 2007 New Revision: 538027 URL: http://svn.apache.org/viewvc?view=rev&rev=538027 Log: o reorganization of code: separation between protected, private and private static methods o no code change
Modified: maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/AbstractJavadocMojo.java Modified: maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/AbstractJavadocMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/AbstractJavadocMojo.java?view=diff&rev=538027&r1=538026&r2=538027 ============================================================================== --- maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/AbstractJavadocMojo.java (original) +++ maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/AbstractJavadocMojo.java Mon May 14 17:27:10 2007 @@ -932,7 +932,7 @@ private String windowtitle; // ---------------------------------------------------------------------- - // + // protected methods // ---------------------------------------------------------------------- /** @@ -1352,61 +1352,8 @@ addFilesFromSource( files, sourceDirectory, excludedPackages ); } } - return files; - } - - /** - * Method to get the excluded source files from the javadoc and create the argument string - * that will be included in the javadoc commandline execution. - * - * @param sourcePaths the list of paths to the source files - * @return a String that contains the exclude argument that will be used by javadoc - */ - private String getExcludedPackages( List sourcePaths ) - { - List excludedNames = null; - - if ( StringUtils.isNotEmpty( sourcepath ) && StringUtils.isNotEmpty( subpackages ) ) - { - String[] excludedPackages = getExcludedPackages(); - String[] subpackagesList = subpackages.split( "[:]" ); - - excludedNames = getExcludedNames( sourcePaths, subpackagesList, excludedPackages ); - } - - String excludeArg = ""; - if ( StringUtils.isNotEmpty( subpackages ) && excludedNames != null ) - { - //add the excludedpackage names - for ( Iterator it = excludedNames.iterator(); it.hasNext(); ) - { - String str = (String) it.next(); - excludeArg = excludeArg + str; - - if ( it.hasNext() ) - { - excludeArg = excludeArg + ":"; - } - } - } - return excludeArg; - } - - /** - * Method to format the specified source paths that will be accepted by the javadoc tool. - * - * @param sourcePaths the list of paths to the source files that will be included in the javadoc - * @return a String that contains the formatted source path argument - */ - private String getSourcePath( List sourcePaths ) - { - String sourcePath = null; - if ( StringUtils.isEmpty( subpackages ) || StringUtils.isNotEmpty( sourcepath ) ) - { - sourcePath = StringUtils.join( sourcePaths.iterator(), File.pathSeparator ); - } - return sourcePath; + return files; } /** @@ -1469,56 +1416,87 @@ { sourcePaths = Arrays.asList( sourcepath.split( "[;]" ) ); } + return sourcePaths; } /** - * Method that removes the invalid directories in the specified source directories + * Method that indicates whether the javadoc can be generated or not. If the project does not contain any source + * files and no subpackages are specified, the plugin will terminate. * - * @param sourceDirs the list of source directories that will be validated - * @return a List of valid source directories + * @param files the project files + * @return a boolean that indicates whether javadoc report can be generated or not */ - // TODO: could be better aligned with JXR, including getFiles() vs hasSources that finds java files. - private static List pruneSourceDirs( List sourceDirs ) + protected boolean canGenerateReport( List files ) { - List pruned = new ArrayList( sourceDirs.size() ); - for ( Iterator i = sourceDirs.iterator(); i.hasNext(); ) + boolean canGenerate = true; + + if ( files.isEmpty() && StringUtils.isEmpty( subpackages ) ) { - String dir = (String) i.next(); - File directory = new File( dir ); - if ( directory.exists() && directory.isDirectory() ) + canGenerate = false; + } + + return canGenerate; + } + + // ---------------------------------------------------------------------- + // private methods + // ---------------------------------------------------------------------- + + /** + * Method to get the excluded source files from the javadoc and create the argument string + * that will be included in the javadoc commandline execution. + * + * @param sourcePaths the list of paths to the source files + * @return a String that contains the exclude argument that will be used by javadoc + */ + private String getExcludedPackages( List sourcePaths ) + { + List excludedNames = null; + + if ( StringUtils.isNotEmpty( sourcepath ) && StringUtils.isNotEmpty( subpackages ) ) + { + String[] excludedPackages = getExcludedPackages(); + String[] subpackagesList = subpackages.split( "[:]" ); + + excludedNames = getExcludedNames( sourcePaths, subpackagesList, excludedPackages ); + } + + String excludeArg = ""; + if ( StringUtils.isNotEmpty( subpackages ) && excludedNames != null ) + { + //add the excludedpackage names + for ( Iterator it = excludedNames.iterator(); it.hasNext(); ) { - if ( !pruned.contains( dir ) ) + String str = (String) it.next(); + excludeArg = excludeArg + str; + + if ( it.hasNext() ) { - pruned.add( dir ); + excludeArg = excludeArg + ":"; } } } - return pruned; + + return excludeArg; } /** - * Method that gets all the source files to be excluded from the javadoc on the given - * source paths. + * Method to format the specified source paths that will be accepted by the javadoc tool. * - * @param sourcePaths the path to the source files - * @param subpackagesList list of subpackages to be included in the javadoc - * @param excludedPackages the package names to be excluded in the javadoc - * @return a List of the source files to be excluded in the generated javadoc + * @param sourcePaths the list of paths to the source files that will be included in the javadoc + * @return a String that contains the formatted source path argument */ - private static List getExcludedNames( List sourcePaths, String[] subpackagesList, String[] excludedPackages ) + private String getSourcePath( List sourcePaths ) { - List excludedNames = new ArrayList(); - for ( Iterator i = sourcePaths.iterator(); i.hasNext(); ) + String sourcePath = null; + + if ( StringUtils.isEmpty( subpackages ) || StringUtils.isNotEmpty( sourcepath ) ) { - String path = (String) i.next(); - for ( int j = 0; j < subpackagesList.length; j++ ) - { - List excludes = getExcludedPackages( path, excludedPackages ); - excludedNames.addAll( excludes ); - } + sourcePath = StringUtils.join( sourcePaths.iterator(), File.pathSeparator ); } - return excludedNames; + + return sourcePath; } /** @@ -1540,6 +1518,7 @@ { excludePackages[i] = excludePackages[i].replace( '.', File.separatorChar ); } + return excludePackages; } @@ -1596,33 +1575,6 @@ } /** - * Copy from [EMAIL PROTECTED] MavenProject#getCompileArtifacts()} - * @param artifacts - * @return - */ - private static List getCompileArtifacts( Set artifacts ) - { - List list = new ArrayList( artifacts.size() ); - - for ( Iterator i = artifacts.iterator(); i.hasNext(); ) - { - Artifact a = (Artifact) i.next(); - - // TODO: classpath check doesn't belong here - that's the other method - if ( a.getArtifactHandler().isAddedToClasspath() ) - { - // TODO: let the scope handler deal with this - if ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) || Artifact.SCOPE_PROVIDED.equals( a.getScope() ) - || Artifact.SCOPE_SYSTEM.equals( a.getScope() ) ) - { - list.add( a ); - } - } - } - return list; - } - - /** * Method to put the artifacts in the hashmap. * * @param compileArtifactMap the hashmap that will contain the artifacts @@ -1727,6 +1679,7 @@ stylesheetfile = javadocOutputDirectory + File.separator + DEFAULT_CSS_NAME; } } + return stylesheetfile; } @@ -1750,6 +1703,7 @@ getLog().error( "Unrecognized access level to show '" + show + "'. Defaulting to protected." ); accessLevel = "-protected"; } + return accessLevel; } @@ -2021,58 +1975,6 @@ } /** - * Call the javadoc tool to have its version - * - * @param javadocExe - * @return the javadoc version as float - * @throws IOException if any - * @throws CommandLineException if any - */ - private static float getJavadocVersion( File javadocExe ) - throws IOException, CommandLineException - { - if ( !javadocExe.exists() || !javadocExe.isFile() ) - { - throw new IOException( "The javadoc executable '" + javadocExe + "' doesn't exist or is not a file. " ); - } - - Commandline cmd = new Commandline(); - cmd.setExecutable( javadocExe.getAbsolutePath() ); - cmd.setWorkingDirectory( javadocExe.getParentFile() ); - cmd.createArgument().setValue( "-J-fullversion" ); - - CommandLineUtils.StringStreamConsumer out = new CommandLineUtils.StringStreamConsumer(); - CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer(); - - int exitCode = CommandLineUtils.executeCommandLine( cmd, out, err ); - - if ( exitCode != 0 ) - { - StringBuffer msg = new StringBuffer( "Exit code: " + exitCode + " - " + err.getOutput() ); - msg.append( '\n' ); - msg.append( "Command line was:" + Commandline.toString( cmd.getCommandline() ) ); - throw new CommandLineException( msg.toString() ); - } - - /* - * Exemple: java full version "1.5.0_11-b03" - * - * @see com.sun.tools.javac.main.JavaCompiler#fullVersion() - */ - StringTokenizer token = new StringTokenizer( err.getOutput(), "\"" ); - token.nextToken(); - - String version = token.nextToken(); - String str = version.substring( 0, 3 ); - if ( version.length() >= 5 ) - { - str = str + version.substring( 4, 5 ); - } - - return Float.parseFloat( str ); - } - - /** * Is the Java or Javadoc version at least the requested version. * * @param requiredVersion the required version, for example 1.5f @@ -2242,89 +2144,31 @@ } /** - * Convenience method to wrap an argument value in quotes. Intended for values which may contain whitespaces. + * Convenience method to process offlineLink values as individual -linkoffline javadoc options * - * @param value the argument value. - * @return argument with quote + * @param arguments argument list */ - private static String quotedArgument( String value ) + private void addLinkofflineArguments( List arguments ) { - String arg = value; - if ( StringUtils.isNotEmpty( arg ) ) + if ( offlineLinks != null ) { - if ( arg.indexOf( "'" ) != -1 ) + for ( int i = 0; i < offlineLinks.size(); i++ ) { - arg = StringUtils.replace( arg, "'", "\\'" ); + OfflineLink offlineLink = (OfflineLink) offlineLinks.get( i ); + addArgIfNotEmpty( arguments, "-linkoffline", quotedPathArgument( offlineLink.getUrl() ) + " " + + quotedPathArgument( offlineLink.getLocation().getAbsolutePath() ), true ); } - arg = "'" + arg + "'"; } - - return arg; } /** - * Convenience method to format a path argument so that it is properly interpreted by the javadoc tool. Intended - * for path values which may contain whitespaces. + * Convenience method to process link values as individual -link javadoc options * - * @param value the argument value. - * @return path argument with quote + * @param arguments argument list */ - private static String quotedPathArgument( String value ) + private void addLinkArguments( List arguments ) { - String path = value; - - if ( StringUtils.isNotEmpty( path ) ) - { - path = path.replace( '\\', '/' ); - if ( path.indexOf( "\'" ) != -1 ) - { - String split[] = path.split( "\'" ); - path = ""; - - for ( int i = 0; i < split.length; i++ ) - { - if ( i != split.length - 1 ) - { - path = path + split[i] + "\\'"; - } - else - { - path = path + split[i]; - } - } - } - path = "'" + path + "'"; - } - - return path; - } - - /** - * Convenience method to process offlineLink values as individual -linkoffline javadoc options - * - * @param arguments argument list - */ - private void addLinkofflineArguments( List arguments ) - { - if ( offlineLinks != null ) - { - for ( int i = 0; i < offlineLinks.size(); i++ ) - { - OfflineLink offlineLink = (OfflineLink) offlineLinks.get( i ); - addArgIfNotEmpty( arguments, "-linkoffline", quotedPathArgument( offlineLink.getUrl() ) + " " - + quotedPathArgument( offlineLink.getLocation().getAbsolutePath() ), true ); - } - } - } - - /** - * Convenience method to process link values as individual -link javadoc options - * - * @param arguments argument list - */ - private void addLinkArguments( List arguments ) - { - if ( links != null ) + if ( links != null ) { for ( int i = 0; i < links.size(); i++ ) { @@ -2424,186 +2268,6 @@ } /** - * Convenience method that copy all <code>doc-files</code> directories from <code>javadocDir</code> - * to the <code>outputDirectory</code>. - * - * @param outputDirectory the output directory - * @param javadocDir the javadoc directory - * @throws java.io.IOException if any - */ - private static void copyJavadocResources( File outputDirectory, File javadocDir ) - throws IOException - { - if ( javadocDir.exists() && javadocDir.isDirectory() ) - { - List docFiles = FileUtils.getDirectoryNames( javadocDir, "**/doc-files", null, false, true ); - for ( Iterator it = docFiles.iterator(); it.hasNext(); ) - { - String docFile = (String) it.next(); - - File docFileOutput = new File( outputDirectory, docFile ); - FileUtils.mkdir( docFileOutput.getAbsolutePath() ); - FileUtils.copyDirectory( new File( javadocDir, docFile ), docFileOutput ); - } - } - } - - /** - * Method that indicates whether the javadoc can be generated or not. If the project does not contain any source - * files and no subpackages are specified, the plugin will terminate. - * - * @param files the project files - * @return a boolean that indicates whether javadoc report can be generated or not - */ - protected boolean canGenerateReport( List files ) - { - boolean canGenerate = true; - - if ( files.isEmpty() && StringUtils.isEmpty( subpackages ) ) - { - canGenerate = false; - } - - return canGenerate; - } - - /** - * Method that gets the files or classes that would be included in the javadocs using the subpackages - * parameter. - * - * @param sourceDirectory the directory where the source files are located - * @param fileList the list of all files found in the sourceDirectory - * @param excludePackages package names to be excluded in the javadoc - * @return a StringBuffer that contains the appended file names of the files to be included in the javadoc - */ - private static List getIncludedFiles( File sourceDirectory, String[] fileList, String[] excludePackages ) - { - List files = new ArrayList(); - - for ( int j = 0; j < fileList.length; j++ ) - { - boolean include = true; - for ( int k = 0; k < excludePackages.length && include; k++ ) - { - // handle wildcards (*) in the excludePackageNames - String[] excludeName = excludePackages[k].split( "[*]" ); - - if ( excludeName.length > 1 ) - { - int u = 0; - while ( include && u < excludeName.length ) - { - if ( !"".equals( excludeName[u].trim() ) && fileList[j].indexOf( excludeName[u] ) != -1 ) - { - include = false; - } - u++; - } - } - else - { - if ( fileList[j].startsWith( sourceDirectory.toString() + File.separatorChar + excludeName[0] ) ) - { - if ( excludeName[0].endsWith( String.valueOf( File.separatorChar ) ) ) - { - int i = fileList[j].lastIndexOf( File.separatorChar ); - String packageName = fileList[j].substring( 0, i + 1 ); - File currentPackage = new File( packageName ); - File excludedPackage = new File( sourceDirectory, excludeName[0] ); - if ( currentPackage.equals( excludedPackage ) - && fileList[j].substring( i ).indexOf( ".java" ) != -1 ) - { - include = true; - } - else - { - include = false; - } - } - else - { - include = false; - } - } - } - } - - if ( include ) - { - files.add( quotedPathArgument( fileList[j] ) ); - } - } - - return files; - } - - /** - * Method that gets the complete package names (including subpackages) of the packages that were defined - * in the excludePackageNames parameter. - * - * @param sourceDirectory the directory where the source files are located - * @param excludePackagenames package names to be excluded in the javadoc - * @return a List of the packagenames to be excluded - */ - private static List getExcludedPackages( String sourceDirectory, String[] excludePackagenames ) - { - List files = new ArrayList(); - for ( int i = 0; i < excludePackagenames.length; i++ ) - { - String[] fileList = FileUtils.getFilesFromExtension( sourceDirectory, new String[] { "java" } ); - for ( int j = 0; j < fileList.length; j++ ) - { - String[] excludeName = excludePackagenames[i].split( "[*]" ); - int u = 0; - while ( u < excludeName.length ) - { - if ( !"".equals( excludeName[u].trim() ) && fileList[j].indexOf( excludeName[u] ) != -1 - && sourceDirectory.indexOf( excludeName[u] ) == -1 ) - { - files.add( fileList[j] ); - } - u++; - } - } - } - - List excluded = new ArrayList(); - for ( Iterator it = files.iterator(); it.hasNext(); ) - { - String file = (String) it.next(); - int idx = file.lastIndexOf( File.separatorChar ); - String tmpStr = file.substring( 0, idx ); - tmpStr = tmpStr.replace( '\\', '/' ); - String[] srcSplit = tmpStr.split( sourceDirectory.replace( '\\', '/' ) + '/' ); - String excludedPackage = srcSplit[1].replace( '/', '.' ); - - if ( !excluded.contains( excludedPackage ) ) - { - excluded.add( excludedPackage ); - } - } - - return excluded; - } - - /** - * Convenience method that gets the files to be included in the javadoc. - * - * @param sourceDirectory the directory where the source files are located - * @param files the variable that contains the appended filenames of the files to be included in the javadoc - * @param excludePackages the packages to be excluded in the javadocs - */ - private static void addFilesFromSource( List files, File sourceDirectory, String[] excludePackages ) - { - String[] fileList = FileUtils.getFilesFromExtension( sourceDirectory.getPath(), new String[] { "java" } ); - if ( fileList != null && fileList.length != 0 ) - { - List tmpFiles = getIncludedFiles( sourceDirectory, fileList, excludePackages ); - files.addAll( tmpFiles ); - } - } - - /** * @param sourcePaths * @param files * @return the list of package names for files in the sourcePaths @@ -2681,8 +2345,7 @@ * Generate an "options" file for all options and arguments and add the "@options" in the command line. * * @see <a href="http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/javadoc.html#argumentfiles"> - * Reference Guide, Command line argument files - * </a> + * Reference Guide, Command line argument files</a> * * @param cmd * @param options @@ -2776,8 +2439,7 @@ * Generate a file called "packages" to hold all package namesand add the "@packages" in the command line. * * @see <a href="http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/javadoc.html#argumentfiles"> - * Reference Guide, Command line argument files - * </a> + * Reference Guide, Command line argument files</a> * * @param cmd * @param javadocOutputDirectory @@ -2806,5 +2468,359 @@ { packagesFile.deleteOnExit(); } + } + + // ---------------------------------------------------------------------- + // private static methods + // ---------------------------------------------------------------------- + + /** + * Method that removes the invalid directories in the specified source directories + * + * @param sourceDirs the list of source directories that will be validated + * @return a List of valid source directories + */ + // TODO: could be better aligned with JXR, including getFiles() vs hasSources that finds java files. + private static List pruneSourceDirs( List sourceDirs ) + { + List pruned = new ArrayList( sourceDirs.size() ); + for ( Iterator i = sourceDirs.iterator(); i.hasNext(); ) + { + String dir = (String) i.next(); + File directory = new File( dir ); + if ( directory.exists() && directory.isDirectory() ) + { + if ( !pruned.contains( dir ) ) + { + pruned.add( dir ); + } + } + } + + return pruned; + } + + /** + * Method that gets all the source files to be excluded from the javadoc on the given + * source paths. + * + * @param sourcePaths the path to the source files + * @param subpackagesList list of subpackages to be included in the javadoc + * @param excludedPackages the package names to be excluded in the javadoc + * @return a List of the source files to be excluded in the generated javadoc + */ + private static List getExcludedNames( List sourcePaths, String[] subpackagesList, String[] excludedPackages ) + { + List excludedNames = new ArrayList(); + for ( Iterator i = sourcePaths.iterator(); i.hasNext(); ) + { + String path = (String) i.next(); + for ( int j = 0; j < subpackagesList.length; j++ ) + { + List excludes = getExcludedPackages( path, excludedPackages ); + excludedNames.addAll( excludes ); + } + } + + return excludedNames; + } + + /** + * Copy from [EMAIL PROTECTED] MavenProject#getCompileArtifacts()} + * @param artifacts + * @return list of compile artifacts + */ + private static List getCompileArtifacts( Set artifacts ) + { + List list = new ArrayList( artifacts.size() ); + + for ( Iterator i = artifacts.iterator(); i.hasNext(); ) + { + Artifact a = (Artifact) i.next(); + + // TODO: classpath check doesn't belong here - that's the other method + if ( a.getArtifactHandler().isAddedToClasspath() ) + { + // TODO: let the scope handler deal with this + if ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) || Artifact.SCOPE_PROVIDED.equals( a.getScope() ) + || Artifact.SCOPE_SYSTEM.equals( a.getScope() ) ) + { + list.add( a ); + } + } + } + + return list; + } + + /** + * Convenience method to wrap an argument value in quotes. Intended for values which may contain whitespaces. + * + * @param value the argument value. + * @return argument with quote + */ + private static String quotedArgument( String value ) + { + String arg = value; + if ( StringUtils.isNotEmpty( arg ) ) + { + if ( arg.indexOf( "'" ) != -1 ) + { + arg = StringUtils.replace( arg, "'", "\\'" ); + } + arg = "'" + arg + "'"; + } + + return arg; + } + + /** + * Convenience method to format a path argument so that it is properly interpreted by the javadoc tool. Intended + * for path values which may contain whitespaces. + * + * @param value the argument value. + * @return path argument with quote + */ + private static String quotedPathArgument( String value ) + { + String path = value; + + if ( StringUtils.isNotEmpty( path ) ) + { + path = path.replace( '\\', '/' ); + if ( path.indexOf( "\'" ) != -1 ) + { + String split[] = path.split( "\'" ); + path = ""; + + for ( int i = 0; i < split.length; i++ ) + { + if ( i != split.length - 1 ) + { + path = path + split[i] + "\\'"; + } + else + { + path = path + split[i]; + } + } + } + path = "'" + path + "'"; + } + + return path; + } + + /** + * Convenience method that copy all <code>doc-files</code> directories from <code>javadocDir</code> + * to the <code>outputDirectory</code>. + * + * @param outputDirectory the output directory + * @param javadocDir the javadoc directory + * @throws java.io.IOException if any + */ + private static void copyJavadocResources( File outputDirectory, File javadocDir ) + throws IOException + { + if ( javadocDir.exists() && javadocDir.isDirectory() ) + { + List docFiles = FileUtils.getDirectoryNames( javadocDir, "**/doc-files", null, false, true ); + for ( Iterator it = docFiles.iterator(); it.hasNext(); ) + { + String docFile = (String) it.next(); + + File docFileOutput = new File( outputDirectory, docFile ); + FileUtils.mkdir( docFileOutput.getAbsolutePath() ); + FileUtils.copyDirectory( new File( javadocDir, docFile ), docFileOutput ); + } + } + } + + /** + * Method that gets the files or classes that would be included in the javadocs using the subpackages + * parameter. + * + * @param sourceDirectory the directory where the source files are located + * @param fileList the list of all files found in the sourceDirectory + * @param excludePackages package names to be excluded in the javadoc + * @return a StringBuffer that contains the appended file names of the files to be included in the javadoc + */ + private static List getIncludedFiles( File sourceDirectory, String[] fileList, String[] excludePackages ) + { + List files = new ArrayList(); + + for ( int j = 0; j < fileList.length; j++ ) + { + boolean include = true; + for ( int k = 0; k < excludePackages.length && include; k++ ) + { + // handle wildcards (*) in the excludePackageNames + String[] excludeName = excludePackages[k].split( "[*]" ); + + if ( excludeName.length > 1 ) + { + int u = 0; + while ( include && u < excludeName.length ) + { + if ( !"".equals( excludeName[u].trim() ) && fileList[j].indexOf( excludeName[u] ) != -1 ) + { + include = false; + } + u++; + } + } + else + { + if ( fileList[j].startsWith( sourceDirectory.toString() + File.separatorChar + excludeName[0] ) ) + { + if ( excludeName[0].endsWith( String.valueOf( File.separatorChar ) ) ) + { + int i = fileList[j].lastIndexOf( File.separatorChar ); + String packageName = fileList[j].substring( 0, i + 1 ); + File currentPackage = new File( packageName ); + File excludedPackage = new File( sourceDirectory, excludeName[0] ); + if ( currentPackage.equals( excludedPackage ) + && fileList[j].substring( i ).indexOf( ".java" ) != -1 ) + { + include = true; + } + else + { + include = false; + } + } + else + { + include = false; + } + } + } + } + + if ( include ) + { + files.add( quotedPathArgument( fileList[j] ) ); + } + } + + return files; + } + + /** + * Method that gets the complete package names (including subpackages) of the packages that were defined + * in the excludePackageNames parameter. + * + * @param sourceDirectory the directory where the source files are located + * @param excludePackagenames package names to be excluded in the javadoc + * @return a List of the packagenames to be excluded + */ + private static List getExcludedPackages( String sourceDirectory, String[] excludePackagenames ) + { + List files = new ArrayList(); + for ( int i = 0; i < excludePackagenames.length; i++ ) + { + String[] fileList = FileUtils.getFilesFromExtension( sourceDirectory, new String[] { "java" } ); + for ( int j = 0; j < fileList.length; j++ ) + { + String[] excludeName = excludePackagenames[i].split( "[*]" ); + int u = 0; + while ( u < excludeName.length ) + { + if ( !"".equals( excludeName[u].trim() ) && fileList[j].indexOf( excludeName[u] ) != -1 + && sourceDirectory.indexOf( excludeName[u] ) == -1 ) + { + files.add( fileList[j] ); + } + u++; + } + } + } + + List excluded = new ArrayList(); + for ( Iterator it = files.iterator(); it.hasNext(); ) + { + String file = (String) it.next(); + int idx = file.lastIndexOf( File.separatorChar ); + String tmpStr = file.substring( 0, idx ); + tmpStr = tmpStr.replace( '\\', '/' ); + String[] srcSplit = tmpStr.split( sourceDirectory.replace( '\\', '/' ) + '/' ); + String excludedPackage = srcSplit[1].replace( '/', '.' ); + + if ( !excluded.contains( excludedPackage ) ) + { + excluded.add( excludedPackage ); + } + } + + return excluded; + } + + /** + * Convenience method that gets the files to be included in the javadoc. + * + * @param sourceDirectory the directory where the source files are located + * @param files the variable that contains the appended filenames of the files to be included in the javadoc + * @param excludePackages the packages to be excluded in the javadocs + */ + private static void addFilesFromSource( List files, File sourceDirectory, String[] excludePackages ) + { + String[] fileList = FileUtils.getFilesFromExtension( sourceDirectory.getPath(), new String[] { "java" } ); + if ( fileList != null && fileList.length != 0 ) + { + List tmpFiles = getIncludedFiles( sourceDirectory, fileList, excludePackages ); + files.addAll( tmpFiles ); + } + } + + /** + * Call the javadoc tool to have its version + * + * @param javadocExe + * @return the javadoc version as float + * @throws IOException if any + * @throws CommandLineException if any + */ + private static float getJavadocVersion( File javadocExe ) + throws IOException, CommandLineException + { + if ( !javadocExe.exists() || !javadocExe.isFile() ) + { + throw new IOException( "The javadoc executable '" + javadocExe + "' doesn't exist or is not a file. " ); + } + + Commandline cmd = new Commandline(); + cmd.setExecutable( javadocExe.getAbsolutePath() ); + cmd.setWorkingDirectory( javadocExe.getParentFile() ); + cmd.createArgument().setValue( "-J-fullversion" ); + + CommandLineUtils.StringStreamConsumer out = new CommandLineUtils.StringStreamConsumer(); + CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer(); + + int exitCode = CommandLineUtils.executeCommandLine( cmd, out, err ); + + if ( exitCode != 0 ) + { + StringBuffer msg = new StringBuffer( "Exit code: " + exitCode + " - " + err.getOutput() ); + msg.append( '\n' ); + msg.append( "Command line was:" + Commandline.toString( cmd.getCommandline() ) ); + throw new CommandLineException( msg.toString() ); + } + + /* + * Exemple: java full version "1.5.0_11-b03" + * + * @see com.sun.tools.javac.main.JavaCompiler#fullVersion() + */ + StringTokenizer token = new StringTokenizer( err.getOutput(), "\"" ); + token.nextToken(); + + String version = token.nextToken(); + String str = version.substring( 0, 3 ); + if ( version.length() >= 5 ) + { + str = str + version.substring( 4, 5 ); + } + + return Float.parseFloat( str ); } }