Skip to content
Closed
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
4 changes: 2 additions & 2 deletions src/Umbraco.Cms.Targets/Umbraco.Cms.Targets.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@
</ItemGroup>

<!-- Generate JSON schema on build (and before copying to project) -->
<Target Name="GenerateAppsettingsSchema" BeforeTargets="Build;CopyUmbracoJsonSchemaFiles" Condition="!Exists('$(_UmbracoCmsJsonSchemaReference)')">
<Target Name="GenerateAppsettingsSchema" AfterTargets="Build" BeforeTargets="CopyUmbracoJsonSchemaFiles" Condition="!Exists('$(_UmbracoCmsJsonSchemaReference)')">
<Message Text="Generating $(_UmbracoCmsJsonSchemaReference) because it doesn't exist" Importance="high" />
<Exec WorkingDirectory="$(MSBuildThisFileDirectory)..\..\tools\Umbraco.JsonSchema" Command="dotnet run --configuration $(Configuration) -- --outputFile &quot;$(MSBuildThisFileDirectory)$(_UmbracoCmsJsonSchemaReference)&quot;" />
<Exec WorkingDirectory="$(MSBuildThisFileDirectory)..\..\tools\Umbraco.JsonSchema" Command="dotnet run --configuration $(Configuration) -- --assembly &quot;$(TargetPath)&quot; --type &quot;Umbraco.Cms.Targets.UmbracoCmsSchema&quot; --output &quot;$(MSBuildThisFileDirectory)$(_UmbracoCmsJsonSchemaReference)&quot;" />
</Target>

<!-- Remove generated JSON schema on clean -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Umbraco.Cms.Core.Configuration;
using Umbraco.Cms.Core.Configuration.Models;

namespace Umbraco.Cms.Targets;

internal class UmbracoCmsSchema
{
public UmbracoDefinition Umbraco { get; set; } = null!;
Expand Down
33 changes: 33 additions & 0 deletions src/Umbraco.Core/Configuration/LoggingSettingsExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) Umbraco.
// See LICENSE for more details.

using Microsoft.Extensions.Hosting;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.Extensions;

namespace Umbraco.Extensions;

/// <summary>
/// Extension methods for <see cref="LoggingSettings" />.
/// </summary>
public static class LoggingSettingsExtensions
{
/// <summary>
/// Gets the absolute logging path (maps a virtual path to the applications content root).
/// </summary>
/// <param name="loggingSettings">The logging settings.</param>
/// <param name="hostEnvironment">The host environment.</param>
/// <returns>
/// The absolute logging path.
/// </returns>
public static string GetAbsoluteLoggingPath(this LoggingSettings loggingSettings, IHostEnvironment hostEnvironment)
{
var dir = loggingSettings.Directory;
if (dir.StartsWith("~/"))
{
return hostEnvironment.MapPathContentRoot(dir);
}

return dir;
}
}
5 changes: 2 additions & 3 deletions src/Umbraco.Core/Configuration/Models/GlobalSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,12 @@ internal const string
public int VersionCheckPeriod { get; set; } = StaticVersionCheckPeriod;

/// <summary>
/// Gets or sets a value for the Umbraco back-office path.
/// Gets or sets a value for the Umbraco back-office path.
/// </summary>
[Obsolete($"{nameof(UmbracoPath)} is no longer configurable, this property is scheduled for removal in V12.")]
public string UmbracoPath
{
get => Constants.System.DefaultUmbracoPath;
[Obsolete($"{nameof(UmbracoPath)} is no longer configurable, this property setter is scheduled for removal in V12.")]
// NOTE: When removing this, also clean up the hardcoded removal of UmbracoPath in Umbraco.JsonSchema
set { }
}

Expand Down
25 changes: 9 additions & 16 deletions src/Umbraco.Core/Configuration/Models/LoggingSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
// See LICENSE for more details.

using System.ComponentModel;
using Microsoft.Extensions.Hosting;
using Umbraco.Cms.Core.Extensions;

namespace Umbraco.Cms.Core.Configuration.Models;

/// <summary>
/// Typed configuration options for logging settings.
/// Typed configuration options for logging settings.
/// </summary>
[UmbracoOptions(Constants.Configuration.ConfigLogging)]
public class LoggingSettings
Expand All @@ -17,25 +15,20 @@ public class LoggingSettings
internal const string StaticDirectory = Constants.SystemDirectories.LogFiles;

/// <summary>
/// Gets or sets a value for the maximum age of a log file.
/// Gets or sets a value for the maximum age of a log file.
/// </summary>
/// <value>
/// The maximum log age.
/// </value>
[DefaultValue(StaticMaxLogAge)]
public TimeSpan MaxLogAge { get; set; } = TimeSpan.Parse(StaticMaxLogAge);

