Skip to content

Commit 1f9973e

Browse files
asbjornuJakeGinnivan
authored andcommitted
R# cleanup
1 parent 5b408dd commit 1f9973e

File tree

5 files changed

+92
-76
lines changed

5 files changed

+92
-76
lines changed
Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,41 @@
11
using System;
22
using System.IO;
3+
34
using LibGit2Sharp;
5+
46
using NUnit.Framework;
57

68
[TestFixture]
79
public class GitVersionTaskDirectoryTests
810
{
9-
string workDirectory;
1011
string gitDirectory;
12+
string workDirectory;
13+
1114

1215
[SetUp]
1316
public void CreateTemporaryRepository()
1417
{
15-
workDirectory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
18+
this.workDirectory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
19+
this.gitDirectory = Repository.Init(this.workDirectory)
20+
.TrimEnd(Path.DirectorySeparatorChar);
1621

17-
gitDirectory = Repository.Init(workDirectory)
18-
.TrimEnd(new[] { Path.DirectorySeparatorChar });
19-
20-
Assert.NotNull(gitDirectory);
22+
Assert.NotNull(this.gitDirectory);
2123
}
2224

25+
2326
[TearDown]
2427
public void Cleanup()
2528
{
26-
Directory.Delete(workDirectory, true);
29+
Directory.Delete(this.workDirectory, true);
2730
}
2831

32+
2933
[Test]
3034
public void Finds_GitDirectory()
3135
{
3236
try
3337
{
34-
VersionAndBranchFinder.GetVersion(workDirectory, null, true, null);
38+
VersionAndBranchFinder.GetVersion(this.workDirectory, null, true, null);
3539
}
3640
catch (Exception ex)
3741
{
@@ -41,10 +45,11 @@ public void Finds_GitDirectory()
4145
}
4246
}
4347

48+
4449
[Test]
4550
public void Finds_GitDirectory_In_Parent()
4651
{
47-
var childDir = Path.Combine(workDirectory, "child");
52+
var childDir = Path.Combine(this.workDirectory, "child");
4853
Directory.CreateDirectory(childDir);
4954

5055
try
@@ -58,4 +63,4 @@ public void Finds_GitDirectory_In_Parent()
5863
Assert.IsNotAssignableFrom<RepositoryNotFoundException>(ex);
5964
}
6065
}
61-
}
66+
}

src/GitVersionTask/AssemblyInfoBuilder/UpdateAssemblyInfo.cs

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,30 @@
33
using System;
44
using System.IO;
55
using System.Text;
6+
67
using GitVersion;
78
using GitVersion.Helpers;
9+
810
using Microsoft.Build.Framework;
9-
using Microsoft.Build.Utilities;
10-
using Logger = GitVersion.Logger;
1111

1212
public class UpdateAssemblyInfo : Task
1313
{
14+
IFileSystem fileSystem;
15+
16+
TaskLogger logger;
17+
18+
19+
public UpdateAssemblyInfo()
20+
{
21+
CompileFiles = new ITaskItem[]
22+
{
23+
};
24+
this.logger = new TaskLogger(this);
25+
this.fileSystem = new FileSystem();
26+
Logger.SetLoggers(this.LogInfo, this.LogWarning, s => this.LogError(s));
27+
}
28+
29+
1430
[Required]
1531
public string SolutionDirectory { get; set; }
1632

@@ -31,19 +47,6 @@ public class UpdateAssemblyInfo : Task
3147

3248
public bool NoFetch { get; set; }
3349

34-
TaskLogger logger;
35-
IFileSystem fileSystem;
36-
37-
public UpdateAssemblyInfo()
38-
{
39-
CompileFiles = new ITaskItem[] { };
40-
logger = new TaskLogger(this);
41-
fileSystem = new FileSystem();
42-
Logger.SetLoggers(
43-
this.LogInfo,
44-
this.LogWarning,
45-
s => this.LogError(s));
46-
}
4750

4851
public override bool Execute()
4952
{
@@ -54,12 +57,12 @@ public override bool Execute()
5457
}
5558
catch (WarningException errorException)
5659
{
57-
logger.LogWarning(errorException.Message);
60+
this.logger.LogWarning(errorException.Message);
5861
return true;
5962
}
6063
catch (Exception exception)
6164
{
62-
logger.LogError("Error occurred: " + exception);
65+
this.logger.LogError("Error occurred: " + exception);
6366
return false;
6467
}
6568
finally
@@ -68,20 +71,22 @@ public override bool Execute()
6871
}
6972
}
7073

