Merge pull request #5748 from umbraco/v8/feature/mb-embed-prepare

Prepare MB future
This commit is contained in:
Shannon Deminick
2019-07-02 18:18:07 +10:00
committed by GitHub
15 changed files with 115 additions and 21 deletions

View File

@@ -4,6 +4,7 @@ using Umbraco.Core.Composing;
using Umbraco.Core.Dictionary;
using Umbraco.Core.IO;
using Umbraco.Core.Logging.Viewer;
using Umbraco.Core.Manifest;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.PackageActions;
using Umbraco.Core.Persistence.Mappers;
@@ -66,9 +67,16 @@ namespace Umbraco.Core
/// Gets the validators collection builder.
/// </summary>
/// <param name="composition">The composition.</param>
internal static ManifestValueValidatorCollectionBuilder Validators(this Composition composition)
internal static ManifestValueValidatorCollectionBuilder ManifestValueValidators(this Composition composition)
=> composition.WithCollectionBuilder<ManifestValueValidatorCollectionBuilder>();
/// <summary>
/// Gets the manifest filter collection builder.
/// </summary>
/// <param name="composition">The composition.</param>
public static ManifestFilterCollectionBuilder ManifestFilters(this Composition composition)
=> composition.WithCollectionBuilder<ManifestFilterCollectionBuilder>();
/// <summary>
/// Gets the components collection builder.
/// </summary>

View File

@@ -7,6 +7,7 @@ using Umbraco.Core.Configuration.HealthChecks;
using Umbraco.Core.Configuration.UmbracoSettings;
using Umbraco.Core.IO;
using Umbraco.Core.Logging;
using Umbraco.Core.Manifest;
namespace Umbraco.Core
{
@@ -41,7 +42,12 @@ namespace Umbraco.Core
configs.Add(() => new CoreDebug());
// GridConfig depends on runtime caches, manifest parsers... and cannot be available during composition
configs.Add<IGridConfig>(factory => new GridConfig(factory.GetInstance<ILogger>(), factory.GetInstance<AppCaches>(), configDir, factory.GetInstance<IRuntimeState>().Debug));
configs.Add<IGridConfig>(factory => new GridConfig(
factory.GetInstance<ILogger>(),
factory.GetInstance<AppCaches>(),
configDir,
factory.GetInstance<ManifestParser>(),
factory.GetInstance<IRuntimeState>().Debug));
}
}
}

View File

