Java Code Examples for com.android.dx.dex.code.PositionList#LINES

The following examples show how to use com.android.dx.dex.code.PositionList#LINES . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DexBuilderTest.java    From bazel with Apache License 2.0 5 votes vote down vote up
@Test
public void testBuildDexArchive() throws Exception {
  DexBuilder.Options options = new DexBuilder.Options();
  // Use Jar file that has this test in it as the input Jar
  Runfiles runfiles = Runfiles.create();
  options.inputJar = Paths.get(runfiles.rlocation(System.getProperty("testinputjar")));
  options.outputZip =
      FileSystems.getDefault().getPath(System.getenv("TEST_TMPDIR"), "dex_builder_test.zip");
  options.maxThreads = 1;
  Dexing.DexingOptions dexingOptions = new Dexing.DexingOptions();
  dexingOptions.optimize = true;
  dexingOptions.positionInfo = PositionList.LINES;
  DexBuilder.buildDexArchive(options, new Dexing(dexingOptions));
  assertThat(options.outputZip.toFile().exists()).isTrue();

  HashSet<String> files = new HashSet<>();
  try (ZipFile zip = new ZipFile(options.outputZip.toFile())) {
    Enumeration<? extends ZipEntry> entries = zip.entries();
    while (entries.hasMoreElements()) {
      ZipEntry entry = entries.nextElement();
      files.add(entry.getName());
      if (entry.getName().endsWith(".dex")) {
        Dex dex = new Dex(zip.getInputStream(entry));
        assertWithMessage(entry.getName()).that(dex.classDefs()).hasSize(1);
      } else if (entry.getName().endsWith("/testresource.txt")) {
        byte[] content = ByteStreams.toByteArray(zip.getInputStream(entry));
        assertWithMessage(entry.getName()).that(content).isEqualTo("test".getBytes(UTF_8));
      }
    }
  }
  // Make sure this test is in the Zip file, which also means we parsed its dex code above
  assertThat(files).contains(getClass().getName().replace('.', '/') + ".class.dex");
  // Make sure test resource is in the Zip file, which also means it had the expected content
  assertThat(files)
      .contains(getClass().getPackage().getName().replace('.', '/') + "/testresource.txt");
}
 
Example 2
Source File: DexFileMergerTest.java    From bazel with Apache License 2.0 5 votes vote down vote up
private Path buildDexArchive(Path inputJar, String outputZip) throws Exception {
  DexBuilder.Options options = new DexBuilder.Options();
  options.inputJar = inputJar;
  options.outputZip = FileSystems.getDefault().getPath(System.getenv("TEST_TMPDIR"), outputZip);
  options.maxThreads = 1;
  Dexing.DexingOptions dexingOptions = new Dexing.DexingOptions();
  dexingOptions.optimize = true;
  dexingOptions.positionInfo = PositionList.LINES;
  DexBuilder.buildDexArchive(options, new Dexing(new DxContext(), dexingOptions));
  return options.outputZip;
}
 
Example 3
Source File: DexFileSplitterTest.java    From bazel with Apache License 2.0 5 votes vote down vote up
private Path buildDexArchive(Path inputJar, String outputZip) throws Exception {
  DexBuilder.Options options = new DexBuilder.Options();
  // Use Jar file that has this test in it as the input Jar
  options.inputJar = inputJar;
  options.outputZip =
      FileSystems.getDefault().getPath(System.getenv("TEST_TMPDIR"), outputZip);
  options.maxThreads = 1;
  Dexing.DexingOptions dexingOptions = new Dexing.DexingOptions();
  dexingOptions.optimize = true;
  dexingOptions.positionInfo = PositionList.LINES;
  DexBuilder.buildDexArchive(options, new Dexing(new DxContext(), dexingOptions));
  return options.outputZip;
}