You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2012/10/24 03:06:11 UTC

[1/2] git commit: Remove distinction between core libraries and ordinary libraries - core libraries still get loaded first Fix some broken tests due to shifting things around

Updated Branches:
  refs/heads/5.4-js-rewrite 0ae142958 -> 10d8a289e


Remove distinction between core libraries and ordinary libraries
- core libraries still get loaded first
Fix some broken tests due to shifting things around


Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/10d8a289
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/10d8a289
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/10d8a289

Branch: refs/heads/5.4-js-rewrite
Commit: 10d8a289eaf2525e53c84167fc32360b40650129
Parents: ad4d98c
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Tue Oct 23 18:06:02 2012 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Tue Oct 23 18:06:02 2012 -0700

----------------------------------------------------------------------
 .../META-INF/modules/core/pageinit.coffee          |   22 ++++++---------
 .../internal/services/DocumentLinker.java          |   14 +---------
 .../internal/services/DocumentLinkerImpl.java      |   12 +-------
 .../services/PartialMarkupDocumentLinker.java      |    7 -----
 .../services/ajax/JavaScriptSupportImpl.java       |    8 +-----
 .../services/javascript/ModuleManagerImpl.java     |    3 +-
 .../services/javascript/ModuleManager.java         |    7 +---
 .../resources/org/apache/tapestry5/core.properties |    2 +-
 .../services/DocumentLinkerImplTest.groovy         |   19 ++++++-------
 .../services/ajax/JavaScriptSupportImplTest.groovy |    7 +++--
 10 files changed, 29 insertions(+), 72 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/10d8a289/tapestry-core/src/main/coffeescript/META-INF/modules/core/pageinit.coffee
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/coffeescript/META-INF/modules/core/pageinit.coffee b/tapestry-core/src/main/coffeescript/META-INF/modules/core/pageinit.coffee
index dcbabdc..57ebc26 100644
--- a/tapestry-core/src/main/coffeescript/META-INF/modules/core/pageinit.coffee
+++ b/tapestry-core/src/main/coffeescript/META-INF/modules/core/pageinit.coffee
@@ -134,19 +134,15 @@ define ["_", "core/console", "core/spi", "core/events"],
 
         finalCallback.call null
 
-      # Loads all the core libraries (the core JavaScript Stack), in order.It then ensures that some key modules have
-      # initialized, and loads all other libraries in order (this includes other stacks beyond core, and free-standing
-      # libraries). It then executes the immediate initializations. After that, it waits for the DOM to be ready and
-      # executes the other initializations. A lot of the complexity here is for compatibility with Tapestry 5.3 and
-      # earlier, where dependencies were exclusively defined in terms of load order (and there were lots of globals).
-      loadLibrariesAndInitialize: (coreLibraries, libraries, immediateInits, otherInits) ->
-        exports.loadLibraries coreLibraries, ->
-          console.debug "#{coreLibraries?.length or 0} core libraries loaded"
-          exports.loadLibraries libraries, ->
-            console.debug "#{libraries?.length or 0} additional libraries loaded"
-            exports.initialize immediateInits
-
-            spi.domReady -> exports.initialize otherInits
+      # Loads all specified libraries in order (this includes other the core stack, other stacks, and
+      # any free-standing libraries). It then executes the immediate initializations. After that, it waits for the DOM to be
+      # ready (which, given typical Tapestry page structure, it almost certainly is at the point this function
+      # executed), and then executes the other initializations.
+      loadLibrariesAndInitialize: (libraries, immediateInits, otherInits) ->
+        exports.loadLibraries libraries, ->
+          exports.initialize immediateInits
+
+          spi.domReady -> exports.initialize otherInits
 
       evalJavaScript: (js) ->
         console.debug "Evaluating: #{js}"

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/10d8a289/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/DocumentLinker.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/DocumentLinker.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/DocumentLinker.java
index eafddd6..886d534 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/DocumentLinker.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/DocumentLinker.java
@@ -22,23 +22,11 @@ import org.apache.tapestry5.services.javascript.StylesheetLink;
  * Responsible for injecting script and style links into the &lt;head&gt; and &lt;body&gt; element of the rendered HTML
  * document.
  *
