Search in sources :

Example 1 with N4JSCompileException

use of org.eclipse.n4js.generator.headless.N4JSCompileException in project n4js by eclipse.

the class AccessControlTest method compile.

/**
 * Compiles the projects generated into the path at {@link #FIXTURE_ROOT}, which in this test case the projects
 * representing the currently tested scenario and returns the generated issues.
 *
 * @return the generated issues
 */
private static Collection<Issue> compile(MemberType memberType) {
    IssueCollector issueCollector = new IssueCollector();
    try {
        N4HeadlessCompiler hlc = HeadlessCompilerFactory.createCompilerWithDefaults();
        final File projectRoot = Paths.get(FIXTURE_ROOT, memberType.name()).toFile();
        hlc.compileAllProjects(Arrays.asList(projectRoot), issueCollector);
    } catch (N4JSCompileException e) {
    // nothing to do
    }
    return issueCollector.getCollectedIssues();
}
Also used : N4JSCompileException(org.eclipse.n4js.generator.headless.N4JSCompileException) N4HeadlessCompiler(org.eclipse.n4js.generator.headless.N4HeadlessCompiler) IssueCollector(org.eclipse.n4js.generator.headless.IssueCollector) File(java.io.File)

Example 2 with N4JSCompileException

use of org.eclipse.n4js.generator.headless.N4JSCompileException in project n4js by eclipse.

the class ScenarioTest method testScenario11FailDueToInvisbleProject.

/**
 * Testing compiling
 */
@Test
public void testScenario11FailDueToInvisbleProject() {
    N4HeadlessCompiler hlc = HeadlessCompilerFactory.createCompilerWithDefaults();
    File root = new File(workspace, "scenario11");
    List<File> pProjectRoots = // 
    Arrays.asList(new File(root, "wsp1"));
    try {
        hlc.compileAllProjects(pProjectRoots);
        assertFalse("Should not have reached this point.", true);
    } catch (N4JSCompileException e) {
        String msg = e.getMessage();
        String expected = "Cannot compile project D due to 4 errors.";
        assertTrue("Wrong error message: '" + msg + "' expected beginning : '" + expected + "'", msg.startsWith(expected));
    }
    // expect source-files (depends on the chosen build order algorithm):
    assertExists(root, "wsp1/A/src-gen/packA/A.js");
    assertExists(root, "wsp1/C/src-gen/packC/C.js");
}
Also used : N4JSCompileException(org.eclipse.n4js.generator.headless.N4JSCompileException) N4HeadlessCompiler(org.eclipse.n4js.generator.headless.N4HeadlessCompiler) File(java.io.File) Test(org.junit.Test)

Example 3 with N4JSCompileException

use of org.eclipse.n4js.generator.headless.N4JSCompileException in project n4js by eclipse.

the class N4jscBase method doCompileAndTestAndRun.

/**
 * Core algorithm to call the invoke compilation testing and running.
 *
 * @throws ExitCodeException
 *             in error cases.
 */
private void doCompileAndTestAndRun() throws ExitCodeException {
    if (debug) {
        System.out.println("N4JS compiling...");
    }
    try {
        switch(buildtype) {
            case singlefile:
                compileArgumentsAsSingleFiles();
                break;
            case projects:
                compileArgumentsAsProjects();
                break;
            case allprojects:
                compileAllProjects();
                break;
            case dontcompile:
            default:
                registerProjects();
        }
    } catch (N4JSCompileException e) {
        // dump all information to error-stream.
        e.userDump(System.err);
        throw new ExitCodeException(EXITCODE_COMPILE_ERROR);
    }
    if (null != testCatalogFile) {
        final String catalog = testCatalogSupplier.get();
        try (final FileOutputStream fos = new FileOutputStream(testCatalogFile)) {
            fos.write(catalog.getBytes());
            fos.flush();
        } catch (IOException e) {
            System.out.println("Error while writing test catalog file at: " + testCatalogFile);
            throw new ExitCodeException(EXITCODE_TEST_CATALOG_ASSEMBLATION_ERROR);
        }
    }
    if (testThisLocation != null) {
        if (buildtype != BuildType.dontcompile) {
            flushAndIinsertMarkerInOutputs();
        }
        headlessTester.runTests(tester, implementationId, checkLocationToTest(), testReportRoot);
    }
    if (runThisFile != null) {
        if (buildtype != BuildType.dontcompile) {
            flushAndIinsertMarkerInOutputs();
        }
        headlessRunner.startRunner(runner, implementationId, systemLoader, checkFileToRun(), targetPlatformInstallLocation);
    }
    if (debug) {
        System.out.println("... done.");
    }
}
Also used : N4JSCompileException(org.eclipse.n4js.generator.headless.N4JSCompileException) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException)

Aggregations

N4JSCompileException (org.eclipse.n4js.generator.headless.N4JSCompileException)3 File (java.io.File)2 N4HeadlessCompiler (org.eclipse.n4js.generator.headless.N4HeadlessCompiler)2 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 IssueCollector (org.eclipse.n4js.generator.headless.IssueCollector)1 Test (org.junit.Test)1