Quantcast
Viewing all articles
Browse latest Browse all 10

XMLBeans integration in IntelliJ 13

Apache XMLBeans is a framework for binding XML schemas with Java object. It has been developed as an alternative to JAXB when the latter supported only a subset of XML schema features. XMLBeans works by compiling XSDs into Java source code with a tool called SCOMP. Generated classes can then be used by other part of the application code.

To be fully usable, this framework requires an integration in the build process : the build tool must invoke SCOMP to compile XSDs, then add generated classes to the source paths before compiling the rest of the source code. For Maven, the XMLBeans maven plugin does the job. Within IntelliJ IDEA there is no native integration. Nevertheless, there are some workarounds (e.g. launching Maven goals or SCOMP as a “before make” action), but none is 100% satisfactory. They require manual configuration, perform useless work (e.g. launching goal when building a module without any XSD to compile), or introduce dependency toward the environment (e.g. the installation path of SCOMP).

To solve this issue, we decided to implement a plugin for XMLBeans integration in IntelliJ. This plugin provides the following features :

  • Facet based configuration: both production and test sources can be configured for each module.
  • Transparent Maven integration: detects xmlbeans:xmlbeans and xmlbeans:test-xmlbeans execution and configuration on Maven project import.
  • Smart execution: the plugin only perform required amount of work.
  • Integrated compilation: module’s own classpath is used, ensuring correct version of XMLBeans is used. Error and warning are reported as standard compilation errors.

Facet based configuration

XMLBeans compilation is configured and added to the build process of a module with a facet. Each facet can configure two executions of XMLBeans : one for production sources and one for test sources. The second one can be enabled and disabled with the check box “Enable test configuration”. Each configuration allows to define the following parameters :

  • XSD sources directory: root directory containing XSD files
  • XSD configs directory: root directory containing xsdconfig files
  • Generated sources directory: directory where sources generated by XMLBeans are placed
  • Generated classes directory: directory where generated sources are compiled
  • Java sources level: Java level of sources generated by XMLBeans
  • Max memory size: Maximum amount of memory used by XMLBeans

The configuration is validated on the fly, and the plugin proposes quick fixes for most common errors, such as creating missing directories, or restoring default values.

Image may be NSFW.
Clik here to view.
XMLBeans facet configuration

XMLBeans facet configuration

Transparent Maven integration

The plugin transparently integrates with Maven. Just import your pom.xml files in Maven tool window and the plugin will automatically detects XMLBeans Maven plugin executions, and add a properly configured Facet on the imported module. If pom.xml is later modified, or the facet is manually modified, the facet can be automatically reconfigured by re-importing Maven projects. It’s also worth to know that the plugin respects Maven build order for its execution, avoiding missing classes error when compiling dependent modules. Finally, Maven convention are used as default values for configuration when the facet is manually added to a non-Maven module.

Smart execution

The plugin does not systematically re-compile XSD files on each make. It first checks that the module is in the compilation scope, then checks if the XSDs files have been modified since last successful compilation. This avoid unnecessary work.

Integrated compilation

The plugin executes XMLBeans with the classpath of the module. Doing this ensures two things :

  • XMLBeans is present in module’s classpath: this helps to detect missing dependency before runtime
  • Correct version of XMLBeans is used: this ensures that the version of XMLBeans used for compilation is the same as the one used at runtime by the module

Finally, it’s worth to note that errors and warnings of XSD files compilation are reported in “Messages Make” tool window, as standard, navigatable items.

Practical information and links

  • The plugin is licensed under the Apache 2.0 License.
  • The source code is available on GitHub
  • Binaries are available in JetBrains plugins repository
  • To build properly with Maven, you need to deploy in your repository a zipped vanilla installation of IntelliJ 13.0.2 under the following coordinates : org.jetbrains:org.jetbrains.intellij-ce:13.0.2

Viewing all articles
Browse latest Browse all 10

Trending Articles