@@ -1,14 +1,15 @@
using System.IO;
using Umbraco.Core.Cache;
using Umbraco.Core.Logging;
using Umbraco.Core.Manifest;
namespace Umbraco.Core.Configuration.Grid
{
class GridConfig : IGridConfig
{
public GridConfig(ILogger logger, AppCaches appCaches, DirectoryInfo configFolder, bool isDebug)
public GridConfig(ILogger logger, AppCaches appCaches, DirectoryInfo configFolder, ManifestParser manifestParser, bool isDebug)
{
EditorsConfig = new GridEditorsConfig(logger, appCaches, configFolder, isDebug);
EditorsConfig = new GridEditorsConfig(logger, appCaches, configFolder, manifestParser, isDebug);
}
public IGridEditorsConfig EditorsConfig { get; }

View File

@@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json.Linq;
using Umbraco.Core.Cache;
using Umbraco.Core.Composing;
using Umbraco.Core.Logging;
using Umbraco.Core.Manifest;
using Umbraco.Core.PropertyEditors;
@@ -15,13 +13,15 @@ namespace Umbraco.Core.Configuration.Grid
private readonly ILogger _logger;
private readonly AppCaches _appCaches;
private readonly DirectoryInfo _configFolder;
private readonly ManifestParser _manifestParser;
private readonly bool _isDebug;
public GridEditorsConfig(ILogger logger, AppCaches appCaches, DirectoryInfo configFolder, bool isDebug)
public GridEditorsConfig(ILogger logger, AppCaches appCaches, DirectoryInfo configFolder, ManifestParser manifestParser, bool isDebug)
{
_logger = logger;
_appCaches = appCaches;
_configFolder = configFolder;
_manifestParser = manifestParser;
_isDebug = isDebug;
}
@@ -31,9 +31,6 @@ namespace Umbraco.Core.Configuration.Grid
{
List<GridEditor> GetResult()
{
// TODO: should use the common one somehow! + ignoring _appPlugins here!
var parser = new ManifestParser(_appCaches, Current.ManifestValidators, _logger);
var editors = new List<GridEditor>();
var gridConfig = Path.Combine(_configFolder.FullName, "grid.editors.config.js");
if (File.Exists(gridConfig))
@@ -42,7 +39,7 @@ namespace Umbraco.Core.Configuration.Grid
try
{
editors.AddRange(parser.ParseGridEditors(sourceString));
editors.AddRange(_manifestParser.ParseGridEditors(sourceString));
}
catch (Exception ex)
{
@@ -51,7 +48,7 @@ namespace Umbraco.Core.Configuration.Grid
}
// add manifest editors, skip duplicates
foreach (var gridEditor in parser.Manifest.GridEditors)
foreach (var gridEditor in _manifestParser.Manifest.GridEditors)
{
if (editors.Contains(gridEditor) == false) editors.Add(gridEditor);
}

View File

@@ -0,0 +1,19 @@
using System.Collections.Generic;
namespace Umbraco.Core.Manifest
{
/// <summary>
/// Provides filtering for package manifests.
/// </summary>
public interface IManifestFilter
{
/// <summary>
/// Filters package manifests.
/// </summary>
/// <param name="manifests">The package manifests.</param>
/// <remarks>
/// <para>It is possible to remove, change, or add manifests.</para>
/// </remarks>
void Filter(List<PackageManifest> manifests);
}
}

View File

@@ -0,0 +1,28 @@
using System.Collections.Generic;
using Umbraco.Core.Composing;
namespace Umbraco.Core.Manifest
{
/// <summary>
/// Contains the manifest filters.
/// </summary>
public class ManifestFilterCollection : BuilderCollectionBase<IManifestFilter>
{
/// <summary>
/// Initializes a new instance of the <see cref="ManifestFilterCollection"/> class.
/// </summary>
public ManifestFilterCollection(IEnumerable<IManifestFilter> items)
: base(items)
{ }
/// <summary>
/// Filters package manifests.
/// </summary>
/// <param name="manifests">The package manifests.</param>
public void Filter(List<PackageManifest> manifests)
{
foreach (var filter in this)
filter.Filter(manifests);
}
}
}

View File

@@ -0,0 +1,12 @@
using Umbraco.Core.Composing;
namespace Umbraco.Core.Manifest
{
public class ManifestFilterCollectionBuilder : OrderedCollectionBuilderBase<ManifestFilterCollectionBuilder, ManifestFilterCollection, IManifestFilter>
{
protected override ManifestFilterCollectionBuilder This => this;
// do NOT cache this, it's only used once
protected override Lifetime CollectionLifetime => Lifetime.Transient;
}
}

View File

@@ -22,24 +22,26 @@ namespace Umbraco.Core.Manifest
private readonly IAppPolicyCache _cache;
private readonly ILogger _logger;
private readonly ManifestValueValidatorCollection _validators;
private readonly ManifestFilterCollection _filters;
private string _path;
/// <summary>
/// Initializes a new instance of the <see cref="ManifestParser"/> class.
/// </summary>
public ManifestParser(AppCaches appCaches, ManifestValueValidatorCollection validators, ILogger logger)
: this(appCaches, validators, "~/App_Plugins", logger)
public ManifestParser(AppCaches appCaches, ManifestValueValidatorCollection validators, ManifestFilterCollection filters, ILogger logger)
: this(appCaches, validators, filters, "~/App_Plugins", logger)
{ }
/// <summary>
/// Initializes a new instance of the <see cref="ManifestParser"/> class.
/// </summary>
private ManifestParser(AppCaches appCaches, ManifestValueValidatorCollection validators, string path, ILogger logger)
private ManifestParser(AppCaches appCaches, ManifestValueValidatorCollection validators, ManifestFilterCollection filters, string path, ILogger logger)
{
if (appCaches == null) throw new ArgumentNullException(nameof(appCaches));
_cache = appCaches.RuntimeCache;
_validators = validators ?? throw new ArgumentNullException(nameof(validators));
_filters = filters ?? throw new ArgumentNullException(nameof(filters));
if (string.IsNullOrWhiteSpace(path)) throw new ArgumentNullOrEmptyException(nameof(path));
Path = path;
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
@@ -78,6 +80,7 @@ namespace Umbraco.Core.Manifest
if (string.IsNullOrWhiteSpace(text))
continue;
var manifest = ParseManifest(text);
manifest.Source = path;
manifests.Add(manifest);
}
catch (Exception e)
@@ -86,6 +89,8 @@ namespace Umbraco.Core.Manifest
}
}
_filters.Filter(manifests);
return manifests;
}

View File

@@ -9,6 +9,16 @@ namespace Umbraco.Core.Manifest
/// </summary>
public class PackageManifest
{
/// <summary>
/// Gets the source path of the manifest.
/// </summary>
/// <remarks>
/// <para>Gets the full absolute file path of the manifest,
/// using system directory separators.</para>
/// </remarks>
[JsonIgnore]
public string Source { get; set; }
/// <summary>
/// Gets or sets the scripts listed in the manifest.
/// </summary>

View File

@@ -58,7 +58,7 @@ namespace Umbraco.Core.Runtime
composition.RegisterUnique<ManifestParser>();
// register our predefined validators
composition.WithCollectionBuilder<ManifestValueValidatorCollectionBuilder>()
composition.ManifestValueValidators()
.Add<RequiredValidator>()
.Add<RegexValidator>()
.Add<DelimitedValueValidator>()
@@ -66,6 +66,9 @@ namespace Umbraco.Core.Runtime
.Add<IntegerValidator>()
.Add<DecimalValidator>();
// register the manifest filter collection builder (collection is empty by default)
composition.ManifestFilters();
// properties and parameters derive from data editors
composition.WithCollectionBuilder<DataEditorCollectionBuilder>()
.Add(() => composition.TypeLoader.GetDataEditors());

View File

@@ -219,6 +219,9 @@
<Compile Include="Composing\TypeLoader.cs" />
<Compile Include="IO\MediaPathSchemes\UniqueMediaPathScheme.cs" />
<Compile Include="Logging\Viewer\LogTimePeriod.cs" />
<Compile Include="Manifest\IManifestFilter.cs" />
<Compile Include="Manifest\ManifestFilterCollection.cs" />
<Compile Include="Manifest\ManifestFilterCollectionBuilder.cs" />
<Compile Include="Mapping\MapperContext.cs" />
<Compile Include="Migrations\Upgrade\Common\DeleteKeysAndIndexes.cs" />
<Compile Include="Migrations\Upgrade\V_8_0_0\DataTypes\ContentPickerPreValueMigrator.cs" />

View File

@@ -44,7 +44,7 @@ namespace Umbraco.Tests.Manifest
new RequiredValidator(Mock.Of<ILocalizedTextService>()),
new RegexValidator(Mock.Of<ILocalizedTextService>(), null)
};
_parser = new ManifestParser(AppCaches.Disabled, new ManifestValueValidatorCollection(validators), Mock.Of<ILogger>());
_parser = new ManifestParser(AppCaches.Disabled, new ManifestValueValidatorCollection(validators), new ManifestFilterCollection(Array.Empty<IManifestFilter>()), Mock.Of<ILogger>());
}
[Test]

View File

@@ -248,6 +248,11 @@ namespace Umbraco.Tests.Testing
// register empty content apps collection
Composition.WithCollectionBuilder<ContentAppFactoryCollectionBuilder>();
// manifest
Composition.ManifestValueValidators();
Composition.ManifestFilters();
}
protected virtual void ComposeMapper(bool configure)

View File

@@ -21,7 +21,7 @@ namespace Umbraco.Web.Editors
/// <summary>
/// Provides a general object validator.
/// </summary>
internal interface IEditorValidator : IDiscoverable
public interface IEditorValidator : IDiscoverable
{
/// <summary>
/// Gets the object type validated by this validator.

View File

@@ -32,9 +32,6 @@ using System.Runtime.InteropServices;
// Umbraco Headless
[assembly: InternalsVisibleTo("Umbraco.Headless")]
// Umbraco ModelsBuilder
[assembly: InternalsVisibleTo("Umbraco.ModelsBuilder")]
// code analysis
// IDE1006 is broken, wants _value syntax for consts, etc - and it's even confusing ppl at MS, kill it
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "~_~")]