Author: spouliot
Date: 2008-01-21 09:19:26 -0500 (Mon, 21 Jan 2008)
New Revision: 93391
Added:
trunk/cecil/gendarme/rules/Gendarme.Rules.Ui/UseSTAThreadAttributeOnSWFEntryPointsRule.cs
Modified:
trunk/cecil/gendarme/rules/Gendarme.Rules.Ui/ChangeLog
trunk/cecil/gendarme/rules/Gendarme.Rules.Ui/Gendarme.Rules.Ui.xml.in
trunk/cecil/gendarme/rules/Gendarme.Rules.Ui/Makefile.am
Log:
2008-01-21 Sebastien Pouliot <[EMAIL PROTECTED]>
* UseSTAThreadAttributeOnSWFEntryPointsRule.cs: New. Rule to check
that SWF apps have the [STAThread] attribute on their entry point.
[Daniel Abramov]
* Makefile.am: Add rule and test to the build.
* Gendarme.Rules.Ui.xml.in: Add rule description.
Modified: trunk/cecil/gendarme/rules/Gendarme.Rules.Ui/ChangeLog
===================================================================
--- trunk/cecil/gendarme/rules/Gendarme.Rules.Ui/ChangeLog 2008-01-21
14:18:41 UTC (rev 93390)
+++ trunk/cecil/gendarme/rules/Gendarme.Rules.Ui/ChangeLog 2008-01-21
14:19:26 UTC (rev 93391)
@@ -1,3 +1,11 @@
+2008-01-21 Sebastien Pouliot <[EMAIL PROTECTED]>
+
+ * UseSTAThreadAttributeOnSWFEntryPointsRule.cs: New. Rule to check
+ that SWF apps have the [STAThread] attribute on their entry point.
+ [Daniel Abramov]
+ * Makefile.am: Add rule and test to the build.
+ * Gendarme.Rules.Ui.xml.in: Add rule description.
+
2007-11-29 Sebastien Pouliot <[EMAIL PROTECTED]>
* ExecutableTargetRule.cs: Move assembly reference checking code in
Modified: trunk/cecil/gendarme/rules/Gendarme.Rules.Ui/Gendarme.Rules.Ui.xml.in
===================================================================
--- trunk/cecil/gendarme/rules/Gendarme.Rules.Ui/Gendarme.Rules.Ui.xml.in
2008-01-21 14:18:41 UTC (rev 93390)
+++ trunk/cecil/gendarme/rules/Gendarme.Rules.Ui/Gendarme.Rules.Ui.xml.in
2008-01-21 14:19:26 UTC (rev 93391)
@@ -11,4 +11,10 @@
<problem>The assembly '{0}' refers to System.Windows.Forms
assembly but isn't compiled using /target:winexe. A console windows will be
shown under Windows.</problem>
<solution>Recompile the assembly using /target:winexe</solution>
</rule>
+ <rule Name="UseSTAThreadAttributeOnSWFEntryPointsRule"
+
Type="Gendarme.Rules.Ui.UseSTAThreadAttributeOnSWFEntryPointsRule,
Gendarme.Rules.Ui, [EMAIL PROTECTED]@, Culture=neutral, PublicKeyToken=null"
+
Uri="http://www.mono-project.com/Gendarme#UseSTAThreadAttributeOnSWFEntryPointsRule"
>
+ <problem>The System.Windows.Forms applications '{0}'
entry-point (Main) is missing an [STAThread] attribute.</problem>
+ <solution>Add a [STAThread] attribute to your application Main
method.</solution>
+ </rule>
</rules>
Modified: trunk/cecil/gendarme/rules/Gendarme.Rules.Ui/Makefile.am
===================================================================
--- trunk/cecil/gendarme/rules/Gendarme.Rules.Ui/Makefile.am 2008-01-21
14:18:41 UTC (rev 93390)
+++ trunk/cecil/gendarme/rules/Gendarme.Rules.Ui/Makefile.am 2008-01-21
14:19:26 UTC (rev 93391)
@@ -10,7 +10,7 @@
ui_rules_sources_in = ../../AssemblyInfo.cs.in
ui_rules_generated_sources = $(ui_rules_sources_in:.in=)
ui_rules_sources = ExecutableTargetRule.cs GtkSharpExecutableTargetRule.cs \
- SystemWindowsFormsExecutableTargetRule.cs
+ SystemWindowsFormsExecutableTargetRule.cs
UseSTAThreadAttributeOnSWFEntryPointsRule.cs
ui_rules_build_sources = $(addprefix $(srcdir)/, $(ui_rules_sources))
ui_rules_build_sources += $(ui_rules_generated_sources)
@@ -34,7 +34,7 @@
done;
ui_test_sources = ExecutableTargetTest.cs GtkSharpExecutableTargetTest.cs \
- SystemWindowsFormsExecutableTargetTest.cs
+ SystemWindowsFormsExecutableTargetTest.cs
UseSTAThreadAttributeOnSWFEntryPointsTest.cs
ui_test_build_sources = $(addprefix $(srcdir)/Test/, $(ui_test_sources))
Added:
trunk/cecil/gendarme/rules/Gendarme.Rules.Ui/UseSTAThreadAttributeOnSWFEntryPointsRule.cs
===================================================================
---
trunk/cecil/gendarme/rules/Gendarme.Rules.Ui/UseSTAThreadAttributeOnSWFEntryPointsRule.cs
2008-01-21 14:18:41 UTC (rev 93390)
+++
trunk/cecil/gendarme/rules/Gendarme.Rules.Ui/UseSTAThreadAttributeOnSWFEntryPointsRule.cs
2008-01-21 14:19:26 UTC (rev 93391)
@@ -0,0 +1,79 @@
+//
+// Gendarme.Rules.UI.UseSTAThreadAttributeOnSWFEntryPointsRule
+//
+// Authors:
+// Daniel Abramov <[EMAIL PROTECTED]>
+//
+// (C) 2008 Daniel Abramov
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+
+using Gendarme.Framework;
+using Gendarme.Framework.Rocks;
+
+using Mono.Cecil;
+
+namespace Gendarme.Rules.UI {
+
+ public class UseSTAThreadAttributeOnSWFEntryPointsRule : 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)
+ {
+ if (assembly.EntryPoint == null)
+ return runner.RuleSuccess;
+
+ bool referencesSWF = false;
+ foreach (AssemblyNameReference assRef in
assembly.MainModule.AssemblyReferences) {
+ if (assRef.Name == SystemWindowsForms) { // SWF
referenced
+ referencesSWF = true;
+ break;
+ }
+ }
+
+ if (!referencesSWF)
+ return runner.RuleSuccess;
+
+ MethodDefinition entryPoint = assembly.EntryPoint;
+ bool hasSTA = entryPoint.HasAttribute (STAThread);
+ bool hasMTA = entryPoint.HasAttribute (MTAThread);
+
+ if (hasSTA && !hasMTA)
+ return runner.RuleSuccess;
+
+ 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)
+ text = "In order for Windows Forms to work
properly, remove [System.MTAThread] attribute from the entry point, leaving
[System.STAThread] there.";
+ 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);
+ }
+ }
+}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches