Skip to content

Commit

Permalink
GitTools#1175 - First pass at GitVersionCore on netstadard - wip.
Browse files Browse the repository at this point in the history
Haven't been able to resolve some compilation errors yet due to lack of replacemnt API's on netstandard.
  • Loading branch information
dazinator committed Jul 29, 2017
1 parent c8332ef commit 120d8b6
Show file tree
Hide file tree
Showing 27 changed files with 341 additions and 211 deletions.
5 changes: 3 additions & 2 deletions src/GitVersion.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
# Visual Studio 15
VisualStudioVersion = 15.0.26430.16
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitVersionExe", "GitVersionExe\GitVersionExe.csproj", "{C3578A7B-09A6-4444-9383-0DEAFA4958BD}"
EndProject
Expand All @@ -26,6 +26,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
..\GitVersion.yml = ..\GitVersion.yml
..\LICENSE = ..\LICENSE
..\mkdocs.yml = ..\mkdocs.yml
NuGet.config = NuGet.config
..\README.md = ..\README.md
EndProjectSection
EndProject
Expand Down
111 changes: 110 additions & 1 deletion src/GitVersionCore/BuildServers/AppVeyor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
using System;
using System.Net;
using System.Text;
#if !NETDESKTOP
using System.Net.Http;
using System.Threading.Tasks;
using System.Net.Http.Headers;
using Newtonsoft.Json;
using System.IO;
#endif

public class AppVeyor : BuildServerBase
{
Expand All @@ -13,6 +20,97 @@ public override bool CanApplyToCurrentContext()
return !string.IsNullOrEmpty(Environment.GetEnvironmentVariable(EnvironmentVariableName));
}

#if !NETDESKTOP


public override string GenerateSetVersionMessage(VersionVariables variables)
{

var buildNumber = Environment.GetEnvironmentVariable("APPVEYOR_BUILD_NUMBER");
var restBase = Environment.GetEnvironmentVariable("APPVEYOR_API_URL");

var request = (HttpWebRequest)WebRequest.Create(restBase + "api/build");
request.Method = "PUT";


var data = string.Format("{{ \"version\": \"{0}.build.{1}\" }}", variables.FullSemVer, buildNumber);
var bytes = Encoding.UTF8.GetBytes(data);
if (request.Headers == null)
{
request.Headers = new WebHeaderCollection();
}
var bytesLength = bytes.Length;
request.Headers["Content-Length"] = bytesLength.ToString();

// request.ContentLength = bytes.Length;
request.ContentType = "application/json";

using (var writeStream = request.GetRequestStreamAsync().Result)
{
writeStream.Write(bytes, 0, bytes.Length);
}

//var result = request.BeginGetRequestStream((asyncResult) =>
// {
// using (var writeStream = request.EndGetRequestStream(asyncResult))
// {
// writeStream.Write(bytes, 0, bytes.Length);
// }

// }, null);

// result.AsyncWaitHandle.WaitOne(new TimeSpan(0, 3, 0));

using (var response = (HttpWebResponse)request.GetResponseAsync().Result)
{
if (response.StatusCode != HttpStatusCode.OK && response.StatusCode != HttpStatusCode.NoContent)
{
var message = string.Format("Request failed. Received HTTP {0}", response.StatusCode);
return message;
}
}

return string.Format("Set AppVeyor build number to '{0}'.", variables.FullSemVer);

}


public override string[] GenerateSetParameterMessage(string name, string value)
{

// var buildNumber = Environment.GetEnvironmentVariable("APPVEYOR_BUILD_NUMBER");
var restBase = Environment.GetEnvironmentVariable("APPVEYOR_API_URL");

var request = (HttpWebRequest)WebRequest.Create(restBase + "api/build/variables");
request.Method = "POST";
request.ContentType = "application/json";
request.Accept = "application/json";

var data = string.Format("{{ \"name\": \"GitVersion_{0}\", \"value\": \"{1}\" }}", name, value);
var bytes = Encoding.UTF8.GetBytes(data);
if (request.Headers == null)
{
request.Headers = new WebHeaderCollection();
}
var bytesLength = bytes.Length;
// No property for content-length - and no Add() method on header collection? WHAAAAT
// request.ContentLength = bytes.Length;
request.Headers["Content-Length"] = bytesLength.ToString();

using (var writeStream = request.GetRequestStreamAsync().Result)
{
writeStream.Write(bytes, 0, bytes.Length);
}

return new[]
{
string.Format("Adding Environment Variable. name='GitVersion_{0}' value='{1}']", name, value)
};
}


#else

public override string GenerateSetVersionMessage(VersionVariables variables)
{
var buildNumber = Environment.GetEnvironmentVariable("APPVEYOR_BUILD_NUMBER");
Expand All @@ -23,7 +121,14 @@ public override string GenerateSetVersionMessage(VersionVariables variables)

var data = string.Format("{{ \"version\": \"{0}.build.{1}\" }}", variables.FullSemVer, buildNumber);
var bytes = Encoding.UTF8.GetBytes(data);
request.ContentLength = bytes.Length;
if (request.Headers == null)
{
request.Headers = new WebHeaderCollection();
}
var bytesLength = bytes.Length;
request.Headers["Content-Length"] = bytesLength.ToString();

// request.ContentLength = bytes.Length;
request.ContentType = "application/json";

using (var writeStream = request.GetRequestStream())
Expand Down Expand Up @@ -60,5 +165,9 @@ public override string[] GenerateSetParameterMessage(string name, string value)
string.Format("Adding Environment Variable. name='GitVersion_{0}' value='{1}']", name, value)
};
}


