DSLD: Cannot get any pointcut to match

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

DSLD: Cannot get any pointcut to match

Peter Niederwieser
Administrator
I'm trying to write a little DSLD for Spock. Groovy event console says that my pointcuts are being registered (every time I modify/save the script), but no matter what I try, pointcuts never seem to match. For example:

contribute(enclosingClass(subType("spock.lang.Specification"))) {
  log("XXXXXXXXXXXXXXXXXXXXXXXXX")
}

I never see this log output in the Groovy event console while clicking around or requesting content assist inside a spec class. Throwing an exception instead of logging doesn't do anything either. An exception thrown from the top level of the DSLD script is shown in the error log.

I've also tried other stuff like "contribute(enclosingClass(annotatedBy(Singleton)))", but the problem remains the same.

Any ideas? I'm using Groovy Eclipse 2.7.0/Groovy 1.8.6 on Eclipse 3.7.2.

Cheers,
Peter
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: DSLD: Cannot get any pointcut to match

Andrew Eisenberg
Make sure that your project is compiling cleanly (shouldn't really
matter, but you never know), and there are no exceptions in your event
console or the error log.

I did this.  Hovering over foo and foo2 showed what I expected.

spk.dsld
contribute(enclosingClass(annotatedBy(Singleton))) {
        property name:'foo', doc:"Yo!"
}

contribute(enclosingClass(subType("spock.lang.Specification"))) {
        property name:'foo2', doc:"Yo!"
}

Other.groovy
import spock.lang.Specification;
@Singleton
class Other extends Specification{
        def f() {
                foo
                foo2
        }
}

spock/lang/Specification.groovy
package spock.lang
class Specification { }

The groovy event console is honestly a bit cluttered.  I use it more
to make sure that exceptions aren't thrown.  If I'm checking to see if
a pointcut is specified properly, then I add dummy variables like
above.

If this doesn't help you at all, then I can zip up the project for you.

Interestingly, I found a bug that if I named the script 'spock.dsld'
and put it in the default package, there is a compile error on the
import statement.  So, make sure that your script is not named
spock.dsld or it's not in the default package.

---------------------------------------------------------------------
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

Re: DSLD: Cannot get any pointcut to match

