Quantcast

Resource bundling in dev commandline vs. dev WAR

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Resource bundling in dev commandline vs. dev WAR

alxndrsn
Hi,

I have a project with an in-place plugin.  When I run from the
commandline (`grails run-app`) then my resources bundle fine.
However, when I build a WAR (Environment = dev) and run this with
Jetty, then CSS resources are still bundled as expected, but for the
same module the javascript files are included separately and inherited
JS are not included.

application resource definition:
  1 modules = {
  2         common {
  3                 dependsOn 'jquery, jquery-ui' // need to redefine
these to make sure they are loaded first
  4                 resource url:[dir:'css', file:'radio.css']
  5                 resource url:[dir:'js', file:'on_air.js'],
disposition:'head'
  6                 resource url:[dir:'js', file:'dummy.js'], disposition:'head'
  7         }
  8 }

in-place plugin resource definition:
  1 modules = {
  2         common {
  3                 dependsOn "jquery, jquery-ui"
  4                 resource url:[dir:'css', file:'reset.css', plugin:'core']
...
 23                 resource url:[dir:'js',
file:"frontlinesms_core.js", plugin:'core'], disposition:'hea
...
 37         }

HTML (commandline - bundle-bundle_common_head.js contains ~20 JS files
inherited from in-place plugin, and also on_air.js):
<link href="/radio/static/bundle-bundle_common_head.css"
type="text/css" rel="stylesheet" media="screen, projection" />
<script src="/radio/static/bundle-bundle_common_head.js"
type="text/javascript" ></script>

HTML (WAR):
<link href="/static/bundle-bundle_common_head.css" type="text/css"
rel="stylesheet" media="screen, projection" />
<script src="/static/js/on_air.js" type="text/javascript" ></script>
<script src="/static/js/dummy.js" type="text/javascript" ></script>

Is there any obvious reason for this difference in behaviour, and any
simple way I can force the WAR to behave as expected?

Thanks for any help,

Alex

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Resource bundling in dev commandline vs. dev WAR

alxndrsn
Any pointers at all on how to debug this would be much appreciated.

On 19 July 2012 15:47, Alex Anderson
<[hidden email]> wrote:

> Hi,
>
> I have a project with an in-place plugin.  When I run from the
> commandline (`grails run-app`) then my resources bundle fine.
> However, when I build a WAR (Environment = dev) and run this with
> Jetty, then CSS resources are still bundled as expected, but for the
> same module the javascript files are included separately and inherited
> JS are not included.
>
> application resource definition:
>   1 modules = {
>   2         common {
>   3                 dependsOn 'jquery, jquery-ui' // need to redefine
> these to make sure they are loaded first
>   4                 resource url:[dir:'css', file:'radio.css']
>   5                 resource url:[dir:'js', file:'on_air.js'],
> disposition:'head'
>   6                 resource url:[dir:'js', file:'dummy.js'], disposition:'head'
>   7         }
>   8 }
>
> in-place plugin resource definition:
>   1 modules = {
>   2         common {
>   3                 dependsOn "jquery, jquery-ui"
>   4                 resource url:[dir:'css', file:'reset.css', plugin:'core']
> ...
>  23                 resource url:[dir:'js',
> file:"frontlinesms_core.js", plugin:'core'], disposition:'hea
> ...
>  37         }
>
> HTML (commandline - bundle-bundle_common_head.js contains ~20 JS files
> inherited from in-place plugin, and also on_air.js):
> <link href="/radio/static/bundle-bundle_common_head.css"
> type="text/css" rel="stylesheet" media="screen, projection" />
> <script src="/radio/static/bundle-bundle_common_head.js"
> type="text/javascript" ></script>
>
> HTML (WAR):
> <link href="/static/bundle-bundle_common_head.css" type="text/css"
> rel="stylesheet" media="screen, projection" />
> <script src="/static/js/on_air.js" type="text/javascript" ></script>
> <script src="/static/js/dummy.js" type="text/javascript" ></script>
>
> Is there any obvious reason for this difference in behaviour, and any
> simple way I can force the WAR to behave as expected?
>
> Thanks for any help,
>
> Alex

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Resource bundling in dev commandline vs. dev WAR

alxndrsn
> <[hidden email]> wrote:
>> I have a project with an in-place plugin.  When I run from the
>> commandline (`grails run-app`) then my resources bundle fine.
>> However, when I build a WAR (Environment = dev) and run this with
>> Jetty, then CSS resources are still bundled as expected, but for the
>> same module the javascript files are included separately and inherited
>> JS are not included.
>>
>> application resource definition:
>>   1 modules = {
>>   2         common {
>>   3                 dependsOn 'jquery, jquery-ui' // need to redefine
>> these to make sure they are loaded first
>>   4                 resource url:[dir:'css', file:'radio.css']
>>   5                 resource url:[dir:'js', file:'on_air.js'],
>> disposition:'head'
>>   6                 resource url:[dir:'js', file:'dummy.js'], disposition:'head'
>>   7         }
>>   8 }
>>
>> in-place plugin resource definition:
>>   1 modules = {
>>   2         common {
>>   3                 dependsOn "jquery, jquery-ui"
>>   4                 resource url:[dir:'css', file:'reset.css', plugin:'core']
>> ...
>>  23                 resource url:[dir:'js',
>> file:"frontlinesms_core.js", plugin:'core'], disposition:'hea
>> ...
>>  37         }
>>
>> HTML (commandline - bundle-bundle_common_head.js contains ~20 JS files
>> inherited from in-place plugin, and also on_air.js):
>> <link href="/radio/static/bundle-bundle_common_head.css"
>> type="text/css" rel="stylesheet" media="screen, projection" />
>> <script src="/radio/static/bundle-bundle_common_head.js"
>> type="text/javascript" ></script>
>>
>> HTML (WAR):grailsResourceProcessor.dumpResources()
>> <link href="/static/bundle-bundle_common_head.css" type="text/css"
>> rel="stylesheet" media="screen, projection" />
>> <script src="/static/js/on_air.js" type="text/javascript" ></script>
>> <script src="/static/js/dummy.js" type="text/javascript" ></script>
>>
>> Is there any obvious reason for this difference in behaviour, and any
>> simple way I can force the WAR to behave as expected?

Looking at the output from `grailsResourceProcessor.dumpResources()`
the JS files are not included as "synthetic resources" when run from
the WAR, but they are when run from the commandline.

Unfortunately I can't work out what this actually means, and which
behaviour is correct.  Any suggestions?

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Resource bundling in dev commandline vs. dev WAR

Marc Palmer Local

On 26 Jul 2012, at 11:14, Alex Anderson wrote:

>> <[hidden email]> wrote:
>>> I have a project with an in-place plugin.  When I run from the
>>> commandline (`grails run-app`) then my resources bundle fine.
>>> However, when I build a WAR (Environment = dev) and run this with
>>> Jetty, then CSS resources are still bundled as expected, but for the
>>> same module the javascript files are included separately and inherited
>>> JS are not included.
>>>
>>> application resource definition:
>>>  1 modules = {
>>>  2         common {
>>>  3                 dependsOn 'jquery, jquery-ui' // need to redefine
>>> these to make sure they are loaded first
>>>  4                 resource url:[dir:'css', file:'radio.css']
>>>  5                 resource url:[dir:'js', file:'on_air.js'],
>>> disposition:'head'
>>>  6                 resource url:[dir:'js', file:'dummy.js'], disposition:'head'
>>>  7         }
>>>  8 }
>>>
>>> in-place plugin resource definition:
>>>  1 modules = {
>>>  2         common {
>>>  3                 dependsOn "jquery, jquery-ui"
>>>  4                 resource url:[dir:'css', file:'reset.css', plugin:'core']
>>> ...
>>> 23                 resource url:[dir:'js',
>>> file:"frontlinesms_core.js", plugin:'core'], disposition:'hea
>>> ...
>>> 37         }
>>>
>>> HTML (commandline - bundle-bundle_common_head.js contains ~20 JS files
>>> inherited from in-place plugin, and also on_air.js):
>>> <link href="/radio/static/bundle-bundle_common_head.css"
>>> type="text/css" rel="stylesheet" media="screen, projection" />
>>> <script src="/radio/static/bundle-bundle_common_head.js"
>>> type="text/javascript" ></script>
>>>
>>> HTML (WAR):grailsResourceProcessor.dumpResources()
>>> <link href="/static/bundle-bundle_common_head.css" type="text/css"
>>> rel="stylesheet" media="screen, projection" />
>>> <script src="/static/js/on_air.js" type="text/javascript" ></script>
>>> <script src="/static/js/dummy.js" type="text/javascript" ></script>
>>>
>>> Is there any obvious reason for this difference in behaviour, and any
>>> simple way I can force the WAR to behave as expected?
>
> Looking at the output from `grailsResourceProcessor.dumpResources()`
> the JS files are not included as "synthetic resources" when run from
> the WAR, but they are when run from the commandline.
>
> Unfortunately I can't work out what this actually means, and which
> behaviour is correct.  Any suggestions?


Hi,

First: I don't recall that there is explicit support for defining resources in modules additively, without using the overrides section.

In short: don't use the same module names.

If the problem does not go away when you switch to unique module names, then please raise a JIRA with a sample project demonstration the problem - if there is a problem it must be related to resolving artefacts or resources in inline plugins - which I never use.

Marc
~ ~ ~
Marc Palmer
Freelancer (Grails/Groovy/Java/UX)

I offer commercial support for Grails plugins from as low as $50/mo.
For details see: http://grailsrocks.com

Blog: http://www.anyware.co.uk | Resumé: http://www.anyware.co.uk/marc
Contributor @ http://grails.org |  Founder @ http://noticelocal.com
Developer @ http://weceem.org | Member @ http://spottymushroom.com
Twitter: http://twitter.com/wangjammer5 


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Resource bundling in dev commandline vs. dev WAR

alxndrsn
Hi Marc,

Thanks for the response.

> First: I don't recall that there is explicit support for defining resources in modules additively, without using the overrides section.
>
> In short: don't use the same module names.
Is it possible to add new resources to a bundle using the `overrides` section?

> If the problem does not go away when you switch to unique module names, then please raise a JIRA with a sample project demonstration the problem - if there is a problem it must be related to resolving artefacts or resources in inline plugins - which I never use.
I've not had any other problems with inline plugins.

Is there a simple explanation for the disparity between handling of
CSS (working in my unsupported case described previously), and JS (not
working)?

Thanks,

Alex

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Resource bundling in dev commandline vs. dev WAR

Marc Palmer Local

On 26 Jul 2012, at 12:42, Alex Anderson wrote:

> Hi Marc,
>
> Thanks for the response.
>
>> First: I don't recall that there is explicit support for defining resources in modules additively, without using the overrides section.
>>
>> In short: don't use the same module names.
> Is it possible to add new resources to a bundle using the `overrides` section?
>

Yes but you don't need to. Bundles are cross-module - although this can introduce some module dependency confusion.

You can either add resources to a module, which should use the default bundle of that module, and/or you can specify an explicit bundle id on the resource you declare, whether in overrides or some other module.

>> If the problem does not go away when you switch to unique module names, then please raise a JIRA with a sample project demonstration the problem - if there is a problem it must be related to resolving artefacts or resources in inline plugins - which I never use.
> I've not had any other problems with inline plugins.
>
> Is there a simple explanation for the disparity between handling of
> CSS (working in my unsupported case described previously), and JS (not
> working)?


Well there are different processors applied, but aside from that nothing off the top of my head.

I think your "merging" of modules may be working inconsistently, by luck.

Marc

~ ~ ~
Marc Palmer
Freelancer (Grails/Groovy/Java/UX)

I offer commercial support for Grails plugins from as low as $50/mo.
For details see: http://grailsrocks.com

Blog: http://www.anyware.co.uk | Resumé: http://www.anyware.co.uk/marc
Contributor @ http://grails.org |  Founder @ http://noticelocal.com
Developer @ http://weceem.org | Member @ http://spottymushroom.com
Twitter: http://twitter.com/wangjammer5 


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Resource bundling in dev commandline vs. dev WAR

alxndrsn
>> Is it possible to add new resources to a bundle using the `overrides` section?
> Yes but you don't need to. Bundles are cross-module - although this can introduce some module dependency confusion.
This didn't appear to work...

> You can either add resources to a module, which should use the default bundle of that module, and/or you can specify >
If a GSP in a plugin "requires" module `X` (originally defined in the
plugin), will that also include resources from *bundle* `X` defined in
module `Y` with `defaultBundle('X')` inside the main application?
i.e. does gsp code such as `<r:require module="X"/>` include the
bundle or the module?

If I add resources to bundle X in the way described above, is there a
way to guarantee order, especially of resources from the plugin vs
resources from the application?

Thanks again for the help with this,

Alex

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Resource bundling in dev commandline vs. dev WAR

Marc Palmer Local

On 27 Jul 2012, at 09:04, Alex Anderson <[hidden email]> wrote:

>>> Is it possible to add new resources to a bundle using the `overrides` section?
>> Yes but you don't need to. Bundles are cross-module - although this can introduce some module dependency confusion.
> This didn't appear to work...

Did you try it in an overrides section rather than in a duplicated module name?

>
>> You can either add resources to a module, which should use the default bundle of that module, and/or you can specify >
> If a GSP in a plugin "requires" module `X` (originally defined in the
> plugin), will that also include resources from *bundle* `X` defined in
> module `Y` with `defaultBundle('X')` inside the main application?
> i.e. does gsp code such as `<r:require module="X"/>` include the
> bundle or the module?
>

Require is about *modules*, nothing else. A bundle is just a resource that is created for you, by aggregating other resources.

By default, a module will be bundle if it has > 1 resource of a bundlable type, and it will be bundled using the module name.

You change this with defaultBundle setting on the module, or per-resource bundle ids.

> If I add resources to bundle X in the way described above, is there a
> way to guarantee order, especially of resources from the plugin vs
> resources from the application?

Let me correct you (I think): you are not adding a resource to a bundle. You are adding a resource to a module. It may or may not be bundled, that is a packaging detail.

However that's an interesting problem. Currently you cannot order resources added in "overrides" clause, but this is feasible in future because you can address resources by id within the module you are overriding, so we could have "after:['x', 'y']" and a before equivalent.

You can do this now by structuring your modules well, breaking them down into dependencies that will let you use overrides to add a dependsOn to the module, such that it depends on your code that you want to add at a certain place.

Using overrides you can change the dependencies of any module:

modules = {
    common {
        dependsOn 'x', 'y', 'z'
    }

    x {
       resource url:'css/main.css'
    }

    y {
       resource url:'css/sub1.css'
    }


    z {
       resource url:'css/sub2.css'
    }

}

Then in you could override the dependencies of common:

modules = {
    overrides {
        common {
            dependsOn 'x', 'newmodule', 'y', 'z'
        }
    }

    newmodule {
        resource url:'css/injected.css'
    }
}


That will make the order of resources:

main.css
injected.css
sub1.css
sub2.css

Note that they would not be bundled at all, because no module has more than one resource in it (why bundle one resource?).

If you add bundle:'whatever' to all those resources, or defaultBundle:'whatever' to all those modules, they will be bundled together - but I can't guarantee right now that they appear in the right dependency order in the bundle. This was (or is) a known and complex bug.

Generally bundling is best done within modules at the moment.

Marc
~ ~ ~
Marc Palmer
Freelancer (Grails/Groovy/Java/UX)

I offer commercial support for Grails plugins from as low as $50/mo.
For details see: http://grailsrocks.com

Blog: http://www.anyware.co.uk | Resumé: http://www.anyware.co.uk/marc
Contributor @ http://grails.org |  Founder @ http://noticelocal.com
Developer @ http://weceem.org | Member @ http://spottymushroom.com
Twitter: http://twitter.com/wangjammer5 


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Loading...