Generating resources before run/debur or after file changes?

How can I hook a filesystem change or hook before running/debugging?

 

What I want to do is to be able to generate new resources based on other resources. And I want to keep them updated before running so they are available.

 

I'm already doing that in a gradle plugin before build/processResources. But I want to integrate it with intelliJ to avoid having to run that gradle task manually and without using gradle at all.

 

0
8 comments

Hey, thanks for the reply!

I have tested, and the hook works. But it seems that the callback is handled in another thread. Because i put a Thread.sleep(5000) inside processStarted handler, and the application starts before the sleep ends.

I need to execute the generator code, that won't run immediately and delay the application start until it has finished.

0

Then you need to implement another method instead of `processStarted()`.

Actually, it would be better to make your plugin a part of a build process. Unfortunately, there seems to be no documentation on the topic. Please take a look at `org.jetbrains.jps.incremental.resources.ResourcesBuilder` - it performs a related task.

0

Ok. Thanks for the info!

Since it is not documented. I'm going to put here my progress so other people can benefit.

After some tries with extension I found this:

<extension>

<stepsBeforeRunProvider implementation="..."></stepsBeforeRunProvider>

</extension>

Here you can do it overriding getId+createTask+executeTask and creating a Key.

I was not able to report in the status bar. So I'm going to check the ResourcesBuilder:

That ends referring to: META-INF/services/org.jetbrains.jps.incremental.BuilderService

I will inform about my progress later :)

0

It seemed that for META-INF you had to create a jps plugin. And I wanted to avoid that. So here is my initial dummy implementation that I will fill later:

https://github.com/soywiz/korge/commit/38a9fec4b9435f9c60c2618606e1cbbe618fdda0

0

Right, you need a JPS plugin - actually, it's not hard at all :)

I said this is better 'cause this way your plugin will have better compatibility with others. For example, if you want these file to be packed into an artifact (File | Project Structure | Artifacts), that's the only way to go.

0

I see. But as far as I remember debug JPS was harder than a normal plugin. That's why I wanted to start first with this. Now I have already implemented it. But I don't know how to get the "build/resources/main" folder (from a Module). It already works but right now I have hardcoded it which is not very future-proof:

https://github.com/soywiz/korge/blob/develop/korge-intellij-plugin/src/com/soywiz/korge/intellij/UpdateResourcesBeforeRunProvider.kt#L56

Any tips on this?

0

Actually, I was wrong about the docs - here they are, along with instructions for debugging.

On a positive side, developing a JPS plugin is easier - you don't need to restart IDEA even after major changes.

0

Please sign in to leave a comment.