[Laszlo-checkins] r12430 - in openlaszlo/trunk/WEB-INF/lps: schema server/src/org/openlaszlo/compiler

hqm@openlaszlo.org hqm at openlaszlo.org
Mon Jan 12 10:35:16 PST 2009


Author: hqm
Date: 2009-01-12 10:35:13 -0800 (Mon, 12 Jan 2009)
New Revision: 12430

Modified:
   openlaszlo/trunk/WEB-INF/lps/schema/lfc-undeclared.lzx
   openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/CompilationEnvironment.java
   openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/Compiler.java
   openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/Parser.java
Log:
Change 20090112-hqm-K by hqm at badtzmaru.home on 2009-01-12 13:05:42 EST
    in /Users/hqm/openlaszlo/trunk5
    for http://svn.openlaszlo.org/openlaszlo/trunk

Summary:   Allow compiler options to be set in canvas tag

New Features:

Bugs Fixed: LPP-7612

Technical Reviewer: ptw
QA Reviewer: philr
Doc Reviewer: (pending)

Documentation:

Release Notes:

Details:
    

Tests:

compile test app with 

// see that runtime = swf10
<canvas compileroptions="debug:true; runtime:swf10" >
  <debug   oninit='Debug.info("$debug", $debug, "$runtime", $runtime, "$profile", $profile)'/>
  <text bgcolor="#ccffcc" text="${'runtime='+canvas.runtime + ' $debug='+$debug}"/>	
</canvas>

// see that backtrace is enabled
<canvas compileroptions="backtrace:true; debug:true; profile:false; runtime:swf8" >
  <debug   oninit='Debug.info("$debug", $debug, "$runtime", $runtime, "$profile", $profile)'/>
  <text bgcolor="#ccffcc" text="${'runtime='+canvas.runtime + ' $debug='+$debug}"/>	
</canvas>




Modified: openlaszlo/trunk/WEB-INF/lps/schema/lfc-undeclared.lzx
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/schema/lfc-undeclared.lzx	2009-01-12 18:26:54 UTC (rev 12429)
+++ openlaszlo/trunk/WEB-INF/lps/schema/lfc-undeclared.lzx	2009-01-12 18:35:13 UTC (rev 12430)
@@ -1,7 +1,7 @@
 <library>
   
   <!-- * X_LZ_COPYRIGHT_BEGIN ***************************************************
-  * Copyright 2008 Laszlo Systems, Inc.  All Rights Reserved.                   *
+  * Copyright 2008, 2009 Laszlo Systems, Inc.  All Rights Reserved.                   *
   * Use is subject to license terms.                                            *
   * X_LZ_COPYRIGHT_END ****************************************************** -->
 
@@ -183,6 +183,7 @@
 
   <interface extends="view" name="canvas">
     <insert>
+      <attribute name="compileroptions" type="string" value=""/>
       <attribute name="debug" type="boolean" value="false"/>
       <attribute name="title" type="string" value="OpenLaszlo Application"/>
       <attribute name="id" type="ID"/>

Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/CompilationEnvironment.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/CompilationEnvironment.java	2009-01-12 18:26:54 UTC (rev 12429)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/CompilationEnvironment.java	2009-01-12 18:35:13 UTC (rev 12430)
@@ -767,6 +767,19 @@
         return mCompileTimeConstants;
     }
 
+    // Set up runtime-related compile-time constants 
+    public void setRuntimeConstants(String runtime) {
+        mCompileTimeConstants.put("$runtime", runtime);
+        mCompileTimeConstants.put("$swf7", Boolean.valueOf("swf7".equals(runtime)));
+        mCompileTimeConstants.put("$swf8", Boolean.valueOf("swf8".equals(runtime)));
+        mCompileTimeConstants.put("$as2", Boolean.valueOf(Arrays.asList(new String[] {"swf7", "swf8"}).contains(runtime)));
+        mCompileTimeConstants.put("$swf9", Boolean.valueOf("swf9".equals(runtime)));
+        mCompileTimeConstants.put("$swf10", Boolean.valueOf("swf10".equals(runtime)));
+        mCompileTimeConstants.put("$as3", Boolean.valueOf(this.isAS3()));
+        mCompileTimeConstants.put("$dhtml", Boolean.valueOf("dhtml".equals(runtime)));
+        mCompileTimeConstants.put("$j2me", Boolean.valueOf("j2me".equals(runtime)));
+        mCompileTimeConstants.put("$svg", Boolean.valueOf("svg".equals(runtime)));            
+        mCompileTimeConstants.put("$js1", Boolean.valueOf(Arrays.asList(new String[] {"dhtml", "j2me", "svg"}).contains(runtime)));
+    }
 
