Beispiel #1
0
        public IPackageMetadata Lookup(string workingDirectory, ModuleInfo module, PackageRef reference, string platform, string templateName, bool?source,
                                       bool forceUpgrade, bool?safeResolve)
        {
            if (!_featureManager.IsFeatureEnabled(Feature.PackageManagement))
            {
                return(null);
            }

            if (module != null && reference.Folder != null)
            {
                var existingPath = this.m_PackageLocator.DiscoverExistingPackagePath(module.Path, reference, platform);
                if (existingPath != null && Directory.Exists(existingPath))
                {
                    RedirectableConsole.WriteLine("Found an existing working copy of this package at " + existingPath);

                    Directory.CreateDirectory(Path.Combine(workingDirectory, reference.Folder));
                    using (var writer = new StreamWriter(Path.Combine(workingDirectory, reference.Folder, ".redirect")))
                    {
                        writer.WriteLine(existingPath);
                    }

                    return(null);
                }
                else
                {
                    if (File.Exists(Path.Combine(workingDirectory, reference.Folder, ".redirect")))
                    {
                        try
                        {
                            File.Delete(Path.Combine(workingDirectory, reference.Folder, ".redirect"));
                        }
                        catch
                        {
                        }
                    }
                }
            }

            var request = new PackageRequestRef(
                reference.Uri,
                reference.GitRef,
                platform,
                forceUpgrade,
                reference.IsStaticReference);

            return(_packageLookup.Lookup(workingDirectory, request));
        }
        public IPackageMetadata Lookup(PackageRequestRef request)
        {
            request.Uri = _packageRedirector.RedirectPackageUrl(request.Uri);

            if (request.Uri.StartsWith("local-pointer://", StringComparison.InvariantCultureIgnoreCase))
            {
                throw new InvalidOperationException("local-pointer:// URIs should never reach this section of code.");
            }

            IPackageMetadata metadata = null;
            var schemeFound           = false;

            foreach (var protocol in _packageProtocols)
            {
                foreach (var scheme in protocol.Schemes)
                {
                    if (request.Uri.StartsWith(scheme + "://"))
                    {
                        schemeFound = true;
                        metadata    = protocol.ResolveSource(request);
                        break;
                    }
                }

                if (schemeFound)
                {
                    break;
                }
            }

            if (!schemeFound)
            {
                throw new InvalidOperationException("Unknown package protocol scheme for URI: " + request.Uri);
            }

            if (schemeFound && metadata == null)
            {
                throw new InvalidOperationException("Package resolution failed to complete successfully");
            }

            return(metadata);
        }
Beispiel #3
0
        public IPackageMetadata Lookup(PackageRequestRef request)
        {
            request.Uri = _packageRedirector.RedirectPackageUrl(request.Uri);

            if (request.Uri.StartsWith("local-pointer://", StringComparison.InvariantCultureIgnoreCase))
            {
                throw new InvalidOperationException("local-pointer:// URIs should never reach this section of code.");
            }

            IPackageMetadata metadata = null;
            var schemeFound = false;
            foreach (var protocol in _packageProtocols)
            {
                foreach (var scheme in protocol.Schemes)
                {
                    if (request.Uri.StartsWith(scheme + "://"))
                    {
                        schemeFound = true;
                        metadata = protocol.ResolveSource(request);
                        break;
                    }
                }

                if (schemeFound)
                {
                    break;
                }
            }

            if (!schemeFound)
            {
                throw new InvalidOperationException("Unknown package protocol scheme for URI: " + request.Uri);
            }

            if (schemeFound && metadata == null)
            {
                throw new InvalidOperationException("Package resolution failed to complete successfully");
            }

            return metadata;
        }
        public void Resolve(ModuleInfo module, PackageRef reference, string platform, string templateName, bool? source, bool forceUpgrade = false)
        {
            if (!_featureManager.IsFeatureEnabled(Feature.PackageManagement))
            {
                return;
            }

            if (module != null && reference.Folder != null)
            {
                var existingPath = this.m_PackageLocator.DiscoverExistingPackagePath(module.Path, reference, platform);
                if (existingPath != null && Directory.Exists(existingPath))
                {
                    Console.WriteLine("Found an existing working copy of this package at " + existingPath);

                    Directory.CreateDirectory(reference.Folder);
                    using (var writer = new StreamWriter(Path.Combine(reference.Folder, ".redirect")))
                    {
                        writer.WriteLine(existingPath);
                    }

                    return;
                }
                else
                {
                    if (File.Exists(Path.Combine(reference.Folder, ".redirect")))
                    {
                        try
                        {
                            File.Delete(Path.Combine(reference.Folder, ".redirect"));
                        }
                        catch
                        {
                        }
                    }
                }
            }

            var request = new PackageRequestRef(
                reference.Uri,
                reference.GitRef,
                platform,
                !forceUpgrade && reference.IsCommitReference);

            var metadata = _packageLookup.Lookup(request);

            string toolFolder = null;
            if (reference.Folder == null)
            {
                if (metadata.PackageType == PACKAGE_TYPE_GLOBAL_TOOL)
                {
                }
                else
                {
                    throw new InvalidOperationException(
                        "No target folder was provided for package resolution, and the resulting package is not " +
                        "a global tool.");
                }
            }
            else
            {
                if (metadata.PackageType == PackageManager.PACKAGE_TYPE_TEMPLATE && templateName == null)
                {
                    throw new InvalidOperationException(
                        "Template referenced as part of module packages.  Templates can only be used " +
                        "with the --start option.");
                }
                else if (metadata.PackageType == PackageManager.PACKAGE_TYPE_LIBRARY)
                {
                    Directory.CreateDirectory(reference.Folder);

                    if (new DirectoryInfo(reference.Folder).GetFiles().Length > 0 || new DirectoryInfo(reference.Folder).GetDirectories().Length > 0)
                    {
                        if (!File.Exists(Path.Combine(reference.Folder, ".git")) && !Directory.Exists(Path.Combine(reference.Folder, ".git")) &&
                            !File.Exists(Path.Combine(reference.Folder, ".pkg")))
                        {
                            Console.Error.WriteLine(
                                "WARNING: The package directory '" + reference.Folder + "' already exists and contains " +
                                "files and/or subdirectories, but neither a .pkg file nor a .git file or subdirectory exists.  " +
                                "This indicates the package directory contains data that is not been instantiated or managed " +
                                "by Protobuild.  Since there is no safe way to initialize the package in this directory " +
                                "without a potential loss of data, Protobuild will not modify the contents of this folder " +
                                "during package resolution.  If the folder does not contains the required package " +
                                "dependencies, the project generation or build may unexpectedly fail.");
                            return;
                        }
                    }

                    if (source == null)
                    {
                        if (File.Exists(Path.Combine(reference.Folder, ".git")) || Directory.Exists(Path.Combine(reference.Folder, ".git")))
                        {
                            Console.WriteLine("Git repository present at " + Path.Combine(reference.Folder, ".git") + "; leaving as source version.");
                            source = true;
                        }
                        else
                        {
                            Console.WriteLine("Package type not specified (and no file at " + Path.Combine(reference.Folder, ".git") + "), requesting binary version.");
                            source = false;
                        }
                    }
                }
            }

            metadata.Resolve(metadata, reference.Folder, templateName, forceUpgrade, source);
        }