#endif

}
}
2 changes: 2 additions & 0 deletions src/GitVersionCore/BuildServers/BuildServerList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ public static class BuildServerList
{
static List<IBuildServer> BuildServers = new List<IBuildServer>
{
#if NETDESKTOP
new ContinuaCi(),
#endif
new TeamCity(),
new AppVeyor(),
new MyGet(),
Expand Down
4 changes: 4 additions & 0 deletions src/GitVersionCore/BuildServers/ContinuaCi.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace GitVersion
{
#if NETDESKTOP
using Microsoft.Win32;

public class ContinuaCi : BuildServerBase
Expand Down Expand Up @@ -42,4 +43,7 @@ static bool RegistryKeyExists(string keyName, RegistryView registryView)
return localKey != null;
}
}

#endif

}
4 changes: 2 additions & 2 deletions src/GitVersionCore/BuildServers/MyGet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public override bool CanApplyToCurrentContext()
var buildRunner = Environment.GetEnvironmentVariable("BuildRunner");

return !string.IsNullOrEmpty(buildRunner)
&& buildRunner.Equals("MyGet", StringComparison.InvariantCultureIgnoreCase);
&& buildRunner.Equals("MyGet", StringComparerUtils.IngoreCaseComparison);
}

public override string[] GenerateSetParameterMessage(string name, string value)
Expand All @@ -20,7 +20,7 @@ public override string[] GenerateSetParameterMessage(string name, string value)
string.Format("##myget[setParameter name='GitVersion.{0}' value='{1}']", name, ServiceMessageEscapeHelper.EscapeValue(value))
};

if (string.Equals(name, "LegacySemVerPadded", StringComparison.InvariantCultureIgnoreCase))
if (string.Equals(name, "LegacySemVerPadded", StringComparerUtils.IngoreCaseComparison))
{
messages.Add(string.Format("##myget[buildNumber '{0}']", ServiceMessageEscapeHelper.EscapeValue(value)));
}
Expand Down
1 change: 1 addition & 0 deletions src/GitVersionCore/Configuration/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using YamlDotNet.Serialization;

Expand Down
2 changes: 1 addition & 1 deletion src/GitVersionCore/Configuration/ConfigurationProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace GitVersion
using System.IO;
using System.Linq;
using System.Text;
using WarningException = System.ComponentModel.WarningException;
using WarningException = GitTools.WarningException;

public class ConfigurationProvider
{
Expand Down
5 changes: 4 additions & 1 deletion src/GitVersionCore/Configuration/LegacyConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ namespace GitVersion
using System.Collections.Generic;
using System.Linq;
using YamlDotNet.Serialization;
using System.Reflection;

/// <summary>
/// Obsolete properties are added to this, so we can check to see if they are used and provide good error messages for migration
Expand Down Expand Up @@ -42,7 +43,9 @@ public Dictionary<string, LegacyBranchConfig> Branches

private T MergeObjects<T>(T target, T source)
{
typeof(T).GetProperties()

var typeInfo = typeof(T);
typeInfo.GetProperties()
.Where(prop => prop.CanRead && prop.CanWrite)
.Select(_ => new
{
Expand Down
2 changes: 2 additions & 0 deletions src/GitVersionCore/Configuration/OldConfigurationException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ public OldConfigurationException(string message) : base(message)
{
}

#if NETDESKTOP
protected OldConfigurationException(
SerializationInfo info,
StreamingContext context) : base(info, context)
{
}
#endif
}
}
30 changes: 30 additions & 0 deletions src/GitVersionCore/Configuration/TypeHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Reflection;

//public static class TypeHelper
//{
//#if NETDESKTOP
// public static Type GetType<T>()
// {
// return GetType<T>();
// }
//#else
// public static TypeInfo GetType<T>()
// {
// return GetType<T>();
// }
//#endif

//#if NETDESKTOP
// public static IEnumerable<ConstructorInfo> GetConstructorsForType<T>()
// {
// return GetType<T>().GetConstructors();
// }
//#else
// public static IEnumerable<ConstructorInfo> GetConstructorsForType<T>()
// {
// return GetType<T>().DeclaredConstructors;
// }
//#endif
//}
1 change: 1 addition & 0 deletions src/GitVersionCore/ExecuteCore.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace GitVersion
{
using GitTools;
using GitVersion.Helpers;
using LibGit2Sharp;
using System;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace GitVersionCore.Extensions
{
using System.IO;
using System.Reflection;

public static class ReadEmbeddedResourceExtensions
{
Expand All @@ -23,7 +24,11 @@ public static string ReadAsStringFromEmbeddedResource<T>(this string resourceNam

public static Stream ReadFromEmbeddedResource<T>(this string resourceName)
{
#if NETDESKTOP
var assembly = typeof(T).Assembly;
#else
var assembly = typeof(T).GetTypeInfo().Assembly;
#endif
return assembly.GetManifestResourceStream(resourceName);
}
}
Expand Down
Loading

0 comments on commit 120d8b6

Please sign in to comment.