mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-21 19:34:40 +08:00
Cleanup and refactor module/theme recipe step handler code.
--HG-- branch : recipe
This commit is contained in:
@@ -10,7 +10,6 @@
|
|||||||
</Recipe>
|
</Recipe>
|
||||||
|
|
||||||
<!-- Steps -->
|
<!-- Steps -->
|
||||||
<Module src="http://" replace="false" />
|
|
||||||
<Module name="module1" repository="somerepo" version="1.1" replace="true" />
|
<Module name="module1" repository="somerepo" version="1.1" replace="true" />
|
||||||
|
|
||||||
<Feature disable="f1, f2" enable="f3,f4" />
|
<Feature disable="f1, f2" enable="f3,f4" />
|
||||||
@@ -38,7 +37,6 @@
|
|||||||
|
|
||||||
<Migration features="f2,f4"/>
|
<Migration features="f2,f4"/>
|
||||||
|
|
||||||
<Theme src="http://" enable="true" current="true" />
|
|
||||||
<Theme name="theme1" repository="somerepo" replace="true" />
|
<Theme name="theme1" repository="somerepo" replace="true" />
|
||||||
|
|
||||||
<Custom1 attr1="value1" />
|
<Custom1 attr1="value1" />
|
||||||
|
@@ -125,7 +125,7 @@ namespace Orchard.Tests.Modules.Recipes.Services {
|
|||||||
var sampleRecipe = recipes[0];
|
var sampleRecipe = recipes[0];
|
||||||
var recipeSteps = (List<RecipeStep>) sampleRecipe.RecipeSteps;
|
var recipeSteps = (List<RecipeStep>) sampleRecipe.RecipeSteps;
|
||||||
|
|
||||||
Assert.That(recipeSteps.Count, Is.EqualTo(11));
|
Assert.That(recipeSteps.Count, Is.EqualTo(9));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
@@ -38,22 +38,18 @@ namespace Orchard.Recipes.RecipeHandlers {
|
|||||||
public Localizer T { get; set; }
|
public Localizer T { get; set; }
|
||||||
ILogger Logger { get; set; }
|
ILogger Logger { get; set; }
|
||||||
|
|
||||||
// <Module src="http://" replace="false" />
|
// <Module name="module1" [repository="somerepo"] version="1.1" replace="false" />
|
||||||
// <Module name="module1" [repository="somerepo"] version="1.1" replace="true" />
|
// install modules from feed.
|
||||||
// install modules from url or feed.
|
|
||||||
public void ExecuteRecipeStep(RecipeContext recipeContext) {
|
public void ExecuteRecipeStep(RecipeContext recipeContext) {
|
||||||
if (!String.Equals(recipeContext.RecipeStep.Name, "Module", StringComparison.OrdinalIgnoreCase)) {
|
if (!String.Equals(recipeContext.RecipeStep.Name, "Module", StringComparison.OrdinalIgnoreCase)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool replace;
|
bool replace;
|
||||||
string source = null, name = null, version = null, repository = null;
|
string name = null, version = null, repository = null;
|
||||||
|
|
||||||
foreach (var attribute in recipeContext.RecipeStep.Step.Attributes()) {
|
foreach (var attribute in recipeContext.RecipeStep.Step.Attributes()) {
|
||||||
if (String.Equals(attribute.Name.LocalName, "src", StringComparison.OrdinalIgnoreCase)) {
|
if (String.Equals(attribute.Name.LocalName, "replace", StringComparison.OrdinalIgnoreCase)) {
|
||||||
source = attribute.Value;
|
|
||||||
}
|
|
||||||
else if (String.Equals(attribute.Name.LocalName, "replace", StringComparison.OrdinalIgnoreCase)) {
|
|
||||||
replace = Boolean.Parse(attribute.Value);
|
replace = Boolean.Parse(attribute.Value);
|
||||||
}
|
}
|
||||||
else if (String.Equals(attribute.Name.LocalName, "name", StringComparison.OrdinalIgnoreCase)) {
|
else if (String.Equals(attribute.Name.LocalName, "name", StringComparison.OrdinalIgnoreCase)) {
|
||||||
@@ -70,48 +66,43 @@ namespace Orchard.Recipes.RecipeHandlers {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (source != null) {
|
if (name == null) {
|
||||||
|
throw new InvalidOperationException("Name is required in a Module declaration in a recipe file.");
|
||||||
}
|
}
|
||||||
else {
|
// download and install module from the orchard feed or a custom feed if repository is specified.
|
||||||
if (name == null) {
|
bool enforceVersion = version != null;
|
||||||
throw new InvalidOperationException("Either name or source is required in a Module declaration in a recipe file.");
|
bool installed = false;
|
||||||
}
|
PackagingSource packagingSource = _packagingSourceManager.GetSources().FirstOrDefault();
|
||||||
// download and install module from the orchard feed or a custom feed if repository is specified.
|
if (repository != null) {
|
||||||
bool enforceVersion = version != null;
|
enforceVersion = false;
|
||||||
bool installed = false;
|
packagingSource = new PackagingSource {FeedTitle = repository, FeedUrl = repository};
|
||||||
PackagingSource packagingSource = _packagingSourceManager.GetSources().FirstOrDefault();
|
}
|
||||||
if (repository != null) {
|
foreach (var packagingEntry in _packagingSourceManager.GetExtensionList(packagingSource)) {
|
||||||
enforceVersion = false;
|
if (String.Equals(packagingEntry.Title, name, StringComparison.OrdinalIgnoreCase)) {
|
||||||
packagingSource = new PackagingSource {FeedTitle = repository, FeedUrl = repository};
|
if (enforceVersion && !String.Equals(packagingEntry.Version, version, StringComparison.OrdinalIgnoreCase)) {
|
||||||
}
|
continue;
|
||||||
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;
|
|
||||||
}
|
|
||||||
// use for replace.
|
|
||||||
bool moduleExists = false;
|
|
||||||
foreach (var extension in _extensionManager.AvailableExtensions()
|
|
||||||
.Where(extension =>
|
|
||||||
DefaultExtensionTypes.IsModule(extension.ExtensionType) &&
|
|
||||||
String.Equals(packagingEntry.Title, extension.Name, StringComparison.OrdinalIgnoreCase))) {
|
|
||||||
moduleExists = true;
|
|
||||||
}
|
|
||||||
_packageManager.Install(packagingEntry.PackageId, packagingEntry.Version, packagingSource.FeedUrl, HostingEnvironment.MapPath("~/"));
|
|
||||||
_moduleService.EnableFeatures(new[] { packagingEntry.Title }, true);
|
|
||||||
_dataMigrationManager.Update(packagingEntry.Title);
|
|
||||||
|
|
||||||
installed = true;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
// use for replace.
|
||||||
|
bool moduleExists = false;
|
||||||
|
foreach (var extension in _extensionManager.AvailableExtensions()
|
||||||
|
.Where(extension =>
|
||||||
|
DefaultExtensionTypes.IsModule(extension.ExtensionType) &&
|
||||||
|
String.Equals(packagingEntry.Title, extension.Name, StringComparison.OrdinalIgnoreCase))) {
|
||||||
|
moduleExists = true;
|
||||||
|
}
|
||||||
|
_packageManager.Install(packagingEntry.PackageId, packagingEntry.Version, packagingSource.FeedUrl, HostingEnvironment.MapPath("~/"));
|
||||||
|
_moduleService.EnableFeatures(new[] { packagingEntry.Title }, true);
|
||||||
|
_dataMigrationManager.Update(packagingEntry.Title);
|
||||||
|
installed = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!installed) {
|
|
||||||
throw new InvalidOperationException(string.Format("Module {0} was not found in the specified location.", name));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!installed) {
|
||||||
|
throw new InvalidOperationException(string.Format("Module {0} was not found in the specified location.", name));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
recipeContext.Executed = true;
|
recipeContext.Executed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -37,22 +37,18 @@ namespace Orchard.Recipes.RecipeHandlers {
|
|||||||
public Localizer T { get; set; }
|
public Localizer T { get; set; }
|
||||||
ILogger Logger { get; set; }
|
ILogger Logger { get; set; }
|
||||||
|
|
||||||
// <Theme src="http://" enable="true" current="true />
|
// <Theme name="theme1" repository="somethemerepo" version="1.1" enable="true" current="true" replace="false" />
|
||||||
// <Theme name="theme1" repository="somethemerepo" version="1.1" replace="true" />
|
// install themes from feed.
|
||||||
// install themes from url or feed.
|
|
||||||
public void ExecuteRecipeStep(RecipeContext recipeContext) {
|
public void ExecuteRecipeStep(RecipeContext recipeContext) {
|
||||||
if (!String.Equals(recipeContext.RecipeStep.Name, "Theme", StringComparison.OrdinalIgnoreCase)) {
|
if (!String.Equals(recipeContext.RecipeStep.Name, "Theme", StringComparison.OrdinalIgnoreCase)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool replace, enable = false, current = false;
|
bool replace, enable = false, current = false;
|
||||||
string source = null, name = null, version = null, repository = null;
|
string name = null, version = null, repository = null;
|
||||||
|
|
||||||
foreach (var attribute in recipeContext.RecipeStep.Step.Attributes()) {
|
foreach (var attribute in recipeContext.RecipeStep.Step.Attributes()) {
|
||||||
if (String.Equals(attribute.Name.LocalName, "src", StringComparison.OrdinalIgnoreCase)) {
|
if (String.Equals(attribute.Name.LocalName, "replace", StringComparison.OrdinalIgnoreCase)) {
|
||||||
source = attribute.Value;
|
|
||||||
}
|
|
||||||
else if (String.Equals(attribute.Name.LocalName, "replace", StringComparison.OrdinalIgnoreCase)) {
|
|
||||||
replace = Boolean.Parse(attribute.Value);
|
replace = Boolean.Parse(attribute.Value);
|
||||||
}
|
}
|
||||||
else if (String.Equals(attribute.Name.LocalName, "enable", StringComparison.OrdinalIgnoreCase)) {
|
else if (String.Equals(attribute.Name.LocalName, "enable", StringComparison.OrdinalIgnoreCase)) {
|
||||||
@@ -75,50 +71,46 @@ namespace Orchard.Recipes.RecipeHandlers {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (source != null) {
|
if (name == null) {
|
||||||
|
throw new InvalidOperationException("Name is required in a Theme declaration in a recipe file.");
|
||||||
}
|
}
|
||||||
else {
|
// download and install theme from the orchard feed or a custom feed if repository is specified.
|
||||||
if (name == null) {
|
bool enforceVersion = version != null;
|
||||||
throw new InvalidOperationException("Either name or source is required in a Theme declaration in a recipe file.");
|
bool installed = false;
|
||||||
}
|
PackagingSource packagingSource = _packagingSourceManager.GetSources().FirstOrDefault();
|
||||||
// download and install theme from the orchard feed or a custom feed if repository is specified.
|
if (repository != null) {
|
||||||
bool enforceVersion = version != null;
|
enforceVersion = false;
|
||||||
bool installed = false;
|
packagingSource = new PackagingSource { FeedTitle = repository, FeedUrl = repository };
|
||||||
PackagingSource packagingSource = _packagingSourceManager.GetSources().FirstOrDefault();
|
}
|
||||||
if (repository != null) {
|
foreach (var packagingEntry in _packagingSourceManager.GetExtensionList(packagingSource)) {
|
||||||
enforceVersion = false;
|
if (String.Equals(packagingEntry.Title, name, StringComparison.OrdinalIgnoreCase)) {
|
||||||
packagingSource = new PackagingSource { FeedTitle = repository, FeedUrl = repository };
|
if (enforceVersion && !String.Equals(packagingEntry.Version, version, StringComparison.OrdinalIgnoreCase)) {
|
||||||
}
|
continue;
|
||||||
foreach (var packagingEntry in _packagingSourceManager.GetExtensionList(packagingSource)) {
|
}
|
||||||
if (String.Equals(packagingEntry.Title, name, StringComparison.OrdinalIgnoreCase)) {
|
// use for replace.
|
||||||
if (enforceVersion && !String.Equals(packagingEntry.Version, version, StringComparison.OrdinalIgnoreCase)) {
|
bool themeExists = false;
|
||||||
continue;
|
foreach (var extension in _extensionManager.AvailableExtensions()
|
||||||
}
|
.Where(extension =>
|
||||||
// use for replace.
|
DefaultExtensionTypes.IsTheme(extension.ExtensionType) &&
|
||||||
bool themeExists = false;
|
String.Equals(packagingEntry.Title, extension.Name, StringComparison.OrdinalIgnoreCase))) {
|
||||||
foreach (var extension in _extensionManager.AvailableExtensions()
|
themeExists = true;
|
||||||
.Where(extension =>
|
}
|
||||||
DefaultExtensionTypes.IsTheme(extension.ExtensionType) &&
|
_packageManager.Install(packagingEntry.PackageId, packagingEntry.Version, packagingSource.FeedUrl, HostingEnvironment.MapPath("~/"));
|
||||||
String.Equals(packagingEntry.Title, extension.Name, StringComparison.OrdinalIgnoreCase))) {
|
if (current) {
|
||||||
themeExists = true;
|
_themeService.EnableThemeFeatures(packagingEntry.Title);
|
||||||
}
|
_siteThemeService.SetSiteTheme(packagingEntry.Title);
|
||||||
_packageManager.Install(packagingEntry.PackageId, packagingEntry.Version, packagingSource.FeedUrl, HostingEnvironment.MapPath("~/"));
|
}
|
||||||
if (enable) {
|
else if (enable) {
|
||||||
_themeService.EnableThemeFeatures(packagingEntry.Title);
|
_themeService.EnableThemeFeatures(packagingEntry.Title);
|
||||||
}
|
|
||||||
if (current) {
|
|
||||||
_siteThemeService.SetSiteTheme(packagingEntry.Title);
|
|
||||||
}
|
|
||||||
|
|
||||||
installed = true;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!installed) {
|
installed = true;
|
||||||
throw new InvalidOperationException(string.Format("Theme {0} was not found in the specified location.", name));
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!installed) {
|
||||||
|
throw new InvalidOperationException(string.Format("Theme {0} was not found in the specified location.", name));
|
||||||
}
|
}
|
||||||
|
|
||||||
recipeContext.Executed = true;
|
recipeContext.Executed = true;
|
||||||
|
Reference in New Issue
Block a user