예제 #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));
        }
예제 #2
0
        private byte[] DownloadBinaryPackage(string uri, string gitHash, string platform, out string format)
        {
            format = null;

            string sourceUri, type;
            Dictionary <string, string> downloadMap, archiveTypeMap, resolvedHash;

            _packageLookup.Lookup(
                uri,
                platform,
                true,
                out sourceUri,
                out type,
                out downloadMap,
                out archiveTypeMap,
                out resolvedHash);

            if (!downloadMap.ContainsKey(gitHash))
            {
                if (string.IsNullOrWhiteSpace(sourceUri))
                {
                    throw new InvalidOperationException("Unable to resolve binary package for version \"" + gitHash + "\" and platform \"" + platform + "\" and this package does not have a source repository");
                }
                else
                {
                    Console.WriteLine("Unable to resolve binary package for version \"" + gitHash + "\" and platform \"" + platform + "\", falling back to source version");
                    return(null);
                }
            }
            var fileUri         = downloadMap[gitHash];
            var archiveType     = archiveTypeMap[gitHash];
            var resolvedGitHash = resolvedHash[gitHash];

            format = archiveType;
            return(this.GetBinary(fileUri));
        }
예제 #3
0
        public int Execute(Execution execution)
        {
            using (var client = new RetryableWebClient())
            {
                var sourcePackage = _packageUrlParser.Parse(execution.PackageUrl);

                RedirectableConsole.WriteLine("Retrieving source package...");
                var metadata = _packageLookup.Lookup(execution.WorkingDirectory, new PackageRequestRef(
                                                         sourcePackage.Uri,
                                                         sourcePackage.GitRef,
                                                         execution.PackagePushPlatform,
                                                         true,
                                                         sourcePackage.IsStaticReference));

                if (metadata.GetProtobuildPackageBinary == null)
                {
                    RedirectableConsole.ErrorWriteLine(
                        "ERROR: URL resolved to a package metadata type '" + metadata.GetType().Name + "', " +
                        "but this type doesn't provide a mechanism to convert to a Protobuild package.");
                }

                string archiveType;
                byte[] archiveData;
                metadata.GetProtobuildPackageBinary(metadata, out archiveType, out archiveData);

                var protobuildPackageMetadata = metadata as ProtobuildPackageMetadata;
                if (protobuildPackageMetadata == null)
                {
                    RedirectableConsole.ErrorWriteLine("--repush requires that the source URL resolve to a Protobuild package");
                    return(1);
                }

                RedirectableConsole.WriteLine("Detected package type as " + archiveType + ".");

                if (execution.PackagePushVersion.StartsWith("hash:", StringComparison.InvariantCulture))
                {
                    var sha1   = new SHA1Managed();
                    var hashed = sha1.ComputeHash(Encoding.ASCII.GetBytes(execution.PackagePushVersion.Substring("hash:".Length)));
                    execution.PackagePushVersion = BitConverter.ToString(hashed).ToLowerInvariant().Replace("-", "");
                }

                RedirectableConsole.WriteLine("Creating new package version...");

                var uploadParameters = new System.Collections.Specialized.NameValueCollection
                {
                    { "__apikey__", execution.PackagePushApiKey },
                    { "version", execution.PackagePushVersion },
                    { "platform", execution.PackagePushPlatform },
                };

                var json = fastJSON.JSON.ToDynamic(
                    System.Text.Encoding.ASCII.GetString(
                        client.UploadValues(execution.PackagePushUrl + "/version/new/api", uploadParameters)));

                if (json.has_error)
                {
                    RedirectableConsole.WriteLine(json.error);
                    return(1);
                }

                var uploadTarget   = (string)json.result.uploadUrl;
                var finalizeTarget = (string)json.result.finalizeUrl;

                RedirectableConsole.WriteLine("Uploading package...");
                this.PushBinary(uploadTarget, archiveData);

                RedirectableConsole.WriteLine("Finalizing package version...");

                var finalizeParameters = new System.Collections.Specialized.NameValueCollection
                {
                    { "__apikey__", execution.PackagePushApiKey },
                    { "archiveType", archiveType },
                };

                json = fastJSON.JSON.ToDynamic(
                    System.Text.Encoding.ASCII.GetString(
                        client.UploadValues(finalizeTarget, finalizeParameters)));

                if (json.has_error)
                {
                    RedirectableConsole.WriteLine(json.error);
                    return(1);
                }

                if (execution.PackagePushBranchToUpdate != null)
                {
                    RedirectableConsole.WriteLine("Updating branch " + execution.PackagePushBranchToUpdate + " to point at new version...");

                    var branchUpdateParameters = new System.Collections.Specialized.NameValueCollection
                    {
                        { "__apikey__", execution.PackagePushApiKey },
                        { "name", execution.PackagePushBranchToUpdate },
                        { "git", execution.PackagePushVersion },
                    };

                    json = fastJSON.JSON.ToDynamic(
                        System.Text.Encoding.ASCII.GetString(
                            client.UploadValues(
                                execution.PackagePushUrl + "/branch/edit/" + execution.PackagePushBranchToUpdate + "/api",
                                branchUpdateParameters)));

                    if (json.has_error)
                    {
                        RedirectableConsole.WriteLine(json.error);
                        return(1);
                    }
                }

                RedirectableConsole.WriteLine("Package version repushed successfully.");
            }
            return(0);
        }
예제 #4
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);
        }
예제 #5
0
        public void Resolve(ModuleInfo module, PackageRef reference, string platform, string templateName, bool?source, bool forceUpgrade = false)
        {
            if (module != null)
            {
                var existingPath = this.m_PackageLocator.DiscoverExistingPackagePath(module.Path, reference);
                if (existingPath != null)
                {
                    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
                        {
                        }
                    }
                }
            }

            string sourceUri, type;
            Dictionary <string, string> downloadMap, archiveTypeMap, resolvedHash;

            _packageLookup.Lookup(
                reference.Uri,
                platform,
                true,
                out sourceUri,
                out type,
                out downloadMap,
                out archiveTypeMap,
                out resolvedHash);

            if (type == 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 (type == PackageManager.PACKAGE_TYPE_LIBRARY)
            {
                Directory.CreateDirectory(reference.Folder);

                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;
                    }
                }
            }

            if (source.Value && !string.IsNullOrWhiteSpace(sourceUri))
            {
                switch (type)
                {
                case PackageManager.PACKAGE_TYPE_LIBRARY:
                    this.ResolveLibrarySource(reference, sourceUri, forceUpgrade);
                    break;

                case PackageManager.PACKAGE_TYPE_TEMPLATE:
                    this.ResolveTemplateSource(reference, templateName, sourceUri);
                    break;
                }
            }
            else
            {
                switch (type)
                {
                case PackageManager.PACKAGE_TYPE_LIBRARY:
                    this.ResolveLibraryBinary(reference, platform, sourceUri, forceUpgrade);
                    break;

                case PackageManager.PACKAGE_TYPE_TEMPLATE:
                    this.ResolveTemplateBinary(reference, templateName, platform, sourceUri);
                    break;
                }
            }
        }