Skip to content

Commit ff47ad3

Browse files
author
Stewart Miles
committed
Added support for global config of maven repos and pod sources.
Also, remove unused variables in IOSResolver and fix local paths in test data. Bug: 131865569 Change-Id: I339ccb813236e8f67605acb1a7c7a45ea8eca1e2
1 parent 88e1b70 commit ff47ad3

File tree

8 files changed

+129
-32
lines changed

8 files changed

+129
-32
lines changed

sample/Assets/PlayServicesResolver/Editor/SampleDependencies.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
<dependencies>
2+
23
<!-- Android dependencies are specified under the "androidPackages" element.
34
Each "androidPackage" element contains the attributes of an Android
45
dependency (e.g AAR, JAR reference). -->
56
<androidPackages>
7+
<!-- Global set of repositories to search for packages.
8+
These repos will be searched for all packages specified by
9+
androidPackage. -->
10+
<repositories>
11+
<repository>https://repo.maven.apache.org/maven2</repository>
12+
</repositories>
613
<!-- The "spec" attribute is *required* and provides the Maven package
714
specification.
815
@@ -36,6 +43,12 @@
3643

3744
<!-- iOS Cocoapod dependencies can be specified by each iosPod element. -->
3845
<iosPods>
46+
<!-- Global set of sources to search for Cocoapods.
47+
These sources will be searched for all Cocoapods specified by
48+
iosPod. -->
49+
<sources>
50+
<source>https://cocoapods.mycompany.com/Specs</source>
51+
</sources>
3952
<!-- iosPod supports the following attributes:
4053
* "name" (required)
4154
Name of the Cocoapod.

