Search in sources :

Example 1 with ProjectWorkspace

use of com.facebook.buck.testutil.integration.ProjectWorkspace in project buck by facebook.

the class AarWithLibsIntegrationTest method testLibsInAarAreIncludedInApk.

@Test
public void testLibsInAarAreIncludedInApk() throws IOException {
    AssumeAndroidPlatform.assumeSdkIsAvailable();
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "android_project", tmp);
    workspace.setUp();
    // More importantly, the content of the libs/ should end up in the .apk of an android_binary()
    // that transitively includes //:aar, but this is easier to test.
    Path output = workspace.buildAndReturnOutput("//java/com/example/aar:extract-classes-dex");
    String smali = new String(Files.readAllBytes(output), UTF_8);
    String primaryClass = MorePaths.pathWithPlatformSeparators("com/example/PrimaryClass.smali");
    String dependency = MorePaths.pathWithPlatformSeparators("com/example/dependency/Dependency.smali");
    assertThat("A class from the classes.jar in the .aar should make it into the APK.", smali, containsString(primaryClass));
    assertThat("A class from a jar in the libs directory in the .aar should make it into the APK.", smali, containsString(dependency));
}
Also used : Path(java.nio.file.Path) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 2 with ProjectWorkspace

use of com.facebook.buck.testutil.integration.ProjectWorkspace in project buck by facebook.

the class AndroidBuildConfigIntegrationTest method testBuildConfigWithValuesFile.

@Test
public void testBuildConfigWithValuesFile() throws IOException {
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "build_config", tmp);
    workspace.setUp();
    workspace.runBuckCommand("run", "//:main_values_file_test").assertSuccess();
}
Also used : ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) Test(org.junit.Test)

Example 3 with ProjectWorkspace

use of com.facebook.buck.testutil.integration.ProjectWorkspace in project buck by facebook.

the class AndroidAarIntegrationTest method testCxxLibraryDependent.

@Test
public void testCxxLibraryDependent() throws IOException {
    AssumeAndroidPlatform.assumeNdkIsAvailable();
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "android_aar_native_deps/cxx_deps", tmp);
    workspace.setUp();
    String target = "//:app";
    workspace.runBuckBuild(target).assertSuccess();
    Path aar = workspace.getPath(BuildTargets.getGenPath(filesystem, BuildTargetFactory.newInstance(target), AndroidAar.AAR_FORMAT));
    ZipInspector zipInspector = new ZipInspector(aar);
    zipInspector.assertFileExists("AndroidManifest.xml");
    zipInspector.assertFileExists("classes.jar");
    zipInspector.assertFileExists("R.txt");
    zipInspector.assertFileExists("res/");
    zipInspector.assertFileExists("jni/armeabi/libdep.so");
    zipInspector.assertFileExists("jni/armeabi/libnative.so");
    zipInspector.assertFileExists("jni/armeabi-v7a/libdep.so");
    zipInspector.assertFileExists("jni/armeabi-v7a/libnative.so");
    zipInspector.assertFileExists("jni/x86/libdep.so");
    zipInspector.assertFileExists("jni/x86/libnative.so");
}
Also used : Path(java.nio.file.Path) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) ZipInspector(com.facebook.buck.testutil.integration.ZipInspector) Test(org.junit.Test)

Example 4 with ProjectWorkspace

use of com.facebook.buck.testutil.integration.ProjectWorkspace in project buck by facebook.

the class AndroidAarIntegrationTest method testBuildAndroidAar.

@Test
public void testBuildAndroidAar() throws IOException {
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "android_aar_build/caseA", tmp);
    workspace.setUp();
    String target = "//:app";
    workspace.runBuckBuild(target).assertSuccess();
    Path aar = workspace.getPath(BuildTargets.getGenPath(filesystem, BuildTargetFactory.newInstance(target), AndroidAar.AAR_FORMAT));
    ZipInspector zipInspector = new ZipInspector(aar);
    zipInspector.assertFileExists("AndroidManifest.xml");
    zipInspector.assertFileExists("classes.jar");
    zipInspector.assertFileExists("R.txt");
    zipInspector.assertFileExists("assets/a.txt");
    zipInspector.assertFileExists("assets/b.txt");
    zipInspector.assertFileExists("res/raw/helloworld.txt");
    zipInspector.assertFileExists("res/values/values.xml");
    zipInspector.assertFileContents("res/values/values.xml", workspace.getFileContents("res/values/A.xml").trim());
    Path contents = tmp.getRoot().resolve("aar-contents");
    Unzip.extractZipFile(aar, contents, Unzip.ExistingFileMode.OVERWRITE);
    try (JarFile classes = new JarFile(contents.resolve("classes.jar").toFile())) {
        assertThat(classes.getJarEntry("com/example/HelloWorld.class"), Matchers.notNullValue());
    }
}
Also used : Path(java.nio.file.Path) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) ZipInspector(com.facebook.buck.testutil.integration.ZipInspector) JarFile(java.util.jar.JarFile) Test(org.junit.Test)

Example 5 with ProjectWorkspace

use of com.facebook.buck.testutil.integration.ProjectWorkspace in project buck by facebook.

the class AndroidAarIntegrationTest method testResultIsRecorded.

@Test
public void testResultIsRecorded() throws IOException, InterruptedException {
    AssumeAndroidPlatform.assumeNdkIsAvailable();
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "android_project", tmp);
    workspace.setUp();
    workspace.enableDirCache();
    workspace.runBuckBuild("//apps/sample:nearly_empty_aar").assertSuccess();
    workspace.runBuckCommand("clean");
    Path result = workspace.buildAndReturnOutput("//apps/sample:nearly_empty_aar");
    assertThat(workspace.asCell().getFilesystem().exists(result), Matchers.is(true));
}
Also used : Path(java.nio.file.Path) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) Test(org.junit.Test)

Aggregations

ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)747 Test (org.junit.Test)726 Path (java.nio.file.Path)219 BuildTarget (com.facebook.buck.model.BuildTarget)177 ProcessResult (com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult)127 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)89 Matchers.containsString (org.hamcrest.Matchers.containsString)50 BuckBuildLog (com.facebook.buck.testutil.integration.BuckBuildLog)47 ProcessExecutor (com.facebook.buck.util.ProcessExecutor)35 ZipInspector (com.facebook.buck.testutil.integration.ZipInspector)21 HumanReadableException (com.facebook.buck.util.HumanReadableException)14 OcamlRuleBuilder.createStaticLibraryBuildTarget (com.facebook.buck.ocaml.OcamlRuleBuilder.createStaticLibraryBuildTarget)13 TestConsole (com.facebook.buck.testutil.TestConsole)12 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)10 DefaultProcessExecutor (com.facebook.buck.util.DefaultProcessExecutor)10 Cell (com.facebook.buck.rules.Cell)9 TestContext (com.facebook.buck.testutil.integration.TestContext)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)9 MappedByteBuffer (java.nio.MappedByteBuffer)9 FileChannel (java.nio.channels.FileChannel)9