Skip to content

Commit

Permalink
Merge pull request #3451 from arturcic/feature/abstractions
Browse files Browse the repository at this point in the history
Added GitVersion.Abstractions module
  • Loading branch information
arturcic authored Mar 28, 2023
2 parents 83dbf0e + ea49bfa commit 7feae1d
Show file tree
Hide file tree
Showing 142 changed files with 1,052 additions and 1,050 deletions.
40 changes: 20 additions & 20 deletions new-cli/GitVersion.Common/GitVersion.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,64 +3,64 @@
<PackageReference Include="Polly" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\src\GitVersion.Core\Git\AuthenticationInfo.cs">
<Compile Include="..\..\src\GitVersion.Abstractions\Git\AuthenticationInfo.cs">
<Link>Git\AuthenticationInfo.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.Core\Git\CommitFilter.cs">
<Compile Include="..\..\src\GitVersion.Abstractions\Git\CommitFilter.cs">
<Link>Git\CommitFilter.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.Core\Git\IBranch.cs">
<Compile Include="..\..\src\GitVersion.Abstractions\Git\IBranch.cs">
<Link>Git\IBranch.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.Core\Git\IBranchCollection.cs">
<Compile Include="..\..\src\GitVersion.Abstractions\Git\IBranchCollection.cs">
<Link>Git\IBranchCollection.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.Core\Git\ICommit.cs">
<Compile Include="..\..\src\GitVersion.Abstractions\Git\ICommit.cs">
<Link>Git\ICommit.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.Core\Git\ICommitCollection.cs">
<Compile Include="..\..\src\GitVersion.Abstractions\Git\ICommitCollection.cs">
<Link>Git\ICommitCollection.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.Core\Git\IGitObject.cs">
<Compile Include="..\..\src\GitVersion.Abstractions\Git\IGitObject.cs">
<Link>Git\IGitObject.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.Core\Git\IGitRepository.cs">
<Compile Include="..\..\src\GitVersion.Abstractions\Git\IGitRepository.cs">
<Link>Git\IGitRepository.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.Core\Git\INamedReference.cs">
<Compile Include="..\..\src\GitVersion.Abstractions\Git\INamedReference.cs">
<Link>Git\INamedReference.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.Core\Git\IObjectId.cs">
<Compile Include="..\..\src\GitVersion.Abstractions\Git\IObjectId.cs">
<Link>Git\IObjectId.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.Core\Git\IReference.cs">
<Compile Include="..\..\src\GitVersion.Abstractions\Git\IReference.cs">
<Link>Git\IReference.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.Core\Git\IReferenceCollection.cs">
<Compile Include="..\..\src\GitVersion.Abstractions\Git\IReferenceCollection.cs">
<Link>Git\IReferenceCollection.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.Core\Git\IRefSpec.cs">
<Compile Include="..\..\src\GitVersion.Abstractions\Git\IRefSpec.cs">
<Link>Git\IRefSpec.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.Core\Git\IRefSpecCollection.cs">
<Compile Include="..\..\src\GitVersion.Abstractions\Git\IRefSpecCollection.cs">
<Link>Git\IRefSpecCollection.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.Core\Git\IRemote.cs">
<Compile Include="..\..\src\GitVersion.Abstractions\Git\IRemote.cs">
<Link>Git\IRemote.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.Core\Git\IRemoteCollection.cs">
<Compile Include="..\..\src\GitVersion.Abstractions\Git\IRemoteCollection.cs">
<Link>Git\IRemoteCollection.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.Core\Git\ITag.cs">
<Compile Include="..\..\src\GitVersion.Abstractions\Git\ITag.cs">
<Link>Git\ITag.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.Core\Git\ITagCollection.cs">
<Compile Include="..\..\src\GitVersion.Abstractions\Git\ITagCollection.cs">
<Link>Git\ITagCollection.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.Core\Git\ReferenceName.cs">
<Compile Include="..\..\src\GitVersion.Abstractions\Git\ReferenceName.cs">
<Link>Git\ReferenceName.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.Core\Git\RefSpecDirection.cs">
<Compile Include="..\..\src\GitVersion.Abstractions\Git\RefSpecDirection.cs">
<Link>Git\RefSpecDirection.cs</Link>
</Compile>
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>

