use of org.eclipse.n4js.cli.helper.CliTools.CliException in project n4js by eclipse.
the class XtIdeTest method generated_dts.
/**
* Compares the content of the generated .d.ts file with the expectation string.
*
* <pre>
* // XPECT generated_dts ---
* <EXPECTED CONTENT OF GENERATED D.TS FILE>
* // ---
* </pre>
*/
@Xpect
public void generated_dts(XtMethodData data) throws IOException {
String moduleName = xtData.workspace.moduleNameOfXtFile;
int idxStart = Math.max(moduleName.lastIndexOf("/") + 1, 0);
int idxEnd = moduleName.lastIndexOf(".");
String genDtsFileName = moduleName.substring(idxStart, idxEnd) + ".d.ts";
try {
FileURI genDtsFileURI = getFileURIFromModuleName(genDtsFileName);
String genDtsCode = Files.readString(genDtsFileURI.toPath());
assertTrue(genDtsCode.startsWith(OUTPUT_FILE_PREAMBLE));
String genDtsCodeTrimmedPreamble = genDtsCode.substring(OUTPUT_FILE_PREAMBLE.length()).trim();
assertTrue(genDtsCodeTrimmedPreamble.startsWith(IMPORT_N4JSGLOBALS));
String genDtsCodeTrimmed = genDtsCodeTrimmedPreamble.substring(IMPORT_N4JSGLOBALS.length()).trim();
assertEquals(data.getUnescapeExpectationRaw(), genDtsCodeTrimmed);
CliTools cliTools = new CliTools();
ensureTSC(cliTools);
List<Project> allProjectsWithGenerateDts = FluentIterable.from(xtData.workspace.getAllProjects()).filter(Project::isGenerateDts).toList();
assertFalse("no projects found with .d.ts generation turned on", allProjectsWithGenerateDts.isEmpty());
for (Project project : allProjectsWithGenerateDts) {
File workingDir = getProjectRoot(project.getName());
// copy n4jsglobals.d.ts to output dir to make d.ts globals available
Path n4jsGlobalsDTS = N4jsLibsAccess.getN4JSGlobalsDTS();
Files.copy(n4jsGlobalsDTS, workingDir.toPath().resolve("src-gen/n4jsglobals.d.ts"));
ProcessResult result;
try {
result = cliTools.nodejsRun(workingDir.toPath(), TSC2.getAbsoluteFile().toPath());
} catch (CliException e) {
throw new AssertionError("error while running tsc in working directory: " + workingDir, e);
}
assertFalse("TypeScript Error: " + result.getStdOut(), result.getStdOut().contains(": error "));
}
} catch (IllegalStateException e) {
throw new RuntimeException("Could not find file " + genDtsFileName + "\nDid you set: " + XtSetupParser.GENERATE_DTS + " in SETUP section?", e);
}
}
use of org.eclipse.n4js.cli.helper.CliTools.CliException in project n4js by eclipse.
the class BuildN4jsLibs method compile.
private static void compile(Path n4jsLibsRootPath) {
CliCompileResult compileResult = new CliCompileResult();
try {
CliTools cliTools = new CliTools();
cliTools.setInheritIO(true);
// we want '--clean' but *not* '--noPersist'
N4jscTestOptions options = COMPILE(false, n4jsLibsRootPath.toFile()).clean();
Preconditions.checkState(options.isClean());
Preconditions.checkState(!options.isNoPersist());
cliTools.callN4jscInprocess(options, false, compileResult);
} catch (CliException e) {
if (compileResult.getException() != null) {
throw new RuntimeException(compileResult.getException());
} else if (compileResult.getErrs() > 0) {
// case to suppress further error reporting:
throw new RuntimeException("Errors while compiling n4js-libs");
} else {
throw new RuntimeException(e);
}
} catch (Exception e) {
println("EXCEPTION while compiling n4js-libs:");
e.printStackTrace();
Throwable root = Throwables.getRootCause(e);
if (root != e) {
println("Root cause:");
root.printStackTrace();
}
Throwables.throwIfUnchecked(e);
throw new RuntimeException(e);
}
}
Aggregations