Skip to content

Commit 06d76e5

Browse files
committed
decoupled modules from core and use abstractions instead
1 parent 683ca38 commit 06d76e5

25 files changed

+105
-97
lines changed

new-cli/GitVersion.Common/GitVersion.Common.csproj

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,64 +3,64 @@
33
<PackageReference Include="Polly" />
44
</ItemGroup>
55
<ItemGroup>
6-
<Compile Include="..\..\src\GitVersion.Core\Git\AuthenticationInfo.cs">
6+
<Compile Include="..\..\src\GitVersion.Abstractions\Git\AuthenticationInfo.cs">
77
<Link>Git\AuthenticationInfo.cs</Link>
88
</Compile>
9-
<Compile Include="..\..\src\GitVersion.Core\Git\CommitFilter.cs">
9+
<Compile Include="..\..\src\GitVersion.Abstractions\Git\CommitFilter.cs">
1010
<Link>Git\CommitFilter.cs</Link>
1111
</Compile>
12-
<Compile Include="..\..\src\GitVersion.Core\Git\IBranch.cs">
12+
<Compile Include="..\..\src\GitVersion.Abstractions\Git\IBranch.cs">
1313
<Link>Git\IBranch.cs</Link>
1414
</Compile>
15-
<Compile Include="..\..\src\GitVersion.Core\Git\IBranchCollection.cs">
15+
<Compile Include="..\..\src\GitVersion.Abstractions\Git\IBranchCollection.cs">
1616
<Link>Git\IBranchCollection.cs</Link>
1717
</Compile>
18-
<Compile Include="..\..\src\GitVersion.Core\Git\ICommit.cs">
18+
<Compile Include="..\..\src\GitVersion.Abstractions\Git\ICommit.cs">
1919
<Link>Git\ICommit.cs</Link>
2020
</Compile>
21-
<Compile Include="..\..\src\GitVersion.Core\Git\ICommitCollection.cs">
21+
<Compile Include="..\..\src\GitVersion.Abstractions\Git\ICommitCollection.cs">
2222
<Link>Git\ICommitCollection.cs</Link>
2323
</Compile>
24-
<Compile Include="..\..\src\GitVersion.Core\Git\IGitObject.cs">
24+
<Compile Include="..\..\src\GitVersion.Abstractions\Git\IGitObject.cs">
2525
<Link>Git\IGitObject.cs</Link>
2626
</Compile>
27-
<Compile Include="..\..\src\GitVersion.Core\Git\IGitRepository.cs">
27+
<Compile Include="..\..\src\GitVersion.Abstractions\Git\IGitRepository.cs">
2828
<Link>Git\IGitRepository.cs</Link>
2929
</Compile>
30-
<Compile Include="..\..\src\GitVersion.Core\Git\INamedReference.cs">
30+
<Compile Include="..\..\src\GitVersion.Abstractions\Git\INamedReference.cs">
3131
<Link>Git\INamedReference.cs</Link>
3232
</Compile>
33-
<Compile Include="..\..\src\GitVersion.Core\Git\IObjectId.cs">
33+
<Compile Include="..\..\src\GitVersion.Abstractions\Git\IObjectId.cs">
3434
<Link>Git\IObjectId.cs</Link>
3535
</Compile>
36-
<Compile Include="..\..\src\GitVersion.Core\Git\IReference.cs">
36+
<Compile Include="..\..\src\GitVersion.Abstractions\Git\IReference.cs">
3737
<Link>Git\IReference.cs</Link>
3838
</Compile>
39-
<Compile Include="..\..\src\GitVersion.Core\Git\IReferenceCollection.cs">
39+
<Compile Include="..\..\src\GitVersion.Abstractions\Git\IReferenceCollection.cs">
4040
<Link>Git\IReferenceCollection.cs</Link>
4141
</Compile>
42-
<Compile Include="..\..\src\GitVersion.Core\Git\IRefSpec.cs">
42+
<Compile Include="..\..\src\GitVersion.Abstractions\Git\IRefSpec.cs">
4343
<Link>Git\IRefSpec.cs</Link>
4444
</Compile>
45-
<Compile Include="..\..\src\GitVersion.Core\Git\IRefSpecCollection.cs">
45+
<Compile Include="..\..\src\GitVersion.Abstractions\Git\IRefSpecCollection.cs">
4646
<Link>Git\IRefSpecCollection.cs</Link>
4747
</Compile>
48-
<Compile Include="..\..\src\GitVersion.Core\Git\IRemote.cs">
48+
<Compile Include="..\..\src\GitVersion.Abstractions\Git\IRemote.cs">
4949
<Link>Git\IRemote.cs</Link>
5050
</Compile>
51-
<Compile Include="..\..\src\GitVersion.Core\Git\IRemoteCollection.cs">
51+
<Compile Include="..\..\src\GitVersion.Abstractions\Git\IRemoteCollection.cs">
5252
<Link>Git\IRemoteCollection.cs</Link>
5353
</Compile>
54-
<Compile Include="..\..\src\GitVersion.Core\Git\ITag.cs">
54+
<Compile Include="..\..\src\GitVersion.Abstractions\Git\ITag.cs">
5555
<Link>Git\ITag.cs</Link>
5656
</Compile>
57-
<Compile Include="..\..\src\GitVersion.Core\Git\ITagCollection.cs">
57+
<Compile Include="..\..\src\GitVersion.Abstractions\Git\ITagCollection.cs">
5858
<Link>Git\ITagCollection.cs</Link>
5959
</Compile>
60-
<Compile Include="..\..\src\GitVersion.Core\Git\ReferenceName.cs">
60+
<Compile Include="..\..\src\GitVersion.Abstractions\Git\ReferenceName.cs">
6161
<Link>Git\ReferenceName.cs</Link>
6262
</Compile>
63-
<Compile Include="..\..\src\GitVersion.Core\Git\RefSpecDirection.cs">
63+
<Compile Include="..\..\src\GitVersion.Abstractions\Git\RefSpecDirection.cs">
6464
<Link>Git\RefSpecDirection.cs</Link>
6565
</Compile>
6666
</ItemGroup>

