/** * Receive a nested FileList * * @param fileList a list of sources */ public void addFileList(FileList fileList) { if (!fileLists.contains(fileList)) { fileLists.add(fileList); } }
/** * Receive a nested fileset * * @param fileSet a fileset of source files */ public void addFileSet(FileSet fileSet) { if (!fileSets.contains(fileSet)) { fileSets.add(fileSet); } }
/** * Receive a nested argument * * @param arg An argument to pass to JSDoc3. This can be used pass arguments not exposed directly * by the ant task (e.g --test, --explain, etc.) */ public void addArg(Argument arg) { if (!args.contains(arg)) { args.add(arg); } }
/** Helper method to add optional boolean arguments. Checks for null first, then adds */ private void addOptionalBooleanArgument(Vector<String> arguments, Boolean value, String option) { if (value) { arguments.add(option); } }
/** Helper method to add optional arguments. Checks for null first, then adds */ private void addOptionalArgument(Vector<String> arguments, String value, String option) { if (value != null) { arguments.add(option); arguments.add(value); } }
/** * Create the array of arguments to pass to rhino engine. It looks something like this: -modules * <jsdoc.home>/node_modules -modules <jsdoc.home>/rhino_modules \ -modules <jsdoc.home> * <jsdoc.home>/jsdoc.js --dirname=<jsdoc.home> \ <options> <sourcefiles|sourcedirs> * * @return a string[] of commands to pass to the rhino engine */ private String[] createArguments() throws BuildException { Vector<String> arguments = new Vector<String>(); // return if certain attributes are not present if ((jsDocHome == null)) { throw new BuildException("jsdochome must be specified"); } // add the modules folders arguments.add("-modules"); arguments.add(jsDocHome + "/node_modules"); arguments.add("-modules"); if (new File(jsDocHome + "/rhino").exists()) { arguments.add(jsDocHome + "/rhino"); } else { arguments.add(jsDocHome + "/rhino_modules"); } arguments.add("-modules"); arguments.add(jsDocHome + "/lib"); arguments.add("-modules"); arguments.add(jsDocHome); // add the main jsodc js arguments.add(jsDocHome + "/jsdoc.js"); // add the dirname arguments.add("--dirname=" + jsDocHome); addOptionalArgument(arguments, template, "-t"); // add the template addOptionalArgument(arguments, toDir, "-d"); // add the output dir addOptionalArgument(arguments, encoding, "-e"); // the encoding to use addOptionalArgument(arguments, config, "-c"); // the config file to use addOptionalArgument(arguments, tutorials, "-u"); // the tutorials dir addOptionalBooleanArgument(arguments, isIncludingPrivate, "-p"); addOptionalBooleanArgument(arguments, isRecursive, "-r"); if (inputFile != null) { arguments.add(inputFile); } else if (inputDir != null) { arguments.add(inputDir); } else if (fileSets.size() != 0 || fileLists.size() != 0) { // Loop through fileSets for (int i = 0, l = fileSets.size(); i < l; i++) { FileSet fs = fileSets.elementAt(i); // Ummm....? DirectoryScanner ds = fs.getDirectoryScanner(getProject()); // Get base directory from fileset File dir = ds.getBasedir(); // Get included files from fileset String[] srcs = ds.getIncludedFiles(); // Loop through files for (int j = 0; j < srcs.length; j++) { // Make file object from base directory and filename File temp = new File(dir, srcs[j]); // Call the JSMin class with this file arguments.add(temp.getAbsolutePath()); } } // Loop through fileLists for (int i = 0; i < fileLists.size(); i++) { FileList fs = fileLists.elementAt(i); // Get included files from filelist String[] srcs = fs.getFiles(getProject()); // Get base directory from filelist File dir = fs.getDir(getProject()); // Loop through files for (int j = 0; j < srcs.length; j++) { // Make file object from base directory and filename File temp = new File(dir, srcs[j]); // Call the JSMin class with this file arguments.add(temp.getAbsolutePath()); } } } else { throw new BuildException( "No inputs specified. Task requires 'file' attribute OR 'dir' attribute OR nested filesets"); } if (args.size() != 0) { for (int i = 0, l = args.size(); i < l; i++) { arguments.addAll(Arrays.asList(args.elementAt(i).getParts())); } } return arguments.toArray(new String[0]); }