[Laszlo-checkins] r9586 - in openlaszlo/trunk: 3rd-party/jars/dev WEB-INF/lps/lfc WEB-INF/lps/schema WEB-INF/lps/server WEB-INF/lps/server/src/org/openlaszlo/js2doc

dda@openlaszlo.org dda at openlaszlo.org
Wed Jun 11 11:03:56 PDT 2008


Author: dda
Date: 2008-06-11 11:03:42 -0700 (Wed, 11 Jun 2008)
New Revision: 9586

Added:
   openlaszlo/trunk/3rd-party/jars/dev/serializer.jar
   openlaszlo/trunk/3rd-party/jars/dev/xalan.jar
   openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/js2doc/SchemaBuilder.java
Modified:
   openlaszlo/trunk/WEB-INF/lps/lfc/build.xml
   openlaszlo/trunk/WEB-INF/lps/schema/build.xml
   openlaszlo/trunk/WEB-INF/lps/server/build.xml
   openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/js2doc/JS2Doc.java
   openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/js2doc/JS2DocUtils.java
   openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/js2doc/JS2Doc_Test.java
   openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/js2doc/Main.java
   openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/js2doc/WholeFile_Test.java
Log:
Change 20080611-dda-t by dda at lester.local on 2008-06-11 13:52:34 EDT
    in /Users/dda/laszlo/src/svn/openlaszlo/trunk-d
    for http://svn.openlaszlo.org/openlaszlo/trunk

Summary: Preliminary version of XML schema for LFC

New Features:

Bugs Fixed: LPP-3508 (partial)

Technical Reviewer: hminsky (pending)
QA Reviewer: (pending)
Doc Reviewer: (pending)

Documentation:

Release Notes:

Details:
    This is a preliminary version of the xml schema for LFC.
    The result is put into WEB-INF/lps/schema/lfc-new.xml,
    and is in the form of lfc.xml in that same directory.
    It can be used for some testing and future refinements.

Tests:



Added: openlaszlo/trunk/3rd-party/jars/dev/serializer.jar


Property changes on: openlaszlo/trunk/3rd-party/jars/dev/serializer.jar
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: openlaszlo/trunk/3rd-party/jars/dev/xalan.jar


Property changes on: openlaszlo/trunk/3rd-party/jars/dev/xalan.jar
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Modified: openlaszlo/trunk/WEB-INF/lps/lfc/build.xml
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/build.xml	2008-06-11 17:56:27 UTC (rev 9585)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/build.xml	2008-06-11 18:03:42 UTC (rev 9586)
@@ -48,6 +48,7 @@
     <property file="${LPS_HOME}/WEB-INF/lps/config/lps.properties" />
     <property name="LFCdir" value="${LPS_HOME}/${compiler.runtime.dir}" />
     <property name="lfc.src.dir" value="${LPS_HOME}/WEB-INF/lps/lfc" />
+    <property name="schema.dir" value="${LPS_HOME}/WEB-INF/lps/schema" />
 
     <condition property="JAVA_DEBUG" value="" else="-ea">
       <equals arg1="${build.debug}" arg2="off" />
@@ -111,6 +112,10 @@
     </ant>     
   </target>
 
+  <fileset id="lfc.depend.lzx" dir="." excludes="*.lzl" />
+  <fileset id="lfc.depend.scgrammar" dir="${sc.dir}" includes="**/*" />
+  <fileset id="lfc.depend.sc" dir="${LPS_HOME}/WEB-INF/lps/server/src/org/openlaszlo/sc" includes="**/*" />
+
   <!-- We want to build the cross-product of [dhtml, swf7, swf8] with [ regular, debug, backtrace, profile ] -->
   <target name="lfcs"
           depends="init">
@@ -121,6 +126,7 @@
       <srcfileset dir="${sc.dir}" includes="**/*" />
       <srcfileset dir="${LPS_HOME}/WEB-INF/lps/server/src/org/openlaszlo/sc" includes="**/*" />
       <targetfileset dir="${LFCdir}" includes="*.js,*.lzl,*.swc" excludes="lzpreloader.lzl"/>
+      <targetfileset dir="${schema.dir}" includes="lfc-new.lzx"/>
     </dependset>
 
     <script language="javascript">
@@ -256,6 +262,8 @@
       }
     }
     ]]> </script>
+    <ant dir="${schema.dir}"  target="lfc.schema" />
+
   </target>
 
   <target name="doc" />

Modified: openlaszlo/trunk/WEB-INF/lps/schema/build.xml
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/schema/build.xml	2008-06-11 17:56:27 UTC (rev 9585)
+++ openlaszlo/trunk/WEB-INF/lps/schema/build.xml	2008-06-11 18:03:42 UTC (rev 9586)
@@ -1,7 +1,7 @@
 <project name="schema" default="build">
 
 <!-- * X_LZ_COPYRIGHT_BEGIN ***************************************************
