use of com.facebook.buck.util.MockClassLoader in project buck by facebook.
the class Jsr199JavacIntegrationTest method shouldUseSpecifiedJavacJar.
@Test
public void shouldUseSpecifiedJavacJar() throws Exception {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
BuildRule rule = new FakeBuildRule("//:fake", pathResolver);
resolver.addToIndex(rule);
Path fakeJavacJar = Paths.get("ae036e57-77a7-4356-a79c-0f85b1a3290d", "fakeJavac.jar");
ExecutionContext executionContext = TestExecutionContext.newInstance();
MockClassLoader mockClassLoader = new MockClassLoader(ClassLoader.getSystemClassLoader(), ImmutableMap.of(JavacOptions.COM_SUN_TOOLS_JAVAC_API_JAVAC_TOOL, MockJavac.class));
executionContext.getClassLoaderCache().injectClassLoader(ClassLoader.getSystemClassLoader(), ImmutableList.of(fakeJavacJar.toUri().toURL()), mockClassLoader);
Jsr199Javac javac = createJavac(/* withSyntaxError */
false, Optional.of(fakeJavacJar));
JavacExecutionContext javacExecutionContext = JavacExecutionContext.of(new JavacEventSinkToBuckEventBusBridge(executionContext.getBuckEventBus()), executionContext.getStdErr(), executionContext.getClassLoaderCache(), executionContext.getObjectMapper(), executionContext.getVerbosity(), executionContext.getCellPathResolver(), executionContext.getJavaPackageFinder(), createProjectFilesystem(), NoOpClassUsageFileWriter.instance(), executionContext.getEnvironment(), executionContext.getProcessExecutor(), ImmutableList.of(fakeJavacJar), Optional.empty());
boolean caught = false;
try {
javac.buildWithClasspath(javacExecutionContext, BuildTargetFactory.newInstance("//some:example"), ImmutableList.of(), ImmutableList.of(), SOURCE_PATHS, pathToSrcsList, Optional.empty(), JavacOptions.AbiGenerationMode.CLASS);
fail("Did not expect compilation to succeed");
} catch (UnsupportedOperationException ex) {
if (ex.toString().contains("abcdef")) {
caught = true;
}
}
assertTrue("mock Java compiler should throw", caught);
}
Aggregations