Skip to content
This repository was archived by the owner on Sep 4, 2024. It is now read-only.

Commit 64a45d9

Browse files
committed
Merge branch 'sm-with-config'
2 parents f2e9e9c + 8246057 commit 64a45d9

File tree

3 files changed

+68
-23
lines changed

3 files changed

+68
-23
lines changed

Mono.Addins/Mono.Addins.Database/AddinScanner.cs

+61-21
Original file line numberDiff line numberDiff line change
@@ -551,22 +551,8 @@ bool ScanAssembly (IProgressStatus monitor, string filePath, AddinScanResult sca
551551

552552
// Get the config file from the resources, if there is one
553553

554-
foreach (string res in reflector.GetResourceNames (asm)) {
555-
if (res.EndsWith (".addin") || res.EndsWith (".addin.xml")) {
556-
using (Stream s = reflector.GetResourceStream (asm, res)) {
557-
AddinDescription ad = AddinDescription.Read (s, Path.GetDirectoryName (filePath));
558-
if (config != null) {
559-
if (!config.IsExtensionModel && !ad.IsExtensionModel) {
560-
// There is more than one add-in definition
561-
monitor.ReportError ("Duplicate add-in definition found in assembly: " + filePath, null);
562-
return false;
563-
}
564-
config = AddinDescription.Merge (config, ad);
565-
} else
566-
config = ad;
567-
}
568-
}
569-
}
554+
if (!ScanEmbeddedDescription (monitor, filePath, reflector, asm, out config))
555+
return false;
570556

571557
if (config == null || config.IsExtensionModel) {
572558
// In this case, only scan the assembly if it has the Addin attribute.
@@ -596,6 +582,29 @@ bool ScanAssembly (IProgressStatus monitor, string filePath, AddinScanResult sca
596582
}
597583
}
598584

585+
static bool ScanEmbeddedDescription (IProgressStatus monitor, string filePath, IAssemblyReflector reflector, object asm, out AddinDescription config)
586+
{
587+
config = null;
588+
foreach (string res in reflector.GetResourceNames (asm)) {
589+
if (res.EndsWith (".addin") || res.EndsWith (".addin.xml")) {
590+
using (Stream s = reflector.GetResourceStream (asm, res)) {
591+
AddinDescription ad = AddinDescription.Read (s, Path.GetDirectoryName (filePath));
592+
if (config != null) {
593+
if (!config.IsExtensionModel && !ad.IsExtensionModel) {
594+
// There is more than one add-in definition
595+
monitor.ReportError ("Duplicate add-in definition found in assembly: " + filePath, null);
596+
return false;
597+
}
598+
config = AddinDescription.Merge (config, ad);
599+
}
600+
else
601+
config = ad;
602+
}
603+
}
604+
}
605+
return true;
606+
}
607+
599608
bool ScanDescription (IProgressStatus monitor, IAssemblyReflector reflector, AddinDescription config, object rootAssembly, AddinScanResult scanResult)
600609
{
601610
// First of all scan the main module
@@ -669,14 +678,14 @@ bool ScanDescription (IProgressStatus monitor, IAssemblyReflector reflector, Add
669678
if (!config.IsRoot) {
670679
foreach (ModuleDescription mod in config.OptionalModules) {
671680
try {
672-
assemblies.Clear ();
681+
var asmList = new List<Tuple<string,object>> ();
673682
for (int n=0; n<mod.Assemblies.Count; n++) {
674683
string s = mod.Assemblies [n];
675684
if (mod.IgnorePaths.Contains (s))
676685
continue;
677686
string asmFile = Path.Combine (config.BasePath, s);
678687
object asm = reflector.LoadAssembly (asmFile);
679-
assemblies.Add (asm);
688+
asmList.Add (new Tuple<string,object> (asmFile,asm));
680689
scanResult.AddPathToIgnore (Path.GetFullPath (asmFile));
681690
ScanAssemblyImports (reflector, mod, asm);
682691
}
@@ -691,9 +700,9 @@ bool ScanDescription (IProgressStatus monitor, IAssemblyReflector reflector, Add
691700
scanResult.AddPathToIgnore (Path.GetFullPath (path));
692701
}
693702

694-
foreach (object asm in assemblies)
695-
ScanAssemblyContents (reflector, config, mod, asm, scanResult);
696-
703+
foreach (var asm in asmList)
704+
ScanSubmodule (monitor, mod, reflector, config, scanResult, asm.Item1, asm.Item2);
705+
697706
} catch (Exception ex) {
698707
ReportReflectionException (monitor, ex, config, scanResult);
699708
}
@@ -704,6 +713,37 @@ bool ScanDescription (IProgressStatus monitor, IAssemblyReflector reflector, Add
704713
return true;
705714
}
706715

716+
bool ScanSubmodule (IProgressStatus monitor, ModuleDescription mod, IAssemblyReflector reflector, AddinDescription config, AddinScanResult scanResult, string assemblyName, object asm)
717+
{
718+
AddinDescription mconfig;
719+
ScanEmbeddedDescription (monitor, assemblyName, reflector, asm, out mconfig);
720+
if (mconfig != null) {
721+
if (!mconfig.IsExtensionModel) {
722+
monitor.ReportError ("Submodules can't define new add-ins: " + assemblyName, null);
723+
return false;
724+
}
725+
if (mconfig.OptionalModules.Count != 0) {
726+
monitor.ReportError ("Submodules can't define nested submodules: " + assemblyName, null);
727+
return false;
728+
}
729+
if (mconfig.ConditionTypes.Count != 0) {
730+
monitor.ReportError ("Submodules can't define condition types: " + assemblyName, null);
731+
return false;
732+
}
733+
if (mconfig.ExtensionNodeSets.Count != 0) {
734+
monitor.ReportError ("Submodules can't define extension node sets: " + assemblyName, null);
735+
return false;
736+
}
737+
if (mconfig.ExtensionPoints.Count != 0) {
738+
monitor.ReportError ("Submodules can't define extension points sets: " + assemblyName, null);
739+
return false;
740+
}
741+
mod.MergeWith (mconfig.MainModule);
742+
}
743+
ScanAssemblyContents (reflector, config, mod, asm, scanResult);
744+
return true;
745+
}
746+
707747
void ReportReflectionException (IProgressStatus monitor, Exception ex, AddinDescription config, AddinScanResult scanResult)
708748
{
709749
scanResult.AddFileToWithFailure (config.AddinFile);

Mono.Addins/Mono.Addins.Description/AddinDescription.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1193,8 +1193,7 @@ internal static AddinDescription Merge (AddinDescription desc1, AddinDescription
11931193
desc1.MainModule.Assemblies.Add (s);
11941194
foreach (string s in desc2.MainModule.DataFiles)
11951195
desc1.MainModule.DataFiles.Add (s);
1196-
desc1.MainModule.Dependencies.AddRange (desc2.MainModule.Dependencies);
1197-
desc1.MainModule.Extensions.AddRange (desc2.MainModule.Extensions);
1196+
desc1.MainModule.MergeWith (desc2.MainModule);
11981197
return desc1;
11991198
}
12001199

Mono.Addins/Mono.Addins.Description/ModuleDescription.cs

+6
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ public ModuleDescription ()
6666
{
6767
}
6868

69+
internal void MergeWith (ModuleDescription module)
70+
{
71+
Dependencies.AddRange (module.Dependencies);
72+
Extensions.AddRange (module.Extensions);
73+
}
74+
6975
/// <summary>
7076
/// Checks if this module depends on the specified add-in.
7177
/// </summary>

0 commit comments

Comments
 (0)