Skip to content

Commit 2428465

Browse files
Suporting json config file and better ResultReport
1 parent c4b466b commit 2428465

10 files changed

+131
-65
lines changed

.gitignore

+40-17
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,32 @@
44
# User-specific files
55
*.suo
66
*.user
7+
*.userosscache
78
*.sln.docstates
89

10+
# User-specific files (MonoDevelop/Xamarin Studio)
11+
*.userprefs
12+
913
# Build results
1014
[Dd]ebug/
1115
[Dd]ebugPublic/
1216
[Rr]elease/
17+
[Rr]eleases/
1318
x64/
19+
x86/
1420
build/
1521
bld/
1622
[Bb]in/
1723
[Oo]bj/
1824

19-
# Roslyn cache directories
20-
*.ide/
25+
# Visual Studio 2015 cache/options directory
26+
.vs/
2127

2228
# MSTest test Results
2329
[Tt]est[Rr]esult*/
2430
[Bb]uild[Ll]og.*
2531

26-
#NUNIT
32+
# NUNIT
2733
*.VisualState.xml
2834
TestResult.xml
2935

@@ -32,6 +38,10 @@ TestResult.xml
3238
[Rr]eleasePS/
3339
dlldata.c
3440

41+
# DNX
42+
project.lock.json
43+
artifacts/
44+
3545
*_i.c
3646
*_p.c
3747
*_i.h
@@ -84,7 +94,7 @@ _ReSharper*/
8494
*.[Rr]e[Ss]harper
8595
*.DotSettings.user
8696

87-
# JustCode is a .NET coding addin-in
97+
# JustCode is a .NET coding add-in
8898
.JustCode
8999

90100
# TeamCity is a build add-in
@@ -128,17 +138,16 @@ publish/
128138
## passwords
129139
#*.pubxml
130140

131-
# NuGet Packages Directory
132-
packages/*
133-
## TODO: If the tool you use requires repositories.config
134-
## uncomment the next line
135-
#!packages/repositories.config
141+
*.publishproj
136142

137-
# Enable "build/" folder in the NuGet Packages folder since
138-
# NuGet packages use it for MSBuild targets.
139-
# This line needs to be after the ignore of the build folder
140-
# (and the packages folder if the line above has been uncommented)
141-
!packages/build/
143+
# NuGet Packages
144+
*.nupkg
145+
# The packages folder can be ignored because of Package Restore
146+
**/packages/*
147+
# except build/, which is used as an MSBuild target.
148+
!**/packages/build/
149+
# Uncomment if necessary however generally it will be regenerated when needed
150+
#!**/packages/repositories.config
142151

143152
# Windows Azure Build Output
144153
csx/
@@ -147,9 +156,13 @@ csx/
147156
# Windows Store app package directory
148157
AppPackages/
149158

159+
# Visual Studio cache files
160+
# files ending in .cache can be ignored
161+
*.[Cc]ache
162+
# but keep track of directories ending in .cache
163+
!*.[Cc]ache/
164+
150165
# Others
151-
sql/
152-
*.Cache
153166
ClientBin/
154167
[Ss]tyle[Cc]op.*
155168
~$*
@@ -159,6 +172,7 @@ ClientBin/
159172
*.pfx
160173
*.publishsettings
161174
node_modules/
175+
orleans.codegen.cs
162176

163177
# RIA/Silverlight projects
164178
Generated_Code/
@@ -183,7 +197,16 @@ UpgradeLog*.htm
183197
# Microsoft Fakes
184198
FakesAssemblies/
185199

200+
# Node.js Tools for Visual Studio
201+
.ntvs_analysis.dat
202+
203+
# Visual Studio 6 build log
204+
*.plg
205+
206+
# Visual Studio 6 workspace options file
207+
*.opt
208+
186209
# LightSwitch generated files
187210
GeneratedArtifacts/
188211
_Pvt_Extensions/
189-
ModelManifest.xml
212+
ModelManifest.xml

MetricsExtractor/Custom/TypeMetricWithNamespace.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public TypeMetricWithNamespace(ITypeMetric typeMetric)
4848

4949
public string Namespace { get; private set; }
5050

51-
public string FullName { get { return string.Format("{0}.{1}", Namespace, Name); } }
51+
public string FullName => $"{Namespace}.{Name}";
5252

5353
public ClassRank Rank { get; private set; }
5454

