Skip to content

Commit

Permalink
Added path issues fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jzapdot committed Jul 5, 2021
2 parents 48b9c62 + 71a8e14 commit e84474a
Show file tree
Hide file tree
Showing 15 changed files with 75 additions and 80 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Releases]
### [2.3.2] - 2021-07-04
#### Fixed
These issues should help resolve any operating system path issues that caused either plugins to fail to be discovered or files to be written incorrectly.
* Modified `WriteToDiskPostProcessor` so that it will replace any inapropriate path characters per-platform with the correct ones.
* Modified `GenerateOptions` and `ConfigOptions` for the Genesis.CLI so that the case-sensitive "plugins" folder name is used and removed any platform-specific path characters.
* Added `OperatingSystemTools` helper methods for determining current operating system

### [2.3.1] - 2021-07-01
#### Changed
* Modified `GetAttributes` and `HasAttributes` extension methods with optional bool parameter `canInherit` so that a user can check to see if a `ITypeSymbol` is decorated with an matching attribute or base type name.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using Genesis.Plugin;
using Genesis.Shared;
using Serilog;
using Serilog.Core;
using OperatingSystem = Genesis.Plugin.OperatingSystem;

namespace Genesis.Core.Plugin
{
Expand All @@ -54,10 +59,23 @@ public void Configure(IGenesisConfig genesisConfig)

public CodeGenFile[] PostProcess(CodeGenFile[] files)
{
var logger = Log.Logger.ForContext<WriteToDiskPostProcessor>();
var basePath = _targetDirectoryConfig.TargetDirectory + Path.DirectorySeparatorChar;

// Get the path-specific slash characters that should be replaced if encountered.
var replaceSlash = OperatingSystemTools.GetOperatingSystem() switch
{
OperatingSystem.macOS => "\\",
OperatingSystem.Linux => "\\",
OperatingSystem.Windows => "/",
_ => throw new ArgumentException(nameof(OSPlatform))
};
var pathDirectorySeparatorStr = Path.DirectorySeparatorChar.ToString();

Parallel.ForEach(files, (codeGenFile, state) =>
{
var path = basePath + codeGenFile.FileName;
var path = Path.GetFullPath(Path.Combine(basePath, codeGenFile.FileName))
.Replace(replaceSlash, pathDirectorySeparatorStr);
var directoryName = Path.GetDirectoryName(path);
if (!Directory.Exists(directoryName))
{
Expand Down
12 changes: 12 additions & 0 deletions ExternalApp/Genesis.Plugin/Tools/OperatingSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Genesis.Plugin
{
/// <summary>
/// Represents distinct supported flavors of operating systems.
/// </summary>
public enum OperatingSystem
{
Windows = 0,
macOS = 1,
Linux = 2
}
}
31 changes: 31 additions & 0 deletions ExternalApp/Genesis.Plugin/Tools/OperatingSystemTools.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Runtime.InteropServices;

namespace Genesis.Plugin
{
/// <summary>
/// Helper methods for dealing with operating systems.
/// </summary>
public class OperatingSystemTools
{
public static OperatingSystem GetOperatingSystem()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
return OperatingSystem.macOS;
}

if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
return OperatingSystem.Linux;
}

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return OperatingSystem.Windows;
}

throw new Exception("Cannot determine operating system!");
}
}
}
6 changes: 3 additions & 3 deletions ExternalApp/Genesis/Options/ConfigOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,20 @@ internal sealed class ConfigOptions
longName:"create",
SetName = "create",
HelpText = "Specifies that a config file should be created and populated with all settings from " +
"availables plugins.")]
"available plugins.")]
public bool DoCreate { get; set; }

[Option(
longName: "output-path",
SetName = "create",
HelpText = "The output file path where this config should be written",
Default = "./new_config.json")]
Default = "new_config.json")]
public string CreatePath { get; set; }

[Option(
"plugin-path",
HelpText = "The path to the plugin folder.",
Default = "./plugins")]
Default = "Plugins")]
public string PluginPath { get; set; }

[Option(
Expand Down
2 changes: 1 addition & 1 deletion ExternalApp/Genesis/Options/GenerateOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ internal sealed class GenerateOptions
[Option(
"plugin-path",
HelpText = "The path to the plugin folder.",
Default = "./plugins")]
Default = "Plugins")]
public string PluginPath { get; set; }

[Option(
Expand Down
5 changes: 2 additions & 3 deletions Unity/Assets/ExampleContent/GenesisSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@ MonoBehaviour:
- key: Genesis.CodeGenerators
value: Genesis.Unity.Factory.Plugin.ScriptableFactoryCodeGenerator
- key: Genesis.PostProcessors
value: Genesis.Core.Plugin.AddFileHeaderPostProcessor, Genesis.Core.Plugin.CleanTargetDirectoryPostProcessor,
Genesis.Core.Plugin.NewLinePostProcessor, Genesis.Core.Plugin.MergeFilesPostProcessor,
Genesis.Core.Plugin.WriteToDiskPostProcessor
value: Genesis.Core.Plugin.CleanTargetDirectoryPostProcessor, Genesis.Core.Plugin.NewLinePostProcessor,
Genesis.Core.Plugin.MergeFilesPostProcessor, Genesis.Core.Plugin.WriteToDiskPostProcessor
- key: Genesis.DoUseWhiteListedAssemblies
value: false
- key: Genesis.WhiteListedAssemblies
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool (Genesis v2.0.4.0).
//
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool (Genesis v2.0.4.0).
//
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool (Genesis v2.0.4.0).
//
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool (Genesis v2.0.4.0).
//
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool (Genesis v2.0.4.0).
//
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool (Genesis v2.0.4.0).
//
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool (Genesis v2.0.4.0).
//
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool (Genesis v2.0.4.0).
//
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
Expand Down

0 comments on commit e84474a

Please sign in to comment.