Skip to content

Commit

Permalink
Add vdmj.lifecycle property
Browse files Browse the repository at this point in the history
  • Loading branch information
nickbattle committed Oct 20, 2023
1 parent 2b9c9b1 commit 32f0501
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
5 changes: 5 additions & 0 deletions vdmj/src/main/java/com/fujitsu/vdmj/config/Properties.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
28 changes: 27 additions & 1 deletion vdmj/src/main/java/com/fujitsu/vdmj/plugins/VDMJ.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
}
}
}
3 changes: 3 additions & 0 deletions vdmj/src/test/resources/vdmj.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 32f0501

Please sign in to comment.