-
 }

Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/Compiler.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/Compiler.java	2009-01-12 18:26:54 UTC (rev 12429)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/Compiler.java	2009-01-12 18:35:13 UTC (rev 12430)
@@ -252,7 +252,30 @@
         }
     }
 
+    static void checkKnownRuntime (String runtime) throws CompilationError {
+        if (runtime != null) {
+            if (! KNOWN_RUNTIMES.contains(runtime)) {
+                List runtimes = new Vector();
+                for (Iterator iter = KNOWN_RUNTIMES.iterator();
+                     iter.hasNext(); ) {
+                    runtimes.add("\"" + iter.next() + "\"");
+                }
+                
+                throw new CompilationError(
+                    MessageFormat.format(
+                        "Request for unknown runtime: The runtime or \"lzr\" query parameter has the value \"{0}\".  It must be {1}{2}.",
+                        new String[] {
+                            runtime,
+                            new ChoiceFormat(
+                                "1#| 2#either | 2<one of ").
+                            format(runtimes.size()),
+                            new ListFormat("or").format(runtimes)
+                        }));
+            }
+        }
+    }
 
+
     /**
      * Compiles <var>file</var>, and write the bytes to
      * a stream.
@@ -285,24 +308,6 @@
         if (runtime != null) {
             mLogger.info("canvas compiler compiling runtime = " + runtime);
             env.setProperty(env.RUNTIME_PROPERTY, runtime);
-            if (! KNOWN_RUNTIMES.contains(runtime)) {
-                List runtimes = new Vector();
-                for (Iterator iter = KNOWN_RUNTIMES.iterator();
-                     iter.hasNext(); ) {
-                    runtimes.add("\"" + iter.next() + "\"");
-                }
-                
-                throw new CompilationError(
-                    MessageFormat.format(
-                        "Request for unknown runtime: The \"lzr\" query parameter has the value \"{0}\".  It must be {1}{2}.",
-                        new String[] {
-                            runtime,
-                            new ChoiceFormat(
-                                "1#| 2#either | 2<one of ").
-                            format(runtimes.size()),
-                            new ListFormat("or").format(runtimes)
-                        }));
-            }
         }
 
         String proxied = props.getProperty(CompilationEnvironment.PROXIED_PROPERTY);
@@ -395,33 +400,24 @@
 
 
             Map compileTimeConstants = new HashMap();
+            env.setCompileTimeConstants(compileTimeConstants);
+
             compileTimeConstants.put("$debug", new Boolean(
                                          env.getBooleanProperty(CompilationEnvironment.DEBUG_PROPERTY)));
             compileTimeConstants.put("$profile", new Boolean(
                                          env.getBooleanProperty(CompilationEnvironment.PROFILE_PROPERTY)));
+            compileTimeConstants.put("$backtrace", new Boolean(
+                                         env.getBooleanProperty(CompilationEnvironment.BACKTRACE_PROPERTY)));
 
-            boolean backtraceValue = env.getBooleanProperty(CompilationEnvironment.BACKTRACE_PROPERTY);
-            compileTimeConstants.put("$backtrace", new Boolean(backtraceValue));
-
             runtime = env.getProperty(env.RUNTIME_PROPERTY);
-
             // Must be kept in sync with server/sc/lzsc.py main
-            compileTimeConstants.put("$runtime", runtime);
-            compileTimeConstants.put("$swf7", Boolean.valueOf("swf7".equals(runtime)));
-            compileTimeConstants.put("$swf8", Boolean.valueOf("swf8".equals(runtime)));
-            compileTimeConstants.put("$as2", Boolean.valueOf(Arrays.asList(new String[] {"swf7", "swf8"}).contains(runtime)));
-            compileTimeConstants.put("$swf9", Boolean.valueOf("swf9".equals(runtime)));
-            compileTimeConstants.put("$swf10", Boolean.valueOf("swf10".equals(runtime)));
-            compileTimeConstants.put("$as3", Boolean.valueOf(env.isAS3()));
-            compileTimeConstants.put("$dhtml", Boolean.valueOf("dhtml".equals(runtime)));
-            compileTimeConstants.put("$j2me", Boolean.valueOf("j2me".equals(runtime)));
-            compileTimeConstants.put("$svg", Boolean.valueOf("svg".equals(runtime)));            
-            compileTimeConstants.put("$js1", Boolean.valueOf(Arrays.asList(new String[] {"dhtml", "j2me", "svg"}).contains(runtime)));
-            env.setCompileTimeConstants(compileTimeConstants);
+            env.setRuntimeConstants(runtime);
 
             Document doc = env.getParser().parse(file, env);
             Element root = doc.getRootElement();
             
+            checkKnownRuntime(env.getProperty(env.RUNTIME_PROPERTY));
+
             // cssfile cannot be set in the canvas tag
             String cssfile = props.getProperty(CompilationEnvironment.CSSFILE_PROPERTY);
             if (cssfile != null) {
@@ -480,7 +476,7 @@
             // This isn't in a finally clause, because it won't generally
             // succeed if an error occurs.
             writer.close();
-            
+
             Canvas canvas = env.getCanvas();
             if (!errors.isEmpty()) {
                 if (canvas != null) {
@@ -492,7 +488,7 @@
                 System.err.println(errors.toCompilationError().getMessage());
             }
             if (canvas != null) {
-              canvas.setBacktrace(backtraceValue);
+              canvas.setBacktrace(env.getBooleanProperty(CompilationEnvironment.BACKTRACE_PROPERTY));
               canvas.setSourceAnnotations(env.getBooleanProperty(CompilationEnvironment.SOURCE_ANNOTATIONS_PROPERTY));
               // set file path (relative to webapp) in canvas
               canvas.setFilePath(FileUtils.relativePath(file, LPS.HOME()));

Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/Parser.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/Parser.java	2009-01-12 18:26:54 UTC (rev 12429)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/Parser.java	2009-01-12 18:35:13 UTC (rev 12430)
@@ -31,6 +31,7 @@
 import org.openlaszlo.server.*;
 import org.openlaszlo.utils.*;
 import org.openlaszlo.xml.internal.*;
+import org.openlaszlo.css.CSSParser;
 
 import javax.xml.transform.TransformerConfigurationException;
 import javax.xml.transform.TransformerFactory;
@@ -404,6 +405,15 @@
         // Override passed in runtime target properties 'debug' and 'profile' with 
         // canvas values, if any.
         if (root.getName().equals("canvas")) {
+
+            String copts = root.getAttributeValue("compileroptions");
+            if (copts != null) {
+                parseCompilerOptions(root, env);
+            }
+
+            // "debug" and "profile" are here for back
+            // compatibility. But the preferred way to set compiler
+            // options is compileroptions="debug: true;backtrace: true"
             String dbg = root.getAttributeValue("debug");
             if (dbg != null) {
                 cc.put("$debug", new Boolean(dbg));
@@ -425,6 +435,52 @@
     static final String UNLESS = "unless";
     static final String OTHERWISE = "otherwise";
 
+    // Set compiler options
+    void parseCompilerOptions(Element element, CompilationEnvironment env) {
+        Map cc = env.getCompileTimeConstants();
+
+        try {
+            Map properties = new CSSParser
+                (new AttributeStream(element, "compileroptions")).Parse();
+
+            for (Iterator i2 = properties.entrySet().iterator(); i2.hasNext(); ) {
+                Map.Entry entry = (Map.Entry) i2.next();
+                String key = (String) entry.getKey();
+                Object value = entry.getValue();
+
+                mLogger.info("parseCompilerOptions key="+key+" value="+value + " typeof(value)="+value.getClass().getName());
+
+                if (key.equals("debug")) {
+                    if (! (value instanceof Boolean)) {
+                        throw new CompilationError("value of compileroptions.debug must be a boolean", element);
+                    }
+                    cc.put("$debug", value);
+                    env.setProperty(env.DEBUG_PROPERTY, ((Boolean) value).booleanValue());
+                } else if (key.equals("profile")) {
+                    if (! (value instanceof Boolean)) {
+                        throw new CompilationError("value of compileroptions.profile must be a boolean", element);
+                    }
+                    cc.put("$profile", value);
+                    env.setProperty(env.PROFILE_PROPERTY, ((Boolean) value).booleanValue());
+                } else if (key.equals("backtrace")) {
+                    if (! (value instanceof Boolean)) {
+                        throw new CompilationError("value of compileroptions.backtrace must be a boolean", element);
+                    }
+                    cc.put("$backtrace", value);
+                    env.setProperty(env.BACKTRACE_PROPERTY, ((Boolean) value).booleanValue());
+                } else if (key.equals("runtime")) {
+                    env.setProperty(env.RUNTIME_PROPERTY, (String)value);
+                    env.setRuntimeConstants((String)value);
+                }
+            }
+        } catch (org.openlaszlo.css.ParseException e) {
+            throw new CompilationError(e);
+        } catch (org.openlaszlo.css.TokenMgrError e) {
+            throw new CompilationError(e);
+        }
+    }
+
+
     /**
        usage: 
 



More information about the Laszlo-checkins mailing list