aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2018-07-27 00:35:52 -0700
committerRob Mensching <rob@firegiant.com>2018-07-27 11:31:18 -0700
commitc8c73ccddedcb64f9989e3d5a9f15240b476b551 (patch)
tree099f35daf71912b211223abcefafc97068971217 /src/WixToolset.Core
parent854e616eb3516c7405691b679617aa08c1dd1cdd (diff)
downloadwix-c8c73ccddedcb64f9989e3d5a9f15240b476b551.tar.gz
wix-c8c73ccddedcb64f9989e3d5a9f15240b476b551.tar.bz2
wix-c8c73ccddedcb64f9989e3d5a9f15240b476b551.zip
Remove WixFileNotFoundException, report checked paths and improve bind path command-line parsing
Diffstat (limited to 'src/WixToolset.Core')
-rw-r--r--src/WixToolset.Core/Bind/FileResolver.cs36
-rw-r--r--src/WixToolset.Core/Bind/ResolveFieldsCommand.cs5
-rw-r--r--src/WixToolset.Core/Bind/TransferFilesCommand.cs2
-rw-r--r--src/WixToolset.Core/CommandLine/CommandLineParser.cs18
-rw-r--r--src/WixToolset.Core/Preprocessor.cs2
5 files changed, 43 insertions, 20 deletions
diff --git a/src/WixToolset.Core/Bind/FileResolver.cs b/src/WixToolset.Core/Bind/FileResolver.cs
index 86075e46..01dfe36c 100644
--- a/src/WixToolset.Core/Bind/FileResolver.cs
+++ b/src/WixToolset.Core/Bind/FileResolver.cs
@@ -43,17 +43,24 @@ namespace WixToolset.Core.Bind
43 43
44 public string Resolve(SourceLineNumber sourceLineNumbers, IntermediateTupleDefinition tupleDefinition, string source) 44 public string Resolve(SourceLineNumber sourceLineNumbers, IntermediateTupleDefinition tupleDefinition, string source)
45 { 45 {
46 var checkedPaths = new List<string>();
47
46 foreach (var extension in this.LibrarianExtensions) 48 foreach (var extension in this.LibrarianExtensions)
47 { 49 {
48 var resolved = extension.Resolve(sourceLineNumbers, tupleDefinition, source); 50 var resolved = extension.ResolveFile(sourceLineNumbers, tupleDefinition, source);
51
52 if (resolved?.CheckedPaths != null)
53 {
54 checkedPaths.AddRange(resolved.CheckedPaths);
55 }
49 56
50 if (null != resolved) 57 if (!String.IsNullOrEmpty(resolved?.Path))
51 { 58 {
52 return resolved; 59 return resolved?.Path;
53 } 60 }
54 } 61 }
55 62
56 return this.ResolveUsingBindPaths(source, tupleDefinition, sourceLineNumbers, BindStage.Normal); 63 return this.MustResolveUsingBindPaths(source, tupleDefinition, sourceLineNumbers, BindStage.Normal, checkedPaths);
57 } 64 }
58 65
59 /// <summary> 66 /// <summary>
@@ -66,24 +73,32 @@ namespace WixToolset.Core.Bind
66 /// <returns>Should return a valid path for the stream to be imported.</returns> 73 /// <returns>Should return a valid path for the stream to be imported.</returns>
67 public string ResolveFile(string source, IntermediateTupleDefinition tupleDefinition, SourceLineNumber sourceLineNumbers, BindStage bindStage) 74 public string ResolveFile(string source, IntermediateTupleDefinition tupleDefinition, SourceLineNumber sourceLineNumbers, BindStage bindStage)
68 { 75 {
76 var checkedPaths = new List<string>();
77
69 foreach (var extension in this.ResolverExtensions) 78 foreach (var extension in this.ResolverExtensions)
70 { 79 {
71 var resolved = extension.ResolveFile(source, tupleDefinition, sourceLineNumbers, bindStage); 80 var resolved = extension.ResolveFile(source, tupleDefinition, sourceLineNumbers, bindStage);
72 81
73 if (null != resolved) 82 if (resolved?.CheckedPaths != null)
83 {
84 checkedPaths.AddRange(resolved.CheckedPaths);
85 }
86
87 if (!String.IsNullOrEmpty(resolved?.Path))
74 { 88 {
75 return resolved; 89 return resolved?.Path;
76 } 90 }
77 } 91 }
78 92
79 return this.ResolveUsingBindPaths(source, tupleDefinition, sourceLineNumbers, bindStage); 93 return this.MustResolveUsingBindPaths(source, tupleDefinition, sourceLineNumbers, bindStage, checkedPaths);
80 } 94 }
81 95
82 private string ResolveUsingBindPaths(string source, IntermediateTupleDefinition tupleDefinition, SourceLineNumber sourceLineNumbers, BindStage bindStage) 96 private string MustResolveUsingBindPaths(string source, IntermediateTupleDefinition tupleDefinition, SourceLineNumber sourceLineNumbers, BindStage bindStage, List<string> checkedPaths)
83 { 97 {
84 string resolved = null; 98 string resolved = null;
85 99
86 // If the file exists, we're good to go. 100 // If the file exists, we're good to go.
101 checkedPaths.Add(source);
87 if (CheckFileExists(source)) 102 if (CheckFileExists(source))
88 { 103 {
89 resolved = source; 104 resolved = source;
@@ -121,6 +136,7 @@ namespace WixToolset.Core.Bind
121 { 136 {
122 var filePath = Path.Combine(bindPath.Path, pathWithoutSourceDir); 137 var filePath = Path.Combine(bindPath.Path, pathWithoutSourceDir);
123 138
139 checkedPaths.Add(filePath);
124 if (CheckFileExists(filePath)) 140 if (CheckFileExists(filePath))
125 { 141 {
126 resolved = filePath; 142 resolved = filePath;
@@ -131,6 +147,7 @@ namespace WixToolset.Core.Bind
131 { 147 {
132 var filePath = Path.Combine(bindPath.Path, path); 148 var filePath = Path.Combine(bindPath.Path, path);
133 149
150 checkedPaths.Add(filePath);
134 if (CheckFileExists(filePath)) 151 if (CheckFileExists(filePath))
135 { 152 {
136 resolved = filePath; 153 resolved = filePath;
@@ -141,10 +158,9 @@ namespace WixToolset.Core.Bind
141 158
142 if (null == resolved) 159 if (null == resolved)
143 { 160 {
144 throw new WixFileNotFoundException(sourceLineNumbers, source, tupleDefinition.Name); 161 throw new WixException(ErrorMessages.FileNotFound(sourceLineNumbers, source, tupleDefinition.Name, checkedPaths));
145 } 162 }
146 163
147 // Didn't find the file.
148 return resolved; 164 return resolved;
149 } 165 }
150 166
diff --git a/src/WixToolset.Core/Bind/ResolveFieldsCommand.cs b/src/WixToolset.Core/Bind/ResolveFieldsCommand.cs
index 0d5c3142..b7ed8a18 100644
--- a/src/WixToolset.Core/Bind/ResolveFieldsCommand.cs
+++ b/src/WixToolset.Core/Bind/ResolveFieldsCommand.cs
@@ -152,10 +152,9 @@ namespace WixToolset.Core.Bind
152 } 152 }
153#endif 153#endif
154 } 154 }
155 catch (WixFileNotFoundException) 155 catch (WixException e)
156 { 156 {
157 // display the error with source line information 157 this.Messaging.Write(e.Error);
158 this.Messaging.Write(ErrorMessages.FileNotFound(row.SourceLineNumbers, objectField.Path));
159 } 158 }
160 } 159 }
161 160
diff --git a/src/WixToolset.Core/Bind/TransferFilesCommand.cs b/src/WixToolset.Core/Bind/TransferFilesCommand.cs
index b89d3d03..b9c54a14 100644
--- a/src/WixToolset.Core/Bind/TransferFilesCommand.cs
+++ b/src/WixToolset.Core/Bind/TransferFilesCommand.cs
@@ -63,7 +63,7 @@ namespace WixToolset.Core.Bind
63 } 63 }
64 catch (FileNotFoundException e) 64 catch (FileNotFoundException e)
65 { 65 {
66 throw new WixFileNotFoundException(fileTransfer.SourceLineNumbers, e.FileName); 66 throw new WixException(ErrorMessages.FileNotFound(fileTransfer.SourceLineNumbers, e.FileName));
67 } 67 }
68 catch (DirectoryNotFoundException) 68 catch (DirectoryNotFoundException)
69 { 69 {
diff --git a/src/WixToolset.Core/CommandLine/CommandLineParser.cs b/src/WixToolset.Core/CommandLine/CommandLineParser.cs
index 92944ab2..d518931a 100644
--- a/src/WixToolset.Core/CommandLine/CommandLineParser.cs
+++ b/src/WixToolset.Core/CommandLine/CommandLineParser.cs
@@ -22,6 +22,8 @@ namespace WixToolset.Core.CommandLine
22 22
23 internal class CommandLineParser : ICommandLineParser 23 internal class CommandLineParser : ICommandLineParser
24 { 24 {
25 private static readonly char[] BindPathSplit = { '=' };
26
25 public CommandLineParser(IServiceProvider serviceProvider) 27 public CommandLineParser(IServiceProvider serviceProvider)
26 { 28 {
27 this.ServiceProvider = serviceProvider; 29 this.ServiceProvider = serviceProvider;
@@ -380,15 +382,15 @@ namespace WixToolset.Core.CommandLine
380 382
381 foreach (var bindPath in bindPaths) 383 foreach (var bindPath in bindPaths)
382 { 384 {
383 var bp = BindPath.Parse(bindPath); 385 var bp = ParseBindPath(bindPath);
384 386
385 if (Directory.Exists(bp.Path)) 387 if (File.Exists(bp.Path))
386 { 388 {
387 result.Add(bp); 389 this.Messaging.Write(ErrorMessages.ExpectedDirectoryGotFile("-bindpath", bp.Path));
388 } 390 }
389 else if (File.Exists(bp.Path)) 391 else
390 { 392 {
391 this.Messaging.Write(ErrorMessages.ExpectedDirectoryGotFile("-bindpath", bp.Path)); 393 result.Add(bp);
392 } 394 }
393 } 395 }
394 396
@@ -407,5 +409,11 @@ namespace WixToolset.Core.CommandLine
407 409
408 return false; 410 return false;
409 } 411 }
412
413 public static BindPath ParseBindPath(string bindPath)
414 {
415 string[] namedPath = bindPath.Split(BindPathSplit, 2);
416 return (1 == namedPath.Length) ? new BindPath(namedPath[0]) : new BindPath(namedPath[0], namedPath[1]);
417 }
410 } 418 }
411} 419}
diff --git a/src/WixToolset.Core/Preprocessor.cs b/src/WixToolset.Core/Preprocessor.cs
index ac8cefe3..aca954bd 100644
--- a/src/WixToolset.Core/Preprocessor.cs
+++ b/src/WixToolset.Core/Preprocessor.cs
@@ -649,7 +649,7 @@ namespace WixToolset.Core
649 649
650 if (null == includeFile) 650 if (null == includeFile)
651 { 651 {
652 throw new WixFileNotFoundException(sourceLineNumbers, includePath, "include"); 652 throw new WixException(ErrorMessages.FileNotFound(sourceLineNumbers, includePath, "include"));
653 } 653 }
654 654
655 using (XmlReader reader = XmlReader.Create(includeFile, DocumentXmlReaderSettings)) 655 using (XmlReader reader = XmlReader.Create(includeFile, DocumentXmlReaderSettings))