|
| 1 | +<?xml version="1.0" encoding="utf-8"?> |
| 2 | +<Project ToolsVersion="14.0" DefaultTargets="Build" InitialTargets="EnsurePreconditions" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" TreatAsLocalProperty="WhatIf"> |
| 3 | + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" /> |
| 4 | + <PropertyGroup> |
| 5 | + <WhatIf Condition="'$(WhatIf)' != 'true'">false</WhatIf> |
| 6 | + </PropertyGroup> |
| 7 | + <Import Project="$(MSBuildThisFileDirectory)repositories.props" /> |
| 8 | + |
| 9 | + <ItemDefinitionGroup> |
| 10 | + <Repository> |
| 11 | + <LocalPath>$(RepositoryPath)%(Identity)/</LocalPath> |
| 12 | + <ServerPath>%(Url)/tree/master/</ServerPath> |
| 13 | + </Repository> |
| 14 | + </ItemDefinitionGroup> |
| 15 | + |
| 16 | + <Target Name="EnsurePreconditions"> |
| 17 | + <Error Condition="'$(OS)' != 'Windows_NT'" Text="This tool can only be run on Windows_NT."/> |
| 18 | + </Target> |
| 19 | + |
| 20 | + <Target Name="Clean"> |
| 21 | + <RemoveDir Directories="$(OutDir)"/> |
| 22 | + </Target> |
| 23 | + |
| 24 | + <Target Name="PrepareOutput"> |
| 25 | + <MakeDir Condition="!Exists('$(OutDir)')" Directories="$(OutDir)"/> |
| 26 | + <MakeDir Condition="!Exists('$(RepositoryPath)')" Directories="$(RepositoryPath)"/> |
| 27 | + </Target> |
| 28 | + |
| 29 | + <Target Name="Clone" DependsOnTargets="PrepareOutput" Outputs="%(Repository.Identity)"> |
| 30 | + <PropertyGroup> |
| 31 | + <CloneCommand>git clone %(Repository.Url).git --depth 1 %(LocalPath)</CloneCommand> |
| 32 | + </PropertyGroup> |
| 33 | + <Exec Condition="!Exists('%(Repository.LocalPath)')" Command="$(CloneCommand)" /> |
| 34 | + <Exec Command="git rev-parse HEAD 2>&1" WorkingDirectory="%(Repository.LocalPath)" ConsoleToMSBuild="true"> |
| 35 | + <Output TaskParameter="ConsoleOutput" PropertyName="CommitHash"/> |
| 36 | + </Exec> |
| 37 | + <ItemGroup> |
| 38 | + <ClonedRepository Include="@(Repository)"> |
| 39 | + <ServerPath>%(Url)/tree/$(CommitHash)/</ServerPath> |
| 40 | + </ClonedRepository> |
| 41 | + </ItemGroup> |
| 42 | + </Target> |
| 43 | + |
| 44 | + <Target Name="SelectProjects" DependsOnTargets="Clone" Outputs="@(SourceProject)"> |
| 45 | + <SelectProjects Repositories="@(ClonedRepository)"> |
| 46 | + <Output TaskParameter="SelectedProjects" ItemName="SourceProject"/> |
| 47 | + </SelectProjects> |
| 48 | + </Target> |
| 49 | + <UsingTask TaskName="SelectProjects" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll"> |
| 50 | + <ParameterGroup> |
| 51 | + <Repositories ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true"/> |
| 52 | + <SelectedProjects ParameterType="Microsoft.Build.Framework.ITaskItem[]" Output="true"/> |
| 53 | + </ParameterGroup> |
| 54 | + <Task> |
| 55 | + <Using Namespace="System"/> |
| 56 | + <Using Namespace="System.Collections.Generic"/> |
| 57 | + <Using Namespace="System.IO"/> |
| 58 | + <Using Namespace="System.Linq"/> |
| 59 | + <Using Namespace="System.Reflection"/> |
| 60 | + <Using Namespace="Microsoft.Build.Framework"/> |
| 61 | + <Code> |
| 62 | + <![CDATA[ |
| 63 | + var matcherType = Type.GetType("Microsoft.Build.Shared.FileMatcher, Microsoft.Build.Tasks.Core, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"); |
| 64 | + var getFilesFunction = matcherType.GetMethod("GetFiles", BindingFlags.NonPublic | BindingFlags.Static, null, CallingConventions.Any, new Type[]{typeof(string), typeof(string)}, new ParameterModifier[0]); |
| 65 | + |
| 66 | + var selectedProjects = new List<ITaskItem>(); |
| 67 | + foreach (var repository in Repositories) |
| 68 | + { |
| 69 | + var projects = repository.GetMetadata("Projects"); |
| 70 | + var localPath = repository.GetMetadata("LocalPath"); |
| 71 | + foreach (var projectItemSpec in projects.Split(new char[]{';'}, StringSplitOptions.RemoveEmptyEntries)) |
| 72 | + { |
| 73 | + var trimmed = projectItemSpec.Trim(); |
| 74 | + if (!string.IsNullOrEmpty(trimmed)) |
| 75 | + { |
| 76 | + var itemSpec = trimmed; |
| 77 | + var files = (string[])getFilesFunction.Invoke(null, new object[] {localPath, itemSpec}); |
| 78 | + foreach (var file in files) |
| 79 | + { |
| 80 | + selectedProjects.Add(new TaskItem(localPath + file)); |
| 81 | + } |
| 82 | + } |
| 83 | + } |
| 84 | + } |
| 85 | + SelectedProjects = selectedProjects.OrderBy(i => i.GetMetadata("Identity")).ToArray(); |
| 86 | + Log.LogMessage("Selected Projects:"); |
| 87 | + foreach (var project in SelectedProjects) |
| 88 | + { |
| 89 | + Log.LogMessage(project.GetMetadata("FullPath")); |
| 90 | + } |
| 91 | + ]]> |
| 92 | + </Code> |
| 93 | + </Task> |
| 94 | + </UsingTask> |
| 95 | + |
| 96 | + <Target Name="Validate" DependsOnTargets="SelectProjects"> |
| 97 | + <Error Condition="!Exists('%(SourceProject.Identity)')" Text="Expected File '%(SourceProject.FullPath)' does not exist." Code="SB001"/> |
| 98 | + </Target> |
| 99 | + |
| 100 | + <Target Name="Prepare" DependsOnTargets="Validate" Outputs="%(ClonedRepository.Identity)"> |
| 101 | + <PropertyGroup> |
| 102 | + <PrepareCommand>$([System.String]::Copy('%(ClonedRepository.PrepareCommand)').Trim())</PrepareCommand> |
| 103 | + </PropertyGroup> |
| 104 | + <Exec Command="cmd /c "$(PrepareCommand)"" WorkingDirectory="%(ClonedRepository.LocalPath)" /> |
| 105 | + </Target> |
| 106 | + |
| 107 | + <Target Name="BuildGenerator"> |
| 108 | + <MSBuild Projects="$(SourcesDir)SourceBrowser/src/HtmlGenerator/HtmlGenerator.csproj" Targets="Build"> |
| 109 | + <Output TaskParameter="TargetOutputs" PropertyName="HtmlGeneratorExePath"/> |
| 110 | + </MSBuild> |
| 111 | + </Target> |
| 112 | + |
| 113 | + <Target Name="Build" DependsOnTargets="BuildGenerator;Prepare"> |
| 114 | + <Error Condition="!Exists('$(HtmlGeneratorExePath)')" Text="Html generator executable not found."/> |
| 115 | + <RemoveDuplicates Inputs="@(SourceProject)"> |
| 116 | + <Output TaskParameter="Filtered" ItemName="_FilteredProject"/> |
| 117 | + </RemoveDuplicates> |
| 118 | + <RemoveDir Directories="$(OutDir)index/"/> |
| 119 | + <WriteLinesToFile Lines="@(_FilteredProject -> '%(FullPath)')" File="$(OutDir)index.list" Overwrite="true"/> |
| 120 | + <PropertyGroup> |
| 121 | + <SourceIndexCmd>$(HtmlGeneratorExePath)</SourceIndexCmd> |
| 122 | + <SourceIndexCmd>$(SourceIndexCmd) /out:$(OutDir)index/</SourceIndexCmd> |
| 123 | + <SourceIndexCmd>$(SourceIndexCmd) /in:$(OutDir)index.list</SourceIndexCmd> |
| 124 | + <SourceIndexCmd>$(SourceIndexCmd) /p:SourceIndex=true</SourceIndexCmd> |
| 125 | + <SourceIndexCmd>$(SourceIndexCmd)@(ClonedRepository -> ' /serverPath:"%(LocalPath)=%(ServerPath)"', '')</SourceIndexCmd> |
| 126 | + </PropertyGroup> |
| 127 | + <Exec Command="$(SourceIndexCmd)"/> |
| 128 | + </Target> |
| 129 | + |
| 130 | + <Target Name="Rebuild" DependsOnTargets="Clean;Build"/> |
| 131 | +</Project> |
0 commit comments