Java Code Examples for com.android.ide.common.res2.ResourceSet#setPreprocessor()
The following examples show how to use
com.android.ide.common.res2.ResourceSet#setPreprocessor() .
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: MergeResources.java From javaide with GNU General Public License v3.0 | 6 votes |
@NonNull private List<ResourceSet> getConfiguredResourceSets() { List<ResourceSet> resourceSets = Lists.newArrayList(getInputResourceSets()); List<ResourceSet> generatedSets = Lists.newArrayListWithCapacity(resourceSets.size()); for (ResourceSet resourceSet : resourceSets) { resourceSet.setNormalizeResources(normalizeResources); 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; }
Example 2
Source File: MergeResources.java From javafxmobile-plugin with BSD 3-Clause "New" or "Revised" License | 5 votes |
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; }
Example 3
Source File: MergeResources.java From javafxmobile-plugin with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override protected void doIncrementalTaskAction(Map<File, FileStatus> changedInputs) throws IOException { ResourcePreprocessor preprocessor = getPreprocessor(); // create a merger and load the known state. ResourceMerger merger = new ResourceMerger(minSdk); try { if (!merger.loadFromBlob(getIncrementalFolder(), true /*incrementalState*/)) { doFullTaskAction(); return; } for (ResourceSet resourceSet : merger.getDataSets()) { resourceSet.setPreprocessor(preprocessor); } List<ResourceSet> resourceSets = getConfiguredResourceSets(preprocessor); // compare the known state to the current sets to detect incompatibility. // This is in case there's a change that's too hard to do incrementally. In this case // we'll simply revert to full build. if (!merger.checkValidUpdate(resourceSets)) { getLogger().info("Changed Resource sets: full task run!"); doFullTaskAction(); return; } // The incremental process is the following: // Loop on all the changed files, find which ResourceSet it belongs to, then ask // the resource set to update itself with the new file. for (Map.Entry<File, FileStatus> entry : changedInputs.entrySet()) { File changedFile = entry.getKey(); merger.findDataSetContaining(changedFile, fileValidity); if (fileValidity.getStatus() == FileValidity.FileStatus.UNKNOWN_FILE) { doFullTaskAction(); return; } else if (fileValidity.getStatus() == FileValidity.FileStatus.VALID_FILE) { if (!fileValidity.getDataSet().updateWith( fileValidity.getSourceFile(), changedFile, entry.getValue(), getILogger())) { getLogger().info( String.format("Failed to process %s event! Full task run", entry.getValue())); doFullTaskAction(); return; } } } MergingLog mergingLog = getBlameLogFolder() != null ? new MergingLog(getBlameLogFolder()) : null; try (QueueableResourceCompiler resourceCompiler = processResources ? makeAapt( buildToolInfo.get(), aaptGeneration, getBuilder(), crunchPng, mergingLog) : QueueableResourceCompiler.NONE) { MergedResourceWriter writer = new MergedResourceWriter( workerExecutorFacade, getOutputDir(), 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) { merger.cleanBlob(getIncrementalFolder()); throw new ResourceException(e.getMessage(), e); } finally { cleanup(); } }