committed by
GitHub
41 changed files with 542 additions and 278 deletions
@ -1,129 +0,0 @@ |
|||||
using System.Xml.Linq; |
|
||||
using System.Linq; |
|
||||
|
|
||||
public class Parameters |
|
||||
{ |
|
||||
public string Configuration { get; private set; } |
|
||||
public bool SkipTests { get; private set; } |
|
||||
public string MainRepo { get; private set; } |
|
||||
public string MasterBranch { get; private set; } |
|
||||
public string ReleasePlatform { get; private set; } |
|
||||
public string ReleaseConfiguration { get; private set; } |
|
||||
public string ReleaseBranchPrefix { get; private set; } |
|
||||
public string MSBuildSolution { get; private set; } |
|
||||
public bool IsLocalBuild { get; private set; } |
|
||||
public bool IsRunningOnUnix { get; private set; } |
|
||||
public bool IsRunningOnWindows { get; private set; } |
|
||||
public bool IsRunningOnAppVeyor { get; private set; } |
|
||||
public bool IsRunningOnAzure { get; private set; } |
|
||||
public bool IsPullRequest { get; private set; } |
|
||||
public bool IsMainRepo { get; private set; } |
|
||||
public bool IsMasterBranch { get; private set; } |
|
||||
public bool IsReleaseBranch { get; private set; } |
|
||||
public bool IsTagged { get; private set; } |
|
||||
public bool IsReleasable { get; private set; } |
|
||||
public bool IsMyGetRelease { get; private set; } |
|
||||
public bool IsNuGetRelease { get; private set; } |
|
||||
public bool PublishTestResults { get; private set; } |
|
||||
public string Version { get; private set; } |
|
||||
public DirectoryPath ArtifactsDir { get; private set; } |
|
||||
public DirectoryPath NugetRoot { get; private set; } |
|
||||
public DirectoryPath ZipRoot { get; private set; } |
|
||||
public DirectoryPath BinRoot { get; private set; } |
|
||||
public DirectoryPath TestResultsRoot { get; private set; } |
|
||||
public string DirSuffix { get; private set; } |
|
||||
public DirectoryPathCollection BuildDirs { get; private set; } |
|
||||
public string FileZipSuffix { get; private set; } |
|
||||
public FilePath ZipCoreArtifacts { get; private set; } |
|
||||
public FilePath ZipNuGetArtifacts { get; private set; } |
|
||||
public DirectoryPath ZipSourceControlCatalogDesktopDirs { get; private set; } |
|
||||
public FilePath ZipTargetControlCatalogDesktopDirs { get; private set; } |
|
||||
|
|
||||
public Parameters(ICakeContext context) |
|
||||
{ |
|
||||
var buildSystem = context.BuildSystem(); |
|
||||
|
|
||||
// ARGUMENTS |
|
||||
Configuration = context.Argument("configuration", "Release"); |
|
||||
SkipTests = context.HasArgument("skip-tests"); |
|
||||
|
|
||||
// CONFIGURATION |
|
||||
MainRepo = "https://github.com/AvaloniaUI/Avalonia"; |
|
||||
MasterBranch = "master"; |
|
||||
ReleaseBranchPrefix = "refs/heads/release/"; |
|
||||
ReleaseConfiguration = "Release"; |
|
||||
MSBuildSolution = "./dirs.proj"; |
|
||||
|
|
||||
// PARAMETERS |
|
||||
IsLocalBuild = buildSystem.IsLocalBuild; |
|
||||
IsRunningOnUnix = context.IsRunningOnUnix(); |
|
||||
IsRunningOnWindows = context.IsRunningOnWindows(); |
|
||||
IsRunningOnAppVeyor = buildSystem.AppVeyor.IsRunningOnAppVeyor; |
|
||||
IsRunningOnAzure = buildSystem.IsRunningOnVSTS || buildSystem.IsRunningOnTFS || context.EnvironmentVariable("LOGNAME") == "vsts"; |
|
||||
|
|
||||
IsPullRequest = buildSystem.AppVeyor.Environment.PullRequest.IsPullRequest; |
|
||||
IsMainRepo = StringComparer.OrdinalIgnoreCase.Equals(MainRepo, context.EnvironmentVariable("BUILD_REPOSITORY_URI")); |
|
||||
IsMasterBranch = StringComparer.OrdinalIgnoreCase.Equals(MasterBranch, context.EnvironmentVariable("BUILD_SOURCEBRANCHNAME")); |
|
||||
IsReleaseBranch = (context.EnvironmentVariable("BUILD_SOURCEBRANCH")??"").StartsWith(ReleaseBranchPrefix, StringComparison.OrdinalIgnoreCase); |
|
||||
IsTagged = buildSystem.AppVeyor.Environment.Repository.Tag.IsTag |
|
||||
&& !string.IsNullOrWhiteSpace(buildSystem.AppVeyor.Environment.Repository.Tag.Name); |
|
||||
IsReleasable = StringComparer.OrdinalIgnoreCase.Equals(ReleaseConfiguration, Configuration); |
|
||||
IsMyGetRelease = !IsTagged && IsReleasable; |
|
||||
IsNuGetRelease = IsMainRepo && IsReleasable && IsReleaseBranch; |
|
||||
|
|
||||
// VERSION |
|
||||
Version = context.Argument("force-nuget-version", GetVersion()); |
|
||||
|
|
||||
if (IsRunningOnAppVeyor) |
|
||||
{ |
|
||||
string tagVersion = null; |
|
||||
if (IsTagged) |
|
||||
{ |
|
||||
var tag = buildSystem.AppVeyor.Environment.Repository.Tag.Name; |
|
||||
var nugetReleasePrefix = "nuget-release-"; |
|
||||
IsNuGetRelease = IsTagged && IsReleasable && tag.StartsWith(nugetReleasePrefix); |
|
||||
if(IsNuGetRelease) |
|
||||
tagVersion = tag.Substring(nugetReleasePrefix.Length); |
|
||||
} |
|
||||
if(tagVersion != null) |
|
||||
{ |
|
||||
Version = tagVersion; |
|
||||
} |
|
||||
else |
|
||||
{ |
|
||||
// Use AssemblyVersion with Build as version |
|
||||
Version += "-build" + context.EnvironmentVariable("APPVEYOR_BUILD_NUMBER") + "-beta"; |
|
||||
} |
|
||||
} |
|
||||
else if (IsRunningOnAzure) |
|
||||
{ |
|
||||
if(!IsNuGetRelease) |
|
||||
{ |
|
||||
// Use AssemblyVersion with Build as version |
|
||||
Version += "-build" + context.EnvironmentVariable("BUILD_BUILDID") + "-beta"; |
|
||||
} |
|
||||
|
|
||||
PublishTestResults = true; |
|
||||
} |
|
||||
|
|
||||
// DIRECTORIES |
|
||||
ArtifactsDir = (DirectoryPath)context.Directory("./artifacts"); |
|
||||
NugetRoot = ArtifactsDir.Combine("nuget"); |
|
||||
ZipRoot = ArtifactsDir.Combine("zip"); |
|
||||
BinRoot = ArtifactsDir.Combine("bin"); |
|
||||
TestResultsRoot = ArtifactsDir.Combine("test-results"); |
|
||||
BuildDirs = context.GetDirectories("**/bin") + context.GetDirectories("**/obj"); |
|
||||
DirSuffix = Configuration; |
|
||||
FileZipSuffix = Version + ".zip"; |
|
||||
ZipCoreArtifacts = ZipRoot.CombineWithFilePath("Avalonia-" + FileZipSuffix); |
|
||||
ZipNuGetArtifacts = ZipRoot.CombineWithFilePath("Avalonia-NuGet-" + FileZipSuffix); |
|
||||
ZipSourceControlCatalogDesktopDirs = (DirectoryPath)context.Directory("./samples/ControlCatalog.Desktop/bin/" + DirSuffix + "/net461"); |
|
||||
ZipTargetControlCatalogDesktopDirs = ZipRoot.CombineWithFilePath("ControlCatalog.Desktop-" + FileZipSuffix); |
|
||||
} |
|
||||
|
|
||||
private static string GetVersion() |
|
||||
{ |
|
||||
var xdoc = XDocument.Load("./build/SharedVersion.props"); |
|
||||
return xdoc.Descendants().First(x => x.Name.LocalName == "Version").Value; |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,89 @@ |
|||||
|
using System; |
||||
|
using System.Collections; |
||||
|
using System.ComponentModel; |
||||
|
using System.Globalization; |
||||
|
|
||||
|
namespace Avalonia.Markup.Xaml.Converters |
||||
|
{ |
||||
|
public class NullableTypeConverter<T> : TypeConverter where T : TypeConverter, new() |
||||
|
{ |
||||
|
private TypeConverter _inner; |
||||
|
|
||||
|
public NullableTypeConverter() |
||||
|
{ |
||||
|
_inner = new T(); |
||||
|
} |
||||
|
|
||||
|
public NullableTypeConverter(TypeConverter inner) |
||||
|
{ |
||||
|
_inner = inner; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) |
||||
|
{ |
||||
|
if (value == null) |
||||
|
return null; |
||||
|
return _inner.ConvertTo(context, culture, value, destinationType); |
||||
|
} |
||||
|
|
||||
|
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) |
||||
|
{ |
||||
|
if (value == null) |
||||
|
return null; |
||||
|
if (value as string == "") |
||||
|
return null; |
||||
|
return _inner.ConvertFrom(context, culture, value); |
||||
|
} |
||||
|
|
||||
|
public override object CreateInstance(ITypeDescriptorContext context, IDictionary propertyValues) |
||||
|
{ |
||||
|
return _inner.CreateInstance(context, propertyValues); |
||||
|
} |
||||
|
|
||||
|
public override bool GetStandardValuesSupported(ITypeDescriptorContext context) |
||||
|
{ |
||||
|
return _inner.GetStandardValuesSupported(context); |
||||
|
} |
||||
|
|
||||
|
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) |
||||
|
{ |
||||
|
return _inner.GetStandardValuesExclusive(context); |
||||
|
} |
||||
|
|
||||
|
public override bool GetCreateInstanceSupported(ITypeDescriptorContext context) |
||||
|
{ |
||||
|
return _inner.GetCreateInstanceSupported(context); |
||||
|
} |
||||
|
|
||||
|
public override bool GetPropertiesSupported(ITypeDescriptorContext context) |
||||
|
{ |
||||
|
return _inner.GetPropertiesSupported(context); |
||||
|
} |
||||
|
|
||||
|
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) |
||||
|
{ |
||||
|
return _inner.GetStandardValues(context); |
||||
|
} |
||||
|
|
||||
|
public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) |
||||
|
{ |
||||
|
return _inner.GetProperties(context, value, attributes); |
||||
|
} |
||||
|
|
||||
|
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) |
||||
|
{ |
||||
|
return _inner.CanConvertTo(context, destinationType); |
||||
|
} |
||||
|
|
||||
|
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) |
||||
|
{ |
||||
|
return _inner.CanConvertFrom(context, sourceType); |
||||
|
} |
||||
|
|
||||
|
public override bool IsValid(ITypeDescriptorContext context, object value) |
||||
|
{ |
||||
|
return _inner.IsValid(context, value); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,31 @@ |
|||||
|
using Avalonia.Controls; |
||||
|
using Avalonia.UnitTests; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace Avalonia.Markup.Xaml.UnitTests.Converters |
||||
|
{ |
||||
|
public class ClassWithNullableProperties |
||||
|
{ |
||||
|
public Thickness? Thickness { get; set; } |
||||
|
public Orientation? Orientation { get; set; } |
||||
|
} |
||||
|
|
||||
|
public class NullableConverterTests |
||||
|
{ |
||||
|
[Fact] |
||||
|
public void Nullable_Types_Should_Still_Be_Converted_Properly() |
||||
|
{ |
||||
|
using (UnitTestApplication.Start(TestServices.MockPlatformWrapper)) |
||||
|
{ |
||||
|
var xaml = @"<ClassWithNullableProperties
|
||||
|
xmlns='clr-namespace:Avalonia.Markup.Xaml.UnitTests.Converters' |
||||
|
Thickness = '5' Orientation='Vertical' |
||||
|
></ClassWithNullableProperties>";
|
||||
|
var loader = new AvaloniaXamlLoader(); |
||||
|
var data = (ClassWithNullableProperties)loader.Load(xaml, typeof(ClassWithNullableProperties).Assembly); |
||||
|
Assert.Equal(new Thickness(5), data.Thickness); |
||||
|
Assert.Equal(Orientation.Vertical, data.Orientation); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,4 +0,0 @@ |
|||||
<?xml version="1.0" encoding="utf-8"?> |
|
||||
<packages> |
|
||||
<package id="Cake" version="0.30.0" /> |
|
||||
</packages> |
|
||||
Loading…
Reference in new issue