diff --git a/main.js b/main.js index d4b92de3..e4c994ce 100644 --- a/main.js +++ b/main.js @@ -60,7 +60,7 @@ sourceFiles = jsdoc.src.getFilePaths(opts._); - jsdoc.parser.parseFiles(sourceFiles); + jsdoc.parser.parseFiles(sourceFiles, opts.encoding); if (opts.validate) { var jsonSchema = require('sitepen/jsonSchema'); diff --git a/modules/common/fs.js b/modules/common/fs.js index 588a8a9b..236e8100 100644 --- a/modules/common/fs.js +++ b/modules/common/fs.js @@ -6,31 +6,37 @@ (function() { var slash = java.lang.System.getProperty('file.separator') || '/', - File = Packages.java.io.File, + File = java.io.File, defaultEncoding = java.lang.System.getProperty('file.encoding'); - exports.read = function(path, options) { + exports.read = function(path, encoding) { var options = options || {}, - encoding = options.encoding || defaultEncoding; - - return readFile(path, encoding); + encoding = encoding || defaultEncoding, + input; +print('encoding is '+encoding); + input = new java.util.Scanner( + new File(path), + encoding + ).useDelimiter("\\Z"); + + return String( input.next() ); } - exports.write = function(path, content, options) { + exports.write = function(path, content, encoding) { var options = options || {}, - encoding = options.encoding || defaultEncoding, - out; + encoding = encoding || defaultEncoding, + output; - out = new Packages.java.io.PrintWriter( - new Packages.java.io.OutputStreamWriter( - new Packages.java.io.FileOutputStream(path), + output = new java.io.PrintWriter( + new java.io.OutputStreamWriter( + new java.io.FileOutputStream(path), encoding ) ); - out.write(content); - out.flush(); - out.close(); + output.write(content); + output.flush(); + output.close(); } /** diff --git a/modules/jsdoc/opts.js b/modules/jsdoc/opts.js index 18b65c53..9a1f850c 100644 --- a/modules/jsdoc/opts.js +++ b/modules/jsdoc/opts.js @@ -18,9 +18,10 @@ destination: 'jsdoc.xml' }; - argsParser.addOption('t', 'template', true, 'The name of the template to use.'); + argsParser.addOption('t', 'template', true, 'The name of the template to use. Default: the "default" template'); + argsParser.addOption('e', 'encoding', true, 'Assume this encoding when reading all source files. Default: your system default encoding'); argsParser.addOption('T', 'test', false, 'Run unit tests and quit.'); - argsParser.addOption('d', 'destination', true, 'The path to output folder.'); + argsParser.addOption('d', 'destination', true, 'The path to output folder. Default: ./jsdocs'); argsParser.addOption('h', 'help', false, 'Print help message and quit.'); argsParser.addOption('V', 'validate', false, 'Validate the results produced by parsing the source code.'); diff --git a/modules/jsdoc/parser.js b/modules/jsdoc/parser.js index 395f60c3..0e900f30 100644 --- a/modules/jsdoc/parser.js +++ b/modules/jsdoc/parser.js @@ -125,17 +125,17 @@ /** */ - exports.parseFiles = function(sourceFiles) { + exports.parseFiles = function(sourceFiles, encoding) { var ast = getParser(), fs = require('common/fs'), source = ''; for (i = 0, leni = sourceFiles.length; i < leni; i++) { try { - source = fs.read(sourceFiles[i]); + source = fs.read(sourceFiles[i], encoding); } catch(e) { - print('ERROR: ' + e); + print('FILE READ ERROR: ' + e); continue; }