Peter Niederwieser
Administrator
Found the problem. spock.dsld is in spock-core, and I was trying with a spec in spock-specs (since spock-core doesn't have any). However, according to DSLD preferences, spock.dsld is only active for spock-core, but not for spock-specs. Also I don't see a way to manually add spock.dsld to spock-specs' DSLDs. Is auto-detection of DSLD's in project dependencies something that could be added, similar to how they are detected in external dependencies?

Cheers,
Peter
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: DSLD: Cannot get any pointcut to match

Andrew Eisenberg
If your dsld is added to the dsld package and pushed to the output
folder as a .dsld file (ie- not compiled) this should work.

So, go to Preferences -> Groovy -> Compiler and enable script folder
support (you can also do this on a project by project basis if you go
to Project -> propertties).  Add a new entry, something like **/*.dsld
and make sure the entry is checked.  Then check the output folder of
your project to make sure that the dsld is being properly copied over.

Then the dsld will be picked up by other projects that depend on the
project it is coming from.

On Thu, Jul 5, 2012 at 6:53 AM, Peter Niederwieser <[hidden email]> wrote:

> Found the problem. spock.dsld is in spock-core, and I was trying with a spec
> in spock-specs (since spock-core doesn't have any). However, according to
> DSLD preferences, spock.dsld is only active for spock-core, but not for
> spock-specs. Also I don't see a way to manually add spock.dsld to
> spock-specs' DSLDs. Is auto-detection of DSLD's in project dependencies
> something that could be added, similar to how they are detected in external
> dependencies?
>
> Cheers,
> Peter
>
> --
> View this message in context: http://groovy-eclipse-plugin.42567.n3.nabble.com/DSLD-Cannot-get-any-pointcut-to-match-tp4024991p4024996.html
> Sent from the groovy-eclipse-plugin-user mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>

---------------------------------------------------------------------
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

Re: DSLD: Cannot get any pointcut to match

Peter Niederwieser
Administrator
File ends up in spock-core/bin/dsld/spk.dsld as expected, but other projects don't pick it up. DSLD list refresh, rebuild, and restart don't help. Should I create an issue?

Cheers,
Peter
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: DSLD: Cannot get any pointcut to match

Andrew Eisenberg
Sure.  Raise an issue.

And just to be sure...spock-core is exporting the bin folder and the
other projects have spock-core on the classpath?  Is there a package
declaration in spk.dsld?

On Thu, Jul 5, 2012 at 2:35 PM, Peter Niederwieser <[hidden email]> wrote:

> File ends up in spock-core/bin/dsld/spk.dsld as expected, but other projects
> don't pick it up. DSLD list refresh, rebuild, and restart don't help. Should
> I create an issue?
>
> Cheers,
> Peter
>
> --
> View this message in context: http://groovy-eclipse-plugin.42567.n3.nabble.com/DSLD-Cannot-get-any-pointcut-to-match-tp4024991p4024998.html
> Sent from the groovy-eclipse-plugin-user mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>

---------------------------------------------------------------------
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

Re: DSLD: Cannot get any pointcut to match

Peter Niederwieser
Administrator
Definite "yes" to everything but "spock-core is exporting the bin folder". How would I do that? Java Build Path/Order And Export has everything selected, but "bin" doesn't show up there, and it's not possible to add something. "bin" *is* configured as the output folder for spock-core. And other projects see all spock-core classes.

Cheers,
Peter
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: DSLD: Cannot get any pointcut to match

Andrew Eisenberg
Well, I thought this was working, but looks like I never wrote a test
for this.  Urrgh...this is not the setup that I have used before.
Most of the time I consume dslds defined in jar files or external
folders.

As a work around for now, you can add a linked folder to your
dependent projects.  Once you produce your final jars, this shouldn't
be necessary.

To do this select the dependent project and go to File -> new ->
Folder -> Advanced.  Choose the src folder that contains your dsld.
Rename to something else.  Now make sure that the dsld is being used.

I'll figure out what's going on tomorrow.

On Thu, Jul 5, 2012 at 3:42 PM, Peter Niederwieser <[hidden email]> wrote:

> Definite "yes" to everything but "spock-core is exporting the bin folder".
> How would I do that? Java Build Path/Order And Export has everything
> selected, but "bin" doesn't show up there, and it's not possible to add
> something. "bin" *is* configured as the output folder for spock-core. And
> other projects see all spock-core classes.
>
> Cheers,
> Peter
>
> --
> View this message in context: http://groovy-eclipse-plugin.42567.n3.nabble.com/DSLD-Cannot-get-any-pointcut-to-match-tp4024991p4025000.html
> Sent from the groovy-eclipse-plugin-user mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>

---------------------------------------------------------------------
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

Re: DSLD: Cannot get any pointcut to match

Peter Niederwieser
Administrator
Andrew Eisenberg wrote
To do this select the dependent project and go to File -> new ->
Folder -> Advanced.  Choose the src folder that contains your dsld.
Rename to something else.  Now make sure that the dsld is being used.
I couldn't get this to work (again DSLD wasn't detected), but testing with a spec in spock-core/src/test/groovy works well enough for the moment.

Cheers,
Peter
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: DSLD: Cannot get any pointcut to match

Andrew Eisenberg
I think I have a fix for this problem.  I need to do a bit more
testing, but I should be able to commit tomorrow.

On Thu, Jul 5, 2012 at 9:00 PM, Peter Niederwieser <[hidden email]> wrote:

>
> Andrew Eisenberg wrote
>>
>> To do this select the dependent project and go to File -> new ->
>> Folder -> Advanced.  Choose the src folder that contains your dsld.
>> Rename to something else.  Now make sure that the dsld is being used.
>>
>
> I couldn't get this to work (again DSLD wasn't detected), but testing with a
> spec in spock-core/src/test/groovy works well enough for the moment.
>
> Cheers,
> Peter
>
>
> --
> View this message in context: http://groovy-eclipse-plugin.42567.n3.nabble.com/DSLD-Cannot-get-any-pointcut-to-match-tp4024991p4025005.html
> Sent from the groovy-eclipse-plugin-user mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>

---------------------------------------------------------------------
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

Re: DSLD: Cannot get any pointcut to match

Andrew Eisenberg
In reply to this post by Peter Niederwieser
Here's what I got:

contribute(currentType()) {
        method name: 'Mock', declaringType:'MockingApi'
}

contribute(enclosingClass(subType("Specification")) &
        enclosingCallDeclaringType('MockingApi') &
        enclosingCall(name("Mock") &
        hasArgument(delegateTypes: type(subType()))) & enclosingClosure()) {

        delegatesTo delegateTypes.first()
}


There are a few things to note:

1. I removed all package names in my simple example. You will need to
add them back.
2. Whenever you use a variable, it always returns a collection (since
it may match more than one argument).  So, I changed your variable to
delegateTypes and am accessing it like a collection
3. The type of the expression 'List' is 'java.util.List'.  your old
pointcut was matching against Class.  This is not right.  The type of
the expression 'List.class' is java.lang.Class.  I know this is not
exactly how things work at runtime, but doing things this way make so
many other things more intuitive and just work that it is worth
deviating from the runtime semantics.
4. You'll notice that I use type(subType()) instead of type().  This
is a bug and I have fixed this, but you will need a snapshot of 2.7.1
to use it (so stick to what I have above for now).
5. You'll also notice that I use enclosingCallDeclaringType instead of
declaringType inside of enclosingCall.  Another bug, but less easy to
fix. I raised https://jira.codehaus.org/browse/GRECLIPSE-1460

This is working for me now.  Let me know if you get it working.  I can
help you with any other parts that you need since writing dslds can be
less than intuitive sometimes.

On Thu, Jul 5, 2012 at 9:00 PM, Peter Niederwieser <[hidden email]> wrote:

>
> Andrew Eisenberg wrote
>>
>> To do this select the dependent project and go to File -> new ->
>> Folder -> Advanced.  Choose the src folder that contains your dsld.
>> Rename to something else.  Now make sure that the dsld is being used.
>>
>
> I couldn't get this to work (again DSLD wasn't detected), but testing with a
> spec in spock-core/src/test/groovy works well enough for the moment.
>
> Cheers,
> Peter
>
>
> --
> View this message in context: http://groovy-eclipse-plugin.42567.n3.nabble.com/DSLD-Cannot-get-any-pointcut-to-match-tp4024991p4025005.html
> Sent from the groovy-eclipse-plugin-user mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>

---------------------------------------------------------------------
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

Re: DSLD: Cannot get any pointcut to match

Peter Niederwieser
Administrator
Thanks a lot, Andrew. Your version works fine. I was already wondering whether there is a difference between enclosingCall(declaringType()) and enclosingCallDeclaringType().

In my particular case, since Spock is already heavily based on AST manipulation, it would be very attractive to write my own pointcuts. Right now I'm after this:

List list = Mock { /* delegates to java.util.List */ }

