use of com.google.javascript.jscomp.Result in project closure-compiler by google.
the class SourceMapTestCase method compile.
protected RunResult compile(String js1, String fileName1, String js2, String fileName2) {
Compiler compiler = new Compiler();
CompilerOptions options = getCompilerOptions();
options.setChecksOnly(true);
List<SourceFile> inputs = ImmutableList.of(SourceFile.fromCode(fileName1, js1));
if (js2 != null && fileName2 != null) {
inputs = ImmutableList.of(SourceFile.fromCode(fileName1, js1), SourceFile.fromCode(fileName2, js2));
}
Result result = compiler.compile(EXTERNS, inputs, options);
assertTrue("compilation failed", result.success);
String source = compiler.toSource();
StringBuilder sb = new StringBuilder();
try {
result.sourceMap.validate(true);
result.sourceMap.appendTo(sb, "testcode");
} catch (IOException e) {
throw new RuntimeException("unexpected exception", e);
}
RunResult rr = new RunResult();
rr.generatedSource = source;
rr.sourceMap = result.sourceMap;
rr.sourceMapFileContent = sb.toString();
return rr;
}
use of com.google.javascript.jscomp.Result in project closure-compiler by google.
the class CompileTask method execute.
@Override
public void execute() {
if (this.outputFile == null) {
throw new BuildException("outputFile attribute must be set");
}
Compiler.setLoggingLevel(Level.OFF);
CompilerOptions options = createCompilerOptions();
Compiler compiler = createCompiler(options);
List<SourceFile> externs = findExternFiles(options);
List<SourceFile> sources = findSourceFiles();
if (isStale() || forceRecompile) {
log("Compiling " + sources.size() + " file(s) with " + externs.size() + " extern(s)");
Result result = compiler.compile(externs, sources, options);
if (result.success) {
StringBuilder source = new StringBuilder(compiler.toSource());
if (this.outputWrapperFile != null) {
try {
this.outputWrapper = Files.asCharSource(this.outputWrapperFile, UTF_8).read();
} catch (Exception e) {
throw new BuildException("Invalid output_wrapper_file specified.");
}
}
if (this.outputWrapper != null) {
int pos = this.outputWrapper.indexOf(CommandLineRunner.OUTPUT_MARKER);
if (pos > -1) {
String prefix = this.outputWrapper.substring(0, pos);
source.insert(0, prefix);
// end of outputWrapper
int suffixStart = pos + CommandLineRunner.OUTPUT_MARKER.length();
String suffix = this.outputWrapper.substring(suffixStart);
source.append(suffix);
} else {
throw new BuildException("Invalid output_wrapper specified. " + "Missing '" + CommandLineRunner.OUTPUT_MARKER + "'.");
}
}
if (result.sourceMap != null) {
flushSourceMap(result.sourceMap);
}
writeResult(source.toString());
} else {
throw new BuildException("Compilation failed.");
}
} else {
log("None of the files changed. Compilation skipped.");
}
}
use of com.google.javascript.jscomp.Result in project closure-compiler by google.
the class DebuggerGwtMain method doCompile.
private void doCompile() {
SourceFile externFile = SourceFile.fromCode("externs", externs.getValue());
SourceFile srcFile = SourceFile.fromCode("input0", input0.getValue());
Compiler compiler = new Compiler();
try {
Result result = compiler.compile(externFile, srcFile, options);
updateUi(compiler, result);
} catch (Exception e) {
updateUiException(e);
}
}
Aggregations