Skip to content

Commit 35ef11e

Browse files
Eyaml/Compiler Targets Stability (#64)
Add a safety net for erroneous or non-compliant compiler eyaml descriptions that keeps the plugin still in a usable state. Also look for the new "EXE-Vars" keys under the old location as well.
1 parent ccf1f47 commit 35ef11e

File tree

1 file changed

+32
-7
lines changed

1 file changed

+32
-7
lines changed

org/enigma/TargetHandler.java

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,16 @@ private TargetHandler()
4848

4949
static
5050
{
51-
load();
51+
try
52+
{
53+
load();
54+
}
55+
catch (Throwable e)
56+
{
57+
// keep the plugin in a usable state even if this
58+
// happens to fail to find any target compilers
59+
EnigmaRunner.showDefaultExceptionHandler(e);
60+
}
5261
}
5362

5463
public static void load()
@@ -271,30 +280,46 @@ private static ArrayList<TargetSelection> findCompilers()
271280
{
272281
String ey = file.getName();
273282
if (!ey.endsWith(".ey")) continue; //$NON-NLS-1$
283+
TargetSelection ps = null;
274284
try
275285
{
276286
YamlNode node = YamlParser.parse(file);
277-
YamlNode exeVarsNode = (YamlNode) node.getM("EXE-Vars");
278-
279-
TargetSelection ps = new TargetSelection();
287+
ps = new TargetSelection();
280288
ps.id = ey.substring(0,ey.length() - 3);
281289
ps.name = node.getMC("Name"); //$NON-NLS-1$
282290
ps.desc = node.getMC("Description",null); //$NON-NLS-1$
283291
ps.auth = node.getMC("Maintainer",null); //$NON-NLS-1$
284-
ps.ext = exeVarsNode.getMC("Build-Extension",null); //$NON-NLS-1$
285-
ps.outputexe = exeVarsNode.getMC("Run-output",null); //$NON-NLS-1$
286292
ps.depends = new HashMap<String,Set<String>>();
287293
Set<String> target = new HashSet<String>();
288294
String targplat = node.getMC("Target-platform",null); //$NON-NLS-1$
289295
if (target != null) targplat = normalize(targplat);
290296
target.add(targplat);
291297
ps.depends.put("target",target); //$NON-NLS-1$
292298
if (node.getBool("Native",false)) defCompiler = ps; //$NON-NLS-1$
293-
tCompilers.add(ps);
299+
try
300+
{
301+
YamlNode exeVarsNode = (YamlNode) node.getM("EXE-Vars"); //$NON-NLS-1$
302+
ps.ext = exeVarsNode.getMC("Build-Extension",null); //$NON-NLS-1$
303+
ps.outputexe = exeVarsNode.getMC("Run-output",null); //$NON-NLS-1$
304+
}
305+
catch (IndexOutOfBoundsException e)
306+
{
307+
// there was no "EXE-Vars" key, which is optional
308+
// but still check under the old location
309+
ps.ext = node.getMC("Build-Extension",null); //$NON-NLS-1$
310+
ps.outputexe = node.getMC("Run-output",null); //$NON-NLS-1$
311+
}
312+
313+
// only add the target if there were no errors
314+
if (ps != null) tCompilers.add(ps);
294315
}
295316
catch (FileNotFoundException e)
296317
{
297318
}
319+
catch (Exception e)
320+
{
321+
EnigmaRunner.showDefaultExceptionHandler(e);
322+
}
298323
}
299324
return tCompilers;
300325
}

0 commit comments

Comments
 (0)