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

Fixed path handling for plugins #608

Merged
merged 2 commits into from
Dec 17, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ jobs:
- name: Setup dotnet
uses: actions/setup-dotnet@v3
with:
dotnet-version: "7.0.x"
dotnet-version: "8.0.x"

- name: Build and pack .NET Core Global Tool
run: >-
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</PropertyGroup>

<ItemGroup>
<SourceRoot Include="$(MSBuildThisFileDirectory)/../"/>
<SourceRoot Include="$(MSBuildThisFileDirectory)/../" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 4 additions & 2 deletions src/NuGetForUnity.Cli/Fakes/AssemblyLoader.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#nullable enable
using System.IO;
using System.Reflection;
using NuGetForUnity.Cli;
using NugetForUnity.Configuration;
Expand All @@ -17,8 +18,9 @@ internal static class AssemblyLoader
/// <returns>Assembly of the loaded plugin.</returns>
internal static Assembly Load(NugetForUnityPluginId pluginId)
{
var loadContext = new NugetAssemblyLoadContext(pluginId.Path);
var assembly = loadContext.LoadFromAssemblyPath(pluginId.Path);
var path = Path.GetFullPath(Path.Combine(UnityPathHelper.AbsoluteProjectPath, pluginId.Path));
var loadContext = new NugetAssemblyLoadContext(path);
var assembly = loadContext.LoadFromAssemblyPath(path);
return assembly;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/NuGetForUnity.Cli/NuGetForUnity.Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<OutputType>Exe</OutputType>
<RootNamespace>NuGetForUnity.Cli</RootNamespace>
<AssemblyName>NuGetForUnity.Cli</AssemblyName>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<PlatformTarget>AnyCPU</PlatformTarget>
<PackAsTool>true</PackAsTool>
<ToolCommandName>nugetforunity</ToolCommandName>
Expand Down
48 changes: 24 additions & 24 deletions src/NuGetForUnity.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,21 @@ private static void FixRoslynAnalyzerImportSettings()
File.WriteAllText(
analyzerDllMetaPath,
$"""
fileFormatVersion: 2
guid: {Guid.NewGuid():N}
labels:
- RoslynAnalyzer
PluginImporter:
platformData:
- first:
: Any
second:
enabled: 0
- first:
Any:
second:
enabled: 0
""",
fileFormatVersion: 2
guid: {Guid.NewGuid():N}
labels:
- RoslynAnalyzer
PluginImporter:
platformData:
- first:
: Any
second:
enabled: 0
- first:
Any:
second:
enabled: 0
""",
utf8NoBom);
}
}
Expand All @@ -142,18 +142,18 @@ private static int PrintUsage()
description.Split(new[] { "\n", "\r\n" }, StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries));
Console.WriteLine(
$"""
Description:
{description}
Description:
{description}

Usage:
nugetforunity restore <PROJECT_PATH> [options]
Usage:
nugetforunity restore <PROJECT_PATH> [options]

Arguments:
<PROJECT_PATH> The path to the Unity project, should be the root path where e.g. the 'ProjectSettings' folder is located. If not specified, the command will use the current directory. [default: {DefaultProjectPath}]
Arguments:
<PROJECT_PATH> The path to the Unity project, should be the root path where e.g. the 'ProjectSettings' folder is located. If not specified, the command will use the current directory. [default: {DefaultProjectPath}]

Options:
-?, -h, --help Show command line help.
""");
Options:
-?, -h, --help Show command line help.
""");
return 1;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using NugetForUnity.PluginAPI.Models;

namespace NugetForUnity.PluginAPI.ExtensionPoints
{
/// <summary>
/// Implement this interface to add additional handling for each found installed package.
/// </summary>
public interface IFoundInstalledPackageHandler
{
/// <summary>
/// This will be called for each found installed package in the project.
/// </summary>
/// <param name="installedPackage">The installedPackage created from found nuspec file.</param>
void ProcessInstalledPackage(INugetPackage installedPackage);
}
}
6 changes: 6 additions & 0 deletions src/NuGetForUnity.PluginAPI/INugetPluginRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,11 @@ public interface INugetPluginRegistry
/// </summary>
/// <param name="packageUninstallHandler">The package uninstall handler to register.</param>
void RegisterPackageUninstallHandler(IPackageUninstallHandler packageUninstallHandler);

/// <summary>
/// Register a class that will be called when installed package is found.
/// </summary>
/// <param name="foundInstalledPackageHandler">The found installed package handler to register.</param>
void RegisterFoundInstalledPackageHandler(IFoundInstalledPackageHandler foundInstalledPackageHandler);
}
}
4 changes: 2 additions & 2 deletions src/NuGetForUnity.PluginAPI/Models/INugetPackageIdentifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ public interface INugetPackageIdentifier
string Id { get; }

