Module installation handler for the recipes: discover and find module to install from orchard or custom feed.

Updating recipe with a gallery module.

--HG--
branch : recipe
This commit is contained in:
Suha Can
2011-02-18 13:16:42 -08:00
parent 148e1b988f
commit 2afa3cd9bf
5 changed files with 49 additions and 6 deletions

View File

@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using Orchard.Packaging.GalleryServer;
using Orchard.Packaging.Models;

View File

@@ -79,6 +79,10 @@
<Project>{17F86780-9A1F-4AA1-86F1-875EEC2730C7}</Project>
<Name>Orchard.Modules</Name>
</ProjectReference>
<ProjectReference Include="..\Orchard.Packaging\Orchard.Packaging.csproj">
<Project>{DFD137A2-DDB5-4D22-BE0D-FA9AD4C8B059}</Project>
<Name>Orchard.Packaging</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />

View File

@@ -1,12 +1,19 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Orchard.Localization;
using Orchard.Logging;
using Orchard.Packaging.Models;
using Orchard.Packaging.Services;
using Orchard.Recipes.Models;
using Orchard.Recipes.Services;
namespace Orchard.Recipes.RecipeHandlers {
public class ModuleRecipeHandler : IRecipeHandler {
public ModuleRecipeHandler() {
private readonly IPackagingSourceManager _packagingSourceManager;
public ModuleRecipeHandler(IPackagingSourceManager packagingSourceManager) {
_packagingSourceManager = packagingSourceManager;
Logger = NullLogger.Instance;
T = NullLocalizer.Instance;
}
@@ -23,7 +30,7 @@ namespace Orchard.Recipes.RecipeHandlers {
}
bool replace;
string source, name, version, repository;
string source = null, name = null, version = null, repository = null;
foreach (var attribute in recipeContext.RecipeStep.Step.Attributes()) {
if (String.Equals(attribute.Name.LocalName, "src", StringComparison.OrdinalIgnoreCase)) {
@@ -42,11 +49,39 @@ namespace Orchard.Recipes.RecipeHandlers {
repository = attribute.Value;
}
else {
Logger.Error("Unrecognized attribute {0} encountered in step Module. Skipping.", attribute.Name.LocalName);
throw new InvalidOperationException(string.Format("Unrecognized attribute {0} encountered in step Module.", attribute.Name.LocalName));
}
}
// download and install module.
if (source != null) {
}
else {
if (name == null) {
throw new InvalidOperationException("Either name or source is required in a Module declaration in a recipe file.");
}
// download and install module from the orchard feed or a custom feed if repository is specified.
bool enforceVersion = version != null;
bool installed = false;
PackagingSource packagingSource = null;
if (repository != null) {
enforceVersion = false;
packagingSource = new PackagingSource {FeedTitle = repository, FeedUrl = repository};
}
foreach (var packagingEntry in _packagingSourceManager.GetExtensionList(packagingSource)) {
if (String.Equals(packagingEntry.Title, name, StringComparison.OrdinalIgnoreCase)) {
if (enforceVersion && !String.Equals(packagingEntry.Version, version, StringComparison.OrdinalIgnoreCase)) {
continue;
}
// install.
installed = true;
}
}
if (!installed) {
throw new InvalidOperationException(string.Format("Module {0} was not found in the specified location.", name));
}
}
recipeContext.Executed = true;
}

View File

@@ -9,10 +9,12 @@
<Version>1.0</Version>
</Recipe>
<Module name="Bing.Maps" version="0.5.0" replace="false" />
<Feature enable="Orchard.PublishLater,Orchard.Blogs,Orchard.Comments,Orchard.ContentTypes,
Orchard.jQuery,Orchard.Lists,Orchard.Media,
Orchard.Tags,Orchard.Scripting,Orchard.Scripting.Lightweight,
TinyMce,PackagingServices,Orchard.Packaging,Gallery,TheThemeMachine,Orchard.Experimental" />
TinyMce,TheThemeMachine,Orchard.Experimental" />
<Metadata>
<Types>

View File

@@ -100,6 +100,9 @@ namespace Orchard.Setup.Services {
"Orchard.Users",
"Orchard.Roles",
"Orchard.Modules",
"PackagingServices",
"Orchard.Packaging",
"Gallery",
"Orchard.Recipes"
};