Java Code Examples for com.android.ide.common.res2.ResourceMerger#addDataSet()

The following examples show how to use com.android.ide.common.res2.ResourceMerger#addDataSet() . 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: AARLibraries.java    From appinventor-extensions with Apache License 2.0 6 votes vote down vote up
/**
 * Merges the resources from all of the dependent AAR libraries into the main resource bundle for
 * the compiling app.
 *
 * @param outputDir the output directory to write the R.java files.
 * @param mainResDir the resource directory where the resource descriptors for the app reside.
 * @param cruncher configured PNG cruncher utility for reducing the size of PNG assets.
 * @return true if the merge was successful, otherwise false.
 */
public boolean mergeResources(File outputDir, File mainResDir, PngCruncher cruncher) {
  List<ResourceSet> resourceSets = getResourceSets();
  ResourceSet mainResSet = new ResourceSet("main");
  mainResSet.addSource(mainResDir);
  resourceSets.add(mainResSet);
  ResourceMerger merger = new ResourceMerger();

  try {
    for (ResourceSet resourceSet : resourceSets) {
      resourceSet.loadFromFiles(LOG);
      merger.addDataSet(resourceSet);
    }

    MergedResourceWriter writer = new MergedResourceWriter(outputDir, cruncher, false, false, null);
    writer.setInsertSourceMarkers(true);
    merger.mergeData(writer, false);
    return true;
  } catch(MergingException e) {
    e.printStackTrace();
    return false;
  }
}
 
Example 2
Source File: MergeAndroidResourceSourcesStep.java    From buck with Apache License 2.0 6 votes vote down vote up
@Override
public StepExecutionResult execute(ExecutionContext context) {
  ResourceMerger merger = new ResourceMerger(1);
  try {
    for (Path resPath : getResPaths()) {
      ResourceSet set = new ResourceSet(resPath.toString(), true);
      set.setDontNormalizeQualifiers(true);
      set.addSource(resPath.toFile());
      set.loadFromFiles(new ResourcesSetLoadLogger(context.getBuckEventBus()));
      merger.addDataSet(set);
    }
    MergedResourceWriter writer =
        MergedResourceWriter.createWriterWithoutPngCruncher(
            getOutFolderPath().toFile(),
            null /*publicFile*/,
            null /*blameLogFolder*/,
            new NoOpResourcePreprocessor(),
            getTmpFolderPath().toFile());
    merger.mergeData(writer, /* cleanUp */ false);
  } catch (MergingException e) {
    LOG.error(e, "Failed merging resources.");
    return StepExecutionResults.ERROR;
  }
  return StepExecutionResults.SUCCESS;
}
 
Example 3
Source File: MergeResources.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void doFullTaskAction() throws IOException {
    // this is full run, clean the previous output
    File destinationDir = getOutputDir();
    FileUtils.emptyFolder(destinationDir);

    List<ResourceSet> resourceSets = getConfiguredResourceSets();

    // create a new merger and populate it with the sets.
    ResourceMerger merger = new ResourceMerger();

    try {
        for (ResourceSet resourceSet : resourceSets) {
            resourceSet.loadFromFiles(getILogger());
            merger.addDataSet(resourceSet);
        }

        // get the merged set and write it down.
        MergedResourceWriter writer = new MergedResourceWriter(
                destinationDir, getCruncher(),
                getCrunchPng(), getProcess9Patch(), getPublicFile(), preprocessor);
        writer.setInsertSourceMarkers(getInsertSourceMarkers());

        merger.mergeData(writer, false /*doCleanUp*/);

        // No exception? Write the known state.
        merger.writeBlobTo(getIncrementalFolder(), writer);
        throw new StopExecutionException("Stop for now.");
    } catch (MergingException e) {
        System.out.println(e.getMessage());
        merger.cleanBlob(getIncrementalFolder());
        throw new ResourceException(e.getMessage(), e);
    }
}
 
Example 4
Source File: MergeResources.java    From javafxmobile-plugin with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
protected void doFullTaskAction() throws IOException {
    ResourcePreprocessor preprocessor = getPreprocessor();

    // this is full run, clean the previous output
    File destinationDir = getOutputDir();
    FileUtils.cleanOutputDir(destinationDir);

    List<ResourceSet> resourceSets = getConfiguredResourceSets(preprocessor);

    // create a new merger and populate it with the sets.
    ResourceMerger merger = new ResourceMerger(minSdk);
    MergingLog mergingLog =
            getBlameLogFolder() != null ? new MergingLog(getBlameLogFolder()) : null;

    try (QueueableResourceCompiler resourceCompiler =
                 processResources
                         ? makeAapt(
                         buildToolInfo.get(),
                         aaptGeneration,
                         getBuilder(),
                         crunchPng,
                         mergingLog)
                         : QueueableResourceCompiler.NONE) {

        for (ResourceSet resourceSet : resourceSets) {
            resourceSet.loadFromFiles(getILogger());
            merger.addDataSet(resourceSet);
        }

        MergedResourceWriter writer =
                new MergedResourceWriter(
                        workerExecutorFacade,
                        destinationDir,
                        getPublicFile(),
                        mergingLog,
                        preprocessor,
                        resourceCompiler,
                        getIncrementalFolder(),
                        null,
                        null,
                        false,
                        getCrunchPng());

        merger.mergeData(writer, false /*doCleanUp*/);

        // No exception? Write the known state.
        merger.writeBlobTo(getIncrementalFolder(), writer, false);
    } catch (MergingException e) {
        System.out.println(e.getMessage());
        merger.cleanBlob(getIncrementalFolder());
        throw new ResourceException(e.getMessage(), e);
    } finally {
        cleanup();
    }
}