Skip to content

Commit

Permalink
Added support for global config of maven repos and pod sources.
Browse files Browse the repository at this point in the history
Also, remove unused variables in IOSResolver and fix local paths in test data.

Bug: 131865569
Change-Id: I339ccb813236e8f67605acb1a7c7a45ea8eca1e2
  • Loading branch information
Stewart Miles committed May 3, 2019
1 parent 88e1b70 commit ff47ad3
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 32 deletions.
13 changes: 13 additions & 0 deletions sample/Assets/PlayServicesResolver/Editor/SampleDependencies.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
<dependencies>

<!-- Android dependencies are specified under the "androidPackages" element.
Each "androidPackage" element contains the attributes of an Android
dependency (e.g AAR, JAR reference). -->
<androidPackages>
<!-- Global set of repositories to search for packages.
These repos will be searched for all packages specified by
androidPackage. -->
<repositories>
<repository>https://repo.maven.apache.org/maven2</repository>
</repositories>
<!-- The "spec" attribute is *required* and provides the Maven package
specification.
Expand Down Expand Up @@ -36,6 +43,12 @@

<!-- iOS Cocoapod dependencies can be specified by each iosPod element. -->
<iosPods>
<!-- Global set of sources to search for Cocoapods.
These sources will be searched for all Cocoapods specified by
iosPod. -->
<sources>
<source>https://cocoapods.mycompany.com/Specs</source>
</sources>
<!-- iosPod supports the following attributes:
* "name" (required)
Name of the Cocoapod.
Expand Down
45 changes: 24 additions & 21 deletions source/IOSResolver/src/IOSResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ private class Pod {
/// </summary>
public bool fromXmlFile = false;

/// <summary>
/// Global set of sources for all pods.
/// </summary>
public static List<KeyValuePair<string, string>> Sources =
new List<KeyValuePair<string, string>>();

/// <summary>
/// Convert a dictionary of property key / value pairs to a string that can be appended
/// to a Podfile pod declaration.
Expand Down Expand Up @@ -349,6 +355,19 @@ protected override bool Read(string filename, Logger logger) {
} else if (elementName == "sources" &&
parentElementName == "iosPod") {
return true;
} else if (elementName == "sources" &&
parentElementName == "iosPods") {
if (isStart) {
sources = new List<string>();
} else {
foreach (var source in sources) {
Pod.Sources.Add(
new KeyValuePair<string, string>(
source, String.Format("{0}:{1}", filename,
reader.LineNumber)));
}
}
return true;
} else if (elementName == "source" &&
parentElementName == "sources") {
if (isStart && reader.Read() && reader.NodeType == XmlNodeType.Text) {
Expand Down Expand Up @@ -397,32 +416,11 @@ protected override bool Read(string filename, Logger logger) {
// Ruby Gem executable filename.
private static string GEM_EXECUTABLE = "gem";

// Extensions of pod source files to include in the project.
private static HashSet<string> SOURCE_FILE_EXTENSIONS = new HashSet<string>(
new string[] {
".h",
".c",
".cc",
".cpp",
".mm",
".m",
});

/// <summary>
/// Name of the Xcode project generated by Unity.
/// </summary>
public const string PROJECT_NAME = "Unity-iPhone";

// Build configuration names in Unity generated Xcode projects. These are required before
// Unity 2017 where PBXProject.BuildConfigNames was introduced.
private static string[] BUILD_CONFIG_NAMES = new string[] {
"Debug",
"Release",
"ReleaseForProfiling",
"ReleaseForRunning",
"ReleaseForTesting",
};

/// <summary>
/// Main executable target of the Xcode project generated by Unity.
/// </summary>
Expand Down Expand Up @@ -1684,6 +1682,9 @@ private static string GeneratePodfileSourcesSection() {
var processedSources = new HashSet<string>();
int sourceIndex = 0;
bool sourcesAvailable;
foreach (var kv in Pod.Sources) {
interleavedSourcesLines.Add(String.Format("source '{0}'", kv.Key));
}
do {
sourcesAvailable = false;
foreach (var pod in pods.Values) {
Expand Down Expand Up @@ -2216,6 +2217,8 @@ private static void RefreshXmlDependencies() {
foreach (var podName in podsToRemove) {
pods.Remove(podName);
}
// Clear all sources (only can be set via XML config).
Pod.Sources = new List<KeyValuePair<string, string>>();
// Read pod specifications from XML dependencies.
xmlDependencies.ReadAll(logger);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,29 @@ public enum LogLevel {
/// </summary>
private List<string> repositoryPaths = new List<string>();


/// <summary>
/// List of additional global repository paths.
/// These are added to the set of repositories used to construct this class.
/// The key in the pair is the repo and the value is the source (file & line) it was
/// parsed from.
/// </summary>
internal static List<KeyValuePair<string, string>> AdditionalRepositoryPaths =
new List<KeyValuePair<string, string>>();

/// <summary>
/// Get the set of repository paths.
/// This includes the repo paths specified at construction and AdditionalRepositoryPaths.
/// </summary>
internal List<string> RepositoryPaths { get { return new List<string>(repositoryPaths); } }
internal List<string> RepositoryPaths {
get {
var allPaths = new List<string>(repositoryPaths);
foreach (var kv in AdditionalRepositoryPaths) {
allPaths.Add(kv.Value);
}
return allPaths;
}
}

/// <summary>
/// The client dependencies map. This is a proper subset of dependencyMap.
Expand Down Expand Up @@ -303,6 +322,7 @@ public static Dictionary<string, Dependency> GetAllDependencies() {
public void ClearDependencies()
{
clientDependenciesMap = new Dictionary<string, Dependency>();
AdditionalRepositoryPaths = new List<KeyValuePair<string, string>>();
}

/// <summary>
Expand Down
13 changes: 13 additions & 0 deletions source/PlayServicesResolver/src/AndroidXmlDependencies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,19 @@ protected override bool Read(string filename, Logger logger) {
} else if (elementName == "repositories" &&
parentElementName == "androidPackage") {
return true;
} else if (elementName == "repositories" &&
parentElementName == "androidPackages") {
if (isStart) {
repositories = new List<string>();
} else {
foreach (var repo in repositories) {
PlayServicesSupport.AdditionalRepositoryPaths.Add(
new KeyValuePair<string, string>(
repo, String.Format("{0}:{1}", filename,
reader.LineNumber)));
}
}
return true;
} else if (elementName == "repository" &&
parentElementName == "repositories") {
if (isStart && reader.Read() && reader.NodeType == XmlNodeType.Text) {
Expand Down
8 changes: 8 additions & 0 deletions source/PlayServicesResolver/src/ResolverVer1_1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,14 @@ internal static Dictionary<string, string> DependenciesToPackageSpecs(
internal static List<KeyValuePair<string, string>> DependenciesToRepoUris(
IEnumerable<Dependency> dependencies) {
var sourcesByRepo = new OrderedDictionary();
// Add global repos first.
foreach (var kv in PlayServicesSupport.AdditionalRepositoryPaths) {
var sources = kv.Value;
if (sourcesByRepo.Contains(kv.Key)) {
sources += ", " + kv.Value;
}
sourcesByRepo[kv.Key] = sources;
}
// Build array of repos to search, they're interleaved across all dependencies as the
// order matters.
int maxNumberOfRepos = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@
<repository>Assets/Firebase/m2repository</repository>
</repositories>
</androidPackage>
<!-- Global repository. -->
<repositories>
<repository>file:///my/nonexistant/test/repo</repository>
</repositories>
</androidPackages>
</dependencies>
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,9 @@ private static void ValidateDependencies(TestCaseResult testCaseResult) {
// Validate configured repos are present.
CompareKeyValuePairLists(
new List<KeyValuePair<string, string>>() {
new KeyValuePair<string, string>(
"file:///my/nonexistant/test/repo",
"Assets/PlayServicesResolver/Editor/TestDependencies.xml:14"),
new KeyValuePair<string, string>(
"file:///" + Path.GetFullPath(
"Assets/Firebase/m2repository").Replace("\\", "/"),
Expand Down Expand Up @@ -896,6 +899,20 @@ private static string ExtractZip(string zipFile, List<string> failureMessages) {
return outputDir;
}

/// <summary>
/// In .gradle file contents, replace file:///PROJECT_DIR URIs with the absolute path to the
/// project directory.
/// </summary>
/// <param name="filename">Name of the file.</param>
/// <param name="contents">Contents of the file to search and replace.</param>
private static string ReplaceFileProjectDirUri(string filename, string contents) {
if (filename.ToLower().EndsWith(".gradle")) {
return contents.Replace("file:///PROJECT_DIR",
"file:///" + Path.GetFullPath(".").Replace("\\", "/"));
}
return contents;
}

/// <summary>
/// Compare the contents of two directories.
/// </summary>
Expand Down Expand Up @@ -972,24 +989,40 @@ private static List<string> CompareDirectoryContents(string expectedAssetsDir,
}
}
} else {
bool differs = true;
// Determine whether to display the file as a string.
bool displayContents = false;
string expectedContentsAsString = "(binary)";
string resolvedContentsAsString = expectedContentsAsString;
string resolvedExtension = Path.GetExtension(resolvedFile).ToLower();
foreach (var extension in new[] { ".xml", ".txt", ".gradle" }) {
if (resolvedExtension == extension) {
displayContents = true;
break;
}
}
// Log an error.
failureMessages.Add(String.Format(
"Artifact {0} does not match contents of {1}\n" +
"--- {0} -------\n" +
"{2}\n" +
"--- {0} end ---\n",
resolvedFile, expectedFile,
displayContents ? System.Text.Encoding.Default.GetString(resolvedContents) :
"(binary)"));
if (displayContents) {
expectedContentsAsString = ReplaceFileProjectDirUri(
expectedFile,
System.Text.Encoding.Default.GetString(expectedContents));
resolvedContentsAsString = ReplaceFileProjectDirUri(
expectedFile,
System.Text.Encoding.Default.GetString(resolvedContents));
differs = expectedContentsAsString != resolvedContentsAsString;
}
if (differs) {
// Log an error.
failureMessages.Add(String.Format(
"Artifact {0} does not match contents of {1}\n" +
"--- {0} -------\n" +
"{2}\n" +
"--- {0} end ---\n" +
"--- {1} -------\n" +
"{3}\n" +
"--- {1} -------\n",
resolvedFile, expectedFile, resolvedContentsAsString,
expectedContentsAsString));
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ allprojects {
url "https://maven.google.com"
}
maven {
url "file:////Users/smiles/dev/src/unity-jar-resolver/test_output/testAndroidResolverAsyncResolveBatchMode/testAndroidResolverAsyncResolveBatchMode/Assets/Firebase/m2repository" // Assets/PlayServicesResolver/Editor/TestDependencies.xml:10
url "file:///my/nonexistant/test/repo" // Assets/PlayServicesResolver/Editor/TestDependencies.xml:14, Assets/PlayServicesResolver/Editor/TestDependencies.xml:14
}
maven {
url "file:///PROJECT_DIR/Assets/Firebase/m2repository" // Assets/PlayServicesResolver/Editor/TestDependencies.xml:10
}
mavenLocal()
jcenter()
Expand Down

0 comments on commit ff47ad3

Please sign in to comment.