public GitInstallationState(IGitEnvironment currentEnvironment) { GitInstallationPath = currentEnvironment.GitInstallationPath; GitExecutablePath = currentEnvironment.GitExecutablePath; GitLfsInstallationPath = currentEnvironment.GitLfsInstallationPath; GitLfsExecutablePath = currentEnvironment.GitLfsExecutablePath; }
public ProcessEnvironment(IProcessEnvironment defaultEnvironment, IGitEnvironment environment) { this.defaultEnvironment = defaultEnvironment; GitEnvironment = environment; Logger = LogHelper.GetLogger(GetType()); }
public Platform(IGitEnvironment environment) { Environment = environment; TaskManager = new TaskManager(); ProcessManager = new GitProcessManager(Environment); GitClient = new GitClient(this); Instance = this; }
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 ApplicationManager(IMainThreadSynchronizationContext synchronizationContext, IGitEnvironment environment) : base(synchronizationContext as SynchronizationContext, environment) { FirstRun = ApplicationCache.Instance.FirstRun; InstanceId = ApplicationCache.Instance.InstanceId; ListenToUnityExit(); Initialize(); }
public GitInstaller(IGitEnvironment environment, IProcessManager processManager, CancellationToken token, GitInstallationState state = null, GitInstallDetails installDetails = null) : base(token) { this.environment = environment; this.processManager = processManager; this.state = state; this.sharpZipLibHelper = ZipHelper.Instance; this.installDetails = installDetails ?? new GitInstallDetails(environment.UserCachePath, environment); progressReporter.OnProgress += progress.UpdateProgress; }
public static Package Load(ITaskManager taskManager, IGitEnvironment environment, UriString packageFeed) { Package package = null; var filename = packageFeed.Filename.ToSPath(); if (!filename.IsInitialized || filename.IsRoot) { return(package); } var key = filename.FileNameWithoutExtension + "_updatelastCheckTime"; var now = DateTimeOffset.Now; var feed = environment.UserCachePath.Combine(packageFeed.Filename); if (!feed.FileExists() || now.Date > environment.UserSettings.Get <DateTimeOffset>(key).Date) { feed = new DownloadTask(taskManager, packageFeed, environment.UserCachePath) .Catch(ex => { Logger.Warning(@"Error downloading package feed:{0} ""{1}"" Message:""{2}""", packageFeed, ex.GetType().ToString(), ex.GetExceptionMessageShort()); return(true); }) .RunSynchronously().ToSPath(); if (feed.IsInitialized) { environment.UserSettings.Set <DateTimeOffset>(key, now); } } if (!feed.IsInitialized) { // try from assembly resources feed = AssemblyResources.ToFile(ResourceType.Platform, packageFeed.Filename, environment.UserCachePath, environment); } if (feed.IsInitialized) { try { package = feed.ReadAllText().FromJson <Package>(true, false); } catch (Exception ex) { Logger.Error(ex); } } return(package); }
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 static DugiteReleaseManifest Load(ITaskManager taskManager, SPath localCacheFile, UriString packageFeed, IGitEnvironment environment, bool alwaysDownload = false) { DugiteReleaseManifest package = null; var filename = localCacheFile.FileName; var cacheDir = localCacheFile.Parent; var key = localCacheFile.FileNameWithoutExtension + "_updatelastCheckTime"; var now = DateTimeOffset.Now; if (!localCacheFile.FileExists() || (alwaysDownload || now.Date > environment.UserSettings.Get <DateTimeOffset>(key).Date)) { var result = new DownloadTask(taskManager, packageFeed, localCacheFile.Parent, filename) .Catch(ex => { Logger.Warning(@"Error downloading package feed:{0} ""{1}"" Message:""{2}""", packageFeed, ex.GetType().ToString(), ex.GetExceptionMessageShort()); return(true); }).RunSynchronously(); localCacheFile = result.ToSPath(); if (localCacheFile.IsInitialized && !alwaysDownload) { environment.UserSettings.Set <DateTimeOffset>(key, now); } } if (!localCacheFile.IsInitialized) { // try from assembly resources localCacheFile = AssemblyResources.ToFile(ResourceType.Platform, filename, cacheDir, environment); } if (localCacheFile.IsInitialized) { try { package = Load(taskManager, localCacheFile, cacheDir, environment); } catch (Exception ex) { Logger.Error(ex); } } return(package); }
public static void Initialize(IGitEnvironment env, IPlatform plat) { environment = env; platform = plat; //platform.Keychain.ConnectionsChanged += UserMayHaveChanged; // we need to do this to get the initial user information up front //UserMayHaveChanged(); repository = environment.Repository; UnityShim.Editor_finishedDefaultHeaderGUI += InspectorHeaderFinished; if (repository != null) { repository.LocksChanged += RepositoryOnLocksChanged; repository.CheckAndRaiseEventsIfCacheNewer(CacheType.GitLocks, lastLocksChangedEvent); } }
private static SPath TryGetFile(ResourceType resourceType, string resource, IGitEnvironment environment) { /* * This function attempts to get files embedded in the callers assembly. * Unity.VersionControl.Git which tends to contain logos * Git.Api which tends to contain application resources * * Each file's name is their physical path in the project. * * When running tests, we assume the tests are looking for application resources, and default to returning Git.Api * * First check for the resource in the calling assembly. * If the resource cannot be found, fallback to looking in Git.Api's assembly. * If the resource is still not found, it attempts to find it in the file system */ (string type, string os) = ParseResourceType(resourceType, environment); var stream = TryGetResource(resourceType, type, os, resource); if (stream != null) { var target = SPath.GetTempFilename(); return(target.WriteAllBytes(stream.ToByteArray())); } SPath possiblePath = environment.ExtensionInstallPath.Combine(type, os, resource); if (possiblePath.FileExists()) { return(possiblePath); } var basePath = resourceType == ResourceType.Icon ? "Editor" : "Api"; possiblePath = environment.ExtensionInstallPath.Parent.Combine(basePath, type, os, resource); if (possiblePath.FileExists()) { return(possiblePath); } return(SPath.Default); }
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 static SPath RelativeToProject(this SPath path, IGitEnvironment environment) { path.ThrowIfNotInitialized(); Guard.ArgumentNotNull(environment, nameof(environment)); var projectPath = environment.UnityProjectPath.ToSPath(); var repositoryPath = environment.RepositoryPath; if (projectPath == repositoryPath) { return(path); } if (repositoryPath.IsChildOf(projectPath)) { throw new InvalidOperationException($"RepositoryPath:\"{repositoryPath}\" should not be child of ProjectPath:\"{projectPath}\""); } return(repositoryPath.Combine(path).MakeAbsolute().RelativeTo(projectPath)); }
public UserSettings(IGitEnvironment environment) { SettingsPath = environment.UserCachePath.Combine(settingsFileName); }
public GitObjectFactory(IGitEnvironment environment) { this.environment = environment; }
public static SPath ToFile(ResourceType resourceType, string resource, SPath destinationPath, IGitEnvironment environment) { var source = TryGetFile(resourceType, resource, environment); if (source.IsInitialized) { return(source.Copy(destinationPath)); } return(SPath.Default); }
public HttpClient(IGitEnvironment environment) { this.client = new System.Net.Http.HttpClient(); this.client.DefaultRequestHeaders.Add(HeaderNames.UserAgent, USER_AGENT_HEADER); this.client.DefaultRequestHeaders.Add(HeaderNames.Authorization, $"Basic {environment.EncodededCredentials}"); }
/// <summary> /// Creates an instance of the process manager and the <see cref="GitProcessEnvironment"/>. /// </summary> /// <param name="environment"></param> public GitProcessManager(IGitEnvironment environment) : base(environment) { GitEnvironment = environment; GitProcessEnvironment = new ProcessEnvironment(DefaultProcessEnvironment, environment); }
public static Stream ToStream(ResourceType resourceType, string resource, IGitEnvironment environment) { return(TryGetStream(resourceType, resource, environment)); }
public LocalSettings(IGitEnvironment environment) { SettingsPath = environment.UnityProjectPath.ToSPath().Combine(RelativeSettingsPath, settingsFileName); }
public GitProcessEnvironment(IGitEnvironment environment, SPath repositoryRoot) : base(environment, FindRepositoryRoot(repositoryRoot)) { Instance = this; Reset(); }
public SystemSettings(IGitEnvironment environment) { SettingsPath = environment.SystemCachePath.Combine(settingsFileName); }