Skip to content

Commit

Permalink
Generating management sdk from nuget spec.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Tavares committed Dec 4, 2013
1 parent 078f52b commit da8bc01
Show file tree
Hide file tree
Showing 16 changed files with 245 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,6 @@ packages

# Mac development
.DS_Store

# Specification DLLs
*.Specification.dll
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/10/nuspec.xsd">
<metadata>
<id>Hydra.Generator</id>
<version>1.0.5085.22928-prerelease</version>
<title>Hydra.Generator</title>
<authors>Microsoft Corporation</authors>
<owners>Microsoft Corporation</owners>
<licenseUrl>http://go.microsoft.com/fwlink/?LinkId=235170</licenseUrl>
<projectUrl>https://github.com/WindowsAzure/hydra</projectUrl>
<iconUrl>http://go.microsoft.com/fwlink/?LinkID=288890</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Advanced code generation for REST APIs, package for spec consumers.</description>
<summary>Advanced code generation for REST APIs, package for spec consumers.</summary>
<releaseNotes>Experimental prerelease</releaseNotes>
<copyright>Copyright 2013</copyright>
</metadata>
</package>
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">

<PropertyGroup Condition="$(GetSpecFromNuGet) == ''">
<SpecAssemblyPath>..\$(SpecAssemblyProjectDirName)\bin\$(Configuration)\$(SpecAssemblyFileName)</SpecAssemblyPath>
</PropertyGroup>

<PropertyGroup Condition="$(GetSpecFromNuGet) != ''">
<RestoreConfigFile>restore.config</RestoreConfigFile>
<RestoreConfigSwitch Condition="$(UsePrivateFeed) != ''">-ConfigFile $(RestoreConfigFile)</RestoreConfigSwitch>
<RestoreConfigSwitch Condition="$(UsePrivateFeed) == ''"></RestoreConfigSwitch>
</PropertyGroup>

<PropertyGroup>
<HydraExePath Condition="$(HydraExePath)==''">$(MSBuildThisFileDirectory)\..\tools\Hydra.exe</HydraExePath>
<!-- support running hydra either on Windows or under mono -->
<HydraCommand Condition="$(OS) == 'Windows_NT'">"$(HydraExePath)"</HydraCommand>
<HydraCommand Condition="$(OS) != 'Windows_NT'">mono --runtime=v4.0.30319 $(HydraExePath)</HydraCommand>
</PropertyGroup>

<Target Name="EnsureEnvironment">
<Error Text="The PRIVATE_FEED_URL property is not set. Either set it in the environment or specify it on the msbuild command line"
Condition="'$(PRIVATE_FEED_URL)'==''" ContinueOnError="ErrorAndContinue" />
<Error Text="The PRIVATE_FEED_USER_NAME property is not set. Either set it in the environment or specify it on the msbuild command line."
Condition="'$(PRIVATE_FEED_USER_NAME)'==''" ContinueOnError="ErrorAndContinue" />
<Error Text="The PRIVATE_FEED_PASSWORD property is not set. Either set it in the environment or specify it on the msbuild command line."
Condition="'$(PRIVATE_FEED_PASSWORD)'==''" ContinueOnError="ErrorAndContinue" />
</Target>

<Target Name="CreateRestoreConfig" DependsOnTargets="EnsureEnvironment" Condition="'$(UsePrivateFeed)'!=''">
<Exec Command='$(NuGetCommand) sources Add -Name Target -Source $(PRIVATE_FEED_URL) $(RestoreConfigSwitch)' />
<Exec Command='$(NuGetCommand) sources Update -Name Target -UserName $(PACKAGE_PUBLISHING_USER_NAME) -Password $(PACKAGE_PUBLISHING_PASSWORD) $(RestoreConfigSwitch)'
EchoOff="true"/>
</Target>

<Target Name="UpdateSpecDll" DependsOnTargets="CreateRestoreConfig" Condition="$(GetSpecFromNuGet)!=''">
<Exec Command="$(NuGetCommand) update $(PackagesConfig) $(RestoreConfigSwitch)" ContinueOnError="ErrorAndContinue" />
<Delete Files="$(RestoreConfigFile)" Condition="'$(UsePrivateFeed)'!=''" />
</Target>

<Target Name="UpdateSpecDll" Condition="$(GetSpecFromNuGet)==''">
<Copy SourceFiles="$(SpecAssemblyPath)" DestinationFolder="$(OutputPath)" />
</Target>

<Target Name="GenerateCodeFromSpecs" DependsOnTargets="UpdateSpecDll">
<Exec Command="$(HydraCommand)" />
</Target>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">

