Skip to content

Commit

Permalink
Automated rollback of commit 3181c2f1362622985aca24747ed9512573d25dc0.
Browse files Browse the repository at this point in the history
RELNOTES: None
PiperOrigin-RevId: 174502289
  • Loading branch information
corbinrsmith-work authored and damienmg committed Nov 6, 2017
1 parent f675cb7 commit c28b4ce
Show file tree
Hide file tree
Showing 6 changed files with 194 additions and 126 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.jimfs.Jimfs;
import com.google.common.truth.Subject;
import com.google.common.truth.FailureStrategy;
import com.google.common.truth.SubjectFactory;
import com.google.devtools.build.android.AndroidDataBuilder.ResourceType;
import com.google.devtools.build.android.AndroidDataMerger.MergeConflictException;
import com.google.devtools.build.android.AndroidDataMerger.SourceChecker;
Expand Down Expand Up @@ -179,7 +180,7 @@ public void mergeDirectAndTransitiveDeps() throws Exception {
file("layout/exit").root(directRoot).source("res/layout/exit.xml"))
.combining(
xml("id/exit")
.root(transitiveRoot)
.root(directRoot)
.source("values/ids.xml")
.value(IdXmlResourceValue.of()))
.build());
Expand Down Expand Up @@ -243,7 +244,7 @@ public void mergeWithOverwriteInTransitiveDeps() throws Exception {
file("layout/exit").root(directRoot).source("res/layout/exit.xml"))
.combining(
xml("id/exit")
.root(transitiveRoot)
.root(directRoot)
.source("values/ids.xml")
.value(IdXmlResourceValue.of()))
.build());
Expand Down Expand Up @@ -462,11 +463,6 @@ public void mergeTransitiveConflictWithPrimaryOverride() throws Exception {
Path primaryRoot = fileSystem.getPath("primary");
Path directRoot = fileSystem.getPath("direct");
Path transitiveRoot = fileSystem.getPath("transitive");
DataSource primaryStrings = DataSource.of(primaryRoot.resolve("res/values/strings.xml"));
DataSource transitive1String =
DataSource.of(transitiveRoot.resolve("1/res/values/strings.xml"));
DataSource transitive2String =
DataSource.of(transitiveRoot.resolve("2/res/values/strings.xml"));

ParsedAndroidData transitiveDependency =
ParsedAndroidDataBuilder.buildOn(transitiveRoot, fqnFactory)
Expand Down Expand Up @@ -502,7 +498,7 @@ public void mergeTransitiveConflictWithPrimaryOverride() throws Exception {
.overwritable(
xml("string/exit")
.root(primaryRoot)
.source(primaryStrings.overwrite(transitive1String, transitive2String))
.source("values/strings.xml")
.value(SimpleXmlResourceValue.createWithValue(Type.STRING, "way out")))
.build(),
ParsedAndroidDataBuilder.empty());
Expand Down Expand Up @@ -589,13 +585,13 @@ public void mergeDirectTransitivePrimaryConflictWithoutPrimaryOverride() throws
assertThat(loggingHandler.warnings)
.containsExactly(
MergeConflict.of(
fullyQualifiedName,
DataResourceXml.createWithNoNamespace(
primaryRoot.resolve("res/values/strings.xml"),
SimpleXmlResourceValue.createWithValue(Type.STRING, "no way out")),
DataResourceXml.createWithNoNamespace(
transitiveRoot.resolve("res/values/strings.xml"),
SimpleXmlResourceValue.createWithValue(Type.STRING, "wrong way out")))
fullyQualifiedName,
DataResourceXml.createWithNoNamespace(
directRoot.resolve("res/values/strings.xml"),
SimpleXmlResourceValue.createWithValue(Type.STRING, "no way out")),
DataResourceXml.createWithNoNamespace(
transitiveRoot.resolve("res/values/strings.xml"),
SimpleXmlResourceValue.createWithValue(Type.STRING, "wrong way out")))
.toConflictMessage());
}

