JSR-269 integration

classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

JSR-269 integration

Renato Garcia
Hi,

I'm working on a prototype for JSR-269 bridge for Groovy. It is working
fine for groovyc command line but I would like to make it work on
Eclipse Groovy plugin as well.

Basically, I'm trying to generate Java code, compile it and make it
visible to the IDE during an AST transformation.

My first issue is how to control the output dir for the generated
sources. Using the groovyc, in order to specify the output directory for
generated sources, I'm using a joint compilation option ie.:
groovyc -j -J -s generatedDir. Also there is the standard groovyc -d
option to specify where the target output directory. If nothing is
specified it just generates the sources and compiled classes in the
working dir. This is the same behaviour of javac.

Here is the code I use to obtain those values inside the AST transformation:

          println "Joint Options: " +
sourceUnit.configuration.jointCompilationOptions
          println "Target dir: " + sourceUnit.configuration.targetDirectory
          println "Current dir: " + new File(".").toURI()

Now, inside Eclipse this obviously doesn't work because I can't pass the
parameters and I can't access the project configuration from the AST.
The current dir returned is the user home dir, although the file is
created at the home dir, it doesn´t get compiled. This is the second
issue. I'm using the following code to compile the generated class:

           def cu = new CompilationUnit(sourceUnit.getClassLoader())
           cu.setConfiguration( sourceUnit.getConfiguration() )
           cu.addSource(file) // Use the file that was generated previously
           cu.compile()

I was expecting this to compile the generated source file and put the
.class on the project output dir, but it seem to have no effect.

So objectively my questions are:
- What would be the best way to specify and determine the output
directory for the generated sources? I think that maybe a possible
solution, would be to make the existing Eclipse Annotation Processing
configurations (Project properties ->  Java Compiler ->  Annotation
Processing ) somehow available to the groovy eclipse compiler?
- How can I add the generated source file to the compilation process?

Thanks in advance,
Renato


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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: JSR-269 integration

Andrew Eisenberg
We haven't done any work to support JSR 269.  Have you tried using Project properties ->  Java Compiler ->  Annotation Processing?  And what was your experience?

