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>2009-08-29 20:50:33 +0400
committerSebastien Pouliot <sebastien@ximian.com>2009-08-29 20:50:33 +0400
commit7d29e0a0e9323fc5b2f83f5592d5903f073e8744 (patch)
tree471279d8a9836594e4d3f6a96a4227aef07e87ff
parent6b34f3382bea621aa67fda51441a0183b7891206 (diff)
In Gendarme.Rules.Portability/Test:
2009-08-29 Sebastien Pouliot <sebastien@ximian.com> * MonoCompatibilityReviewTest.cs: Adjust DeleteDefinitionData since we are now keeping multiple zip files. In Gendarme.Rules.Portability: 2008-08-29 Sebastien Pouliot <sebastien@ximian.com> * MonoCompatibilityReviewRule.cs: Added a Version configurable property to select between (local) definition files (e.g. a new gendarme reviewing compoatibility with an older mono). Automatic download of new difinition files when Gendarme is updated (since a new version of mono is likely available). Updated documentation svn path=/trunk/mono-tools/; revision=140921
-rw-r--r--gendarme/rules/Gendarme.Rules.Portability/ChangeLog8
-rw-r--r--gendarme/rules/Gendarme.Rules.Portability/MonoCompatibilityReviewRule.cs133
-rw-r--r--gendarme/rules/Gendarme.Rules.Portability/Test/ChangeLog5
-rw-r--r--gendarme/rules/Gendarme.Rules.Portability/Test/MonoCompatibilityReviewTest.cs7
4 files changed, 128 insertions, 25 deletions
diff --git a/gendarme/rules/Gendarme.Rules.Portability/ChangeLog b/gendarme/rules/Gendarme.Rules.Portability/ChangeLog
index 3ad8ec55..163ea53d 100644
--- a/gendarme/rules/Gendarme.Rules.Portability/ChangeLog
+++ b/gendarme/rules/Gendarme.Rules.Portability/ChangeLog
@@ -1,3 +1,11 @@
+2008-08-29 Sebastien Pouliot <sebastien@ximian.com>
+
+ * MonoCompatibilityReviewRule.cs: Added a Version configurable
+ property to select between (local) definition files (e.g. a new
+ gendarme reviewing compoatibility with an older mono). Automatic
+ download of new difinition files when Gendarme is updated (since
+ a new version of mono is likely available). Updated documentation
+
2009-08-26 Jesse Jones <jesjones@mindspring.com>
* MonoCompatibilityReviewRule.cs: Edited the description.
diff --git a/gendarme/rules/Gendarme.Rules.Portability/MonoCompatibilityReviewRule.cs b/gendarme/rules/Gendarme.Rules.Portability/MonoCompatibilityReviewRule.cs
index c67542a6..3ab33b5f 100644
--- a/gendarme/rules/Gendarme.Rules.Portability/MonoCompatibilityReviewRule.cs
+++ b/gendarme/rules/Gendarme.Rules.Portability/MonoCompatibilityReviewRule.cs
@@ -3,8 +3,10 @@
//
// Authors:
// Andreas Noever <andreas.noever@gmail.com>
+// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) 2007 Andreas Noever
+// Copyright (C) 2009 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,6 +30,7 @@
using System;
using System.Collections.Generic;
+using System.ComponentModel;
using System.IO;
using System.Net;
@@ -47,13 +50,16 @@ namespace Gendarme.Rules.Portability {
/// <summary>
/// This rule will fire if one of the assemblies being checked contains a call to a .NET
/// method which is either not implemented on Mono or partially implemented. It does
- /// this by downloading a MoMA definitions.zip file into <c>~/.local/share/Gendarme/definitions.zip</c>
- /// (on Unix) and checking for calls to the methods therein. The rule will work without
+ /// this by downloading a MoMA definitions file under <c>~/.local/share/Gendarme/</c> (on UNIX)
+ /// or <c>C:\Documents and Settings\{username}\Local Settings\Application Data\Gendarme</c>
+ /// (on Windows) and checking for calls to the methods therein. The rule will work without
/// MoMA but if it does fire it may be useful to download and run MoMA.
/// </summary>
/// <remarks>
- /// The definitions.zip will not be downloaded if it already exists so it's a good idea to
- /// manually remove it now and then.
+ /// By default the rule will use the latest local version available. This can be overriden to use a
+ /// specific, local, version if you want to review compatibility against a specific Mono version.
+ /// You can also manually remove them, now and then, to ensure you are using the latest version.
+ /// Also upgrading Gendarme will try to download a newer version of the definitions files.
/// </remarks>
[Problem ("The method is either missing or partially implemented on Mono.")]
@@ -68,6 +74,9 @@ namespace Gendarme.Rules.Portability {
private HashSet<string> NotImplementedInternal; //value is unused
private HashSet<string> MissingInternal; //value is unused
private Dictionary<string, string> TodoInternal; //value = TODO Description
+
+ private Version version;
+ private string definitions_folder;
public HashSet<string> NotImplemented {
get { return NotImplementedInternal; }
@@ -80,26 +89,92 @@ namespace Gendarme.Rules.Portability {
public Dictionary<string, string> ToDo {
get { return TodoInternal; }
}
-
- public override void Initialize (IRunner runner)
+
+ private string DefinitionsFolder {
+ get {
+ if (definitions_folder == null) {
+ string localAppDataFolder = Environment.GetFolderPath (Environment.SpecialFolder.LocalApplicationData);
+ definitions_folder = Path.Combine (localAppDataFolder, "Gendarme");
+ if (!Directory.Exists (definitions_folder))
+ Directory.CreateDirectory (definitions_folder);
+ }
+ return definitions_folder;
+ }
+ }
+
+ /// <summary>
+ /// The version of Mono against which you wish to review compatibility.
+ /// You need to have this version of the definitions file downloaded in order to use it.
+ /// This is useful if you want to upgrade Gendarme but still want to test compatibility
+ /// against an older version of Mono.
+ /// </summary>
+ [Description ("The version of Mono against which you wish to review compatibility.")]
+ public string Version {
+ get {
+ if (version == null)
+ return String.Empty;
+ return version.ToString ();
+ }
+ set {
+ version = new Version (value);
+ string file = GetFileName (version);
+ if (!File.Exists (file)) {
+ version = null;
+ throw new FileNotFoundException ("Cannot find definitions for the requested version.", file);
+ }
+ }
+ }
+
+ private string GetFileName (Version version)
{
- base.Initialize (runner);
+ return Path.Combine (DefinitionsFolder, String.Format ("definitions-{0}.zip", version));
+ }
- string localAppDataFolder = Environment.GetFolderPath (Environment.SpecialFolder.LocalApplicationData);
- string definitionsFolder = Path.Combine (localAppDataFolder, "Gendarme");
- string definitionsFile = Path.Combine (definitionsFolder, "definitions.zip");
+ private Version GetLastestLocalDefinition ()
+ {
+ string [] def_files = Directory.GetFiles (DefinitionsFolder, "definitions-*.zip");
+ if (def_files.Length > 1)
+ Array.Sort<string> (def_files);
+ if (def_files.Length == 0)
+ return new Version ();
- if (!File.Exists (definitionsFile)) {
- if (!Directory.Exists (definitionsFolder))
- Directory.CreateDirectory (definitionsFolder);
+ try {
+ string latest = def_files [def_files.Length - 1];
+ int s = latest.LastIndexOf ("definitions-") + 12;
+ return new Version (latest.Substring (s, latest.Length - s - 4)); // remove .zip
+ }
+ catch (FormatException) {
+ return new Version ();
+ }
+ }
- if (!Download (definitionsFile)) {
- Active = false;
- return;
+ private string SelectDefinitionsFile ()
+ {
+ Version def_version = version;
+
+ // nothing specified ?
+ if (def_version == null) {
+ // then we'll use the latest local version available
+ def_version = GetLastestLocalDefinition ();
+ // if Gendarme version is newer than the definitions then there's likely something new available
+ if (typeof (IRule).Assembly.GetName ().Version > def_version) {
+ // however we don't want to download a (potentially) unexisting file each time we execute
+ // Gendarme (e.g. a development release, like 2.5.x.x) so we limit this to once per week
+ FileInfo fi = new FileInfo (GetFileName (def_version));
+ if (!fi.Exists || (fi.CreationTimeUtc < DateTime.UtcNow.AddDays (-7)))
+ def_version = DownloadLatestDefinitions ();
}
}
- using (FileStream fs = File.OpenRead (definitionsFile)) {
+ return GetFileName (def_version);
+ }
+
+ private void LoadDefinitions (string filename)
+ {
+ if (!File.Exists (filename))
+ return;
+
+ using (FileStream fs = File.OpenRead (filename)) {
using (ZipInputStream zs = new ZipInputStream (fs)) {
ZipEntry ze;
while ((ze = zs.GetNextEntry ()) != null) {
@@ -119,30 +194,44 @@ namespace Gendarme.Rules.Portability {
}
}
}
+ }
+
+ public override void Initialize (IRunner runner)
+ {
+ base.Initialize (runner);
+
+ // get the specified or latest definition file available locally *or*
+ // download it if none is present or if gendarme is more recent than the file
+ LoadDefinitions (SelectDefinitionsFile ());
// rule is active only if we have, at least one of, the MoMA files
Active = ((NotImplemented != null) || (Missing != null) || (ToDo != null));
}
- private bool Download (string definitionsFile)
+ private Version DownloadLatestDefinitions ()
{
+ Version v = null;
// try to download files from the net
try {
string definitionsUri;
using (MoMASubmit ws = new MoMASubmit ()) {
- definitionsUri = ws.GetLatestDefinitionsVersion ().Split ('|') [2];
+ string lastest_def = ws.GetLatestDefinitionsVersion ();
+ int s = lastest_def.LastIndexOf ('/') + 1;
+ int e = lastest_def.LastIndexOf ('-');
+ v = new Version (lastest_def.Substring (s, e - s));
+ definitionsUri = lastest_def.Split ('|') [2];
}
using (WebClient wc = new WebClient ()) {
- wc.DownloadFile (new Uri (definitionsUri), definitionsFile);
+ string filename = GetFileName (v);
+ wc.DownloadFile (new Uri (definitionsUri), filename);
}
}
catch (WebException e) {
if (Runner.VerbosityLevel > 0)
Console.Error.WriteLine (e);
- return false;
}
- return true;
+ return v;
}
private static Dictionary<string, string> ReadWithComments (TextReader reader)
diff --git a/gendarme/rules/Gendarme.Rules.Portability/Test/ChangeLog b/gendarme/rules/Gendarme.Rules.Portability/Test/ChangeLog
index 1124a996..3ad936d8 100644
--- a/gendarme/rules/Gendarme.Rules.Portability/Test/ChangeLog
+++ b/gendarme/rules/Gendarme.Rules.Portability/Test/ChangeLog
@@ -1,3 +1,8 @@
+2009-08-29 Sebastien Pouliot <sebastien@ximian.com>
+
+ * MonoCompatibilityReviewTest.cs: Adjust DeleteDefinitionData since
+ we are now keeping multiple zip files.
+
2008-11-18 Sebastien Pouliot <sebastien@ximian.com>
* MonoCompatibilityReviewTest.cs: Adjust test wrt rule changes.
diff --git a/gendarme/rules/Gendarme.Rules.Portability/Test/MonoCompatibilityReviewTest.cs b/gendarme/rules/Gendarme.Rules.Portability/Test/MonoCompatibilityReviewTest.cs
index 2366ced6..bcd4d6e9 100644
--- a/gendarme/rules/Gendarme.Rules.Portability/Test/MonoCompatibilityReviewTest.cs
+++ b/gendarme/rules/Gendarme.Rules.Portability/Test/MonoCompatibilityReviewTest.cs
@@ -146,9 +146,10 @@ namespace Test.Rules.Portability {
{
string localAppDataFolder = Environment.GetFolderPath (Environment.SpecialFolder.LocalApplicationData);
string definitionsFolder = Path.Combine (localAppDataFolder, "Gendarme");
- string definitionsFile = Path.Combine (definitionsFolder, "definitions.zip");
- if (File.Exists (definitionsFile))
- File.Delete (definitionsFile);
+ string[] files = Directory.GetFiles (definitionsFolder, "definitions*.zip");
+ foreach (string file in files) {
+ File.Delete (file);
+ }
}
[Test]