Beispiel #1
0
        private void ResolveTemplateBinary(ProtobuildPackageMetadata protobuildMetadata, string folder, string templateName, bool forceUpgrade)
        {
            if (folder != string.Empty)
            {
                throw new InvalidOperationException("Reference folder must be empty for template type.");
            }

            // The template is a reference to a Git repository.
            if (Directory.Exists(".staging"))
            {
                PathUtils.AggressiveDirectoryDelete(".staging");
            }

            Directory.CreateDirectory(".staging");

            var package = GetProtobuildBinaryPackage(protobuildMetadata);

            if (package == null)
            {
                _sourcePackageResolve.Resolve(protobuildMetadata, folder, templateName, forceUpgrade);
                return;
            }

            ExtractTo(protobuildMetadata.BinaryFormat, package, ".staging");

            _projectTemplateApplier.Apply(".staging", templateName);
            PathUtils.AggressiveDirectoryDelete(".staging");
        }
Beispiel #2
0
        private void ResolveProtobuild(string workingDirectory, ProtobuildPackageMetadata protobuildMetadata, string folder, string templateName, bool forceUpgrade)
        {
            switch (protobuildMetadata.PackageType)
            {
            case PackageManager.PACKAGE_TYPE_LIBRARY:
                ResolveLibraryBinary(workingDirectory, protobuildMetadata, Path.Combine(workingDirectory, folder), forceUpgrade, () =>
                {
                    var package = GetBinaryPackage(protobuildMetadata);
                    if (package == null)
                    {
                        _sourcePackageResolve.Resolve(workingDirectory, protobuildMetadata, folder, null, forceUpgrade);
                        return(null);
                    }
                    return(package);
                });
                break;

            case PackageManager.PACKAGE_TYPE_TEMPLATE:
                ResolveTemplateBinary(workingDirectory, protobuildMetadata, folder, templateName, forceUpgrade);
                break;

            case PackageManager.PACKAGE_TYPE_GLOBAL_TOOL:
                ResolveGlobalToolBinary(workingDirectory, protobuildMetadata, forceUpgrade);
                break;

            default:
                throw new InvalidOperationException("Unable to resolve binary package with type '" + protobuildMetadata.PackageType + "' using Protobuild-based package.");
            }
        }
Beispiel #3
0
 private byte[] DownloadBinaryPackage(ProtobuildPackageMetadata metadata)
 {
     try
     {
         return(_progressiveWebOperation.Get(metadata.BinaryURI));
     }
     catch (InvalidOperationException ex)
     {
         Console.WriteLine("Unable to download binary package for version \"" + metadata.GitCommit + "\" and platform \"" + metadata.Platform + "\", falling back to source version");
         return(null);
     }
 }
 private void ResolveProtobuild(ProtobuildPackageMetadata protobuildMetadata, string folder, string templateName, bool forceUpgrade)
 {
     ResolveGit(
         new GitPackageMetadata(
             protobuildMetadata.SourceURI,
             protobuildMetadata.GitCommit,
             protobuildMetadata.PackageType,
             (metadata, s, name, upgrade, source) => Resolve(metadata, s, name, upgrade)
             ),
         folder,
         templateName,
         forceUpgrade);
 }
Beispiel #5
0
        private bool DownloadBinaryPackage(ProtobuildPackageMetadata metadata, string targetPath)
        {
            if (File.Exists(targetPath))
            {
                File.Delete(targetPath);
            }

            var packageData = this.DownloadBinaryPackage(metadata);

            if (packageData == null)
            {
                // There is no binary package available.
                return(false);
            }

            var attempts = 10;

            while (attempts > 0)
            {
                try
                {
                    using (var stream = new FileStream(targetPath, FileMode.Create, FileAccess.Write, FileShare.None))
                    {
                        stream.Write(packageData, 0, packageData.Length);
                    }
                    break;
                }
                catch (IOException ex)
                {
                    // On Windows, we can't write out the package file if another instance of Protobuild
                    // is writing it out at the moment.  Just wait and retry in another second.
                    Console.WriteLine("WARNING: Unable to write downloaded package file (attempt " + (11 - attempts) + " / 10)");
                    System.Threading.Thread.Sleep(5000);
                    attempts--;
                }
            }

            if (attempts == 0)
            {
                Console.WriteLine(
                    "WARNING: Unable to write out downloaded package!  Assuming " +
                    "another instance of Protobuild will provide it.");
            }

            return(true);
        }
        private bool DownloadBinaryPackage(ProtobuildPackageMetadata metadata, string targetPath)
        {
            if (File.Exists(targetPath))
            {
                File.Delete(targetPath);
            }

            var packageData = this.DownloadBinaryPackage(metadata);
            if (packageData == null)
            {
                // There is no binary package available.
                return false;
            }

            var attempts = 10;
            while (attempts > 0)
            {
                try
                {
                    using (var stream = new FileStream(targetPath, FileMode.Create, FileAccess.Write, FileShare.None))
                    {
                        stream.Write(packageData, 0, packageData.Length);
                    }
                    break;
                }
                catch (IOException ex)
                {
                    // On Windows, we can't write out the package file if another instance of Protobuild
                    // is writing it out at the moment.  Just wait and retry in another second.
                    Console.WriteLine("WARNING: Unable to write downloaded package file (attempt " + (11 - attempts) + " / 10)");
                    System.Threading.Thread.Sleep(5000);
                    attempts--;
                }
            }

            if (attempts == 0)
            {
                Console.WriteLine(
                    "WARNING: Unable to write out downloaded package!  Assuming " +
                    "another instance of Protobuild will provide it.");
            }

            return true;
        }
