Repository: incubator-reef Updated Branches: refs/heads/master c5f33b233 -> 73fe0057c
[REEF-115] Pull reef version from pom file This fix will pull the Nuspec files into a temporary location /lang/cs/.nuget/nuspec, extract the version string from /lang/cs/pom.xml, and replace all $version$ tokens in the Nuspec files with the extracted version string. These finalized nuspec files are then used to create the NuGet packages. The packages are then copied to /lang/cs/.nuget/packages, but can also be found under the project's corresponding directory under /lang/cs/bin. JIRA REEF-115: https://github.com/apache/incubator-reef/pull/93 Author: tmajest <[email protected]> This closes #93 Project: http://git-wip-us.apache.org/repos/asf/incubator-reef/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-reef/commit/73fe0057 Tree: http://git-wip-us.apache.org/repos/asf/incubator-reef/tree/73fe0057 Diff: http://git-wip-us.apache.org/repos/asf/incubator-reef/diff/73fe0057 Branch: refs/heads/master Commit: 73fe0057cab6b83072fdc37996ecdb04a8b7f4ee Parents: c5f33b2 Author: tmajest <[email protected]> Authored: Thu Feb 19 14:08:52 2015 -0800 Committer: Julia Wang <[email protected]> Committed: Fri Feb 27 15:31:56 2015 -0800 ---------------------------------------------------------------------- lang/cs/.gitignore | 2 + lang/cs/.nuget/NuGet.targets | 53 +++++++++++++++++++- lang/cs/.nuget/finalizeNuspec.ps1 | 92 ++++++++++++++++++++++++++++++++++ lang/cs/build.props | 7 +++ 4 files changed, 152 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/73fe0057/lang/cs/.gitignore ---------------------------------------------------------------------- diff --git a/lang/cs/.gitignore b/lang/cs/.gitignore index aeaff29..3da4cf8 100644 --- a/lang/cs/.gitignore +++ b/lang/cs/.gitignore @@ -6,5 +6,7 @@ TestResults **/*.suo **/*.csproj.user **/obj +**/.nuget/nuspec +**/.nuget/packages http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/73fe0057/lang/cs/.nuget/NuGet.targets ---------------------------------------------------------------------- diff --git a/lang/cs/.nuget/NuGet.targets b/lang/cs/.nuget/NuGet.targets index 401dcdd..0a5b958 100644 --- a/lang/cs/.nuget/NuGet.targets +++ b/lang/cs/.nuget/NuGet.targets @@ -79,9 +79,15 @@ under the License. <PaddedSolutionDir Condition=" '$(OS)' == 'Windows_NT'">"$(SolutionDir) "</PaddedSolutionDir> <PaddedSolutionDir Condition=" '$(OS)' != 'Windows_NT' ">"$(SolutionDir)"</PaddedSolutionDir> + <!-- Nuspec file --> + <FinalizedNuspecFile>$(SolutionDir)\.nuget\nuspec\$(AssemblyName).nuspec</FinalizedNuspecFile> + + <!-- Project path --> + <NugetProjectPath>$(SolutionDir)\$(RootNamespace)</NugetProjectPath> + <!-- Commands --> <RestoreCommand>$(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(NonInteractiveSwitch) $(RequireConsentSwitch) -solutionDir $(PaddedSolutionDir)</RestoreCommand> - <BuildCommand>$(NuGetCommand) pack "$(ProjectPath)" -Properties "Configuration=$(Configuration);Platform=$(Platform)" $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols</BuildCommand> + <BuildCommand>$(NuGetCommand) pack "$(FinalizedNuspecFile)" -BasePath $(NugetProjectPath) -Properties "Configuration=$(Configuration);Platform=$(Platform)" $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" </BuildCommand> <!-- We need to ensure packages are restored prior to assembly resolve --> <BuildDependsOn Condition="$(RestorePackages) == 'true'"> @@ -96,6 +102,11 @@ under the License. </BuildDependsOn> </PropertyGroup> + <!-- Make sure clean will clean up .nuget/packages and .nuget/nuspec directories --> + <PropertyGroup> + <CleanDependsOn>$(CleanDependsOn);CleanNugetPackages</CleanDependsOn> + </PropertyGroup> + <Target Name="CheckPrerequisites"> <!-- Raise an error if we're unable to locate nuget.exe --> <Error Condition="'$(DownloadNuGetExe)' != 'true' AND !Exists('$(NuGetExePath)')" Text="Unable to locate '$(NuGetExePath)'" /> @@ -120,7 +131,10 @@ under the License. Condition="'$(OS)' == 'Windows_NT' And Exists('$(PackagesConfig)')" /> </Target> - <Target Name="BuildPackage" DependsOnTargets="CheckPrerequisites"> + <Target Name="BuildPackage" DependsOnTargets="BuildNupkg; MoveNuGetPackage"> + </Target> + + <Target Name="BuildNupkg" DependsOnTargets="CheckPrerequisites; FinalizeNuspecFiles"> <Exec Command="$(BuildCommand)" Condition=" '$(OS)' != 'Windows_NT' " /> @@ -129,6 +143,41 @@ under the License. Condition=" '$(OS)' == 'Windows_NT' " /> </Target> + <Target Name="FinalizeNuspecFiles"> + <PropertyGroup> + <FinalizeNuspecScript>$(SolutionDir)\.nuget\finalizeNuspec.ps1</FinalizeNuspecScript> + <ScriptCommand Condition="'$(IsSnapshot)' == 'true'">$(FinalizeNuspecScript) -SolutionDir $(SolutionDir) -Snapshot -SnapshotNumber $(SnapshotNumber)</ScriptCommand> + <ScriptCommand Condition="'$(IsSnapshot)' == 'false'">$(FinalizeNuspecScript) -SolutionDir $(SolutionDir)</ScriptCommand> + </PropertyGroup> + <Message Text="===SCRIPT: $(ScriptCommand)" /> + + <Exec Command="powershell -NonInteractive -NoProfile -Command $(ScriptCommand)" > + </Exec> + </Target> + + <Target Name="MoveNuGetPackage" DependsOnTargets="BuildNupkg"> + <ItemGroup> + <NugetPackageFiles Include="$(SolutionDir)\bin\$(Platform)\$(Configuration)\$(RootNamespace)\*.nupkg" /> + </ItemGroup> + + <PropertyGroup> + <NugetPackageOutputDir>$(SolutionDir)\.nuget\packages</NugetPackageOutputDir> + </PropertyGroup> + + <Copy SourceFiles="@(NugetPackageFiles)" DestinationFolder="$(NugetPackageOutputDir)" /> + </Target> + + <Target Name="CleanNugetPackages"> + <PropertyGroup> + <NuspecFilesDir>$(SolutionDir)\.nuget\nuspec</NuspecFilesDir> + <PackagesDir>$(SolutionDir)\.nuget\packages</PackagesDir> + </PropertyGroup> + + <RemoveDir Directories="$(NuspecFilesDir);$(PackagesDir)" /> + </Target> + + + <UsingTask TaskName="DownloadNuGet" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll"> <ParameterGroup> <OutputFilename ParameterType="System.String" Required="true" /> http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/73fe0057/lang/cs/.nuget/finalizeNuspec.ps1 ---------------------------------------------------------------------- diff --git a/lang/cs/.nuget/finalizeNuspec.ps1 b/lang/cs/.nuget/finalizeNuspec.ps1 new file mode 100644 index 0000000..69683d8 --- /dev/null +++ b/lang/cs/.nuget/finalizeNuspec.ps1 @@ -0,0 +1,92 @@ +<# +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at +http://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +#> + +Param( + [Parameter(Mandatory=$true)] + [string]$SolutionDir, + + [switch]$Snapshot, + + [int]$SnapshotNumber +) + +Function Get-Nuspec-Version { + <# + .DESCRIPTION + Extracts the NuGet version number from the pom.xml file in the source directory. + #> + + $pomPath = "$SolutionDir\pom.xml" + $pom = [xml] (Get-Content $pomPath) + $version = $pom.project.parent.version -replace '-incubating-SNAPSHOT','' + return $version +} + +Function Prep-Nuspec-Files { + <# + .DESCRIPTION + Creates a directory for the finalized nuspec files to live. Next, + the temporary nuspec files in each source directory will get copied + to the new nuspec directory. + #> + + $nuspecDir = "$SolutionDir\.nuget\nuspec" + + # Delete the directory if it already exists + if (Test-Path $nuspecDir) { + rmdir -Force -Recurse $nuspecDir + } + + # Create directory for finalized nuspec files to live + mkdir -Force $nuspecDir + + # Copy over temporary nuspec files into new nuspec directory + $tempNuspecFiles = Get-ChildItem $SolutionDir\**\*.nuspec + foreach ($tempNuspecFile in $tempNuspecFiles) { + Copy-Item $tempNuspecFile.FullName $nuspecDir + } +} + +Function Finalize-Nuspec-Version { + <# + .DESCRIPTION + Replaces the $version$ token in each nuspec file with the actual version string. + #> + + param([string]$version) + + if ($Snapshot) { + $fullVersion = "$version-SNAPSHOT-$SnapshotNumber" + } + else { + $fullVersion = $version + } + + $nuspecDir = "$SolutionDir\.nuget\nuspec" + $nuspecFiles = Get-ChildItem $nuspecDir + + # Replace the $version$ token with the specified version in each nuspec file + foreach ($nuspec in $nuspecFiles) { + $finalizedNuspec = Get-Content $nuspec.FullName | foreach { $_ -replace '\$version\$',"$fullVersion" } + Set-Content -Path $nuspec.FullName -Value $finalizedNuspec + } +} + +Prep-Nuspec-Files +$version = Get-Nuspec-Version +Finalize-Nuspec-Version($version) +Exit $LASTEXITCODE http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/73fe0057/lang/cs/build.props ---------------------------------------------------------------------- diff --git a/lang/cs/build.props b/lang/cs/build.props index c2fcc90..ae783c6 100644 --- a/lang/cs/build.props +++ b/lang/cs/build.props @@ -70,6 +70,12 @@ under the License. <WarningLevel>4</WarningLevel> </PropertyGroup> + <!-- REEF NuGet properties --> + <PropertyGroup> + <IsSnapshot>true</IsSnapshot> + <SnapshotNumber>0</SnapshotNumber> + </PropertyGroup> + <!-- Package versions --> <PropertyGroup> <AvroVersion>1.4.0.0</AvroVersion> @@ -77,5 +83,6 @@ under the License. <ProtobufVersion>2.0.0.668</ProtobufVersion> <RxVersion>2.2.5</RxVersion> </PropertyGroup> + </Project>
