Grails JIRA

  • Log In Access more options
    • Online Help
    • GreenHopper Help
    • Agile Answers
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What’s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
  • Agile
Grails
  • Grails
  • GRAILS-3180 Top level task: Improvements to Grail...
  • GRAILS-2285

ability to override a plugin's artefacts

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Sub-task Sub-task
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.0-RC4
  • Fix Version/s: 1.3-RC1
  • Component/s: None
  • Labels:
    None

Description

It should be possible to override services/controllers/etc; summary of problem:

I've written a plugin, called MyPlugin.

I've written an app, called MyApp; which is designed to use MyPlugin for
base/default functionality.

MyPlugin provides a service, called ThisService.

MyApp needs to override or replace the ThisService service.

However when I try to run MyApp, or install MyPlugin into MyApp, when MyApp
has its own ThisService - I get a: "Invalid duplicate class definition of
class ThisService" exception.

This is a major hassle - to get around it I need to temporarily remove
MyApp's ThisService, then install (or) re-install MyPlugin, then remove
MyPlugin's ThisService; then finally put MyApp's ThisService back into
place so that I'm able to continue development/testing with MyApp.

More info:

http://www.nabble.com/how-to-override-a-service-provided-by-a-plugin--to15035806.html

  • Options
    • Sort By Name
    • Sort By Date
    • Ascending
    • Descending
    • Download All

Attachments

  1. Text File
    _GrailsCompile.groovy.patch
    28/Apr/09 4:49 PM
    1 kB
    Lari Hotari

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
  • Git Commits
Hide
Permalink
Graeme Rocher added a comment - 28/Jan/08 9:02 AM

have to be post 1.0 i'm afraid

Show
Graeme Rocher added a comment - 28/Jan/08 9:02 AM have to be post 1.0 i'm afraid
Hide
Permalink
Mingfai Ma added a comment - 17/Jan/09 1:36 AM

one more similar use case. sometimes, user may want to disable/remove particular controller/services of a plugin, e.g.a demo controller

reference
http://www.nabble.com/Grails-plugin-and-demo-tt21494978.html#a21494978

Show
Mingfai Ma added a comment - 17/Jan/09 1:36 AM one more similar use case. sometimes, user may want to disable/remove particular controller/services of a plugin, e.g.a demo controller reference http://www.nabble.com/Grails-plugin-and-demo-tt21494978.html#a21494978
Hide
Permalink
Graeme Rocher added a comment - 06/Feb/09 8:13 AM

Well for your issue, you could get around it by simply defining another Spring bean that matches the name of the service provided by the plugin. So if you have a FooService provided by Plugin A you simply defined

fooService(MyAlternativeImplementation)

in resources.groovy. For your case Mingfai. I have implemented the ability for a plugin author to exclude particular resources from a plugin when installed into an app like:

class FooGrailsPlugin {
	def pluginExcludes = ['grails-app/controllers/DemoController.groovy']
}

However I will leave this issue open as it would be nice to add overriding simply by defining a class of the same name as in a plugin, but I'm not sure we'll get this into 1.1

Show
Graeme Rocher added a comment - 06/Feb/09 8:13 AM Well for your issue, you could get around it by simply defining another Spring bean that matches the name of the service provided by the plugin. So if you have a FooService provided by Plugin A you simply defined fooService(MyAlternativeImplementation) in resources.groovy. For your case Mingfai. I have implemented the ability for a plugin author to exclude particular resources from a plugin when installed into an app like: class FooGrailsPlugin { def pluginExcludes = ['grails-app/controllers/DemoController.groovy'] } However I will leave this issue open as it would be nice to add overriding simply by defining a class of the same name as in a plugin, but I'm not sure we'll get this into 1.1
Hide
Permalink
Graeme Rocher added a comment - 10/Feb/09 7:28 AM

Moving non-critical issues that aren't going to make it into 1.1 to 1.2

Show
Graeme Rocher added a comment - 10/Feb/09 7:28 AM Moving non-critical issues that aren't going to make it into 1.1 to 1.2
Hide
Permalink
Lari Hotari added a comment - 28/Apr/09 4:47 PM

I had this same problem while using Searchable plugin. I wanted to override the default SearchableController, but at least in my case the version in my project never got compiled. I think that groovyc doesn't overwrite existing classes and that was the problem. I made a quick fix to the _GrailsCompile.groovy . The "project classes" get compiled in a separate directory and they are moved to the actual classes directory after compiling . This solution makes it possible to override classes from plugins. (My env is Linux + Java 1.6.0_14ea) I'll attach the patch too.

Show
Lari Hotari added a comment - 28/Apr/09 4:47 PM I had this same problem while using Searchable plugin. I wanted to override the default SearchableController, but at least in my case the version in my project never got compiled. I think that groovyc doesn't overwrite existing classes and that was the problem. I made a quick fix to the _GrailsCompile.groovy . The "project classes" get compiled in a separate directory and they are moved to the actual classes directory after compiling . This solution makes it possible to override classes from plugins. (My env is Linux + Java 1.6.0_14ea) I'll attach the patch too.
Hide
Permalink
Lari Hotari added a comment - 28/Apr/09 4:49 PM

Changes to _GrailsCompile.groovy that make it possible to override classes (like Controllers) coming from plugins in the grails application.

