Skip to main content

Problem with overrideKey in production mode

  4 posts   Feedicon  
Replies: 3 - Last Post: February 19, 2014 08:29
by: icefox
showing 1 - 4 of 4
Posted: February 18, 2014 15:33 by sbaruzza
Hi,

I have a problems with jawr 3.5 bundles (a follow-up to issue #261).

Using a composite bundle to choose between two set of mappings (one for debug, one for production), set up as:
jawr.js.bundle.extjs.id=/extjs.js
jawr.js.bundle.extjs.composite=true
jawr.js.bundle.extjs.child.names=extjs-prod, extjs-debug

jawr.js.bundle.extjs-prod.mappings=/ext/ext-all.js
jawr.js.bundle.extjs-prod.debugnever=true
jawr.js.bundle.extjs-prod.bundlepostprocessors=none

jawr.js.bundle.extjs-debug.mappings=/ext/ext-all-debug.js
jawr.js.bundle.extjs-debug.debugonly=true
jawr.js.bundle.extjs-debug.bundlepostprocessors=none


works correctly using the patch for issue #261.

Problems arise when you try to use overrideKey in a production environment to enter debug mode. In this situation, no file will be included by Jawr.

<script type="text/javascript">/* Start adding members resolved by '/extjs.js'. Bundle id is: '/extjs.js' */</script>
<script type="text/javascript">/* Finished adding members resolved by /extjs.js */</script>


Debugging through Jawr code, it appears that a bundle started in production mode will always have an empty itemDebugPathList, thus making it impossible to enter debug mode for a single page.

It seems that the cause resides in CompositeResourceBundle, since its constructor decides whether to use its children as debug or production.

I have replaced its constructor with the following code, using the same conditions found in JoinableResourceBundleImpl.addPathMapping():
public CompositeResourceBundle(String id, String name,
            List<JoinableResourceBundle> childBundles,
            InclusionPattern inclusionPattern,
            ResourceReaderHandler resourceHandler,
            String fileExtension,
            JawrConfig config) {

        super(id, name, fileExtension, inclusionPattern, resourceHandler, config.getGeneratorRegistry());
        this.childBundles = childBundles;
        for (Iterator<JoinableResourceBundle> it = this.childBundles.iterator(); it.hasNext();) {
            JoinableResourceBundle child = it.next();
            if (!child.getInclusionPattern().isIncludeOnlyOnDebug()) {
                this.itemPathList.addAll(child.getItemPathList());
            }

            if (!child.getInclusionPattern().isExcludeOnDebug()) {
                this.itemDebugPathList.addAll(child.getItemDebugPathList());
            }
            this.licensesPathList.addAll(child.getLicensesPathList());

            // If the child has no postprocessors, apply the composite's if any
            if (null == child.getBundlePostProcessor()) {
                child.setBundlePostProcessor(this.getBundlePostProcessor());
            }
            if (null == child.getUnitaryPostProcessor()) {
                child.setUnitaryPostProcessor(this.getUnitaryPostProcessor());
            }
        }
    }


This change breaks a few tests in CompositeResourceBundleTest, since the contained test cases use JoinableResourceBundleImpl.belongsToBundle() which checks if a file is contained in either itemPathList or itemDebugPathList. These test cases can be fixed replacing belongsToBundle() with direct calls to getItemPathList().contains() and getItemDebugPathList().contains().

Applying this patch it's again possible to use overrideKey to enter debug mode in a production environment.
Posted: February 18, 2014 15:34 by sbaruzza
Patch against jawr-core 3.5 (tag)

diff -r 99f404e7e452 jawr-core/src/main/java/net/jawr/web/resource/bundle/CompositeResourceBundle.java
--- a/jawr-core/src/main/java/net/jawr/web/resource/bundle/CompositeResourceBundle.java	Mon Feb 17 17:37:40 2014 +0100
+++ b/jawr-core/src/main/java/net/jawr/web/resource/bundle/CompositeResourceBundle.java	Tue Feb 18 16:33:06 2014 +0100
@@ -53,21 +58,17 @@
 		
 		super(id, name, fileExtension, inclusionPattern, resourceHandler, config.getGeneratorRegistry());
 		this.childBundles = childBundles;
-		
-		boolean debugModeOn = config.isDebugModeOn();
+        // Don't care for debug mode... it may be changed by appending an override key
+        // final boolean debugModeOn = config.isDebugModeOn();
 		for(Iterator<JoinableResourceBundle> it = this.childBundles.iterator();it.hasNext();) {
 			JoinableResourceBundle child = it.next();
+            if (!child.getInclusionPattern().isIncludeOnlyOnDebug()) {
+                this.itemPathList.addAll(child.getItemPathList());
+            }
 			
-			// Skip the child as needed
-			if( (debugModeOn && child.getInclusionPattern().isExcludeOnDebug()) || 
-				(!debugModeOn && child.getInclusionPattern().isIncludeOnlyOnDebug()) )
-				continue;
-			
-			this.itemPathList.addAll(child.getItemPathList());
-			if(child.getInclusionPattern().isIncludeOnDebug()){
+            if (!child.getInclusionPattern().isExcludeOnDebug()) {
 				this.itemDebugPathList.addAll(child.getItemDebugPathList());
 			}
-			
 			this.licensesPathList.addAll(child.getLicensesPathList());
 			
 			// If the child has no postprocessors, apply the composite's if any
@@ -89,7 +90,8 @@
   	}
   	
  	/**
-	 * @return List<JoinableResourceBundle> The bundles which are members of this composite.
+     * @return List<JoinableResourceBundle> The bundles which are members of
+     * this composite.
 	 */
 	public List<JoinableResourceBundle> getChildBundles() {
 		return childBundles;
diff -r 99f404e7e452 jawr-core/src/test/java/test/net/jawr/web/resource/bundle/CompositeResourceBundleTest.java
--- a/jawr-core/src/test/java/test/net/jawr/web/resource/bundle/CompositeResourceBundleTest.java	Mon Feb 17 17:37:40 2014 +0100
+++ b/jawr-core/src/test/java/test/net/jawr/web/resource/bundle/CompositeResourceBundleTest.java	Tue Feb 18 16:33:06 2014 +0100
@@ -63,38 +63,38 @@
 	public void testDebugModeInclusion_debug() {
 		
 		assertTrue("/outsider.js should be added in debug mode",
-				compositeCollectionDebugOnly.belongsToBundle("/outsider.js"));
+				compositeCollectionDebugOnly.getItemDebugPathList().contains("/outsider.js"));
 		
 		assertTrue("/js/subfolder/subfolderscript.js should be added in debug mode",
-				compositeCollectionDebugOnly.belongsToBundle("/js/subfolder/subfolderscript.js"));
+				compositeCollectionDebugOnly.getItemDebugPathList().contains("/js/subfolder/subfolderscript.js"));
 		
 		assertFalse("/js/subfolder2/subfolderscript2.js should not be added in debug mode",
-				compositeCollectionDebugOnly.belongsToBundle("/js/subfolder2/subfolderscript2.js"));
+				compositeCollectionDebugOnly.getItemDebugPathList().contains("/js/subfolder2/subfolderscript2.js"));
 		
 	}
 
 	public void testDebugModeInclusion_nodebug() {
 		
 		assertFalse("/outsider.js should not be added in production mode",
-				compositeCollectionNoDebug.belongsToBundle("/outsider.js"));
+				compositeCollectionNoDebug.getItemPathList().contains("/outsider.js"));
 		
 		assertFalse("/js/subfolder/subfolderscript.js should not be added in production mode",
-				compositeCollectionNoDebug.belongsToBundle("/js/subfolder/subfolderscript.js"));
+				compositeCollectionNoDebug.getItemPathList().contains("/js/subfolder/subfolderscript.js"));
 		
 		assertTrue("/js/subfolder2/subfolderscript2.js should be added in production mode",
-				compositeCollectionNoDebug.belongsToBundle("/js/subfolder2/subfolderscript2.js"));
+				compositeCollectionNoDebug.getItemPathList().contains("/js/subfolder2/subfolderscript2.js"));
 	}
 	
 	public void testDebugModeInclusion_always() {
 		
 		assertTrue("/outsider.js should be added in debug mode",
-				compositeCollectionDebugAlways.belongsToBundle("/outsider.js"));
+				compositeCollectionDebugAlways.getItemDebugPathList().contains("/outsider.js"));
 		
 		assertTrue("/js/subfolder/subfolderscript.js should be added in debug mode",
-				compositeCollectionDebugAlways.belongsToBundle("/js/subfolder/subfolderscript.js"));
+				compositeCollectionDebugAlways.getItemDebugPathList().contains("/js/subfolder/subfolderscript.js"));
 		
 		assertFalse("/js/subfolder2/subfolderscript2.js should not be added in debug mode",
-				compositeCollectionDebugAlways.belongsToBundle("/js/subfolder2/subfolderscript2.js"));
+				compositeCollectionDebugAlways.getItemDebugPathList().contains("/js/subfolder2/subfolderscript2.js"));
 	}
 	
 	// Test: debugonly is not added on prod. mode, and is added in debug mode. 
Posted: February 18, 2014 15:50 by sbaruzza
Created issue #272 on Jira
Posted: February 19, 2014 08:29 by icefox
Hi

Thanks for reporting this issue and providing a patch.

This fix will be available in the next version (3.5.1 ).

Cheers,
Replies: 3 - Last Post: February 19, 2014 08:29
by: icefox
 
 
Close
loading
Please Confirm
Close