From 32f0501999c47f4cd08497dce618733b39605f04 Mon Sep 17 00:00:00 2001 From: nick_battle Date: Fri, 20 Oct 2023 21:08:34 +0100 Subject: [PATCH] Add vdmj.lifecycle property --- .../com/fujitsu/vdmj/config/Properties.java | 5 ++++ .../java/com/fujitsu/vdmj/plugins/VDMJ.java | 28 ++++++++++++++++++- vdmj/src/test/resources/vdmj.properties | 3 ++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/vdmj/src/main/java/com/fujitsu/vdmj/config/Properties.java b/vdmj/src/main/java/com/fujitsu/vdmj/config/Properties.java index 14754cc76..e43a4c96e 100644 --- a/vdmj/src/main/java/com/fujitsu/vdmj/config/Properties.java +++ b/vdmj/src/main/java/com/fujitsu/vdmj/config/Properties.java @@ -35,6 +35,9 @@ */ public class Properties { + /** The main VDMJ lifecycle class */ + public static String lifecycle = null; + /** The tab stop for source files. */ public static int parser_tabstop = 4; @@ -175,6 +178,8 @@ public static void init(String filename) private static void setValues(java.util.Properties vdmj) { + lifecycle = get(vdmj, "vdmj.lifecycle", null); + parser_tabstop = get(vdmj, "vdmj.parser.tabstop", 4); parser_comment_nesting = get(vdmj, "vdmj.parser.comment_nesting", 3); parser_external_readers = get(vdmj, "vdmj.parser.external_readers", null); diff --git a/vdmj/src/main/java/com/fujitsu/vdmj/plugins/VDMJ.java b/vdmj/src/main/java/com/fujitsu/vdmj/plugins/VDMJ.java index 3a6c72d35..fa31ed43b 100644 --- a/vdmj/src/main/java/com/fujitsu/vdmj/plugins/VDMJ.java +++ b/vdmj/src/main/java/com/fujitsu/vdmj/plugins/VDMJ.java @@ -24,9 +24,12 @@ package com.fujitsu.vdmj.plugins; +import java.lang.reflect.Constructor; + import com.fujitsu.vdmj.ExitStatus; import com.fujitsu.vdmj.Settings; import com.fujitsu.vdmj.VDMJMain; +import com.fujitsu.vdmj.config.Properties; /** * The main class for the plugin based VDMJ. @@ -41,9 +44,32 @@ public static String getMainName() public static void main(String[] args) { Settings.mainClass = VDMJ.class; + Properties.init(); - Lifecycle lifecycle = new Lifecycle(args); + Lifecycle lifecycle = loadLifecycle(args); System.exit(lifecycle.run() == ExitStatus.EXIT_OK ? 0 : 1); } + + private static Lifecycle loadLifecycle(String[] args) + { + if (Properties.lifecycle == null) + { + return new Lifecycle(args); + } + + try + { + Class clazz = Class.forName(Properties.lifecycle); + Constructor ctor = clazz.getConstructor(String[].class); + return (Lifecycle) ctor.newInstance((Object)args); + } + catch (Exception e) + { + System.err.println("Cannot instatiate lifecycle " + Properties.lifecycle + "(String[] args)"); + System.err.println(e.toString()); + System.exit(1); + return null; + } + } } diff --git a/vdmj/src/test/resources/vdmj.properties b/vdmj/src/test/resources/vdmj.properties index f254bd34b..c5452e6f2 100644 --- a/vdmj/src/test/resources/vdmj.properties +++ b/vdmj/src/test/resources/vdmj.properties @@ -2,6 +2,9 @@ # Settings for VDMJ. These override defaults in the code. # +# The main VDMJ lifecycle class (default null => use builtin) +# vdmj.lifecycle = null; + # The tab stop for source files (default 4) vdmj.parser.tabstop = 4