// ReSharper disable UnusedParameter.Local
        void CheckArguments(
            string packageId,
            string packageVersion,
            string feedId,
            string feedUri,
            string feedUsername,
            string feedPassword,
            string maxDownloadAttempts,
            string attemptBackoffSeconds,
            out IVersion version,
            out Uri uri,
            out int parsedMaxDownloadAttempts,
            out TimeSpan parsedAttemptBackoff)
        {
            Guard.NotNullOrWhiteSpace(packageId, "No package ID was specified. Please pass --packageId YourPackage");
            Guard.NotNullOrWhiteSpace(packageVersion, "No package version was specified. Please pass --packageVersion 1.0.0.0");
            Guard.NotNullOrWhiteSpace(feedId, "No feed ID was specified. Please pass --feedId feed-id");
            Guard.NotNullOrWhiteSpace(feedUri, "No feed URI was specified. Please pass --feedUri https://url/to/nuget/feed");

            version = VersionFactory.TryCreateVersion(packageVersion, versionFormat);
            if (version == null)
            {
                throw new CommandException($"Package version '{packageVersion}' specified is not a valid {versionFormat.ToString()} version string");
            }

            if (!Uri.TryCreate(feedUri, UriKind.Absolute, out uri))
            {
                throw new CommandException($"URI specified '{feedUri}' is not a valid URI");
            }

            if (!String.IsNullOrWhiteSpace(feedUsername) && String.IsNullOrWhiteSpace(feedPassword))
            {
                throw new CommandException("A username was specified but no password was provided. Please pass --feedPassword \"FeedPassword\"");
            }

            if (!int.TryParse(maxDownloadAttempts, out parsedMaxDownloadAttempts))
            {
                throw new CommandException($"The requested number of download attempts '{maxDownloadAttempts}' is not a valid integer number");
            }

            if (parsedMaxDownloadAttempts <= 0)
            {
                throw new CommandException("The requested number of download attempts should be more than zero");
            }

            int parsedAttemptBackoffSeconds;

            if (!int.TryParse(attemptBackoffSeconds, out parsedAttemptBackoffSeconds))
            {
                throw new CommandException($"Retry requested download attempt retry backoff '{attemptBackoffSeconds}' is not a valid integer number of seconds");
            }

            if (parsedAttemptBackoffSeconds < 0)
            {
                throw new CommandException("The requested download attempt retry backoff should be a positive integer number of seconds");
            }

            parsedAttemptBackoff = TimeSpan.FromSeconds(parsedAttemptBackoffSeconds);
        }
Example #2
0
        static IVersion?TryParseVersion(string input)
        {
            if (input == null)
            {
                return(null);
            }

            if (input[0].Equals('v') || input[0].Equals('V'))
            {
                input = input.Substring(1);
            }

            return(VersionFactory.TryCreateVersion(input, VersionFormat.Semver));
        }
Example #3
0
        static bool TryParseVersion(string input, out IVersion version)
        {
            if (input == null)
            {
                version = null;
                return(false);
            }

            if (input[0].Equals('v') || input[0].Equals('V'))
            {
                input = input.Substring(1);
            }

            return(VersionFactory.TryCreateVersion(input, out version, VersionFormat.Semver));
        }
Example #4
0
        public override int Execute(string[] commandLineArguments)
        {
            Options.Parse(commandLineArguments);

            Guard.NotNullOrWhiteSpace(packageId, "No package ID was specified. Please pass --packageId YourPackage");
            Guard.NotNullOrWhiteSpace(rawPackageVersion, "No package version was specified. Please pass --packageVersion 1.0.0.0");
            Guard.NotNullOrWhiteSpace(packageHash, "No package hash was specified. Please pass --packageHash YourPackageHash");

            var fileSystem   = CalamariPhysicalFileSystem.GetPhysicalFileSystem();
            var extractor    = new GenericPackageExtractorFactory().createJavaGenericPackageExtractor(fileSystem);
            var packageStore = new PackageStore(extractor);

            if (!VersionFactory.TryCreateVersion(rawPackageVersion, out IVersion version, versionFormat))
            {
                throw new CommandException($"Package version '{rawPackageVersion}' is not a valid {versionFormat} version string. Please pass --packageVersionFormat with a different version type.");
            }
            ;

            var package = packageStore.GetPackage(packageId, version, packageHash);

            if (package == null)
            {
                Log.Verbose($"Package {packageId} version {version} hash {packageHash} has not been uploaded.");

                if (exactMatchOnly)
                {
                    return(0);
                }

                FindEarlierPackages(packageStore, version);

                return(0);
            }

            Log.VerboseFormat("Package {0} {1} hash {2} has already been uploaded", package.PackageId, package.Version, package.Hash);
            Log.ServiceMessages.PackageFound(
                package.PackageId,
                package.Version,
                package.Hash,
                package.Extension,
                package.FullFilePath,
                true);
            return(0);
        }
        public override int Execute(string[] commandLineArguments)
        {
            Options.Parse(commandLineArguments);

            Guard.NotNullOrWhiteSpace(packageId, "No package ID was specified. Please pass --packageId YourPackage");
            Guard.NotNullOrWhiteSpace(rawPackageVersion, "No package version was specified. Please pass --packageVersion 1.0.0.0");
            Guard.NotNullOrWhiteSpace(packageHash, "No package hash was specified. Please pass --packageHash YourPackageHash");

            var version = VersionFactory.TryCreateVersion(rawPackageVersion, versionFormat);

            if (version == null)
            {
                throw new CommandException($"Package version '{rawPackageVersion}' is not a valid {versionFormat} version string. Please pass --packageVersionFormat with a different version type.");
            }

            var package = packageStore.GetPackage(packageId, version, packageHash);

            if (package == null)
            {
                log.Verbose($"Package {packageId} version {version} hash {packageHash} has not been uploaded.");

                if (exactMatchOnly)
                {
                    return(0);
                }

                FindEarlierPackages(version);

                return(0);
            }

            log.VerboseFormat("Package {0} {1} hash {2} has already been uploaded", package.PackageId, package.Version, package.Hash);
            LogPackageFound(
                package.PackageId,
                package.Version,
                package.Hash,
                package.Extension,
                package.FullFilePath,
                true
                );
            return(0);
        }
 public RegisterPackageUseCommand(ILog log, IManagePackageCache journal, ICalamariFileSystem fileSystem)
 {
     this.log        = log;
     this.journal    = journal;
     this.fileSystem = fileSystem;
     Options.Add("packageId=", "Package ID of the used package", v => packageId = new PackageId(v));
     Options.Add("packageVersionFormat=", $"[Optional] Format of version. Options {string.Join(", ", Enum.GetNames(typeof(VersionFormat)))}. Defaults to `{VersionFormat.Semver}`.",
                 v =>
     {
         if (!Enum.TryParse(v, out VersionFormat format))
         {
             throw new CommandException($"The provided version format `{format}` is not recognised.");
         }
         versionFormat = format;
     });
     Options.Add("packageVersion=", "Package version of the used package", v => packageVersion = VersionFactory.TryCreateVersion(v, versionFormat));
     Options.Add("packagePath=", "Path to the package", v => packagePath            = new PackagePath(v));
     Options.Add("taskId=", "Id of the task that is using the package", v => taskId = new ServerTaskId(v));
 }