Skip to content

Commit d174fa6

Browse files
radekdoulikjonpryor
authored andcommitted
[jnimarshalmethod-gen] Add --types option (#355)
The new `jnimarshalmethod-gen --types=FILE` option is a more convenient "overload" of `jnimarshalmethod-gen --type=REGEX`, allowing the regular expressions to be read from `FILE` instead of as separate `-t REGEX` options. In addition to single-line regular expressions, `FILE` may also contain empty lines or lines which start with a `#`, which is ignored so that it may be treated as a comment.
1 parent 0b7f93b commit d174fa6

File tree

1 file changed

+25
-2
lines changed
  • tools/jnimarshalmethod-gen

1 file changed

+25
-2
lines changed

tools/jnimarshalmethod-gen/App.cs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ List<string> ProcessArguments (string [] args)
9393
{ "h|help|?",
9494
"Show this message and exit",
9595
v => help = v != null },
96+
{ "types=",
97+
"Generate marshaling methods only for types whose names match regex patterns listed {FILE}.\n" +
98+
"One regex pattern per line.\n" +
99+
"Empty lines and lines starting with '#' character are ignored as comments.",
100+
v => LoadTypes (v) },
96101
{ "t|type=",
97102
"Generate marshaling methods only for types whose names match {TYPE-REGEX}.",
98103
v => typeNameRegexes.Add (new Regex (v)) },
@@ -116,6 +121,24 @@ List<string> ProcessArguments (string [] args)
116121
return assemblies;
117122
}
118123

124+
void LoadTypes (string typesPath)
125+
{
126+
try {
127+
foreach (var line in File.ReadLines (typesPath)) {
128+
if (string.IsNullOrWhiteSpace (line))
129+
continue;
130+
131+
if (line [0] == '#')
132+
continue;
133+
134+
typeNameRegexes.Add (new Regex (line));
135+
}
136+
} catch (Exception e) {
137+
Error ($"Unable to read profile '{typesPath}'.{Environment.NewLine}{e}");
138+
Environment.Exit (4);
139+
}
140+
}
141+
119142
void ProcessAssemblies (List<string> assemblies)
120143
{
121144
CreateJavaVM (jvmDllPath);
@@ -153,7 +176,7 @@ void ProcessAssemblies (List<string> assemblies)
153176
try {
154177
CreateMarshalMethodAssembly (assembly);
155178
} catch (Exception e) {
156-
Error ($"Unable to process assembly '{assembly}'\n{e.Message}\n{e}");
179+
Error ($"Unable to process assembly '{assembly}'{Environment.NewLine}{e.Message}{Environment.NewLine}{e}");
157180
Environment.Exit (1);
158181
}
159182
}
@@ -168,7 +191,7 @@ void CreateJavaVM (string jvmDllPath)
168191
try {
169192
builder.CreateJreVM ();
170193
} catch (Exception e) {
171-
Error ($"Unable to create Java VM\n{e}");
194+
Error ($"Unable to create Java VM{Environment.NewLine}{e}");
172195
Environment.Exit (3);
173196
}
174197
}

0 commit comments

Comments
 (0)