-* Copyright 2001-2007 Laszlo Systems, Inc.  All Rights Reserved.              *
+* Copyright 2001-2008 Laszlo Systems, Inc.  All Rights Reserved.              *
 * Use is subject to license terms.                                            *
 * X_LZ_COPYRIGHT_END ****************************************************** -->
 
@@ -15,11 +15,16 @@
   <target name="init">
     <tstamp/>
     <property name="build" value="./build"/>
+    <property name="build.dir" value="${LPS_HOME}/WEB-INF/lps/schema/build"/>
     <property name="rnc" value="lzx.rnc"/>
     <property name="docrng" value="lzxdoc.rng"/>
     <property name="rng" value="lzx.rng"/>
     <property name="xsd" value="lzx.xsd"/>
+    <property name="lfc.schema.file" value="lfc-new.lzx"/>
     <property name="html" value="lzx-reference.html"/>
+    <property name="server.dir" value="${LPS_HOME}/WEB-INF/lps/server" />
+    <property name="lfc.src.dir" value="${LPS_HOME}/WEB-INF/lps/lfc" />
+    <property name="js2doc.src.dir" value="${LPS_HOME}/WEB-INF/lps/server/src/org/openlaszlo/js2doc/" />
 
     <mkdir dir="build"/>
     <condition property="schemas.uptodate">
@@ -57,13 +62,31 @@
     <delete file="${rng}"/>
     <delete file="${xsd}"/>
     <delete file="${dtd}"/>
+    <delete file="${lfc.schema.file}"/>
     <delete quiet="true">
       <fileset dir="." defaultexcludes="no" includes="**/*~"/>
       <fileset dir="." defaultexcludes="no" includes="**/*.pyc"/>
     </delete>
   </target>
 
-    
+  <target name="lfc.schema.uptodate" depends="init">
+    <condition property="uptodate">
+      <uptodate property="lfc.schema.uptodate" targetfile="${lfc.schema.file}">
+        <srcfiles dir="${lfc.src.dir}" includes="**/*" />
+        <srcfiles dir="${js2doc.src.dir}" includes="**/*" />
+      </uptodate>
+    </condition>
+  </target>
+
+  <!-- The lfc.schema target is called from lfc/build.xml -->
+  <target name="lfc.schema" description="build the lfc-new.lzx schema description"
+          depends="lfc.schema.uptodate" unless="uptodate">
+    <property name="js2doc.args" value="--schema --out ${build.dir}/lfc-new.xml --dir ${build.dir} ${lfc.src.dir}/LaszloLibrary.lzs" />
+    <ant dir="${server.dir}" target="js2doc.schema" />
+    <copy file="${build.dir}/lfc-new.xml" tofile="${lfc.schema.file}"/>
+
+  </target>
+
   <target name="build" 
           description="Build generated schema files" depends="rng"
           unless="schemas.uptodate"> <!-- don't build dtd unless it is explicitly requested -->

Modified: openlaszlo/trunk/WEB-INF/lps/server/build.xml
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/build.xml	2008-06-11 17:56:27 UTC (rev 9585)
+++ openlaszlo/trunk/WEB-INF/lps/server/build.xml	2008-06-11 18:03:42 UTC (rev 9586)
@@ -388,6 +388,28 @@
     </java>
   </target>
   
+  <!--===============  Target [js2doc.schema]    =================-->
+  <!-- extract documentation from .js file(s) given -->
+  <!-- Note that we don't depend on "build" here, which means you need to manually
+     - build if server sources change. The reason to skip this check is to avoid
+     - repeatedly touching the lps-*.jar file, which causes the java task to always
+     - re-run js2doc in this task. -->
+  <target name="js2doc.schema" depends="init" if="hasdom3"
+        description="extract schema from the .js file(s) given">
+    <!-- fork=true is necessary, otherwise we get a FNF error trying to create the .xml file -->
+    <java classname="org.openlaszlo.js2doc.Main"
+          fork="yes"
+          failonerror="true">
+        <classpath>
+            <path refid="3rd.party.classpath"/>
+            <pathelement path="${LPS_JAR}"/>
+        </classpath> 
+        <sysproperty key="LPS_HOME" value="${LPS_HOME}"/>
+        <sysproperty key="JS2DOC_LIBROOT" value="${LPS_HOME}"/>
+        <arg line="${js2doc.args}"/>
+    </java>
+  </target>
+  
   <!--===============  Target [js2doc.rng]    =================-->
   <target name="js2doc.rng" 
           depends="js2doc.rng.dep"

Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/js2doc/JS2Doc.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/js2doc/JS2Doc.java	2008-06-11 17:56:27 UTC (rev 9585)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/js2doc/JS2Doc.java	2008-06-11 18:03:42 UTC (rev 9586)
@@ -428,6 +428,8 @@
                 visitModifiedDefinition(parseNode, docNode);
             } else if (parseNode instanceof ASTPragmaDirective) {
                 // do nothing
+            } else if (parseNode instanceof ASTPassthroughDirective) {
+                // do nothing
             } else {
                 logger.warning("Unhandled class statement type " + parseNode.getClass().getName());
             }
