public async Task Request()
        {
            if (string.IsNullOrEmpty(File))
            {
                throw new CommandException("Please specify the build information file.");
            }
            if (PackageIds.None())
            {
                throw new CommandException("Please specify at least one package id.");
            }
            if (string.IsNullOrEmpty(Version))
            {
                throw new CommandException("Please specify the package version.");
            }

            if (!FileSystem.FileExists(File))
            {
                throw new CommandException($"Build information file '{File}' does not exist");
            }

            var fileContent = FileSystem.ReadAllText(File);

            var buildInformation = JsonConvert.DeserializeObject <OctopusBuildInformation>(fileContent);

            foreach (var packageId in PackageIds)
            {
                commandOutputProvider.Debug("Pushing build information for package {PackageId} version {Version}...", packageId, Version);
                resultResource = await Repository.BuildInformationRepository.Push(packageId, Version, buildInformation, OverwriteMode);

                pushedBuildInformation.Add(resultResource);
            }
        }
示例#2
0
        public async Task Request()
        {
            if (string.IsNullOrEmpty(File))
            {
                throw new CommandException("Please specify the build information file.");
            }
            if (PackageIds.None())
            {
                throw new CommandException("Please specify at least one package id.");
            }
            if (string.IsNullOrEmpty(Version))
            {
                throw new CommandException("Please specify the package version.");
            }

            if (!FileSystem.FileExists(File))
            {
                throw new CommandException($"Build information file '{File}' does not exist");
            }

            var fileContent = FileSystem.ReadAllText(File);

            var rootDocument = await Repository.LoadRootDocument();

            if (rootDocument.HasLink("BuildInformation"))
            {
                var buildInformation = JsonConvert.DeserializeObject <OctopusBuildInformation>(fileContent);

                foreach (var packageId in PackageIds)
                {
                    commandOutputProvider.Debug("Pushing build information for package {PackageId} version {Version}...", packageId, Version);
                    resultResource = await Repository.BuildInformationRepository.Push(packageId, Version, buildInformation, OverwriteMode);

                    pushedBuildInformation.Add(resultResource);
                }
            }
            else
            {
                commandOutputProvider.Warning("Detected Octopus server version doesn't support the Build Information API.");

                var metadata = JsonConvert.DeserializeObject <OctopusPackageMetadata>(fileContent);
                // old server won't parse without the CommentParser being set, default it to Jira
                metadata.CommentParser = "Jira";

                foreach (var packageId in PackageIds)
                {
                    commandOutputProvider.Debug("Pushing build information as legacy package metadata for package {PackageId} version {Version}...", packageId, Version);
                    var result = await Repository.PackageMetadataRepository.Push(packageId, Version, metadata, OverwriteMode);
                }
            }
        }
示例#3
0
 public void InvokeAction(T connection, object parsedData, PackageIds packageIds)
 {
     foreach (MethodInfo method in GetType().GetMethods())
     {
         PackageHandler attribute = method.GetCustomAttribute <PackageHandler>();
         if (attribute == null)
         {
             continue;
         }
         if (attribute.PackageId != packageIds)
         {
             continue;
         }
         method.Invoke(this, new[] { connection, parsedData });
         return;
     }
     HandleUnknownPacket(connection, parsedData, packageIds);
 }
示例#4
0
        private List <string> GetPackageIds()
        {
            //Get the list of packages from either PackageIds or PackageIdsFilePath Argument.
            List <string> PackagesList = new List <string>();

            if (!string.IsNullOrEmpty(PackageIds))
            {
                PackagesList = PackageIds.Split(new char[] { ',' }).ToList();
            }
            else if (!string.IsNullOrEmpty(PackageIdsFilePath))
            {
                StreamReader packages = new StreamReader(PackageIdsFilePath);
                while (packages.EndOfStream == false)
                {
                    PackagesList.Add(packages.ReadLine());
                }
                packages.Close();
            }
            return(PackagesList);
        }
示例#5
0
        public BuildInformationCommand(IOctopusAsyncRepositoryFactory repositoryFactory, IOctopusFileSystem fileSystem, IOctopusClientFactory clientFactory, ICommandOutputProvider commandOutputProvider)
            : base(clientFactory, repositoryFactory, fileSystem, commandOutputProvider)
        {
            var options = Options.For("Build information pushing");

            options.Add <string>("package-id=", "The ID of the package. Specify multiple packages by specifying this argument multiple times: \n--package-id 'MyCompany.MyApp' --package-id 'MyCompany.MyApp2'.", packageId => PackageIds.Add(packageId), allowsMultiple: true);
            options.Add <string>("version=", "The version of the package; defaults to a timestamp-based version.", v => Version = v);
            options.Add <string>("file=", "Octopus Build Information Json file.", file => File = file);
            options.Add <OverwriteMode>("overwrite-mode=", $"Determines behavior if the package already exists in the repository. Valid values are {Enum.GetNames(typeof(OverwriteMode)).ReadableJoin()}. Default is {DefaultOverwriteMode}.", mode => OverwriteMode = mode);

            pushedBuildInformation = new List <OctopusPackageVersionBuildInformationMappedResource>();
        }