source/IOSResolver/src/IOSResolver.cs

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ private class Pod {
9696
/// </summary>
9797
public bool fromXmlFile = false;
9898

99+
/// <summary>
100+
/// Global set of sources for all pods.
101+
/// </summary>
102+
public static List<KeyValuePair<string, string>> Sources =
103+
new List<KeyValuePair<string, string>>();
104+
99105
/// <summary>
100106
/// Convert a dictionary of property key / value pairs to a string that can be appended
101107
/// to a Podfile pod declaration.
@@ -349,6 +355,19 @@ protected override bool Read(string filename, Logger logger) {
349355
} else if (elementName == "sources" &&
350356
parentElementName == "iosPod") {
351357
return true;
358+
} else if (elementName == "sources" &&
359+
parentElementName == "iosPods") {
360+
if (isStart) {
361+
sources = new List<string>();
362+
} else {
363+
foreach (var source in sources) {
364+
Pod.Sources.Add(
365+
new KeyValuePair<string, string>(
366+
source, String.Format("{0}:{1}", filename,
367+
reader.LineNumber)));
368+
}
369+
}
370+
return true;
352371
} else if (elementName == "source" &&
353372
parentElementName == "sources") {
354373
if (isStart && reader.Read() && reader.NodeType == XmlNodeType.Text) {
@@ -397,32 +416,11 @@ protected override bool Read(string filename, Logger logger) {
397416
// Ruby Gem executable filename.
398417
private static string GEM_EXECUTABLE = "gem";
399418

400-
// Extensions of pod source files to include in the project.
401-
private static HashSet<string> SOURCE_FILE_EXTENSIONS = new HashSet<string>(
402-
new string[] {
403-
".h",
404-
".c",
405-
".cc",
406-
".cpp",
407-
".mm",
408-
".m",
409-
});
410-
411419
/// <summary>
412420
/// Name of the Xcode project generated by Unity.
413421
/// </summary>
414422
public const string PROJECT_NAME = "Unity-iPhone";
415423

416-
// Build configuration names in Unity generated Xcode projects. These are required before
417-
// Unity 2017 where PBXProject.BuildConfigNames was introduced.
418-
private static string[] BUILD_CONFIG_NAMES = new string[] {
419-
"Debug",
420-
"Release",
421-
"ReleaseForProfiling",
422-
"ReleaseForRunning",
423-
"ReleaseForTesting",
424-
};
425-
426424
/// <summary>
427425
/// Main executable target of the Xcode project generated by Unity.
428426
/// </summary>
@@ -1684,6 +1682,9 @@ private static string GeneratePodfileSourcesSection() {
16841682
var processedSources = new HashSet<string>();
16851683
int sourceIndex = 0;
16861684
bool sourcesAvailable;
1685+
foreach (var kv in Pod.Sources) {
1686+
interleavedSourcesLines.Add(String.Format("source '{0}'", kv.Key));
1687+
}
16871688
do {
16881689
sourcesAvailable = false;
16891690
foreach (var pod in pods.Values) {
@@ -2216,6 +2217,8 @@ private static void RefreshXmlDependencies() {
22162217
foreach (var podName in podsToRemove) {
22172218
pods.Remove(podName);
22182219
}
2220+
// Clear all sources (only can be set via XML config).
2221+
Pod.Sources = new List<KeyValuePair<string, string>>();
22192222
// Read pod specifications from XML dependencies.
22202223
xmlDependencies.ReadAll(logger);
22212224
}

source/JarResolverLib/src/Google.JarResolver/PlayServicesSupport.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,29 @@ public enum LogLevel {
7373
/// </summary>
7474
private List<string> repositoryPaths = new List<string>();
7575

76+
77+
/// <summary>
78+
/// List of additional global repository paths.
79+
/// These are added to the set of repositories used to construct this class.
80+
/// The key in the pair is the repo and the value is the source (file & line) it was
81+
/// parsed from.
82+
/// </summary>
83+
internal static List<KeyValuePair<string, string>> AdditionalRepositoryPaths =
84+
new List<KeyValuePair<string, string>>();
85+
7686
/// <summary>
7787
/// Get the set of repository paths.
88+
/// This includes the repo paths specified at construction and AdditionalRepositoryPaths.
7889
/// </summary>
79-
internal List<string> RepositoryPaths { get { return new List<string>(repositoryPaths); } }
90+
internal List<string> RepositoryPaths {
91+
get {
92+
var allPaths = new List<string>(repositoryPaths);
93+
foreach (var kv in AdditionalRepositoryPaths) {
94+
allPaths.Add(kv.Value);
95+
}
96+
return allPaths;
97+
}
98+
}
8099

81100
/// <summary>
82101
/// The client dependencies map. This is a proper subset of dependencyMap.
@@ -303,6 +322,7 @@ public static Dictionary<string, Dependency> GetAllDependencies() {
303322
public void ClearDependencies()
304323
{
305324
clientDependenciesMap = new Dictionary<string, Dependency>();
325+
AdditionalRepositoryPaths = new List<KeyValuePair<string, string>>();
306326
}
307327

308328
/// <summary>

source/PlayServicesResolver/src/AndroidXmlDependencies.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,19 @@ protected override bool Read(string filename, Logger logger) {
119119
} else if (elementName == "repositories" &&
120120
parentElementName == "androidPackage") {
121121
return true;
122+
} else if (elementName == "repositories" &&
123+
parentElementName == "androidPackages") {
124+
if (isStart) {
125+
repositories = new List<string>();
126+
} else {
127+
foreach (var repo in repositories) {
128+
PlayServicesSupport.AdditionalRepositoryPaths.Add(
129+
new KeyValuePair<string, string>(
130+
repo, String.Format("{0}:{1}", filename,
131+
reader.LineNumber)));
132+
}
133+
}
134+
return true;
122135
} else if (elementName == "repository" &&
123136
parentElementName == "repositories") {
124137
if (isStart && reader.Read() && reader.NodeType == XmlNodeType.Text) {

source/PlayServicesResolver/src/ResolverVer1_1.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,14 @@ internal static Dictionary<string, string> DependenciesToPackageSpecs(
559559
internal static List<KeyValuePair<string, string>> DependenciesToRepoUris(
560560
IEnumerable<Dependency> dependencies) {
561561
var sourcesByRepo = new OrderedDictionary();
562+
// Add global repos first.
563+
foreach (var kv in PlayServicesSupport.AdditionalRepositoryPaths) {
564+
var sources = kv.Value;
565+
if (sourcesByRepo.Contains(kv.Key)) {
566+
sources += ", " + kv.Value;
567+
}
568+
sourcesByRepo[kv.Key] = sources;
569+
}
562570
// Build array of repos to search, they're interleaved across all dependencies as the
563571
// order matters.
564572
int maxNumberOfRepos = 0;

source/PlayServicesResolver/test/resolve_async/Assets/PlayServicesResolver/Editor/TestDependencies.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,9 @@
88
<repository>Assets/Firebase/m2repository</repository>
99
</repositories>
1010
</androidPackage>
11+
<!-- Global repository. -->
12+
<repositories>
13+
<repository>file:///my/nonexistant/test/repo</repository>
14+
</repositories>
1115
</androidPackages>
1216
</dependencies>

source/PlayServicesResolver/test/resolve_async/Assets/PlayServicesResolver/Editor/TestResolveAsync.cs

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,9 @@ private static void ValidateDependencies(TestCaseResult testCaseResult) {
644644
// Validate configured repos are present.
645645
CompareKeyValuePairLists(
646646
new List<KeyValuePair<string, string>>() {
647+
new KeyValuePair<string, string>(
648+
"file:///my/nonexistant/test/repo",
649+
"Assets/PlayServicesResolver/Editor/TestDependencies.xml:14"),
647650
new KeyValuePair<string, string>(
648651
"file:///" + Path.GetFullPath(
649652
"Assets/Firebase/m2repository").Replace("\\", "/"),
@@ -896,6 +899,20 @@ private static string ExtractZip(string zipFile, List<string> failureMessages) {
896899
return outputDir;
897900
}
898901

902+
/// <summary>
903+
/// In .gradle file contents, replace file:///PROJECT_DIR URIs with the absolute path to the
904+
/// project directory.
905+
/// </summary>
906+
/// <param name="filename">Name of the file.</param>
907+
/// <param name="contents">Contents of the file to search and replace.</param>
908+
private static string ReplaceFileProjectDirUri(string filename, string contents) {
909+
if (filename.ToLower().EndsWith(".gradle")) {
910+
return contents.Replace("file:///PROJECT_DIR",
911+
"file:///" + Path.GetFullPath(".").Replace("\\", "/"));
912+
}
913+
return contents;
914+
}
915+
899916
/// <summary>
900917
/// Compare the contents of two directories.
901918
/// </summary>
@@ -972,24 +989,40 @@ private static List<string> CompareDirectoryContents(string expectedAssetsDir,
972989
}
973990
}
974991
} else {
992+
bool differs = true;
975993
// Determine whether to display the file as a string.
976994
bool displayContents = false;
995+
string expectedContentsAsString = "(binary)";
996+
string resolvedContentsAsString = expectedContentsAsString;
977997
string resolvedExtension = Path.GetExtension(resolvedFile).ToLower();
978998
foreach (var extension in new[] { ".xml", ".txt", ".gradle" }) {
979999
if (resolvedExtension == extension) {
9801000
displayContents = true;
9811001
break;
9821002
}
9831003
}
984-
// Log an error.
985-
failureMessages.Add(String.Format(
986-
"Artifact {0} does not match contents of {1}\n" +
987-
"--- {0} -------\n" +
988-
"{2}\n" +
989-
"--- {0} end ---\n",
990-
resolvedFile, expectedFile,
991-
displayContents ? System.Text.Encoding.Default.GetString(resolvedContents) :
992-
"(binary)"));
1004+
if (displayContents) {
1005+
expectedContentsAsString = ReplaceFileProjectDirUri(
1006+
expectedFile,
1007+
System.Text.Encoding.Default.GetString(expectedContents));
1008+
resolvedContentsAsString = ReplaceFileProjectDirUri(
1009+
expectedFile,
1010+
System.Text.Encoding.Default.GetString(resolvedContents));
1011+
differs = expectedContentsAsString != resolvedContentsAsString;
1012+
}
1013+
if (differs) {
1014+
// Log an error.
1015+
failureMessages.Add(String.Format(
1016+
"Artifact {0} does not match contents of {1}\n" +
1017+
"--- {0} -------\n" +
1018+
"{2}\n" +
1019+
"--- {0} end ---\n" +
1020+
"--- {1} -------\n" +
1021+
"{3}\n" +
1022+
"--- {1} -------\n",
1023+
resolvedFile, expectedFile, resolvedContentsAsString,
1024+
expectedContentsAsString));
1025+
}
9931026
}
9941027
}
9951028
}

source/PlayServicesResolver/test/resolve_async/ExpectedArtifacts/NoExport/GradleTemplate/mainTemplate.gradle

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ allprojects {
2626
url "https://maven.google.com"
2727
}
2828
maven {
29-
url "file:////Users/smiles/dev/src/unity-jar-resolver/test_output/testAndroidResolverAsyncResolveBatchMode/testAndroidResolverAsyncResolveBatchMode/Assets/Firebase/m2repository" // Assets/PlayServicesResolver/Editor/TestDependencies.xml:10
29+
url "file:///my/nonexistant/test/repo" // Assets/PlayServicesResolver/Editor/TestDependencies.xml:14, Assets/PlayServicesResolver/Editor/TestDependencies.xml:14
30+
}
31+
maven {
32+
url "file:///PROJECT_DIR/Assets/Firebase/m2repository" // Assets/PlayServicesResolver/Editor/TestDependencies.xml:10
3033
}
3134
mavenLocal()
3235
jcenter()

0 commit comments

Comments
 (0)