/// <summary>
/// Gets the normalized version number of the NuGet package.
/// Gets or sets the normalized version number of the NuGet package.
/// This is the normalized version number without build-metadata e.g. <b>1.0.0+b3a8</b> is normalized to <b>1.0.0</b>.
/// </summary>
string Version { get; }
string Version { get; set; }
JoC0de marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Returns the folder path where this package is or will be installed.
Expand Down
5 changes: 5 additions & 0 deletions src/NuGetForUnity.PluginAPI/Models/INugetPluginService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ public interface INugetPluginService
/// </summary>
string ProjectAssetsDir { get; }

/// <summary>
/// Gets the absolute path to the directory where packages are installed.
/// </summary>
string PackageInstallDir { get; }

/// <summary>
/// Allows plugin to register a function that will modify the contents of default new nuspec file.
/// </summary>
Expand Down
5 changes: 5 additions & 0 deletions src/NuGetForUnity.PluginAPI/Models/INuspecFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
/// </summary>
public interface INuspecFile : INugetPackageIdentifier
{
/// <summary>
/// Gets or sets the Id of the package.
/// </summary>
new string Id { get; set; }

/// <summary>
/// Gets or sets the source control branch the package is from.
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions src/NuGetForUnity.Tests/Assets/Tests/Editor/.editorconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# as this is test we are not so strict -> disable most of the warnings

[*.cs]
dotnet_diagnostic.sa1600.severity=none
dotnet_diagnostic.sa1602.severity=none
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma warning disable SA1512,SA1124 // Single-line comments should not be followed by blank line

#if !NUGETFORUNITY_CLI
using JetBrains.Annotations;
#else
Expand Down
2 changes: 1 addition & 1 deletion src/NuGetForUnity/Editor/Configuration/NugetConfigFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public class NugetConfigFile
public INugetPackageSource ActivePackageSource { get; private set; }

/// <summary>
/// Gets the local path where packages are to be installed. It can be a full path or a relative path.
/// Gets the absolute path where packages are to be installed.
/// </summary>
[NotNull]
public string RepositoryPath { get; private set; } = Path.GetFullPath(Path.Combine(Application.dataPath, "Packages"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Reflection;
using JetBrains.Annotations;
using NugetForUnity.Helper;

namespace NugetForUnity.Configuration
{
Expand All @@ -17,7 +18,7 @@ internal sealed class NugetForUnityPluginId : IEquatable<NugetForUnityPluginId>
internal NugetForUnityPluginId([NotNull] string name, [NotNull] string path)
{
Name = name;
Path = path;
Path = System.IO.Path.IsPathRooted(path) ? PathHelper.GetRelativePath(UnityPathHelper.AbsoluteProjectPath, path) : path;
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/NuGetForUnity/Editor/Helper/AssemblyLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace NugetForUnity.Helper
internal static class AssemblyLoader
{
/// <summary>
/// Loads the assembly for the given <paramref name="pluginId"/>.
/// Loads the assembly for the given <paramref name="pluginId" />.
/// </summary>
/// <param name="pluginId">Plugin Id to load.</param>
/// <returns>Assembly of the loaded plugin.</returns>
Expand Down
2 changes: 2 additions & 0 deletions src/NuGetForUnity/Editor/InstalledPackagesManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using NugetForUnity.Configuration;
using NugetForUnity.Models;
using NugetForUnity.PackageSource;
using NugetForUnity.PluginSupport;
using Debug = UnityEngine.Debug;

namespace NugetForUnity
Expand Down Expand Up @@ -347,6 +348,7 @@ private static void AddPackageToInstalledInternal([NotNull] INugetPackage packag
var packages = InstalledPackagesDictionary;
if (!packages.ContainsKey(package.Id))
{
PluginRegistry.Instance.ProcessInstalledPackage(package);
package.IsManuallyInstalled = GetPackageConfigurationById(package.Id)?.IsManuallyInstalled ?? false;
if (package.IsManuallyInstalled)
{
Expand Down
2 changes: 1 addition & 1 deletion src/NuGetForUnity/Editor/NugetPackageUninstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public static void Uninstall([NotNull] INugetPackageIdentifier package, PackageU
/// Uninstalls all of the currently installed packages.
/// </summary>
/// <param name="packagesToUninstall">The list of packages to uninstall.</param>
internal static void UninstallAll([NotNull] [ItemNotNull] List<INugetPackage> packagesToUninstall)
public static void UninstallAll([NotNull] [ItemNotNull] List<INugetPackage> packagesToUninstall)
{
foreach (var package in packagesToUninstall)
{
Expand Down
Binary file modified src/NuGetForUnity/Editor/PluginAPI/NuGetForUnity.PluginAPI.dll
Binary file not shown.
59 changes: 49 additions & 10 deletions src/NuGetForUnity/Editor/PluginAPI/NuGetForUnity.PluginAPI.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
<?xml version="1.0"?>

<doc>
<assembly>
<name>NuGetForUnity.PluginAPI</name>
</assembly>
<members>
<member name="T:NugetForUnity.PluginAPI.ExtensionPoints.IFoundInstalledPackageHandler">
<summary>
Implement this interface to add additional handling for each found installed package.
</summary>
</member>
<member
name="M:NugetForUnity.PluginAPI.ExtensionPoints.IFoundInstalledPackageHandler.ProcessInstalledPackage(NugetForUnity.PluginAPI.Models.INugetPackage)">
<summary>
This will be called for each found installed package in the project.
</summary>
<param name="installedPackage">The installedPackage created from found nuspec file.</param>
</member>
<member name="T:NugetForUnity.PluginAPI.ExtensionPoints.IPackageButtonsHandler">
<summary>
Implement this interface to add additional buttons for each package in NugetForUnity window.
</summary>
</member>
<member name="M:NugetForUnity.PluginAPI.ExtensionPoints.IPackageButtonsHandler.DrawButtons(NugetForUnity.PluginAPI.Models.INugetPackage,NugetForUnity.PluginAPI.Models.INugetPackage,System.Boolean)">
<member
name="M:NugetForUnity.PluginAPI.ExtensionPoints.IPackageButtonsHandler.DrawButtons(NugetForUnity.PluginAPI.Models.INugetPackage,NugetForUnity.PluginAPI.Models.INugetPackage,System.Boolean)">
<summary>
This method will be called for each package that is rendered in NugetForUnity window.
</summary>
Expand All @@ -22,7 +36,8 @@
Implement this interface to add additional handling of files being extracted from nupkg during installation.
</summary>
</member>
<member name="M:NugetForUnity.PluginAPI.ExtensionPoints.IPackageInstallFileHandler.HandleFileExtraction(NugetForUnity.PluginAPI.Models.INugetPackage,System.IO.Compression.ZipArchiveEntry,System.String)">
<member
name="M:NugetForUnity.PluginAPI.ExtensionPoints.IPackageInstallFileHandler.HandleFileExtraction(NugetForUnity.PluginAPI.Models.INugetPackage,System.IO.Compression.ZipArchiveEntry,System.String)">
<summary>
This will be called for each entry that is about to be processed from nupkg that is being installed.
</summary>
Expand All @@ -36,7 +51,8 @@
Implement this interface to add additional handling when nupkg is being uninstalled.
</summary>
</member>
<member name="M:NugetForUnity.PluginAPI.ExtensionPoints.IPackageUninstallHandler.HandleUninstall(NugetForUnity.PluginAPI.Models.INugetPackage,NugetForUnity.PluginAPI.PackageUninstallReason)">
<member
name="M:NugetForUnity.PluginAPI.ExtensionPoints.IPackageUninstallHandler.HandleUninstall(NugetForUnity.PluginAPI.Models.INugetPackage,NugetForUnity.PluginAPI.PackageUninstallReason)">
<summary>
This method will be called for each package being uninstalled. Note that uninstall is also done for old version
when package is being updated.
Expand Down Expand Up @@ -79,24 +95,34 @@
Gets the methods that NugetForUnity provides to the plugin, like logging methods.
</summary>
</member>
<member name="M:NugetForUnity.PluginAPI.INugetPluginRegistry.RegisterPackageButtonDrawer(NugetForUnity.PluginAPI.ExtensionPoints.IPackageButtonsHandler)">
<member
name="M:NugetForUnity.PluginAPI.INugetPluginRegistry.RegisterPackageButtonDrawer(NugetForUnity.PluginAPI.ExtensionPoints.IPackageButtonsHandler)">
<summary>
Register a class that will be used to draw additional buttons for each package in NugetForUnity editor window.
</summary>
<param name="packageButtonsHandler">The package buttons handler to register.</param>
</member>
<member name="M:NugetForUnity.PluginAPI.INugetPluginRegistry.RegisterPackageInstallFileHandler(NugetForUnity.PluginAPI.ExtensionPoints.IPackageInstallFileHandler)">
<member
name="M:NugetForUnity.PluginAPI.INugetPluginRegistry.RegisterPackageInstallFileHandler(NugetForUnity.PluginAPI.ExtensionPoints.IPackageInstallFileHandler)">
<summary>
Register a class that will be called for each file that is extracted from the nupkg that is being installed.
</summary>
<param name="packageInstallFileHandler">The file handler to register.</param>
</member>
<member name="M:NugetForUnity.PluginAPI.INugetPluginRegistry.RegisterPackageUninstallHandler(NugetForUnity.PluginAPI.ExtensionPoints.IPackageUninstallHandler)">
<member
name="M:NugetForUnity.PluginAPI.INugetPluginRegistry.RegisterPackageUninstallHandler(NugetForUnity.PluginAPI.ExtensionPoints.IPackageUninstallHandler)">
<summary>
Register a class that will be called when uninstalling some package.
</summary>
<param name="packageUninstallHandler">The package uninstall handler to register.</param>
</member>
<member
name="M:NugetForUnity.PluginAPI.INugetPluginRegistry.RegisterFoundInstalledPackageHandler(NugetForUnity.PluginAPI.ExtensionPoints.IFoundInstalledPackageHandler)">
<summary>
Register a class that will be called when installed package is found.
</summary>
<param name="foundInstalledPackageHandler">The found installed package handler to register.</param>
</member>
<member name="T:NugetForUnity.PluginAPI.Models.INugetPackage">
<summary>
Represents a NuGet package.
Expand Down Expand Up @@ -130,7 +156,7 @@
</member>
<member name="P:NugetForUnity.PluginAPI.Models.INugetPackageIdentifier.Version">
<summary>
Gets the normalized version number of the NuGet package.
Gets or sets the normalized version number of the NuGet package.
This is the normalized version number without build-metadata e.g. <b>1.0.0+b3a8</b> is normalized to <b>1.0.0</b>.
</summary>
</member>
Expand All @@ -157,7 +183,13 @@
Gets the absolute path to the projects Assets directory.
</summary>
</member>
<member name="M:NugetForUnity.PluginAPI.Models.INugetPluginService.RegisterNuspecCustomizer(System.Action{NugetForUnity.PluginAPI.Models.INuspecFile})">
<member name="P:NugetForUnity.PluginAPI.Models.INugetPluginService.PackageInstallDir">
<summary>
Gets the absolute path to the directory where packages are installed.
</summary>
</member>
<member
name="M:NugetForUnity.PluginAPI.Models.INugetPluginService.RegisterNuspecCustomizer(System.Action{NugetForUnity.PluginAPI.Models.INuspecFile})">
<summary>
Allows plugin to register a function that will modify the contents of default new nuspec file.
</summary>
Expand Down Expand Up @@ -194,6 +226,11 @@
Represents a .nuspec file used to store metadata for a NuGet package.
</summary>
</member>
<member name="P:NugetForUnity.PluginAPI.Models.INuspecFile.Id">
<summary>
Gets or sets the Id of the package.
</summary>
</member>
<member name="P:NugetForUnity.PluginAPI.Models.INuspecFile.RepositoryBranch">
<summary>
Gets or sets the source control branch the package is from.
Expand Down Expand Up @@ -241,13 +278,15 @@
</member>
<member name="P:NugetForUnity.PluginAPI.Models.INuspecFile.Icon">
<summary>
Gets the path to a icon file. The path is relative to the root folder of the package. This is a alternative to using a URL <see cref="P:NugetForUnity.PluginAPI.Models.INuspecFile.IconUrl" />
Gets the path to a icon file. The path is relative to the root folder of the package. This is a alternative to using a URL
<see cref="P:NugetForUnity.PluginAPI.Models.INuspecFile.IconUrl" />
.
</summary>
</member>
<member name="P:NugetForUnity.PluginAPI.Models.INuspecFile.IconFilePath">
<summary>
Gets the full path to a icon file. This is only set if the .nuspec file contains a <see cref="P:NugetForUnity.PluginAPI.Models.INuspecFile.Icon" />. This is a alternative to using a URL
Gets the full path to a icon file. This is only set if the .nuspec file contains a
<see cref="P:NugetForUnity.PluginAPI.Models.INuspecFile.Icon" />. This is a alternative to using a URL
<see cref="P:NugetForUnity.PluginAPI.Models.INuspecFile.IconUrl" />.
</summary>
</member>
Expand Down
Loading
Loading