示例#6
0
        public override bool Execute()
        {
            string indexFilePath = PackageIndexFile.GetMetadata("FullPath");

            PackageIndex index = File.Exists(indexFilePath) ?
                                 index = PackageIndex.Load(indexFilePath) :
                                         new PackageIndex();

            if (PackageIds != null && PackageIds.Any())
            {
                _packageIdsToInclude = new HashSet <string>(PackageIds.Select(i => i.ItemSpec), StringComparer.OrdinalIgnoreCase);
            }

            foreach (var package in Packages.NullAsEmpty().Select(f => f.GetMetadata("FullPath")))
            {
                Log.LogMessage($"Updating from {package}.");
                UpdateFromPackage(index, package);
            }

            foreach (var packageFolder in PackageFolders.NullAsEmpty().Select(f => f.GetMetadata("FullPath")))
            {
                var nupkgs = Directory.EnumerateFiles(packageFolder, "*.nupkg", SearchOption.TopDirectoryOnly);

                if (nupkgs.Any())
                {
                    foreach (var nupkg in nupkgs)
                    {
                        Log.LogMessage($"Updating from {nupkg}.");
                        UpdateFromPackage(index, nupkg, true);
                    }
                }
                else
                {
                    var nuspecFolders = Directory.EnumerateFiles(packageFolder, "*.nuspec", SearchOption.AllDirectories)
                                        .Select(nuspec => Path.GetDirectoryName(nuspec));

                    foreach (var nuspecFolder in nuspecFolders)
                    {
                        Log.LogMessage($"Updating from {nuspecFolder}.");
                        UpdateFromFolderLayout(index, nuspecFolder, true);
                    }
                }
            }

            if (BaselinePackages != null)
            {
                foreach (var baselinePackage in BaselinePackages)
                {
                    var info    = GetOrCreatePackageInfo(index, baselinePackage.ItemSpec);
                    var version = baselinePackage.GetMetadata("Version");

                    info.BaselineVersion = Version.Parse(version);
                }
            }

            if (StablePackages != null)
            {
                foreach (var stablePackage in StablePackages)
                {
                    var info    = GetOrCreatePackageInfo(index, stablePackage.ItemSpec);
                    var version = stablePackage.GetMetadata("Version");

                    info.StableVersions.Add(Version.Parse(version));
                }
            }

            if (ModuleToPackages != null)
            {
                foreach (var moduleToPackage in ModuleToPackages)
                {
                    var package = moduleToPackage.GetMetadata("Package");
                    index.ModulesToPackages[moduleToPackage.ItemSpec] = package;
                }
            }

            if (!String.IsNullOrEmpty(PreRelease))
            {
                index.PreRelease = PreRelease;
            }

            index.Save(indexFilePath);

            return(!Log.HasLoggedErrors);
        }
示例#7
0
 protected abstract void HandleUnknownPacket(T connection, object parsedData, PackageIds type);
示例#8
0
 public PackageHandler(PackageIds packageId)
 {
     this.PackageId = packageId;
 }
 protected Package(PackageIds packageId) => this.PackageId = packageId;
 public PackageRpc(PackageIds packageId) => this.PackageId = packageId;
示例#11
0
        public BuildInformationCommand(IOctopusAsyncRepositoryFactory repositoryFactory, IOctopusFileSystem fileSystem, IOctopusClientFactory clientFactory, ICommandOutputProvider commandOutputProvider)
            : base(clientFactory, repositoryFactory, fileSystem, commandOutputProvider)
        {
            var options = Options.For("Build information pushing");

            options.Add("package-id=", "The ID of the package. Specify multiple packages by specifying this argument multiple times: \n--package-id 'MyCompany.MyApp' --package-id 'MyCompany.MyApp2'.", packageId => PackageIds.Add(packageId));
            options.Add("version=", "The version of the package; defaults to a timestamp-based version", v => Version = v);
            options.Add("file=", "Octopus Build Information Json file.", file => File = file);
            options.Add("overwrite-mode=", "If the build information already exists in the repository, the default behavior is to reject the new build information being pushed (FailIfExists). You can use the overwrite mode to OverwriteExisting or IgnoreIfExists.", mode => OverwriteMode = (OverwriteMode)Enum.Parse(typeof(OverwriteMode), mode, true));

            pushedBuildInformation = new List <OctopusPackageVersionBuildInformationMappedResource>();
        }