@@ -819,9 +821,16 @@
         }
     }
     
+    static class XMLGenerateOptions {
+        boolean createSchema = false;
+    }
+
     static public Document toXML(String inputString, 
                                  File sourceFile, String sourceRoot, String libraryID,
-                                 Set runtimeOptions, List runtimeAliases, List buildOptions) {
+                                 Set runtimeOptions, List runtimeAliases, List buildOptions, XMLGenerateOptions xmlOptions) {
+        if (xmlOptions == null) {
+            xmlOptions = new XMLGenerateOptions();
+        }
         org.openlaszlo.sc.Compiler.Parser p = new org.openlaszlo.sc.Compiler.Parser();
         SimpleNode parseRoot = p.parse(inputString);
         
@@ -873,6 +882,17 @@
             
             ReprocessComments.reprocess(docRoot, true);
             
+            Element schemaRoot = null;
+            if (xmlOptions.createSchema) {
+                org.w3c.dom.Document schemaDoc = factory.newDocumentBuilder().newDocument();
+                org.w3c.dom.Element libraryNode = schemaDoc.createElement("library");
+                schemaDoc.appendChild(libraryNode);
+                (new SchemaBuilder(docRoot)).build(libraryNode);
+
+                // Emit the schema document instead of the original js2doc doc
+                doc = schemaDoc;
+            }
+
             doc.normalizeDocument();
             
         } catch (javax.xml.parsers.ParserConfigurationException e) {

Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/js2doc/JS2DocUtils.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/js2doc/JS2DocUtils.java	2008-06-11 17:56:27 UTC (rev 9585)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/js2doc/JS2DocUtils.java	2008-06-11 18:03:42 UTC (rev 9586)
@@ -36,6 +36,13 @@
             super(message);
             this.node = node;
         }
+
+        /** Constructs an instance.
+         * @param e an exception
+         */
+        public InternalError(Exception e) {
+            super(e);
+        }
     }
 
 
@@ -59,7 +66,16 @@
         return stringResult;
     }
 
