1
1
using System ;
2
2
using System . Linq ;
3
- using GitVersion . Logging ;
3
+ using GitVersion . Configuration ;
4
4
using GitVersion . OutputVariables ;
5
- using GitVersion . VersionCalculation ;
6
- using GitVersion . VersionCalculation . Cache ;
7
5
using GitVersion . VersionConverters . AssemblyInfo ;
8
6
using GitVersion . VersionConverters . GitVersionInfo ;
9
7
using GitVersion . VersionConverters . OutputGenerator ;
12
10
13
11
namespace GitVersion
14
12
{
15
- public class GitVersionTool : IGitVersionTool
13
+ public class GitVersionOutputTool : IGitVersionOutputTool
16
14
{
17
- private readonly ILog log ;
18
- private readonly IGitVersionCache gitVersionCache ;
19
- private readonly INextVersionCalculator nextVersionCalculator ;
20
- private readonly IVariableProvider variableProvider ;
21
- private readonly IGitPreparer gitPreparer ;
22
- private readonly IGitVersionCacheKeyFactory cacheKeyFactory ;
15
+ private readonly IOptions < GitVersionOptions > options ;
16
+ private readonly IConfigProvider configProvider ;
23
17
private readonly IOutputGenerator outputGenerator ;
24
18
private readonly IWixVersionFileUpdater wixVersionFileUpdater ;
25
19
private readonly IGitVersionInfoGenerator gitVersionInfoGenerator ;
26
20
private readonly IAssemblyInfoFileUpdater assemblyInfoFileUpdater ;
27
21
private readonly IProjectFileUpdater projectFileUpdater ;
28
22
29
- private readonly IOptions < GitVersionOptions > options ;
30
- private readonly Lazy < GitVersionContext > versionContext ;
31
- private GitVersionContext context => versionContext . Value ;
32
-
33
- public GitVersionTool ( ILog log , INextVersionCalculator nextVersionCalculator , IVariableProvider variableProvider , IGitPreparer gitPreparer ,
34
- IGitVersionCache gitVersionCache , IGitVersionCacheKeyFactory cacheKeyFactory ,
35
- IOutputGenerator outputGenerator , IWixVersionFileUpdater wixVersionFileUpdater , IGitVersionInfoGenerator gitVersionInfoGenerator , IAssemblyInfoFileUpdater assemblyInfoFileUpdater ,
36
- IOptions < GitVersionOptions > options , Lazy < GitVersionContext > versionContext , IProjectFileUpdater projectFileUpdater )
23
+ public GitVersionOutputTool ( IOptions < GitVersionOptions > options , IConfigProvider configProvider ,
24
+ IOutputGenerator outputGenerator , IWixVersionFileUpdater wixVersionFileUpdater ,
25
+ IGitVersionInfoGenerator gitVersionInfoGenerator , IAssemblyInfoFileUpdater assemblyInfoFileUpdater ,
26
+ IProjectFileUpdater projectFileUpdater )
37
27
{
38
- this . log = log ?? throw new ArgumentNullException ( nameof ( log ) ) ;
39
-
40
- this . nextVersionCalculator = nextVersionCalculator ?? throw new ArgumentNullException ( nameof ( nextVersionCalculator ) ) ;
41
- this . variableProvider = variableProvider ?? throw new ArgumentNullException ( nameof ( variableProvider ) ) ;
42
- this . gitPreparer = gitPreparer ?? throw new ArgumentNullException ( nameof ( gitPreparer ) ) ;
43
-
44
- this . cacheKeyFactory = cacheKeyFactory ?? throw new ArgumentNullException ( nameof ( cacheKeyFactory ) ) ;
45
- this . gitVersionCache = gitVersionCache ?? throw new ArgumentNullException ( nameof ( gitVersionCache ) ) ;
28
+ this . options = options ?? throw new ArgumentNullException ( nameof ( options ) ) ;
29
+ this . configProvider = configProvider ?? throw new ArgumentNullException ( nameof ( configProvider ) ) ;
46
30
47
31
this . outputGenerator = outputGenerator ?? throw new ArgumentNullException ( nameof ( outputGenerator ) ) ;
32
+
48
33
this . wixVersionFileUpdater = wixVersionFileUpdater ?? throw new ArgumentNullException ( nameof ( wixVersionFileUpdater ) ) ;
49
34
this . gitVersionInfoGenerator = gitVersionInfoGenerator ?? throw new ArgumentNullException ( nameof ( gitVersionInfoGenerator ) ) ;
50
35
this . assemblyInfoFileUpdater = assemblyInfoFileUpdater ?? throw new ArgumentNullException ( nameof ( gitVersionInfoGenerator ) ) ;
51
-
52
- this . options = options ?? throw new ArgumentNullException ( nameof ( options ) ) ;
53
- this . versionContext = versionContext ?? throw new ArgumentNullException ( nameof ( versionContext ) ) ;
54
- this . projectFileUpdater = projectFileUpdater ;
55
- }
56
-
57
- public VersionVariables CalculateVersionVariables ( )
58
- {
59
- gitPreparer . Prepare ( ) ; //we need to prepare the repository before using it for version calculation
60
-
61
- var gitVersionOptions = options . Value ;
62
-
63
- var cacheKey = cacheKeyFactory . Create ( gitVersionOptions . ConfigInfo . OverrideConfig ) ;
64
- var versionVariables = gitVersionOptions . Settings . NoCache ? default : gitVersionCache . LoadVersionVariablesFromDiskCache ( cacheKey ) ;
65
-
66
- if ( versionVariables != null ) return versionVariables ;
67
-
68
- var semanticVersion = nextVersionCalculator . FindVersion ( ) ;
69
- versionVariables = variableProvider . GetVariablesFor ( semanticVersion , context . Configuration , context . IsCurrentCommitTagged ) ;
70
-
71
- if ( gitVersionOptions . Settings . NoCache ) return versionVariables ;
72
- try
73
- {
74
- gitVersionCache . WriteVariablesToDiskCache ( cacheKey , versionVariables ) ;
75
- }
76
- catch ( AggregateException e )
77
- {
78
- log . Warning ( $ "One or more exceptions during cache write:{ System . Environment . NewLine } { e } ") ;
79
- }
80
-
81
- return versionVariables ;
36
+ this . projectFileUpdater = projectFileUpdater ?? throw new ArgumentNullException ( nameof ( projectFileUpdater ) ) ;
82
37
}
83
38
84
39
public void OutputVariables ( VersionVariables variables )
@@ -87,7 +42,8 @@ public void OutputVariables(VersionVariables variables)
87
42
88
43
using ( outputGenerator )
89
44
{
90
- outputGenerator . Execute ( variables , new OutputContext ( gitVersionOptions . WorkingDirectory , gitVersionOptions . OutputFile ) ) ;
45
+ var configuration = configProvider . Provide ( overrideConfig : options . Value . ConfigInfo . OverrideConfig ) ;
46
+ outputGenerator . Execute ( variables , new OutputContext ( gitVersionOptions . WorkingDirectory , gitVersionOptions . OutputFile , configuration . UpdateBuildNumber ) ) ;
91
47
}
92
48
}
93
49
0 commit comments