Ejemplo n.º 1
0
  @Test
  public void testManifestParsingAndWriting() {
    try {

      InputStream manifestStream =
          this.getClass().getClassLoader().getResourceAsStream("AndroidManifest.xml");
      String manifestString = IOUtils.toString(manifestStream);
      Manifest manifest =
          manifestSerializer.readManifest(new ByteArrayInputStream(manifestString.getBytes()));

      assertNotNull(manifest);
      assertEquals("android.permission.VIBRATE", manifest.getUsesPermissions().get(0).getName());

      ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

      manifestSerializer.writeManifest(manifest, outputStream);

      String output = IOUtils.toString(new ByteArrayInputStream(outputStream.toByteArray()));

      assertEquals(formatWhitespace(manifestString), formatWhitespace(output));

    } catch (IOException e) {
      e.printStackTrace();
    }
  }
  @Override
  public boolean process(
      Set<? extends TypeElement> typeElements, RoundEnvironment roundEnvironment) {

    long start = System.currentTimeMillis();

    // setup transfuse processor with manifest and R classes
    File manifestFile = manifestLocator.findManifest();
    Manifest manifest = manifestParser.readManifest(manifestFile);

    RResourceComposite r =
        new RResourceComposite(
            buildR(rBuilder, manifest.getApplicationPackage() + ".R"),
            buildR(rBuilder, "android.R"));

    configurationScope.enter();

    configurationScope.seed(
        ScopeKey.of(File.class)
            .annotatedBy("@javax.inject.Named(value=" + TransfuseAndroidModule.MANIFEST_FILE + ")"),
        manifestFile);
    configurationScope.seed(ScopeKey.of(RResource.class), r);
    configurationScope.seed(
        ScopeKey.of(Manifest.class)
            .annotatedBy(
                "@javax.inject.Named(value=" + TransfuseAndroidModule.ORIGINAL_MANIFEST + ")"),
        manifest);

    TransfuseProcessor transfuseProcessor = processorProvider.get();

    if (!baseModuleConfiguration) {
      transfuseProcessor.submit(
          TransfuseModule.class,
          reloadableASTElementFactory.buildProviders(
              Collections.singleton(elements.getTypeElement(APIModule.class.getName()))));
      baseModuleConfiguration = true;
    }

    transfuseProcessor.submit(
        Application.class, buildASTCollection(roundEnvironment, Application.class));
    transfuseProcessor.submit(
        TransfuseModule.class, buildASTCollection(roundEnvironment, TransfuseModule.class));
    transfuseProcessor.submit(
        ImplementedBy.class, buildASTCollection(roundEnvironment, ImplementedBy.class));
    transfuseProcessor.submit(Factory.class, buildASTCollection(roundEnvironment, Factory.class));
    transfuseProcessor.submit(Activity.class, buildASTCollection(roundEnvironment, Activity.class));
    transfuseProcessor.submit(
        BroadcastReceiver.class, buildASTCollection(roundEnvironment, BroadcastReceiver.class));
    transfuseProcessor.submit(Service.class, buildASTCollection(roundEnvironment, Service.class));
    transfuseProcessor.submit(Fragment.class, buildASTCollection(roundEnvironment, Fragment.class));

    transfuseProcessor.execute();

    if (roundEnvironment.processingOver()) {
      transfuseProcessor.checkForErrors();
    }

    logger.info("Transfuse took " + (System.currentTimeMillis() - start) + "ms to process");

    configurationScope.exit();

    return true;
  }