Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions DsmSuite.Analyzer.DotNet.Lib/BinaryFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ namespace DsmSuite.Analyzer.DotNet.Lib
public class BinaryFile
{
private readonly IProgress<ProgressInfo> _progress;
private readonly IList<TypeDefinition> _typeList = new List<TypeDefinition>();
private readonly IList<String> _includedAssemblyStrings = new List<String>();
private readonly List<TypeDefinition> _typeList = new List<TypeDefinition>();
private readonly List<String> _includedAssemblyStrings = new List<String>();

public BinaryFile(string filename, IProgress<ProgressInfo> progress, List<String> includedAssemblyStrings)
{
FileInfo = new FileInfo(filename);
_progress = progress;
_includedAssemblyStrings = includedAssemblyStrings;
if (includedAssemblyStrings != null)
_includedAssemblyStrings.AddRange(includedAssemblyStrings);
}

public List<DotNetType> Types { get; } = new List<DotNetType>();
Expand Down
133 changes: 116 additions & 17 deletions DsmSuite.Analyzer.DotNet.Test/Analysis/AnalyzerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,8 @@ namespace DsmSuite.Analyzer.DotNet.Test.Analysis
[TestClass]
public class AnalyzerTest
{
[TestMethod]
public void TestAnalyze()
private void TestAnalyze(AnalyzerSettings analyzerSettings)
{
AnalyzerSettings analyzerSettings = AnalyzerSettings.CreateDefault();
analyzerSettings.Input.AssemblyDirectory = TestData.RootDirectory;
analyzerSettings.Transformation.IgnoredNames = new List<string>();

IDsiModel model = new DsiModel("Test", analyzerSettings.Transformation.IgnoredNames, Assembly.GetExecutingAssembly());
DotNet.Analysis.Analyzer analyzer = new DotNet.Analysis.Analyzer(model, analyzerSettings, null);
analyzer.Analyze();
Expand Down Expand Up @@ -81,30 +76,30 @@ public void TestAnalyze()
IDsiElement elementGenericParameterType = model.FindElementByName("DsmSuite.Analyzer.DotNet.Test.Data.GenericParameterType`1");
Assert.IsNotNull(elementGenericParameterType);

IDsiElement elementGenericParameterTypeParameter = model.FindElementByName("DsmSuite.Analyzer.DotNet.Test.Data.GenericParameterTypeParameter");
IDsiElement elementGenericParameterTypeParameter = model.FindElementByName("DsmSuite.Analyzer.DotNet.Test.Data.GenericParameterTypeParameter");
Assert.IsNotNull(elementGenericParameterTypeParameter);

// Return types
IDsiElement elementReturnType = model.FindElementByName("DsmSuite.Analyzer.DotNet.Test.Data.ReturnType");
IDsiElement elementReturnType = model.FindElementByName("DsmSuite.Analyzer.DotNet.Test.Data.ReturnType");
Assert.IsNotNull(elementReturnType);

IDsiElement elementReturnEnum = model.FindElementByName("DsmSuite.Analyzer.DotNet.Test.Data.ReturnEnum");
IDsiElement elementReturnEnum = model.FindElementByName("DsmSuite.Analyzer.DotNet.Test.Data.ReturnEnum");
Assert.IsNotNull(elementReturnEnum);

IDsiElement elementGenericReturnType = model.FindElementByName("DsmSuite.Analyzer.DotNet.Test.Data.GenericReturnType`1");
IDsiElement elementGenericReturnType = model.FindElementByName("DsmSuite.Analyzer.DotNet.Test.Data.GenericReturnType`1");
Assert.IsNotNull(elementGenericReturnType);

IDsiElement elementGenericReturnTypeParameter = model.FindElementByName("DsmSuite.Analyzer.DotNet.Test.Data.GenericReturnTypeParameter");
IDsiElement elementGenericReturnTypeParameter = model.FindElementByName("DsmSuite.Analyzer.DotNet.Test.Data.GenericReturnTypeParameter");
Assert.IsNotNull(elementGenericReturnTypeParameter);

IDsiElement elementDelegateGenericParameter = model.FindElementByName("DsmSuite.Analyzer.DotNet.Test.Data.DelegateGenericParameter");
Assert.IsNotNull(elementDelegateGenericParameter);

IDsiElement elementEventsArgsGenericParameter = model.FindElementByName("DsmSuite.Analyzer.DotNet.Test.Data.EventsArgsGenericParameter");
IDsiElement elementEventsArgsGenericParameter = model.FindElementByName("DsmSuite.Analyzer.DotNet.Test.Data.EventsArgsGenericParameter");
Assert.IsNotNull(elementEventsArgsGenericParameter);

// Main relations
Assert.IsTrue(model.DoesRelationExist(elementMainClient.Id, elementMainType.Id));
Assert.IsTrue(model.DoesRelationExist(elementMainClient.Id, elementMainType.Id));
Assert.IsTrue(model.DoesRelationExist(elementMainClient.Id, elementEventsArgsGenericParameter.Id));

Assert.IsTrue(model.DoesRelationExist(elementMainType.Id, elementNestedType.Id));
Expand All @@ -116,15 +111,15 @@ public void TestAnalyze()
Assert.IsTrue(model.DoesRelationExist(elementMainTypeAnonymous.Id, elementDelegateGenericParameter.Id));
Assert.IsTrue(model.DoesRelationExist(elementMainTypeAnonymous.Id, elementDelegateGenericParameter.Id));

Assert.IsTrue(model.DoesRelationExist(elementMainType.Id, elementInterfaceA.Id));
Assert.IsTrue(model.DoesRelationExist(elementMainType.Id, elementBaseType.Id));
Assert.IsTrue(model.DoesRelationExist(elementMainType.Id, elementInterfaceA.Id));
Assert.IsTrue(model.DoesRelationExist(elementMainType.Id, elementBaseType.Id));

Assert.IsTrue(model.DoesRelationExist(elementMainType.Id, elementEventsArgsGenericParameter.Id));
Assert.IsTrue(model.DoesRelationExist(elementMainType.Id, elementDelegateGenericParameter.Id));

// Field relations
Assert.IsTrue(model.DoesRelationExist(elementMainType.Id, elementFieldType.Id));
Assert.IsTrue(model.DoesRelationExist(elementMainType.Id, elementGenericFieldType.Id));
Assert.IsTrue(model.DoesRelationExist(elementMainType.Id, elementFieldType.Id));
Assert.IsTrue(model.DoesRelationExist(elementMainType.Id, elementGenericFieldType.Id));

// Property relations
Assert.IsTrue(model.DoesRelationExist(elementMainType.Id, elementPropertyType.Id));
Expand Down Expand Up @@ -157,5 +152,109 @@ public void TestAnalyze()
Assert.IsTrue(model.DoesRelationExist(elementInterfaceA.Id, elementGenericReturnType.Id));
Assert.IsTrue(model.DoesRelationExist(elementInterfaceA.Id, elementGenericReturnTypeParameter.Id));
}

[TestMethod]
public void TestAnalyzeDirectory()
{
AnalyzerSettings analyzerSettings = AnalyzerSettings.CreateDefault();
analyzerSettings.Input.AssemblyDirectory = TestData.RootDirectory;
analyzerSettings.Transformation.IgnoredNames = new List<string>();

TestAnalyze(analyzerSettings);
}

[TestMethod]
public void TestAnalyzeDirectories()
{
AnalyzerSettings analyzerSettings = AnalyzerSettings.CreateDefault();
analyzerSettings.Input.AssemblyDirectories = new List<string> { TestData.RootDirectory };
analyzerSettings.Transformation.IgnoredNames = new List<string>();

TestAnalyze(analyzerSettings);
}

[TestMethod]
public void TestIncludeAssemblyNames()
{
IDsiModel model;
DotNet.Analysis.Analyzer analyzer;

AnalyzerSettings analyzerSettings = AnalyzerSettings.CreateDefault();
analyzerSettings.Input.AssemblyDirectories = new List<string> { TestData.RootDirectory };
analyzerSettings.Transformation.IgnoredNames = new List<string>();

analyzerSettings.Input.IncludeAssemblyNames = new List<string> { @".*" };
model = new DsiModel("Test", analyzerSettings.Transformation.IgnoredNames, Assembly.GetExecutingAssembly());
analyzer = new DotNet.Analysis.Analyzer(model, analyzerSettings, null);
analyzer.Analyze();
Assert.IsNotNull(model.FindElementByName("DsmSuite.Analyzer.DotNet.Test.Data.MainClient"));

analyzerSettings.Input.IncludeAssemblyNames = new List<string> { @"Model", @"Dot[Nn]et\.Test\.(Data)?" };
model = new DsiModel("Test", analyzerSettings.Transformation.IgnoredNames, Assembly.GetExecutingAssembly());
analyzer = new DotNet.Analysis.Analyzer(model, analyzerSettings, null);
analyzer.Analyze();
Assert.IsNotNull(model.FindElementByName("DsmSuite.Analyzer.DotNet.Test.Data.MainClient"));

analyzerSettings.Input.IncludeAssemblyNames = new List<string> { @"Model" };
model = new DsiModel("Test", analyzerSettings.Transformation.IgnoredNames, Assembly.GetExecutingAssembly());
analyzer = new DotNet.Analysis.Analyzer(model, analyzerSettings, null);
analyzer.Analyze();
Assert.IsNull(model.FindElementByName("DsmSuite.Analyzer.DotNet.Test.Data.MainClient"));
}

[TestMethod]
public void TestIncludedNames()
{
IDsiModel model;
DotNet.Analysis.Analyzer analyzer;

AnalyzerSettings analyzerSettings = AnalyzerSettings.CreateDefault();
analyzerSettings.Input.AssemblyDirectories = new List<string> { TestData.RootDirectory };
analyzerSettings.Transformation.IgnoredNames = new List<string>();

analyzerSettings.Transformation.IncludedNames = new List<string> { @"Model", @"Dot[Nn]et\.Test\.(Data)?.Main" };
model = new DsiModel("Test", analyzerSettings.Transformation.IgnoredNames, Assembly.GetExecutingAssembly());
analyzer = new DotNet.Analysis.Analyzer(model, analyzerSettings, null);
analyzer.Analyze();
Assert.IsNotNull(model.FindElementByName("DsmSuite.Analyzer.DotNet.Test.Data.MainClient"));
Assert.IsNull(model.FindElementByName("DsmSuite.Analyzer.DotNet.Test.Data.BaseType"));
}

[TestMethod]
public void TestIgnoredNames()
{
IDsiModel model;
DotNet.Analysis.Analyzer analyzer;

AnalyzerSettings analyzerSettings = AnalyzerSettings.CreateDefault();
analyzerSettings.Input.AssemblyDirectories = new List<string> { TestData.RootDirectory };
analyzerSettings.Transformation.IncludedNames = new List<string>();

analyzerSettings.Transformation.IgnoredNames = new List<string> { @"Model", @"/" };
model = new DsiModel("Test", analyzerSettings.Transformation.IgnoredNames, Assembly.GetExecutingAssembly());
analyzer = new DotNet.Analysis.Analyzer(model, analyzerSettings, null);
analyzer.Analyze();
Assert.IsNotNull(model.FindElementByName("DsmSuite.Analyzer.DotNet.Test.Data.MainClient"));
Assert.IsNotNull(model.FindElementByName("DsmSuite.Analyzer.DotNet.Test.Data.MainType"));
Assert.IsNull(model.FindElementByName("DsmSuite.Analyzer.DotNet.Test.Data.MainType/NestedType"));
}
[TestMethod]
public void TestIncludedIgnoredNames()
{
IDsiModel model;
DotNet.Analysis.Analyzer analyzer;

AnalyzerSettings analyzerSettings = AnalyzerSettings.CreateDefault();
analyzerSettings.Input.AssemblyDirectories = new List<string> { TestData.RootDirectory };
analyzerSettings.Transformation.IncludedNames = new List<string> { @"Main" };

analyzerSettings.Transformation.IgnoredNames = new List<string> { @"MainType$" };
model = new DsiModel("Test", analyzerSettings.Transformation.IgnoredNames, Assembly.GetExecutingAssembly());
analyzer = new DotNet.Analysis.Analyzer(model, analyzerSettings, null);
analyzer.Analyze();
Assert.IsNotNull(model.FindElementByName("DsmSuite.Analyzer.DotNet.Test.Data.MainClient"));
Assert.IsNull(model.FindElementByName("DsmSuite.Analyzer.DotNet.Test.Data.MainType"));
Assert.IsNotNull(model.FindElementByName("DsmSuite.Analyzer.DotNet.Test.Data.MainType/NestedType"));
}
}
}
7 changes: 3 additions & 4 deletions DsmSuite.Analyzer.DotNet/Analysis/Analyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ private void FindAssemblies()
{
//For every configured assembly directory lookup the files in the
//directory and process the content of the files
IList<string> assemblyFolders = _analyzerSettings.Input.AssemblyDirectories;
foreach (string assemblyFolder in assemblyFolders)
foreach (string assemblyFolder in _analyzerSettings.AssemblyDirectories())
{
Logger.LogUserMessage($"Assembly folder: {assemblyFolder}");
foreach (string assemblyFilename in Directory.EnumerateFiles(assemblyFolder))
Expand Down Expand Up @@ -82,12 +81,12 @@ private void FindRelations()

private bool Accept(string name)
{
/* Check wether the name meets the regex descriptions that have been configured.
/* Check whether the name meets the regex descriptions that have been configured.
* If no regex descriptions have been configured then the file is accepted.
*/
bool accept = false;

if (_analyzerSettings.Input.IncludeAssemblyNames.Count > 0)
if (_analyzerSettings.Input.IncludeAssemblyNames?.Count > 0)
{
string fileNameWithoutExtension = "";
try
Expand Down
3 changes: 1 addition & 2 deletions DsmSuite.Analyzer.DotNet/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ public ConsoleAction(AnalyzerSettings analyzerSettings) : base("Analyzing .Net c
protected override bool CheckPrecondition()
{
bool result = true;
IList<string> assemblyFolders = _analyzerSettings.Input.AssemblyDirectories;
foreach (string assemblyFolder in assemblyFolders)
foreach (string assemblyFolder in _analyzerSettings.AssemblyDirectories())
{
if (!Directory.Exists(assemblyFolder))
{
Expand Down
33 changes: 33 additions & 0 deletions DsmSuite.Analyzer.DotNet/Settings/AnalyzerSettings.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml;
using System.Xml.Serialization;
using DsmSuite.Common.Util;

namespace DsmSuite.Analyzer.DotNet.Settings
{
/// <summary>
/// InputSettings determine which assemblies are analyzed.<para/>
/// Either a single directory can be specified
/// in <c>AssemblyDirectory</c>, or multiple directories in <c>AssemblyDirectories</c>. Setting both
/// <c>AssemblyDirectory</c> and <c>AssemblyDirectories</c> leads to undefined behaviour.<para/>
/// If <c>IncludeAssemblyNames</c> is non-empty, an assembly is only analyzed if its <b>basename</b> contains
/// a match for a regex in <c>IncludeAssemblyNames</c>; otherwise all assemblies are analyzed.
/// Note that regex matching is case-sensitive.
/// </summary>
[Serializable]
public class InputSettings
{
Expand All @@ -17,6 +27,16 @@ public class InputSettings
public List<string> IncludeAssemblyNames { get; set; }
}

/// <summary>
/// TransformationSettings determine which symbols are included in the output model.<para/>
/// If <c>IncludedNames</c> is non-empty, symbols are only included if they contain a match for
/// a regex in this list. Otherwise all symbols are included.<para/>
/// If <c>IgnoredNames</c> is non-empty, symbols are not included if they contain a match for
/// a regex in this list. Otherwise all symbols are included.
/// IgnoredNames is evaluated after IncludedNames, so a symbol that matches both is ignored.<para/>
/// Note that regex matching is case-sensitive.
/// </summary>
/// todo Why both IgnoredNames and IncludedNames and why is one handled by DsiModel and the other by BinaryFile
[Serializable]
public class TransformationSettings
{
Expand All @@ -43,6 +63,17 @@ public class AnalyzerSettings
public TransformationSettings Transformation { get; set; }
public OutputSettings Output { get; set; }

/// <summary>
/// A convenience method that returns the configured assembly directory/ies.
/// </summary>
public IEnumerable<string> AssemblyDirectories()
{
if (Input.AssemblyDirectories?.Count > 0)
return Input.AssemblyDirectories;
else
return Enumerable.Repeat(Input.AssemblyDirectory, 1);
}

public static AnalyzerSettings CreateDefault()
{
AnalyzerSettings analyzerSettings = new AnalyzerSettings
Expand Down Expand Up @@ -100,6 +131,8 @@ public static AnalyzerSettings ReadFromFile(string filename)
private void ResolvePaths(string settingFilePath)
{
Input.AssemblyDirectory = FilePath.ResolveFile(settingFilePath, Input.AssemblyDirectory);
for (int i = 0; i < (Input.AssemblyDirectories?.Count ?? 0); i++)
Input.AssemblyDirectories[i] = FilePath.ResolveFile(settingFilePath, Input.AssemblyDirectories[i]);
Output.Filename = FilePath.ResolveFile(settingFilePath, Output.Filename);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Moq;
using System.Collections.Generic;
using DsmSuite.DsmViewer.Application.Actions.Element;
using System;

namespace DsmSuite.DsmViewer.Application.Test.Actions.Element
{
Expand Down Expand Up @@ -59,8 +60,8 @@ public void WhenUndoActionThenElementNameIsRevertedDataModel()
[TestMethod]
public void GivenLoadedActionWhenGettingDataThenActionAttributesMatch()
{
object[] args = { _model.Object, _data };
ElementChangeNameAction action = new ElementChangeNameAction(args);
object[] args = { _model.Object, null, _data };
ElementChangeNameAction action = Activator.CreateInstance(typeof(ElementChangeNameAction), args) as ElementChangeNameAction;

Assert.AreEqual(3, action.Data.Count);
Assert.AreEqual(ElementId.ToString(), _data["element"]);
Expand Down
Loading