Beispiel #7
0
        private void ResolveGlobalToolBinary(ProtobuildPackageMetadata protobuildMetadata, bool forceUpgrade)
        {
            var toolFolder = _packageGlobalTool.GetGlobalToolInstallationPath(protobuildMetadata.ReferenceURI);

            if (File.Exists(Path.Combine(toolFolder, ".pkg")))
            {
                if (!forceUpgrade)
                {
                    Console.WriteLine("Protobuild binary package already present at " + toolFolder);
                    return;
                }
            }

            Console.WriteLine("Creating and emptying " + toolFolder);
            PathUtils.AggressiveDirectoryDelete(toolFolder);
            Directory.CreateDirectory(toolFolder);

            Console.WriteLine("Installing " + protobuildMetadata.ReferenceURI + " at version " + protobuildMetadata.GitCommit);
            var package = GetProtobuildBinaryPackage(protobuildMetadata);

            if (package == null)
            {
                Console.WriteLine("The specified global tool package is not available for this platform.");
                return;
            }

            ExtractTo(protobuildMetadata.BinaryFormat, package, toolFolder);

            var file = File.Create(Path.Combine(toolFolder, ".pkg"));

            file.Close();

            _packageGlobalTool.ScanPackageForToolsAndInstall(toolFolder);

            Console.WriteLine("Binary resolution complete");
        }
 private void ResolveProtobuild(ProtobuildPackageMetadata protobuildMetadata, string folder, string templateName, bool forceUpgrade)
 {
     ResolveGit(
         new GitPackageMetadata(
             protobuildMetadata.SourceURI,
             protobuildMetadata.GitCommit,
             protobuildMetadata.PackageType,
             (metadata, s, name, upgrade, source) => Resolve(metadata, s, name, upgrade)
             ),
         folder,
         templateName,
         forceUpgrade);
 }
