Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit f01a3da

Browse files
authored
Merge pull request #323 from github/shana/task-system-ftw
New task system based on schedulers
2 parents f956879 + d93cebd commit f01a3da

File tree

238 files changed

+9747
-6000
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

238 files changed

+9747
-6000
lines changed

GitHub.Unity.sln

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,21 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Net.Http-net_3_5", "
2121
EndProject
2222
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CopyLibrariesToDevelopmentFolder", "src\packaging\CopyLibrariesToDevelopmentFolder\CopyLibrariesToDevelopmentFolder.csproj", "{44257C81-EE4A-4817-9AF4-A26C02AA6DD4}"
2323
EndProject
24-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTests", "src\UnitTests\UnitTests.csproj", "{69F13D9D-AD56-4EEC-AE10-D528EE23E1A9}"
24+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTests", "src\tests\UnitTests\UnitTests.csproj", "{69F13D9D-AD56-4EEC-AE10-D528EE23E1A9}"
2525
EndProject
26-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IntegrationTests", "src\IntegrationTests\IntegrationTests.csproj", "{1AC3F82E-AEAE-4C84-825C-207BB264FCFA}"
26+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IntegrationTests", "src\tests\IntegrationTests\IntegrationTests.csproj", "{1AC3F82E-AEAE-4C84-825C-207BB264FCFA}"
2727
EndProject
2828
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{D17F1B4C-42DC-4E78-BCEF-9F239A084C4D}"
2929
EndProject
3030
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "packaging", "packaging", "{B50B646C-3B86-4BDA-9F2B-766F96608CE0}"
3131
EndProject
3232
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CopyLibrariesToPackageProject", "src\packaging\CopyLibrariesToPackageProject\CopyLibrariesToPackageProject.csproj", "{7DEF4226-7740-457F-9199-34174C49A978}"
3333
EndProject
34-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestUtils", "src\TestUtils\TestUtils.csproj", "{66A1D219-F61D-4AE4-9BD7-AAEB97276FFF}"
34+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestUtils", "src\tests\TestUtils\TestUtils.csproj", "{66A1D219-F61D-4AE4-9BD7-AAEB97276FFF}"
35+
EndProject
36+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TaskSystem", "src\tests\TaskSystemIntegrationTests\TaskSystem.csproj", "{1A382F40-FD9E-43E1-89C1-320073F35CE9}"
37+
EndProject
38+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestApp", "src\tests\TestApp\TestApp.csproj", "{08B87D2A-8CF1-4211-B7AA-5209F00F72F8}"
3539
EndProject
3640
Global
3741
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -106,6 +110,18 @@ Global
106110
{66A1D219-F61D-4AE4-9BD7-AAEB97276FFF}.dev|Any CPU.Build.0 = Debug|Any CPU
107111
{66A1D219-F61D-4AE4-9BD7-AAEB97276FFF}.Release|Any CPU.ActiveCfg = Release|Any CPU
108112
{66A1D219-F61D-4AE4-9BD7-AAEB97276FFF}.Release|Any CPU.Build.0 = Release|Any CPU
113+
{1A382F40-FD9E-43E1-89C1-320073F35CE9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
114+
{1A382F40-FD9E-43E1-89C1-320073F35CE9}.Debug|Any CPU.Build.0 = Debug|Any CPU
115+
{1A382F40-FD9E-43E1-89C1-320073F35CE9}.dev|Any CPU.ActiveCfg = Debug|Any CPU
116+
{1A382F40-FD9E-43E1-89C1-320073F35CE9}.dev|Any CPU.Build.0 = Debug|Any CPU
117+
{1A382F40-FD9E-43E1-89C1-320073F35CE9}.Release|Any CPU.ActiveCfg = Release|Any CPU
118+
{1A382F40-FD9E-43E1-89C1-320073F35CE9}.Release|Any CPU.Build.0 = Release|Any CPU
119+
{08B87D2A-8CF1-4211-B7AA-5209F00F72F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
120+
{08B87D2A-8CF1-4211-B7AA-5209F00F72F8}.Debug|Any CPU.Build.0 = Debug|Any CPU
121+
{08B87D2A-8CF1-4211-B7AA-5209F00F72F8}.dev|Any CPU.ActiveCfg = Debug|Any CPU
122+
{08B87D2A-8CF1-4211-B7AA-5209F00F72F8}.dev|Any CPU.Build.0 = Debug|Any CPU
123+
{08B87D2A-8CF1-4211-B7AA-5209F00F72F8}.Release|Any CPU.ActiveCfg = Release|Any CPU
124+
{08B87D2A-8CF1-4211-B7AA-5209F00F72F8}.Release|Any CPU.Build.0 = Release|Any CPU
109125
EndGlobalSection
110126
GlobalSection(SolutionProperties) = preSolution
111127
HideSolutionNode = FALSE
@@ -119,5 +135,7 @@ Global
119135
{1AC3F82E-AEAE-4C84-825C-207BB264FCFA} = {D17F1B4C-42DC-4E78-BCEF-9F239A084C4D}
120136
{7DEF4226-7740-457F-9199-34174C49A978} = {B50B646C-3B86-4BDA-9F2B-766F96608CE0}
121137
{66A1D219-F61D-4AE4-9BD7-AAEB97276FFF} = {D17F1B4C-42DC-4E78-BCEF-9F239A084C4D}
138+
{1A382F40-FD9E-43E1-89C1-320073F35CE9} = {D17F1B4C-42DC-4E78-BCEF-9F239A084C4D}
139+
{08B87D2A-8CF1-4211-B7AA-5209F00F72F8} = {D17F1B4C-42DC-4E78-BCEF-9F239A084C4D}
122140
EndGlobalSection
123141
EndGlobal

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ else
3232
nuget restore
3333
fi
3434

35-
xbuild GitHub.Unity.sln /verbosity:minimal /property:Configuration=$Configuration /target:$Target
35+
xbuild GitHub.Unity.sln /verbosity:normal /property:Configuration=$Configuration /target:$Target
3636

3737
cp -r unity/PackageProject/Assets/Editor/GitHub ../github-unity-test/GitHubExtensionProject/Assets/Editor || true
3838

common/SolutionInfo.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#pragma warning disable 436
2+
13
using System.Reflection;
24
using System.Resources;
35
using System.Runtime.CompilerServices;
@@ -18,6 +20,7 @@
1820
[assembly: InternalsVisibleTo("TestUtils", AllInternalsVisible = true)]
1921
[assembly: InternalsVisibleTo("UnitTests", AllInternalsVisible = true)]
2022
[assembly: InternalsVisibleTo("IntegrationTests", AllInternalsVisible = true)]
23+
[assembly: InternalsVisibleTo("TaskSystemIntegrationTests", AllInternalsVisible = true)]
2124

2225
//Required for NSubstitute
2326
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2", AllInternalsVisible = true)]

src/GitHub.Api/Api/ApplicationInfo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#pragma warning disable 436
12
namespace GitHub.Unity
23
{
34
public static class ApplicationInfo

src/GitHub.Api/ApplicationManagerBase.cs

Lines changed: 53 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace GitHub.Unity
66
{
77
abstract class ApplicationManagerBase : IApplicationManager
88
{
9-
protected static readonly ILogging logger = Logging.GetLogger<IApplicationManager>();
9+
protected static ILogging Logger { get; } = Logging.GetLogger<IApplicationManager>();
1010

1111
private IEnvironment environment;
1212
private AppConfiguration appConfiguration;
@@ -19,129 +19,107 @@ public ApplicationManagerBase(SynchronizationContext synchronizationContext)
1919
ThreadingHelper.SetMainThread();
2020
UIScheduler = TaskScheduler.FromCurrentSynchronizationContext();
2121
ThreadingHelper.MainThreadScheduler = UIScheduler;
22-
CancellationTokenSource = new CancellationTokenSource();
22+
TaskManager = new TaskManager(UIScheduler);
2323
// accessing Environment triggers environment initialization if it hasn't happened yet
24-
Platform = new Platform(Environment, Environment.FileSystem);
24+
Platform = new Platform(Environment);
2525
}
2626

27-
protected void Initialize(IUIDispatcher uiDispatcher)
27+
protected void Initialize()
2828
{
2929
UserSettings = new UserSettings(Environment);
30-
UserSettings.Initialize();
31-
Logging.TracingEnabled = UserSettings.Get("EnableTraceLogging", false);
32-
3330
LocalSettings = new LocalSettings(Environment);
34-
LocalSettings.Initialize();
35-
3631
SystemSettings = new SystemSettings(Environment);
32+
33+
UserSettings.Initialize();
34+
LocalSettings.Initialize();
3735
SystemSettings.Initialize();
3836

37+
Logging.TracingEnabled = UserSettings.Get("EnableTraceLogging", false);
3938
ProcessManager = new ProcessManager(Environment, Platform.GitEnvironment, CancellationToken);
40-
Platform.Initialize(ProcessManager, uiDispatcher);
39+
Platform.Initialize(ProcessManager, TaskManager);
40+
GitClient = new GitClient(Environment, ProcessManager, Platform.CredentialManager, TaskManager);
4141
}
4242

43-
public virtual Task Run()
43+
public virtual ITask Run()
4444
{
45-
Task task = null;
46-
try
47-
{
48-
task = RunInternal();
49-
}
50-
catch (Exception ex)
51-
{
52-
logger.Error(ex);
53-
throw;
54-
}
55-
return task;
45+
var progress = new ProgressReport();
46+
return new ActionTask(SetupAndRestart(progress));
5647
}
5748

5849
protected abstract string DetermineInstallationPath();
5950
protected abstract string GetAssetsPath();
6051
protected abstract string GetUnityPath();
6152

62-
public virtual async Task RestartRepository()
53+
public virtual ITask RestartRepository()
6354
{
64-
await ThreadingHelper.SwitchToThreadAsync();
55+
return new FuncTask<bool>(TaskManager.Token, _ =>
56+
{
57+
Environment.Initialize();
6558

66-
Environment.Initialize();
59+
if (Environment.RepositoryPath == null)
60+
return false;
61+
return true;
6762

68-
if (Environment.RepositoryPath != null)
63+
})
64+
.Defer(async s =>
6965
{
70-
try
71-
{
72-
var repositoryManagerFactory = new RepositoryManagerFactory();
73-
repositoryManager = repositoryManagerFactory.CreateRepositoryManager(Platform, TaskRunner, Environment.RepositoryPath, CancellationToken);
74-
}
75-
catch (Exception ex)
76-
{
77-
logger.Error(ex);
78-
}
66+
if (!s)
67+
return false;
68+
69+
var repositoryPathConfiguration = new RepositoryPathConfiguration(Environment.RepositoryPath);
70+
var gitConfig = new GitConfig(repositoryPathConfiguration.DotGitConfig);
71+
72+
var repositoryWatcher = new RepositoryWatcher(Platform, repositoryPathConfiguration, TaskManager.Token);
73+
repositoryManager = new RepositoryManager(Platform, TaskManager, gitConfig, repositoryWatcher,
74+
GitClient, repositoryPathConfiguration, TaskManager.Token);
75+
76+
await repositoryManager.Initialize().SafeAwait();
7977
Environment.Repository = repositoryManager.Repository;
80-
repositoryManager.Initialize();
78+
Logger.Trace($"Got a repository? {Environment.Repository}");
8179
repositoryManager.Start();
82-
}
80+
return true;
81+
})
82+
.Finally((_, __) => { });
8383
}
8484

85-
private async Task RunInternal()
85+
private async Task SetupAndRestart(ProgressReport progress)
8686
{
87-
await ThreadingHelper.SwitchToThreadAsync();
88-
89-
var gitSetup = new GitSetup(Environment, Environment.FileSystem, CancellationToken);
87+
var gitSetup = new GitSetup(Environment, CancellationToken);
9088
var expectedPath = gitSetup.GitInstallationPath;
91-
92-
var setupDone = await gitSetup.SetupIfNeeded(
93-
//new Progress<float>(x => logger.Trace("Percentage: {0}", x)),
94-
//new Progress<long>(x => logger.Trace("Remaining: {0}", x))
95-
);
96-
89+
var setupDone = await gitSetup.SetupIfNeeded(progress.Percentage, progress.Remaining);
9790
if (setupDone)
9891
Environment.GitExecutablePath = gitSetup.GitExecutablePath;
9992
else
10093
Environment.GitExecutablePath = await LookForGitInstallationPath();
10194

102-
logger.Trace("Environment.GitExecutablePath \"{0}\" Exists:{1}", gitSetup.GitExecutablePath, gitSetup.GitExecutablePath.FileExists());
95+
Logger.Trace("Environment.GitExecutablePath \"{0}\" Exists:{1}", gitSetup.GitExecutablePath, gitSetup.GitExecutablePath.FileExists());
10396

104-
await RestartRepository();
97+
await RestartRepository().StartAwait();
10598

10699
if (Environment.IsWindows)
107100
{
108-
string credentialHelper = null;
109-
var gitConfigGetTask = new GitConfigGetTask(Environment, ProcessManager,
110-
new TaskResultDispatcher<string>(s => {
111-
credentialHelper = s;
112-
}), "credential.helper", GitConfigSource.Global);
113-
114-
115-
await gitConfigGetTask.RunAsync(CancellationToken.None);
101+
var credentialHelper = await GitClient.GetConfig("credential.helper", GitConfigSource.Global).StartAwait();
116102

117103
if (string.IsNullOrEmpty(credentialHelper))
118104
{
119-
var gitConfigSetTask = new GitConfigSetTask(Environment, ProcessManager,
120-
new TaskResultDispatcher<string>(s => { }), "credential.helper", "wincred",
121-
GitConfigSource.Global);
122-
123-
await gitConfigSetTask.RunAsync(CancellationToken.None);
105+
await GitClient.SetConfig("credential.helper", "wincred", GitConfigSource.Global).StartAwait();
124106
}
125107
}
126108
}
127109

128-
private async Task<string> LookForGitInstallationPath()
110+
private async Task<NPath> LookForGitInstallationPath()
129111
{
130112
NPath cachedGitInstallPath = null;
131113
var path = SystemSettings.Get("GitInstallPath");
132114
if (!String.IsNullOrEmpty(path))
133115
cachedGitInstallPath = path.ToNPath();
134116

135117
// Root paths
136-
if (cachedGitInstallPath == null ||
137-
!cachedGitInstallPath.DirectoryExists())
118+
if (cachedGitInstallPath != null && cachedGitInstallPath.DirectoryExists())
138119
{
139-
return await GitEnvironment.FindGitInstallationPath(ProcessManager);
140-
}
141-
else
142-
{
143-
return cachedGitInstallPath.ToString();
120+
return cachedGitInstallPath;
144121
}
122+
return await GitClient.FindGitInstallation().SafeAwait();
145123
}
146124

147125
private bool disposed = false;
@@ -151,7 +129,7 @@ protected virtual void Dispose(bool disposing)
151129
{
152130
if (disposed) return;
153131
disposed = true;
154-
if (CancellationTokenSource != null) CancellationTokenSource.Cancel();
132+
if (TaskManager != null) TaskManager.Stop();
155133
if (repositoryManager != null) repositoryManager.Dispose();
156134
}
157135
}
@@ -194,11 +172,11 @@ public IEnvironment Environment
194172
public IPlatform Platform { get; protected set; }
195173
public virtual IProcessEnvironment GitEnvironment { get; set; }
196174
public IProcessManager ProcessManager { get; protected set; }
197-
public ITaskResultDispatcher MainThreadResultDispatcher { get; protected set; }
198-
public CancellationToken CancellationToken { get; protected set; }
199-
public ITaskRunner TaskRunner { get; protected set; }
175+
public CancellationToken CancellationToken { get { return TaskManager.Token; } }
176+
public ITaskManager TaskManager { get; protected set; }
177+
public IGitClient GitClient { get; protected set; }
178+
200179

201-
protected CancellationTokenSource CancellationTokenSource { get; private set; }
202180
protected TaskScheduler UIScheduler { get; private set; }
203181
protected SynchronizationContext SynchronizationContext { get; private set; }
204182
protected IRepositoryManager RepositoryManager { get { return repositoryManager; } }

src/GitHub.Api/Authentication/IPlatform.cs

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)