private PackageData GetGitPackage(string id, string version, [CanBeNull] string hash, [CanBeNull] string revision = null) { // If we don't have a hash, we know this isn't a git package if (hash == null) { return(null); } // This must be a git package, make sure we return something try { var packageFolder = mySolution.SolutionDirectory.Combine($"Library/PackageCache/{id}@{hash}"); if (!packageFolder.ExistsDirectory) { var shortHash = hash.Substring(0, Math.Min(hash.Length, 10)); packageFolder = mySolution.SolutionDirectory.Combine($"Library/PackageCache/{id}@{shortHash}"); } return(GetPackageDataFromFolder(id, packageFolder, PackageSource.Git, new GitDetails(version, hash, revision))); } catch (Exception e) { myLogger.Error(e, "Error resolving git package"); return(PackageData.CreateUnknown(id, version)); } }
private PackageData GetPackageData(string id, string version, string registry, FileSystemPath builtInPackagesFolder, [CanBeNull] ManifestLockDetails lockDetails) { // Order is important here. A package can be listed in manifest.json, but if it also exists in Packages, // that embedded copy takes precedence. We look for an embedded folder with the same name, but it can be // under any name - we'll find it again and override it when we look at the other embedded packages. // Registry packages are the most likely to match, and can't clash with other packages, so check them early. // The file: protocol is used by local but it can also be a protocol for git, so check git before local. try { return(GetEmbeddedPackage(id, id) ?? GetRegistryPackage(id, version, registry) ?? GetGitPackage(id, version, lockDetails?.Hash, lockDetails?.Revision) ?? GetLocalPackage(id, version) ?? GetLocalTarballPackage(id, version) ?? GetBuiltInPackage(id, version, builtInPackagesFolder) ?? PackageData.CreateUnknown(id, version)); } catch (Exception e) { myLogger.Error(e, $"Error resolving package {id}"); return(PackageData.CreateUnknown(id, version)); } }
private PackageData GetPackageData(string id, PackagesLockDependency details, FileSystemPath builtInPackagesFolder) { try { PackageData packageData = null; switch (details.Source) { case "embedded": packageData = GetEmbeddedPackage(id, details.Version); break; case "registry": packageData = GetRegistryPackage(id, details.Version, details.Url ?? DefaultRegistryUrl); break; case "builtin": packageData = GetBuiltInPackage(id, details.Version, builtInPackagesFolder); break; case "git": packageData = GetGitPackage(id, details.Version, details.Hash); break; case "local": packageData = GetLocalPackage(id, details.Version); break; case "local-tarball": packageData = GetLocalTarballPackage(id, details.Version); break; } return(packageData ?? PackageData.CreateUnknown(id, details.Version)); } catch (Exception e) { myLogger.Error(e, $"Error resolving package {id}"); return(PackageData.CreateUnknown(id, details.Version)); } }
private PackageData GetBuiltInPackage(string id, string version, FileSystemPath builtInPackagesFolder) { // If we can identify the module root of the current project, use it to look up the module if (builtInPackagesFolder.ExistsDirectory) { var packageFolder = builtInPackagesFolder.Combine(id); return(GetPackageDataFromFolder(id, packageFolder, PackageSource.BuiltIn)); } // We can't find the actual package. If we "know" it's a module/built in package, then mark it as an // unresolved built in package, rather than just an unresolved package. The Unity Explorer can use this to // put the unresolved package in the right place, rather than show as a top level unresolved package simply // because we haven't found the application package cache yet. // We can rely on an ID starting with "com.unity.modules." as this is the convention Unity uses. Since they // control the namespace of their own registries, we can be confident that they won't publish normal // packages with the same naming convention. We can't be sure for third part registries, but if anyone does // that, they only have themselves to blame. // If we don't recognise the package as a built in, let someone else handle it return(id.StartsWith("com.unity.modules.") ? PackageData.CreateUnknown(id, version, PackageSource.BuiltIn) : null); }