Author: spouliot
Date: 2008-02-15 15:19:23 -0500 (Fri, 15 Feb 2008)
New Revision: 95822

Modified:
   trunk/mono-tools/gendarme/rules/Gendarme.Rules.Ui/ChangeLog
   trunk/mono-tools/gendarme/rules/Gendarme.Rules.Ui/ExecutableTargetRule.cs
   
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Ui/GtkSharpExecutableTargetRule.cs
   
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Ui/SystemWindowsFormsExecutableTargetRule.cs
   
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Ui/UseSTAThreadAttributeOnSWFEntryPointsRule.cs
Log:
2008-02-15  Sebastien Pouliot  <[EMAIL PROTECTED]>

        * ExecutableTargetRule.cs
        * GtkSharpExecutableTargetRule.cs
        * SystemWindowsFormsExecutableTargetRule.cs
        * UseSTAThreadAttributeOnSWFEntryPointsRule.cs:
                Update rules wrt framework changes.



Modified: trunk/mono-tools/gendarme/rules/Gendarme.Rules.Ui/ChangeLog
===================================================================
--- trunk/mono-tools/gendarme/rules/Gendarme.Rules.Ui/ChangeLog 2008-02-15 
20:18:14 UTC (rev 95821)
+++ trunk/mono-tools/gendarme/rules/Gendarme.Rules.Ui/ChangeLog 2008-02-15 
20:19:23 UTC (rev 95822)
@@ -1,3 +1,11 @@
+2008-02-15  Sebastien Pouliot  <[EMAIL PROTECTED]>
+
+       * ExecutableTargetRule.cs
+       * GtkSharpExecutableTargetRule.cs
+       * SystemWindowsFormsExecutableTargetRule.cs
+       * UseSTAThreadAttributeOnSWFEntryPointsRule.cs:
+               Update rules wrt framework changes.
+
 2008-01-21  Sebastien Pouliot  <[EMAIL PROTECTED]>
 
        * UseSTAThreadAttributeOnSWFEntryPointsRule.cs: New. Rule to check

Modified: 
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Ui/ExecutableTargetRule.cs
===================================================================
--- trunk/mono-tools/gendarme/rules/Gendarme.Rules.Ui/ExecutableTargetRule.cs   
2008-02-15 20:18:14 UTC (rev 95821)
+++ trunk/mono-tools/gendarme/rules/Gendarme.Rules.Ui/ExecutableTargetRule.cs   
2008-02-15 20:19:23 UTC (rev 95822)
@@ -4,7 +4,7 @@
 // Authors:
 //     Sebastien Pouliot <[EMAIL PROTECTED]>
 //
