Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare MB future #5748

Merged
merged 3 commits into from
Jul 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/Umbraco.Core/CompositionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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;
Expand Down Expand Up @@ -66,9 +67,16 @@ public static UrlSegmentProviderCollectionBuilder UrlSegmentProviders(this Compo
/// 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>
Expand Down
8 changes: 7 additions & 1 deletion src/Umbraco.Core/ConfigsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Umbraco.Core.Configuration.UmbracoSettings;
using Umbraco.Core.IO;
using Umbraco.Core.Logging;
using Umbraco.Core.Manifest;

namespace Umbraco.Core
{
Expand Down Expand Up @@ -41,7 +42,12 @@ public static void AddCoreConfigs(this Configs configs)
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));
}
}
}
5 changes: 3 additions & 2 deletions src/Umbraco.Core/Configuration/Grid/GridConfig.cs
Original file line number Diff line number Diff line change
@@ -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; }
Expand Down
13 changes: 5 additions & 8 deletions src/Umbraco.Core/Configuration/Grid/GridEditorsConfig.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -15,13 +13,15 @@ internal class GridEditorsConfig : IGridEditorsConfig
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;
}

Expand All @@ -31,9 +31,6 @@ public IEnumerable<IGridEditorConfig> Editors
{
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))
Expand All @@ -42,7 +39,7 @@ List<GridEditor> GetResult()

try
{
editors.AddRange(parser.ParseGridEditors(sourceString));
editors.AddRange(_manifestParser.ParseGridEditors(sourceString));
}
catch (Exception ex)
{
Expand All @@ -51,7 +48,7 @@ List<GridEditor> GetResult()
}

// 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);
}
Expand Down
19 changes: 19 additions & 0 deletions src/Umbraco.Core/Manifest/IManifestFilter.cs
Original file line number Diff line number Diff line change
@@ -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);
Shazwazza marked this conversation as resolved.
Show resolved Hide resolved
}
}
28 changes: 28 additions & 0 deletions src/Umbraco.Core/Manifest/ManifestFilterCollection.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
12 changes: 12 additions & 0 deletions src/Umbraco.Core/Manifest/ManifestFilterCollectionBuilder.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
11 changes: 8 additions & 3 deletions src/Umbraco.Core/Manifest/ManifestParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,26 @@ public class ManifestParser
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));
Expand Down Expand Up @@ -78,6 +80,7 @@ private IEnumerable<PackageManifest> GetManifests()
if (string.IsNullOrWhiteSpace(text))
continue;
var manifest = ParseManifest(text);
manifest.Source = path;
manifests.Add(manifest);
}
catch (Exception e)
Expand All @@ -86,6 +89,8 @@ private IEnumerable<PackageManifest> GetManifests()
}
}

_filters.Filter(manifests);

return manifests;
}

Expand Down
10 changes: 10 additions & 0 deletions src/Umbraco.Core/Manifest/PackageManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
5 changes: 4 additions & 1 deletion src/Umbraco.Core/Runtime/CoreInitialComposer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,17 @@ public override void Compose(Composition composition)
composition.RegisterUnique<ManifestParser>();

// register our predefined validators
composition.WithCollectionBuilder<ManifestValueValidatorCollectionBuilder>()
composition.ManifestValueValidators()
.Add<RequiredValidator>()
.Add<RegexValidator>()
.Add<DelimitedValueValidator>()
.Add<EmailValidator>()
.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());
Expand Down
3 changes: 3 additions & 0 deletions src/Umbraco.Core/Umbraco.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
2 changes: 1 addition & 1 deletion src/Umbraco.Tests/Manifest/ManifestParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void Setup()
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]
Expand Down
5 changes: 5 additions & 0 deletions src/Umbraco.Tests/Testing/UmbracoTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,11 @@ protected virtual void ComposeMisc()

// register empty content apps collection
Composition.WithCollectionBuilder<ContentAppFactoryCollectionBuilder>();

// manifest
Composition.ManifestValueValidators();
Composition.ManifestFilters();

}

protected virtual void ComposeMapper(bool configure)
Expand Down
2 changes: 1 addition & 1 deletion src/Umbraco.Web/Editors/IEditorValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 0 additions & 3 deletions src/Umbraco.Web/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@
// 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 = "~_~")]