<PropertyGroup>
<!--
Is the spec being generated from being retrieved via NuGet or from a local project?
If this is a project that uses the spec from the same solution (for example, a test
project) then set this property to blank (or just remove it completely)
-->
<GetSpecFromNuGet>1</GetSpecFromNuGet>
</PropertyGroup>

<!-- User settable properties to control how specs are found in the same solution -->
<PropertyGroup Condition="$(GetSpecFromNuGet) == ''">
<!-- name of project directory which builds the spec dll -->
<SpecAssemblyProjectDirName>MySpec</SpecAssemblyProjectDirName>

<!-- The filename for the generated spec assembly -->
<SpecAssemblyFileName>$(SpecAssemblyProjectDirName).dll</SpecAssemblyFileName>
</PropertyGroup>

<!-- User settable properties to control how specs are retrieved from NuGet -->
<PropertyGroup Condition="$(GetSpecFromNuGet) != ''">
<!-- Set this to use a private feed, with credentials pulled from the environment -->
<UsePrivateFeed>true</UsePrivateFeed>
<!-- Where's the private feed to pull from? -->
<PRIVATE_FEED_URL>https://www.myget.org/F/hydra/</PRIVATE_FEED_URL>
<!--
The following two properties also need to be available. It is recommended that
you set them as environment variables rather than setting them here.
<PRIVATE_FEED_USER_NAME>User name for access to private feed</PRIVATE_FEED_USER_NAME>
<PRIVATE_FEED_PASSWORD>Password for access to private feed</PRIVATE_FEED_PASSWORD>
-->
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Hydra>
<Assembly>Spec assembly name goes here</Assembly>
<OutputDirectory>Generated</OutputDirectory>

<Specification>
<Type>REST Client type name goes here</Type>

<Platform>
<Flavor>CSharp.Azure</Flavor>
<OutputPath>Output file name goes here</OutputPath>
</Platform>

</Specification>
</Hydra>
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
param($installPath, $toolsPath, $package, $project)
# This is the MSBuild targets file to add
$targetsFile = [System.IO.Path]::Combine($toolsPath, 'BuildPackages.targets')

# Need to load MSBuild assembly if it's not loaded yet.
Add-Type -AssemblyName 'Microsoft.Build, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

# Grab the loaded MSBuild project for the project
$msbuild = [Microsoft.Build.Evaluation.ProjectCollection]::GlobalProjectCollection.GetLoadedProjects($project.FullName) | Select-Object -First 1

# Add import of GenerateCode.props. Must be done before the targets file that was automatically loaded
$targetsImport = $msbuild.Xml.Imports | Where-Object { $_.Project.EndsWith('Hydra.Generator.targets') } | Select-Object -First 1
$msbuild.Xml.InsertBeforeChild($msbuild.Xml.CreateImportElement("GenerateCode.props"), $targetsImport)

# Add BeforeBuild target to run the code generation
$target = $msbuild.Xml.AddTarget("BeforeBuild")
$target.DependsOnTargets = "RestorePackages;GenerateCodeFromSpecs"

$project.Save()
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
param($installPath, $toolsPath, $package, $project)

# Need to load MSBuild assembly if it's not loaded yet.
Add-Type -AssemblyName 'Microsoft.Build, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

# Grab the loaded MSBuild project for the project
$msbuild = [Microsoft.Build.Evaluation.ProjectCollection]::GlobalProjectCollection.GetLoadedProjects($project.FullName) | Select-Object -First 1

# Find all the imports and targets added by this package.
$itemsToRemove = @()

# Allow many in case a past package was incorrectly uninstalled
$itemsToRemove += $msbuild.Xml.Imports | Where-Object { $_.Project.EndsWith('GenerateCode.props') }
$itemsToRemove += $msbuild.Xml.Targets | Where-Object { $_.Name -eq 'BeforeBuild' -and $_.DependsOnTargets.Contains('GenerateCodeFromSpecs') }

# Remove the elements and save the project
if ($itemsToRemove -and $itemsToRemove.length)
{
foreach ($itemToRemove in $itemsToRemove)
{
$msbuild.Xml.RemoveChild($itemToRemove) | out-null
}

$project.Save()
}
36 changes: 36 additions & 0 deletions src/Management/GenerateCode.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">

<PropertyGroup>
<!--
Is the spec being generated from being retrieved via NuGet or from a local project?
If this is a project that uses the spec from the same solution (for example, a test
project) then set this property to blank (or just remove it completely)
-->
<GetSpecFromNuGet>1</GetSpecFromNuGet>
</PropertyGroup>

<!-- User settable properties to control how specs are found in the same solution -->
<PropertyGroup Condition="$(GetSpecFromNuGet) == ''">
<!-- name of project directory which builds the spec dll -->
<SpecAssemblyProjectDirName>MySpec</SpecAssemblyProjectDirName>