Beispiel #5
0
        public void Resolve(ModuleInfo module, PackageRef reference, string platform, string templateName, bool?source, bool forceUpgrade = false)
        {
            if (!_featureManager.IsFeatureEnabled(Feature.PackageManagement))
            {
                return;
            }

            if (module != null && reference.Folder != null)
            {
                var existingPath = this.m_PackageLocator.DiscoverExistingPackagePath(module.Path, reference, platform);
                if (existingPath != null && Directory.Exists(existingPath))
                {
                    Console.WriteLine("Found an existing working copy of this package at " + existingPath);

                    Directory.CreateDirectory(reference.Folder);
                    using (var writer = new StreamWriter(Path.Combine(reference.Folder, ".redirect")))
                    {
                        writer.WriteLine(existingPath);
                    }

                    return;
                }
                else
                {
                    if (File.Exists(Path.Combine(reference.Folder, ".redirect")))
                    {
                        try
                        {
                            File.Delete(Path.Combine(reference.Folder, ".redirect"));
                        }
                        catch
                        {
                        }
                    }
                }
            }

            var request = new PackageRequestRef(
                reference.Uri,
                reference.GitRef,
                platform,
                !forceUpgrade && reference.IsCommitReference);

            var metadata = _packageLookup.Lookup(request);

            string toolFolder = null;

            if (reference.Folder == null)
            {
                if (metadata.PackageType == PACKAGE_TYPE_GLOBAL_TOOL)
                {
                }
                else
                {
                    throw new InvalidOperationException(
                              "No target folder was provided for package resolution, and the resulting package is not " +
                              "a global tool.");
                }
            }
            else
            {
                if (metadata.PackageType == PackageManager.PACKAGE_TYPE_TEMPLATE && templateName == null)
                {
                    throw new InvalidOperationException(
                              "Template referenced as part of module packages.  Templates can only be used " +
                              "with the --start option.");
                }
                else if (metadata.PackageType == PackageManager.PACKAGE_TYPE_LIBRARY)
                {
                    Directory.CreateDirectory(reference.Folder);

                    if (new DirectoryInfo(reference.Folder).GetFiles().Length > 0 || new DirectoryInfo(reference.Folder).GetDirectories().Length > 0)
                    {
                        if (!File.Exists(Path.Combine(reference.Folder, ".git")) && !Directory.Exists(Path.Combine(reference.Folder, ".git")) &&
                            !File.Exists(Path.Combine(reference.Folder, ".pkg")))
                        {
                            Console.Error.WriteLine(
                                "WARNING: The package directory '" + reference.Folder + "' already exists and contains " +
                                "files and/or subdirectories, but neither a .pkg file nor a .git file or subdirectory exists.  " +
                                "This indicates the package directory contains data that is not been instantiated or managed " +
                                "by Protobuild.  Since there is no safe way to initialize the package in this directory " +
                                "without a potential loss of data, Protobuild will not modify the contents of this folder " +
                                "during package resolution.  If the folder does not contains the required package " +
                                "dependencies, the project generation or build may unexpectedly fail.");
                            return;
                        }
                    }

                    if (source == null)
                    {
                        if (File.Exists(Path.Combine(reference.Folder, ".git")) || Directory.Exists(Path.Combine(reference.Folder, ".git")))
                        {
                            Console.WriteLine("Git repository present at " + Path.Combine(reference.Folder, ".git") + "; leaving as source version.");
                            source = true;
                        }
                        else
                        {
                            Console.WriteLine("Package type not specified (and no file at " + Path.Combine(reference.Folder, ".git") + "), requesting binary version.");
                            source = false;
                        }
                    }
                }
            }

            metadata.Resolve(metadata, reference.Folder, templateName, forceUpgrade, source);
        }