示例#12
0
        public override bool Execute()
        {
            string indexFilePath = PackageIndexFile.GetMetadata("FullPath");

            PackageIndex index = File.Exists(indexFilePath) ?
                                 index = PackageIndex.Load(indexFilePath) :
                                         new PackageIndex();

            if (PackageIds != null && PackageIds.Any())
            {
                _packageIdsToInclude = new HashSet <string>(PackageIds.Select(i => i.ItemSpec), StringComparer.OrdinalIgnoreCase);
            }

            foreach (var package in Packages.NullAsEmpty().Select(f => f.GetMetadata("FullPath")))
            {
                Log.LogMessage($"Updating from {package}.");
                UpdateFromPackage(index, package);
            }

            foreach (var packageFolder in PackageFolders.NullAsEmpty().Select(f => f.GetMetadata("FullPath")))
            {
                var nupkgs = Directory.EnumerateFiles(packageFolder, "*.nupkg", SearchOption.TopDirectoryOnly);

                if (nupkgs.Any())
                {
                    foreach (var nupkg in nupkgs)
                    {
                        Log.LogMessage($"Updating from {nupkg}.");
                        UpdateFromPackage(index, nupkg, true);
                    }
                }
                else
                {
                    var nuspecFolders = Directory.EnumerateFiles(packageFolder, "*.nuspec", SearchOption.AllDirectories)
                                        .Select(nuspec => Path.GetDirectoryName(nuspec));

                    foreach (var nuspecFolder in nuspecFolders)
                    {
                        Log.LogMessage($"Updating from {nuspecFolder}.");
                        UpdateFromFolderLayout(index, nuspecFolder, true);
                    }
                }
            }

            if (BaselinePackages != null)
            {
                foreach (var baselinePackage in BaselinePackages)
                {
                    var info    = GetOrCreatePackageInfo(index, baselinePackage.ItemSpec);
                    var version = baselinePackage.GetMetadata("Version");

                    info.BaselineVersion = Version.Parse(version);
                }
            }

            if (StablePackages != null)
            {
                foreach (var stablePackage in StablePackages)
                {
                    var info    = GetOrCreatePackageInfo(index, stablePackage.ItemSpec);
                    var version = stablePackage.GetMetadata("Version");

                    info.StableVersions.Add(Version.Parse(version));
                }
            }

            if (ModuleToPackages != null)
            {
                foreach (var moduleToPackage in ModuleToPackages)
                {
                    var package = moduleToPackage.GetMetadata("Package");
                    index.ModulesToPackages[moduleToPackage.ItemSpec] = package;
                }
            }

            if (InboxFrameworkListFolder != null)
            {
                index.MergeFrameworkLists(InboxFrameworkListFolder.GetMetadata("FullPath"));
            }

            if (InboxFrameworkLayoutFolders != null)
            {
                foreach (var inboxFrameworkLayoutFolder in InboxFrameworkLayoutFolders)
                {
                    var layoutDirectory = inboxFrameworkLayoutFolder.GetMetadata("FullPath");
                    var targetFramework = NuGetFramework.Parse(inboxFrameworkLayoutFolder.GetMetadata("TargetFramework"));

                    index.MergeInboxFromLayout(targetFramework, layoutDirectory);
                }
            }

            if (SetBaselineVersionsToLatestStableVersion)
            {
                foreach (var packageInfo in index.Packages.Values)
                {
                    var maxVersion = packageInfo.StableVersions.Max();
                    packageInfo.BaselineVersion = maxVersion;
                }
            }

            if (UpdateStablePackageInfo && Packages == null && PackageFolders == null)
            {
                // Given we will query the web for every package, we should run in parallel to try to optimize the performance.
                Parallel.ForEach(index.Packages, (package) =>
                {
                    IEnumerable <Version> stablePackageVersions = NuGetUtility.GetAllVersionsForPackageId(package.Key, includePrerelease: false, includeUnlisted: false, Log, CancellationToken.None);
                    package.Value.StableVersions.Clear();
                    package.Value.StableVersions.AddRange(stablePackageVersions);
                });
            }

            if (!String.IsNullOrEmpty(PreRelease))
            {
                index.PreRelease = PreRelease;
            }

            index.Save(indexFilePath);

            return(!Log.HasLoggedErrors);
        }
示例#13
0
 protected override void HandleUnknownPacket(ClientConnection connection, object parsedData, PackageIds type)
 {
 }