using System; using System.IO; using System.Linq; using UnityEditor.Scripting.ScriptCompilation; namespace UnityEditor.TestTools.TestRunner.GUI.TestAssets { /// internal class CustomScriptAssemblyMappingFinder : ICustomScriptAssemblyMappingFinder { /// /// The provided string argument is null. public ICustomScriptAssembly FindCustomScriptAssemblyFromFolderPath(string folderPath) { if (folderPath == null) { throw new ArgumentNullException(nameof(folderPath)); } var scriptInFolderPath = Path.Combine(folderPath, "Foo.cs"); var customScriptAssembly = FindCustomScriptAssemblyFromScriptPath(scriptInFolderPath); return customScriptAssembly; } /// /// Finds the Custom Script Assembly associated with the provided script asset path. /// /// The script path to check. /// The associated ; null if none. private static ICustomScriptAssembly FindCustomScriptAssemblyFromScriptPath(string scriptPath) { try { var customScriptAssembly = EditorCompilationInterface.Instance.FindCustomScriptAssemblyFromScriptPath(scriptPath); return new CustomScriptAssemblyWrapper(customScriptAssembly); } catch (Exception) { return null; } } /// /// Custom Script Assembly wrapper. /// internal class CustomScriptAssemblyWrapper : ICustomScriptAssembly { internal readonly CustomScriptAssembly targetAssembly; /// /// Creates a new instance of the class. /// /// The to be represented by the wrapper. /// The provided argument is null. internal CustomScriptAssemblyWrapper(CustomScriptAssembly assembly) { targetAssembly = assembly ?? throw new ArgumentNullException(nameof(assembly), "The provided assembly must not be null."); } /// public bool HasPrecompiledReference(string libraryFilename) { var precompiledReferences = targetAssembly.PrecompiledReferences; var libraryReferenceExists = precompiledReferences != null && precompiledReferences.Any(r => Path.GetFileName(r) == libraryFilename); return libraryReferenceExists; } /// public bool HasAssemblyFlag(AssemblyFlags flag) { var hasAssemblyFlag = (targetAssembly.AssemblyFlags & flag) == flag; return hasAssemblyFlag; } } } }