Use ServiceManager in ExternalBuilder
Hi all,
When using the ServiceManager from within an ExternalBuilder plugin I run into NPE's. I guess the external builder context is not quite the same hence the problem(s). The service I want to access is an ApplicationService that contains the settings for my external builder.
What is the correct way to pass this service to my external builder plugin? Or if it can not be done using the ServiceManager how can I pass values to my plugin.
Thanks in advance for any input.
Best regards,
Johan
Please sign in to leave a comment.
ExternalBuilder plugins run in a separate process and do not have any access to application components or services. To provide custom configuration for your custom build process, you can create a facet. You can look at the code of the Android plugin for an example of how this is done.
Hello,
to load application-level settings in the external build process you need to implement JpsGlobalExtensionSerializer and return your implementation
from JpsModelSerializerExtension#getGlobalExtensionSerializers. You can see how intelli-lang properties are loaded:
https://upsource.jetbrains.com/ideace/view/6fe642265c99af27f5e728b34ef50e30daad3702/plugins/IntelliLang/intellilang-jps-plugin/src/org/jetbrains/jps/intellilang/model/impl/JpsIntelliLangConfigurationSerializer.java;nav:562:599:focused
--
Nikolay Chashnikov
Software Developer
JetBrains
http://www.jetbrains.com
"Develop with pleasure!"
Thank to both of you, I'll look into both alternative.
Regards,
Johan
I took a look at the JpsModelSerializerExtension option. My plugin offers an applicatiion wide function so a facet seems not to be what I need.
The way I understand things is that serialization (to an xml file) is used as a pass through between IJ and the external builder. Is that correct? I got the xml read part to work in the external builder thanks to the given example. I miss the xml writing part :(
How to create the xml from the Configurable impl (the UI component to view and set the settings of my plugin). Previously I implemented the PersistentStateComponent to save these settings. To me it seems that this works differently from the JDOM scheme used in the JpsModelSerializerExtension approach.
It seems to me that all I need to get access to the correct JpsGlobal value from within my Configurable impl. I then can reuse the logic to read&write the xml. Is there a way to do this (access a JpsGlobal I mean) or am I going about it in the wrong way?
Many thanks for you help.
Regards,
Johan
External Builder loads the project configuration from the xml files where it is stored by IntelliJ IDEA. So JpsModelSerializerExtension provides a way
to load/store project configuration for the external build where the standard PersistentStateComponent aren't available. Currently if you need to
access some part of project configuration from the external build you need to implement deserialization twice: on IDEA side using
PerstistentStateComponent and on the external build side using JpsModelSerializerExtension. 'save' methods of JpsModelSerializerExtension's components
aren't used for now. In the future IDEA will use JPS model and JpsModelSerializerExtension in the IDE process as well so this duplication will go away.
--
Nikolay Chashnikov
Software Developer
JetBrains
http://www.jetbrains.com
"Develop with pleasure!"
Thank you for this clarification Nikolay!
A few more questions if you don't mind, just to make sure I understand it correctly:
- within IDEA (not the ext builder) I use the PerstistentStateComponent way to save to xml
- within the ext builder I use JpsModelSerializerExtension to read the xml
For my PerstistentStateComponent impl I used StoragePathMacros.APP_CONFIG for the storage file of the @state. Since the JpsModelSerializerExtension is project based I need to use PROJECT_CONFIG_DIR then. Correct?
Thanks for you help in this matter.
Regards,
Johan
Yes, you understand it correctly except that JpsModelSerializerExtension isn't project-based. If you implement getGlobalExtensionSerializers() method
the 'configFileName' parameter of JpsGlobalExtensionSerializer refers to file name located under StoragePathMacros.APP_CONFIG directory.
--
Nikolay Chashnikov
Software Developer
JetBrains
http://www.jetbrains.com
"Develop with pleasure!"
Thanks a million Nikolay. It works now.
Best regards,
Johan