Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ferventcoder committed Jan 4, 2017
1 parent 16fe0c8 commit d20fc60
Show file tree
Hide file tree
Showing 7 changed files with 265 additions and 31 deletions.
2 changes: 2 additions & 0 deletions src/chocolatey/chocolatey.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@
<Compile Include="infrastructure.app\domain\RegistryValueExtensions.cs" />
<Compile Include="infrastructure.app\domain\RegistryValueKindType.cs" />
<Compile Include="infrastructure.app\events\HandlePackageResultCompletedMessage.cs" />
<Compile Include="infrastructure.app\nuget\ChocolateyPackage.cs" />
<Compile Include="infrastructure.app\nuget\ChocolateyPackageDownloader.cs" />
<Compile Include="infrastructure.app\services\FileTypeDetectorService.cs" />
<Compile Include="infrastructure.app\services\IFileTypeDetectorService.cs" />
<Compile Include="infrastructure\registration\SecurityProtocol.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

namespace chocolatey.infrastructure.app.nuget
{
using logging;
using NuGet;

// ReSharper disable InconsistentNaming
Expand All @@ -41,7 +42,13 @@ public void Log(MessageLevel level, string message, params object[] args)
break;
case MessageLevel.Error:
this.Log().Error("[NuGet] " + message, args);
break;
break;
//todo: case MessageLevel.Fatal:
// this.Log().Fatal("[NuGet] " + message, args);
// break;
//case MessageLevel.Verbose:
// this.Log().Info(ChocolateyLoggers.Verbose,"[NuGet] " + message, args);
// break;
}
}
}
Expand Down
117 changes: 117 additions & 0 deletions src/chocolatey/infrastructure.app/nuget/ChocolateyPackage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// Copyright © 2011 - Present RealDimensions Software, LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
//
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace chocolatey.infrastructure.app.nuget
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Versioning;
using NuGet;

