use of org.lflang.LFRuntimeModule in project lingua-franca by lf-lang.
the class Main method main.
/**
* Main function of the stand-alone compiler.
*
* @param args CLI arguments
*/
public static void main(final String[] args) {
final ReportingBackend reporter = new ReportingBackend(new Io());
// Injector used to obtain Main instance.
final Injector injector = new LFStandaloneSetup(new LFRuntimeModule(), new LFStandaloneModule(reporter)).createInjectorAndDoEMFRegistration();
// Main instance.
final Main main = injector.getInstance(Main.class);
// Apache Commons Options object configured to according to available CLI arguments.
Options options = CLIOption.getOptions();
// CLI arguments parser.
CommandLineParser parser = new DefaultParser();
// Helper object for printing "help" menu.
HelpFormatter formatter = new HelpFormatter();
try {
main.cmd = parser.parse(options, args, true);
// If requested, print help and abort
if (main.cmd.hasOption(CLIOption.HELP.option.getOpt())) {
formatter.printHelp("lfc", options);
System.exit(0);
}
// If requested, print version and abort
if (main.cmd.hasOption(CLIOption.VERSION.option.getLongOpt())) {
System.out.println("lfc " + VERSION);
System.exit(0);
}
List<String> files = main.cmd.getArgList();
if (files.size() < 1) {
reporter.printFatalErrorAndExit("No input files.");
}
try {
List<Path> paths = files.stream().map(Paths::get).collect(Collectors.toList());
main.runGenerator(paths, injector);
} catch (RuntimeException e) {
reporter.printFatalErrorAndExit("An unexpected error occurred:", e);
}
} catch (ParseException e) {
reporter.printFatalError("Unable to parse commandline arguments. Reason: " + e.getMessage());
formatter.printHelp("lfc", options);
System.exit(1);
}
}
use of org.lflang.LFRuntimeModule in project lingua-franca by lf-lang.
the class TestBase method runSingleTestAndPrintResults.
/**
* Run a test, print results on stderr.
*
* @param test Test case.
* @param testClass The test class that will execute the test. This is target-specific,
* it may provide some target-specific configuration. We pass a class
* and not a new instance because this method needs to ensure the object
* is properly injected, and so, it needs to control its entire lifecycle.
* @param level Level to which to run the test.
*/
public static void runSingleTestAndPrintResults(LFTest test, Class<? extends TestBase> testClass, TestLevel level) {
Injector injector = new LFStandaloneSetup(new LFRuntimeModule()).createInjectorAndDoEMFRegistration();
TestBase runner;
try {
@SuppressWarnings("unchecked") Constructor<? extends TestBase> constructor = (Constructor<? extends TestBase>) testClass.getConstructors()[0];
runner = constructor.newInstance();
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
throw new IllegalStateException(e);
}
injector.injectMembers(runner);
Set<LFTest> tests = Set.of(test);
try {
runner.validateAndRun(tests, t -> true, level);
} catch (IOException e) {
throw new RuntimeIOException(e);
}
checkAndReportFailures(tests);
}
Aggregations