details: http://code.openbravo.com/erp/devel/pi/rev/3f542c7def01 changeset: 4648:3f542c7def01 user: Iván Perdomo <ivan.perdomo <at> openbravo.com> date: Wed Aug 19 15:04:05 2009 +0200 summary: Added support for exporting js details files
diffstat: src-test/org/openbravo/test/javascript/JavaScriptAPIChecker.java | 119 ++++++++--- src-test/org/openbravo/test/javascript/JavaScriptAntTest.java | 24 ++ src/build.xml | 3 +- 3 files changed, 109 insertions(+), 37 deletions(-) diffs (212 lines): diff -r 59c0ede95a86 -r 3f542c7def01 src-test/org/openbravo/test/javascript/JavaScriptAPIChecker.java --- a/src-test/org/openbravo/test/javascript/JavaScriptAPIChecker.java Wed Aug 19 14:37:33 2009 +0200 +++ b/src-test/org/openbravo/test/javascript/JavaScriptAPIChecker.java Wed Aug 19 15:04:05 2009 +0200 @@ -26,6 +26,7 @@ import java.util.HashMap; import java.util.Iterator; +import org.apache.log4j.Logger; import org.mozilla.javascript.FunctionNode; import org.mozilla.javascript.Node; import org.mozilla.javascript.ScriptOrFnNode; @@ -38,9 +39,30 @@ * @author iperdomo */ public class JavaScriptAPIChecker { + private static final Logger log = Logger.getLogger(JavaScriptAPIChecker.class); private HashMap<String, String> apiMap = new HashMap<String, String>(); private File apiDetailsFolder = null; private File jsFolder = null; + private boolean export = false; + + /** + * Returns if the export of .details file should be made + * + * @return true if the export procedure should be made, false if not + */ + public boolean isExport() { + return export; + } + + /** + * Sets the flag to export the .details file + * + * @param export + * boolean that sets that export procedure should be made + */ + public void setExport(boolean export) { + this.export = export; + } /** * Sets the folder where the .details file are located @@ -89,50 +111,75 @@ throw new RuntimeException("A folder containing the JavaScript files must be set"); } - FilenameFilter detailsFilter = new FilenameFilter() { - public boolean accept(File dir, String fileName) { - return fileName.endsWith(".details"); + if (isExport()) { // export + // Parsing the .js files and checking it agains the api map + + FilenameFilter jsFilter = new FilenameFilter() { + public boolean accept(File dir, String fileName) { + return fileName.endsWith(".js"); + } + }; + + final JavaScriptParser jsp = new JavaScriptParser(); + + final String[] jsFiles = jsFolder.list(jsFilter); + for (int j = 0; j < jsFiles.length; j++) { + final File jsFile = new File(jsFolder, jsFiles[j]); + jsp.setFile(jsFile); + try { + final File detailFile = new File(apiDetailsFolder, jsFiles[j] + ".details"); + jsp.toFile(detailFile); + } catch (IOException e) { + log.error(e.getMessage(), e); + } } - }; + log.info("Export done!"); + } else { // check + FilenameFilter detailsFilter = new FilenameFilter() { + public boolean accept(File dir, String fileName) { + return fileName.endsWith(".details"); + } + }; - // Building a map with the current API details - final String[] detailFiles = apiDetailsFolder.list(detailsFilter); - for (int i = 0; i < detailFiles.length; i++) { - final File dFile = new File(apiDetailsFolder, detailFiles[i]); - int pos = detailFiles[i].indexOf(".details"); - final String jsFileName = detailFiles[i].substring(0, pos); - String line; - int lineNo = 1; - try { - BufferedReader br = new BufferedReader(new FileReader(dFile)); - while ((line = br.readLine()) != null) { - apiMap.put(jsFileName + line, String.valueOf(lineNo)); - lineNo++; + // Building a map with the current API details + final String[] detailFiles = apiDetailsFolder.list(detailsFilter); + for (int i = 0; i < detailFiles.length; i++) { + final File dFile = new File(apiDetailsFolder, detailFiles[i]); + int pos = detailFiles[i].indexOf(".details"); + final String jsFileName = detailFiles[i].substring(0, pos); + String line; + int lineNo = 1; + try { + BufferedReader br = new BufferedReader(new FileReader(dFile)); + while ((line = br.readLine()) != null) { + apiMap.put(jsFileName + line, String.valueOf(lineNo)); + lineNo++; + } + br.close(); + } catch (Exception e) { + log.error(e.getMessage(), e); } - br.close(); - } catch (Exception e) { - e.printStackTrace(); } - } - // Parsing the .js files and checking it agains the api map + // Parsing the .js files and checking it agains the api map - FilenameFilter jsFilter = new FilenameFilter() { - public boolean accept(File dir, String fileName) { - return fileName.endsWith(".js"); - } - }; + FilenameFilter jsFilter = new FilenameFilter() { + public boolean accept(File dir, String fileName) { + return fileName.endsWith(".js"); + } + }; - final JavaScriptParser jsp = new JavaScriptParser(); + final JavaScriptParser jsp = new JavaScriptParser(); - final String[] jsFiles = jsFolder.list(jsFilter); - for (int j = 0; j < jsFiles.length; j++) { - final File jsFile = new File(jsFolder, jsFiles[j]); - jsp.setFile(jsFile); - try { - checkJS(jsp, jsFiles[j]); - } catch (IOException e) { - e.printStackTrace(); + final String[] jsFiles = jsFolder.list(jsFilter); + for (int j = 0; j < jsFiles.length; j++) { + final File jsFile = new File(jsFolder, jsFiles[j]); + jsp.setFile(jsFile); + try { + checkJS(jsp, jsFiles[j]); + } catch (IOException e) { + log.error(e.getMessage(), e); + } } } } diff -r 59c0ede95a86 -r 3f542c7def01 src-test/org/openbravo/test/javascript/JavaScriptAntTest.java --- a/src-test/org/openbravo/test/javascript/JavaScriptAntTest.java Wed Aug 19 14:37:33 2009 +0200 +++ b/src-test/org/openbravo/test/javascript/JavaScriptAntTest.java Wed Aug 19 15:04:05 2009 +0200 @@ -34,6 +34,26 @@ private JavaScriptAPIChecker jsAPIChecker = null; private String apiDetailsPath = null; private String jsPath = null; + private boolean export; + + /** + * Returns if the export of .details file should be made + * + * @return true if the export procedure should be made, false if not + */ + public boolean isExport() { + return export; + } + + /** + * Sets the flag to export the .details file + * + * @param export + * boolean that sets that export procedure should be made + */ + public void setExport(boolean export) { + this.export = export; + } /** * Gets the folder path of the .details files @@ -81,10 +101,14 @@ public void execute() throws BuildException { log.debug("JS API details folder: " + this.apiDetailsPath); log.debug("JS folder:" + this.jsPath); + log.debug("JS Export procedure:" + this.export); + jsAPIChecker = new JavaScriptAPIChecker(); jsAPIChecker.setDetailsFolder(new File(this.apiDetailsPath)); jsAPIChecker.setJSFolder(new File(this.jsPath)); + jsAPIChecker.setExport(this.export); jsAPIChecker.process(); + if (!jsAPIChecker.getAPIMap().isEmpty()) { throw new BuildException("API Map must be empty: " + jsAPIChecker.getAPIMap()); } diff -r 59c0ede95a86 -r 3f542c7def01 src/build.xml --- a/src/build.xml Wed Aug 19 14:37:33 2009 +0200 +++ b/src/build.xml Wed Aug 19 15:04:05 2009 +0200 @@ -273,7 +273,8 @@ <target name="run.api.test.javascript"> <taskdef name="jstest" classname="org.openbravo.test.javascript.JavaScriptAntTest" classpathref="project.class.path" /> - <jstest apiDetailsPath="${api.test.javascript.details}" jsPath="${base.web}/js" /> + <property name="export" value="no" /> + <jstest apiDetailsPath="${api.test.javascript.details}" jsPath="${base.web}/js" export="${export}" /> </target> <target name="compileSqlc" depends="sqlc"> ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ Openbravo-commits mailing list Openbravo-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbravo-commits