/// <summary>
/// Gets or sets the folder to use for log files
/// Gets or sets the folder to use for log files.
/// </summary>
/// <value>
/// The directory.
/// </value>
[DefaultValue(StaticDirectory)]
public string Directory { get; set; } = StaticDirectory;

public string GetAbsoluteLoggingPath(IHostEnvironment hostEnvironment)
{
var dir = Directory;
if (dir.StartsWith("~/"))
{
return hostEnvironment.MapPathContentRoot(dir);
}

return dir;
}
}
10 changes: 8 additions & 2 deletions tools/Umbraco.JsonSchema/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

internal class Options
{
[Option("outputFile", Default = "appsettings-schema.Umbraco.Cms.json", HelpText = "Output file to save the generated JSON schema for Umbraco CMS.")]
public string OutputFile { get; set; } = null!;
[Option('a', "assembly", Required = true, HelpText = "Assembly file (DLL) to load, get the specified type and generate the JSON schema from.")]
public string AssemblyFilePath { get; set; } = null!;

[Option('t', "type", Required = true, HelpText = "Type name (including namespace) to generate the JSON schema from.")]
public string TypeName { get; set; } = null!;

[Option('o', "output", Required = true, HelpText = "Output file path to write the generated JSON schema to.")]
public string OutputFilePath { get; set; } = null!;
}
42 changes: 42 additions & 0 deletions tools/Umbraco.JsonSchema/PluginLoadContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System.Reflection;
using System.Runtime.Loader;

/// <inheritdoc />
internal class PluginLoadContext : AssemblyLoadContext
{
/// <summary>
/// The resolver.
/// </summary>
private readonly AssemblyDependencyResolver _resolver;

/// <summary>
/// Initializes a new instance of the <see cref="PluginLoadContext" /> class.
/// </summary>
/// <param name="pluginPath">The plugin path.</param>
public PluginLoadContext(string pluginPath)
=> _resolver = new AssemblyDependencyResolver(pluginPath);

/// <inheritdoc />
protected override Assembly? Load(AssemblyName assemblyName)
{
string? assemblyPath = _resolver.ResolveAssemblyToPath(assemblyName);
if (assemblyPath != null)
{
return LoadFromAssemblyPath(assemblyPath);
}

return null;
}

/// <inheritdoc />
protected override IntPtr LoadUnmanagedDll(string unmanagedDllName)
{
string? libraryPath = _resolver.ResolveUnmanagedDllToPath(unmanagedDllName);
if (libraryPath != null)
{
return LoadUnmanagedDllFromPath(libraryPath);
}

return IntPtr.Zero;
}
}
21 changes: 14 additions & 7 deletions tools/Umbraco.JsonSchema/Program.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
using CommandLine;
using Umbraco.Cms.Core.Configuration.Models;

await Parser.Default.ParseArguments<Options>(args).WithParsedAsync(async options =>
{
// Generate CMS schema
var jsonSchemaGenerator = new UmbracoJsonSchemaGenerator();
var jsonSchema = jsonSchemaGenerator.Generate(typeof(UmbracoCmsSchema));
// Load assembly and get type
var assemblyFile = Path.GetFullPath(options.AssemblyFilePath);
if (!File.Exists(assemblyFile))
{
throw new FileNotFoundException($"Could not find file '{assemblyFile}'.", assemblyFile);
}

var plc = new PluginLoadContext(assemblyFile);
var assembly = plc.LoadFromAssemblyPath(assemblyFile);
var type = assembly.GetType(options.TypeName, true);

// TODO: When the UmbracoPath setter is removed from GlobalSettings (scheduled for V12), remove this line as well
jsonSchema.Definitions[nameof(GlobalSettings)]?.Properties?.Remove(nameof(GlobalSettings.UmbracoPath));
// Generate schema
var jsonSchemaGenerator = new UmbracoJsonSchemaGenerator();
var jsonSchema = jsonSchemaGenerator.Generate(type);

await File.WriteAllTextAsync(options.OutputFile, jsonSchema.ToJson());
await File.WriteAllTextAsync(options.OutputFilePath, jsonSchema.ToJson());
});
9 changes: 4 additions & 5 deletions tools/Umbraco.JsonSchema/Umbraco.JsonSchema.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Title>Umbraco JSON schema generator</Title>
<Description>Generates a JSON schema from a specific type in an assembly file.</Description>
<OutputType>Exe</OutputType>
<IsPackable>false</IsPackable>
<PackAsTool>true</PackAsTool>
<ToolCommandName>umbraco-jsonschema</ToolCommandName>
<EnablePackageValidation>false</EnablePackageValidation>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="NJsonSchema" Version="10.8.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Umbraco.Core\Umbraco.Core.csproj" />
</ItemGroup>
</Project>