Beispiel #9
0
        private byte[] GetProtobuildBinaryPackage(ProtobuildPackageMetadata metadata)
        {
            if (metadata.BinaryFormat == null && metadata.BinaryURI == null)
            {
                // There is no binary format for this package.
                return(null);
            }

            var localFileExists = false;

            try
            {
                localFileExists = File.Exists(metadata.BinaryURI);
            }
            catch
            {
            }

            if (metadata.BinaryFormat != null && localFileExists)
            {
                // This is a local package file, read it directly.
                using (var stream = new FileStream(metadata.BinaryURI, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    var data = new byte[stream.Length];
                    stream.Read(data, 0, data.Length);
                    return(data);
                }
            }

            if (this.HasBinaryPackage(metadata))
            {
                // We have it already downloaded in the cache.
                var file = Path.Combine(
                    _packageCacheConfiguration.GetCacheDirectory(),
                    this.GetPackageName(metadata));
                using (var stream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    var data = new byte[stream.Length];
                    stream.Read(data, 0, data.Length);
                    return(data);
                }
            }

            // We must use the package retrieval interface to download a copy
            // of the package.
            var tempFile = Path.Combine(
                _packageCacheConfiguration.GetCacheDirectory(),
                this.GetPackageName(metadata) + ".tmp");

            if (!DownloadBinaryPackage(metadata, tempFile))
            {
                return(null);
            }

            var saveFile = Path.Combine(
                _packageCacheConfiguration.GetCacheDirectory(),
                this.GetPackageName(metadata));

            try
            {
                File.Move(tempFile, saveFile);
            }
            catch (Exception)
            {
                Console.WriteLine("WARNING: Unable to save package to cache.");
                saveFile = tempFile;
            }

            byte[] saveData;
            using (var stream = new FileStream(saveFile, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                saveData = new byte[stream.Length];
                stream.Read(saveData, 0, saveData.Length);
            }

            if (saveFile == tempFile)
            {
                File.Delete(tempFile);
            }

            return(saveData);
        }
        private void ResolveTemplateBinary(ProtobuildPackageMetadata protobuildMetadata, string folder, string templateName, bool forceUpgrade)
        {
            if (folder != string.Empty)
            {
                throw new InvalidOperationException("Reference folder must be empty for template type.");
            }

            // The template is a reference to a Git repository.
            if (Directory.Exists(".staging"))
            {
                PathUtils.AggressiveDirectoryDelete(".staging");
            }

            Directory.CreateDirectory(".staging");

            var package = GetProtobuildBinaryPackage(protobuildMetadata);
            if (package == null)
            {
                _sourcePackageResolve.Resolve(protobuildMetadata, folder, templateName, forceUpgrade);
                return;
            }

            ExtractTo(protobuildMetadata.BinaryFormat, package, ".staging");

            _projectTemplateApplier.Apply(".staging", templateName);
            PathUtils.AggressiveDirectoryDelete(".staging");
        }
 private void ResolveProtobuild(ProtobuildPackageMetadata protobuildMetadata, string folder, string templateName, bool forceUpgrade)
 {
     switch (protobuildMetadata.PackageType)
     {
         case PackageManager.PACKAGE_TYPE_LIBRARY:
             ResolveLibraryBinary(protobuildMetadata, folder, forceUpgrade, () =>
             {
                 var package = GetProtobuildBinaryPackage(protobuildMetadata);
                 if (package == null)
                 {
                     _sourcePackageResolve.Resolve(protobuildMetadata, folder, null, forceUpgrade);
                     return null;
                 }
                 return package;
             });
             break;
         case PackageManager.PACKAGE_TYPE_TEMPLATE:
             ResolveTemplateBinary(protobuildMetadata, folder, templateName, forceUpgrade);
             break;
         case PackageManager.PACKAGE_TYPE_GLOBAL_TOOL:
             ResolveGlobalToolBinary(protobuildMetadata, forceUpgrade);
             break;
         default:
             throw new InvalidOperationException("Unable to resolve binary package with type '" + protobuildMetadata.PackageType + "' using Protobuild-based package.");
     }
 }
        private void ResolveGlobalToolBinary(ProtobuildPackageMetadata protobuildMetadata, bool forceUpgrade)
        {
            var toolFolder = _packageGlobalTool.GetGlobalToolInstallationPath(protobuildMetadata.ReferenceURI);

            if (File.Exists(Path.Combine(toolFolder, ".pkg")))
            {
                if (!forceUpgrade)
                {
                    Console.WriteLine("Protobuild binary package already present at " + toolFolder);
                    return;
                }
            }

            Console.WriteLine("Creating and emptying " + toolFolder);
            PathUtils.AggressiveDirectoryDelete(toolFolder);
            Directory.CreateDirectory(toolFolder);

            Console.WriteLine("Installing " + protobuildMetadata.ReferenceURI + " at version " + protobuildMetadata.GitCommit);
            var package = GetProtobuildBinaryPackage(protobuildMetadata);
            if (package == null)
            {
                Console.WriteLine("The specified global tool package is not available for this platform.");
                return;
            }

            ExtractTo(protobuildMetadata.BinaryFormat, package, toolFolder);

            var file = File.Create(Path.Combine(toolFolder, ".pkg"));
            file.Close();

            _packageGlobalTool.ScanPackageForToolsAndInstall(toolFolder);

            Console.WriteLine("Binary resolution complete");
        }
        private byte[] GetProtobuildBinaryPackage(ProtobuildPackageMetadata metadata)
        {
            if (metadata.BinaryFormat == null && metadata.BinaryURI == null)
            {
                // There is no binary format for this package.
                return null;
            }

            var localFileExists = false;
            try
            {
                localFileExists = File.Exists(metadata.BinaryURI);
            }
            catch
            {
            }

            if (metadata.BinaryFormat != null && localFileExists)
            {
                // This is a local package file, read it directly.
                using (var stream = new FileStream(metadata.BinaryURI, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    var data = new byte[stream.Length];
                    stream.Read(data, 0, data.Length);
                    return data;
                }
            }

            if (this.HasBinaryPackage(metadata))
            {
                // We have it already downloaded in the cache.
                var file = Path.Combine(
                    _packageCacheConfiguration.GetCacheDirectory(),
                    this.GetPackageName(metadata));
                using (var stream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    var data = new byte[stream.Length];
                    stream.Read(data, 0, data.Length);
                    return data;
                }
            }

            // We must use the package retrieval interface to download a copy
            // of the package.
            var tempFile = Path.Combine(
                _packageCacheConfiguration.GetCacheDirectory(),
                this.GetPackageName(metadata) + ".tmp");
            if (!DownloadBinaryPackage(metadata, tempFile))
            {
                return null;
            }

            var saveFile = Path.Combine(
                _packageCacheConfiguration.GetCacheDirectory(),
                this.GetPackageName(metadata));
            try
            {
                File.Move(tempFile, saveFile);
            }
            catch (Exception)
            {
                Console.WriteLine("WARNING: Unable to save package to cache.");
                saveFile = tempFile;
            }

            byte[] saveData;
            using (var stream = new FileStream(saveFile, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                saveData = new byte[stream.Length];
                stream.Read(saveData, 0, saveData.Length);
            }

            if (saveFile == tempFile)
            {
                File.Delete(tempFile);
            }

            return saveData;
        }
 private byte[] DownloadBinaryPackage(ProtobuildPackageMetadata metadata)
 {
     try
     {
         return _progressiveWebOperation.Get(metadata.BinaryURI);
     }
     catch (InvalidOperationException ex)
     {
         Console.WriteLine("Unable to download binary package for version \"" + metadata.GitCommit + "\" and platform \"" + metadata.Platform + "\", falling back to source version");
         return null;
     }
 }