-// Copyright (C) 2006-2007 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2006-2008 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -32,7 +32,8 @@
 
 namespace Gendarme.Rules.Ui {
 
-       abstract public class ExecutableTargetRule : IAssemblyRule {
+       [Solution ("Recompile the assembly using '/target:winexe'.")]
+       abstract public class ExecutableTargetRule : Rule, IAssemblyRule {
 
                private bool CheckReferences (AssemblyDefinition assembly)
                {
@@ -60,26 +61,25 @@
 
                abstract protected byte[] GetAssemblyPublicKeyToken ();
 
-               public MessageCollection CheckAssembly (AssemblyDefinition 
assembly, Runner runner)
+               public RuleResult CheckAssembly (AssemblyDefinition assembly)
                {
                        // 1. Check entry point, if no entry point then it's 
not an executable
                        if (assembly.EntryPoint == null)
-                               return runner.RuleSuccess;
+                               return RuleResult.DoesNotApply;
 
                        // 2. Check if the assembly references SWF or GTK#
                        if (!CheckReferences (assembly))
-                               return runner.RuleSuccess;
+                               return RuleResult.DoesNotApply;
 
-                       // *** ok, the rule applies! ***
+                       // *** ok, the rule applies! only Success or Failure 
from this point on ***
 
                        // 3. On Windows a console window will appear if the 
subsystem isn't Windows
                        //    i.e. the assembly wasn't compiled with 
/target:winexe
                        if (assembly.Kind == AssemblyKind.Windows)
-                               return runner.RuleSuccess;
+                               return RuleResult.Success;
 
-                       string text = String.Format ("This {0} application was 
compiled without /target:winexe", Toolkit);
-                       Message msg = new Message (text, null, 
MessageType.Warning);
-                       return new MessageCollection (msg);
+                       Runner.Report (assembly, Severity.Medium, 
Confidence.Total, String.Empty);
+                       return RuleResult.Failure;
                }
        }
 }

Modified: 
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Ui/GtkSharpExecutableTargetRule.cs
===================================================================
--- 
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Ui/GtkSharpExecutableTargetRule.cs
   2008-02-15 20:18:14 UTC (rev 95821)
+++ 
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Ui/GtkSharpExecutableTargetRule.cs
   2008-02-15 20:19:23 UTC (rev 95822)
@@ -4,7 +4,7 @@
 // Authors:
 //     Sebastien Pouliot <[EMAIL PROTECTED]>
 //
-// Copyright (C) 2006-2007 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2006-2008 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -28,8 +28,11 @@
 
 using System;
 
+using Gendarme.Framework;
+
 namespace Gendarme.Rules.Ui {
 
+       [Problem ("The assembly refers to the 'gtk-sharp.dll' assembly but 
isn't compiled using /target:winexe. A console windows will be shown under 
Windows.")]
        public class GtkSharpExecutableTargetRule: ExecutableTargetRule {
 
                protected override string Toolkit {

Modified: 
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Ui/SystemWindowsFormsExecutableTargetRule.cs
===================================================================
--- 
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Ui/SystemWindowsFormsExecutableTargetRule.cs
 2008-02-15 20:18:14 UTC (rev 95821)
+++ 
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Ui/SystemWindowsFormsExecutableTargetRule.cs
 2008-02-15 20:19:23 UTC (rev 95822)
@@ -4,7 +4,7 @@
 // Authors:
 //     Sebastien Pouliot <[EMAIL PROTECTED]>
 //
-// Copyright (C) 2006-2007 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2006-2008 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -28,9 +28,12 @@
 
 using System;
 
+using Gendarme.Framework;
+
 namespace Gendarme.Rules.Ui {
 
-       public class SystemWindowsFormsExecutableTargetRule: 
ExecutableTargetRule {
+       [Problem ("The assembly refers to the 'System.Windows.Forms.dll' 
assembly but isn't compiled using /target:winexe. A console windows will be 
shown under Windows.")]
+       public class SystemWindowsFormsExecutableTargetRule : 
ExecutableTargetRule {
 
                protected override string Toolkit {
                        get { return "WinForms"; }

Modified: 
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Ui/UseSTAThreadAttributeOnSWFEntryPointsRule.cs
===================================================================
--- 
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Ui/UseSTAThreadAttributeOnSWFEntryPointsRule.cs
      2008-02-15 20:18:14 UTC (rev 95821)
+++ 
trunk/mono-tools/gendarme/rules/Gendarme.Rules.Ui/UseSTAThreadAttributeOnSWFEntryPointsRule.cs
      2008-02-15 20:19:23 UTC (rev 95822)
@@ -26,6 +26,7 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
+using System;
 
 using Gendarme.Framework;
 using Gendarme.Framework.Rocks;
@@ -34,16 +35,22 @@
 
 namespace Gendarme.Rules.Ui {
 
-       public class UseSTAThreadAttributeOnSWFEntryPointsRule : IAssemblyRule {
+       [Problem ("The System.Windows.Forms applications entry-point (Main) is 
missing an [STAThread] attribute.")]
+       [Solution ("Add a [STAThread] attribute to your application Main 
method.")]
+       public class UseSTAThreadAttributeOnSWFEntryPointsRule : Rule, 
IAssemblyRule {
+
                private const string SystemWindowsForms = 
"System.Windows.Forms";
 
                private const string STAThread = "System.STAThreadAttribute";
                private const string MTAThread = "System.MTAThreadAttribute";
 
-               public MessageCollection CheckAssembly (AssemblyDefinition 
assembly, Runner runner)
+               public RuleResult CheckAssembly (AssemblyDefinition assembly)
                {
-                       if (assembly.EntryPoint == null)
-                               return runner.RuleSuccess;
+                       MethodDefinition entry_point = assembly.EntryPoint;
+                       
+                       // rule applies only if the assembly has an entry point
+                       if (entry_point == null)
+                               return RuleResult.DoesNotApply;
 
                        bool referencesSWF = false;
                        foreach (AssemblyNameReference assRef in 
assembly.MainModule.AssemblyReferences) {
@@ -53,17 +60,18 @@
                                }
                        }
 
+                       // rule applies only if the assembly reference 
System.Windows.Forms.dll
                        if (!referencesSWF)
-                               return runner.RuleSuccess;
+                               return RuleResult.DoesNotApply;
 
-                       MethodDefinition entryPoint = assembly.EntryPoint;
-                       bool hasSTA = entryPoint.HasAttribute (STAThread);
-                       bool hasMTA = entryPoint.HasAttribute (MTAThread);
+                       bool hasSTA = entry_point.HasAttribute (STAThread);
+                       bool hasMTA = entry_point.HasAttribute (MTAThread);
 
+                       // success if only [STAThread] attribute is present
                        if (hasSTA && !hasMTA)
-                               return runner.RuleSuccess;
+                               return RuleResult.Success;
 
-                       string text = string.Empty;
+                       string text = String.Empty;
                        if (!hasSTA && hasMTA)
                                text = "In order for Windows Forms to work 
properly, replace [System.MTAThread] attribute with [System.STAThread] on the 
entry point.";
                        else if (hasSTA && hasMTA)
@@ -71,9 +79,9 @@
                        else if (!hasSTA && !hasMTA)
                                text = "In order for Windows Forms to work 
properly, place [System.STAThread] attribute upon the entry point.";
 
-                       Location loc = new Location (entryPoint);
-                       Message msg = new Message (text, loc, 
MessageType.Error);
-                       return new MessageCollection (msg);
+                       // note: assembly rule reporting a method defect
+                       Runner.Report (entry_point, Severity.High, 
Confidence.Total, text);
+                       return RuleResult.Failure;
                }
        }
 }

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to