@Test public void testUpdateWithBasicFiles() throws Exception { File root = getIncMergeRoot("basicFiles"); File fakeRoot = getMergedBlobFolder(root); ResourceMerger resourceMerger = new ResourceMerger(0); assertTrue(resourceMerger.loadFromBlob(fakeRoot, true )); checkSourceFolders(resourceMerger); List<ResourceSet> sets = resourceMerger.getDataSets(); assertEquals(2, sets.size()); RecordingLogger logger = new RecordingLogger(); ResourceSet mainSet = sets.get(0); File mainBase = new File(root, "main"); File mainDrawable = new File(mainBase, "drawable"); File mainDrawableLdpi = new File(mainBase, "drawable-ldpi"); File mainDrawableTouched = new File(mainDrawable, "touched.png"); mainSet.updateWith(mainBase, mainDrawableTouched, FileStatus.CHANGED, logger); checkLogger(logger); File mainDrawableRemoved = new File(mainDrawable, "removed.png"); mainSet.updateWith(mainBase, mainDrawableRemoved, FileStatus.REMOVED, logger); checkLogger(logger); File mainDrawableLdpiRemoved = new File(mainDrawableLdpi, "removed.png"); mainSet.updateWith(mainBase, mainDrawableLdpiRemoved, FileStatus.REMOVED, logger); checkLogger(logger); ResourceSet overlaySet = sets.get(1); File overlayBase = new File(root, "overlay"); File overlayDrawable = new File(overlayBase, "drawable"); File overlayDrawableHdpi = new File(overlayBase, "drawable-hdpi"); File overlayDrawableNewOverlay = new File(overlayDrawable, "new_overlay.png"); overlaySet.updateWith(overlayBase, overlayDrawableNewOverlay, FileStatus.NEW, logger); checkLogger(logger); File overlayDrawableRemovedOverlay = new File(overlayDrawable, "removed_overlay.png"); overlaySet.updateWith(overlayBase, overlayDrawableRemovedOverlay, FileStatus.REMOVED, logger); checkLogger(logger); File overlayDrawableHdpiNewAlternate = new File(overlayDrawableHdpi, "new_alternate.png"); overlaySet.updateWith(overlayBase, overlayDrawableHdpiNewAlternate, FileStatus.NEW, logger); checkLogger(logger); resourceMerger.validateDataSets(); ListMultimap<String, ResourceItem> mergedMap = resourceMerger.getDataMap(); List<ResourceItem> drawableUntouched = mergedMap.get("drawable/untouched"); assertEquals(1, drawableUntouched.size()); assertTrue(drawableUntouched.get(0).isWritten()); assertFalse(drawableUntouched.get(0).isTouched()); assertFalse(drawableUntouched.get(0).isRemoved()); List<ResourceItem> drawableTouched = mergedMap.get("drawable/touched"); assertEquals(1, drawableTouched.size()); assertTrue(drawableTouched.get(0).isWritten()); assertTrue(drawableTouched.get(0).isTouched()); assertFalse(drawableTouched.get(0).isRemoved()); List<ResourceItem> drawableRemoved = mergedMap.get("drawable/removed"); assertEquals(1, drawableRemoved.size()); assertTrue(drawableRemoved.get(0).isWritten()); assertTrue(drawableRemoved.get(0).isRemoved()); List<ResourceItem> drawableNewOverlay = mergedMap.get("drawable/new_overlay"); assertEquals(2, drawableNewOverlay.size()); ResourceItem newOverlay = drawableNewOverlay.get(1); assertEquals(overlayDrawableNewOverlay, newOverlay.getSource().getFile()); assertFalse(newOverlay.isWritten()); assertTrue(newOverlay.isTouched()); List<ResourceItem> drawableHdpiNewAlternate = mergedMap.get("drawable-hdpi-v4/new_alternate"); assertEquals(1, drawableHdpiNewAlternate.size()); ResourceItem newAlternate = drawableHdpiNewAlternate.get(0); assertEquals(overlayDrawableHdpiNewAlternate, newAlternate.getSource().getFile()); assertFalse(newAlternate.isWritten()); assertTrue(newAlternate.isTouched()); File resFolder = getFolderCopy(new File(root, "resOut")); resFolder.deleteOnExit(); File mergeLogFolder = TestUtils.createTempDirDeletedOnExit(); mergeLogFolder.deleteOnExit(); MergedResourceWriter writer = MergedResourceWriter.createWriterWithoutPngCruncher( resFolder, null , mergeLogFolder, mPreprocessor, mTemporaryFolder.getRoot()); resourceMerger.mergeData(writer, false ); checkImageColor(new File(resFolder, "drawable" + File.separator + "touched.png"), (int) 0xFF00FF00); checkImageColor(new File(resFolder, "drawable" + File.separator + "untouched.png"), (int) 0xFF00FF00); checkImageColor(new File(resFolder, "drawable" + File.separator + "new_overlay.png"), (int) 0xFF00FF00); checkImageColor(new File(resFolder, "drawable" + File.separator + "removed_overlay.png"), (int) 0xFF00FF00); checkImageColor(new File(resFolder, "drawable-hdpi-v4" + File.separator + "new_alternate.png"), (int) 0xFF00FF00); assertFalse(new File(resFolder, "drawable-ldpi-v4" + File.separator + "removed.png").isFile()); MergingLog mergingLog = new MergingLog(mergeLogFolder); SourceFile original = mergingLog.find( new SourceFile(new File(resFolder, "drawable" + File.separator + "touched.png"))); assertTrue(original.getSourceFile().getAbsolutePath().endsWith( "basicFiles/main/drawable/touched.png".replace('/', File.separatorChar))); }
@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);  }