Skip to content
mihoPublic

About

VMF is a Lightweight Modeling Framework for the Java Platform (works on JDK 11-24)

Topics

Resources

Stars

25 stars

Watchers

4 watching

Forks

Latest commit

 

History

1,035 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

VMF

Javadocs Javadocs Javadocs VMF CI Join the chat at https://gitter.im/VMF_/Lobby


VMF is a lightweight modeling framework. It conveniently translates annotated Java interfaces into powerful implementations. It writes all the inevitable but boring boilerplate code for you and provides a modern and stable API. It is designed to work with the newest versions of Java as soon as they are released. It works well with Java 11-24. It generates/supports:

A VMF model consists of annotated Java interfaces. We could call this "wannabe" code. Just specify the interface and its properties and get a fully functional implementation including property setters and getters, builders, iterators, and much more. Even for a simple model VMF provides a lot of useful APIs:

Multi-target support: portable vs. language-specific features

VMF models are declared once as annotated Java interfaces and can generate native code for Java, C# (.NET 10), TypeScript (ES2022), and Python (3.10+). VMF separates core modeling behavior from serialization and platform-specific integrations:

Category Multilingual (Portable Contract: Java, C#, TypeScript, Python) Java + C# (Target-specific extras) Single-language / Platform-specific
Core modeling Types, multiple inheritance, @InterfaceOnly, redeclaration, generics, scalars & defaults, containment & cycles, opposite references, content equality & deep copy, read-only views & @Immutable, sets/ordered sets/maps/keyed containment, @DelegateTo behaviors & hooks, external types/enums/UUID/untyped Object, reflection order & annotations, declared validation (@Multiplicity, @Range, @Length, @Pattern), depth-first graph traversal & writable cursors (traversal) Builders (applyFrom/applyTo), static type catalog & reflection writes, ModelValidator application rules & reference-following, shallow copy*, list sort / removeIf* Java: generator host (Gradle/Maven plugins, IntelliJ integration, vmfedit), VCollections interop.
C#: IEquatable<T>, object initializers, partial binding methods.
TypeScript: vmf.edit(...) rollback blocks, installModelBindings(...), bigint for 64-bit long, identity-only === (N3) with contentEquals().
Python: PEP 8 snake_case, PEP 484/561 typing, with vmf.edit(origin): rollback blocks, install_model_bindings(...), native __eq__/__hash__ (N2).
Events & history Local & recursive listeners, registration order (E7), nearest-ancestor delivery (E8), immediate reentrant listener edits (E9), recording & undo/redo with causal recording order (H4) Direct property & raw collection listeners, native transactions Java: JavaBeans PropertyChangeListener.
C#: INotifyPropertyChanged (WPF/MAUI/Avalonia binding) on mutable models & read-only views.
Serialization & interchange JSON (json module): reference-aware snapshots (stable @Id references J7 or synthetic @vmf-id, plus @vmf-type and @WireName) and plain external JSON (ReferenceMode: IDS / REJECT / OMIT) XML & YAML snapshots (via Jackson in Java), per-format @WireName(format = ...) overrides, Draft-07 JSON Schema generation, feature bundles (plugin persistence), V1 preview change journals (JournalBinding.forModel / CreateJournalBinding) / diff / merge / patches** Java: arbitrary Jackson-serializable untyped Object payloads; direct ChangeJournal JSON/YAML/XML via VMFJacksonModule; custom formats via VMFJacksonModule.withFormat(...).

* Shallow copy and list sort/removeIf are kept Java+C# for now and recorded as candidates for future contract extension.
** Portable change journals remain a feature preview (envelope v1) and will be evaluated for a portable contract module once the format leaves preview.

  • Contract & scenarios: The portable contract defines all 87 shared rules across 13 modules; ./gradlew :vmf:verifyPortableContract executes the shared JSON scenarios on Java, C#, TypeScript, and Python.
  • Language mappings: Java, C#, TypeScript, and Python.
  • Workshop & C# conformance: The Workshop example exchanges reference-aware and plain JSON across all four targets; conformance/TEST-AREAS.md records the classification of every C# conformance area.

Using VMF

Checkout the tutorial projects: https://github.com/miho/VMF-Tutorials

For Maven projects, see the VMF Maven plugin guide.

VMF comes with excellent Gradle support. Just add the plugin like so (get the latest version here):

plugins {
  id "eu.mihosoft.vmf" version "0.4.0"
}

Now just add the model definitions to the VMF source folder, e.g., src/main/vmf/. The package name must end with .vmfmodel, for example:

package eu.mihosoft.vmf.tutorial.vmfmodel;

import eu.mihosoft.vmf.core.Container;
import eu.mihosoft.vmf.core.Contains;

interface Parent {

    @Contains(opposite = "parent")
    Child[] getChildren();

    String getName();
}

interface Child {
    @Container(opposite="children")
    Parent getParent();
    
    int getValue();
}

Just call the vmfGenModelSources task to generate the implementation.

See Generic model interfaces for reusable property declarations with named concrete bindings.

To improve IDE support, enable the IntelliJ support via

buildscript {
  ext.vmfPluginIntelliJIntegration = true
}

Saving plugin features

Register the core and plugin models in a ModelRegistry. Once the plugins have attached their VMF objects, use the codec from vmf-jackson to save and reload the owner and its directly attached features in one file. Use a .json, .yaml, .yml, or .xml filename, or pass the shared VMFDocumentFormat explicitly. A filename without an extension uses JSON. Unrecognized extensions require an explicit format.

var codec = new VMFFeatureCodec(registry);
codec.save(path, device, attachments);

var loaded = codec.load(path, Device.class);
Device restored = loaded.owner();
var calibration = loaded.attachments().find(restored, Calibration.class);

The codec handles modeled properties for each registered feature type. If a plugin required by the file is missing, loading reports its type name. See the two-plugin example.

Snapshots

Between releases, main is published as -SNAPSHOT (e.g. 0.5.0-SNAPSHOT) to the Maven Central snapshot repository. To use it, add the repository for plugins (settings.gradle) and, for other VMF artifacts such as vmf-jackson, for dependencies:

// settings.gradle
pluginManagement {
  repositories {
    maven {
      url = uri('https://central.sonatype.com/repository/maven-snapshots/')
      mavenContent { snapshotsOnly() }
    }
    gradlePluginPortal()
    mavenCentral()
  }
}
// build.gradle
plugins {
  id "eu.mihosoft.vmf" version "0.5.0-SNAPSHOT"
}

repositories {
  mavenCentral()
  maven {
    url = uri('https://central.sonatype.com/repository/maven-snapshots/')
    mavenContent { snapshotsOnly() }
  }
}

Snapshots change without notice and are deleted after 90 days; Gradle caches them for 24 hours (--refresh-dependencies fetches the latest). How snapshots and releases are published: docs/RELEASING.md.

Building VMF (Core, Runtime and Plugin)

Requirements

  • Install JDK 11 and JDK 17. Set JAVA_HOME to the JDK that runs Gradle. CI uses JDK 17, 21 and 24.
  • Install Maven (mvn on your path) to run the full build.
  • The first build downloads dependencies.
  • IDE: Gradle Plugin (not necessary for command line usage)

IDE

Open the VMF Gradle project in your favourite IDE (tested with IntelliJ 2024) and build it by executing the publishToMavenLocal task.

Command Line

Navigate to the VMFGradle project (i.e., path/to/VMF/) and enter the following command

Bash (Linux/macOS/Cygwin/other Unix shell)

bash gradlew publishToMavenLocal

Windows (CMD)

gradlew publishToMavenLocal

NOTE: to execute the tests within the VMF project (basic tests) execute the test task after executing publishToMavenLocal.

Testing VMF

From the repository root, run sh ./build-and-test-all.sh on Linux or macOS, or build-and-test-all.bat on Windows. These are the same commands that CI uses. They build VMF into your local Maven repository and test the generator, both build plugins, generated models and Jackson integration.

Once dependencies are cached, append --offline to either command. This lets you run the full suite during a repository outage without requesting dependencies or publishing artifacts to Maven Central.

Viewing the Report

An HTML version of the test report is located in the build folder test-suite/build/reports/tests/test/index.html.

Local performance verification

Run the local performance gate to check containment, events, recording, and replay against a saved machine-local baseline.

About

VMF is a Lightweight Modeling Framework for the Java Platform (works on JDK 11-24)

Topics

Resources

Stars

25 stars

Watchers

4 watching

Forks

Releases

Packages

Used by

Contributors

Languages