Skip to content

Commit

Permalink
Enable plugin package download
Browse files Browse the repository at this point in the history
  • Loading branch information
dtivel committed May 18, 2017
1 parent 4b92d6d commit b2678ce
Show file tree
Hide file tree
Showing 188 changed files with 24,456 additions and 2,404 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
Expand All @@ -14,6 +14,7 @@
using NuGet.Packaging;
using NuGet.Packaging.Core;
using NuGet.ProjectModel;
using NuGet.Protocol;
using NuGet.Repositories;

namespace NuGet.Commands
Expand Down Expand Up @@ -73,19 +74,41 @@ public async Task CopyPackagesToOriginalCaseAsync(IEnumerable<RestoreTargetGraph
}

var originalCaseContext = GetPathContext(identity, isLowercase: _request.IsLowercasePackagesDirectory);
var localPackageFilePath = GetLocalPackageFilePath(remoteMatch);
var packageIdentity = new PackageIdentity(remoteMatch.Library.Name, remoteMatch.Library.Version);
IPackageDownloader packageDependency = null;

// Install the package.
var installed = await PackageExtractor.InstallFromSourceAsync(
destination => CopyToAsync(remoteMatch, destination, token),
originalCaseContext,
token);
if (string.IsNullOrEmpty(localPackageFilePath))
{
packageDependency = await remoteMatch.Provider.GetPackageDownloaderAsync(
packageIdentity,
_request.CacheContext,
_request.Log,
token);
}
else
{
packageDependency = new LocalPackageArchiveDownloader(
localPackageFilePath,
packageIdentity,
_request.Log);
}

if (installed)
// Install the package.
using (packageDependency)
{
_request.Log.LogMinimal(string.Format(
CultureInfo.CurrentCulture,
Strings.Log_ConvertedPackageToOriginalCase,
identity));
var installed = await PackageExtractor.InstallFromSourceAsync(
packageDependency,
originalCaseContext,
token);

if (installed)
{
_request.Log.LogMinimal(string.Format(
CultureInfo.CurrentCulture,
Strings.Log_ConvertedPackageToOriginalCase,
identity));
}
}
}
}
Expand Down Expand Up @@ -122,39 +145,22 @@ private static PackageIdentity GetPackageIdentity(RemoteMatch remoteMatch)
remoteMatch.Library.Version);
}

private async Task CopyToAsync(RemoteMatch remoteMatch, Stream destination, CancellationToken token)
private string GetLocalPackageFilePath(RemoteMatch remoteMatch)
{
var library = remoteMatch.Library;
// Try to get the package from the local repositories first.

// Try to get the package from the local repositories first.
var localPackage = NuGetv3LocalRepositoryUtility.GetPackage(
_localRepositories,
library.Name,
library.Version);

if (localPackage != null && File.Exists(localPackage.Package.ZipPath))
{
using (var stream = new FileStream(
localPackage.Package.ZipPath,
FileMode.Open,
FileAccess.Read,
FileShare.Read,
bufferSize: 4096,
useAsync: true))
{
await stream.CopyToAsync(destination, bufferSize: 4096, cancellationToken: token);
}
}
else
{
// Otherwise, get it from the provider.
await remoteMatch.Provider.CopyToAsync(
remoteMatch.Library,
destination,
_request.CacheContext,
_request.Log,
token);
return localPackage.Package.ZipPath;
}

return null;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
Expand Down Expand Up @@ -234,7 +234,7 @@ private async Task InstallPackagesAsync(IEnumerable<RestoreTargetGraph> graphs,
}
}

private Task InstallPackageAsync(RemoteMatch installItem, CancellationToken token)
private async Task InstallPackageAsync(RemoteMatch installItem, CancellationToken token)
{
var packageIdentity = new PackageIdentity(installItem.Library.Name, installItem.Library.Version);

Expand All @@ -245,15 +245,17 @@ private Task InstallPackageAsync(RemoteMatch installItem, CancellationToken toke
_request.PackageSaveMode,
_request.XmlDocFileSaveMode);

return PackageExtractor.InstallFromSourceAsync(
stream => installItem.Provider.CopyToAsync(
installItem.Library,
stream,
_request.CacheContext,
_logger,
token),
versionFolderPathContext,
token);
using (var packageDependency = await installItem.Provider.GetPackageDownloaderAsync(
packageIdentity,
_request.CacheContext,
_logger,
token))
{
await PackageExtractor.InstallFromSourceAsync(
packageDependency,
versionFolderPathContext,
token);
}
}

private Task<RestoreTargetGraph[]> WalkRuntimeDependenciesAsync(LibraryRange projectRange,
Expand Down
Loading

0 comments on commit b2678ce

Please sign in to comment.