@Test public void testUpdateWithBasicValues() throws Exception { File root = getIncMergeRoot("basicValues"); 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 mainValues = new File(mainBase, "values"); File mainValuesEn = new File(mainBase, "values-en"); File mainValuesTouched = new File(mainValues, "values.xml"); mainSet.updateWith(mainBase, mainValuesTouched, FileStatus.CHANGED, logger); checkLogger(logger); File mainValuesEnRemoved = new File(mainValuesEn, "values.xml"); mainSet.updateWith(mainBase, mainValuesEnRemoved, FileStatus.REMOVED, logger); checkLogger(logger); ResourceSet overlaySet = sets.get(1); File overlayBase = new File(root, "overlay"); File overlayValues = new File(overlayBase, "values"); File overlayValuesFr = new File(overlayBase, "values-fr"); File overlayValuesNew = new File(overlayValues, "values.xml"); overlaySet.updateWith(overlayBase, overlayValuesNew, FileStatus.NEW, logger); checkLogger(logger); File overlayValuesFrNew = new File(overlayValuesFr, "values.xml"); overlaySet.updateWith(overlayBase, overlayValuesFrNew, FileStatus.NEW, logger); checkLogger(logger); resourceMerger.validateDataSets(); ListMultimap<String, ResourceItem> mergedMap = resourceMerger.getDataMap(); List<ResourceItem> valuesUntouched = mergedMap.get("string/untouched"); assertEquals(1, valuesUntouched.size()); assertTrue(valuesUntouched.get(0).isWritten()); assertFalse(valuesUntouched.get(0).isTouched()); assertFalse(valuesUntouched.get(0).isRemoved()); List<ResourceItem> valuesTouched = mergedMap.get("string/touched"); assertEquals(1, valuesTouched.size()); assertTrue(valuesTouched.get(0).isWritten()); assertTrue(valuesTouched.get(0).isTouched()); assertFalse(valuesTouched.get(0).isRemoved()); List<ResourceItem> valuesRemoved = mergedMap.get("string/removed"); assertEquals(1, valuesRemoved.size()); assertTrue(valuesRemoved.get(0).isWritten()); assertTrue(valuesRemoved.get(0).isRemoved()); valuesRemoved = mergedMap.get("string-en/removed"); assertEquals(1, valuesRemoved.size()); assertTrue(valuesRemoved.get(0).isWritten()); assertTrue(valuesRemoved.get(0).isRemoved()); List<ResourceItem> valuesNewOverlay = mergedMap.get("string/new_overlay"); assertEquals(2, valuesNewOverlay.size()); ResourceItem newOverlay = valuesNewOverlay.get(1); assertFalse(newOverlay.isWritten()); assertTrue(newOverlay.isTouched()); List<ResourceItem> valuesFrNewAlternate = mergedMap.get("string-fr/new_alternate"); assertEquals(1, valuesFrNewAlternate.size()); ResourceItem newAlternate = valuesFrNewAlternate.get(0); assertFalse(newAlternate.isWritten()); assertTrue(newAlternate.isTouched()); File resFolder = getFolderCopy(new File(root, "resOut")); File mergeLogFolder = TestUtils.createTempDirDeletedOnExit(); mergeLogFolder.deleteOnExit(); MergedResourceWriter writer = MergedResourceWriter.createWriterWithoutPngCruncher( resFolder, null , mergeLogFolder, mPreprocessor, mTemporaryFolder.getRoot()); resourceMerger.mergeData(writer, false ); Map<String, String> map = quickStringOnlyValueFileParser( new File(resFolder, "values" + File.separator + "values.xml")); assertEquals("untouched", map.get("untouched")); assertEquals("touched", map.get("touched")); assertEquals("new_overlay", map.get("new_overlay")); map = quickStringOnlyValueFileParser( new File(resFolder, "values-fr" + File.separator + "values-fr.xml")); assertEquals("new_alternate", map.get("new_alternate")); assertFalse(new File(resFolder, "values-en" + File.separator + "values-en.xml").isFile()); MergingLog mergingLog = new MergingLog(mergeLogFolder); SourceFile destFile = mergingLog.destinationFor( new SourceFile(overlayValuesNew)); SourceFilePosition original = mergingLog.find( new SourceFilePosition(destFile, new SourcePosition(2,5,-1))); assertEquals(new SourcePosition(2, 4, 55, 2, 51, 102), original.getPosition()); assertTrue(original.getFile().getSourceFile().getAbsolutePath().endsWith( "basicValues/overlay/values/values.xml".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);  }