Skip to content

Commit

Permalink
Merge pull request Azure#1047 from Azure/master
Browse files Browse the repository at this point in the history
Sync to Master branch
  • Loading branch information
Hovsep committed May 17, 2016
2 parents b73c784 + b39ebd5 commit e23db71
Show file tree
Hide file tree
Showing 456 changed files with 62,938 additions and 1,983 deletions.
10 changes: 9 additions & 1 deletion AutoRest.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.24720.0
VisualStudioVersion = 14.0.25123.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AutoRest.Core", "AutoRest\AutoRest.Core\AutoRest.Core.csproj", "{C876085F-9DC3-41F0-B7B4-17022CD84684}"
EndProject
Expand Down Expand Up @@ -372,6 +372,14 @@ Global
{DA37E6A9-5D59-45A3-A809-ABA85031C369}.Portable-Debug|Any CPU.Build.0 = Portable-Debug|Any CPU
{DA37E6A9-5D59-45A3-A809-ABA85031C369}.Portable-Release|Any CPU.ActiveCfg = Portable-Release|Any CPU
{DA37E6A9-5D59-45A3-A809-ABA85031C369}.Portable-Release|Any CPU.Build.0 = Portable-Release|Any CPU
{654344A5-0556-49C7-BFB3-59676D7440D3}.Net45-Debug|Any CPU.ActiveCfg = Net45-Debug|Any CPU
{654344A5-0556-49C7-BFB3-59676D7440D3}.Net45-Debug|Any CPU.Build.0 = Net45-Debug|Any CPU
{654344A5-0556-49C7-BFB3-59676D7440D3}.Net45-Release|Any CPU.ActiveCfg = Net45-Release|Any CPU
{654344A5-0556-49C7-BFB3-59676D7440D3}.Net45-Release|Any CPU.Build.0 = Net45-Release|Any CPU
{654344A5-0556-49C7-BFB3-59676D7440D3}.Portable-Debug|Any CPU.ActiveCfg = Portable-Debug|Any CPU
{654344A5-0556-49C7-BFB3-59676D7440D3}.Portable-Debug|Any CPU.Build.0 = Portable-Debug|Any CPU
{654344A5-0556-49C7-BFB3-59676D7440D3}.Portable-Release|Any CPU.ActiveCfg = Portable-Release|Any CPU
{654344A5-0556-49C7-BFB3-59676D7440D3}.Portable-Release|Any CPU.Build.0 = Portable-Release|Any CPU
{654344A5-0556-49C7-BFB3-59676D7440D3}.Net45-Debug|Any CPU.ActiveCfg = Debug|Any CPU
{654344A5-0556-49C7-BFB3-59676D7440D3}.Net45-Debug|Any CPU.Build.0 = Debug|Any CPU
{654344A5-0556-49C7-BFB3-59676D7440D3}.Net45-Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down
3 changes: 3 additions & 0 deletions AutoRest/AutoRest.Core.Tests/CodeGeneratorsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,11 @@ public void OutputToSingleFile()
};

