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

Commit

Permalink
Merge branch 'sm-with-config'
Browse files Browse the repository at this point in the history
  • Loading branch information
slluis committed Jan 24, 2014
2 parents f2e9e9c + 8246057 commit 64a45d9
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 23 deletions.
82 changes: 61 additions & 21 deletions Mono.Addins/Mono.Addins.Database/AddinScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -551,22 +551,8 @@ bool ScanAssembly (IProgressStatus monitor, string filePath, AddinScanResult sca

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

foreach (string res in reflector.GetResourceNames (asm)) {
if (res.EndsWith (".addin") || res.EndsWith (".addin.xml")) {
using (Stream s = reflector.GetResourceStream (asm, res)) {
AddinDescription ad = AddinDescription.Read (s, Path.GetDirectoryName (filePath));
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 (!ScanEmbeddedDescription (monitor, filePath, reflector, asm, out config))
return false;

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

static bool ScanEmbeddedDescription (IProgressStatus monitor, string filePath, IAssemblyReflector reflector, object asm, out AddinDescription config)
{
config = null;
foreach (string res in reflector.GetResourceNames (asm)) {
if (res.EndsWith (".addin") || res.EndsWith (".addin.xml")) {
using (Stream s = reflector.GetResourceStream (asm, res)) {
AddinDescription ad = AddinDescription.Read (s, Path.GetDirectoryName (filePath));
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;
}
}
}
return true;
}

bool ScanDescription (IProgressStatus monitor, IAssemblyReflector reflector, AddinDescription config, object rootAssembly, AddinScanResult scanResult)
{
// First of all scan the main module
Expand Down Expand Up @@ -669,14 +678,14 @@ bool ScanDescription (IProgressStatus monitor, IAssemblyReflector reflector, Add
if (!config.IsRoot) {
foreach (ModuleDescription mod in config.OptionalModules) {
try {
assemblies.Clear ();
var asmList = new List<Tuple<string,object>> ();
for (int n=0; n<mod.Assemblies.Count; n++) {
string s = mod.Assemblies [n];
if (mod.IgnorePaths.Contains (s))
continue;
string asmFile = Path.Combine (config.BasePath, s);
object asm = reflector.LoadAssembly (asmFile);
assemblies.Add (asm);
asmList.Add (new Tuple<string,object> (asmFile,asm));
scanResult.AddPathToIgnore (Path.GetFullPath (asmFile));
ScanAssemblyImports (reflector, mod, asm);
}
Expand All @@ -691,9 +700,9 @@ bool ScanDescription (IProgressStatus monitor, IAssemblyReflector reflector, Add
scanResult.AddPathToIgnore (Path.GetFullPath (path));
}

foreach (object asm in assemblies)
ScanAssemblyContents (reflector, config, mod, asm, scanResult);
foreach (var asm in asmList)
ScanSubmodule (monitor, mod, reflector, config, scanResult, asm.Item1, asm.Item2);

} catch (Exception ex) {
ReportReflectionException (monitor, ex, config, scanResult);
}
Expand All @@ -704,6 +713,37 @@ bool ScanDescription (IProgressStatus monitor, IAssemblyReflector reflector, Add
return true;
}

bool ScanSubmodule (IProgressStatus monitor, ModuleDescription mod, IAssemblyReflector reflector, AddinDescription config, AddinScanResult scanResult, string assemblyName, object asm)
{
AddinDescription mconfig;
ScanEmbeddedDescription (monitor, assemblyName, reflector, asm, out mconfig);
if (mconfig != null) {
if (!mconfig.IsExtensionModel) {
monitor.ReportError ("Submodules can't define new add-ins: " + assemblyName, null);
return false;
}
if (mconfig.OptionalModules.Count != 0) {
monitor.ReportError ("Submodules can't define nested submodules: " + assemblyName, null);
return false;
}
if (mconfig.ConditionTypes.Count != 0) {
monitor.ReportError ("Submodules can't define condition types: " + assemblyName, null);
return false;
}
if (mconfig.ExtensionNodeSets.Count != 0) {
monitor.ReportError ("Submodules can't define extension node sets: " + assemblyName, null);
return false;
}
if (mconfig.ExtensionPoints.Count != 0) {
monitor.ReportError ("Submodules can't define extension points sets: " + assemblyName, null);
return false;
}
mod.MergeWith (mconfig.MainModule);
}
ScanAssemblyContents (reflector, config, mod, asm, scanResult);
return true;
}

void ReportReflectionException (IProgressStatus monitor, Exception ex, AddinDescription config, AddinScanResult scanResult)
{
scanResult.AddFileToWithFailure (config.AddinFile);
Expand Down
3 changes: 1 addition & 2 deletions Mono.Addins/Mono.Addins.Description/AddinDescription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1193,8 +1193,7 @@ internal static AddinDescription Merge (AddinDescription desc1, AddinDescription
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);
desc1.MainModule.MergeWith (desc2.MainModule);
return desc1;
}

Expand Down
6 changes: 6 additions & 0 deletions Mono.Addins/Mono.Addins.Description/ModuleDescription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ public ModuleDescription ()
{
}

internal void MergeWith (ModuleDescription module)
{
Dependencies.AddRange (module.Dependencies);
Extensions.AddRange (module.Extensions);
}

/// <summary>
/// Checks if this module depends on the specified add-in.
/// </summary>
Expand Down

0 comments on commit 64a45d9

Please sign in to comment.