MetricsExtractor/MetodoRuim.cs

+25-6
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,33 @@ namespace MetricsExtractor
55
[Serializable]
66
public class MetodoRuim
77
{
8-
public string ClassName { get; set; }
8+
public MetodoRuim()
9+
{
10+
11+
}
912

10-
public string NomeMetodo { get; set; }
13+
public MetodoRuim(string className, string ns, string nomeMetodo, double manutenibilidade, double complexidade, double quantidadeDeLinhas)
14+
{
15+
ClassName = className;
16+
Namespace = ns;
17+
NomeMetodo = nomeMetodo;
18+
Manutenibilidade = manutenibilidade;
19+
Complexidade = complexidade;
20+
QuantidadeDeLinhas = quantidadeDeLinhas;
21+
}
1122

12-
public double Manutenibilidade { get; set; }
13-
14-
public double Complexidade { get; set; }
23+
public string FullClassName => $"{Namespace}.{ClassName}";
1524

16-
public double QuantidadeDeLinhas { get; set; }
25+
public string ClassName { get; }
26+
27+
public string Namespace { get; }
28+
29+
public string NomeMetodo { get; }
30+
31+
public double Manutenibilidade { get; }
32+
33+
public double Complexidade { get; }
34+
35+
public double QuantidadeDeLinhas { get; }
1736
}
1837
}

MetricsExtractor/MetricConfiguration.cs

+20-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System.Collections.Generic;
22
using System.Collections.Immutable;
3+
using System.IO;
34
using DocoptNet;
5+
using Newtonsoft.Json;
46
using static System.IO.Path;
57

68
namespace MetricsExtractor
@@ -12,17 +14,32 @@ public class MetricConfiguration
1214
public MetricConfiguration(IDictionary<string, ValueObject> arguments)
1315
{
1416
_arguments = arguments;
17+
if (!string.IsNullOrWhiteSpace(JsonConfigFile))
18+
{
19+
var converted = JsonConvert.DeserializeAnonymousType(File.ReadAllText(JsonConfigFile), new { IgnoredProjects, IgnoredNamespaces, IgnoredTypes });
20+
IgnoredProjects = converted.IgnoredProjects;
21+
IgnoredNamespaces = converted.IgnoredNamespaces;
22+
IgnoredTypes = converted.IgnoredTypes;
23+
}
24+
else
25+
{
26+
IgnoredProjects = GetImmutableArray("ignoredProjects");
27+
IgnoredNamespaces = GetImmutableArray("ignoredNamespaces");
28+
IgnoredTypes = GetImmutableArray("ignoredTypes");
29+
}
1530
}
1631

1732
public string Solution => _arguments["<solution>"].ToString();
1833

1934
public string SolutionDirectory => GetDirectoryName(Solution);
2035

21-
public ImmutableArray<string> IgnoredProjects => GetImmutableArray("ignoredProjects");
36+
public ImmutableArray<string> IgnoredProjects { get; }
2237

23-
public ImmutableArray<string> IgnoredNamespaces => GetImmutableArray("ignoredNamespaces");
38+
public ImmutableArray<string> IgnoredNamespaces { get; }
2439

25-
public ImmutableArray<string> IgnoredTypes => GetImmutableArray("ignoredTypes");
40+
public ImmutableArray<string> IgnoredTypes { get; }
41+
42+
public string JsonConfigFile => _arguments["<jsonfileconfig>"].ToString();
2643

2744
private ImmutableArray<string> GetImmutableArray(string key)
2845
=> _arguments[$"<{key}>"] != null

MetricsExtractor/MetricsExtractor.csproj

+4
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@
5757
<HintPath>..\packages\Microsoft.CodeAnalysis.Workspaces.Common.1.0.0\lib\net45\Microsoft.CodeAnalysis.Workspaces.Desktop.dll</HintPath>
5858
<Private>True</Private>
5959
</Reference>
60+
<Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
61+
<HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
62+
<Private>True</Private>
63+
</Reference>
6064
<Reference Include="RazorEngine">
6165
<HintPath>..\packages\RazorEngine.3.4.2\lib\net45\RazorEngine.dll</HintPath>
6266
</Reference>

MetricsExtractor/Program.cs