<IsUnitTestProject>false</IsUnitTestProject>
<DisableApiAnalyzers>true</DisableApiAnalyzers>
<DisableApiAnalyzers>false</DisableApiAnalyzers>
<IsUnitTestProject Condition="$(MSBuildProjectName.EndsWith('.Tests')) or $(MSBuildProjectName.EndsWith('.Testing'))">true</IsUnitTestProject>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ namespace GitVersion.Agents;
public abstract class BuildAgentBase : ICurrentBuildAgent
{
protected readonly ILog Log;
protected IEnvironment Environment { get; }
protected IEnvironment Environment;

protected BuildAgentBase(IEnvironment environment, ILog log)
{
this.Log = log;
Environment = environment;
this.Environment = environment;
}

protected abstract string EnvironmentVariable { get; }
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

namespace GitVersion;

public abstract class GitVersionModule : IGitVersionModule
public interface IGitVersionModule
{
public abstract void RegisterTypes(IServiceCollection services);
void RegisterTypes(IServiceCollection services);

protected static IEnumerable<Type> FindAllDerivedTypes<T>(Assembly? assembly)
static IEnumerable<Type> FindAllDerivedTypes<T>(Assembly? assembly)
{
assembly.NotNull();

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ internal interface IConfigurationBuilder
{
void AddOverride(IReadOnlyDictionary<object, object?> value);

GitVersionConfiguration Build();
IGitVersionConfiguration Build();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace GitVersion.Configuration;
public interface IConfigurationFileLocator
{
bool TryGetConfigurationFile(string? workingDirectory, string? projectRootDirectory, out string? configFilePath);
GitVersionConfiguration ReadConfiguration(string? configFilePath);
IGitVersionConfiguration ReadConfiguration(string? configFilePath);
IReadOnlyDictionary<object, object?>? ReadOverrideConfiguration(string? configFilePath);
void Verify(string? workingDirectory, string? projectRootDirectory);
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System.Text.Encodings.Web;
using GitVersion.OutputVariables;

namespace GitVersion.Extensions;

public static class GitVersionVariablesExtensions
{
public static string ToJsonString(this GitVersionVariables gitVersionVariables)
{
var variablesType = typeof(VersionVariablesJsonModel);
var variables = new VersionVariablesJsonModel();

foreach (var (key, value) in gitVersionVariables.OrderBy(x => x.Key))
{
var propertyInfo = variablesType.GetProperty(key);
propertyInfo?.SetValue(variables, ChangeType(value, propertyInfo.PropertyType));
}

var serializeOptions = GetJsonSerializerOptions();

return JsonSerializer.Serialize(variables, serializeOptions);
}

public static JsonSerializerOptions GetJsonSerializerOptions()
{
var serializeOptions = new JsonSerializerOptions
{
WriteIndented = true,
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
Converters =
{
new VersionVariablesJsonStringConverter()
}
};
return serializeOptions;
}

private static object? ChangeType(object? value, Type type)
{
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>))
{
if (value == null || value.ToString()?.Length == 0)
{
return null;
}

type = Nullable.GetUnderlyingType(type)!;
}

return Convert.ChangeType(value, type);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ public static bool IsValidPath(this string? path)

try
{
_ = Path.GetFullPath(path);
_ = PathHelper.GetFullPath(path);
}
catch
{
path = PathHelper.Combine(System.Environment.CurrentDirectory, path);
path = PathHelper.Combine(Environment.CurrentDirectory, path);

try
{
_ = Path.GetFullPath(path);
_ = PathHelper.GetFullPath(path);
}
catch
{
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
26 changes: 26 additions & 0 deletions src/GitVersion.Abstractions/GitVersion.Abstractions.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<PackageId>GitVersion.Abstractions</PackageId>
<Title>GitVersion</Title>
<Description>Derives SemVer information from a repository following GitFlow or GitHubFlow. This is the Core library which both GitVersion cli and Task use allowing programatic usage of GitVersion.</Description>

<Product>$(AssemblyName)</Product>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" />
<PackageReference Include="Microsoft.Extensions.Options" />
<PackageReference Include="Polly" />
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="GitVersion.Core" />
<InternalsVisibleTo Include="GitVersion.Output" />
<InternalsVisibleTo Include="GitVersion.Schema" />
<InternalsVisibleTo Include="GitVersion.Core.Tests" />
<InternalsVisibleTo Include="GitVersion.App.Tests" />
<InternalsVisibleTo Include="GitVersion.MsBuild.Tests" />
</ItemGroup>

</Project>
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ namespace GitVersion.Helpers;
public static class StringComparerUtils
{
public static readonly StringComparer IgnoreCaseComparer = StringComparer.InvariantCultureIgnoreCase;
public static readonly StringComparison OsDependentComparison = System.Environment.OSVersion.Platform == PlatformID.Unix ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase;
public static readonly StringComparer OsDependentComparer = System.Environment.OSVersion.Platform == PlatformID.Unix ? StringComparer.Ordinal : StringComparer.OrdinalIgnoreCase;
public static readonly StringComparison OsDependentComparison = Environment.OSVersion.Platform == PlatformID.Unix ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase;
public static readonly StringComparer OsDependentComparer = Environment.OSVersion.Platform == PlatformID.Unix ? StringComparer.Ordinal : StringComparer.OrdinalIgnoreCase;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace GitVersion;

public class GitVersionOptions
{
public string WorkingDirectory { get; set; } = System.Environment.CurrentDirectory;
public string WorkingDirectory { get; set; } = Environment.CurrentDirectory;
public AssemblySettingsInfo AssemblySettingsInfo { get; } = new();
public AuthenticationInfo AuthenticationInfo { get; } = new();

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions src/GitVersion.Abstractions/PublicAPI.Shipped.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#nullable enable
Loading

0 comments on commit 7feae1d

Please sign in to comment.