Expand Down Expand Up @@ -681,7 +677,7 @@ public void mergeDirectTransitivePrimaryConflictWithPrimaryOverride() throws Exc
ParsedAndroidDataBuilder.buildOn(fqnFactory)
.overwritable(
xml("string/exit")
.source(primaryStrings.overwrite(directStrings, transitiveStrings))
.source(primaryStrings.overwrite(directStrings))
.value(SimpleXmlResourceValue.createWithValue(Type.STRING, "way out")))
.build(),
ParsedAndroidDataBuilder.empty());
Expand Down Expand Up @@ -949,7 +945,7 @@ public void mergeCombiningLayoutIDResources() throws Exception {
file("layout/zzDirect").source(directLayout))
.combining(
xml("id/back_door").source(transitiveLayout).value(IdXmlResourceValue.of()),
xml("id/slide").source(transitiveLayout).value(IdXmlResourceValue.of()))
xml("id/slide").source(directLayout).value(IdXmlResourceValue.of()))
.build());
assertAbout(unwrittenMergedAndroidData).that(data).isEqualTo(expected);
}
Expand Down Expand Up @@ -1168,14 +1164,10 @@ public void mergeAssetsTransitiveConflict() throws Exception {
public void mergeAssetsTransitiveConflictWithPrimaryOverride() throws Exception {
Path primaryRoot = fileSystem.getPath("primary");
Path transitiveRoot = fileSystem.getPath("transitive");
DataSource transitiveSource =
DataSource.of(transitiveRoot.resolve("assets/hunting/of/the/snark.txt"));
DataSource primarySource =
DataSource.of(primaryRoot.resolve("assets/hunting/of/the/snark.txt"));

ParsedAndroidData transitiveDependency =
ParsedAndroidDataBuilder.buildOn(transitiveRoot)
.assets(file().source(transitiveSource))
.assets(file().source("hunting/of/the/snark.txt"))
.build();

ParsedAndroidData directDependency = ParsedAndroidDataBuilder.empty();
Expand All @@ -1193,7 +1185,7 @@ public void mergeAssetsTransitiveConflictWithPrimaryOverride() throws Exception
UnwrittenMergedAndroidData.of(
primary.getManifest(),
ParsedAndroidDataBuilder.buildOn(primaryRoot)
.assets(file().source(primarySource.overwrite(transitiveSource)))
.assets(file().source("hunting/of/the/snark.txt"))
.build(),
ParsedAndroidDataBuilder.empty());
assertAbout(unwrittenMergedAndroidData).that(data).isEqualTo(expected);
Expand Down Expand Up @@ -1263,22 +1255,20 @@ public void mergeAssetsDirectTransitivePrimaryConflictWithoutPrimaryOverride() t
MergeConflict.of(
RelativeAssetPath.Factory.of(directRoot.resolve("assets"))
.create(directRoot.resolve("assets/hunting/of/the/snark.txt")),
DataValueFile.of(primaryRoot.resolve("assets/hunting/of/the/snark.txt")),
DataValueFile.of(directRoot.resolve("assets/hunting/of/the/snark.txt")),
DataValueFile.of(transitiveRoot.resolve("assets/hunting/of/the/snark.txt")))
.toConflictMessage());
}

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

DataSource primarySource =
DataSource.of(primaryRoot.resolve("assets/hunting/of/the/snark.txt"));
DataSource directSource = DataSource.of(directRoot.resolve("assets/hunting/of/the/snark.txt"));
DataSource transitiveSource =
DataSource.of(transitiveRoot.resolve("assets/hunting/of/the/snark.txt"));

ParsedAndroidData transitiveDependency =
ParsedAndroidDataBuilder.buildOn(transitiveRoot)
Expand All @@ -1299,19 +1289,26 @@ public void imergeAssetsDirectTransitivePrimaryConflictWithPrimaryOverride() thr
UnwrittenMergedAndroidData data =
AndroidDataMerger.createWithDefaults()
.merge(transitiveDependency, directDependency, primary, true, true);

UnwrittenMergedAndroidData expected =
UnwrittenMergedAndroidData.of(
primary.getManifest(),
ParsedAndroidDataBuilder.buildOn(primaryRoot)
.assets(file().source(primarySource.overwrite(directSource, transitiveSource)))
.assets(file().source(primarySource.overwrite(directSource)))
.build(),
ParsedAndroidDataBuilder.empty());
assertAbout(unwrittenMergedAndroidData).that(data).isEqualTo(expected);
}