71-
public void InnerExecute()
74+
75+
void InnerExecute()
7276
{
7377
TempFileTracker.DeleteTempFiles();
7478

7579
InvalidFileChecker.CheckForInvalidFiles(CompileFiles, ProjectFile);
7680

7781
VersionVariables versionVariables;
78-
if (!VersionAndBranchFinder.TryGetVersion(SolutionDirectory, out versionVariables, NoFetch, new Authentication(), fileSystem))
82+
if (!VersionAndBranchFinder.TryGetVersion(SolutionDirectory, out versionVariables, NoFetch, new Authentication()))
7983
{
8084
return;
8185
}
8286
CreateTempAssemblyInfo(versionVariables);
8387
}
8488

89+
8590
void CreateTempAssemblyInfo(VersionVariables versionVariables)
8691
{
8792
if (IntermediateOutputPath == null)
@@ -105,7 +110,9 @@ void CreateTempAssemblyInfo(VersionVariables versionVariables)
105110
{
106111
var content = File.ReadAllText(AssemblyInfoTempFilePath, Encoding.UTF8).Trim();
107112
if (string.Equals(assemblyInfo, content, StringComparison.Ordinal))
113+
{
108114
return; // nothign to do as the file matches what we'd create
115+
}
109116
}
110117
}
111118
catch (Exception)

src/GitVersionTask/GetVersion.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@
99

