@Test public void testUpdateWithFilesVsValues() throws Exception { File root = getIncMergeRoot("filesVsValues"); File fakeRoot = getMergedBlobFolder(root); ResourceMerger resourceMerger = new ResourceMerger(0); assertTrue(resourceMerger.loadFromBlob(fakeRoot, true )); checkSourceFolders(resourceMerger); List<ResourceSet> sets = resourceMerger.getDataSets(); assertEquals(1, sets.size()); RecordingLogger logger = new RecordingLogger(); ResourceSet mainSet = sets.get(0); File mainBase = new File(root, "main"); File mainValues = new File(mainBase, ResourceFolderType.VALUES.getName()); File mainLayout = new File(mainBase, ResourceFolderType.LAYOUT.getName()); File mainValuesTouched = new File(mainValues, "values.xml"); mainSet.updateWith(mainBase, mainValuesTouched, FileStatus.CHANGED, logger); checkLogger(logger); File mainLayoutNew = new File(mainLayout, "alias_replaced_by_file.xml"); mainSet.updateWith(mainBase, mainLayoutNew, FileStatus.NEW, logger); checkLogger(logger); File mainLayoutRemoved = new File(mainLayout, "file_replaced_by_alias.xml"); mainSet.updateWith(mainBase, mainLayoutRemoved, FileStatus.REMOVED, logger); checkLogger(logger); resourceMerger.validateDataSets(); ListMultimap<String, ResourceItem> mergedMap = resourceMerger.getDataMap(); List<ResourceItem> layoutMain = mergedMap.get("layout/main"); assertEquals(1, layoutMain.size()); assertTrue(layoutMain.get(0).isWritten()); assertFalse(layoutMain.get(0).isTouched()); assertFalse(layoutMain.get(0).isRemoved()); List<ResourceItem> layoutReplacedByAlias = mergedMap.get("layout/file_replaced_by_alias"); assertEquals(2, layoutReplacedByAlias.size()); ResourceItem replacedByAlias = layoutReplacedByAlias.get(0); assertTrue(replacedByAlias.isWritten()); assertFalse(replacedByAlias.isTouched()); assertTrue(replacedByAlias.isRemoved()); assertNull(replacedByAlias.getValue()); assertEquals("file_replaced_by_alias.xml", replacedByAlias.getSource().getFile().getName()); replacedByAlias = layoutReplacedByAlias.get(1); assertFalse(replacedByAlias.isWritten()); assertTrue(replacedByAlias.isTouched()); assertFalse(replacedByAlias.isRemoved()); assertNotNull(replacedByAlias.getValue()); assertEquals("values.xml", replacedByAlias.getSource().getFile().getName()); List<ResourceItem> layoutReplacedByFile = mergedMap.get("layout/alias_replaced_by_file"); assertEquals(2, layoutReplacedByFile.size()); ResourceItem replacedByFile = layoutReplacedByFile.get(0); assertTrue(replacedByFile.isWritten()); assertFalse(replacedByFile.isTouched()); assertTrue(replacedByFile.isRemoved()); assertNotNull(replacedByFile.getValue()); assertEquals("values.xml", replacedByFile.getSource().getFile().getName()); replacedByFile = layoutReplacedByFile.get(1); assertFalse(replacedByFile.isWritten()); assertTrue(replacedByFile.isTouched()); assertFalse(replacedByFile.isRemoved()); assertNull(replacedByFile.getValue()); assertEquals("alias_replaced_by_file.xml", replacedByFile.getSource().getFile().getName()); File resFolder = getFolderCopy(new File(root, "resOut")); MergedResourceWriter writer = getConsumer(resFolder); resourceMerger.mergeData(writer, false ); assertFalse(new File(resFolder, "layout" + File.separator + "file_replaced_by_alias.xml") .isFile()); assertTrue(new File(resFolder, "layout" + File.separator + "alias_replaced_by_file.xml") .isFile()); File valuesFile = new File(resFolder, "values" + File.separator + "values.xml"); assertTrue(valuesFile.isFile()); String content = Files.toString(valuesFile, Charsets.UTF_8); assertTrue(content.contains("name=\"file_replaced_by_alias\"")); assertFalse(content.contains("name=\"alias_replaced_by_file\"")); }
@Override public void mergeData(@NonNull MergeConsumer<ResourceItem> consumer, boolean doCleanUp) throws MergingException { clearFilterCache(); super.mergeData(consumer, doCleanUp); }
ResourceMerger extends DataMerger<ResourceItem, ResourceFile, ResourceSet> { @Override public void mergeData(@NonNull MergeConsumer<ResourceItem> consumer, boolean doCleanUp) throws MergingException { clearFilterCache(); super.mergeData(consumer, doCleanUp); } }
ResourceMerger extends DataMerger<ResourceItem, ResourceFile, ResourceSet> { @Override public void mergeData(@NonNull MergeConsumer<ResourceItem> consumer, boolean doCleanUp) throws MergingException { clearFilterCache(); super.mergeData(consumer, doCleanUp); } ResourceMerger(int minSdk); }
ResourceMerger extends DataMerger<ResourceItem, ResourceFile, ResourceSet> { @Override public void mergeData(@NonNull MergeConsumer<ResourceItem> consumer, boolean doCleanUp) throws MergingException { clearFilterCache(); super.mergeData(consumer, doCleanUp); } ResourceMerger(int minSdk); @Override void addDataSet(ResourceSet resourceSet); @Override void mergeData(@NonNull MergeConsumer<ResourceItem> consumer, boolean doCleanUp); }
ResourceMerger extends DataMerger<ResourceItem, ResourceFile, ResourceSet> { @Override public void mergeData(@NonNull MergeConsumer<ResourceItem> consumer, boolean doCleanUp) throws MergingException { clearFilterCache(); super.mergeData(consumer, doCleanUp); } ResourceMerger(int minSdk); @Override void addDataSet(ResourceSet resourceSet); @Override void mergeData(@NonNull MergeConsumer<ResourceItem> consumer, boolean doCleanUp);  }