Custom Annotation Processor with Netbeans Module - java

I'm doing work with a (non Maven, I believe) Netbeans module, which is being used as a Plugin for a program built on top of the Netbeans platform.
What I wanted to do was use custom annotations to add a sort of documentation of how to use the GUI elements (of the plugin I'm working on), when a user goes to the help menu and selects "how to use".
My thought was create a custom annotation, where a user supplies name, and help information for a class. Then the annotation processor goes through the annotations, and outputs a class with the annotation information stored in a class field. This class can then be extended from, and used to display the information in a useful way.
Following this example https://netbeans.org/kb/docs/java/annotations-custom.html
I'm using Java 7, but both the Module and the Annotation Processor Jar are compiled as Java 6. My Netbeans Version is 7.3.1, however I believe the module is being developed for Netbeans Platform 7.0.1.
I have the annotation, and annotation processor compiled into a Jar, which if I use with a regular java project, it works as expected.
However, I cannot get the processor to run during compiling with the Netbeans module project.
I tried adding the Annotation Processor class to the META-INF.services, javax.annotation.processing.Processor file, in the netbeans module.
I tried adding the Annotation Processor class to the META-INF.services, javax.annotation.processing.Processor file, in the Annotation Processor project. (This made it work with my test Project)
I tried adding the -processor compiler flag to the netbeans module project to use the specific annotation processor.

After removing the extends relationship between my class and the expected auto generated class, output from the annotation processor, the code compiled. But at that point I noticed that the annotation processor was in fact being run.
I added the extends relationship back in, and cleaned and compiled again, and it failed to compile but the annotation processor was run, and successfully generated the output file as hoped. I hit build, without cleaning, and it built a final time, and worked as expected.
I don't know what is causing this, it appears to be, at least for a Netbeans module project, that the build order is different than a regular Java Project. Or perhaps there are several intermediate build steps which don't always get cleaned up.

Related

Java annotation not usable from Kotlin project jar

I am working on library that I am transferring from Java to Kotlin. Since the projects is still mixed with both languages, I use kotlin-maven-plugin and maven-compiler-plugin as described in https://kotlinlang.org/docs/reference/using-maven.html . Kotlin version is 1.2.10.
I need to create an annotation in the library, that is going to be used in other projects. The annotation is a standard Java one, and I am able to build my library.
#Target(ElementType.TYPE)
#Retention(RetentionPolicy.RUNTIME)
#Documented
public #interface EnableSomeBehavior {
}
When I import the library in another project (a Java project), I can see the annotation. The auto-completion in my IDE (IntelliJ) actually proposes me annotation.. but for some reason, is not able to import it : when I validate the auto-completion choice, then I am getting a compilation error "cannot resolve symbol 'EnableSomeBehavior' ".
This is quite puzzling.. I've rebuilt several times (in case the jar was corrupted), but it didn't change anything.
I suspect it's something that has to do with the way the Kotlin/Java library is compiled and/or packaged.. The Java annotation is there in the jar, I can see it, and to some extent, the IDE can also see it, since it's proposing it. But somehow, it's not able to use it. It's not an IDE issue, because even compile with Maven from command line fails with the same error.
Any idea of what the problem could be ?
Thanks
Initially, I found that it was working better if the annotation was a Kotlin one instead of a Java one :
#Target(AnnotationTarget.CLASS, AnnotationTarget.FILE)
#Retention(RetentionPolicy.RUNTIME)
#Documented
annotation class EnableSomeBehavior
After rebuilding my library, IntelliJ wouldn't show any error in the project using the annotation. However, compilation would still fail !
I ended up finding that it's not a Kotlin issue at all but a Spring Boot packaging issue : Using Kotlin classes from jar built with kotlin-maven-plugin

Launching an Eclipse 3.x RCP Application using bndtools