public class ChocolateyPackage : IPackage
{
private readonly IPackage _package;

public ChocolateyPackage(IPackage package)
{
_package = package;
}

public string Id { get; set; }
public SemanticVersion Version { get; set; }
public Uri ProjectSourceUrl { get; set; }
public Uri PackageSourceUrl { get; set; }
public Uri DocsUrl { get; set; }
public Uri WikiUrl { get; set; }
public Uri MailingListUrl { get; set; }
public Uri BugTrackerUrl { get; set; }
public IEnumerable<string> Replaces { get; set; }
public IEnumerable<string> Provides { get; set; }
public IEnumerable<string> Conflicts { get; set; }
public string Title { get; set; }
public IEnumerable<string> Authors { get; set; }
public IEnumerable<string> Owners { get; set; }
public Uri IconUrl { get; set; }
public Uri LicenseUrl { get; set; }
public Uri ProjectUrl { get; set; }
public bool RequireLicenseAcceptance { get; set; }
public bool DevelopmentDependency { get; set; }
public string Description { get; set; }
public string Summary { get; set; }
public string ReleaseNotes { get; set; }
public string Language { get; set; }
public string Tags { get; set; }
public string Copyright { get; set; }
public IEnumerable<FrameworkAssemblyReference> FrameworkAssemblies { get; set; }
public ICollection<PackageReferenceSet> PackageAssemblyReferences { get; set; }
public IEnumerable<PackageDependencySet> DependencySets { get; set; }
public Version MinClientVersion { get; set; }
public string PackageHash { get; set; }
public string PackageHashAlgorithm { get; set; }
public long PackageSize { get; set; }
public int VersionDownloadCount { get; set; }
public bool IsApproved { get; set; }
public string PackageStatus { get; set; }
public string PackageSubmittedStatus { get; set; }
public string PackageTestResultStatus { get; set; }
public DateTime? PackageTestResultStatusDate { get; set; }
public string PackageValidationResultStatus { get; set; }
public DateTime? PackageValidationResultDate { get; set; }
public DateTime? PackageCleanupResultDate { get; set; }
public DateTime? PackageReviewedDate { get; set; }
public DateTime? PackageApprovedDate { get; set; }
public string PackageReviewer { get; set; }
public bool IsDownloadCacheAvailable { get; set; }
public DateTime? DownloadCacheDate { get; set; }
public IEnumerable<DownloadCache> DownloadCache { get; set; }
public Uri ReportAbuseUrl { get; set; }
public int DownloadCount { get; set; }

public bool IsAbsoluteLatestVersion { get; set; }
public bool IsLatestVersion { get; set; }
public bool Listed { get; set; }
public DateTimeOffset? Published { get; set; }
public IEnumerable<IPackageAssemblyReference> AssemblyReferences { get; set; }


public IEnumerable<IPackageFile> GetFiles()
{
if (_package != null) return _package.GetFiles();

throw new NotImplementedException("If there is no underlying package passed in, ChocolateyPackage doesn't yet support this method call.");
}

public IEnumerable<FrameworkName> GetSupportedFrameworks()
{
if (_package != null) return _package.GetSupportedFrameworks();

throw new NotImplementedException("If there is no underlying package passed in, ChocolateyPackage doesn't yet support this method call.");
}

public Stream GetStream()
{
if (_package != null) return _package.GetStream();

throw new NotImplementedException("If there is no underlying package passed in, ChocolateyPackage doesn't yet support this method call.");
}

public void ExtractContents(IFileSystem fileSystem, string extractPath)
{
if (_package != null) _package.ExtractContents(fileSystem, extractPath);
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Copyright © 2011 - Present RealDimensions Software, LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
//
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace chocolatey.infrastructure.app.nuget
{
using System;
using System.Globalization;
using System.IO;
using NuGet;
using NuGet.Resources;

// ReSharper disable InconsistentNaming

//public sealed class ChocolateyPackageDownloader : PackageDownloader, IPackageDownloader
//{
// private const string DefaultUserAgentClient = "Chocolatey Core";

// public override void DownloadPackage(Uri uri, IPackageMetadata package, Stream targetStream)
// {
// if (uri == null)
// {
// throw new ArgumentNullException("uri");
// }

// var downloadClient = new HttpClient(uri)
// {
// UserAgent = HttpUtility.CreateUserAgentString(DefaultUserAgentClient)
// };
// DownloadPackage(downloadClient, package, targetStream);
// }

// public override void DownloadPackage(IHttpClient downloadClient, IPackageName package, Stream targetStream)
// {
// if (downloadClient == null)
// {
// throw new ArgumentNullException("downloadClient");
// }

// if (targetStream == null)
// {
// throw new ArgumentNullException("targetStream");
// }

// // Get the operation display text
// string operation = String.Format(CultureInfo.CurrentCulture, NuGetResources.DownloadProgressStatus, package.Id, package.Version);
// CurrentDownloadPackageId = package.Id;

// EventHandler<ProgressEventArgs> progressAvailableHandler = (sender, e) => { OnPackageDownloadProgress(new ProgressEventArgs(operation, e.PercentComplete)); };

// try
// {
// downloadClient.ProgressAvailable += progressAvailableHandler;
// downloadClient.SendingRequest += OnSendingRequest;

// downloadClient.DownloadData(targetStream);
// }
// finally
// {
// downloadClient.ProgressAvailable -= progressAvailableHandler;
// downloadClient.SendingRequest -= OnSendingRequest;
// CurrentDownloadPackageId = null;
// }
// }

// protected override void OnPackageDownloadProgress(ProgressEventArgs e)
// {
// ProgressAvailable(this, e);
// }

// protected override void OnSendingRequest(object sender, WebRequestEventArgs webRequestArgs)
// {
// SendingRequest(this, webRequestArgs);
// }
//}

// ReSharper restore InconsistentNaming
}
55 changes: 28 additions & 27 deletions src/chocolatey/infrastructure.app/nuget/NugetCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,22 @@ public sealed class NugetCommon
{
public static IFileSystem GetNuGetFileSystem(ChocolateyConfiguration configuration, ILogger nugetLogger)
{
var fileSystem = new ChocolateyPhysicalFileSystem(ApplicationParameters.PackagesLocation);
if (configuration.Debug)
{
fileSystem.Logger = nugetLogger;
}

return fileSystem;
return new ChocolateyPhysicalFileSystem(ApplicationParameters.PackagesLocation) { Logger = nugetLogger };
}

public static IPackagePathResolver GetPathResolver(ChocolateyConfiguration configuration, IFileSystem nugetPackagesFileSystem)
{
return new ChocolateyPackagePathResolver(nugetPackagesFileSystem, configuration.AllowMultipleVersions);
}

public static IPackageRepository GetLocalRepository(IPackagePathResolver pathResolver, IFileSystem nugetPackagesFileSystem)
public static IPackageRepository GetLocalRepository(IPackagePathResolver pathResolver, IFileSystem nugetPackagesFileSystem, ILogger nugetLogger)
{
IPackageRepository localRepository = new ChocolateyLocalPackageRepository(pathResolver, nugetPackagesFileSystem);
localRepository.PackageSaveMode = PackageSaveModes.Nupkg | PackageSaveModes.Nuspec;

return localRepository;
return new ChocolateyLocalPackageRepository(pathResolver, nugetPackagesFileSystem)
{ Logger = nugetLogger, PackageSaveMode = PackageSaveModes.Nupkg | PackageSaveModes.Nuspec };
}

public static IPackageRepository GetRemoteRepository(ChocolateyConfiguration configuration, ILogger nugetLogger)
//public static IPackageRepository GetRemoteRepository(ChocolateyConfiguration configuration, ILogger nugetLogger, IPackageDownloader packageDownloader)
public static IPackageRepository GetRemoteRepository(ChocolateyConfiguration configuration, ILogger nugetLogger, PackageDownloader packageDownloader)
{
IEnumerable<string> sources = configuration.Sources.Split(new[] {";", ","}, StringSplitOptions.RemoveEmptyEntries);

Expand Down Expand Up @@ -100,16 +93,20 @@ public static IPackageRepository GetRemoteRepository(ChocolateyConfiguration con
var uri = new Uri(source);
if (uri.IsFile || uri.IsUnc)
{
repositories.Add(new ChocolateyLocalPackageRepository(uri.LocalPath));
repositories.Add(new ChocolateyLocalPackageRepository(uri.LocalPath){ Logger = nugetLogger });
}
else
{
repositories.Add(new DataServicePackageRepository(new RedirectedHttpClient(uri)));
var httpClient = new RedirectedHttpClient(uri)
{
UserAgent = "Chocolatey Core"
};
repositories.Add(new DataServicePackageRepository(httpClient, packageDownloader) { Logger = nugetLogger });
}
}
catch (Exception)
{
repositories.Add(new ChocolateyLocalPackageRepository(source));
repositories.Add(new ChocolateyLocalPackageRepository(source){ Logger = nugetLogger });
}
}

Expand All @@ -119,33 +116,37 @@ public static IPackageRepository GetRemoteRepository(ChocolateyConfiguration con
}

//todo well that didn't work on failing repos... grrr
var repository = new AggregateRepository(repositories) {IgnoreFailingRepositories = true};
repository.ResolveDependenciesVertically = true;
if (configuration.Debug)
var repository = new AggregateRepository(repositories)
{
repository.Logger = nugetLogger;
}
IgnoreFailingRepositories = true,
Logger = nugetLogger,
ResolveDependenciesVertically = true
};

return repository;
}

public static IPackageManager GetPackageManager(ChocolateyConfiguration configuration, ILogger nugetLogger, Action<PackageOperationEventArgs> installSuccessAction, Action<PackageOperationEventArgs> uninstallSuccessAction, bool addUninstallHandler)
{
return GetPackageManager(configuration, nugetLogger, new PackageDownloader(), installSuccessAction, uninstallSuccessAction, addUninstallHandler);
//return GetPackageManager(configuration, nugetLogger, new ChocolateyPackageDownloader(), installSuccessAction, uninstallSuccessAction, addUninstallHandler);
}

// public static IPackageManager GetPackageManager(ChocolateyConfiguration configuration, ILogger nugetLogger, IPackageDownloader packageDownloader, Action<PackageOperationEventArgs> installSuccessAction, Action<PackageOperationEventArgs> uninstallSuccessAction, bool addUninstallHandler)
public static IPackageManager GetPackageManager(ChocolateyConfiguration configuration, ILogger nugetLogger, PackageDownloader packageDownloader, Action<PackageOperationEventArgs> installSuccessAction, Action<PackageOperationEventArgs> uninstallSuccessAction, bool addUninstallHandler)
{
IFileSystem nugetPackagesFileSystem = GetNuGetFileSystem(configuration, nugetLogger);
IPackagePathResolver pathResolver = GetPathResolver(configuration, nugetPackagesFileSystem);
var packageManager = new PackageManager(GetRemoteRepository(configuration, nugetLogger), pathResolver, nugetPackagesFileSystem, GetLocalRepository(pathResolver, nugetPackagesFileSystem))
var packageManager = new PackageManager(GetRemoteRepository(configuration, nugetLogger, packageDownloader), pathResolver, nugetPackagesFileSystem, GetLocalRepository(pathResolver, nugetPackagesFileSystem, nugetLogger))
{
DependencyVersion = DependencyVersion.Highest,
Logger = nugetLogger,
};

if (configuration.Debug)
{
packageManager.Logger = nugetLogger;
}

//NOTE DO NOT EVER use this method - packageManager.PackageInstalling += (s, e) =>
packageManager.PackageInstalled += (s, e) =>
{
var pkg = e.Package;
"chocolatey".Log().Info(ChocolateyLoggers.Important, "{0}{1} v{2}{3}{4}{5}".format_with(
Environment.NewLine,
Expand Down
3 changes: 2 additions & 1 deletion src/chocolatey/infrastructure.app/nuget/NugetList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public static int GetCount(ChocolateyConfiguration configuration, ILogger nugetL

private static IQueryable<IPackage> execute_package_search(ChocolateyConfiguration configuration, ILogger nugetLogger)
{
var packageRepository = NugetCommon.GetRemoteRepository(configuration, nugetLogger);
var packageRepository = NugetCommon.GetRemoteRepository(configuration, nugetLogger, new PackageDownloader());
//todo var packageRepository = NugetCommon.GetRemoteRepository(configuration, nugetLogger, new PackageDownloader());
var searchTerm = configuration.Input.to_lower();

// Whether or not the package is remote determines two things:
Expand Down

0 comments on commit d20fc60

Please sign in to comment.