aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core/ExtensibilityServices/ParseHelper.cs
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2017-12-19 12:25:40 -0800
committerRob Mensching <rob@firegiant.com>2017-12-19 12:25:40 -0800
commit155a6e96346e0cb3d9ab6f5372fa29b46ebaee89 (patch)
tree59d1f151bfde8068b6014b05b5c8cfea3402c974 /src/WixToolset.Core/ExtensibilityServices/ParseHelper.cs
parent6f1665ed759b31bd095f186f9239232c653597cd (diff)
downloadwix-155a6e96346e0cb3d9ab6f5372fa29b46ebaee89.tar.gz
wix-155a6e96346e0cb3d9ab6f5372fa29b46ebaee89.tar.bz2
wix-155a6e96346e0cb3d9ab6f5372fa29b46ebaee89.zip
Integrate simplified message handling
Diffstat (limited to 'src/WixToolset.Core/ExtensibilityServices/ParseHelper.cs')
-rw-r--r--src/WixToolset.Core/ExtensibilityServices/ParseHelper.cs66
1 files changed, 35 insertions, 31 deletions
diff --git a/src/WixToolset.Core/ExtensibilityServices/ParseHelper.cs b/src/WixToolset.Core/ExtensibilityServices/ParseHelper.cs
index 8a67efe9..d2486890 100644
--- a/src/WixToolset.Core/ExtensibilityServices/ParseHelper.cs
+++ b/src/WixToolset.Core/ExtensibilityServices/ParseHelper.cs
@@ -34,10 +34,14 @@ namespace WixToolset.Core.ExtensibilityServices
34 public ParseHelper(IServiceProvider serviceProvider) 34 public ParseHelper(IServiceProvider serviceProvider)
35 { 35 {
36 this.ServiceProvider = serviceProvider; 36 this.ServiceProvider = serviceProvider;
37
38 this.Messaging = serviceProvider.GetService<IMessaging>();
37 } 39 }
38 40
39 private IServiceProvider ServiceProvider { get; } 41 private IServiceProvider ServiceProvider { get; }
40 42
43 private IMessaging Messaging { get; }
44
41 private ITupleDefinitionCreator Creator { get; set; } 45 private ITupleDefinitionCreator Creator { get; set; }
42 46
43 public bool ContainsProperty(string possibleProperty) 47 public bool ContainsProperty(string possibleProperty)
@@ -136,7 +140,7 @@ namespace WixToolset.Core.ExtensibilityServices
136 // TODO: should overriding the parent identifier with a specific id be an error or a warning or just let it slide? 140 // TODO: should overriding the parent identifier with a specific id be an error or a warning or just let it slide?
137 //if (null != parentId) 141 //if (null != parentId)
138 //{ 142 //{
139 // this.core.OnMessage(WixErrors.Xxx(sourceLineNumbers)); 143 // this.core.Write(WixErrors.Xxx(sourceLineNumbers));
140 //} 144 //}
141 145
142 id = inlineSyntax[0].TrimEnd(':'); 146 id = inlineSyntax[0].TrimEnd(':');
@@ -360,7 +364,7 @@ namespace WixToolset.Core.ExtensibilityServices
360 364
361 if (ParseHelper.PutGuidHere.IsMatch(value)) 365 if (ParseHelper.PutGuidHere.IsMatch(value))
362 { 366 {
363 Messaging.Instance.OnMessage(WixErrors.ExampleGuid(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); 367 this.Messaging.Write(ErrorMessages.ExampleGuid(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value));
364 return CompilerConstants.IllegalGuid; 368 return CompilerConstants.IllegalGuid;
365 } 369 }
366 else if (value.StartsWith("!(loc", StringComparison.Ordinal) || value.StartsWith("$(loc", StringComparison.Ordinal) || value.StartsWith("!(wix", StringComparison.Ordinal)) 370 else if (value.StartsWith("!(loc", StringComparison.Ordinal) || value.StartsWith("$(loc", StringComparison.Ordinal) || value.StartsWith("!(wix", StringComparison.Ordinal))
@@ -374,14 +378,14 @@ namespace WixToolset.Core.ExtensibilityServices
374 // TODO: This used to be a pedantic error, what should it be now? 378 // TODO: This used to be a pedantic error, what should it be now?
375 //if (uppercaseGuid != value) 379 //if (uppercaseGuid != value)
376 //{ 380 //{
377 // Messaging.Instance.OnMessage(WixErrors.GuidContainsLowercaseLetters(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); 381 // this.Messaging.Write(WixErrors.GuidContainsLowercaseLetters(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value));
378 //} 382 //}
379 383
380 return String.Concat("{", uppercaseGuid, "}"); 384 return String.Concat("{", uppercaseGuid, "}");
381 } 385 }
382 else 386 else
383 { 387 {
384 Messaging.Instance.OnMessage(WixErrors.IllegalGuidValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); 388 this.Messaging.Write(ErrorMessages.IllegalGuidValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value));
385 } 389 }
386 } 390 }
387 391
@@ -391,7 +395,7 @@ namespace WixToolset.Core.ExtensibilityServices
391 public Identifier GetAttributeIdentifier(SourceLineNumber sourceLineNumbers, XAttribute attribute) 395 public Identifier GetAttributeIdentifier(SourceLineNumber sourceLineNumbers, XAttribute attribute)
392 { 396 {
393 var access = AccessModifier.Public; 397 var access = AccessModifier.Public;
394 var value = Common.GetAttributeValue(sourceLineNumbers, attribute, EmptyRule.CanBeEmpty); 398 var value = Common.GetAttributeValue(this.Messaging, sourceLineNumbers, attribute, EmptyRule.CanBeEmpty);
395 399
396 var match = ParseHelper.LegalIdentifierWithAccess.Match(value); 400 var match = ParseHelper.LegalIdentifierWithAccess.Match(value);
397 if (!match.Success) 401 if (!match.Success)
@@ -407,7 +411,7 @@ namespace WixToolset.Core.ExtensibilityServices
407 411
408 if (Common.IsIdentifier(value) && 72 < value.Length) 412 if (Common.IsIdentifier(value) && 72 < value.Length)
409 { 413 {
410 Messaging.Instance.OnMessage(WixWarnings.IdentifierTooLong(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); 414 this.Messaging.Write(WarningMessages.IdentifierTooLong(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value));
411 } 415 }
412 416
413 return new Identifier(value, access); 417 return new Identifier(value, access);
@@ -415,7 +419,7 @@ namespace WixToolset.Core.ExtensibilityServices
415 419
416 public string GetAttributeIdentifierValue(SourceLineNumber sourceLineNumbers, XAttribute attribute) 420 public string GetAttributeIdentifierValue(SourceLineNumber sourceLineNumbers, XAttribute attribute)
417 { 421 {
418 return Common.GetAttributeIdentifierValue(sourceLineNumbers, attribute); 422 return Common.GetAttributeIdentifierValue(this.Messaging, sourceLineNumbers, attribute);
419 } 423 }
420 424
421 public string[] GetAttributeInlineDirectorySyntax(SourceLineNumber sourceLineNumbers, XAttribute attribute, bool resultUsedToCreateReference = false) 425 public string[] GetAttributeInlineDirectorySyntax(SourceLineNumber sourceLineNumbers, XAttribute attribute, bool resultUsedToCreateReference = false)
@@ -432,12 +436,12 @@ namespace WixToolset.Core.ExtensibilityServices
432 string id = result[0].TrimEnd(':'); 436 string id = result[0].TrimEnd(':');
433 if (1 == result.Length) 437 if (1 == result.Length)
434 { 438 {
435 Messaging.Instance.OnMessage(WixErrors.InlineDirectorySyntaxRequiresPath(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value, id)); 439 this.Messaging.Write(ErrorMessages.InlineDirectorySyntaxRequiresPath(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value, id));
436 return null; 440 return null;
437 } 441 }
438 else if (!this.IsValidIdentifier(id)) 442 else if (!this.IsValidIdentifier(id))
439 { 443 {
440 Messaging.Instance.OnMessage(WixErrors.IllegalIdentifier(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value, id)); 444 this.Messaging.Write(ErrorMessages.IllegalIdentifier(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value, id));
441 return null; 445 return null;
442 } 446 }
443 447
@@ -449,13 +453,13 @@ namespace WixToolset.Core.ExtensibilityServices
449 { 453 {
450 if (!this.IsValidLongFilename(result[0], false, false)) 454 if (!this.IsValidLongFilename(result[0], false, false))
451 { 455 {
452 Messaging.Instance.OnMessage(WixErrors.IllegalLongFilename(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value, result[0])); 456 this.Messaging.Write(ErrorMessages.IllegalLongFilename(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value, result[0]));
453 return null; 457 return null;
454 } 458 }
455 } 459 }
456 else if (!this.IsValidIdentifier(result[0])) 460 else if (!this.IsValidIdentifier(result[0]))
457 { 461 {
458 Messaging.Instance.OnMessage(WixErrors.IllegalIdentifier(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value, result[0])); 462 this.Messaging.Write(ErrorMessages.IllegalIdentifier(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value, result[0]));
459 return null; 463 return null;
460 } 464 }
461 465
@@ -467,14 +471,14 @@ namespace WixToolset.Core.ExtensibilityServices
467 { 471 {
468 if (!this.IsValidLongFilename(result[i], false, false)) 472 if (!this.IsValidLongFilename(result[i], false, false))
469 { 473 {
470 Messaging.Instance.OnMessage(WixErrors.IllegalLongFilename(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value, result[i])); 474 this.Messaging.Write(ErrorMessages.IllegalLongFilename(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value, result[i]));
471 return null; 475 return null;
472 } 476 }
473 } 477 }
474 478
475 if (1 < result.Length && !value.EndsWith("\\")) 479 if (1 < result.Length && !value.EndsWith("\\"))
476 { 480 {
477 Messaging.Instance.OnMessage(WixWarnings.BackslashTerminateInlineDirectorySyntax(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); 481 this.Messaging.Write(WarningMessages.BackslashTerminateInlineDirectorySyntax(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value));
478 } 482 }
479 } 483 }
480 484
@@ -483,7 +487,7 @@ namespace WixToolset.Core.ExtensibilityServices
483 487
484 public int GetAttributeIntegerValue(SourceLineNumber sourceLineNumbers, XAttribute attribute, int minimum, int maximum) 488 public int GetAttributeIntegerValue(SourceLineNumber sourceLineNumbers, XAttribute attribute, int minimum, int maximum)
485 { 489 {
486 return Common.GetAttributeIntegerValue(sourceLineNumbers, attribute, minimum, maximum); 490 return Common.GetAttributeIntegerValue(this.Messaging, sourceLineNumbers, attribute, minimum, maximum);
487 } 491 }
488 492
489 public string GetAttributeLongFilename(SourceLineNumber sourceLineNumbers, XAttribute attribute, bool allowWildcards, bool allowRelative) 493 public string GetAttributeLongFilename(SourceLineNumber sourceLineNumbers, XAttribute attribute, bool allowWildcards, bool allowRelative)
@@ -501,11 +505,11 @@ namespace WixToolset.Core.ExtensibilityServices
501 { 505 {
502 if (allowRelative) 506 if (allowRelative)
503 { 507 {
504 Messaging.Instance.OnMessage(WixErrors.IllegalRelativeLongFilename(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); 508 this.Messaging.Write(ErrorMessages.IllegalRelativeLongFilename(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value));
505 } 509 }
506 else 510 else
507 { 511 {
508 Messaging.Instance.OnMessage(WixErrors.IllegalLongFilename(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); 512 this.Messaging.Write(ErrorMessages.IllegalLongFilename(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value));
509 } 513 }
510 } 514 }
511 else if (allowRelative) 515 else if (allowRelative)
@@ -513,12 +517,12 @@ namespace WixToolset.Core.ExtensibilityServices
513 string normalizedPath = value.Replace('\\', '/'); 517 string normalizedPath = value.Replace('\\', '/');
514 if (normalizedPath.StartsWith("../", StringComparison.Ordinal) || normalizedPath.Contains("/../")) 518 if (normalizedPath.StartsWith("../", StringComparison.Ordinal) || normalizedPath.Contains("/../"))
515 { 519 {
516 Messaging.Instance.OnMessage(WixErrors.PayloadMustBeRelativeToCache(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); 520 this.Messaging.Write(ErrorMessages.PayloadMustBeRelativeToCache(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value));
517 } 521 }
518 } 522 }
519 else if (CompilerCore.IsAmbiguousFilename(value)) 523 else if (CompilerCore.IsAmbiguousFilename(value))
520 { 524 {
521 Messaging.Instance.OnMessage(WixWarnings.AmbiguousFileOrDirectoryName(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); 525 this.Messaging.Write(WarningMessages.AmbiguousFileOrDirectoryName(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value));
522 } 526 }
523 } 527 }
524 528
@@ -539,11 +543,11 @@ namespace WixToolset.Core.ExtensibilityServices
539 543
540 if (CompilerConstants.LongNotSet == longValue || CompilerConstants.IllegalLong == longValue) 544 if (CompilerConstants.LongNotSet == longValue || CompilerConstants.IllegalLong == longValue)
541 { 545 {
542 Messaging.Instance.OnMessage(WixErrors.IntegralValueSentinelCollision(sourceLineNumbers, longValue)); 546 this.Messaging.Write(ErrorMessages.IntegralValueSentinelCollision(sourceLineNumbers, longValue));
543 } 547 }
544 else if (minimum > longValue || maximum < longValue) 548 else if (minimum > longValue || maximum < longValue)
545 { 549 {
546 Messaging.Instance.OnMessage(WixErrors.IntegralValueOutOfRange(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, longValue, minimum, maximum)); 550 this.Messaging.Write(ErrorMessages.IntegralValueOutOfRange(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, longValue, minimum, maximum));
547 longValue = CompilerConstants.IllegalLong; 551 longValue = CompilerConstants.IllegalLong;
548 } 552 }
549 553
@@ -551,11 +555,11 @@ namespace WixToolset.Core.ExtensibilityServices
551 } 555 }
552 catch (FormatException) 556 catch (FormatException)
553 { 557 {
554 Messaging.Instance.OnMessage(WixErrors.IllegalLongValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); 558 this.Messaging.Write(ErrorMessages.IllegalLongValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value));
555 } 559 }
556 catch (OverflowException) 560 catch (OverflowException)
557 { 561 {
558 Messaging.Instance.OnMessage(WixErrors.IllegalLongValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); 562 this.Messaging.Write(ErrorMessages.IllegalLongValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value));
559 } 563 }
560 } 564 }
561 565
@@ -564,7 +568,7 @@ namespace WixToolset.Core.ExtensibilityServices
564 568
565 public string GetAttributeValue(SourceLineNumber sourceLineNumbers, XAttribute attribute, EmptyRule emptyRule = EmptyRule.CanBeWhitespaceOnly) 569 public string GetAttributeValue(SourceLineNumber sourceLineNumbers, XAttribute attribute, EmptyRule emptyRule = EmptyRule.CanBeWhitespaceOnly)
566 { 570 {
567 return Common.GetAttributeValue(sourceLineNumbers, attribute, emptyRule); 571 return Common.GetAttributeValue(this.Messaging, sourceLineNumbers, attribute, emptyRule);
568 } 572 }
569 573
570 public string GetAttributeVersionValue(SourceLineNumber sourceLineNumbers, XAttribute attribute) 574 public string GetAttributeVersionValue(SourceLineNumber sourceLineNumbers, XAttribute attribute)
@@ -584,7 +588,7 @@ namespace WixToolset.Core.ExtensibilityServices
584 return value; 588 return value;
585 } 589 }
586 590
587 Messaging.Instance.OnMessage(WixErrors.IllegalVersionValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); 591 this.Messaging.Write(ErrorMessages.IllegalVersionValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value));
588 } 592 }
589 593
590 return null; 594 return null;
@@ -608,7 +612,7 @@ namespace WixToolset.Core.ExtensibilityServices
608 return YesNoDefaultType.Default; 612 return YesNoDefaultType.Default;
609 613
610 default: 614 default:
611 Messaging.Instance.OnMessage(WixErrors.IllegalYesNoDefaultValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); 615 this.Messaging.Write(ErrorMessages.IllegalYesNoDefaultValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value));
612 return YesNoDefaultType.IllegalValue; 616 return YesNoDefaultType.IllegalValue;
613 } 617 }
614 } 618 }
@@ -628,7 +632,7 @@ namespace WixToolset.Core.ExtensibilityServices
628 return YesNoType.No; 632 return YesNoType.No;
629 633
630 default: 634 default:
631 Messaging.Instance.OnMessage(WixErrors.IllegalYesNoValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); 635 this.Messaging.Write(ErrorMessages.IllegalYesNoValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value));
632 return YesNoType.IllegalValue; 636 return YesNoType.IllegalValue;
633 } 637 }
634 } 638 }
@@ -722,7 +726,7 @@ namespace WixToolset.Core.ExtensibilityServices
722 else 726 else
723 { 727 {
724 var sourceLineNumbers = Preprocessor.GetSourceLineNumbers(element); 728 var sourceLineNumbers = Preprocessor.GetSourceLineNumbers(element);
725 Messaging.Instance.OnMessage(WixErrors.UnhandledExtensionAttribute(sourceLineNumbers, element.Name.LocalName, attribute.Name.LocalName, attribute.Name.NamespaceName)); 729 this.Messaging.Write(ErrorMessages.UnhandledExtensionAttribute(sourceLineNumbers, element.Name.LocalName, attribute.Name.LocalName, attribute.Name.NamespaceName));
726 } 730 }
727 } 731 }
728 732
@@ -736,7 +740,7 @@ namespace WixToolset.Core.ExtensibilityServices
736 else 740 else
737 { 741 {
738 var childSourceLineNumbers = Preprocessor.GetSourceLineNumbers(element); 742 var childSourceLineNumbers = Preprocessor.GetSourceLineNumbers(element);
739 Messaging.Instance.OnMessage(WixErrors.UnhandledExtensionElement(childSourceLineNumbers, parentElement.Name.LocalName, element.Name.LocalName, element.Name.NamespaceName)); 743 this.Messaging.Write(ErrorMessages.UnhandledExtensionElement(childSourceLineNumbers, parentElement.Name.LocalName, element.Name.LocalName, element.Name.NamespaceName));
740 } 744 }
741 } 745 }
742 746
@@ -751,7 +755,7 @@ namespace WixToolset.Core.ExtensibilityServices
751 else 755 else
752 { 756 {
753 var childSourceLineNumbers = Preprocessor.GetSourceLineNumbers(element); 757 var childSourceLineNumbers = Preprocessor.GetSourceLineNumbers(element);
754 Messaging.Instance.OnMessage(WixErrors.UnhandledExtensionElement(childSourceLineNumbers, parentElement.Name.LocalName, element.Name.LocalName, element.Name.NamespaceName)); 758 this.Messaging.Write(ErrorMessages.UnhandledExtensionElement(childSourceLineNumbers, parentElement.Name.LocalName, element.Name.LocalName, element.Name.NamespaceName));
755 } 759 }
756 760
757 return keyPath; 761 return keyPath;
@@ -775,13 +779,13 @@ namespace WixToolset.Core.ExtensibilityServices
775 public void UnexpectedAttribute(XElement element, XAttribute attribute) 779 public void UnexpectedAttribute(XElement element, XAttribute attribute)
776 { 780 {
777 var sourceLineNumbers = Preprocessor.GetSourceLineNumbers(element); 781 var sourceLineNumbers = Preprocessor.GetSourceLineNumbers(element);
778 Common.UnexpectedAttribute(sourceLineNumbers, attribute); 782 Common.UnexpectedAttribute(this.Messaging, sourceLineNumbers, attribute);
779 } 783 }
780 784
781 public void UnexpectedElement(XElement parentElement, XElement childElement) 785 public void UnexpectedElement(XElement parentElement, XElement childElement)
782 { 786 {
783 var sourceLineNumbers = Preprocessor.GetSourceLineNumbers(childElement); 787 var sourceLineNumbers = Preprocessor.GetSourceLineNumbers(childElement);
784 Messaging.Instance.OnMessage(WixErrors.UnexpectedElement(sourceLineNumbers, parentElement.Name.LocalName, childElement.Name.LocalName)); 788 this.Messaging.Write(ErrorMessages.UnexpectedElement(sourceLineNumbers, parentElement.Name.LocalName, childElement.Name.LocalName));
785 } 789 }
786 790
787 private void CreateTupleDefinitionCreator() 791 private void CreateTupleDefinitionCreator()