From: Viktor Hofer Date: Tue, 8 Dec 2020 12:31:52 +0000 (+0100) Subject: Move msbuild tasks into src folder and delete dead code (#45722) X-Git-Tag: submit/tizen/20210909.063632~4267 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e35526f2e7e004681708849d1e35cff8f71c8a29;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Move msbuild tasks into src folder and delete dead code (#45722) * Move tools-local\tasks to src\tasks * Delete dead task code * nit installer.tasks.csproj changes * Remove mobile.tasks intermediate folder --- diff --git a/eng/Configurations.props b/eng/Configurations.props index 7034d1d..159efbf 100644 --- a/eng/Configurations.props +++ b/eng/Configurations.props @@ -15,7 +15,7 @@ $([MSBuild]::NormalizeDirectory('$(RepoRoot)', 'src', 'mono')) $([MSBuild]::NormalizeDirectory('$(RepoRoot)', 'src', 'installer')) $([MSBuild]::NormalizeDirectory('$(RepoRoot)', 'tools-local')) - $([MSBuild]::NormalizeDirectory('$(RepoToolsLocalDir)', 'tasks')) + $([MSBuild]::NormalizeDirectory('$(RepoRoot)', 'src', 'tasks')) $([MSBuild]::NormalizeDirectory('$(ArtifactsDir)', 'ibc')) $([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'docs')) diff --git a/src/mono/Directory.Build.props b/src/mono/Directory.Build.props index 20f40bc..9ec2eef 100644 --- a/src/mono/Directory.Build.props +++ b/src/mono/Directory.Build.props @@ -86,10 +86,10 @@ - $([MSBuild]::NormalizeDirectory('$(RepoTasksDir)', 'mobile.tasks', 'AppleAppBuilder')) + $([MSBuild]::NormalizeDirectory('$(RepoTasksDir)', 'AppleAppBuilder')) $([MSBuild]::NormalizeDirectory('$(LibrariesProjectRoot)', 'Common', tests, 'AppleTestRunner')) - $([MSBuild]::NormalizeDirectory('$(RepoTasksDir)', 'mobile.tasks', 'AndroidAppBuilder')) + $([MSBuild]::NormalizeDirectory('$(RepoTasksDir)', 'AndroidAppBuilder')) $([MSBuild]::NormalizeDirectory('$(LibrariesProjectRoot)', 'Common', tests, 'AndroidTestRunner')) - $([MSBuild]::NormalizeDirectory('$(RepoTasksDir)', 'mobile.tasks', 'AotCompilerTask')) + $([MSBuild]::NormalizeDirectory('$(RepoTasksDir)', 'AotCompilerTask')) diff --git a/src/mono/netcore/nuget/Microsoft.NET.Runtime.Android.Sample.Mono/Microsoft.NET.Runtime.Android.Sample.Mono.pkgproj b/src/mono/netcore/nuget/Microsoft.NET.Runtime.Android.Sample.Mono/Microsoft.NET.Runtime.Android.Sample.Mono.pkgproj index 8497332..86071c5 100644 --- a/src/mono/netcore/nuget/Microsoft.NET.Runtime.Android.Sample.Mono/Microsoft.NET.Runtime.Android.Sample.Mono.pkgproj +++ b/src/mono/netcore/nuget/Microsoft.NET.Runtime.Android.Sample.Mono/Microsoft.NET.Runtime.Android.Sample.Mono.pkgproj @@ -3,7 +3,7 @@ - + diff --git a/src/mono/netcore/nuget/Microsoft.NET.Runtime.iOS.Sample.Mono/Microsoft.NET.Runtime.iOS.Sample.Mono.pkgproj b/src/mono/netcore/nuget/Microsoft.NET.Runtime.iOS.Sample.Mono/Microsoft.NET.Runtime.iOS.Sample.Mono.pkgproj index ba5734a..8b7e035 100644 --- a/src/mono/netcore/nuget/Microsoft.NET.Runtime.iOS.Sample.Mono/Microsoft.NET.Runtime.iOS.Sample.Mono.pkgproj +++ b/src/mono/netcore/nuget/Microsoft.NET.Runtime.iOS.Sample.Mono/Microsoft.NET.Runtime.iOS.Sample.Mono.pkgproj @@ -3,13 +3,13 @@ - + <_iOSSampleFiles Include="$(ArtifactsDir)bin\AppleAppBuilder\$(Configuration)\$(NetCoreAppToolCurrent)\AppleAppBuilder.dll" /> - <_iOSSampleFiles Include="$(RepoToolsLocalDir)tasks\mobile.tasks\AppleAppBuilder\Templates\runtime.m" /> - <_iOSSampleFiles Include="$(RepoToolsLocalDir)tasks\mobile.tasks\AppleAppBuilder\Templates\runtime.h" /> + <_iOSSampleFiles Include="$(RepoTasksDir)AppleAppBuilder\Templates\runtime.m" /> + <_iOSSampleFiles Include="$(RepoTasksDir)AppleAppBuilder\Templates\runtime.h" /> diff --git a/src/mono/netcore/nuget/Microsoft.NET.Runtime.wasm.Sample.Mono/Microsoft.NET.Runtime.wasm.Sample.Mono.pkgproj b/src/mono/netcore/nuget/Microsoft.NET.Runtime.wasm.Sample.Mono/Microsoft.NET.Runtime.wasm.Sample.Mono.pkgproj index 7b7a58c..e3f3e5c3 100644 --- a/src/mono/netcore/nuget/Microsoft.NET.Runtime.wasm.Sample.Mono/Microsoft.NET.Runtime.wasm.Sample.Mono.pkgproj +++ b/src/mono/netcore/nuget/Microsoft.NET.Runtime.wasm.Sample.Mono/Microsoft.NET.Runtime.wasm.Sample.Mono.pkgproj @@ -3,7 +3,7 @@ - + diff --git a/src/mono/netcore/sample/iOS/Makefile b/src/mono/netcore/sample/iOS/Makefile index f9d7ec4..66fc336 100644 --- a/src/mono/netcore/sample/iOS/Makefile +++ b/src/mono/netcore/sample/iOS/Makefile @@ -5,7 +5,7 @@ USE_LLVM=True all: runtimepack run -TOOLS_DIR=../../../../../tools-local/tasks/mobile.tasks +TOOLS_DIR=../../../../tasks appbuilder: $(DOTNET) build -c Release $(TOOLS_DIR)/AotCompilerTask/MonoAOTCompiler.csproj $(DOTNET) build -c Release $(TOOLS_DIR)/AppleAppBuilder/AppleAppBuilder.csproj diff --git a/src/mono/netcore/sample/iOS/Program.csproj b/src/mono/netcore/sample/iOS/Program.csproj index d090c38..f44489c 100644 --- a/src/mono/netcore/sample/iOS/Program.csproj +++ b/src/mono/netcore/sample/iOS/Program.csproj @@ -22,7 +22,7 @@ - + diff --git a/src/mono/netcore/sample/wasm/browser/WasmSample.csproj b/src/mono/netcore/sample/wasm/browser/WasmSample.csproj index 18b86dc..6f036c28 100644 --- a/src/mono/netcore/sample/wasm/browser/WasmSample.csproj +++ b/src/mono/netcore/sample/wasm/browser/WasmSample.csproj @@ -13,7 +13,7 @@ - + - + - + diff --git a/src/mono/wasm/Makefile b/src/mono/wasm/Makefile index 4df7700..0b0ef13 100644 --- a/src/mono/wasm/Makefile +++ b/src/mono/wasm/Makefile @@ -158,10 +158,10 @@ test-runner: $(DOTNET) build $(TOP)/src/libraries/Common/tests/WasmTestRunner /p:Configuration=$(CONFIG) app-builder: - $(DOTNET) build $(TOP)/tools-local/tasks/mobile.tasks/WasmAppBuilder + $(DOTNET) build $(TOP)/src/tasks/WasmAppBuilder build-tasks: - $(DOTNET) build $(TOP)/tools-local/tasks/mobile.tasks/WasmBuildTasks + $(DOTNET) build $(TOP)/src/tasks/WasmBuildTasks run-tests-v8-%: PATH="$(JSVU):$(PATH)" $(DOTNET) build $(TOP)/src/libraries/$*/tests/ /t:Test /p:TargetOS=Browser /p:TargetArchitecture=wasm /p:Configuration=$(CONFIG) /p:JSEngine=V8 $(MSBUILD_ARGS) diff --git a/src/mono/wasm/debugger/tests/debugger-test/debugger-test.csproj b/src/mono/wasm/debugger/tests/debugger-test/debugger-test.csproj index 5baf3e8..f73b777 100644 --- a/src/mono/wasm/debugger/tests/debugger-test/debugger-test.csproj +++ b/src/mono/wasm/debugger/tests/debugger-test/debugger-test.csproj @@ -20,7 +20,7 @@ - + + + netstandard2.0;net461 + false + false + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tools-local/tasks/tasks.proj b/src/tasks/tasks.proj similarity index 80% rename from tools-local/tasks/tasks.proj rename to src/tasks/tasks.proj index a098f6b..cc8732b 100644 --- a/tools-local/tasks/tasks.proj +++ b/src/tasks/tasks.proj @@ -1,15 +1,15 @@ - - - - - diff --git a/tools-local/tasks/installer.tasks/BuildFPMToolPreReqs.cs b/tools-local/tasks/installer.tasks/BuildFPMToolPreReqs.cs deleted file mode 100644 index d88f1ef..0000000 --- a/tools-local/tasks/installer.tasks/BuildFPMToolPreReqs.cs +++ /dev/null @@ -1,351 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using Microsoft.Build.Framework; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; - -namespace Microsoft.DotNet.Build.Tasks -{ - /// - /// This task prepares the command line parameters for running a RPM build using FPM tool and also updates the copyright and changelog file tokens. - /// If parses various values from the config json by first reading it into a model and then builds the required string for parameters and passes it back. - /// - /// - public class BuildFPMToolPreReqs : BuildTask - { - [Required] - public string InputDir { get; set; } - [Required] - public string OutputDir { get; set; } - [Required] - public string PackageVersion { get; set; } - [Required] - public string ConfigJsonFile { get; set; } - [Output] - public string FPMParameters { get; set; } - - public override bool Execute() - { - try - { - if (!File.Exists(ConfigJsonFile)) - { - throw new FileNotFoundException($"Expected file {ConfigJsonFile} was not found."); - } - - // Open the Config Json and read the values into the model - TextReader projectFileReader = File.OpenText(ConfigJsonFile); - if (projectFileReader != null) - { - string jsonFileText = projectFileReader.ReadToEnd(); - ConfigJson configJson = JsonConvert.DeserializeObject(jsonFileText); - - // Update the Changelog and Copyright files by replacing tokens with values from config json - UpdateChangelog(configJson, PackageVersion); - UpdateCopyRight(configJson); - - // Build the full list of parameters - FPMParameters = BuildCmdParameters(configJson, PackageVersion); - Log.LogMessage(MessageImportance.Normal, "Generated RPM paramters: " + FPMParameters); - } - else - { - throw new IOException($"Could not open the file {ConfigJsonFile} for reading."); - } - } - catch (Exception e) - { - Log.LogErrorFromException(e, true); - } - - return !Log.HasLoggedErrors; - } - - // Update the tokens in the changelog file from the config Json - private void UpdateChangelog(ConfigJson configJson, string package_version) - { - try - { - string changelogFile = Path.Combine(InputDir, "templates", "changelog"); - if (!File.Exists(changelogFile)) - { - throw new FileNotFoundException($"Expected file {changelogFile} was not found."); - } - string str = File.ReadAllText(changelogFile); - str = str.Replace("{PACKAGE_NAME}", configJson.Package_Name); - str = str.Replace("{PACKAGE_VERSION}", package_version); - str = str.Replace("{PACKAGE_REVISION}", configJson.Release.Package_Revision); - str = str.Replace("{URGENCY}", configJson.Release.Urgency); - str = str.Replace("{CHANGELOG_MESSAGE}", configJson.Release.Changelog_Message); - str = str.Replace("{MAINTAINER_NAME}", configJson.Maintainer_Name); - str = str.Replace("{MAINTAINER_EMAIL}", configJson.Maintainer_Email); - // The date format needs to be like Wed May 17 2017 - str = str.Replace("{DATE}", DateTime.UtcNow.ToString("ddd MMM dd yyyy")); - File.WriteAllText(changelogFile, str); - } - catch (Exception e) - { - Log.LogError("Exception while updating the changelog file: " + e.Message); - } - } - - private void UpdateCopyRight(ConfigJson configJson) - { - try - { - // Update the tokens in the copyright file from the config Json - string copyrightFile = Path.Combine(InputDir, "templates", "copyright"); - if (!File.Exists(copyrightFile)) - { - throw new FileNotFoundException($"Expected file {copyrightFile} was not found."); - } - string str = File.ReadAllText(copyrightFile); - str = str.Replace("{COPYRIGHT_TEXT}", configJson.CopyRight); - str = str.Replace("{LICENSE_NAME}", configJson.License.Type); - str = str.Replace("{LICENSE_NAME}", configJson.License.Type); - str = str.Replace("{LICENSE_TEXT}", configJson.License.Full_Text); - File.WriteAllText(copyrightFile, str); - } - catch (Exception e) - { - Log.LogError("Exception while updating the copyright file: " + e.Message); - } - } - - private string BuildCmdParameters(ConfigJson configJson, string package_version) - { - // Parameter list that needs to be passed to FPM tool: - // -s : is the input source type(dir) --Static - // -t : is the type of package(rpm) --Static - // -n : is for the name of the package --JSON - // -v : is the version to give to the package --ARG - // -a : architecture --JSON - // -d : is for all dependent packages. This can be used multiple times to specify the dependencies of the package. --JSON - // --rpm-os : the operating system to target this rpm --Static - // --rpm-changelog : the changelog from FILEPATH contents --ARG - // --rpm-summary : it is the RPM summary that shows in the Title --JSON - // --description : it is the description for the package --JSON - // -p : The actual package name (with path) for your package. --ARG+JSON - // --conflicts : Other packages/versions this package conflicts with provided as CSV --JSON - // --directories : Recursively add directories as being owned by the package. --JSON - // --after-install : FILEPATH to the script to be run after install of the package --JSON - // --after-remove : FILEPATH to the script to be run after package removal --JSON - // --license : the licensing name for the package. This will include the license type in the meta-data for the package, but will not include the associated license file within the package itself. --JSON - // --iteration : the iteration to give to the package. This comes from the package_revision --JSON - // --url : url for this package. --JSON - // --verbose : Set verbose output for FPM tool --Static - // : Add all the folder mappings for packge_root, docs, man pages --Static - - var parameters = new List(); - parameters.Add("-s dir"); - parameters.Add("-t rpm"); - parameters.Add(string.Concat("-n ", configJson.Package_Name)); - parameters.Add(string.Concat("-v ", package_version)); - parameters.Add(string.Concat("-a ", configJson.Control.Architecture)); - - // Build the list of dependencies as -d -d - if (configJson.Rpm_Dependencies != null) - { - IEnumerable dependencies; - - switch (configJson.Rpm_Dependencies) - { - case JArray dependencyArray: - dependencies = dependencyArray.ToObject(); - break; - - case JObject dependencyDictionary: - dependencies = dependencyDictionary - .ToObject>() - .Select(pair => new RpmDependency - { - Package_Name = pair.Key, - Package_Version = pair.Value - }); - break; - - default: - throw new ArgumentException( - "Expected 'rpm_dependencies' to be JArray or JObject, but found " + - configJson.Rpm_Dependencies.Type); - } - - foreach (RpmDependency rpmdep in dependencies) - { - string dependency = ""; - if (rpmdep.Package_Name != "") - { - // If no version is specified then the dependency is just the package without >= check - if (rpmdep.Package_Version == "") - { - dependency = rpmdep.Package_Name; - } - else - { - dependency = string.Concat(rpmdep.Package_Name, " >= ", rpmdep.Package_Version); - } - } - if (dependency != "") - { - parameters.Add(string.Concat("-d ", EscapeArg(dependency))); - } - } - } - - // Build the list of owned directories - if (configJson.Directories != null) - { - foreach (string dir in configJson.Directories) - { - if (dir != "") - { - parameters.Add(string.Concat("--directories ", EscapeArg(dir))); - } - } - } - - parameters.Add("--rpm-os linux"); - parameters.Add(string.Concat("--rpm-changelog ", EscapeArg(Path.Combine(InputDir, "templates", "changelog")))); // Changelog File - parameters.Add(string.Concat("--rpm-summary ", EscapeArg(configJson.Short_Description))); - parameters.Add(string.Concat("--description ", EscapeArg(configJson.Long_Description))); - parameters.Add(string.Concat("--maintainer ", EscapeArg(configJson.Maintainer_Name + " <" + configJson.Maintainer_Email + ">"))); - parameters.Add(string.Concat("--vendor ", EscapeArg(configJson.Vendor))); - parameters.Add(string.Concat("-p ", Path.Combine(OutputDir, configJson.Package_Name + ".rpm"))); - if (configJson.Package_Conflicts != null) parameters.Add(string.Concat("--conflicts ", EscapeArg(string.Join(",", configJson.Package_Conflicts)))); - if (configJson.After_Install_Source != null) parameters.Add(string.Concat("--after-install ", Path.Combine(InputDir, EscapeArg(configJson.After_Install_Source)))); - if (configJson.After_Remove_Source != null) parameters.Add(string.Concat("--after-remove ", Path.Combine(InputDir, EscapeArg(configJson.After_Remove_Source)))); - parameters.Add(string.Concat("--license ", EscapeArg(configJson.License.Type))); - parameters.Add(string.Concat("--iteration ", configJson.Release.Package_Revision)); - parameters.Add(string.Concat("--url ", "\"", EscapeArg(configJson.Homepage), "\"")); - parameters.Add("--verbose"); - - // Map all the payload directories as they need to install on the system - if (configJson.Install_Root != null) parameters.Add(string.Concat(Path.Combine(InputDir, "package_root/="), configJson.Install_Root)); // Package Files - if (configJson.Install_Man != null) parameters.Add(string.Concat(Path.Combine(InputDir, "docs", "host/="), configJson.Install_Man)); // Man Pages - if (configJson.Install_Doc != null) parameters.Add(string.Concat(Path.Combine(InputDir, "templates", "copyright="), configJson.Install_Doc)); // CopyRight File - - return string.Join(" ", parameters); - } - - private string EscapeArg(string arg) - { - var sb = new StringBuilder(); - - bool quoted = ShouldSurroundWithQuotes(arg); - if (quoted) sb.Append("\""); - - for (int i = 0; i < arg.Length; ++i) - { - var backslashCount = 0; - - // Consume All Backslashes - while (i < arg.Length && arg[i] == '\\') - { - backslashCount++; - i++; - } - - // Escape any backslashes at the end of the arg - // This ensures the outside quote is interpreted as - // an argument delimiter - if (i == arg.Length) - { - sb.Append('\\', 2 * backslashCount); - } - - // Escape any preceding backslashes and the quote - else if (arg[i] == '"') - { - sb.Append('\\', (2 * backslashCount) + 1); - sb.Append('"'); - } - - // Output any consumed backslashes and the character - else - { - sb.Append('\\', backslashCount); - sb.Append(arg[i]); - } - } - - if (quoted) sb.Append("\""); - - return sb.ToString(); - } - private bool ShouldSurroundWithQuotes(string argument) - { - // Don't quote already quoted strings - if (argument.StartsWith("\"", StringComparison.Ordinal) && - argument.EndsWith("\"", StringComparison.Ordinal)) - { - return false; - } - - // Only quote if whitespace exists in the string - if (argument.Contains(" ") || argument.Contains("\t") || argument.Contains("\n")) - { - return true; - } - return false; - } - - /// - /// Model classes for reading and storing the JSON. - /// - private class ConfigJson - { - public string Maintainer_Name { get; set; } - public string Maintainer_Email { get; set; } - public string Vendor { get; set; } - public string Package_Name { get; set; } - public string Install_Root { get; set; } - public string Install_Doc { get; set; } - public string Install_Man { get; set; } - public string Short_Description { get; set; } - public string Long_Description { get; set; } - public string Homepage { get; set; } - public string CopyRight { get; set; } - public Release Release { get; set; } - public Control Control { get; set; } - public License License { get; set; } - public JContainer Rpm_Dependencies { get; set; } - public List Package_Conflicts { get; set; } - public List Directories { get; set; } - public string After_Install_Source { get; set; } - public string After_Remove_Source { get; set; } - } - - private class Release - { - public string Package_Version { get; set; } - public string Package_Revision { get; set; } - public string Urgency { get; set; } - public string Changelog_Message { get; set; } - } - - private class Control - { - public string Priority { get; set; } - public string Section { get; set; } - public string Architecture { get; set; } - } - - private class License - { - public string Type { get; set; } - public string Full_Text { get; set; } - } - - private class RpmDependency - { - public string Package_Name { get; set; } - public string Package_Version { get; set; } - } - } -} diff --git a/tools-local/tasks/installer.tasks/ChangeEntryPointLibraryName.cs b/tools-local/tasks/installer.tasks/ChangeEntryPointLibraryName.cs deleted file mode 100644 index 490b0e9..0000000 --- a/tools-local/tasks/installer.tasks/ChangeEntryPointLibraryName.cs +++ /dev/null @@ -1,69 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using Microsoft.Build.Framework; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using System.IO; -using System.Linq; - -namespace Microsoft.DotNet.Build.Tasks -{ - public class ChangeEntryPointLibraryName : BuildTask - { - [Required] - public string DepsFile { get; set; } - - public string NewName { get; set; } - - public override bool Execute() - { - JToken deps; - using (var file = File.OpenText(DepsFile)) - using (JsonTextReader reader = new JsonTextReader(file)) - { - deps = JObject.ReadFrom(reader); - } - - if (deps == null) return false; - - string version = string.Empty; - foreach (JProperty target in deps["targets"]) - { - var targetLibrary = target.Value.Children().FirstOrDefault(); - if (targetLibrary == null) - { - continue; - } - version = targetLibrary.Name.Substring(targetLibrary.Name.IndexOf('/') + 1); - if (string.IsNullOrEmpty(NewName)) - { - targetLibrary.Remove(); - } - else - { - targetLibrary.Replace(new JProperty(NewName + '/' + version, targetLibrary.Value)); - } - } - if (!string.IsNullOrEmpty(version)) - { - var library = deps["libraries"].Children().First(); - if (string.IsNullOrEmpty(NewName)) - { - library.Remove(); - } - else - { - library.Replace(new JProperty(NewName + '/' + version, library.Value)); - } - using (var file = File.CreateText(DepsFile)) - using (var writer = new JsonTextWriter(file) { Formatting = Formatting.Indented }) - { - deps.WriteTo(writer); - } - } - - return true; - } - } -} diff --git a/tools-local/tasks/installer.tasks/ReplaceFileContents.cs b/tools-local/tasks/installer.tasks/ReplaceFileContents.cs deleted file mode 100644 index 8c30c6a..0000000 --- a/tools-local/tasks/installer.tasks/ReplaceFileContents.cs +++ /dev/null @@ -1,106 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using Microsoft.Build.Framework; -using Microsoft.Build.Utilities; -using System; -using System.IO; - -namespace Microsoft.DotNet.Build.Tasks -{ - /// - /// Reads contents of an input file, and searches for each replacement passed in. - /// - /// When ReplacementItems is matched, it will replace the Include/ItemSpec with the corresponding - /// ReplacementString metadata value. This can be useful if the ReplacementString is a value that - /// cannot be represented by ITaskItem.ItemSpec (like string.Empty). - /// - /// When a ReplacementPattern is matched it will replace it with the string of the corresponding (by index) - /// item in ReplacementStrings. - /// - /// For example, if 2 ReplacementPatterns are passed in, 2 ReplacementStrings must also passed in and the first - /// pattern will be replaced with the first string, and the second pattern replaced with the second string. - /// - /// ReplacementPattern could easily be a regex, but it isn't needed for current use cases, so leaving this - /// as just a string that will be replaced. - /// - public class ReplaceFileContents : Task - { - [Required] - public string InputFile { get; set; } - - [Required] - public string DestinationFile { get; set; } - - public ITaskItem[] ReplacementItems { get; set; } - - public ITaskItem[] ReplacementPatterns { get; set; } - - public ITaskItem[] ReplacementStrings { get; set; } - - private ITaskItem[] Empty = new ITaskItem[0]; - - public override bool Execute() - { - if (ReplacementItems == null && ReplacementPatterns == null && ReplacementStrings == null) - { - throw new Exception($"ReplaceFileContents was called with no replacement values. Either pass ReplacementItems or ReplacementPatterns/ReplacementStrings properties."); - } - - ReplacementItems = ReplacementItems ?? Empty; - ReplacementPatterns = ReplacementPatterns ?? Empty; - ReplacementStrings = ReplacementStrings ?? Empty; - - if (ReplacementPatterns.Length != ReplacementStrings.Length) - { - throw new Exception($"Expected {nameof(ReplacementPatterns)} (length {ReplacementPatterns.Length}) and {nameof(ReplacementStrings)} (length {ReplacementStrings.Length}) to have the same length."); - } - - if (!File.Exists(InputFile)) - { - throw new FileNotFoundException($"Expected file {InputFile} was not found."); - } - - string inputFileText = File.ReadAllText(InputFile); - string outputFileText = ReplacePatterns(inputFileText); - - WriteOutputFile(outputFileText); - - return true; - } - - public string ReplacePatterns(string inputFileText) - { - var outText = inputFileText; - - foreach (var replacementItem in ReplacementItems) - { - var replacementPattern = replacementItem.ItemSpec; - var replacementString = replacementItem.GetMetadata("ReplacementString"); - - outText = outText.Replace(replacementPattern, replacementString); - } - - for (int i=0; i reportedFailures = new List(); - - // Gather all of the rows with error results - IEnumerable errorRows = from descendant in rows - where descendant.Descendants().FirstOrDefault(f => f.Name == s_ResultElement).Value == "False" - select descendant; - - // Filter out baselined files which are stored as regex patterns - HashSet baselineExcludeElements = new HashSet(); - if(BaselineFiles != null) - { - foreach(var baselineFile in BaselineFiles) - { - IEnumerable baselineExcluded = errorRows.Where(f => Regex.IsMatch(f.Descendants(s_NameElement).First().Value, baselineFile.ItemSpec, RegexOptions.IgnoreCase)); - foreach(var baselineExclude in baselineExcluded) - { - baselineExcludeElements.Add(baselineExclude); - } - } - } - // Gather the results with baselined files filtered out - IEnumerable baselinedRows = errorRows.Except(baselineExcludeElements); - - foreach (var filteredRow in baselinedRows) - { - ITaskItem item = new TaskItem(filteredRow.Descendants(s_NameElement).First().Value); - item.SetMetadata("Error", filteredRow.Descendants(s_ErrorElement).First().Value); - reportedFailures.Add(item); - } - - ErrorResults = reportedFailures.ToArray(); - foreach(var result in ErrorResults) - { - Log.LogError($"{result.ItemSpec} failed with error {result.GetMetadata("Error")}"); - } - return !Log.HasLoggedErrors; - } - } -} diff --git a/tools-local/tasks/installer.tasks/ZipFileCreateFromDirectory.cs b/tools-local/tasks/installer.tasks/ZipFileCreateFromDirectory.cs deleted file mode 100644 index e187008..0000000 --- a/tools-local/tasks/installer.tasks/ZipFileCreateFromDirectory.cs +++ /dev/null @@ -1,133 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using Microsoft.Build.Framework; -using Microsoft.Build.Utilities; -using System; -using System.IO; -using System.IO.Compression; -using System.Text.RegularExpressions; - -namespace Microsoft.DotNet.Build.Tasks -{ - public sealed class ZipFileCreateFromDirectory : Task - { - /// - /// The path to the directory to be archived. - /// - [Required] - public string SourceDirectory { get; set; } - - /// - /// The path of the archive to be created. - /// - [Required] - public string DestinationArchive { get; set; } - - /// - /// Indicates if the destination archive should be overwritten if it already exists. - /// - public bool OverwriteDestination { get; set; } - - /// - /// If zipping an entire folder without exclusion patterns, whether to include the folder in the archive. - /// - public bool IncludeBaseDirectory { get; set; } - - /// - /// An item group of regular expressions for content to exclude from the archive. - /// - public ITaskItem[] ExcludePatterns { get; set; } - - public override bool Execute() - { - try - { - if (File.Exists(DestinationArchive)) - { - if (OverwriteDestination == true) - { - Log.LogMessage(MessageImportance.Low, "{0} already existed, deleting before zipping...", DestinationArchive); - File.Delete(DestinationArchive); - } - else - { - Log.LogWarning("'{0}' already exists. Did you forget to set '{1}' to true?", DestinationArchive, nameof(OverwriteDestination)); - } - } - - Log.LogMessage(MessageImportance.High, "Compressing {0} into {1}...", SourceDirectory, DestinationArchive); - string destinationDirectory = Path.GetDirectoryName(DestinationArchive); - if (!Directory.Exists(destinationDirectory) && !string.IsNullOrEmpty(destinationDirectory)) - { - Directory.CreateDirectory(destinationDirectory); - } - - if (ExcludePatterns == null) - { - ZipFile.CreateFromDirectory(SourceDirectory, DestinationArchive, CompressionLevel.Optimal, IncludeBaseDirectory); - } - else - { - // convert to regular expressions - Regex[] regexes = new Regex[ExcludePatterns.Length]; - for (int i = 0; i < ExcludePatterns.Length; ++i) - regexes[i] = new Regex(ExcludePatterns[i].ItemSpec, RegexOptions.IgnoreCase); - - using (FileStream writer = new FileStream(DestinationArchive, FileMode.CreateNew)) - { - using (ZipArchive zipFile = new ZipArchive(writer, ZipArchiveMode.Create)) - { - var files = Directory.GetFiles(SourceDirectory, "*", SearchOption.AllDirectories); - - foreach (var file in files) - { - // look for a match - bool foundMatch = false; - foreach (var regex in regexes) - { - if (regex.IsMatch(file)) - { - foundMatch = true; - break; - } - } - - if (foundMatch) - { - Log.LogMessage(MessageImportance.Low, "Excluding {0} from archive.", file); - continue; - } - - var relativePath = MakeRelativePath(SourceDirectory, file); - zipFile.CreateEntryFromFile(file, relativePath, CompressionLevel.Optimal); - } - } - } - } - } - catch (Exception e) - { - // We have 2 log calls because we want a nice error message but we also want to capture the callstack in the log. - Log.LogError("An exception has occurred while trying to compress '{0}' into '{1}'.", SourceDirectory, DestinationArchive); - Log.LogErrorFromException(e, /*show stack=*/ true, /*show detail=*/ true, DestinationArchive); - return false; - } - - return true; - } - - private string MakeRelativePath(string root, string subdirectory) - { - if (!subdirectory.StartsWith(root)) - throw new Exception(string.Format("'{0}' is not a subdirectory of '{1}'.", subdirectory, root)); - - // returned string should not start with a directory separator - int chop = root.Length; - if (subdirectory[chop] == Path.DirectorySeparatorChar) - ++chop; - - return subdirectory.Substring(chop); - } - } -} diff --git a/tools-local/tasks/installer.tasks/installer.tasks.csproj b/tools-local/tasks/installer.tasks/installer.tasks.csproj deleted file mode 100644 index fc7b567..0000000 --- a/tools-local/tasks/installer.tasks/installer.tasks.csproj +++ /dev/null @@ -1,46 +0,0 @@ - - - netstandard2.0 - $(TargetFrameworks);net461 - false - false - false - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/tools-local/tasks/installer.tasks/net46/ProcessSharedFrameworkDeps.net46.cs b/tools-local/tasks/installer.tasks/net46/ProcessSharedFrameworkDeps.net46.cs deleted file mode 100644 index d514bd1..0000000 --- a/tools-local/tasks/installer.tasks/net46/ProcessSharedFrameworkDeps.net46.cs +++ /dev/null @@ -1,20 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using System.Reflection; - -namespace Microsoft.DotNet.Build.Tasks -{ - public partial class ProcessSharedFrameworkDeps - { - partial void EnsureInitialized(string buildTasksAssemblyPath) - { - // Ensure the Arcade AssemblyResolver is enabled, so we get the correct assembly - // unification even if an Arcade assembly hasn't been loaded yet. - Assembly buildTasksAssembly = Assembly.Load(AssemblyName.GetAssemblyName(buildTasksAssemblyPath)); - Type assemblyResolver = buildTasksAssembly.GetType("Microsoft.DotNet.Build.Common.Desktop.AssemblyResolver"); - assemblyResolver.GetMethod("Enable").Invoke(null, new object[] { }); - } - } -}