Also, is this a Java 5 style processor or Java 6 (I'm not actually sure if these processors are covered under a different JSR).

My initial thought is that this may just work since it is the JDT compiler that is doing much of the high-level managing of the compilation and it delegates to groovyc only when it needs to process a Groovy file.

Also, can you send over a sample processor and project that you want to work with?  This would help things.
Reply | Threaded
Open this post in threaded view
|

Re: JSR-269 integration

Renato Garcia
Andrew,

Actually I want to have the annotation processors to process my *groovy
classes*, not the java classes, and since this is not supported today, I
wrote an AST transformation and adapters to make this possible. Some of
those adapters will create source files, so my AST transformation need
to know where to place those new generated files and be able to compile
it. Therefore it is not the java compiler that will run the processor,
but the groovy compiler.

As I described in the previous message, I'm not able to determine the
output directory and not able to compile the generated sources when
using groovy eclipse compiler. This is working fine for groovyc so I
would like some help to make it work under groovy eclipse.

Tks!

On 01/12/11 14:21, Andrew Eisenberg wrote:

> We haven't done any work to support JSR 269.  Have you tried using Project
> properties ->   Java Compiler ->   Annotation Processing?  And what was your
> experience?
>
> Also, is this a Java 5 style processor or Java 6 (I'm not actually sure if
> these processors are covered under a different JSR).
>
> My initial thought is that this may just work since it is the JDT compiler
> that is doing much of the high-level managing of the compilation and it
> delegates to groovyc only when it needs to process a Groovy file.
>
> Also, can you send over a sample processor and project that you want to work
> with?  This would help things.
>
> --
> View this message in context: http://groovy-eclipse-plugin.42567.n3.nabble.com/JSR-269-integration-tp3549845p3550538.html
> Sent from the groovy-eclipse-plugin-dev 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
|

Re: JSR-269 integration

Andrew Eisenberg
Do you have a simple processor that we can work with?  And a simple project that uses it?
Reply | Threaded
Open this post in threaded view
|

Re: JSR-269 integration

Renato Garcia
Here are 4 projects.

The first 3 are the complete scenario with the simple processor, the
groovy adapter for JSR-269 and a project that uses both of them.
If you compile "groovy-JSR269-test" using groovyc and pass "-d output -j
-J -s generated" it will create the source files on generated dir and
compile them to output dir.

The 4 project is a very simple project isolating the issue that happens
on the above abstracting from JSR-269.



On 01/12/11 15:36, Andrew Eisenberg wrote:

> Do you have a simple processor that we can work with?  And a simple project
> that uses it?
>
> --
> View this message in context: http://groovy-eclipse-plugin.42567.n3.nabble.com/JSR-269-integration-tp3549845p3550638.html
> Sent from the groovy-eclipse-plugin-dev 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

projects.zip (260K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: JSR-269 integration

Andrew Eisenberg
Thanks for the projects.  I'll see if there is a quick way to get this working.
Reply | Threaded
Open this post in threaded view
|

Re: JSR-269 integration

Andrew Eisenberg
I was able to get this working in Eclipse.  Here are the steps:

1. Your annotation processor must be contained in a separate jar with the correct services/javax.annotation.processing.Processor file in the META-INF folder.  So, simply export your simple-jsr269-processor project to a jar file.
2. The annotation itself does not need to be in this jar file, but the annotation does need to be available to the projects that the processor targets.  For simplicity, you can keep the annotation in the processor jar and then add the processor jar to the target project's classpath.  (But, this is not good separation of concerns, and I would suggest keeping the processor and the annotation in separate jars for releases).
3. In the target project, remove the annotation declaration and all previously generated directories.
4. In the target project go to Properties -> Java Compiler -> Annotation Processors.  Here, you can customize the generated source directory.
5. Now go to Factory path and add the location of your processor jar.

This is how I got things working.  Steps 4&5 can be done per-project or workspace-wide.
Reply | Threaded
Open this post in threaded view
|

Re: JSR-269 integration

Renato Garcia
I've got it working too. Thank you!

I'm bit confused though, it means that groovy-eclipse compiler supports
JSR269 out of the box then? Which is not the case for groovyc?

On 02/12/11 03:25, Andrew Eisenberg wrote:

> I was able to get this working in Eclipse.  Here are the steps:
>
> 1. Your annotation processor must be contained in a separate jar with the
> correct services/javax.annotation.processing.Processor file in the META-INF
> folder.  So, simply export your simple-jsr269-processor project to a jar
> file.
> 2. The annotation itself does not need to be in this jar file, but the
> annotation does need to be available to the projects that the processor
> targets.  For simplicity, you can keep the annotation in the processor jar
> and then add the processor jar to the target project's classpath.  (But,
> this is not good separation of concerns, and I would suggest keeping the
> processor and the annotation in separate jars for releases).
> 3. In the target project, remove the annotation declaration and all
> previously generated directories.
> 4. In the target project go to Properties ->  Java Compiler ->  Annotation
> Processors.  Here, you can customize the generated source directory.
> 5. Now go to Factory path and add the location of your processor jar.
>
> This is how I got things working.  Steps 4&5 can be done per-project or
> workspace-wide.
>
> --
> View this message in context: http://groovy-eclipse-plugin.42567.n3.nabble.com/JSR-269-integration-tp3549845p3552235.html
> Sent from the groovy-eclipse-plugin-dev 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
|

Re: JSR-269 integration

Andrew Eisenberg
On Thu, Dec 1, 2011 at 1:50 PM, Renato Garcia <[hidden email]> wrote:
> I've got it working too. Thank you!
>
> I'm bit confused though, it means that groovy-eclipse compiler supports
> JSR269 out of the box then? Which is not the case for groovyc?

That shouldn't be surprising.  The groovy-eclipse compiler is based
off of the JDT compiler, and we don't deviate much from its behavior,
except to do the actual compilation.

I am not sure what will happen if you try to run in batch mode (ie-
from the command line).

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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: JSR-269 integration

Renato Garcia
OK, I'll give it a go and let you know.

On 02/12/11 07:56, Andrew Eisenberg wrote:

> On Thu, Dec 1, 2011 at 1:50 PM, Renato Garcia<[hidden email]>  wrote:
>> I've got it working too. Thank you!
>>
>> I'm bit confused though, it means that groovy-eclipse compiler supports
>> JSR269 out of the box then? Which is not the case for groovyc?
> That shouldn't be surprising.  The groovy-eclipse compiler is based
> off of the JDT compiler, and we don't deviate much from its behavior,
> except to do the actual compilation.
>
> I am not sure what will happen if you try to run in batch mode (ie-
> from the command line).
>
> ---------------------------------------------------------------------
> 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
|

Re: JSR-269 integration

Renato Garcia
In reply to this post by Andrew Eisenberg
Andrew,

I've tried running in batch mode with several different approaches with
no success. Except with the not patched JDT.

Maven:

Used maven-compiler-plugin with groovy-eclipse-compiler, versions
2.5.2-01 and 2.6.0-01-SNAPSHOT. It doesn't find the processors but
compiles the files. I've tried defining the processor options explicitly
but I could not manage to pass the processorpath option.

I tried using
<compilerArguments>
<processorpath>/home/rgarcia/p.jar</processorpath>
</compilerArguments>
but it  seem to ignore the value on the [DEBUG] Command line options:
showing just the -processopath

and <compilerArgument>-processor /home/rgarcia/p.jar</compilerArgument>

shows the correct output but it falis with:
Unrecognized option : -processorpath /home/rgarcia/p.jar

Cmd line:

I followed the instructions from your blog and used the
GroovyEclipseBatch.zip, but it doesn't call the processors also. Tried
defining the processors options explicitly but no success as well. It
accepts the -processorpath option though.

JDT:

I've tried JDT compiler batch with the ecj-3.7.1.jar and it works even
using the default discovery mechanism, so just placing the jar with the
processor and manifest works, passing the processor options explicitly
also works.


On 02/12/11 07:56, Andrew Eisenberg wrote:

> On Thu, Dec 1, 2011 at 1:50 PM, Renato Garcia<[hidden email]>  wrote:
>> I've got it working too. Thank you!
>>
>> I'm bit confused though, it means that groovy-eclipse compiler supports
>> JSR269 out of the box then? Which is not the case for groovyc?
> That shouldn't be surprising.  The groovy-eclipse compiler is based
> off of the JDT compiler, and we don't deviate much from its behavior,
> except to do the actual compilation.
>
> I am not sure what will happen if you try to run in batch mode (ie-
> from the command line).
>
> ---------------------------------------------------------------------
> 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
|

Re: JSR-269 integration

Andrew Eisenberg
I realize now that we don't even package the apt tools with the
groovy-eclipse-batch artifact, so there isn't any chance that it would
work.  I'm guessing that the ecj artifact somehow has a dependency on
(or includes) the annotation processing.

On Thu, Dec 1, 2011 at 8:36 PM, Renato Garcia [via
groovy-eclipse-plugin] <[hidden email]>
wrote:

> Andrew,
>
> I've tried running in batch mode with several different approaches with
> no success. Except with the not patched JDT.
>
> Maven:
>
> Used maven-compiler-plugin with groovy-eclipse-compiler, versions
> 2.5.2-01 and 2.6.0-01-SNAPSHOT. It doesn't find the processors but
> compiles the files. I've tried defining the processor options explicitly
> but I could not manage to pass the processorpath option.
>
> I tried using
> <compilerArguments>
> <processorpath>/home/rgarcia/p.jar</processorpath>
> </compilerArguments>
> but it  seem to ignore the value on the [DEBUG] Command line options:
> showing just the -processopath
>
> and <compilerArgument>-processor /home/rgarcia/p.jar</compilerArgument>
>
> shows the correct output but it falis with:
> Unrecognized option : -processorpath /home/rgarcia/p.jar
>
> Cmd line:
>
> I followed the instructions from your blog and used the
> GroovyEclipseBatch.zip, but it doesn't call the processors also. Tried
> defining the processors options explicitly but no success as well. It
> accepts the -processorpath option though.
>
> JDT:
>
> I've tried JDT compiler batch with the ecj-3.7.1.jar and it works even
> using the default discovery mechanism, so just placing the jar with the
> processor and manifest works, passing the processor options explicitly
> also works.
>
>
> On 02/12/11 07:56, Andrew Eisenberg wrote:
>
>> On Thu, Dec 1, 2011 at 1:50 PM, Renato Garcia<[hidden email]>  wrote:
>>> I've got it working too. Thank you!
>>>
>>> I'm bit confused though, it means that groovy-eclipse compiler supports
>>> JSR269 out of the box then? Which is not the case for groovyc?
>> That shouldn't be surprising.  The groovy-eclipse compiler is based
>> off of the JDT compiler, and we don't deviate much from its behavior,
>> except to do the actual compilation.
>>
>> I am not sure what will happen if you try to run in batch mode (ie-
>> from the command line).
>>
>> ---------------------------------------------------------------------
>> 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
>
>
>
>
> ________________________________
> If you reply to this email, your message will be added to the discussion
> below:
> http://groovy-eclipse-plugin.42567.n3.nabble.com/JSR-269-integration-tp3549845p3553787.html
> To unsubscribe from JSR-269 integration, click here.
> NAML
Reply | Threaded
Open this post in threaded view
|

Re: JSR-269 integration

Andrew Eisenberg
In reply to this post by Renato Garcia
You can raise a jira issue for this and I can have a look at this.

On Thu, Dec 1, 2011 at 8:55 PM, Andrew Eisenberg <[hidden email]> wrote:

> I realize now that we don't even package the apt tools with the
> groovy-eclipse-batch artifact, so there isn't any chance that it would
> work.  I'm guessing that the ecj artifact somehow has a dependency on
> (or includes) the annotation processing.
>
> On Thu, Dec 1, 2011 at 8:36 PM, Renato Garcia [via
> groovy-eclipse-plugin] <[hidden email]>
> wrote:
>> Andrew,
>>
>> I've tried running in batch mode with several different approaches with
>> no success. Except with the not patched JDT.
>>
>> Maven:
>>
>> Used maven-compiler-plugin with groovy-eclipse-compiler, versions
>> 2.5.2-01 and 2.6.0-01-SNAPSHOT. It doesn't find the processors but
>> compiles the files. I've tried defining the processor options explicitly
>> but I could not manage to pass the processorpath option.
>>
>> I tried using
>> <compilerArguments>
>> <processorpath>/home/rgarcia/p.jar</processorpath>
>> </compilerArguments>
>> but it  seem to ignore the value on the [DEBUG] Command line options:
>> showing just the -processopath
>>
>> and <compilerArgument>-processor /home/rgarcia/p.jar</compilerArgument>
>>
>> shows the correct output but it falis with:
>> Unrecognized option : -processorpath /home/rgarcia/p.jar
>>
>> Cmd line:
>>
>> I followed the instructions from your blog and used the
>> GroovyEclipseBatch.zip, but it doesn't call the processors also. Tried
>> defining the processors options explicitly but no success as well. It
>> accepts the -processorpath option though.
>>
>> JDT:
>>
>> I've tried JDT compiler batch with the ecj-3.7.1.jar and it works even
>> using the default discovery mechanism, so just placing the jar with the
>> processor and manifest works, passing the processor options explicitly
>> also works.
>>
>>
>> On 02/12/11 07:56, Andrew Eisenberg wrote:
>>
>>> On Thu, Dec 1, 2011 at 1:50 PM, Renato Garcia<[hidden email]>  wrote:
>>>> I've got it working too. Thank you!
>>>>
>>>> I'm bit confused though, it means that groovy-eclipse compiler supports
>>>> JSR269 out of the box then? Which is not the case for groovyc?
>>> That shouldn't be surprising.  The groovy-eclipse compiler is based
>>> off of the JDT compiler, and we don't deviate much from its behavior,
>>> except to do the actual compilation.
>>>
>>> I am not sure what will happen if you try to run in batch mode (ie-
>>> from the command line).
>>>
>>> ---------------------------------------------------------------------
>>> 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
>>
>>
>>
>>
>> ________________________________
>> If you reply to this email, your message will be added to the discussion
>> below:
>> http://groovy-eclipse-plugin.42567.n3.nabble.com/JSR-269-integration-tp3549845p3553787.html
>> To unsubscribe from JSR-269 integration, click here.
>> NAML
Reply | Threaded
Open this post in threaded view
|

Re: JSR-269 integration

Renato Garcia
Done -> http://jira.codehaus.org/browse/GRECLIPSE-1269

Thank you

On 02/12/11 14:55, Andrew Eisenberg wrote:
You can raise a jira issue for this and I can have a look at this.

On Thu, Dec 1, 2011 at 8:55 PM, Andrew Eisenberg <[hidden email]> wrote:

> I realize now that we don't even package the apt tools with the
> groovy-eclipse-batch artifact, so there isn't any chance that it would
> work.  I'm guessing that the ecj artifact somehow has a dependency on
> (or includes) the annotation processing.
>
> On Thu, Dec 1, 2011 at 8:36 PM, Renato Garcia [via
> groovy-eclipse-plugin] <[hidden email]>
> wrote:
>> Andrew,
>>
>> I've tried running in batch mode with several different approaches with
>> no success. Except with the not patched JDT.
>>
>> Maven:
>>
>> Used maven-compiler-plugin with groovy-eclipse-compiler, versions
>> 2.5.2-01 and 2.6.0-01-SNAPSHOT. It doesn't find the processors but
>> compiles the files. I've tried defining the processor options explicitly
>> but I could not manage to pass the processorpath option.
>>
>> I tried using
>> <compilerArguments>
>> <processorpath>/home/rgarcia/p.jar</processorpath>
>> </compilerArguments>
>> but it  seem to ignore the value on the [DEBUG] Command line options:
>> showing just the -processopath
>>
>> and <compilerArgument>-processor /home/rgarcia/p.jar</compilerArgument>
>>
>> shows the correct output but it falis with:
>> Unrecognized option : -processorpath /home/rgarcia/p.jar
>>
>> Cmd line:
>>
>> I followed the instructions from your blog and used the
>> GroovyEclipseBatch.zip, but it doesn't call the processors also. Tried
>> defining the processors options explicitly but no success as well. It
>> accepts the -processorpath option though.
>>
>> JDT:
>>
>> I've tried JDT compiler batch with the ecj-3.7.1.jar and it works even
>> using the default discovery mechanism, so just placing the jar with the
>> processor and manifest works, passing the processor options explicitly
>> also works.
>>
>>
>> On 02/12/11 07:56, Andrew Eisenberg wrote:
>>
>>> On Thu, Dec 1, 2011 at 1:50 PM, Renato Garcia<[hidden email]>  wrote:
>>>> I've got it working too. Thank you!
>>>>
>>>> I'm bit confused though, it means that groovy-eclipse compiler supports
>>>> JSR269 out of the box then? Which is not the case for groovyc?
>>> That shouldn't be surprising.  The groovy-eclipse compiler is based
>>> off of the JDT compiler, and we don't deviate much from its behavior,
>>> except to do the actual compilation.
>>>
>>> I am not sure what will happen if you try to run in batch mode (ie-
>>> from the command line).
>>>
>>> ---------------------------------------------------------------------
>>> 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
>>
>>
>>
>>
>> ________________________________
>> If you reply to this email, your message will be added to the discussion
>> below:
>> http://groovy-eclipse-plugin.42567.n3.nabble.com/JSR-269-integration-tp3549845p3553787.html
>> To unsubscribe from JSR-269 integration, click here.
>> NAML


View this message in context: Re: JSR-269 integration
Sent from the groovy-eclipse-plugin-dev mailing list archive at Nabble.com.