Google.JarResolver.PlayServicesSupport.LoadDependencies C# (CSharp) Метод

LoadDependencies() публичный Метод

Loads the dependencies from the settings files.
public LoadDependencies ( bool allClients, bool keepMissing = false ) : Dependency>.Dictionary
allClients bool If true, all client dependencies are loaded and returned ///
keepMissing bool If false, missing dependencies result in a /// ResolutionException being thrown. If true, each missing dependency is included in /// the returned set with RepoPath set to an empty string.
Результат Dependency>.Dictionary
        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;
        }

Usage Example

Пример #1
0
        /// <summary>
        /// Creates an instance of PlayServicesSupport.  This instance is
        /// used to add dependencies for the calling client and invoke the resolution.
        /// </summary>
        /// <returns>The instance.</returns>
        /// <param name="clientName">Client name.  Must be a valid filename.
        /// This is used to uniquely identify
        /// the calling client so that dependencies can be associated with a specific
        /// client to help in resetting dependencies.</param>
        /// <param name="sdkPath">Sdk path for Android SDK.</param>
        /// <param name="additionalRepositories">Array of additional repository paths. can be null</param>
        /// <param name="settingsDirectory">The relative path to the directory
        /// to save the settings.  For Unity projects this is "ProjectSettings"</param>
        /// <param name="logger">Delegate used to write messages to the log.</param>
        internal static PlayServicesSupport CreateInstance(
            string clientName,
            string sdkPath,
            string[] additionalRepositories,
            string settingsDirectory,
            LogMessage logger = null)
        {
            PlayServicesSupport instance = new PlayServicesSupport();

            instance.logger = logger;
            instance.sdk    = sdkPath;
            string badchars = new string(Path.GetInvalidFileNameChars());

            foreach (char ch in clientName)
            {
                if (badchars.IndexOf(ch) >= 0)
                {
                    throw new Exception("Invalid clientName: " + clientName);
                }
            }

            instance.clientName        = clientName;
            instance.settingsDirectory = settingsDirectory;

            // Add the standard repo paths from the Android SDK
            string sdkExtrasDir = Path.Combine("$SDK", "extras");

            instance.repositoryPaths[
                Path.Combine(sdkExtrasDir, Path.Combine("android", "m2repository"))] = true;
            instance.repositoryPaths[
                Path.Combine(sdkExtrasDir, Path.Combine("google", "m2repository"))] = true;
            foreach (string repo in additionalRepositories ?? new string[] {})
            {
                instance.repositoryPaths[repo] = true;
            }
            instance.clientDependenciesMap = instance.LoadDependencies(false,
                                                                       true);
            return(instance);
        }
All Usage Examples Of Google.JarResolver.PlayServicesSupport::LoadDependencies