<!-- The filename for the generated spec assembly -->
<SpecAssemblyFileName>$(SpecAssemblyProjectDirName).dll</SpecAssemblyFileName>
</PropertyGroup>

<!-- User settable properties to control how specs are retrieved from NuGet -->
<PropertyGroup Condition="$(GetSpecFromNuGet) != ''">
<!-- Set this to use a private feed, with credentials pulled from the environment -->
<UsePrivateFeed>true</UsePrivateFeed>
<!-- Where's the private feed to pull from? -->
<PRIVATE_FEED_URL>https://www.myget.org/F/hydra/</PRIVATE_FEED_URL>
<!--
The following two properties also need to be available. It is recommended that
you set them as environment variables rather than setting them here.
<PRIVATE_FEED_USER_NAME>User name for access to private feed</PRIVATE_FEED_USER_NAME>
<PRIVATE_FEED_PASSWORD>Password for access to private feed</PRIVATE_FEED_PASSWORD>
-->
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Copyright (c) Microsoft and contributors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
13 changes: 12 additions & 1 deletion src/Management/Management.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
</PropertyGroup>
<Import Project="..\library.props" />
<ItemGroup>
<Compile Include="ManagementClient.cs" />
<Compile Include="Generated\ManagementClient.cs" />
<Compile Include="ManagementClient.Customization.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="GenerateCode.props" />
<None Include="Microsoft.WindowsAzure.Management.nuget.proj" />
<None Include="Microsoft.WindowsAzure.Management.nuspec" />
<None Include="packages.config" />
Expand All @@ -30,6 +32,9 @@
<Name>Common</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="hydra.xml" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" Condition=" '$(WindowsAzureCurrentConfiguration)' == 'portable' " />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" Condition=" '$(WindowsAzureCurrentConfiguration)' != 'portable' " />
<Import Project="..\..\packages\Microsoft.Bcl.Build.1.0.10\tools\Microsoft.Bcl.Build.targets" Condition="Exists('..\..\packages\Microsoft.Bcl.Build.1.0.10\tools\Microsoft.Bcl.Build.targets')" />
Expand All @@ -39,4 +44,10 @@
</Target>
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets') " />
<Import Project="$(SolutionDir)\src\library.targets" />
<Import Project="GenerateCode.props" />
<Import Project="..\..\packages\Hydra.Generator.1.0.5085.22928-prerelease\build\Hydra.Generator.targets" Condition="Exists('..\..\packages\Hydra.Generator.1.0.5085.22928-prerelease\build\Hydra.Generator.targets')" />
<Target Name="BeforeBuild" DependsOnTargets="RestorePackages;GenerateCodeFromSpecs" />
<Target Name="CopyMicrosoftWindowsAzureManagementSpecification" BeforeTargets="GenerateCodeFromSpecs">
<Copy SourceFiles="..\..\packages\Microsoft.WindowsAzure.Management.Specification.1.0.5085.30254-prerelease\tools\Microsoft.WindowsAzure.Management.Specification.dll" DestinationFolder="." />
</Target>
</Project>
15 changes: 15 additions & 0 deletions src/Management/app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.6.3.0" newVersion="2.6.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.6.3.0" newVersion="2.6.3.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
15 changes: 15 additions & 0 deletions src/Management/hydra.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Hydra>
<Assembly>Microsoft.WindowsAzure.Management.Specification.dll</Assembly>
<OutputDirectory>Generated</OutputDirectory>

<Specification>
<Type>Microsoft.WindowsAzure.Management.ManagementClient</Type>

<Platform>
<Flavor>CSharp.Azure</Flavor>
<OutputPath>ManagementClient.cs</OutputPath>
</Platform>

</Specification>
</Hydra>
2 changes: 2 additions & 0 deletions src/Management/packages.config
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Hydra.Generator" version="1.0.5085.22928-prerelease" targetFramework="portable-net45+sl50+wp80+win" />
<package id="Microsoft.Bcl" version="1.1.3" targetFramework="portable-net45+sl50+wp80+win" />
<package id="Microsoft.Bcl.Async" version="1.0.16" targetFramework="portable-net45+sl50+wp80+win" />
<package id="Microsoft.Bcl.Build" version="1.0.10" targetFramework="portable-net45+sl50+wp80+win" />
<package id="Microsoft.Net.Http" version="2.2.15" targetFramework="portable-net45+sl50+wp80+win" />
<package id="Microsoft.WindowsAzure.Management.Specification" version="1.0.5085.30254-prerelease" targetFramework="portable-net45+sl50+wp80+win" />
<package id="Newtonsoft.Json" version="5.0.6" targetFramework="portable-net45+sl50+wp80+win" />
</packages>

0 comments on commit da8bc01

Please sign in to comment.