You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@groovy.apache.org by "gary_gandy@trendmicro.com" <ga...@trendmicro.com> on 2018/11/01 15:45:58 UTC

Groovy and the OSGI R6 Annotations

Hello,

I've been creating an OSGI bundle using Groovy, and I've run into the following issue using one of the OSGI R6 metadata annotations. When creating a configuration for an OSGI service, you define a custom annotation in Java as the following:

- - - - - JSONServiceConfig.java - - - - -
package com.company.core.service

import org.osgi.service.metatype.annotations.AttributeDefinition;
import org.osgi.service.metatype.annotations.ObjectClassDefinition;

@ObjectClassDefinition(
                        name = "JSONService configuration",
                        description = "This configures the outgoing proxy setup options for the JSONService"
)
public @interface JSONServiceConfig {
            @AttributeDefinition(  name="Proxy Address", description = "IP address for the proxy" )
            String proxyAddress();

            @AttributeDefinition( name="Proxy Port", description = "Port number of the proxy" )
            int proxyPort();
}
- - - - -

The equivalent code in Groovy is hardly changed at all:

- - - - - JSONServiceConfig.groovy - - - - -
package com.company.core.service

import org.osgi.service.metatype.annotations.AttributeDefinition
import org.osgi.service.metatype.annotations.ObjectClassDefinition

@ObjectClassDefinition(
                        name = "JSONService configuration",
                        description = "This configures the outgoing proxy setup options for the JSONService"
)
public @interface JSONServiceConfig {
            @AttributeDefinition(  name="Proxy Address", description = "IP address for the proxy" )
            String proxyAddress()

            @AttributeDefinition( name="Proxy Port", description = "Port number of the proxy" )
            int proxyPort()
}
- - - - -

However, when compiling the Groovy code, the compiler stops at the following error:

JSONServiceConfig.groovy: 6: Annotation @org.osgi.service.metatype.annotations.ObjectClassDefinition is not allowed on element ANNOTATION
@ line 6, column 1.
   @ObjectClassDefinition(
   ^

1 error

Is there some reason that the previous code will compile in Java but not in Groovy, and are there any alterations to be made on the Groovy code to allow compilation?

Regards,
Gary

<table class="TM_EMAIL_NOTICE"><tr><td><pre>
TREND MICRO EMAIL NOTICE
The information contained in this email and any attachments is confidential 
and may be subject to copyright or other intellectual property protection. 
If you are not the intended recipient, you are not authorized to use or 
disclose this information, and we request that you notify us by reply mail or
telephone and delete the original message from your mail system.
</pre></td></tr></table>