/** Translates an Ant file list into the file format that the compiler expects. */ private List<JSSourceFile> findJavaScriptFiles(FileList fileList) { List<JSSourceFile> files = Lists.newLinkedList(); File baseDir = fileList.getDir(getProject()); for (String included : fileList.getFiles(getProject())) { files.add(JSSourceFile.fromFile(new File(baseDir, included), Charset.forName(encoding))); } return files; }
private File manageFileList(FileList fl) throws IOException, InterruptedException { final File fromDir = fl.getDir(getProject()); final String[] srcFiles = fl.getFiles(getProject()); for (String src : srcFiles) { final File f = new File(fromDir, src); final boolean error = processingSingleFile(f); if (error) { return f; } } return null; }
// iterates over all the input file names and adds them to the infuser arguments // object protected void iterateResourceCollections() { for (FileSet fileSet : fileSets) { String files[] = fileSet.getDirectoryScanner(getProject()).getIncludedFiles(); for (String file : files) { String path = fileSet.getDir(getProject()) + "/" + file; try { infuserArguments.parseArgument(path); } catch (Exception ex) { throw new BuildException("Error loading file: " + path, ex); } } } for (FileList fileList : fileLists) { for (String file : fileList.getFiles(getProject())) { String path = fileList.getDir(getProject()) + "/" + file; try { infuserArguments.parseArgument(path); } catch (Exception ex) { throw new BuildException("Error loading file: " + path, ex); } } } }
/** * Returns the most recent modified timestamp of the file collection. * * <p>Note: this must be combined into one method to account for both Path and FileList erasure * types. * * @param fileLists Collection of FileList or Path * @return Most recent modified timestamp */ private long getLastModifiedTime(List<?> fileLists) { long lastModified = 0; for (Object entry : fileLists) { if (entry instanceof FileList) { FileList list = (FileList) entry; for (String fileName : list.getFiles(this.getProject())) { File path = list.getDir(this.getProject()); File file = new File(path, fileName); lastModified = Math.max(getLastModifiedTime(file), lastModified); } } else if (entry instanceof Path) { Path path = (Path) entry; for (String src : path.list()) { File file = new File(src); lastModified = Math.max(getLastModifiedTime(file), lastModified); } } } return lastModified; }
/** * 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]); }