public Dictionary<string, Dependency> LoadDependencies(bool allClients,
bool keepMissing=false)
{
Dictionary<string, Dependency> dependencyMap =
new Dictionary<string, Dependency>();
string[] clientFiles;
if (allClients)
{
clientFiles = Directory.GetFiles(settingsDirectory, "GoogleDependency*");
}
else
{
clientFiles = new string[] { DependencyFileName };
}
foreach (string depFile in clientFiles)
{
if (!File.Exists(depFile))
{
continue;
}
StreamReader sr = new StreamReader(depFile);
XmlTextReader reader = new XmlTextReader(sr);
bool inDependencies = false;
bool inDep = false;
string groupId = null;
string artifactId = null;
string versionId = null;
string[] packageIds = null;
string[] repositories = null;
while (reader.Read())
{
if (reader.Name == "dependencies")
{
inDependencies = reader.IsStartElement();
}
if (inDependencies && reader.Name == "dependency")
{
inDep = reader.IsStartElement();
if (!inDep)
{
if (groupId != null && artifactId != null && versionId != null)
{
Dependency unresolvedDependency =
new Dependency(groupId, artifactId, versionId,
packageIds: packageIds,
repositories: repositories);
foreach (string repo in repositories ?? new string[] {})
{
repositoryPaths[repo] = true;
}
Dependency dep = FindCandidate(unresolvedDependency);
if (dep == null)
{
if (keepMissing)
{
dep = unresolvedDependency;
}
else
{
throw new ResolutionException(
"Cannot find candidate artifact for " +
groupId + ":" + artifactId + ":" + versionId);
}
}
if (!dependencyMap.ContainsKey(dep.Key))
{
dependencyMap[dep.Key] = dep;
}
}
// Reset the dependency being read.
groupId = null;
artifactId = null;
versionId = null;
packageIds = null;
repositories = null;
}
}
if (inDep)
{
if (reader.Name == "groupId")
{
groupId = reader.ReadString();
}
else if (reader.Name == "artifactId")
{
artifactId = reader.ReadString();
}
else if (reader.Name == "version")
{
versionId = reader.ReadString();
}
else if (reader.Name == "packageIds")
{
// ReadContentAs does not appear to work for string[] in Mono 2.0
// instead read the field as a string and split to retrieve each
// packageId from the set.
string packageId = reader.ReadString();
packageIds = Array.FindAll(packageId.Split(new char[] {' '}),
(s) => { return s.Length > 0; });
}
else if (reader.Name == "repositories")
{
string repositoriesValue = reader.ReadString();
repositories = Array.FindAll(repositoriesValue.Split(new char[] {' '}),
(s) => { return s.Length > 0; });
}
}
}
reader.Close();
sr.Close();
}
return dependencyMap;
}