string path = Path.Combine(settings.OutputDirectory, "test.file.cs");
string existingContents = "this is dummy";
_fileSystem.VirtualStore[path] = new StringBuilder(existingContents);
var codeGenerator = new SampleCodeGenerator(settings);
codeGenerator.Generate(new ServiceClient()).GetAwaiter().GetResult();
Assert.DoesNotContain(existingContents, _fileSystem.VirtualStore[path].ToString());
Assert.Equal(4, _fileSystem.VirtualStore.Count);
Assert.True(_fileSystem.VirtualStore.ContainsKey(path));
Assert.True(_fileSystem.VirtualStore.ContainsKey("AutoRest.json"));
Expand Down
2 changes: 1 addition & 1 deletion AutoRest/AutoRest.Core/AutoRest.nuget.proj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<SdkNuGetPackage Include="AutoRest">
<PackageVersion>0.16.0$(NightlyBuildVersion)</PackageVersion>
<PackageVersion>0.17.0$(NightlyBuildVersion)</PackageVersion>
<!--Want to prevent NuGet from reporting warnings
like we are not putting assemblies under the \lib folder-->
<NoPackageAnalysis>true</NoPackageAnalysis>
Expand Down
1 change: 1 addition & 0 deletions AutoRest/AutoRest.Core/AutoRest.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<file src="binaries/net45/AutoRest.Generator.Azure.Ruby.dll" target="tools" />
<file src="binaries/net45/AutoRest.Generator.Python.dll" target="tools" />
<file src="binaries/net45/AutoRest.Generator.Azure.Python.dll" target="tools" />
<file src="binaries/net45/AutoRest.Generator.AzureResourceSchema.dll" target="tools" />
<file src="binaries/net45/AutoRest.Modeler.Swagger.dll" target="tools" />
<file src="binaries/net45/AutoRest.Modeler.CompositeSwagger.dll" target="tools" />
<file src="binaries/net45/Newtonsoft.Json.dll" target="tools" />
Expand Down
3 changes: 2 additions & 1 deletion AutoRest/AutoRest.Core/ClientModel/KnownPrimaryType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public enum KnownPrimaryType
Boolean,
Credentials,
Uuid,
Base64Url
Base64Url,
UnixTime
}
}
21 changes: 12 additions & 9 deletions AutoRest/AutoRest.Core/CodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace Microsoft.Rest.Generator
public abstract class CodeGenerator
{
public const string EnumObject = "x-ms-enum";
private bool firstTimeWriteSingleFile = true;

protected CodeGenerator(Settings settings)
{
Expand Down Expand Up @@ -99,7 +100,7 @@ public async Task Write(ITemplate template, string fileName)
/// <returns></returns>
public async Task Write(string template, string fileName)
{
string relativeFilePath = null;
string filePath = null;

if (Settings.OutputFileName != null)
{
Expand All @@ -110,17 +111,19 @@ public async Task Write(string template, string fileName)
ErrorManager.ThrowErrors();
}

relativeFilePath = Settings.OutputFileName;
filePath = Path.Combine(Settings.OutputDirectory, Settings.OutputFileName);

if (firstTimeWriteSingleFile)
{
// for SingleFileGeneration clean the file before writing only if its the first time
Settings.FileSystem.DeleteFile(filePath);
firstTimeWriteSingleFile = false;
}
}
else
{
relativeFilePath = fileName;
}
string filePath = Path.Combine(Settings.OutputDirectory, relativeFilePath);

// cleans file before writing unless single file
if (!(Settings.OutputFileName != null && IsSingleFileGenerationSupported))
{
filePath = Path.Combine(Settings.OutputDirectory, fileName);
// cleans file before writing
Settings.FileSystem.DeleteFile(filePath);
}
// Make sure the directory exist
Expand Down
4 changes: 2 additions & 2 deletions AutoRest/AutoRest.Core/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
[assembly: AssemblyCompany("Microsoft Corporation")]
[assembly: AssemblyProduct("Microsoft AutoRest")]
[assembly: AssemblyCopyright("Copyright (c) Microsoft Corporation")]
[assembly: AssemblyVersion("0.16.0.0")]
[assembly: AssemblyFileVersion("0.16.0.0")]
[assembly: AssemblyVersion("0.17.0.0")]
[assembly: AssemblyFileVersion("0.17.0.0")]

[assembly: NeutralResourcesLanguage("en")]
[assembly: CLSCompliant(true)]
Expand Down
51 changes: 50 additions & 1 deletion AutoRest/AutoRest.Core/Utilities/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public static string EscapeXmlComment(this string comment)
}

/// <summary>
/// Returns true is the type is a PrimaryType with KnownPrimaryType matching typeToMatch.
/// Returns true if the type is a PrimaryType with KnownPrimaryType matching typeToMatch.
/// </summary>
/// <param name="type"></param>
/// <param name="typeToMatch"></param>
Expand All @@ -263,5 +263,54 @@ public static bool IsPrimaryType(this IType type, KnownPrimaryType typeToMatch)
}
return false;
}

/// <summary>
/// Returns true if the <paramref name="type"/> is a PrimaryType with KnownPrimaryType matching <paramref name="typeToMatch"/>
/// or a DictionaryType with ValueType matching <paramref name="typeToMatch"/> or a SequenceType matching <paramref name="typeToMatch"/>
/// </summary>
/// <param name="type"></param>
/// <param name="typeToMatch"></param>
/// <returns></returns>
public static bool IsOrContainsPrimaryType(this IType type, KnownPrimaryType typeToMatch)
{
if (type == null)
{
return false;
}

if (type.IsPrimaryType(typeToMatch) ||
type.IsDictionaryContainingType(typeToMatch) ||
type.IsSequenceContainingType(typeToMatch))
{
return true;
}
return false;
}

/// <summary>
/// Returns true if the <paramref name="type"/> is a DictionaryType with ValueType matching <paramref name="typeToMatch"/>
/// </summary>
/// <param name="type"></param>
/// <param name="typeToMatch"></param>
/// <returns></returns>
public static bool IsDictionaryContainingType(this IType type, KnownPrimaryType typeToMatch)
{
DictionaryType dictionaryType = type as DictionaryType;
PrimaryType dictionaryPrimaryType = dictionaryType?.ValueType as PrimaryType;
return dictionaryPrimaryType != null && dictionaryPrimaryType.IsPrimaryType(typeToMatch);
}