I have spent the past few days trying to find a solution to my problem. I am trying to launch an Eclipse RCP using the 3.x compatibility layer using the bndtools launcher via a bndrun file.
I am aware of the solution which involves placing bndtools.runtime.eclipse.applauncher in the list of run bundles in order to get an E4 application to start and that there are ways to migrate an E3.x application to E4. We would like to maintain programmatic control over the Rich Client Platform for the time being so migrating to an XMI file for laying out the Workbench is not ideal at this time.
I created a plug-in project which builds using bndtools. To my knowledge I have included all of the necessary bundles to run the application and have followed several examples (as an aside, most of the OSGI examples I found were console-based).
Because I wasn't seeing the RCP load up (we have an RCP plug-in which extends the IApplication interface and our project structure is still Activator based) I was initially at a loss as to why this wasn't working but adding -osgi-console= to the run properties did provide some additional information:
Using -runfw: org.eclipse.osgi
The final lines are the following:
# framework=org.eclipse.osgi.launch.Equinox#59fa1d9b
# registered launcher with arguments for syncing
# will wait for a registered Runnable
Additionally, the plug-in I am using to test with is marked as STRTD and the bundle that is using it is also marked as STRTD whereas most other bundles are marked as ACTIV, which I assume is also part of the problem. I have tried to force bundles to start by including a line to start several bundles (following other examples) but have run into issues where the console will error stating could not load or find main class for org.eclipse.core.runtime when trying to include that in the list of activated bundles.
Googling (and even Binging) have not appeared to produce a solution which explains how to set up an Eclipse 3.x application to run using a bndrun file. What am I missing? Most recently I tried the following properties:
-runproperties: \
osgi.os=win32,\
osgi.clean=true,\
osgi.console=,\
eclipse.product=org.eclipse.sdk.ide,\
osgi.arch=x86_64,\
osgi.ws=win32,\
equinox.use.ds=true,\
eclipse.application=org.eclipse.ui.ide.workbench
I assume that if the actual test bundle I am using would actually activate that I should also be able to find the application ID set in the plugin.xml file and to use that instead. Trying to activate that plug-in also results in a could not find main class error even though I specify a Bundle-Activator in the bnd file. That Activator does not appear to be started since I have it set to print to the console and nothing is printed. I assume that since the bundle is in the STRTD state that it did not start.
Any help with this would be appreciated.
Edit:
As an update, adding org.apache.felix.gogo.runtime and org.apache.felix.gogo.shell did result in my test plug-in's activator getting started. Curiously the plug-in it is dependent on, though, moved from STRTD to RSLVD.
Other discussion has indicated that we might have to manually start an Eclipse instance using EclipseStarter?
The following Github repo contains using an example with bndtools and Eclipse 3.8. It uses an adapted bndtools.runtime.eclipse.applauncher inside /cnf/eclipse_common_3.8/bndtools.runtime.eclipse.applaunch-0‌​.1.0.jar see the 3.8 bnd launch config also include here example.aspectj/example.aspectj.bnd.app/run/launch_org.eclip‌​se.osgi_3.8.x.bndrun‌​. This was (beside the Aspect stuff demoed in the repo) the smallest set of bundles to startup an Eclipse app successfully with bnd.

Frege can't find classes in referenced project or external jar

I think I'm making a simple mistake here, but I can't get Frege to find any classes outside of the local Eclipse project.
I have a working non-trivial Java project (that's not mine), that I do not want to modify. I want to have a new clean Frege enabled project that makes use of classes from the original project.
I tried marking the original project as a dependency of my Frege project, and I tried packaging the original project into a JAR, and listing the JAR as an external dependency of the Frege project. In both cases, a Java file in the Frege project can access the classes, but the Frege compiler says "class org.foo.bar.Class is not a known Java class". This seems like a bug, but I am not confident that I have not missed a simple configuration step.
I have not tried setting arguments in the project configuration as I wouldn't know what to set.
I did quickly discover that I can make a new Java file in the Frege project with a blank subclass of whatever class I need and use that in a Frege file. I have successfully compiled and run a simple program like this. The program just makes a new object, gets a field, and prints the correct value, so I believe my Frege is installed and working properly.
More info:
Eclipse Luna 4.4.0
Java 7
No Maven
Official eclipse-ferge plugin installed through Eclipse
It should be enough to have your library listed in the build path and under "Referenced Libraries". Your recent comment indicates that the compiler does indeed find the class in question.
However, when you have an open editor tab it will not take notice of changed dependencies. Also, especially in recent eclipse versions I have observed that resolved error markers are sometimes not cleaned up correctly.
Please close the editor tab that has the false errors shown, and reopen it.

Intellij: Excluded java class getting considered in make/compilation

As per https://www.jetbrains.com/idea/help/compiler-excludes.html, I excluded one of the java class which was used only for some scripting purposes. While I am running some Junit whose configuration has a before launch task "Make", it is trying to make the project and showing errors in this excluded java class. How is it possible? Is it a bug in my intellij idea ultimate mac version 14.1.4 build 1532? Or am I missing something here?
Strangely, I excluded two classes and this problem is coming in only one of them, i.e. the second excluded file is indeed being excluded and not showing compilation failure during MAKE.

Error compiling Java/Scala mixed project and Lombok

I am trying to compile a Maven Java/Scala mixed project that has a Scala class that depends on a Java bean with lombok annotations. I tried adding the lombok jar file to the boot classpath of the Scala compiler as well as the lombok agent, but the compiler still failed to find the generated getters. Is there a way for the Scala compiler to recognize the lombok annotations? If not, what would be a good workaround?
Pease note that I am trying to avoid introducing another maven project just for compiling this bean first as the bean logically belongs to the same project. Also I cannot rewrite the bean in Scala as it is later used in a GWT project.
Thank you,
I think you'll not be able to avoid it. Normal Scala/Java integration works like this:
Scala goes first, since Java doesn't know anything about Scala.
Scalac parsers Java files and learns about visible elements.
Scalac reads Scala files and generate class files.
Java goes last, and reads Java files plus the class files generated by Scala.
The obvious problem is that Scala doesn't know anything about Lombok annotations, so it can't figure out the elements generated by it.
If you don't have any dependency from Java to Scala, you can simply invert the order: let Java go first, and have Scala include the output classfiles of javac on its classpath.
Otherwise, I suppose you'll need to break it up.

Categories