future = Futures.immediateFuture(new CompileResult(code.get())); compiled.append(result.getContent()); if (useExterns) { String export = result.getExternExport(); if (export != null) { exports.append(export);
protected CompileResult doCompileContent(JsContent content, CompilerOptions options, List<SourceFile> externs) throws CompilerException { Compiler compiler = new Compiler(getErrorManager()); // We shouldn't reuse compilers // disable JS Closure Compiler internal thread compiler.disableThreads(); SourceFile source = SourceFile.fromCode(content.getSource(), content.get()); Result result = compiler.compile(externs, Lists.newArrayList(source), options); if (result.errors.length > 0) { throw new CompilerException(result.errors); } return new CompileResult(compiler, result); }
private ClosureJsCompiler newClosureJsCompiler(final Compiler realComp, CompilerOptions realOptions, DefaultJsCompiler defaultComp, CacheProvider cache) throws InterruptedException, ExecutionException { Future<CompileResult> mockFuture = EasyMock.createMock(Future.class); expect(mockFuture.get()).andReturn(new CompileResult(realComp, realResultMock)).anyTimes(); replay(mockFuture); expect(executorServiceMock.submit(isA(Callable.class))).andReturn(mockFuture); replay(executorServiceMock); ClosureJsCompiler compiler = createMockBuilder(ClosureJsCompiler.class) .addMockedMethods("getCompilerOptions") .withConstructor(defaultComp, cache, "simple", executorServiceMock) .createMock(); expect(compiler.getCompilerOptions(isA(JsUri.class))).andReturn(realOptionsMock).anyTimes(); replay(compiler); return compiler; }
private ClosureJsCompiler newClosureJsCompiler(final Compiler realComp, CompilerOptions realOptions, DefaultJsCompiler defaultComp, CacheProvider cache) throws InterruptedException, ExecutionException { Future<CompileResult> mockFuture = EasyMock.createMock(Future.class); expect(mockFuture.get()).andReturn(new CompileResult(realComp, realResultMock)).anyTimes(); replay(mockFuture); expect(executorServiceMock.submit(isA(Callable.class))).andReturn(mockFuture); replay(executorServiceMock); ClosureJsCompiler compiler = createMockBuilder(ClosureJsCompiler.class) .addMockedMethods("getCompilerOptions") .withConstructor(defaultComp, cache, "simple", executorServiceMock) .createMock(); expect(compiler.getCompilerOptions(isA(JsUri.class))).andReturn(realOptionsMock).anyTimes(); replay(compiler); return compiler; }