Show
Lari Hotari added a comment - 28/Apr/09 4:49 PM Changes to _GrailsCompile.groovy that make it possible to override classes (like Controllers) coming from plugins in the grails application.
Hide
Permalink
Graeme Rocher added a comment - 28/Apr/09 5:02 PM

I'm not sure if this is the right solution, really we should be modifying the GrailsCompiler class to exclude plugin resources that are duplicates of application resources in the compile process. Applying this patch feels a bit hacky.

Show
Graeme Rocher added a comment - 28/Apr/09 5:02 PM I'm not sure if this is the right solution, really we should be modifying the GrailsCompiler class to exclude plugin resources that are duplicates of application resources in the compile process. Applying this patch feels a bit hacky.
Hide
Permalink
Lari Hotari added a comment - 28/Apr/09 5:43 PM

I agree that it's a quick fix that solved my problem. It's a simple solution.

btw. for controllers there isn't any problems in development mode in the original version (application's controller gets used instead of plugin's controller with the same name). The problem hit me after deploying the app as a war file.

Would the correct solution be to modify the compilePlugins target in _GrailsCompile.groovy to exclude any source file found in the application project? (is it getting too complex?)

Show
Lari Hotari added a comment - 28/Apr/09 5:43 PM I agree that it's a quick fix that solved my problem. It's a simple solution. btw. for controllers there isn't any problems in development mode in the original version (application's controller gets used instead of plugin's controller with the same name). The problem hit me after deploying the app as a war file. Would the correct solution be to modify the compilePlugins target in _GrailsCompile.groovy to exclude any source file found in the application project? (is it getting too complex?)
Hide
Permalink
Lari Hotari added a comment - 28/Apr/09 5:53 PM

The original solution didn't work in my env. I just wonder why groovyc doesn't overwrite the class files automaticly since application classes get compiled after plugin classes. Maybe it's normal javac/groovyc behaviour. btw. the original solution has a small problem because it might leave unused inner class files in the target directory.

Show
Lari Hotari added a comment - 28/Apr/09 5:53 PM The original solution didn't work in my env. I just wonder why groovyc doesn't overwrite the class files automaticly since application classes get compiled after plugin classes. Maybe it's normal javac/groovyc behaviour. btw. the original solution has a small problem because it might leave unused inner class files in the target directory.
Hide
Permalink
Donal added a comment - 24/Jul/09 3:34 PM

Hi,

I'd like to override the doWithSpring(), doWithDynamicMethods() etc. methods of a plugin. Judging by the discussion above it seems that I could achieve this by defining a class with the same name as the plugin descriptor and placing it in the conf directory, is that right?

However, it seems like I'll need to wait until version 1.2-M2 before this will work, correct?

Thanks,
Don

Show
Donal added a comment - 24/Jul/09 3:34 PM Hi, I'd like to override the doWithSpring(), doWithDynamicMethods() etc. methods of a plugin. Judging by the discussion above it seems that I could achieve this by defining a class with the same name as the plugin descriptor and placing it in the conf directory, is that right? However, it seems like I'll need to wait until version 1.2-M2 before this will work, correct? Thanks, Don
Hide
Permalink
Daniel Guryca added a comment - 08/Aug/09 5:50 AM

I would appreciate this feature too. Hope it's going to be made into 1.2.
Thanks

Show
Daniel Guryca added a comment - 08/Aug/09 5:50 AM I would appreciate this feature too. Hope it's going to be made into 1.2. Thanks
Hide
Permalink
Graeme Rocher added a comment - 04/Dec/09 4:27 AM

There is no scope / time to resolve these remaining lower priority issues for 1.2 so moving to 1.3

for 1.2 final only issues considered blocking will now be fixed

Show
Graeme Rocher added a comment - 04/Dec/09 4:27 AM There is no scope / time to resolve these remaining lower priority issues for 1.2 so moving to 1.3 for 1.2 final only issues considered blocking will now be fixed
Hide
Permalink
Graeme Rocher added a comment - 24/Mar/10 8:35 AM

Fixed: http://github.com/grails/grails-core/commit/595d80abe7efede56e22de64d30a5c1fc9110638

I used a classloading solution for development instead of relying on copying. Also formalized the separation of a plugin classes directory from the main classes directory.

Show
Graeme Rocher added a comment - 24/Mar/10 8:35 AM Fixed: http://github.com/grails/grails-core/commit/595d80abe7efede56e22de64d30a5c1fc9110638 I used a classloading solution for development instead of relying on copying. Also formalized the separation of a plugin classes directory from the main classes directory.
Hide
Permalink
Kenny Cheang added a comment - 11/Jun/10 4:10 AM

I am running 1.3.1. I tried to override a plugin class located in the 'src/groovy' directory but it didn't work. The original plugin class still got loaded. My question is: can we overwrite the classes in the src folder?

Show
Kenny Cheang added a comment - 11/Jun/10 4:10 AM I am running 1.3.1. I tried to override a plugin class located in the 'src/groovy' directory but it didn't work. The original plugin class still got loaded. My question is: can we overwrite the classes in the src folder?

People

  • Assignee:
    Graeme Rocher
    Reporter:
    Corey
Vote (8)
Watch (9)

Dates

  • Created:
    26/Jan/08 2:05 PM
    Updated:
    11/Jun/10 4:10 AM
    Resolved:
    24/Mar/10 8:35 AM

Agile

  • View on Board
  • Atlassian JIRA (v5.2.1#813-sha1:277a546)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Grails project. Try JIRA - bug tracking software for your team.