/// <summary>
/// Returns true if the <paramref name="type"/>is a SequenceType matching <paramref name="typeToMatch"/>
/// </summary>
/// <param name="type"></param>
/// <param name="typeToMatch"></param>
/// <returns></returns>
public static bool IsSequenceContainingType(this IType type, KnownPrimaryType typeToMatch)
{
SequenceType sequenceType = type as SequenceType;
PrimaryType sequencePrimaryType = sequenceType?.ElementType as PrimaryType;
return sequencePrimaryType != null && sequencePrimaryType.IsPrimaryType(typeToMatch);
}
}
}
5 changes: 4 additions & 1 deletion AutoRest/AutoRest.Core/Utilities/FileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@

using System.IO;
using System.Net;
using System.Text;

namespace Microsoft.Rest.Generator.Utilities
{
public class FileSystem : IFileSystem
{
public void WriteFile(string path, string contents)
{
File.WriteAllText(path, contents);
File.WriteAllText(path, contents, Encoding.UTF8);
}

public string ReadFileAsText(string path)
{
using (var client = new WebClient())
{
client.Headers.Add("User-Agent: AutoRest");
client.Encoding = Encoding.UTF8;
return client.DownloadString(path);
}
}
Expand Down
3 changes: 3 additions & 0 deletions AutoRest/AutoRest/AutoRest.Release.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
},
"Azure.Python": {
"type": "AzurePythonCodeGenerator, AutoRest.Generator.Azure.Python"
},
"AzureResourceSchema": {
"type": "AzureResourceSchemaCodeGenerator, AutoRest.Generator.AzureResourceSchema"
}
},
"modelers": {
Expand Down
3 changes: 2 additions & 1 deletion AutoRest/AutoRest/AutoRest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<Compile Include="..\..\Tools\AssemblyVersionInfo.cs">
<Link>Properties\AssemblyVersionInfo.cs</Link>
</Compile>
<Compile Include="ExitCode.cs" />
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="HelpExample.cs" />
<Compile Include="HelpGenerator.cs" />
Expand Down Expand Up @@ -70,4 +71,4 @@
</Content>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
</Project>
3 changes: 3 additions & 0 deletions AutoRest/AutoRest/AutoRest.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
},
"Azure.Python": {
"type": "AzurePythonCodeGenerator, AutoRest.Generator.Azure.Python"
},
"AzureResourceSchema": {
"type": "AzureResourceSchemaCodeGenerator, AutoRest.Generator.AzureResourceSchema"
}
},
"modelers": {
Expand Down
14 changes: 14 additions & 0 deletions AutoRest/AutoRest/ExitCode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

namespace Microsoft.Rest.Generator.Cli
{
/// <summary>
/// Available exit codes.
/// </summary>
public enum ExitCode : int
{
Success = 0,
Error = 1
}
}
6 changes: 5 additions & 1 deletion AutoRest/AutoRest/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ namespace Microsoft.Rest.Generator.Cli
{
internal class Program
{
private static void Main(string[] args)
private static int Main(string[] args)
{
int exitCode = (int)ExitCode.Error;

try
{
Settings settings = null;
Expand Down Expand Up @@ -69,6 +71,7 @@ private static void Main(string[] args)
{
Console.WriteLine(Resources.GenerationComplete,
settings.CodeGenerator, settings.Input);
exitCode = (int)ExitCode.Success;
}
}

Expand All @@ -91,6 +94,7 @@ private static void Main(string[] args)
Console.Error.WriteLine(Resources.ConsoleErrorMessage, exception.Message);
Console.Error.WriteLine(Resources.ConsoleErrorStackTrace, exception.StackTrace);
}
return exitCode;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using Microsoft.Rest.Generator.AzureResourceSchema;
using Microsoft.Rest.Modeler.Swagger.Tests;
using System.IO;
using Xunit;

namespace AutoRest.Generator.AzureResourceSchema.Tests
{
[Collection("AutoRest Azure Resource Schema Tests")]
public static class AcceptanceTests
{
[Fact]
public static void Storage()
{
RunSwaggerTest("storage.json", "Storage");
}

[Fact]
public static void Batch()
{
RunSwaggerTest("BatchManagement.json", "Batch");
}

[Fact]
public static void Cdn()
{
RunSwaggerTest("cdn.json", "CDN");
}

[Fact]
public static void Compute()
{
RunSwaggerTest("compute.json", "Compute");
}

[Fact]
public static void Network()
{
RunSwaggerTest("network.json", "Network");
}

[Fact]
public static void Web()
{
RunSwaggerTest("web.json", "Web");
}

private static void RunSwaggerTest(string swaggerFileName, string expectedFolderName)
{
SwaggerSpecHelper.RunTests<AzureResourceSchemaCodeGenerator>(
Path.Combine("Swagger", swaggerFileName),
Path.Combine("Expected", expectedFolderName));
}
}
}
Loading

0 comments on commit e23db71

Please sign in to comment.