mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Adding nuget's log to the command's output
--HG-- branch : nuget
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Web.Hosting;
|
||||
using Orchard.Commands;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Packaging.Services;
|
||||
using Orchard.UI.Notify;
|
||||
|
||||
namespace Orchard.Packaging.Commands {
|
||||
[OrchardFeature("Orchard.Packaging")]
|
||||
@@ -11,9 +12,11 @@ namespace Orchard.Packaging.Commands {
|
||||
private const string CreatePackagePath = "CreatedPackages";
|
||||
|
||||
private readonly IPackageManager _packageManager;
|
||||
private readonly INotifier _notifier;
|
||||
|
||||
public PackagingCommands(IPackageManager packageManager) {
|
||||
public PackagingCommands(IPackageManager packageManager, INotifier notifier) {
|
||||
_packageManager = packageManager;
|
||||
_notifier = notifier;
|
||||
}
|
||||
|
||||
[OrchardSwitch]
|
||||
@@ -59,7 +62,10 @@ namespace Orchard.Packaging.Commands {
|
||||
}
|
||||
|
||||
var packageInfo = _packageManager.Install(packageId, Version, location, solutionFolder);
|
||||
Context.Output.WriteLine(T("Package \"{0}\" successfully installed at \"{1}\"", packageInfo.ExtensionName, packageInfo.ExtensionPath));
|
||||
|
||||
foreach(var message in _notifier.List()) {
|
||||
Context.Output.WriteLine(message.Message);
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetSolutionFolder() {
|
||||
|
@@ -81,6 +81,7 @@
|
||||
<Compile Include="Services\IPackageExpander.cs" />
|
||||
<Compile Include="Services\IPackageManager.cs" />
|
||||
<Compile Include="Services\IPackagingSourceManager.cs" />
|
||||
<Compile Include="Services\NugetLogger.cs" />
|
||||
<Compile Include="Services\PackageBuilder.cs" />
|
||||
<Compile Include="Services\PackageData.cs" />
|
||||
<Compile Include="Services\PackageExpander.cs" />
|
||||
|
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using NuGet;
|
||||
using Orchard.Localization;
|
||||
using Orchard.UI.Notify;
|
||||
|
||||
namespace Orchard.Packaging.Services {
|
||||
public class NugetLogger : ILogger {
|
||||
private readonly INotifier _notifier;
|
||||
|
||||
public NugetLogger(INotifier notifier) {
|
||||
_notifier = notifier;
|
||||
}
|
||||
|
||||
public void Log(MessageLevel level, string message, params object[] args) {
|
||||
switch ( level ) {
|
||||
case MessageLevel.Debug:
|
||||
break;
|
||||
case MessageLevel.Info:
|
||||
_notifier.Information(new LocalizedString(String.Format(message, args)));
|
||||
break;
|
||||
case MessageLevel.Warning:
|
||||
_notifier.Warning(new LocalizedString(String.Format(message, args)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -3,24 +3,26 @@ using System.IO;
|
||||
using NuGet;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Localization;
|
||||
|
||||
using Orchard.UI.Notify;
|
||||
using NuGetPackageManager = NuGet.PackageManager;
|
||||
|
||||
namespace Orchard.Packaging.Services {
|
||||
[OrchardFeature("PackagingServices")]
|
||||
public class PackageExpander : IPackageExpander {
|
||||
private readonly INotifier _notifier;
|
||||
|
||||
public PackageExpander() {
|
||||
public PackageExpander(INotifier notifier) {
|
||||
_notifier = notifier;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
public Localizer T { get; set; }
|
||||
|
||||
|
||||
public PackageInfo ExpandPackage(string packageId, string version, string location, string solutionFolder) {
|
||||
|
||||
var packagesPath = Path.Combine(solutionFolder, "packages"); // where to download/uncompress packages
|
||||
var projectPath = Path.Combine(solutionFolder, "Orchard.Web"); // where to install packages (in the project's folder)
|
||||
var logger = new NugetLogger(_notifier);
|
||||
|
||||
// instantiates the appropriate package repository
|
||||
var packageRepository = Uri.IsWellFormedUriString(location, UriKind.Absolute)
|
||||
@@ -38,8 +40,8 @@ namespace Orchard.Packaging.Services {
|
||||
var packageManager = new NuGetPackageManager(
|
||||
packageRepository,
|
||||
new DefaultPackagePathResolver(location),
|
||||
new FileBasedProjectSystem(packagesPath)
|
||||
);
|
||||
new FileBasedProjectSystem(packagesPath) { Logger = logger }
|
||||
) {Logger = logger};
|
||||
|
||||
// specifically tells to ignore dependencies
|
||||
packageManager.InstallPackage(package, ignoreDependencies: true);
|
||||
@@ -47,16 +49,15 @@ namespace Orchard.Packaging.Services {
|
||||
var projectManager = new ProjectManager(
|
||||
new LocalPackageRepository(packagesPath), // source repository for the package to install
|
||||
new DefaultPackagePathResolver(location),
|
||||
new FileBasedProjectSystem(projectPath), // the location of the project (where to copy the content files)
|
||||
new FileBasedProjectSystem(projectPath) { Logger = logger }, // the location of the project (where to copy the content files)
|
||||
new LocalPackageRepository(packagesPath) // the location of the uncompressed package, used to check if the package is already installed
|
||||
);
|
||||
) {Logger = logger};
|
||||
|
||||
// add the package to the project
|
||||
projectManager.AddPackageReference(packageId, packageVersion);
|
||||
|
||||
|
||||
return new PackageInfo {
|
||||
ExtensionName = package.Title,
|
||||
ExtensionName = package.Title ?? package.Id,
|
||||
ExtensionVersion = package.Version.ToString(),
|
||||
ExtensionType = String.Empty, // todo: assign value
|
||||
ExtensionPath = projectPath
|
||||
|
Reference in New Issue
Block a user