final Subject.Factory<UnwrittenMergedAndroidDataSubject, UnwrittenMergedAndroidData>
unwrittenMergedAndroidData = UnwrittenMergedAndroidDataSubject.FACTORY;
final SubjectFactory<UnwrittenMergedAndroidDataSubject, UnwrittenMergedAndroidData>
unwrittenMergedAndroidData =
new SubjectFactory<UnwrittenMergedAndroidDataSubject, UnwrittenMergedAndroidData>() {
@Override
public UnwrittenMergedAndroidDataSubject getSubject(
FailureStrategy fs, UnwrittenMergedAndroidData that) {
return new UnwrittenMergedAndroidDataSubject(fs, that);
}
};

private static final class TestLoggingHandler extends Handler {
public final List<String> warnings = new ArrayList<String>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,6 @@ public void writePublicResourceSameNameDifferentType() throws Exception {
source.resolve("AndroidManifest.xml"), direct, ParsedAndroidDataBuilder.empty())
.write(mergedDataWriter);



assertAbout(paths).that(actual.getManifest()).exists();
assertAbout(paths).that(actual.getResourceDir().resolve("values/values.xml")).exists();
assertAbout(paths)
Expand All @@ -264,9 +262,9 @@ public void writePublicResourceSameNameDifferentType() throws Exception {
"<integer name='zoo'>54321</integer>",
"<!-- " + fs.getPath("source/res/values/strings.xml") + " --><eat-comment/>",
"<string name='foo'>meow</string>",
"<!-- " + fs.getPath("source/res/values/integers.xml") + " --><eat-comment/>",
"<public name='foo' type='integer' id='0x7f040000'/>",
"<public name='foo' type='string' id='0x7f050000'/>",
"<!-- " + fs.getPath("source/res/values/integers.xml") + " --><eat-comment/>",
"<public name='zoo' type='integer' />",
END_RESOURCES);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,8 @@ public void xmlAndFileResourcesConflict() throws Exception {
DataSource otherRootValuesPath = DataSource.of(otherRoot.resolve("res/values/attr.xml"));
FullyQualifiedName idSomeId = fqnFactory.parse("id/some_id");



Truth.assertAbout(parsedAndroidData)
.that(dataSet)
.isEqualTo(
Expand Down Expand Up @@ -380,9 +382,10 @@ public void xmlAndFileResourcesConflict() throws Exception {
ImmutableMap.<DataKey, DataResource>of(
idSomeId, // key
DataResourceXml.createWithNoNamespace(
otherRootValuesPath, IdXmlResourceValue.of()) // value
rootValuesPath, IdXmlResourceValue.of()) // value
),
ImmutableMap.<DataKey, DataAsset>of()));

}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,26 @@
import static com.google.common.truth.Truth.assertThat;

import com.google.common.base.Objects;
import com.google.common.truth.FailureMetadata;
import com.google.common.truth.FailureStrategy;
import com.google.common.truth.Subject;
import com.google.common.truth.SubjectFactory;
import javax.annotation.Nullable;

class UnwrittenMergedAndroidDataSubject
extends Subject<UnwrittenMergedAndroidDataSubject, UnwrittenMergedAndroidData> {

static final Subject.Factory<UnwrittenMergedAndroidDataSubject, UnwrittenMergedAndroidData>
static final SubjectFactory<UnwrittenMergedAndroidDataSubject, UnwrittenMergedAndroidData>
FACTORY =
new Subject.Factory<UnwrittenMergedAndroidDataSubject, UnwrittenMergedAndroidData>() {
new SubjectFactory<UnwrittenMergedAndroidDataSubject, UnwrittenMergedAndroidData>() {
@Override
public UnwrittenMergedAndroidDataSubject createSubject(
FailureMetadata fs, UnwrittenMergedAndroidData that) {
public UnwrittenMergedAndroidDataSubject getSubject(
FailureStrategy fs, UnwrittenMergedAndroidData that) {
return new UnwrittenMergedAndroidDataSubject(fs, that);
}
};

public UnwrittenMergedAndroidDataSubject(
FailureMetadata failureStrategy, @Nullable UnwrittenMergedAndroidData subject) {
FailureStrategy failureStrategy, @Nullable UnwrittenMergedAndroidData subject) {
super(failureStrategy, subject);
}

Expand Down
Loading

0 comments on commit c28b4ce

Please sign in to comment.