Author: mhabersack
Date: 2007-11-09 07:38:49 -0500 (Fri, 09 Nov 2007)
New Revision: 89309
Added:
trunk/mcs/tools/mconfig/Mono.MonoConfig/FeatureNode.cs
Modified:
trunk/mcs/tools/mconfig/ChangeLog
trunk/mcs/tools/mconfig/Mono.MonoConfig/FeatureNodeHandler.cs
trunk/mcs/tools/mconfig/data/config.xml
trunk/mcs/tools/mconfig/mconfig.exe.sources
Log:
2007-11-09 Marek Habersack <[EMAIL PROTECTED]>
* Mono.MonoConfig/FeatureNodeHandler.cs: added support for feature
descriptions.
* Mono.MonoConfig/FeatureNode.cs: a new container for the
'feature' block data.
* data/config.xml: feature storage type has changed.
* mconfig.exe.sources: added Mono.MonoConfig/FeatureNode.cs
Modified: trunk/mcs/tools/mconfig/ChangeLog
===================================================================
--- trunk/mcs/tools/mconfig/ChangeLog 2007-11-09 10:42:46 UTC (rev 89308)
+++ trunk/mcs/tools/mconfig/ChangeLog 2007-11-09 12:38:49 UTC (rev 89309)
@@ -1,3 +1,15 @@
+2007-11-09 Marek Habersack <[EMAIL PROTECTED]>
+
+ * Mono.MonoConfig/FeatureNodeHandler.cs: added support for feature
+ descriptions.
+
+ * Mono.MonoConfig/FeatureNode.cs: a new container for the
+ 'feature' block data.
+
+ * data/config.xml: feature storage type has changed.
+
+ * mconfig.exe.sources: added Mono.MonoConfig/FeatureNode.cs
+
2007-11-08 Marek Habersack <[EMAIL PROTECTED]>
* Mono.MonoConfig/consts.cs.in: use @MONO_SYSCONFDIR@ instead of
Added: trunk/mcs/tools/mconfig/Mono.MonoConfig/FeatureNode.cs
===================================================================
--- trunk/mcs/tools/mconfig/Mono.MonoConfig/FeatureNode.cs 2007-11-09
10:42:46 UTC (rev 89308)
+++ trunk/mcs/tools/mconfig/Mono.MonoConfig/FeatureNode.cs 2007-11-09
12:38:49 UTC (rev 89309)
@@ -0,0 +1,63 @@
+//
+// Authors:
+// Marek Habersack ([EMAIL PROTECTED])
+//
+// (C) 2007 Novell, Inc
+//
+
+//
+// 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 System;
+using System.Collections.Generic;
+using System.IO;
+
+namespace Mono.MonoConfig
+{
+ public class FeatureNode
+ {
+ List <FeatureBlock> blocks;
+ string description;
+
+ public List <FeatureBlock> Blocks {
+ get {
+ if (blocks != null)
+ return blocks;
+
+ return new List <FeatureBlock> ();
+ }
+ }
+
+ public string Description {
+ get {
+ if (description != null)
+ return description;
+
+ return String.Empty;
+ }
+ }
+
+ public FeatureNode (List <FeatureBlock> blocks, string
description)
+ {
+ this.blocks = blocks;
+ this.description = description;
+ }
+ }
+}
Property changes on: trunk/mcs/tools/mconfig/Mono.MonoConfig/FeatureNode.cs
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: trunk/mcs/tools/mconfig/Mono.MonoConfig/FeatureNodeHandler.cs
===================================================================
--- trunk/mcs/tools/mconfig/Mono.MonoConfig/FeatureNodeHandler.cs
2007-11-09 10:42:46 UTC (rev 89308)
+++ trunk/mcs/tools/mconfig/Mono.MonoConfig/FeatureNodeHandler.cs
2007-11-09 12:38:49 UTC (rev 89309)
@@ -39,11 +39,13 @@
string name;
FeatureTarget target;
List <FeatureBlock> blocks;
- Dictionary <string, List <FeatureBlock>> storage;
+ Dictionary <string, FeatureNode> storage;
+ StringBuilder description;
public FeatureNodeHandler ()
{
blocks = new List <FeatureBlock> ();
+ description = new StringBuilder ();
}
public void ReadConfiguration (XPathNavigator nav)
@@ -54,6 +56,15 @@
XPathNodeIterator iter = nav.Select
("blocks/block[string-length (@name) > 0]");
while (iter.MoveNext ())
blocks.Add (new FeatureBlock (iter.Current,
target));
+
+ iter = nav.Select ("description/text()");
+ string val;
+ while (iter.MoveNext ()) {
+ val = iter.Current.Value;
+ if (String.IsNullOrEmpty (val))
+ continue;
+ description.Append (val);
+ }
}
public void StoreConfiguration ()
@@ -62,18 +73,20 @@
List <FeatureBlock> blocksClone = new List
<FeatureBlock> (blocks.Count);
blocksClone.AddRange (blocks);
-
+ FeatureNode fn = new FeatureNode (blocksClone,
description.ToString ());
+
if (storage.ContainsKey (name))
- storage [name] = blocksClone; // allow for
silent override
+ storage [name] = fn; // allow for silent
override
else
- storage.Add (name, blocksClone);
+ storage.Add (name, fn);
blocks.Clear ();
+ description.Length = 0;
}
public void SetStorage (object storage)
{
- this.storage = storage as Dictionary <string, List
<FeatureBlock>>;
+ this.storage = storage as Dictionary <string,
FeatureNode>;
if (this.storage == null)
throw new ApplicationException ("Invalid
storage type");
}
@@ -86,19 +99,83 @@
return null;
List <string> ret = new List <string>
(storage.Count);
- List <FeatureBlock> lfb;
+ string desc;
- foreach (KeyValuePair <string, List
<FeatureBlock>> kvp in storage) {
- lfb = kvp.Value;
- if (lfb.Count == 0)
+ foreach (KeyValuePair <string, FeatureNode> kvp
in storage) {
+ desc = FormatFeatureDescription
(kvp.Key, kvp.Value);
+ if (String.IsNullOrEmpty (desc))
continue;
-
- ret.Add (String.Format ("{0} (Target:
{1})", kvp.Key, lfb [0].Target));
+ ret.Add (desc);
}
return ret;
}
}
+
+ string FormatFeatureDescription (string name, FeatureNode fn)
+ {
+ if (fn == null)
+ return null;
+
+ List <FeatureBlock> lfb = fn.Blocks;
+ if (lfb == null || lfb.Count == 0)
+ return null;
+
+ StringBuilder ret = new StringBuilder ();
+ ret.AppendFormat ("{0} (Target: {1})", name, lfb
[0].Target);
+
+ string desc = fn.Description;
+ if (String.IsNullOrEmpty (desc))
+ return ret.ToString ();
+
+ string indent = " ";
+ int maxLineWidth = Console.WindowWidth - indent.Length;
+ string[] dlines = desc.Split ('\n');
+ string line;
+
+ foreach (string l in dlines) {
+ if (l.Length == 0) {
+ ret.Append ("\n");
+ continue;
+ }
+
+ line = l.Trim ();
+ if (line.Length > maxLineWidth)
+ ret.AppendFormat ("{0}\n",
BreakLongLine (line, indent, maxLineWidth));
+ else
+ ret.AppendFormat ("{0}{1}\n", indent,
line);
+ }
+
+ return ret.ToString ();
+ }
+
+ string BreakLongLine (string line, string indent, int
maxLineWidth)
+ {
+ StringBuilder sb = new StringBuilder ();
+
+ int lineLen = line.Length;
+ int segments = lineLen / maxLineWidth;
+ int segmentStart = 0;
+ int segmentLen = maxLineWidth - 1;
+ int idx;
+
+ while (segments-- >= 0) {
+ idx = line.LastIndexOf (' ', segmentStart +
segmentLen);
+ if (idx > 0)
+ segmentLen = idx - segmentStart;
+ else
+ idx = segmentLen - 1;
+
+ sb.AppendFormat ("{0}{1}\n", indent,
line.Substring (segmentStart, segmentLen));
+ segmentStart = idx + 1;
+ if (lineLen - segmentStart > maxLineWidth)
+ segmentLen = maxLineWidth;
+ else
+ segmentLen = lineLen - segmentStart - 1;
+ }
+
+ return sb.ToString ();
+ }
public bool HasFeature (string featureName)
{
@@ -106,8 +183,12 @@
if (!storage.ContainsKey (featureName))
return false;
+
+ FeatureNode fn = storage [featureName];
+ if (fn == null)
+ return false;
- List <FeatureBlock> blocks = storage [featureName];
+ List <FeatureBlock> blocks = fn.Blocks;
if (blocks == null || blocks.Count == 0)
return false;
@@ -119,10 +200,12 @@
{
AssertStorage ();
- if (!storage.ContainsKey (featureName))
+ FeatureNode fn;
+
+ if (!storage.ContainsKey (featureName) || (fn = storage
[featureName]) == null)
throw new ApplicationException (String.Format
("Missing definition of feature '{0}'", featureName));
-
- List <FeatureBlock> blocks = storage [featureName];
+
+ List <FeatureBlock> blocks = fn.Blocks;
if (blocks == null || blocks.Count == 0)
throw new ApplicationException (String.Format
("Definition of feature '{0}' is empty", featureName));
Modified: trunk/mcs/tools/mconfig/data/config.xml
===================================================================
--- trunk/mcs/tools/mconfig/data/config.xml 2007-11-09 10:42:46 UTC (rev
89308)
+++ trunk/mcs/tools/mconfig/data/config.xml 2007-11-09 12:38:49 UTC (rev
89309)
@@ -4,7 +4,7 @@
<handlers>
<handler section="feature"
type="Mono.MonoConfig.FeatureNodeHandler, mconfig,
Version=0.1.0.0, Culture=neutral, PublicKeyToken=null"
-
storageType="System.Collections.Generic.Dictionary`2[[System.String, mscorlib,
Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089],[System.Collections.Generic.List`1[[Mono.MonoConfig.FeatureBlock,
mconfig, Version=0.1.0.0, Culture=neutral, PublicKeyToken=null]], mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
+
storageType="System.Collections.Generic.Dictionary`2[[System.String, mscorlib,
Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089],[Mono.MonoConfig.FeatureNode, mconfig,
Version=0.1.0.0, Culture=neutral, PublicKeyToken=null]], mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<handler section="configBlock"
type="Mono.MonoConfig.ConfigBlockNodeHandler, mconfig,
Version=0.1.0.0, Culture=neutral, PublicKeyToken=null"
storageType="System.Collections.Generic.Dictionary`2[[System.String, mscorlib,
Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089],[Mono.MonoConfig.ConfigBlockBlock, mconfig,
Version=0.1.0.0, Culture=neutral, PublicKeyToken=null]], mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
@@ -18,6 +18,9 @@
</configuration>
<feature name="AJAX" target="web">
+ <description><![CDATA[
+ Adds entries to your Web.config file which are required by any AJAX.NET
application.
+ ]]></description>
<blocks>
<block name="AJAX config sections"/>
<block name="AJAX controls registration"/>
Modified: trunk/mcs/tools/mconfig/mconfig.exe.sources
===================================================================
--- trunk/mcs/tools/mconfig/mconfig.exe.sources 2007-11-09 10:42:46 UTC (rev
89308)
+++ trunk/mcs/tools/mconfig/mconfig.exe.sources 2007-11-09 12:38:49 UTC (rev
89309)
@@ -6,6 +6,7 @@
Mono.MonoConfig/DefaultConfigFileNodeHandler.cs
Mono.MonoConfig/DefaultNodeHandler.cs
Mono.MonoConfig/FeatureBlock.cs
+Mono.MonoConfig/FeatureNode.cs
Mono.MonoConfig/FeatureNodeHandler.cs
Mono.MonoConfig/FeatureTarget.cs
Mono.MonoConfig/Helpers.cs
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches