Skip to content

Commit

Permalink
Fix bug where merge conflicts for resources defined in XML with equal…
Browse files Browse the repository at this point in the history
… values were being falsely logged during build as warnings

RELNOTES: none
PiperOrigin-RevId: 161723206
  • Loading branch information
Googler authored and laszlocsomor committed Jul 13, 2017
1 parent 60eb53b commit 106fa1e
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,39 @@ public boolean checkEquality(DataSource one, DataSource two) throws IOException
.build()));
}

@Test
public void mergeDirectConflictDuplicatedWithDifferentSources() throws Exception {
Path primaryRoot = fileSystem.getPath("primary");
Path directRoot = fileSystem.getPath("direct");

ParsedAndroidData transitiveDependency = ParsedAndroidDataBuilder.empty();

ParsedAndroidData directDependency =
ParsedAndroidDataBuilder.buildOn(directRoot, fqnFactory)
// Two string/exit will create conflict.
.overwritable(
xml("string/exit")
.source("values/strings.xml")
.value(SimpleXmlResourceValue.createWithValue(Type.STRING, "way out")),
xml("string/exit")
.source("values/more_strings.xml")
.value(SimpleXmlResourceValue.createWithValue(Type.STRING, "way out")),
xml("string/another_key")
.source("values/more_strings.xml")
.value(SimpleXmlResourceValue.createWithValue(Type.STRING, "another way out")))
.build();

UnvalidatedAndroidData primary =
AndroidDataBuilder.of(primaryRoot)
.createManifest("AndroidManifest.xml", "com.google.mergetest")
.buildUnvalidated();

AndroidDataMerger merger = AndroidDataMerger.createWithDefaults();
merger.merge(transitiveDependency, directDependency, primary, false);

assertThat(loggingHandler.warnings).isEmpty();
}

@Test
public void mergeDirectConflictWithPrimaryOverride() throws Exception {
Path primaryRoot = fileSystem.getPath("primary");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,4 +369,13 @@ public DataValue update(DataSource source) {
public String asConflictString() {
return source.asConflictString();
}

@Override
public boolean valueEquals(DataValue value) {
if (!(value instanceof DataResourceXml)) {
return false;
}
DataResourceXml other = (DataResourceXml) value;
return Objects.equals(xml, other.xml);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,10 @@ int serializeTo(

/** Provides a representation of the value suitable for a conflict message. */
String asConflictString();

/**
* Ignores metadata in the DataValue object and returns true if the value properties are
* equivalent to another given DataValue object
*/
boolean valueEquals(DataValue value);
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,9 @@ public DataValue update(DataSource source) {
public String asConflictString() {
return source.asConflictString();
}

@Override
public boolean valueEquals(DataValue value) {
return equals(value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ DataValue overwritten() {
}

boolean isValidWith(SourceChecker checker) throws IOException {
return !primary.equals(overwritten)
return !primary.valueEquals(overwritten)
&& !checker.checkEquality(primary.source(), overwritten.source());
}

Expand Down

0 comments on commit 106fa1e

Please sign in to comment.