public TestData(string testName, ILogging logger, string testRepoName = null, bool withHttpServer = false, ICacheContainer cacheContainer = null, IFileSystem fileSystem = null) { TestName = testName; Logger = logger; Watch = new Stopwatch(); SourceDirectory = TestContext.CurrentContext.TestDirectory.ToSPath(); TestPath = SPath.CreateTempDirectory(testName); SPath.FileSystem = fileSystem ?? new FileSystem(TestPath); if (cacheContainer == null) { var container = new CacheContainer(); container.SetCacheInitializer(CacheType.Branches, () => BranchesCache.Instance); container.SetCacheInitializer(CacheType.GitAheadBehind, () => GitAheadBehindCache.Instance); container.SetCacheInitializer(CacheType.GitLocks, () => GitLocksCache.Instance); container.SetCacheInitializer(CacheType.GitLog, () => GitLogCache.Instance); container.SetCacheInitializer(CacheType.GitStatus, () => GitStatusCache.Instance); container.SetCacheInitializer(CacheType.GitUser, () => GitUserCache.Instance); container.SetCacheInitializer(CacheType.RepositoryInfo, () => RepositoryInfoCache.Instance); cacheContainer = container; } Environment = new IntegrationTestEnvironment(cacheContainer, TestPath, TestPath.Parent, testName); InitializeEnvironment(testRepoName); ApplicationManager = new ApplicationManagerBase(new MainThreadSynchronizationContext(), Environment); if (testRepoName != null) { var testZipFilePath = SourceDirectory.Combine("IOTestsRepo.zip"); ZipHelper.Instance.Extract(testZipFilePath, TestPath, (_, __) => { }, (value, total, name) => true, token: TaskManager.Token); TestRepo = new TestRepoData(this, testRepoName); InstallTestGit(); InitializeRepository(); } #if NUNIT if (withHttpServer) { var filesToServePath = SourceDirectory.Combine("files"); HttpServer = new HttpServer(filesToServePath, 0); var started = new ManualResetEventSlim(); var task = TaskManager.With(HttpServer.Start, TaskAffinity.None); task.OnStart += _ => started.Set(); task.Start(); started.Wait(); } #endif ((ApplicationManagerBase)ApplicationManager).Initialize(); Logger.Trace($"START {testName}"); Watch.Start(); }
public GitInstallDetails(SPath baseDataPath, IEnvironment environment) { ZipPath = baseDataPath.Combine("downloads"); ZipPath.EnsureDirectoryExists(); GitInstallationPath = baseDataPath.Combine(GitDirectory); GitExecutablePath = GitInstallationPath.Combine(environment.IsWindows ? "cmd" : "bin", "git" + UnityEnvironment.ExecutableExtension); //GitLfsExecutablePath = GitExecutablePath.Parent.Combine("git-lfs" + UnityEnvironment.ExecutableExtension); GitLfsExecutablePath = SPath.Default; GitPackageFeed = packageFeed; }
public CreateEnvironmentOptions(SPath?basePath = null) { SPath path = basePath ?? SPath.SystemTemp.Combine(ApplicationInfo.ApplicationName); path.EnsureDirectoryExists(); Extensionfolder = path.Combine(DefaultExtensionFolder); UserProfilePath = path.Combine(DefaultUserProfilePath); UnityProjectPath = path.Combine(DefaultUnityProjectPathAndRepositoryPath).EnsureDirectoryExists(); RepositoryPath = path.Combine(DefaultUnityProjectPathAndRepositoryPath); Extensionfolder.EnsureDirectoryExists(); UserProfilePath.EnsureDirectoryExists(); }
public SPath GetFolder(Folders folder) { switch (folder) { case Folders.CommonApplicationData: return(testPath.Combine("UserProfile", "CommonAppData")); case Folders.Logs: return(testPath.Combine("UserProfile", "Logs")); } return(testPath.Combine("UserProfile", "LocalAppData")); }
private int ProcessEvents(Event[] fileEvents) { var events = new HashSet <EventType>(); foreach (var fileEvent in fileEvents) { if (!running) { break; } if (cancellationToken.IsCancellationRequested) { Stop(); break; } var eventDirectory = new SPath(fileEvent.Directory); var fileA = eventDirectory.Combine(fileEvent.FileA); // handling events in .git/* if (fileA.IsChildOf(paths.DotGitPath) || (paths.WorktreeDotGitPath.IsInitialized && fileA.IsChildOf(paths.WorktreeDotGitPath))) { if (!events.Contains(EventType.ConfigChanged) && fileA.Equals(paths.DotGitConfig)) { events.Add(EventType.ConfigChanged); } else if (!events.Contains(EventType.HeadChanged) && fileA.Equals(paths.DotGitHead)) { events.Add(EventType.HeadChanged); } else if (!events.Contains(EventType.IndexChanged) && fileA.Equals(paths.DotGitIndex)) { events.Add(EventType.IndexChanged); } else if (!events.Contains(EventType.RemoteBranchesChanged) && fileA.IsChildOf(paths.RemotesPath)) { events.Add(EventType.RemoteBranchesChanged); } else if (!events.Contains(EventType.LocalBranchesChanged) && fileA.IsChildOf(paths.BranchesPath)) { events.Add(EventType.LocalBranchesChanged); } else if (!events.Contains(EventType.RepositoryCommitted) && fileA.IsChildOf(paths.DotGitCommitEditMsg)) { events.Add(EventType.RepositoryCommitted); } } else { if (events.Contains(EventType.RepositoryChanged) || ignoredPaths.Any(ignoredPath => fileA.IsChildOf(ignoredPath))) { continue; } events.Add(EventType.RepositoryChanged); } } return(FireEvents(events)); }
private static List <IArchiveEntry> PreprocessEntries(SPath outFolder, IArchive zf, Action <string, long> onStart, Func <string, bool> onFilter) { var entries = new List <IArchiveEntry>(); foreach (IArchiveEntry entry in zf) { if (entry.IsLink || entry.IsSymLink) { continue; } if (entry.IsDirectory) { outFolder.Combine(entry.Name).EnsureDirectoryExists(); continue; // Ignore directories } if (!onFilter?.Invoke(entry.Name) ?? false) { continue; } entries.Add(entry); onStart(entry.Name, entry.Size); } return(entries); }
private static SPath MaybeSetPermissions(SPath destDir, string entryFileName, int mode) { var fullZipToPath = destDir.Combine(entryFileName); fullZipToPath.EnsureParentDirectoryExists(); try { if (SPath.IsUnix && MonoPosixShim.HasMonoPosix) { if (mode == -2115174400) { int fd = MonoPosixShim.Open(fullZipToPath, 64 /*Mono.Unix.Native.OpenFlags.O_CREAT */ | 512 /*Mono.Unix.Native.OpenFlags.O_TRUNC*/, 448 /*Mono.Unix.Native.FilePermissions.S_IRWXU*/ | 32 /*Mono.Unix.Native.FilePermissions.S_IRGRP*/ | 8 /*Mono.Unix.Native.FilePermissions.S_IXGRP*/ | 4 /*Mono.Unix.Native.FilePermissions.S_IROTH*/ | 1 /*Mono.Unix.Native.FilePermissions.S_IXOTH*/ ); MonoPosixShim.Close(fd); } } } catch (Exception ex) { LogHelper.GetLogger <ZipHelper>().Error(ex, "Error setting file attributes in " + fullZipToPath); } return(fullZipToPath); }
private void InitializeEnvironment() { var projectPath = TestPath.Combine("project").EnsureDirectoryExists(); #if UNITY_EDITOR Environment.Initialize(projectPath, TheEnvironment.instance.Environment.UnityVersion, TheEnvironment.instance.Environment.UnityApplication, TheEnvironment.instance.Environment.UnityApplicationContents); #else SPath unityPath, unityContentsPath; unityPath = CurrentExecutionDirectory; while (!unityPath.IsEmpty && !unityPath.DirectoryExists(".Editor")) { unityPath = unityPath.Parent; } if (!unityPath.IsEmpty) { unityPath = unityPath.Combine(".Editor"); unityContentsPath = unityPath.Combine("Data"); } else { unityPath = unityContentsPath = SPath.Default; } Environment.Initialize(projectPath, "2019.2", unityPath, unityContentsPath); #endif }
private static SPath ResolveBasePath(IEnvironment environment, SPath installPath) { var path = installPath; if (!environment.IsWindows) { return(path); } if (environment.Is32Bit) { path = installPath.Combine("mingw32"); } else { path = installPath.Combine("mingw64"); } return(path); }
public static SPath ToFile(ResourceType resourceType, string resource, SPath destinationPath, IEnvironment environment) { var target = destinationPath.Combine(resource); var source = TryGetFile(resourceType, resource, environment); if (source.IsInitialized) { target.DeleteIfExists(); return(source.Copy(target)); } return(SPath.Default); }
public void InstallTestGit() { var installDetails = Environment.GitDefaultInstallation; var state = installDetails.GetDefaults(); Environment.GitInstallationState = state; if (installDetails.GitExecutablePath.FileExists() && installDetails.GitLfsExecutablePath.FileExists()) { return; } var key = installDetails.GitManifest.FileNameWithoutExtension + "_updatelastCheckTime"; Environment.UserSettings.Set(key, DateTimeOffset.Now); var localCache = SourceDirectory.Combine("files/git"); localCache.CopyFiles(installDetails.ZipPath.Parent, true); // skip checking for updates state.GitPackage = DugiteReleaseManifest.Load(TaskManager, installDetails.GitManifest, GitInstaller.GitInstallDetails.ManifestFeed, Environment); var asset = state.GitPackage.DugitePackage; state.GitZipPath = installDetails.ZipPath.Combine(asset.Name); installDetails.GitInstallationPath.DeleteIfExists(); state.GitZipPath.EnsureParentDirectoryExists(); var gitExtractPath = TestPath.Combine("setup", "git_zip_extract_zip_paths").EnsureDirectoryExists(); var source = new UnzipTask(TaskManager, state.GitZipPath, gitExtractPath) .RunSynchronously(); installDetails.GitInstallationPath.EnsureParentDirectoryExists(); source.Move(installDetails.GitInstallationPath); }
private static IEnumerable <string> CreateEnvPath(IGitEnvironment environment, SPath basePath) { yield return(environment.GitExecutablePath.Parent.ToString()); yield return(basePath.Combine("bin").ToString()); if (environment.IsWindows) { yield return(environment.GitInstallPath.Combine("usr/bin").ToString()); } if (environment.GitInstallPath.IsInitialized && environment.GitLfsExecutablePath.Parent != environment.GitExecutablePath.Parent) { yield return(environment.GitLfsExecutablePath.Parent.ToString()); } }
public IntegrationTestEnvironment(SPath testPath, SPath sharedTestPath, string applicationName) { Guard.ArgumentNotNull(applicationName, nameof(applicationName)); ApplicationName = applicationName; this.sharedTestEnvironmentPath = sharedTestPath.Combine("git-unity-test-environment").EnsureDirectoryExists(); this.testPath = testPath.Combine("SystemData").EnsureDirectoryExists(); LocalAppData = GetFolder(Folders.LocalApplicationData); CommonAppData = GetFolder(Folders.CommonApplicationData); UserCachePath = LocalAppData.Combine(applicationName).EnsureDirectoryExists(); SystemCachePath = CommonAppData.Combine(applicationName).EnsureDirectoryExists(); LogPath = GetFolder(Folders.Logs).Combine(applicationName).EnsureDirectoryExists().Combine(logFile); GitDefaultInstallation = new GitInstaller.GitInstallDetails(sharedTestEnvironmentPath, this); }
public static DugiteReleaseManifest Load(ITaskManager taskManager, SPath manifestFile, SPath userCachePath, IGitEnvironment environment) { var manifest = manifestFile.ReadAllText().FromJson <DugiteReleaseManifest>(true, false); var(zipAsset, shaAsset) = manifest.GetAsset(environment); var shaAssetPath = userCachePath.Combine("downloads", shaAsset.Name); if (!shaAssetPath.FileExists()) { var downloader = new Downloader(taskManager); downloader.QueueDownload(shaAsset.Url, shaAssetPath.Parent, shaAssetPath.FileName); downloader.RunSynchronously(); } zipAsset.Hash = shaAssetPath.ReadAllText(); manifest.DugitePackage = zipAsset; return(manifest); }
public RepositoryPathConfiguration(SPath repositoryPath) { RepositoryPath = repositoryPath; WorktreeDotGitPath = SPath.Default; DotGitPath = repositoryPath.Combine(".git"); SPath commonPath; if (DotGitPath.FileExists()) { DotGitPath = DotGitPath.ReadAllLines() .Where(x => x.StartsWith("gitdir:")) .Select(x => x.Substring(7).Trim().ToSPath()) .First(); if (DotGitPath.Combine("commondir").FileExists()) { commonPath = DotGitPath.Combine("commondir").ReadAllLines() .Select(x => x.Trim().ToSPath()) .First(); commonPath = DotGitPath.Combine(commonPath); IsWorktree = true; WorktreeDotGitPath = commonPath; } else { commonPath = DotGitPath; } } else { commonPath = DotGitPath; } BranchesPath = commonPath.Combine("refs", "heads"); RemotesPath = commonPath.Combine("refs", "remotes"); DotGitIndex = DotGitPath.Combine("index"); DotGitHead = DotGitPath.Combine("HEAD"); DotGitConfig = commonPath.Combine("config"); DotGitCommitEditMsg = DotGitPath.Combine("COMMIT_EDITMSG"); }
public TestData(string testName, ILogging logger, bool withHttpServer = false) { TestName = testName; Logger = logger; Watch = new Stopwatch(); SourceDirectory = TestContext.CurrentContext.TestDirectory.ToSPath(); TestPath = SPath.CreateTempDirectory(testName); TaskManager = new TaskManager(); cts = CancellationTokenSource.CreateLinkedTokenSource(TaskManager.Token); try { TaskManager.Initialize(); } catch { // we're on the nunit sync context, which can't be used to create a task scheduler // so use a different context as the main thread. The test won't run on the main nunit thread TaskManager.Initialize(new MainThreadSynchronizationContext(cts.Token)); } Environment = new UnityEnvironment(testName); InitializeEnvironment(); ProcessManager = new ProcessManager(Environment); #if NUNIT if (withHttpServer) { var filesToServePath = SourceDirectory.Combine("files"); HttpServer = new HttpServer(filesToServePath, 0); var started = new ManualResetEventSlim(); var task = TaskManager.With(HttpServer.Start, TaskAffinity.None); task.OnStart += _ => started.Set(); task.Start(); started.Wait(); } #endif Logger.Trace($"START {testName}"); Watch.Start(); }
public void Configure(ProcessStartInfo psi) { defaultEnvironment.Configure(psi); //if (gitInstallPath == SPath.Default || gitInstallPath != Environment.GitInstallPath) ResolvePaths(); var pathEntries = new List <string>(envPath); string separator = GitEnvironment.IsWindows ? ";" : ":"; // we can only set this env var if there is a libexec/git-core. git will bypass internally bundled tools if this env var // is set, which will break Apple's system git on certain tools (like osx-credentialmanager) if (libExecPath.IsInitialized) { psi.EnvironmentVariables["GIT_EXEC_PATH"] = libExecPath.ToString(); } pathEntries.Add("END"); var path = string.Join(separator, pathEntries.ToArray()) + separator + GitEnvironment.Path; var pathEnvVarKey = GitEnvironment.GetEnvironmentVariableKey("PATH"); psi.EnvironmentVariables[pathEnvVarKey] = path; //if (Environment.IsWindows) //{ // psi.EnvironmentVariables["PLINK_PROTOCOL"] = "ssh"; // psi.EnvironmentVariables["TERM"] = "msys"; //} var httpProxy = GitEnvironment.GetEnvironmentVariable("HTTP_PROXY"); if (!string.IsNullOrEmpty(httpProxy)) { psi.EnvironmentVariables["HTTP_PROXY"] = httpProxy; } var httpsProxy = GitEnvironment.GetEnvironmentVariable("HTTPS_PROXY"); if (!string.IsNullOrEmpty(httpsProxy)) { psi.EnvironmentVariables["HTTPS_PROXY"] = httpsProxy; } psi.EnvironmentVariables["DISPLAY"] = "0"; if (!GitEnvironment.IsWindows) { psi.EnvironmentVariables["GIT_TEMPLATE_DIR"] = GitEnvironment.GitInstallPath.Combine("share/git-core/templates"); } if (GitEnvironment.IsLinux) { psi.EnvironmentVariables["PREFIX"] = GitEnvironment.GitExecutablePath.Parent; } var sslCAInfo = GitEnvironment.GetEnvironmentVariable("GIT_SSL_CAINFO"); if (string.IsNullOrEmpty(sslCAInfo)) { var certFile = basePath.Combine("ssl/cacert.pem"); if (certFile.FileExists()) { psi.EnvironmentVariables["GIT_SSL_CAINFO"] = certFile.ToString(); } } /* * psi.WorkingDirectory = workingDirectory; * psi.EnvironmentVariables["HOME"] = SPath.HomeDirectory; * psi.EnvironmentVariables["TMP"] = psi.EnvironmentVariables["TEMP"] = SPath.SystemTemp; * * var path = Environment.Path; * psi.EnvironmentVariables["GHU_WORKINGDIR"] = workingDirectory; * var pathEnvVarKey = Environment.GetEnvironmentVariableKey("PATH"); * * if (dontSetupGit) * { * psi.EnvironmentVariables["GHU_FULLPATH"] = path; * psi.EnvironmentVariables[pathEnvVarKey] = path; * return; * } * * Guard.ArgumentNotNull(psi, "psi"); * * var pathEntries = new List<string>(); * string separator = Environment.IsWindows ? ";" : ":"; * * SPath libexecPath = SPath.Default; * List<string> gitPathEntries = new List<string>(); * if (Environment.GitInstallPath.IsInitialized) * { * var gitPathRoot = Environment.GitExecutablePath.Resolve().Parent.Parent; * var gitExecutableDir = Environment.GitExecutablePath.Parent; // original path to git (might be different from install path if it's a symlink) * * var baseExecPath = gitPathRoot; * var binPath = baseExecPath; * if (Environment.IsWindows) * { * if (baseExecPath.DirectoryExists("mingw32")) * baseExecPath = baseExecPath.Combine("mingw32"); * else * baseExecPath = baseExecPath.Combine("mingw64"); * binPath = baseExecPath.Combine("bin"); * } * * libexecPath = baseExecPath.Combine("libexec", "git-core"); * if (!libexecPath.DirectoryExists()) * libexecPath = SPath.Default; * * if (Environment.IsWindows) * { * gitPathEntries.AddRange(new[] { gitPathRoot.Combine("cmd").ToString(), gitPathRoot.Combine("usr", "bin") }); * } * else * { * gitPathEntries.Add(gitExecutableDir.ToString()); * } * * if (libexecPath.IsInitialized) * gitPathEntries.Add(libexecPath); * gitPathEntries.Add(binPath); * * // we can only set this env var if there is a libexec/git-core. git will bypass internally bundled tools if this env var * // is set, which will break Apple's system git on certain tools (like osx-credentialmanager) * if (libexecPath.IsInitialized) * psi.EnvironmentVariables["GIT_EXEC_PATH"] = libexecPath.ToString(); * } * * if (Environment.GitLfsInstallPath.IsInitialized && libexecPath != Environment.GitLfsInstallPath) * { * pathEntries.Add(Environment.GitLfsInstallPath); * } * if (gitPathEntries.Count > 0) * pathEntries.AddRange(gitPathEntries); * * pathEntries.Add("END"); * * path = string.Join(separator, pathEntries.ToArray()) + separator + path; * * psi.EnvironmentVariables["GHU_FULLPATH"] = path; * psi.EnvironmentVariables[pathEnvVarKey] = path; * * //TODO: Remove with Git LFS Locking becomes standard * psi.EnvironmentVariables["GITLFSLOCKSENABLED"] = "1"; * * if (Environment.IsWindows) * { * psi.EnvironmentVariables["PLINK_PROTOCOL"] = "ssh"; * psi.EnvironmentVariables["TERM"] = "msys"; * } * * var httpProxy = Environment.GetEnvironmentVariable("HTTP_PROXY"); * if (!string.IsNullOrEmpty(httpProxy)) * psi.EnvironmentVariables["HTTP_PROXY"] = httpProxy; * * var httpsProxy = Environment.GetEnvironmentVariable("HTTPS_PROXY"); * if (!string.IsNullOrEmpty(httpsProxy)) * psi.EnvironmentVariables["HTTPS_PROXY"] = httpsProxy; * psi.EnvironmentVariables["DISPLAY"] = "0"; */ }
public override void Configure(ProcessStartInfo psi, SPath?workingDirectory = null) { base.Configure(psi, workingDirectory); var pathEntries = new List <string>(envPath); string separator = Environment.IsWindows ? ";" : ":"; // we can only set this env var if there is a libexec/git-core. git will bypass internally bundled tools if this env var // is set, which will break Apple's system git on certain tools (like osx-credentialmanager) if (libExecPath.IsInitialized) { psi.EnvironmentVariables["GIT_EXEC_PATH"] = libExecPath.ToString(); } pathEntries.Add("END"); var path = string.Join(separator, pathEntries.ToArray()) + separator + Environment.Path; var pathEnvVarKey = Environment.GetEnvironmentVariableKey("PATH"); psi.EnvironmentVariables[pathEnvVarKey] = path; //if (Environment.IsWindows) //{ // psi.EnvironmentVariables["PLINK_PROTOCOL"] = "ssh"; // psi.EnvironmentVariables["TERM"] = "msys"; //} var httpProxy = Environment.GetEnvironmentVariable("HTTP_PROXY"); if (!string.IsNullOrEmpty(httpProxy)) { psi.EnvironmentVariables["HTTP_PROXY"] = httpProxy; } var httpsProxy = Environment.GetEnvironmentVariable("HTTPS_PROXY"); if (!string.IsNullOrEmpty(httpsProxy)) { psi.EnvironmentVariables["HTTPS_PROXY"] = httpsProxy; } psi.EnvironmentVariables["DISPLAY"] = "0"; if (!Environment.IsWindows) { psi.EnvironmentVariables["GIT_TEMPLATE_DIR"] = Environment.GitInstallationPath.Combine("share/git-core/templates"); } if (Environment.IsLinux) { psi.EnvironmentVariables["PREFIX"] = Environment.GitExecutablePath.Parent; } var sslCAInfo = Environment.GetEnvironmentVariable("GIT_SSL_CAINFO"); if (string.IsNullOrWhiteSpace(sslCAInfo)) { var certFile = basePath.Combine("ssl/cacert.pem"); if (certFile.FileExists()) { psi.EnvironmentVariables["GIT_SSL_CAINFO"] = certFile.ToString(); } } }
public ServerConfiguration(SPath processServerDirectory) { ExecutablePath = processServerDirectory.Combine(ProcessExecutableName); }