diff options
author | Lluis Sanchez <lluis@novell.com> | 2010-03-26 13:41:24 +0300 |
---|---|---|
committer | Lluis Sanchez <lluis@novell.com> | 2010-03-26 13:41:24 +0300 |
commit | 8d7baa4674a57123f991a249284156c1920c1c25 (patch) | |
tree | 72222992de904c977690ccac6d36f8e8d0526737 | |
parent | 41b2ca2306941bc6e6feb29ca34ea1d608244a29 (diff) |
* Mono.Addins.Database/AddinScanner.cs:
* Mono.Addins.Description/AddinDescription.cs: Added support for
multiple .addin.xml files in a single assembly.
svn path=/trunk/mono-addins/; revision=154252
-rw-r--r-- | Mono.Addins/ChangeLog | 6 | ||||
-rw-r--r-- | Mono.Addins/Mono.Addins.Database/AddinScanner.cs | 31 | ||||
-rw-r--r-- | Mono.Addins/Mono.Addins.Description/AddinDescription.cs | 26 |
3 files changed, 49 insertions, 14 deletions
diff --git a/Mono.Addins/ChangeLog b/Mono.Addins/ChangeLog index 9c38d62..3fae781 100644 --- a/Mono.Addins/ChangeLog +++ b/Mono.Addins/ChangeLog @@ -1,5 +1,11 @@ 2010-03-26 Lluis Sanchez Gual <lluis@novell.com> + * Mono.Addins.Database/AddinScanner.cs: + * Mono.Addins.Description/AddinDescription.cs: Added support + for multiple .addin.xml files in a single assembly. + +2010-03-26 Lluis Sanchez Gual <lluis@novell.com> + * Makefile.am: * Mono.Addins.csproj: * Mono.Addins/AddinManager.cs: diff --git a/Mono.Addins/Mono.Addins.Database/AddinScanner.cs b/Mono.Addins/Mono.Addins.Database/AddinScanner.cs index 5989c4a..dd63408 100644 --- a/Mono.Addins/Mono.Addins.Database/AddinScanner.cs +++ b/Mono.Addins/Mono.Addins.Database/AddinScanner.cs @@ -550,27 +550,30 @@ namespace Mono.Addins.Database // Get the config file from the resources, if there is one - string configFile = null; foreach (string res in asm.GetManifestResourceNames ()) { if (res.EndsWith (".addin") || res.EndsWith (".addin.xml")) { - configFile = res; - break; + using (Stream s = asm.GetManifestResourceStream (res)) { + string asmFile = new Uri (asm.CodeBase).LocalPath; + AddinDescription ad = AddinDescription.Read (s, Path.GetDirectoryName (asmFile)); + if (config != null) { + if (!config.IsExtensionModel && !ad.IsExtensionModel) { + // There is more than one add-in definition + monitor.ReportError ("Duplicate add-in definition found in assembly: " + filePath, null); + return false; + } + config = AddinDescription.Merge (config, ad); + } else + config = ad; + } } } - if (configFile != null) { - using (Stream s = asm.GetManifestResourceStream (configFile)) { - string asmFile = new Uri (asm.CodeBase).LocalPath; - config = AddinDescription.Read (s, Path.GetDirectoryName (asmFile)); - } - } - else { - // On this case, only scan the assembly if it has the Addin attribute. + if (config == null) { + // In this case, only scan the assembly if it has the Addin attribute. AddinAttribute att = (AddinAttribute) Attribute.GetCustomAttribute (asm, typeof(AddinAttribute), false); - if (att == null) { - config = null; + if (att == null) return true; - } + config = new AddinDescription (); } diff --git a/Mono.Addins/Mono.Addins.Description/AddinDescription.cs b/Mono.Addins/Mono.Addins.Description/AddinDescription.cs index e32afa0..e7e93fd 100644 --- a/Mono.Addins/Mono.Addins.Description/AddinDescription.cs +++ b/Mono.Addins/Mono.Addins.Description/AddinDescription.cs @@ -567,6 +567,9 @@ namespace Mono.Addins.Description } XmlElement elem = config.configDoc.DocumentElement; + if (elem.LocalName == "ExtensionModel") + return config; + config.id = elem.GetAttribute ("id"); config.ns = elem.GetAttribute ("namespace"); config.name = elem.GetAttribute ("name"); @@ -717,6 +720,29 @@ namespace Mono.Addins.Description } } + internal bool IsExtensionModel { + get { return RootElement.LocalName == "ExtensionModel"; } + } + + internal static AddinDescription Merge (AddinDescription desc1, AddinDescription desc2) + { + if (!desc2.IsExtensionModel) { + AddinDescription tmp = desc1; + desc1 = desc2; desc2 = tmp; + } + desc1.ExtensionPoints.AddRange (desc2.ExtensionPoints); + desc1.ExtensionNodeSets.AddRange (desc2.ExtensionNodeSets); + desc1.ConditionTypes.AddRange (desc2.ConditionTypes); + desc1.OptionalModules.AddRange (desc2.OptionalModules); + foreach (string s in desc2.MainModule.Assemblies) + desc1.MainModule.Assemblies.Add (s); + foreach (string s in desc2.MainModule.DataFiles) + desc1.MainModule.DataFiles.Add (s); + desc1.MainModule.Dependencies.AddRange (desc2.MainModule.Dependencies); + desc1.MainModule.Extensions.AddRange (desc2.MainModule.Extensions); + return desc1; + } + void IBinaryXmlElement.Write (BinaryXmlWriter writer) { writer.WriteValue ("id", id); |