+4-11
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using System.IO;
77
using System.IO.Compression;
88
using System.Linq;
9-
using System.Runtime.InteropServices;
109
using System.Text;
1110
using System.Threading.Tasks;
1211
using System.Xml.Serialization;
@@ -33,12 +32,14 @@ class Program
3332
MetricsExtractor.exe -s <solution> [-in <ignoredNamespaces>]
3433
MetricsExtractor.exe -s <solution> [-it <ignoredTypes>]
3534
MetricsExtractor.exe -s <solution> [-ip <ignoredProjects>] [-in <ignoredNamespaces>] [-it <ignoredTypes>]
35+
MetricsExtractor.exe -s <solution> [-jsonconfig <jsonfileconfig>]
3636
3737
Options:
3838
-s --solution Load projects from solution.
3939
-ip <ignoredProjects> --ignoredprojects <ignoredProjects> Projets in solution that you want to ignore, split them by "";""
4040
-in <ignoredNamespaces> --ignorednamespaces <ignoredNamespaces> Namespaces in your application that you want to ignore, split them by "";""
4141
-it <ignoredTypes> --ignoredtypes <ignoredTypes> Types in your application that you want to ignore, split them by "";""
42+
-jsonconfig <jsonfileconfig> User a json file to configure metrics extraction "";""
4243
4344
";
4445
private static readonly List<ClassRank> ClassRanks = Enum.GetValues(typeof(ClassRank)).Cast<ClassRank>().ToList();
@@ -153,19 +154,11 @@ private static EstadoDoProjeto CreateEstadoDoProjeto(List<TypeMetricWithNamespac
153154

154155
private static List<MetodoRuim> GetMetodosRuins(List<MetodoComTipo> metodos, int maxLinesOfCodeOnMethod)
155156
{
156-
var metodosRuins = metodos
157+
return metodos
157158
.Where(x => (x.Metodo.SourceLinesOfCode >= maxLinesOfCodeOnMethod) || (x.Metodo.CyclomaticComplexity >= 10))
158-
.Select(x => new MetodoRuim
159-
{
160-
ClassName = x.Tipo.FullName,
161-
NomeMetodo = x.Metodo.Name,
162-
Complexidade = x.Metodo.CyclomaticComplexity,
163-
Manutenibilidade = x.Metodo.MaintainabilityIndex,
164-
QuantidadeDeLinhas = x.Metodo.SourceLinesOfCode,
165-
})
159+
.Select(x => new MetodoRuim(x.Tipo.Name, x.Tipo.Namespace, x.Metodo.Name, x.Metodo.MaintainabilityIndex, x.Metodo.CyclomaticComplexity, x.Metodo.SourceLinesOfCode))
166160
.OrderByDescending(x => x.QuantidadeDeLinhas).ThenByDescending(x => x.Complexidade)
167161
.ToList();
168-
return metodosRuins;
169162
}
170163

171164
private static async Task<IEnumerable<INamespaceMetric>> RunCodeMetrics(MetricConfiguration configuration)

MetricsExtractor/ReportTemplate/Index.cshtml

+31-11
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
1111
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap-theme.min.css">
1212
<link rel="stylesheet" type="text/css" href="site.css">
13+
<style>
14+
div.tooltip-inner {
15+
max-width: 700px;
16+
}
17+
</style>
1318
<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
1419
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
1520
</head>
@@ -86,8 +91,7 @@
8691
<table class="table table-striped table-hover ">
8792
<thead>
8893
<tr>
89-
<th>Classe</th>
90-
<th>Nome do método</th>
94+
<th>Classe/Nome do método</th>
9195
<th>SLOC <span class="glyphicon glyphicon-exclamation-sign cor-azul" data-original-title="Linhas de Código(Source Lines Of Code)" data-toggle="tooltip" aria-hidden="true"></span></th>
9296
<th>Comp. Ciclomática</th>
9397
<th>Manutenibilidade</th>
@@ -97,8 +101,7 @@
97101
@foreach (MetodoRuim metodoRuim in md.MetodosRuins)
98102
{
99103
<tr>
100-
<td>@metodoRuim.ClassName</td>
101-
<td>@metodoRuim.NomeMetodo</td>
104+
<td>@(metodoRuim.ClassName + "." + metodoRuim.NomeMetodo) <span class="glyphicon glyphicon-exclamation-sign cor-azul" data-original-title="@(metodoRuim.FullClassName + "." + metodoRuim.NomeMetodo)" data-toggle="tooltip" aria-hidden="true"></span></td>
102105
<td>@metodoRuim.QuantidadeDeLinhas</td>
103106
<td>@metodoRuim.Complexidade</td>
104107
<td>@metodoRuim.Manutenibilidade.ToString("N0")</td>
@@ -122,12 +125,29 @@
122125
</div>
123126
<div id="collapse@(type.Key)" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading@(type.Key)" aria-expanded="false">
124127
<div class="panel-body">
125-
<ul>
126-
@foreach (var typeWithMetric in type.Value)
127-
{
128-
<li>@typeWithMetric.FullName</li>
129-
}
130-
</ul>
128+
<table class="table table-striped table-hover table-bordered">
129+
<thead>
130+
<tr>
131+
<th>Classe</th>
132+
<th>Manutenibilidade <span class="glyphicon glyphicon-exclamation-sign cor-azul" data-original-title="Número de 0-100" data-toggle="tooltip" aria-hidden="true"></span></th>
133+
<th>Comp. Ciclomática <span class="glyphicon glyphicon-exclamation-sign cor-azul" data-original-title="Complexidade ciclomática" data-toggle="tooltip" aria-hidden="true"></span></th>
134+
<th>Profundidade de Herança</th>
135+
<th>Linhas de código</th>
136+
</tr>
137+
</thead>
138+
<tbody>
139+
@foreach (var typeWithMetric in type.Value)
140+
{
141+
<tr>
142+
<td>@typeWithMetric.Name <span class="glyphicon glyphicon-exclamation-sign cor-azul" data-original-title="@typeWithMetric.FullName" data-toggle="tooltip" aria-hidden="true"></td>
143+
<td>@typeWithMetric.MaintainabilityIndex.ToString("0")</td>
144+
<td>@typeWithMetric.CyclomaticComplexity</td>
145+
<td>@typeWithMetric.DepthOfInheritance</td>
146+
<td>@typeWithMetric.SourceLinesOfCode</td>
147+
</tr>
148+
}
149+
</tbody>
150+
</table>
131151
</div>
132152
</div>
133153
</div>
@@ -137,7 +157,7 @@
137157
</div>
138158
<script type="text/javascript">
139159
$(function () {
140-
$('[data-toggle="tooltip"]').tooltip();
160+
$('[data-toggle="tooltip"]').tooltip({ trigger: "click" });
141161
$(".progress-bar-success").css("width", "@(md.Manutenibilidade)%");
142162
});
143163
</script>

MetricsExtractor/ReportTemplate/ReportTemplateFactory.cs

-13
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,8 @@ public class ReportTemplateFactory
88
{
99
public string GetReport(EstadoDoProjeto estadoDoProjeto)
1010
{
11-
// Generate the email body from the template file.
1211
var templateFolderPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ReportTemplate");
1312
var templateFilePath = Path.Combine(templateFolderPath, "Index.cshtml");
14-
/*
15-
var templateConfig = new TemplateServiceConfiguration
16-
{
17-
Resolver = new DelegateTemplateResolver(name =>
18-
{
19-
//no caching cause RazorEngine handles that itself
20-
var templatePath = Path.Combine(templateFolderPath, name);
21-
using (var reader = new StreamReader(templatePath)) // let it throw if doesn't exist
22-
return reader.ReadToEnd();
23-
})
24-
};
25-
*/
2613
var service = new TemplateService(/*templateConfig*/);
2714
RazorEngine.Razor.SetTemplateService(service);
2815
var emailHtmlBody = service.Parse(File.ReadAllText(templateFilePath), estadoDoProjeto, null, null);

MetricsExtractor/packages.config

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<package id="Microsoft.CodeAnalysis.CSharp.Workspaces" version="1.0.0" targetFramework="net451" />
99
<package id="Microsoft.CodeAnalysis.Workspaces.Common" version="1.0.0" targetFramework="net451" />
1010
<package id="Microsoft.Composition" version="1.0.30" targetFramework="net45" />
11+
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net452" />
1112
<package id="RazorEngine" version="3.4.2" targetFramework="net45" />
1213
<package id="System.Collections.Immutable" version="1.1.36" targetFramework="net451" />
1314
<package id="System.Reflection.Metadata" version="1.0.21" targetFramework="net451" />

0 commit comments

Comments
 (0)