src/GitVersion.Core/Agents/BuildAgentBase.cs renamed to src/GitVersion.Abstractions/Agents/BuildAgentBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ namespace GitVersion.Agents;
77
public abstract class BuildAgentBase : ICurrentBuildAgent
88
{
99
protected readonly ILog Log;
10-
protected IEnvironment Environment { get; }
10+
protected IEnvironment Environment;
1111

1212
protected BuildAgentBase(IEnvironment environment, ILog log)
1313
{
1414
this.Log = log;
15-
Environment = environment;
15+
this.Environment = environment;
1616
}
1717

1818
protected abstract string EnvironmentVariable { get; }
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1+
using GitVersion.Extensions;
12
using Microsoft.Extensions.DependencyInjection;
23

34
namespace GitVersion;
45

56
public interface IGitVersionModule
67
{
78
void RegisterTypes(IServiceCollection services);
9+
10+
static IEnumerable<Type> FindAllDerivedTypes<T>(Assembly? assembly)
11+
{
12+
assembly.NotNull();
13+
14+
var derivedType = typeof(T);
15+
return assembly.GetTypes().Where(t => t != derivedType && derivedType.IsAssignableFrom(t));
16+
}
817
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System.Text.Encodings.Web;
2+
using GitVersion.OutputVariables;
3+
4+
namespace GitVersion.Extensions;
5+
6+
public static class GitVersionVariablesExtensions
7+
{
8+
public static string ToJsonString(this GitVersionVariables gitVersionVariables)
9+
{
10+
var variablesType = typeof(VersionVariablesJsonModel);
11+
var variables = new VersionVariablesJsonModel();
12+
13+
foreach (var (key, value) in gitVersionVariables.OrderBy(x => x.Key))
14+
{
15+
var propertyInfo = variablesType.GetProperty(key);
16+
propertyInfo?.SetValue(variables, ChangeType(value, propertyInfo.PropertyType));
17+
}
18+
19+
var serializeOptions = GetJsonSerializerOptions();
20+
21+
return JsonSerializer.Serialize(variables, serializeOptions);
22+
}
23+
24+
public static JsonSerializerOptions GetJsonSerializerOptions()
25+
{
26+
var serializeOptions = new JsonSerializerOptions
27+
{
28+
WriteIndented = true,
29+
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
30+
Converters =
31+
{
32+
new VersionVariablesJsonStringConverter()
33+
}
34+
};
35+
return serializeOptions;
36+
}
37+
38+
private static object? ChangeType(object? value, Type type)
39+
{
40+
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>))
41+
{
42+
if (value == null || value.ToString()?.Length == 0)
43+
{
44+
return null;
45+
}
46+
47+
type = Nullable.GetUnderlyingType(type)!;
48+
}
49+
50+
return Convert.ChangeType(value, type);
51+
}
52+
}

src/GitVersion.Abstractions/Extensions/StringExtensions.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Diagnostics.CodeAnalysis;
22
using System.Text.RegularExpressions;
3+
using GitVersion.Helpers;
34

45
namespace GitVersion.Extensions;
56

@@ -19,15 +20,15 @@ public static bool IsValidPath(this string? path)
1920

2021
try
2122
{
22-
_ = Path.GetFullPath(path);
23+
_ = PathHelper.GetFullPath(path);
2324
}
2425
catch
2526
{
26-
path = Path.Combine(Environment.CurrentDirectory, path);
27+
path = PathHelper.Combine(Environment.CurrentDirectory, path);
2728

2829
try
2930
{
30-
_ = Path.GetFullPath(path);
31+
_ = PathHelper.GetFullPath(path);
3132
}
3233
catch
3334
{

src/GitVersion.Abstractions/GitVersion.Abstractions.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
<ItemGroup>
1212
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" />
13+
<PackageReference Include="Microsoft.Extensions.Options" />
1314
<PackageReference Include="Polly" />
1415
</ItemGroup>
1516

0 commit comments

Comments
 (0)