1010
public class GetVersion : Task
1111
{
12+
TaskLogger logger;
13+
14+
15+
public GetVersion()
16+
{
17+
this.logger = new TaskLogger(this);
18+
this.fileSystem = new FileSystem();
19+
Logger.SetLoggers(this.LogInfo, this.LogWarning, s => this.LogError(s));
20+
}
21+
22+
1223
[Required]
1324
public string SolutionDirectory { get; set; }
1425

@@ -80,19 +91,8 @@ public class GetVersion : Task
8091
[Output]
8192
public string CommitsSinceVersionSourcePadded { get; set; }
8293

83-
TaskLogger logger;
8494
IFileSystem fileSystem;
8595

86-
public GetVersion()
87-
{
88-
logger = new TaskLogger(this);
89-
fileSystem = new FileSystem();
90-
Logger.SetLoggers(
91-
this.LogInfo,
92-
this.LogWarning,
93-
s => this.LogError(s));
94-
}
95-
9696
public override bool Execute()
9797
{
9898
try
@@ -111,12 +111,12 @@ public override bool Execute()
111111
}
112112
catch (WarningException errorException)
113113
{
114-
logger.LogWarning(errorException.Message);
114+
this.logger.LogWarning(errorException.Message);
115115
return true;
116116
}
117117
catch (Exception exception)
118118
{
119-
logger.LogError("Error occurred: " + exception);
119+
this.logger.LogError("Error occurred: " + exception);
120120
return false;
121121
}
122122
finally

src/GitVersionTask/VersionAndBranchFinder.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,18 +103,20 @@ static VersionVariables LoadVersionVariablesFromDiskCache(string key, string dir
103103
vv.FileName = cacheFileName;
104104

105105
using (var stream = fileSystem.OpenWrite(cacheFileName))
106-
using (var sw = new StreamWriter(stream))
107106
{
108-
Dictionary<string, string> dictionary;
109-
using (Logger.IndentLog("Creating dictionary"))
107+
using (var sw = new StreamWriter(stream))
110108
{
111-
dictionary = vv.ToDictionary(x => x.Key, x => x.Value);
112-
}
109+
Dictionary<string, string> dictionary;
110+
using (Logger.IndentLog("Creating dictionary"))
111+
{
112+
dictionary = vv.ToDictionary(x => x.Key, x => x.Value);
113+
}
113114

114-
using (Logger.IndentLog("Storing version variables to cache file " + cacheFileName))
115-
{
116-
var serializer = new Serializer();
117-
serializer.Serialize(sw, dictionary);
115+
using (Logger.IndentLog("Storing version variables to cache file " + cacheFileName))
116+
{
117+
var serializer = new Serializer();
118+
serializer.Serialize(sw, dictionary);
119+
}
118120
}
119121
}
120122
}

src/GitVersionTask/WriteVersionInfoToBuildLog.cs

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
namespace GitVersionTask
22
{
3+
using System;
4+
using System.Collections.Generic;
5+
36
using GitVersion;
47
using GitVersion.Helpers;
8+
59
using Microsoft.Build.Framework;
6-
using Microsoft.Build.Utilities;
7-
using System;
8-
using System.Collections.Generic;
9-
using Logger = GitVersion.Logger;
1010

1111
public class WriteVersionInfoToBuildLog : Task
1212
{
13-
[Required]
14-
public string SolutionDirectory { get; set; }
15-
16-
public bool NoFetch { get; set; }
13+
readonly IFileSystem fileSystem;
14+
readonly TaskLogger logger;
1715

18-
TaskLogger logger;
19-
IFileSystem fileSystem;
2016

2117
public WriteVersionInfoToBuildLog()
2218
{
23-
logger = new TaskLogger(this);
24-
fileSystem = new FileSystem();
25-
Logger.SetLoggers(
26-
this.LogInfo,
27-
this.LogWarning,
28-
s => this.LogError(s));
19+
this.logger = new TaskLogger(this);
20+
this.fileSystem = new FileSystem();
21+
Logger.SetLoggers(this.LogInfo, this.LogWarning, s => this.LogError(s));
2922
}
3023

24+
25+
[Required]
26+
public string SolutionDirectory { get; set; }
27+
28+
public bool NoFetch { get; set; }
29+
30+
3131
public override bool Execute()
3232
{
3333
try
@@ -37,12 +37,12 @@ public override bool Execute()
3737
}
3838
catch (WarningException errorException)
3939
{
40-
logger.LogWarning(errorException.Message);
40+
this.logger.LogWarning(errorException.Message);
4141
return true;
4242
}
4343
catch (Exception exception)
4444
{
45-
logger.LogError("Error occurred: " + exception);
45+
this.logger.LogError("Error occurred: " + exception);
4646
return false;
4747
}
4848
finally
@@ -51,27 +51,29 @@ public override bool Execute()
5151
}
5252
}
5353

54-
public void InnerExecute()
54+
55+
void InnerExecute()
5556
{
5657
VersionVariables result;
5758
if (!VersionAndBranchFinder.TryGetVersion(SolutionDirectory, out result, NoFetch, new Authentication(), fileSystem))
5859
{
5960
return;
6061
}
61-
62+
6263
WriteIntegrationParameters(BuildServerList.GetApplicableBuildServers(), result);
6364
}
6465

65-
public void WriteIntegrationParameters(IEnumerable<IBuildServer> applicableBuildServers, VersionVariables variables)
66+
67+
void WriteIntegrationParameters(IEnumerable<IBuildServer> applicableBuildServers, VersionVariables variables)
6668
{
6769
foreach (var buildServer in applicableBuildServers)
6870
{
69-
logger.LogInfo(string.Format("Executing GenerateSetVersionMessage for '{0}'.", buildServer.GetType().Name));
70-
logger.LogInfo(buildServer.GenerateSetVersionMessage(variables));
71-
logger.LogInfo(string.Format("Executing GenerateBuildLogOutput for '{0}'.", buildServer.GetType().Name));
71+
this.logger.LogInfo(string.Format("Executing GenerateSetVersionMessage for '{0}'.", buildServer.GetType().Name));
72+
this.logger.LogInfo(buildServer.GenerateSetVersionMessage(variables));
73+
this.logger.LogInfo(string.Format("Executing GenerateBuildLogOutput for '{0}'.", buildServer.GetType().Name));
7274
foreach (var buildParameter in BuildOutputFormatter.GenerateBuildLogOutput(buildServer, variables))
7375
{
74-
logger.LogInfo(buildParameter);
76+
this.logger.LogInfo(buildParameter);
7577
}
7678
}
7779
}

0 commit comments

Comments
 (0)