-    public static void xmlToFile(org.w3c.dom.Node node, String filename) throws RuntimeException {
+    static final String XALAN_INDENT_AMOUNT = 
+        "{http://xml.apache.org/xslt}" + "indent-amount"; 
+
+    private static void setReadable(Transformer xformer) {
+        xformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); 
+        xformer.setOutputProperty(OutputKeys.INDENT, "yes"); 
+        xformer.setOutputProperty(XALAN_INDENT_AMOUNT, "2"); 
+    }
+
+    public static void xmlToFile(org.w3c.dom.Node node, String filename, boolean readable) throws RuntimeException {
         try {
             // Prepare the DOM document for writing
             Source source = new DOMSource(node);
@@ -70,6 +86,7 @@
     
             // Write the DOM document to the file
             Transformer xformer = TransformerFactory.newInstance().newTransformer();
+            setReadable(xformer);
             xformer.transform(source, result);
         } catch (TransformerConfigurationException e) {
             e.printStackTrace();

Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/js2doc/JS2Doc_Test.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/js2doc/JS2Doc_Test.java	2008-06-11 17:56:27 UTC (rev 9585)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/js2doc/JS2Doc_Test.java	2008-06-11 18:03:42 UTC (rev 9586)
@@ -732,7 +732,7 @@
             try {
                 Document control = XMLUnit.buildControlDocument(result);
                 
-                Document test = JS2Doc.toXML(source, null, null, null, runtimeOptions, runtimeAliases, buildOptions);
+                Document test = JS2Doc.toXML(source, null, null, null, runtimeOptions, runtimeAliases, buildOptions, null);
                 
                 Diff diff = new Diff(control, test);
                 

Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/js2doc/Main.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/js2doc/Main.java	2008-06-11 17:56:27 UTC (rev 9585)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/js2doc/Main.java	2008-06-11 18:03:42 UTC (rev 9586)
@@ -30,6 +30,8 @@
         "  Test mode: validate result against schema given",
         "--reprocess",
         "  Reprocess comments",
+        "--schema",
+        "  Produce schema file for lfc.lzx",
         "--help",
         "  Prints this message.",
         "",
@@ -87,6 +89,7 @@
         boolean reprocessOnly = false;
         String libraryID = null;
         String schemaFilename = null; // used for --test mode
+        JS2Doc.XMLGenerateOptions xmlOptions = new JS2Doc.XMLGenerateOptions();
         
         for (int i = 0; i < args.length; i++) {
             String arg = args[i].intern();
@@ -121,6 +124,8 @@
                         libraryID = args[i];
                     } else
                         badform = true;
+                } else if (arg.equals("--schema")) {
+                    xmlOptions.createSchema = true;
                 } else if (arg.equals("--help")) {
                     for (int j = 0; j < USAGE.length; j++) {
                         System.err.println(USAGE[j]);
@@ -156,11 +161,11 @@
             } else if (reprocessOnly) {
                 if (files.size() > 1)
                     System.err.println("Reprocessing documentation within " + sourceName);
-                reprocess(sourceName, outFileName, outDir, libraryID, runtimeOptions, runtimeAliases, buildOptions);
+                reprocess(sourceName, outFileName, outDir, libraryID, runtimeOptions, runtimeAliases, buildOptions, xmlOptions);
             } else {
                 if (files.size() > 1)
                     System.err.println("Extracting documentation from " + sourceName);
-                process(sourceName, outFileName, outDir, libraryID, runtimeOptions, runtimeAliases, buildOptions);
+                process(sourceName, outFileName, outDir, libraryID, runtimeOptions, runtimeAliases, buildOptions, xmlOptions);
             }
         }
         return 0;
@@ -172,7 +177,8 @@
                                String libraryID,
                                Set runtimeOptions,
                                List runtimeAliases,
-                               List buildOptions)
+                               List buildOptions,
+                               JS2Doc.XMLGenerateOptions xmlOptions)
     {
         File sourceFile = new File(sourceName);
         if (outFileName == null) {
@@ -189,9 +195,9 @@
             String script = "#file " + sourceName + "\n" + "#line 1\n" + scriptContents;
             // TODO [jgrandy 2007/01/11] pass in or retrieve JS2DOC_HOME
             String sourceRoot = System.getProperty("JS2DOC_LIBROOT");
-            Document descr = JS2Doc.toXML(script, sourceFile, sourceRoot, libraryID, runtimeOptions, runtimeAliases, buildOptions);
+            Document descr = JS2Doc.toXML(script, sourceFile, sourceRoot, libraryID, runtimeOptions, runtimeAliases, buildOptions, xmlOptions);
             
-            JS2DocUtils.xmlToFile(descr, outFileName);
+            JS2DocUtils.xmlToFile(descr, outFileName, true);
             
         } catch (IOException e) {
             e.printStackTrace();
@@ -205,7 +211,8 @@
                                String libraryID,
                                Set runtimeOptions,
                                List runtimeAliases,
-                               List buildOptions)
+                               List buildOptions,
+                               JS2Doc.XMLGenerateOptions xmlOptions)
     {
         File sourceFile = new File(sourceName);
         if (outFileName == null) {
@@ -216,13 +223,12 @@
                 FileUtils.getBase(sourceFile.getName()) + ".xml";
             }
         } 
-        File scriptFile = new File(outFileName);
         try {
             String scriptContents = FileUtils.readFileString(sourceFile);
 
             Document descr = ReprocessComments.reprocess(scriptContents);
             
-            JS2DocUtils.xmlToFile(descr, outFileName);
+            JS2DocUtils.xmlToFile(descr, outFileName, true);
             
         } catch (IOException e) {
             e.printStackTrace();
@@ -242,7 +248,7 @@
             String sourceContents = FileUtils.readFileString(sourceFile);
             String source = "#file " + sourceName + "\n" + "#line 1\n" + sourceContents;
             String sourceRoot = System.getProperty("JS2DOC_LIBROOT");
-            Document test = JS2Doc.toXML(source, sourceFile, sourceRoot, libraryID, runtimeOptions, runtimeAliases, buildOptions);
+            Document test = JS2Doc.toXML(source, sourceFile, sourceRoot, libraryID, runtimeOptions, runtimeAliases, buildOptions, null);
             
             String expectName = FileUtils.getBase(sourceName) + ".xml";
             File expectFile = new File(expectName);

Added: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/js2doc/SchemaBuilder.java


Property changes on: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/js2doc/SchemaBuilder.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + native

Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/js2doc/WholeFile_Test.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/js2doc/WholeFile_Test.java	2008-06-11 17:56:27 UTC (rev 9585)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/js2doc/WholeFile_Test.java	2008-06-11 18:03:42 UTC (rev 9586)
@@ -80,7 +80,7 @@
     
                 Document control = XMLUnit.buildControlDocument(result);
                 
-                Document test = JS2Doc.toXML(source, sourceFile, sourceRoot, "test", runtimeOptions, runtimeAliases, buildOptions);
+                Document test = JS2Doc.toXML(source, sourceFile, sourceRoot, "test", runtimeOptions, runtimeAliases, buildOptions, null);
                 
                 Diff diff = new Diff(control, test);
                 



More information about the Laszlo-checkins mailing list