diff options
Diffstat (limited to 'src/WixToolset.BuildTasks/RefreshGeneratedFile.cs')
-rw-r--r-- | src/WixToolset.BuildTasks/RefreshGeneratedFile.cs | 118 |
1 files changed, 0 insertions, 118 deletions
diff --git a/src/WixToolset.BuildTasks/RefreshGeneratedFile.cs b/src/WixToolset.BuildTasks/RefreshGeneratedFile.cs deleted file mode 100644 index fdfc4774..00000000 --- a/src/WixToolset.BuildTasks/RefreshGeneratedFile.cs +++ /dev/null | |||
@@ -1,118 +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 that contains ComponentGroupRefs | ||
16 | /// to harvested output. | ||
17 | /// </summary> | ||
18 | public class RefreshGeneratedFile : Task | ||
19 | { | ||
20 | private static readonly Regex AddPrefix = new Regex(@"^[^a-zA-Z_]", RegexOptions.Compiled); | ||
21 | private static readonly Regex IllegalIdentifierCharacters = new Regex(@"[^A-Za-z0-9_\.]|\.{2,}", RegexOptions.Compiled); // non 'words' and assorted valid characters | ||
22 | |||
23 | private ITaskItem[] generatedFiles; | ||
24 | private ITaskItem[] projectReferencePaths; | ||
25 | |||
26 | /// <summary> | ||
27 | /// The list of files to generate. | ||
28 | /// </summary> | ||
29 | [Required] | ||
30 | public ITaskItem[] GeneratedFiles | ||
31 | { | ||
32 | get { return this.generatedFiles; } | ||
33 | set { this.generatedFiles = value; } | ||
34 | } | ||
35 | |||
36 | /// <summary> | ||
37 | /// All the project references in the project. | ||
38 | /// </summary> | ||
39 | [Required] | ||
40 | public ITaskItem[] ProjectReferencePaths | ||
41 | { | ||
42 | get { return this.projectReferencePaths; } | ||
43 | set { this.projectReferencePaths = value; } | ||
44 | } | ||
45 | |||
46 | /// <summary> | ||
47 | /// Gets a complete list of external cabs referenced by the given installer database file. | ||
48 | /// </summary> | ||
49 | /// <returns>True upon completion of the task execution.</returns> | ||
50 | public override bool Execute() | ||
51 | { | ||
52 | ArrayList componentGroupRefs = 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 | componentGroupRefs.Add(String.Format(CultureInfo.InvariantCulture, "{0}.{1}", referenceName, pog)); | ||
72 | } | ||
73 | } | ||
74 | } | ||
75 | |||
76 | XmlDocument doc = new XmlDocument(); | ||
77 | |||
78 | XmlProcessingInstruction head = doc.CreateProcessingInstruction("xml", "version='1.0' encoding='UTF-8'"); | ||
79 | doc.AppendChild(head); | ||
80 | |||
81 | XmlElement rootElement = doc.CreateElement("Wix"); | ||
82 | rootElement.SetAttribute("xmlns", "http://wixtoolset.org/schemas/v4/wxs"); | ||
83 | doc.AppendChild(rootElement); | ||
84 | |||
85 | XmlElement fragment = doc.CreateElement("Fragment"); | ||
86 | rootElement.AppendChild(fragment); | ||
87 | |||
88 | XmlElement componentGroup = doc.CreateElement("ComponentGroup"); | ||
89 | componentGroup.SetAttribute("Id", "Product.Generated"); | ||
90 | fragment.AppendChild(componentGroup); | ||
91 | |||
92 | foreach (string componentGroupRef in componentGroupRefs) | ||
93 | { | ||
94 | XmlElement componentGroupRefElement = doc.CreateElement("ComponentGroupRef"); | ||
95 | componentGroupRefElement.SetAttribute("Id", componentGroupRef); | ||
96 | componentGroup.AppendChild(componentGroupRefElement); | ||
97 | } | ||
98 | |||
99 | foreach (ITaskItem item in this.GeneratedFiles) | ||
100 | { | ||
101 | string fullPath = item.GetMetadata("FullPath"); | ||
102 | |||
103 | componentGroup.SetAttribute("Id", Path.GetFileNameWithoutExtension(fullPath)); | ||
104 | try | ||
105 | { | ||
106 | doc.Save(fullPath); | ||
107 | } | ||
108 | catch (Exception e) | ||
109 | { | ||
110 | // e.Message will be something like: "Access to the path 'fullPath' is denied." | ||
111 | this.Log.LogMessage(MessageImportance.High, "Unable to save generated file to '{0}'. {1}", fullPath, e.Message); | ||
112 | } | ||
113 | } | ||
114 | |||
115 | return true; | ||
116 | } | ||
117 | } | ||
118 | } | ||