Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono-tools.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastien Pouliot <sebastien@ximian.com>2008-02-15 23:19:23 +0300
committerSebastien Pouliot <sebastien@ximian.com>2008-02-15 23:19:23 +0300
commitfe1f50a4be920ac42bbd5f86f27bcce793963d70 (patch)
treeaf3ced30168f44972f7e4b7cc8d61a7d6ff62886 /gendarme/rules
parent8ac5f814fd3adb7c89b333cbf2ba741f5299c1f5 (diff)
2008-02-15 Sebastien Pouliot <sebastien@ximian.com>
* ExecutableTargetRule.cs * GtkSharpExecutableTargetRule.cs * SystemWindowsFormsExecutableTargetRule.cs * UseSTAThreadAttributeOnSWFEntryPointsRule.cs: Update rules wrt framework changes. svn path=/trunk/mono-tools/; revision=95822
Diffstat (limited to 'gendarme/rules')
-rw-r--r--gendarme/rules/Gendarme.Rules.Ui/ChangeLog8
-rw-r--r--gendarme/rules/Gendarme.Rules.Ui/ExecutableTargetRule.cs20
-rw-r--r--gendarme/rules/Gendarme.Rules.Ui/GtkSharpExecutableTargetRule.cs5
-rw-r--r--gendarme/rules/Gendarme.Rules.Ui/SystemWindowsFormsExecutableTargetRule.cs7
-rw-r--r--gendarme/rules/Gendarme.Rules.Ui/UseSTAThreadAttributeOnSWFEntryPointsRule.cs34
5 files changed, 48 insertions, 26 deletions
diff --git a/gendarme/rules/Gendarme.Rules.Ui/ChangeLog b/gendarme/rules/Gendarme.Rules.Ui/ChangeLog
index 9e5936df..3b463962 100644
--- a/gendarme/rules/Gendarme.Rules.Ui/ChangeLog
+++ b/gendarme/rules/Gendarme.Rules.Ui/ChangeLog
@@ -1,3 +1,11 @@
+2008-02-15 Sebastien Pouliot <sebastien@ximian.com>
+
+ * ExecutableTargetRule.cs
+ * GtkSharpExecutableTargetRule.cs
+ * SystemWindowsFormsExecutableTargetRule.cs
+ * UseSTAThreadAttributeOnSWFEntryPointsRule.cs:
+ Update rules wrt framework changes.
+
2008-01-21 Sebastien Pouliot <sebastien@ximian.com>
* UseSTAThreadAttributeOnSWFEntryPointsRule.cs: New. Rule to check
diff --git a/gendarme/rules/Gendarme.Rules.Ui/ExecutableTargetRule.cs b/gendarme/rules/Gendarme.Rules.Ui/ExecutableTargetRule.cs
index 5441c7d2..05ee3a19 100644
--- a/gendarme/rules/Gendarme.Rules.Ui/ExecutableTargetRule.cs
+++ b/gendarme/rules/Gendarme.Rules.Ui/ExecutableTargetRule.cs
@@ -4,7 +4,7 @@
// Authors:
// Sebastien Pouliot <sebastien@ximian.com>
//
-// 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 @@ using Gendarme.Framework;
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 @@ namespace Gendarme.Rules.Ui {
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;
}
}
}
diff --git a/gendarme/rules/Gendarme.Rules.Ui/GtkSharpExecutableTargetRule.cs b/gendarme/rules/Gendarme.Rules.Ui/GtkSharpExecutableTargetRule.cs
index 03ce7e56..4c01da41 100644
--- a/gendarme/rules/Gendarme.Rules.Ui/GtkSharpExecutableTargetRule.cs
+++ b/gendarme/rules/Gendarme.Rules.Ui/GtkSharpExecutableTargetRule.cs
@@ -4,7 +4,7 @@
// Authors:
// Sebastien Pouliot <sebastien@ximian.com>
//
-// 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 {
diff --git a/gendarme/rules/Gendarme.Rules.Ui/SystemWindowsFormsExecutableTargetRule.cs b/gendarme/rules/Gendarme.Rules.Ui/SystemWindowsFormsExecutableTargetRule.cs
index 5d4c4ca7..4f601a7e 100644
--- a/gendarme/rules/Gendarme.Rules.Ui/SystemWindowsFormsExecutableTargetRule.cs
+++ b/gendarme/rules/Gendarme.Rules.Ui/SystemWindowsFormsExecutableTargetRule.cs
@@ -4,7 +4,7 @@
// Authors:
// Sebastien Pouliot <sebastien@ximian.com>
//
-// 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"; }
diff --git a/gendarme/rules/Gendarme.Rules.Ui/UseSTAThreadAttributeOnSWFEntryPointsRule.cs b/gendarme/rules/Gendarme.Rules.Ui/UseSTAThreadAttributeOnSWFEntryPointsRule.cs
index 63fd8d5b..25250549 100644
--- a/gendarme/rules/Gendarme.Rules.Ui/UseSTAThreadAttributeOnSWFEntryPointsRule.cs
+++ b/gendarme/rules/Gendarme.Rules.Ui/UseSTAThreadAttributeOnSWFEntryPointsRule.cs
@@ -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 @@ using Mono.Cecil;
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 @@ namespace Gendarme.Rules.Ui {
}
}
+ // 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 @@ namespace Gendarme.Rules.Ui {
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;
}
}
}