- * @see org.apache.tapestry5.services.javascript.ModuleManager#writeInitialization(org.apache.tapestry5.dom.Element, java.util.List, java.util.List, java.util.List, java.util.List)
+ * @see org.apache.tapestry5.services.javascript.ModuleManager#writeInitialization(org.apache.tapestry5.dom.Element, java.util.List
  * @since 5.4
  */
 public interface DocumentLinker
 {
-    /**
-     * Special handling for the
-     * {@linkplain org.apache.tapestry5.internal.services.javascript.CoreJavaScriptStack }core JavaScriptStack},
-     * whose contents are loaded directly at page startup. This represents special treatment of the core JavaScriptStack,
-     * starting in release 5.4. It is necessary during the transition from JavaScript libraries (that make use of the
-     * client-side Tapestry and/or T5 globals) to modules.
-     *
-     *
-     * @param libraryURL
-     * @since 5.4
-     */
-    void addCoreLibrary(String libraryURL);
 
     /**
      * Adds a link to load a non-core JavaScript library. These libraries are loaded, sequentially, only once

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/10d8a289/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/DocumentLinkerImpl.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/DocumentLinkerImpl.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/DocumentLinkerImpl.java
index 4301b86..3fa1157 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/DocumentLinkerImpl.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/DocumentLinkerImpl.java
@@ -26,8 +26,6 @@ import java.util.List;
 
 public class DocumentLinkerImpl implements DocumentLinker
 {
-    private final List<String> coreLibraryURLs = CollectionFactory.newList();
-
     private final List<String> libraryURLs = CollectionFactory.newList();
 
     private final ModuleInitsManager initsManager = new ModuleInitsManager();
@@ -65,14 +63,6 @@ public class DocumentLinkerImpl implements DocumentLinker
     }
 
 
-    @Override
-    public void addCoreLibrary(String libraryURL)
-    {
-        coreLibraryURLs.add(libraryURL);
-
-        hasScriptsOrInitializations = true;
-    }
-
     public void addLibrary(String libraryURL)
     {
         libraryURLs.add(libraryURL);
@@ -199,7 +189,7 @@ public class DocumentLinkerImpl implements DocumentLinker
         // (in <head> or at bottom of <body>). Switching to a module approach gives us a new chance to fix this.
         // Eventually, (nearly) everything will be loaded as modules.
 
-        moduleManager.writeInitialization(body, coreLibraryURLs, libraryURLs,
+        moduleManager.writeInitialization(body, libraryURLs,
                 initsManager.forPriority(InitializationPriority.IMMEDIATE),
                 initsManager.forPriority(InitializationPriority.EARLY, InitializationPriority.NORMAL, InitializationPriority.LATE));
     }

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/10d8a289/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PartialMarkupDocumentLinker.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PartialMarkupDocumentLinker.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PartialMarkupDocumentLinker.java
index a802339..fe64a04 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PartialMarkupDocumentLinker.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PartialMarkupDocumentLinker.java
@@ -28,13 +28,6 @@ public class PartialMarkupDocumentLinker implements DocumentLinker
 
     private final ModuleInitsManager initsManager = new ModuleInitsManager();
 
-    @Override
-    public void addCoreLibrary(String libraryURL)
-    {
-        // Really, this will never happen.
-        throw new IllegalStateException("Core libraries may not be added during a partial page render.");
-    }
-
     public void addLibrary(String libraryURL)
     {
         libraryURLs.put(libraryURL);

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/10d8a289/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/JavaScriptSupportImpl.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/JavaScriptSupportImpl.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/JavaScriptSupportImpl.java
index 5d01e6f..a5b9875 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/JavaScriptSupportImpl.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/JavaScriptSupportImpl.java
@@ -331,13 +331,7 @@ public class JavaScriptSupportImpl implements JavaScriptSupport
 
         for (String libraryURL : libraryURLs)
         {
-            if (stackName.equals(InternalConstants.CORE_STACK_NAME))
-            {
-                linker.addCoreLibrary(libraryURL);
-            } else
-            {
-                linker.addLibrary(libraryURL);
-            }
+            linker.addLibrary(libraryURL);
         }
 
         stylesheetLinks.addAll(stack.getStylesheets());

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/10d8a289/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/ModuleManagerImpl.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/ModuleManagerImpl.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/ModuleManagerImpl.java
index cfa2927..3509f79 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/ModuleManagerImpl.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/ModuleManagerImpl.java
@@ -139,7 +139,7 @@ public class ModuleManagerImpl implements ModuleManager
         tracker.clearOnInvalidation(cache);
     }
 
-    public void writeInitialization(Element body, List<String> coreLibraryURLs, List<String> libraryURLs, List<JSONArray> immediateInits, List<JSONArray> deferredInits)
+    public void writeInitialization(Element body, List<String> libraryURLs, List<JSONArray> immediateInits, List<JSONArray> deferredInits)
     {
         body.element("script", "src", requireJS.toClientURL());
 
@@ -150,7 +150,6 @@ public class ModuleManagerImpl implements ModuleManager
         StringBuilder content = new StringBuilder(1000);
 
         content.append(globalMessages.format("core-page-initialization-template",
-                convert(coreLibraryURLs),
                 convert(libraryURLs),
                 convert(immediateInits),
                 convert(deferredInits)));

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/10d8a289/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/ModuleManager.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/ModuleManager.java b/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/ModuleManager.java
index 4913175..d0c2667 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/ModuleManager.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/ModuleManager.java
@@ -42,17 +42,14 @@ public interface ModuleManager
      *
      * @param body
      *         {@code <body>} element of the page, to which new {@code <script>>} element(s) will be added.
-     * @param coreLibraryURLs
-     *         list of static JavaScript library URLs that must be loaded on the page, prior to any initializations
      * @param libraryURLs
      *         list of additional static JavaScript library URLs that must be loaded on the page, after the
      *         coreLibraryURLs, and before an initializations
      * @param immediateInits
-     *         list of immediate initializations that occur as soon as the static JavaScript libraries are loaded
+ *         list of immediate initializations that occur as soon as the static JavaScript libraries are loaded
      * @param deferredInits
-     *          list of initializations that are deferred until after the browser document is ready    *
      */
-    void writeInitialization(Element body, List<String> coreLibraryURLs, List<String> libraryURLs, List<JSONArray> immediateInits, List<JSONArray> deferredInits);
+    void writeInitialization(Element body, List<String> libraryURLs, List<JSONArray> immediateInits, List<JSONArray> deferredInits);
 
     /**
      * Given a module name (which may be a path of names separated by slashes), locates the corresponding {@link Resource}.

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/10d8a289/tapestry-core/src/main/resources/org/apache/tapestry5/core.properties
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/resources/org/apache/tapestry5/core.properties b/tapestry-core/src/main/resources/org/apache/tapestry5/core.properties
index d3cc13a..a096a54 100644
--- a/tapestry-core/src/main/resources/org/apache/tapestry5/core.properties
+++ b/tapestry-core/src/main/resources/org/apache/tapestry5/core.properties
@@ -49,7 +49,7 @@ required=You must provide a value for %s.
 
 core-page-initialization-template=\
 require(["core/pageinit"], function(pageinit) {\
-  pageinit.loadLibrariesAndInitialize(%s, %s, %s, %s); \
+  pageinit.loadLibrariesAndInitialize(%s, %s, %s); \
 });
 
 # Default values for selected core component parameters.

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/10d8a289/tapestry-core/src/test/groovy/org/apache/tapestry5/internal/services/DocumentLinkerImplTest.groovy
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/groovy/org/apache/tapestry5/internal/services/DocumentLinkerImplTest.groovy b/tapestry-core/src/test/groovy/org/apache/tapestry5/internal/services/DocumentLinkerImplTest.groovy
index bab9659..f76defb 100644
--- a/tapestry-core/src/test/groovy/org/apache/tapestry5/internal/services/DocumentLinkerImplTest.groovy
+++ b/tapestry-core/src/test/groovy/org/apache/tapestry5/internal/services/DocumentLinkerImplTest.groovy
@@ -93,13 +93,13 @@ class DocumentLinkerImplTest extends InternalBaseTestCase {
 
         document.newRootElement("html").element("body").element("p").text("Ready to be updated with scripts.")
 
-        def manager = mockModuleManager(["core.js"], ["foo.js", "bar/baz.js"], [], [new JSONArray("core/pageinit:evalJavaScript", "pageInitialization();")])
+        def manager = mockModuleManager(["core.js", "foo.js", "bar/baz.js"], [], [new JSONArray("core/pageinit:evalJavaScript", "pageInitialization();")])
 
         DocumentLinkerImpl linker = new DocumentLinkerImpl(manager, true, "1.2.3")
 
         replay()
 
-        linker.addCoreLibrary("core.js")
+        linker.addLibrary("core.js")
         linker.addLibrary("foo.js")
         linker.addLibrary("bar/baz.js")
         linker.addScript(InitializationPriority.NORMAL, "pageInitialization();")
@@ -197,7 +197,7 @@ class DocumentLinkerImplTest extends InternalBaseTestCase {
 
         document.newRootElement("html").element("body").element("p").text("Ready to be updated with scripts.")
 
-        def manager = mockModuleManager([], [], [new JSONArray("core/pageinit:evalJavaScript", "doSomething();")], [])
+        def manager = mockModuleManager([], [new JSONArray("core/pageinit:evalJavaScript", "doSomething();")], [])
 
         DocumentLinkerImpl linker = new DocumentLinkerImpl(manager, true, "1.2.3")
 
@@ -223,7 +223,7 @@ class DocumentLinkerImplTest extends InternalBaseTestCase {
 
         document.newRootElement("html").element("notbody").element("p").text("Ready to be updated with scripts.")
 
-        def manager = mockModuleManager([], ["foo.js"], [], [])
+        def manager = mockModuleManager(["foo.js"], [], [])
 
         DocumentLinkerImpl linker = new DocumentLinkerImpl(manager, true, "1.2.3")
 
@@ -250,7 +250,7 @@ class DocumentLinkerImplTest extends InternalBaseTestCase {
         head.element("meta")
         head.element("script")
 
-        def manager = mockModuleManager([], [], [new JSONArray("['immediate/module:myfunc', {'fred':'barney'}]")], [])
+        def manager = mockModuleManager([], [new JSONArray("['immediate/module:myfunc', {'fred':'barney'}]")], [])
 
         DocumentLinkerImpl linker = new DocumentLinkerImpl(manager, true, "1.2.3")
 
@@ -277,7 +277,7 @@ class DocumentLinkerImplTest extends InternalBaseTestCase {
         head.element("meta")
         head.element("script")
 
-        def manager = mockModuleManager([], [], [], [new JSONArray("['my/module', 'barney']")])
+        def manager = mockModuleManager([], [], [new JSONArray("['my/module', 'barney']")])
 
         DocumentLinkerImpl linker = new DocumentLinkerImpl(manager, true, "1.2.3")
 
@@ -341,7 +341,7 @@ class DocumentLinkerImplTest extends InternalBaseTestCase {
 
         head.element("meta")
 
-        def manager = mockModuleManager([], [], [], [new JSONArray("['my/module']"),
+        def manager = mockModuleManager([], [], [new JSONArray("['my/module']"),
             new JSONArray("my/other/module:normal", 111, 222),
             new JSONArray("my/other/module:late", 333, 444)])
 
@@ -370,7 +370,7 @@ class DocumentLinkerImplTest extends InternalBaseTestCase {
 
         head.element("meta")
 
-        def manager = mockModuleManager([], [], [], [new JSONArray("['my/module']"),
+        def manager = mockModuleManager([], [], [new JSONArray("['my/module']"),
             new JSONArray("my/other/module:normal", 111, 222)])
 
         DocumentLinkerImpl linker = new DocumentLinkerImpl(manager, true, "1.2.3")
@@ -390,12 +390,11 @@ class DocumentLinkerImplTest extends InternalBaseTestCase {
         verify()
     }
 
-    private ModuleManager mockModuleManager(def coreLibraryURLs, def libraryURLs, def immediateInits, def deferredInits) {
+    private ModuleManager mockModuleManager(def libraryURLs, def immediateInits, def deferredInits) {
 
         ModuleManager mock = newMock(ModuleManager);
 
         expect(mock.writeInitialization(isA(Element),
-            eq(coreLibraryURLs),
             eq(libraryURLs),
             eq(immediateInits),
             eq(deferredInits))).andAnswer({

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/10d8a289/tapestry-core/src/test/groovy/org/apache/tapestry5/internal/services/ajax/JavaScriptSupportImplTest.groovy
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/groovy/org/apache/tapestry5/internal/services/ajax/JavaScriptSupportImplTest.groovy b/tapestry-core/src/test/groovy/org/apache/tapestry5/internal/services/ajax/JavaScriptSupportImplTest.groovy
index 3740f53..71d5a35 100644
--- a/tapestry-core/src/test/groovy/org/apache/tapestry5/internal/services/ajax/JavaScriptSupportImplTest.groovy
+++ b/tapestry-core/src/test/groovy/org/apache/tapestry5/internal/services/ajax/JavaScriptSupportImplTest.groovy
@@ -42,7 +42,8 @@ class JavaScriptSupportImplTest extends InternalBaseTestCase {
     void partial_mode_add_script() {
         DocumentLinker linker = mockDocumentLinker()
 
-        train_init(linker, InitializationPriority.NORMAL, "evalScript", "doSomething();")
+        linker.addInitialization(InitializationPriority.NORMAL, "core/pageinit", "evalJavaScript",
+            new JSONArray().put("doSomething();"))
 
         replay()
 
@@ -108,8 +109,8 @@ class JavaScriptSupportImplTest extends InternalBaseTestCase {
 
         expect(stack.stacks).andReturn([])
 
-        linker.addCoreLibrary("stack1.js")
-        linker.addCoreLibrary("stack2.js")
+        linker.addLibrary("stack1.js")
+        linker.addLibrary("stack2.js")
         linker.addStylesheetLink(stylesheetLink)
     }