Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update build task #14

Merged
merged 1 commit into from
Feb 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.proj
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
</PropertyGroup>

<UsingTask AssemblyFile="tools\AutoRest.Build.Tasks.dll" TaskName="ValidateStrongNameSignatureTask" />
<UsingTask AssemblyFile="tools\AutoRest.Build.Tasks.dll" TaskName="RegexReplacementTask" />
<UsingTask AssemblyFile="tools\AutoRest.Build.Tasks.dll" TaskName="RegexReplaceTask" />

<!-- CI build related. -->
<PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion tools/AutoRest.Build.Tasks/AutoRest.Build.Tasks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RegexReplacementTask.cs" />
<Compile Include="RegexReplaceTask.cs" />
<Compile Include="StrongNameUtility.cs" />
<Compile Include="ValidateStrongNameSignatureTask.cs" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,43 @@

namespace Microsoft.Rest.Common.Build.Tasks
{
public class RegexReplacementTask : Task
/// <summary>
/// Build task to apply RegularExpression to file[s].
/// </summary>
public class RegexReplaceTask : Task
{
/// <summary>
/// The files to search for a match.
/// </summary>
[Required]
public ITaskItem[] Files { get; set; }

[Required]
public string Find { get; set; }
/// <summary>
/// True/False to log Replace actions.
/// </summary>
public bool LogTask { get; set; }

[Required]
public string Replace { get; set; }
/// <summary>
/// If provided, results of applying the Regex are written to the OutputDirectory.
/// </summary>
public string OutputDirectory { get; set; }

public bool LogReplacement { get; set; }
/// <summary>
/// The regular expression pattern to match.
/// </summary>
[Required]
public string Pattern { get; set; }

/// <summary>
/// Gets or sets the optional output directory. If a OutputDir value is
/// specified, the original file contents will not be overwritten.
/// The replacement string.
/// </summary>
public string OutputDir { get; set; }
[Required]
public string Replacement { get; set; }

/// <summary>
/// Executes the Regex.Replace task.
/// </summary>
/// <returns>True if the task succeeded; otherwise, false.</returns>
public override bool Execute()
{
try
Expand All @@ -41,22 +59,22 @@ public override bool Execute()

string content = Regex.Replace(
File.ReadAllText(fileName),
Find,
Replace);
Pattern,
Replacement);

string outputFileName = fileName;
string message = null;
if (!string.IsNullOrEmpty(OutputDir))
if (!string.IsNullOrEmpty(OutputDirectory))
{
string path = Path.GetFullPath(OutputDir);
string path = Path.GetFullPath(OutputDirectory);
outputFileName = Path.Combine(path, Path.GetFileName(fileName));
message = " saved as " + outputFileName;
}

File.WriteAllText(outputFileName, content, Encoding.UTF8);
File.SetAttributes(outputFileName, oldAttributes);

if (LogReplacement)
if (LogTask)
{
Log.LogMessage("Processed regular expression replacement in file {0}{1}", fileName, message);
}
Expand Down
24 changes: 10 additions & 14 deletions tools/NuGet.targets
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,29 @@
<PublishSymbolSourcePackages>true</PublishSymbolSourcePackages>
</PropertyGroup>

<UsingTask AssemblyFile="Microsoft.Rest.Common.Build.Tasks.dll" TaskName="RegexReplacementTask" />
<UsingTask AssemblyFile="Microsoft.Rest.Common.Build.Tasks.dll" TaskName="RegexReplaceTask" />
<Target Name="EnsureBinariesFolderExists">
<MakeDir Directories="binaries" Condition="!Exists('binaries')" />
<MakeDir Directories="binaries\packages" Condition="!Exists('binaries\packages')" />
<MakeDir Directories="binaries\packages\specs" Condition="!Exists('binaries\packages\specs')" />
</Target>

<!-- Replacing version token dependency. -->
<Target Name="BuildDynamicNuSpecs"
DependsOnTargets="EnsureBinariesFolderExists">
<!-- First we copy nuspec files to binaries folder -->
<Target Name="BuildDynamicNuSpecs" DependsOnTargets="EnsureBinariesFolderExists">
<!-- Copy nuspec files to binaries folder. -->
<ItemGroup>
<NuspecFilesToCopy Include="%(SdkNuGetPackage.Folder)%(SdkNuGetPackage.Identity).nuspec" />
</ItemGroup>
<Copy SourceFiles="@(NuspecFilesToCopy)"
DestinationFolder="binaries\packages\specs"/>

<!-- Then we update version string -->
<Copy SourceFiles="@(NuspecFilesToCopy)" DestinationFolder="binaries\packages\specs"/>
<!-- Update version string. -->
<ItemGroup>
<NuspecFilesToUpdate Include="binaries\packages\specs\*.nuspec" />
</ItemGroup>
<RegexReplacementTask Files="@(NuspecFilesToUpdate)"
OutputDir="binaries\packages\specs\"
Find="__VERSION_%(SdkNuGetPackage.Identity)__"
Replace="%(SdkNuGetPackage.PackageVersion)"
LogReplacement="false" />

<RegexReplaceTask Files="@(NuspecFilesToUpdate)"
OutputDirectory="binaries\packages\specs\"
Pattern="__VERSION_%(SdkNuGetPackage.Identity)__"
Replacement="%(SdkNuGetPackage.PackageVersion)"
LogTask="false" />
<Message Text="Created dynamic nuspec %(NuspecFilesToUpdate2.Identity)" />
</Target>

Expand Down