How make Eclipse instrument classes at build time? - eclipse-plugin

Sometimes I have to perform some custom bytecode transformation.
I have used mainly asm and javaassit.
Inside eclipse usually I run my code with the -javaagent jvm parameter. Outside eclipse I use maven, ant, or the command prompt to invoke the weavers before running the application code.
But the point is that: I would like to perform instrumentation at build time inside eclipse.
What is the best way to do it?
Is there an already made plugin that I can connect to by implementing some api?
May I script this with eclipse monkey?
May I use an ant builder and invoke my weaver with it?
Should I look at the AspectJ plugin (must be huge) and try to figure out how to make my own plugin?
Should I look at the some other plugin to get inspiration?
Thanks.

You can create an annotation processor. This way you will be able to use it with ant, maven and any IDE (not only Eclipse).
Here is an example:
http://java.dzone.com/news/using-java-6-processors

Related

intellij hybris class recompile not working

I installed hybris plugin.
Imported project with it.
Have done ant clean all.
Then, if I try to build->recompile class it's not working. Seems like idea doesn't see classes generated by ant.
If I do build->rebuild project and then build->recompile class it's working fine, but it's not convenient at all. I believe there is fix to this, but I couldn't find it.
This is usual error I've got(packages are different for different cases):
this is essentially the expected behaviour. You can't mix "ant" build
and "native IDEA" build. Those are two separate build systems.
This is an explanation of hybris plugin developer (hybris-integration.atlassian.net/browse/IIPS-120)
And he suggests a solution for that:
before you try to import the project you need to do ant clean all (you will not need to use ant afterwards)
import the project using hybris plugin.
Press Build->Recompile project
Then you can create or modify your test run configuration if needed.
Recompile your classes and so on directly in Idea.
Also, he mentioned deal with JRebel here (hybris-integration.atlassian.net/browse/IIPS-47)
we support both compilation modes. Ant targets and idea internal. They
shouldn't be mixed as idea has it's own compilation model/cache. If
you use idea compilation then you can use JRebel or hotswap.
You cant hotswap classes in hybris without the help of a hotswap agent.There is a tool available in the market called JRebel. It is a good commercial tool if one can afford. However, if you are an open-sourcist, there is a promising alternative to JRebel, which is DCEVM (Dynamic Code Evolution Virtual Machine) along with HotswapAgent.
I don't know if this help,
you can start another cmd console, and run
setantenv and ant build to hotswap class in runtime.

Intellij - how to make a plugin that can perform IDE actions via a CLI or web service?

I need some help getting started making a specific IntelliJ plugin.
I want to make an IntelliJ plugin that makes it so you can launch intelliJ actions from CLI (or from a web service if it's easier).
For example, I'm done building my project with a gradle script... but i want to get it ready in intelliJ too. Right now I have to do this manually with a point-and-clicks.
Instead I want to have this the ability to externally trigger some IntelliJ commands. In my example I would want to fire off these requests from my gradle script:
run-intellij-command {project-path} --action refresh-gradle
run-intellij-command {project-path} --action build-project
run-intellij-command {project-path} --action start-debugging --configurationName={configuration-name}
Does anyone have an example of how I can get started with this?
Really hoping there is an intellij plugin project that already does something similar like reacting to cli commands or hosts a web service that can be called?
Thanks!
Also created this https://youtrack.jetbrains.com/issue/IDEA-184885
hoping to see this feature become a reality some day
You can use the ApplicationStarterEx interface to implement that. Provide a class implementing the interface, and register it in your plugin.xml as the <appStarter> extension point.
To execute your code, use Tools | Create Command-line Launcher, and then run idea <startername> <arguments> from the command line, where startername is what you return from ApplicationStarter.getCommandName().
I'm not aware of any existing open-source plugins that implement similar functionality.

How should I set up a web project using Kotlin on the back-end and in the browser?

If I wanted to build a website which used Kotlin both on the back-end, and in the browser - how would I set this up? Is there a Maven archetype or a Gradle template that captures best-practices for something like this?
The easiest way is to keep the modules separate, and I guess conceptually you'd probably want to do that also. While IntelliJ IDEA for instance doesn't natively support the ability to output to JS and JVM with Kotlin, in principle with Gradle/Maven you could. Here are instructions on targeting JVM and JavaScript for Gradle http://kotlinlang.org/docs/reference/using-gradle.html

How can I check the build command for my JavafX app in IntelliJ IDEA

Im creating a JavaFX application in IntelliJ IDEA, and I am new to IntelliJ.
I would like to be able to compile my JavaFX application on a Raspberry Pi, but my app is quite complex and relies on 3rd party libraries, etc.
I would like to be able to see what exactly is going on in IntelliJ when I run "Make Project"
Is there a command line output screen that Im simply missing? I want the exact command that IntelliJ uses to compile the application.
Essentially, on the Pi, I want to get the code from my repo, run the compilation command and produce an executable JAR on demand.
I have of course read the doco on how to compile a JavaFX application, but if I could see what IntelliJ does, that would be fantastic.
So far I haven't found such an option but the process is most likely some sort of flow based on IntelliJ plugins and the documentation seems to support this theory.
Perhaps you'd consider using a software management and build tool such as maven or ant or something similar. This should give you (almost) unlimited options to configure your desired build sequence and 3rd party dependencies.

Maven2 life cycle help

I’ve built a custom Maven2 plug-in using Ant. I would like to call another maven plug-in in particular the Cargo Maven2 plug-in immediately after the custom Ant plug-in successfully completes. However, I do not want to attach the Cargo plug-in to another goal or phase. Is there a way to have them run consecutively without having to write a batch script? Is there away to have the Custom Ant plug-in call out to the Cargo plug-in?
See this discussion: Re: calling plugin in another plugin? According to the Maven developers, this is not the way plugins are supposed to work.
However, there is this interesting comment:
Plugins/Mojos should be thin wrappers around a library. You'd want to use the library directly.
Cargo is not only a Maven plugin, it also has a Java API and an Ant task. So you could probably:
call the Cargo Ant task from your Ant mojo (I think you'll just need the Cargo JARs in your plugin's classpath);
rewrite your Ant mojo in Java, and invoke the Cargo API (you'd want to look at the sources of the Cargo plugin).
The Ant script that the maven-ant-plugin executes is not really aware of Maven as such; this plugin is designed for backwards compatibility with custom Ant tasks. I cannot think of a clean way of doing what you want though there may be some kind of hack that allows you to do it.
It should also be possible to execute a second instance of Maven from inside Ant, which runs purely the Cargo goal, but in that case you might encounter problems with locked files and the like. The way to do it would be to just use an tag in your Ant script and call the "mvn" executable with the appropriate goals as arguments.
The cleanest way is to simply bind the Cargo goal to a phase of the build, and have that run after Ant is finished. I do not see any disadvantage to that approach - you haven't really stated any specific reasons why you want to avoid it.
You might be interested in the two following maven
The Mojo Executor plugin and
The GMaven plugin
The GMaven plugin lets you write maven plugins using groovy. This gives you full access to ant using the Ant Builder, it is a very easy way to write ant scripts in Groovy.
Then in this Groovy mojo you could call any maven mojo using the Mojo Executor.
I have used those in several custom maven plugin and I haven't found an easier way to write and combine mojos.