Search in sources :

Example 1 with ExitCodeException

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);
    }
}
Also used : RunConfiguration(org.eclipse.n4js.runner.RunConfiguration) IRunnerDescriptor(org.eclipse.n4js.runner.extension.IRunnerDescriptor) ExitCodeException(org.eclipse.n4js.hlc.base.ExitCodeException)

Example 2 with ExitCodeException

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();
    }
}
Also used : ITesterDescriptor(org.eclipse.n4js.tester.extension.ITesterDescriptor) TestConfiguration(org.eclipse.n4js.tester.TestConfiguration) ExitCodeException(org.eclipse.n4js.hlc.base.ExitCodeException) TestTree(org.eclipse.n4js.tester.domain.TestTree)

Example 3 with ExitCodeException

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);
    }
}
Also used : IOException(java.io.IOException) ExitCodeException(org.eclipse.n4js.hlc.base.ExitCodeException) File(java.io.File)

Example 4 with ExitCodeException

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);
    }
}
Also used : UtilN4(org.eclipse.n4js.utils.UtilN4) NodeBinaryLocatorHelper(org.eclipse.n4js.binaries.nodejs.NodeBinaryLocatorHelper) FileDeleter(org.eclipse.n4js.utils.io.FileDeleter) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) N4JSGlobals(org.eclipse.n4js.N4JSGlobals) Optional(com.google.common.base.Optional) IWorkflowComponent(org.eclipse.emf.mwe2.runtime.workflow.IWorkflowComponent) JsonNode(com.fasterxml.jackson.databind.JsonNode) LinkedList(java.util.LinkedList) N4jscBase(org.eclipse.n4js.hlc.base.N4jscBase) Path(java.nio.file.Path) ExternalLibrariesActivator(org.eclipse.n4js.external.libraries.ExternalLibrariesActivator) NodeProcessBuilder(org.eclipse.n4js.binaries.nodejs.NodeProcessBuilder) N4JSStandaloneSetup(org.eclipse.n4js.N4JSStandaloneSetup) FileVisitor(java.nio.file.FileVisitor) Iterator(java.util.Iterator) Files(java.nio.file.Files) FileCopier(org.eclipse.n4js.utils.io.FileCopier) IWorkflowContext(org.eclipse.emf.mwe2.runtime.workflow.IWorkflowContext) FileWriter(java.io.FileWriter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) Collectors(java.util.stream.Collectors) File(java.io.File) Injector(com.google.inject.Injector) FileVisitResult(java.nio.file.FileVisitResult) List(java.util.List) Stream(java.util.stream.Stream) Entry(java.util.Map.Entry) ExitCodeException(org.eclipse.n4js.hlc.base.ExitCodeException) ExitCodeException(org.eclipse.n4js.hlc.base.ExitCodeException) N4jscBase(org.eclipse.n4js.hlc.base.N4jscBase)

Aggregations

ExitCodeException (org.eclipse.n4js.hlc.base.ExitCodeException)4 File (java.io.File)2 IOException (java.io.IOException)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Optional (com.google.common.base.Optional)1 Injector (com.google.inject.Injector)1 FileWriter (java.io.FileWriter)1 FileVisitResult (java.nio.file.FileVisitResult)1 FileVisitor (java.nio.file.FileVisitor)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)1 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Entry (java.util.Map.Entry)1 Collectors (java.util.stream.Collectors)1