@NonNull private List<ResourceSet> getConfiguredResourceSets(ResourcePreprocessor preprocessor) { List<ResourceSet> resourceSets = Lists.newArrayList(getInputResourceSets()); List<ResourceSet> generatedSets = Lists.newArrayListWithCapacity(resourceSets.size()); for (ResourceSet resourceSet : resourceSets) { resourceSet.setPreprocessor(preprocessor); ResourceSet generatedSet = new GeneratedResourceSet(resourceSet); resourceSet.setGeneratedSet(generatedSet); generatedSets.add(generatedSet); } // Put all generated sets at the start of the list. resourceSets.addAll(0, generatedSets); return resourceSets; }
private List<ResourceSet> getConfiguredResourceSets(ResourcePreprocessor preprocessor) { // it is possible that this get called twice in case the incremental run fails and reverts // back to full task run. Because the cached ResourceList is modified we don't want // to recompute this twice (plus, why recompute it twice anyway?) if (processedInputs == null) { processedInputs = computeResourceSetList(); List<ResourceSet> generatedSets = Lists.newArrayListWithCapacity(processedInputs.size()); for (ResourceSet resourceSet : processedInputs) { resourceSet.setPreprocessor(preprocessor); ResourceSet generatedSet = new GeneratedResourceSet(resourceSet); resourceSet.setGeneratedSet(generatedSet); generatedSets.add(generatedSet); } // We want to keep the order of the inputs. Given inputs: // (A, B, C, D) // We want to get: // (A-generated, A, B-generated, B, C-generated, C, D-generated, D). // Therefore, when later in {@link DataMerger} we look for sources going through the // list backwards, B-generated will take priority over A (but not B). // A real life use-case would be if an app module generated resource overrode a library // module generated resource (existing not in generated but bundled dir at this stage): // (lib, app debug, app main) // We will get: // (lib generated, lib, app debug generated, app debug, app main generated, app main) for (int i = 0; i < generatedSets.size(); ++i) { processedInputs.add(2 * i, generatedSets.get(i)); } } return processedInputs; }