TIP: how to create Relax-NG version of the liquibase schema

I use nxml mode in emacs, which requires Relax-NG Compact Notation (RNC) schemas.

To be able to edit liquibase changelogs in nxml, I have created a maven pom file that will download the liquibase-core jar, extract the XSD files and convert of them to Relax-NG Compact notation (it will create a Relax-NG XML Notation schema as well): GitHub - steinarb/convert-liquibase-xsd-to-rnc: Maven pom to download liquibase XSD schemas and convert one of them to Relax-NG XML and compact notation schemas

Usage (example for version 4.32 of the liquibase XSD schema):

  1. Clone this project

    mkdir -p ~/git
    cd ~/git/
    git clone https://github.com/steinarb/convert-liquibase-xsd-to-rnc.git
    
  2. Build with

    cd convert-liquibase-xsd-to-rnc/
    mvn -Dliquibase-xsd.version=4.32 install
    
  3. The resulting schemas can be found in the target directory of the project:

    drwxr-xr-x 4 sb sb   4096 May 29 17:35 .
    drwxr-xr-x 4 sb sb   4096 May 29 17:35 ..
    -rw-r--r-- 1 sb sb  39593 May 29 17:35 dbchangelog-4.32.rnc
    -rw-r--r-- 1 sb sb 153739 May 29 17:35 dbchangelog-4.32.rng
    drwxr-xr-x 3 sb sb   4096 May 29 17:35 dependency
    drwxr-xr-x 2 sb sb   4096 May 29 17:35 dependency-maven-plugin-markers
    

I have built this schema transform into my liquibase maven projects.

I was already extracting the XSD schema currently used because at one point in time the server serving the schemas from their canonical URL went down and loading my apps failed. I then discovered that the XSD parsing had a fallback in loading the XSD schema from a classpath resource. However I am running in OSGi and in OSGi classpath resources are bundle local (a “bundle” in OSGi is a jar file with some special stuff in MANIFEST.MF). Some might see this as a limitation, but most of the time I see this as a feature.

Anyway: this meant to be proof against this server going down I had to extract the liquibase schema of the version I am currently using and add it as a classpath resource of the jar file the changelog is loaded from. This is done by:

So I added the conversion:

In the schema locating file (which nxml mode uses to find its schemas) I have put a comment that if nxml fails in loading the changelog, then run “mvn install”: sampleapp/sampleapp.db.liquibase/src/main/resources/sampleapp-db-changelog/schemas.xml at 93ebf95e0f0b00fb9840f4cdede1e19625cb5033 · steinarb/sampleapp · GitHub