Which leads me to the question: Is it possible to write a custom pointcut that allows me to bind to the type of the variable and contribute that type as the delegate type of the closure? Or more generally, is it possible to write an "enclosing" style custom pointcut?

Cheers,
Peter
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: DSLD: Cannot get any pointcut to match

Andrew Eisenberg
There might be some way to do this.  There is a way to define custom
pointcuts, but it is a little clunky.  I'll have to think about this a
bit.

On Fri, Jul 6, 2012 at 4:00 PM, Peter Niederwieser <[hidden email]> wrote:

> Thanks a lot, Andrew. Your version works fine. I was already wondering
> whether there is a difference between enclosingCall(declaringType()) and
> enclosingCallDeclaringType().
>
> In my particular case, since Spock is already heavily based on AST
> manipulation, it would be very attractive to write my own pointcuts. Right
> now I'm after this:
>
> List list = Mock { /* delegates to java.util.List */ }
>
> Which leads me to the question: Is it possible to write a custom pointcut
> that allows me to bind to the type of the variable and contribute that type
> as the delegate type of the closure? Or more generally, is it possible to
> write an "enclosing" style custom pointcut?
>
> Cheers,
> Peter
>
> --
> View this message in context: http://groovy-eclipse-plugin.42567.n3.nabble.com/DSLD-Cannot-get-any-pointcut-to-match-tp4024991p4025012.html
> Sent from the groovy-eclipse-plugin-user mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>

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

    http://xircles.codehaus.org/manage_email


Loading...