use of org.eclipse.n4js.hlc.base.ExitCodeException in project n4js by eclipse.
the class HeadlessRunner method startRunner.
/**
* Actually start the requested file with the chosen runner. Workspace from headlesCompiler should be configured
* before calling this method.
*
* @param runner
* the runner to be used
* @param implementationId
* to be used for API-IMPL projects
* @param systemLoader
* to be used when loading the modules
* @param locationToRun
* location of the code to be executed
* @param targetPlatformInstallLocation
* location for externally installed node_modules
* @throws ExitCodeException
* in cases of errors
*/
public void startRunner(String runner, String implementationId, String systemLoader, URI locationToRun, File targetPlatformInstallLocation) throws ExitCodeException {
IRunnerDescriptor runnerDescriptor = checkRunner(runner);
logger.info("Using runner :" + runnerDescriptor.getId());
RunConfiguration runConfiguration = null;
try {
if (targetPlatformInstallLocation != null) {
runConfiguration = runnerFrontEnd.createConfiguration(runnerDescriptor.getId(), implementationId, systemLoader, locationToRun, targetPlatformInstallLocation.toPath().resolve("node_modules").toAbsolutePath().toString());
} else {
runConfiguration = runnerFrontEnd.createConfiguration(runnerDescriptor.getId(), implementationId, systemLoader, locationToRun);
}
} catch (java.lang.IllegalStateException e2) {
logger.error(Throwables.getStackTraceAsString(e2));
throw new ExitCodeException(EXITCODE_RUNNER_STOPPED_WITH_ERROR, "Cannot create run configuration.", e2);
}
try {
Process process = runnerFrontEnd.run(runConfiguration);
int exit = process.waitFor();
if (exit != 0) {
throw new ExitCodeException(EXITCODE_RUNNER_STOPPED_WITH_ERROR, "The spawned runner '" + runnerDescriptor.getId() + "' exited with code=" + exit);
}
} catch (InterruptedException e1) {
logger.error(Throwables.getStackTraceAsString(e1));
throw new ExitCodeException(EXITCODE_RUNNER_STOPPED_WITH_ERROR, "The spawned runner exited by throwing an exception", e1);
}
}
use of org.eclipse.n4js.hlc.base.ExitCodeException in project n4js by eclipse.
the class HeadlessTester method runTests.
/**
* Actually start the requested tester to test provided location. Workspace from headlesCompiler should be
* configured before calling this method.
*
* @param tester
* the tester to be used
* @param implementationId
* to be used for API-IMPL projects
* @param locationToTest
* location of the test code
* @throws ExitCodeException
* in cases of errors
*/
public void runTests(String tester, String implementationId, URI locationToTest, File testReportRoot) throws ExitCodeException {
ITesterDescriptor testerDescriptor = checkTester(tester);
logger.info("Using tester :" + testerDescriptor.getId());
TestConfiguration testConfiguration = null;
try {
testConfiguration = testerFrontEnd.createConfiguration(testerDescriptor.getId(), implementationId, locationToTest);
} catch (java.lang.IllegalStateException e2) {
logger.error(Throwables.getStackTraceAsString(e2));
throw new ExitCodeException(EXITCODE_TESTER_STOPPED_WITH_ERROR, "Cannot create test configuration.", e2);
}
try {
TestTree testTree = testConfiguration.getTestTree();
LoggingTestListener testListener = new LoggingTestListener(testerEventBus, logger, testTree);
Process process = testerFrontEnd.test(testConfiguration);
int exit = process.waitFor();
if (!testListener.finished())
throw new ExitCodeException(EXITCODE_TESTER_STOPPED_WITH_ERROR, "Test session has not finished.");
if (testReportRoot != null)
createTestReport(testReportRoot, testTree);
if (!testListener.isOK())
throw new ExitCodeException(EXITCODE_TESTER_STOPPED_WITH_ERROR, "There were test errors, see console logs and/or test report for details.");
if (exit != 0)
throw new ExitCodeException(EXITCODE_TESTER_STOPPED_WITH_ERROR, "The spawned tester '" + testerDescriptor.getId() + "' exited with code=" + exit);
} catch (InterruptedException e1) {
logger.error(Throwables.getStackTraceAsString(e1));
throw new ExitCodeException(EXITCODE_TESTER_STOPPED_WITH_ERROR, "The spawned tester exited by throwing an exception", e1);
} finally {
testerFacade.shutdownFramework();
}
}
use of org.eclipse.n4js.hlc.base.ExitCodeException in project n4js by eclipse.
the class HeadlessTester method createTestReport.
private void createTestReport(File testReportRoot, TestTree testTree) throws ExitCodeException {
if (!(testReportRoot.isDirectory() && testReportRoot.canWrite()))
throw new ExitCodeException(EXITCODE_TESTER_STOPPED_WITH_ERROR, "cannot write test report to " + testReportRoot.getAbsolutePath() + ".");
File report = new File(testReportRoot, TEST_REPORT_NAME);
try {
if (report.exists())
FileDeleter.delete(report);
TestReport testReport = new TestReport((StringBuilder) testTreeXmlTransformer.apply(testTree));
testReport.dump(report);
} catch (IOException e) {
throw new ExitCodeException(EXITCODE_TESTER_STOPPED_WITH_ERROR, "Cannot generate test report at: " + report.getAbsolutePath() + ".", e);
}
}
use of org.eclipse.n4js.hlc.base.ExitCodeException in project n4js by eclipse.
the class UpdateShippedCode method cleanAndcompile.
private static void cleanAndcompile(File... foldersContainingProjectFolders) {
final String foldersContainingProjectsStr = Stream.of(foldersContainingProjectFolders).map(file -> file.getAbsolutePath()).collect(Collectors.joining(File.pathSeparator));
// Clean all projects first
final String[] cleanArgs = { "--clean", "--buildType", "allprojects", "--projectlocations", foldersContainingProjectsStr };
try {
new N4jscBase().doMain(cleanArgs);
} catch (ExitCodeException e) {
println("ERROR: while cleaning the projects, an ExitCodeException is thrown; " + "code: " + e.getExitCode() + ", " + "message: " + e.getMessage());
e.printStackTrace();
throw new RuntimeException(e);
}
// Then compile the projects
final String[] args = { "--buildType", "allprojects", "--projectlocations", foldersContainingProjectsStr };
try {
new N4jscBase().doMain(args);
} catch (ExitCodeException e) {
println("ERROR: headless compiler threw ExitCodeException (probably code compiled with errors); " + "code: " + e.getExitCode() + ", " + "message: " + e.getMessage());
e.printStackTrace();
throw new RuntimeException(e);
}
}
Aggregations