/** * Returns a string of all error messages associated with this response. */ public String toErrorString() { if (errorString == null) { StringBuilder sb = new StringBuilder(); for (String error : getErrors()) { sb.append(error); } errorString = sb.toString(); } return errorString; }
public JsResponseBuilder(JsResponse response) { this(); if (response.getAllJsContent() != null) { jsCode.addAll(Lists.newArrayList(response.getAllJsContent())); } if (response.getErrors() != null) { errors.addAll(Lists.newArrayList(response.getErrors())); } if (response.getExterns() != null) { rawExterns.append(response.getExterns()); } statusCode = response.getStatusCode(); cacheTtlSecs = response.getCacheTtlSecs(); proxyCacheable = response.isProxyCacheable(); }
@Ignore("This class was not being run and when I ran it this test did not pass. Not familiar enough to enable it.") @Test public void testCompileErrorOpt() throws Exception { jsUriMock = mockJsUri(false); // opt realCompMock = mockRealJsCompiler(JS_ERROR, realResultMock, ACTUAL_COMPILER_OUTPUT); realOptionsMock = mockRealJsCompilerOptions(true); // force compiler to run compiler = newClosureJsCompiler(realCompMock, realOptionsMock, compilerMock, cacheMock); JsResponse actual = compiler.compile(jsUriMock, EXPORT_COMPILER_CONTENTS, EXTERN); assertTrue(actual.getErrors().get(0).contains(ERROR_NAME)); assertEquals(1, actual.getErrors().size()); }
@Ignore("This class was not being run and when I ran it this test did not pass. Not familiar enough to enable it.") @Test public void testCompileErrorOpt() throws Exception { jsUriMock = mockJsUri(false); // opt realCompMock = mockRealJsCompiler(JS_ERROR, realResultMock, ACTUAL_COMPILER_OUTPUT); realOptionsMock = mockRealJsCompilerOptions(true); // force compiler to run compiler = newClosureJsCompiler(realCompMock, realOptionsMock, compilerMock, cacheMock); JsResponse actual = compiler.compile(jsUriMock, EXPORT_COMPILER_CONTENTS, EXTERN); assertTrue(actual.getErrors().get(0).contains(ERROR_NAME)); assertEquals(1, actual.getErrors().size()); }
@Ignore("This class was not being run and when I ran it this test did not pass. Not familiar enough to enable it.") @Test public void testCompileErrorDeb() throws Exception { jsUriMock = mockJsUri(true); // debug realCompMock = mockRealJsCompiler(JS_ERROR, realResultMock, ACTUAL_COMPILER_OUTPUT); realOptionsMock = mockRealJsCompilerOptions(true); // force compiler to run realResultMock = mockRealJsResult(); compiler = newClosureJsCompiler(realCompMock, realOptionsMock, compilerMock, cacheMock); JsResponse actual = compiler.compile(jsUriMock, EXPORT_COMPILER_CONTENTS, EXTERN); assertTrue(actual.getErrors().get(0).contains(ERROR_NAME)); assertEquals(1, actual.getErrors().size()); }
@Test public void testCompile() throws Exception { JsResponse actual = compiler.compile(null, ImmutableList.of(JsContent.fromText(COMPILE_CONTENT, "js")), null); assertEquals(COMPILE_CONTENT, actual.toJsString()); assertEquals(0, actual.getErrors().size()); }
@Ignore("This class was not being run and when I ran it this test did not pass. Not familiar enough to enable it.") @Test public void testCompileErrorDeb() throws Exception { jsUriMock = mockJsUri(true); // debug realCompMock = mockRealJsCompiler(JS_ERROR, realResultMock, ACTUAL_COMPILER_OUTPUT); realOptionsMock = mockRealJsCompilerOptions(true); // force compiler to run realResultMock = mockRealJsResult(); compiler = newClosureJsCompiler(realCompMock, realOptionsMock, compilerMock, cacheMock); JsResponse actual = compiler.compile(jsUriMock, EXPORT_COMPILER_CONTENTS, EXTERN); assertTrue(actual.getErrors().get(0).contains(ERROR_NAME)); assertEquals(1, actual.getErrors().size()); }
@Test public void testCompile() throws Exception { JsResponse actual = compiler.compile(null, ImmutableList.of(JsContent.fromText(COMPILE_CONTENT, "js")), null); assertEquals(COMPILE_CONTENT, actual.toJsString()); assertEquals(0, actual.getErrors().size()); }
@Ignore("This class was not being run and when I ran it this test did not pass. Not familiar enough to enable it.") @SuppressWarnings("unchecked") @Test public void testCompileSuccessOptWithProfiling() throws Exception { jsUriMock = mockJsUri(false); // opt realOptionsMock = new CompilerOptions(); realOptionsMock.enableExternExports(false); realOptionsMock.sourceMapOutputPath = "test.out"; realOptionsMock.sourceMapFormat = Format.V2; realOptionsMock.sourceMapDetailLevel = SourceMap.DetailLevel.ALL; realOptionsMock.ideMode = false; realOptionsMock.convertToDottedProperties = true; for (Map.Entry<String, String> compilerTest : COMPILER_IO.entrySet()) { List<JsContent> content = newJsContents(compilerTest.getKey()); exportResponseMock = mockJsResponse(compilerTest.getKey()); compilerMock = mockDefaultJsCompiler(exportResponseMock, content); compiler = newProfilingClosureJsCompiler(realOptionsMock, compilerMock, cacheMock); JsResponse actual = compiler.compile(jsUriMock, content, EXTERN); assertEquals(compilerTest.getValue(), actual.toJsString()); assertTrue(actual.getErrors().isEmpty()); } }
@Ignore("This class was not being run and when I ran it this test did not pass. Not familiar enough to enable it.") @SuppressWarnings("unchecked") @Test public void testCompileSuccessOptWithProfiling() throws Exception { jsUriMock = mockJsUri(false); // opt realOptionsMock = new CompilerOptions(); realOptionsMock.enableExternExports(false); realOptionsMock.sourceMapOutputPath = "test.out"; realOptionsMock.sourceMapFormat = Format.V2; realOptionsMock.sourceMapDetailLevel = SourceMap.DetailLevel.ALL; realOptionsMock.ideMode = false; realOptionsMock.convertToDottedProperties = true; for (Map.Entry<String, String> compilerTest : COMPILER_IO.entrySet()) { List<JsContent> content = newJsContents(compilerTest.getKey()); exportResponseMock = mockJsResponse(compilerTest.getKey()); compilerMock = mockDefaultJsCompiler(exportResponseMock, content); compiler = newProfilingClosureJsCompiler(realOptionsMock, compilerMock, cacheMock); JsResponse actual = compiler.compile(jsUriMock, content, EXTERN); assertEquals(compilerTest.getValue(), actual.toJsString()); assertTrue(actual.getErrors().isEmpty()); } }
@Test public void testCompileSuccessOpt() throws Exception { jsUriMock = mockJsUri(false); // opt realResultMock = mockRealJsResult(); realCompMock = mockRealJsCompiler(null, realResultMock, ACTUAL_COMPILER_OUTPUT); realOptionsMock = mockRealJsCompilerOptions(false); compiler = newClosureJsCompiler(realCompMock, realOptionsMock, compilerMock, cacheMock); JsResponse actual = compiler.compile(jsUriMock, EXPORT_COMPILER_CONTENTS, EXTERN); assertEquals(ACTUAL_COMPILER_OUTPUT, actual.toJsString()); assertTrue(actual.getErrors().isEmpty()); }
@Test public void testCompileSuccessDeb() throws Exception { jsUriMock = mockJsUri(true); // debug realResultMock = mockRealJsResult(); realCompMock = mockRealJsCompiler(null, realResultMock, ACTUAL_COMPILER_OUTPUT); realOptionsMock = mockRealJsCompilerOptions(false); compiler = newClosureJsCompiler(realCompMock, realOptionsMock, compilerMock, cacheMock); JsResponse actual = compiler.compile(jsUriMock, EXPORT_COMPILER_CONTENTS, EXTERN); assertEquals(EXPORT_COMPILER_STRING, actual.toJsString()); assertTrue(actual.getErrors().isEmpty()); }
@Test public void testCompileSuccessOpt() throws Exception { jsUriMock = mockJsUri(false); // opt realResultMock = mockRealJsResult(); realCompMock = mockRealJsCompiler(null, realResultMock, ACTUAL_COMPILER_OUTPUT); realOptionsMock = mockRealJsCompilerOptions(false); compiler = newClosureJsCompiler(realCompMock, realOptionsMock, compilerMock, cacheMock); JsResponse actual = compiler.compile(jsUriMock, EXPORT_COMPILER_CONTENTS, EXTERN); assertEquals(ACTUAL_COMPILER_OUTPUT, actual.toJsString()); assertTrue(actual.getErrors().isEmpty()); }
@Test public void testCompileSuccessDeb() throws Exception { jsUriMock = mockJsUri(true); // debug realResultMock = mockRealJsResult(); realCompMock = mockRealJsCompiler(null, realResultMock, ACTUAL_COMPILER_OUTPUT); realOptionsMock = mockRealJsCompilerOptions(false); compiler = newClosureJsCompiler(realCompMock, realOptionsMock, compilerMock, cacheMock); JsResponse actual = compiler.compile(jsUriMock, EXPORT_COMPILER_CONTENTS, EXTERN); assertEquals(EXPORT_COMPILER_STRING, actual.toJsString()); assertTrue(actual.getErrors().isEmpty()); }
/** * Compile content in the inbound JsResponseBuilder. * TODO: Convert JsCompiler to take JsResponseBuilder directly rather than Iterable<JsContent> * @throws JsException */ public boolean process(JsRequest request, JsResponseBuilder builder) throws JsException { Iterable<JsContent> jsContents = builder.build().getAllJsContent(); for (JsContent jsc : jsContents) { FeatureBundle bundle = jsc.getFeatureBundle(); if (bundle != null) { builder.appendExterns(bundle.getApis(ApiDirective.Type.JS, true)); } } JsResponse result = compiler.compile(request.getJsUri(), jsContents, builder.build().getExterns()); builder.clearJs().appendAllJs(result.getAllJsContent()); builder.setStatusCode(result.getStatusCode()); builder.addErrors(result.getErrors()); int refresh = result.getCacheTtlSecs(); if (refresh > 0) { // Allow ttl overwrite by compiler builder.setCacheTtlSecs(refresh); } return true; }