diff options
author | Rob Mensching <rob@firegiant.com> | 2018-07-19 00:58:00 -0700 |
---|---|---|
committer | Rob Mensching <rob@firegiant.com> | 2018-07-21 07:36:59 -0700 |
commit | 2724cfee4c163f3297ee25edfd2372767cfd4945 (patch) | |
tree | 8cdda34c83bea014a586a491e3b4b187ad8f16da /src/WixToolset.BuildTasks/RefreshBundleGeneratedFile.cs | |
parent | 4d40bef9cf51b8cff7e1f6a73fdf68b9722eb8a0 (diff) | |
download | wix-2724cfee4c163f3297ee25edfd2372767cfd4945.tar.gz wix-2724cfee4c163f3297ee25edfd2372767cfd4945.tar.bz2 wix-2724cfee4c163f3297ee25edfd2372767cfd4945.zip |
Move tool projects to Tools repo
Diffstat (limited to 'src/WixToolset.BuildTasks/RefreshBundleGeneratedFile.cs')
-rw-r--r-- | src/WixToolset.BuildTasks/RefreshBundleGeneratedFile.cs | 132 |
1 files changed, 0 insertions, 132 deletions
diff --git a/src/WixToolset.BuildTasks/RefreshBundleGeneratedFile.cs b/src/WixToolset.BuildTasks/RefreshBundleGeneratedFile.cs deleted file mode 100644 index 5445e0cd..00000000 --- a/src/WixToolset.BuildTasks/RefreshBundleGeneratedFile.cs +++ /dev/null | |||
@@ -1,132 +0,0 @@ | |||
1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. | ||
2 | |||
3 | namespace WixToolset.BuildTasks | ||
4 | { | ||
5 | using System; | ||
6 | using System.Collections; | ||
7 | using System.Globalization; | ||
8 | using System.IO; | ||
9 | using System.Text.RegularExpressions; | ||
10 | using System.Xml; | ||
11 | using Microsoft.Build.Framework; | ||
12 | using Microsoft.Build.Utilities; | ||
13 | |||
14 | /// <summary> | ||
15 | /// This task refreshes the generated file for bundle projects. | ||
16 | /// </summary> | ||
17 | public class RefreshBundleGeneratedFile : Task | ||
18 | { | ||
19 | private static readonly Regex AddPrefix = new Regex(@"^[^a-zA-Z_]", RegexOptions.Compiled); | ||
20 | private static readonly Regex IllegalIdentifierCharacters = new Regex(@"[^A-Za-z0-9_\.]|\.{2,}", RegexOptions.Compiled); // non 'words' and assorted valid characters | ||
21 | |||
22 | private ITaskItem[] generatedFiles; | ||
23 | private ITaskItem[] projectReferencePaths; | ||
24 | |||
25 | /// <summary> | ||
26 | /// The list of files to generate. | ||
27 | /// </summary> | ||
28 | [Required] | ||
29 | public ITaskItem[] GeneratedFiles | ||
30 | { | ||
31 | get { return this.generatedFiles; } | ||
32 | set { this.generatedFiles = value; } | ||
33 | } | ||
34 | |||
35 | /// <summary> | ||
36 | /// All the project references in the project. | ||
37 | /// </summary> | ||
38 | [Required] | ||
39 | public ITaskItem[] ProjectReferencePaths | ||
40 | { | ||
41 | get { return this.projectReferencePaths; } | ||
42 | set { this.projectReferencePaths = value; } | ||
43 | } | ||
44 | |||
45 | /// <summary> | ||
46 | /// Gets a complete list of external cabs referenced by the given installer database file. | ||
47 | /// </summary> | ||
48 | /// <returns>True upon completion of the task execution.</returns> | ||
49 | public override bool Execute() | ||
50 | { | ||
51 | ArrayList payloadGroupRefs = new ArrayList(); | ||
52 | ArrayList packageGroupRefs = new ArrayList(); | ||
53 | for (int i = 0; i < this.ProjectReferencePaths.Length; i++) | ||
54 | { | ||
55 | ITaskItem item = this.ProjectReferencePaths[i]; | ||
56 | |||
57 | if (!String.IsNullOrEmpty(item.GetMetadata(Common.DoNotHarvest))) | ||
58 | { | ||
59 | continue; | ||
60 | } | ||
61 | |||
62 | string projectPath = CreateProjectReferenceDefineConstants.GetProjectPath(this.ProjectReferencePaths, i); | ||
63 | string projectName = Path.GetFileNameWithoutExtension(projectPath); | ||
64 | string referenceName = Common.GetIdentifierFromName(CreateProjectReferenceDefineConstants.GetReferenceName(item, projectName)); | ||
65 | |||
66 | string[] pogs = item.GetMetadata("RefProjectOutputGroups").Split(';'); | ||
67 | foreach (string pog in pogs) | ||
68 | { | ||
69 | if (!String.IsNullOrEmpty(pog)) | ||
70 | { | ||
71 | // TODO: Add payload group references and package group references once heat is generating them | ||
72 | ////payloadGroupRefs.Add(String.Format(CultureInfo.InvariantCulture, "{0}.{1}", referenceName, pog)); | ||
73 | packageGroupRefs.Add(String.Format(CultureInfo.InvariantCulture, "{0}.{1}", referenceName, pog)); | ||
74 | } | ||
75 | } | ||
76 | } | ||
77 | |||
78 | XmlDocument doc = new XmlDocument(); | ||
79 | |||
80 | XmlProcessingInstruction head = doc.CreateProcessingInstruction("xml", "version='1.0' encoding='UTF-8'"); | ||
81 | doc.AppendChild(head); | ||
82 | |||
83 | XmlElement rootElement = doc.CreateElement("Wix"); | ||
84 | rootElement.SetAttribute("xmlns", "http://wixtoolset.org/schemas/v4/wxs"); | ||
85 | doc.AppendChild(rootElement); | ||
86 | |||
87 | XmlElement fragment = doc.CreateElement("Fragment"); | ||
88 | rootElement.AppendChild(fragment); | ||
89 | |||
90 | XmlElement payloadGroup = doc.CreateElement("PayloadGroup"); | ||
91 | payloadGroup.SetAttribute("Id", "Bundle.Generated.Payloads"); | ||
92 | fragment.AppendChild(payloadGroup); | ||
93 | |||
94 | XmlElement packageGroup = doc.CreateElement("PackageGroup"); | ||
95 | packageGroup.SetAttribute("Id", "Bundle.Generated.Packages"); | ||
96 | fragment.AppendChild(packageGroup); | ||
97 | |||
98 | foreach (string payloadGroupRef in payloadGroupRefs) | ||
99 | { | ||
100 | XmlElement payloadGroupRefElement = doc.CreateElement("PayloadGroupRef"); | ||
101 | payloadGroupRefElement.SetAttribute("Id", payloadGroupRef); | ||
102 | payloadGroup.AppendChild(payloadGroupRefElement); | ||
103 | } | ||
104 | |||
105 | foreach (string packageGroupRef in packageGroupRefs) | ||
106 | { | ||
107 | XmlElement packageGroupRefElement = doc.CreateElement("PackageGroupRef"); | ||
108 | packageGroupRefElement.SetAttribute("Id", packageGroupRef); | ||
109 | packageGroup.AppendChild(packageGroupRefElement); | ||
110 | } | ||
111 | |||
112 | foreach (ITaskItem item in this.GeneratedFiles) | ||
113 | { | ||
114 | string fullPath = item.GetMetadata("FullPath"); | ||
115 | |||
116 | payloadGroup.SetAttribute("Id", Path.GetFileNameWithoutExtension(fullPath) + ".Payloads"); | ||
117 | packageGroup.SetAttribute("Id", Path.GetFileNameWithoutExtension(fullPath) + ".Packages"); | ||
118 | try | ||
119 | { | ||
120 | doc.Save(fullPath); | ||
121 | } | ||
122 | catch (Exception e) | ||
123 | { | ||
124 | // e.Message will be something like: "Access to the path 'fullPath' is denied." | ||
125 | this.Log.LogMessage(MessageImportance.High, "Unable to save generated file to '{0}'. {1}", fullPath, e.Message); | ||
126 | } | ||
127 | } | ||
128 | |||
129 | return true; | ||
130 | } | ||
131 | } | ||
132 | } | ||