• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

samsmithnz / DotNetCensus / 4773330594

pending completion
4773330594

Pull #90

github

GitHub
Merge 6991c8b68 into 0b3e1d200
Pull Request #90: Code gardening

444 of 486 branches covered (91.36%)

Branch coverage included in aggregate %.

75 of 75 new or added lines in 9 files covered. (100.0%)

912 of 959 relevant lines covered (95.1%)

934.72 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.19
/src/DotNetCensus.Core/Projects/ProjectClassification.cs
1
using System.Text;
2

3
namespace DotNetCensus.Core.Projects;
4

5
public static class ProjectClassification
6
{
7
    public static bool IsProjectFile(string fileName, bool primaryScan = true)
8
    {
12,357✔
9
        if (primaryScan)
12,357✔
10
        {
7,882✔
11
            switch (new FileInfo(fileName).Extension.ToLower())
7,882✔
12
            {
13
                case ".csproj":
14
                case ".sqlproj":
15
                case ".vbproj":
16
                case ".fsproj":
17
                case ".vbp":
18
                    return true;
875✔
19
            }
20
        }
7,007✔
21
        else
22
        {
4,475✔
23
            switch (fileName.ToLower())
4,475✔
24
            {
25
                case "project.json":
26
                case "web.config":
27
                    //case "directory.build.props":
28
                    return true;
66✔
29
            }
30
        }
4,409✔
31
        return false;
11,416✔
32
    }
12,357✔
33

34
    public static string GetFrameworkFamily(string frameworkCode)
35
    {
1,292✔
36
        if (string.IsNullOrEmpty(frameworkCode))
1,292✔
37
        {
58✔
38
            return "(Unknown)";
58✔
39
        }
40
        else if (frameworkCode.StartsWith("netstandard"))
1,234✔
41
        {
90✔
42
            return ".NET Standard";
90✔
43
        }
44
        else if (frameworkCode.StartsWith("v1.") ||
1,144✔
45
                 frameworkCode.StartsWith("v2.") ||
1,144✔
46
                 frameworkCode.StartsWith("v3.") ||
1,144✔
47
                 frameworkCode.StartsWith("v4.") ||
1,144✔
48
                 frameworkCode.StartsWith("net4") ||
1,144✔
49
                 frameworkCode.StartsWith("Unity"))
1,144✔
50
        {
359✔
51
            return ".NET Framework";
359✔
52
        }
53
        else if (frameworkCode.StartsWith("netcoreapp"))
785✔
54
        {
265✔
55
            return ".NET Core";
265✔
56
        }
57
        else if (frameworkCode.StartsWith("net")) //net5.0, net6.0, etc)
520✔
58
        {
484✔
59
            return ".NET";
484✔
60
        }
61
        else if (frameworkCode.StartsWith("vb6"))
36✔
62
        {
31✔
63
            return "Visual Basic 6";
31✔
64
        }
65
        else
66
        {
5✔
67
            return "(Unknown)";
5✔
68
        }
69
    }
1,292✔
70

71
    public static string GetFriendlyName(string frameworkCode, string family)
72
    {
781✔
73

74
        if (string.IsNullOrEmpty(frameworkCode))
781✔
75
        {
35✔
76
            return "(Unknown)";
35✔
77
        }
78
        else if (frameworkCode.StartsWith("netstandard"))
746✔
79
        {
54✔
80
            return family + " " + frameworkCode.Replace("netstandard", "");
54✔
81
        }
82
        else if (frameworkCode.StartsWith("v1.") ||
692✔
83
                 frameworkCode.StartsWith("v2.") ||
692✔
84
                 frameworkCode.StartsWith("v3.") ||
692✔
85
                 frameworkCode.StartsWith("v4."))
692✔
86
        {
166✔
87
            //Drop the v from the version string. (e.g. v3.0 becomes 3.0)
88
            return family + " " + frameworkCode.Replace("v", "");
166✔
89
        }
90
        else if (frameworkCode.StartsWith("net4"))
526✔
91
        {
51✔
92
            string number = frameworkCode.Replace("net", "");
51✔
93
            StringBuilder formattedNumber = new();
51✔
94
            //Add .'s between each number. Gross. (e.g. net462 becomes 4.6.2)
95
            for (int i = 0; i < number.Length; i++)
404✔
96
            {
151✔
97
                formattedNumber.Append(number[i]);
151✔
98
                if (i < number.Length - 1)
151✔
99
                {
100✔
100
                    formattedNumber.Append('.');
100✔
101
                }
100✔
102
            }
151✔
103
            return family + " " + formattedNumber;
51!
104
        }
105
        else if (frameworkCode.StartsWith("netcoreapp"))
475✔
106
        {
162✔
107
            return family + " " + frameworkCode.Replace("netcoreapp", "");
162✔
108
        }
109
        else if (frameworkCode.StartsWith("net")) //net5.0, net6.0, etc)
313✔
110
        {
293✔
111
            return family + " " + frameworkCode.Replace("net", "");
293✔
112
        }
113
        else if (frameworkCode.StartsWith("vb6"))
20✔
114
        {
18✔
115
            return "Visual Basic 6";
18✔
116
        }
117
        else
118
        {
2✔
119
            return "(Unknown)";
2✔
120
        }
121
    }
781✔
122

123
    public static string GetHistoricalFrameworkVersion(string line)
124
    {
112✔
125
        string productVersion = line.Replace("<ProductVersion>", "").Replace("</ProductVersion>", "").Replace("ProductVersion = ", "").Replace("\"", "").Trim();
112✔
126
        //https://en.wikipedia.org/wiki/Microsoft_Visual_Studio#History
127
        //+---------------------------+---------------+-----------+----------------+
128
        //|       Product name        |   Codename    | Version # | .NET Framework | 
129
        //+---------------------------+---------------+-----------+----------------+
130
        //| Visual Studio .NET (2002) | Rainier       | 7.0.*     | 1              |
131
        //| Visual Studio .NET 2003   | Everett       | 7.1.*     | 1.1            |
132
        //| Visual Studio 2005        | Whidbey       | 8.0.*     | 2.0, 3.0       |
133
        //| Visual Studio 2008        | Orcas         | 9.0.*     | 2.0, 3.0, 3.5  |
134
        //| Visual Studio 2010        | Dev10/Rosario | 10.0.*    | 2.0 – 4.0      |
135
        //| Visual Studio 2012        | Dev11         | 11.0.*    | 2.0 – 4.5.2    |
136
        //| Visual Studio 2013        | Dev12         | 12.0.*    | 2.0 – 4.5.2    |
137
        //| Visual Studio 2015        | Dev14         | 14.0.*    | 2.0 – 4.6      |
138
        //+---------------------------+---------------+-----------+----------------+
139

140
        //Only process the earliest Visual Studio's, as the later versions should be picked up by the product version
141
        //Note that this may not be entirely accurate - for example, VS2008 could ignore a .NET 3 version, but these should be pretty rare - even if it misidentifies .NET framework 1/2/3 - the story is the same - these are wildly obsolete and need to be resolved.
142
        if (productVersion.StartsWith("7.0"))
112✔
143
        {
16✔
144
            return "v1.0";
16✔
145
        }
146
        else if (productVersion.StartsWith("7.1"))
96✔
147
        {
16✔
148
            return "v1.1";
16✔
149
        }
150
        else if (productVersion.StartsWith("8.0"))
80✔
151
        {
48✔
152
            return "v2.0";
48✔
153
        }
154
        else
155
        {
32✔
156
            return "";
32✔
157
        }
158
    }
112✔
159

160
    //public static string GetUnityFrameworkVersion(string line)
161
    //{
162
    //    //An example of what to expect:
163
    //    //m_EditorVersion: 2020.3.12f1
164
    //    //m_EditorVersionWithRevision: 2020.3.12f1(b3b2c6512326)
165
    //    string fullVersion = line.Replace("m_EditorVersion:", "").Trim();
166
    //    string[] splitVersion = fullVersion.Split('.');
167
    //    string unityVersion = "";
168
    //    if (splitVersion.Length >= 2)
169
    //    {
170
    //        unityVersion = "Unity3d v" + splitVersion[0] + "." + splitVersion[1];
171
    //    }
172

173
    //    return unityVersion;
174
    //}
175

176
    // get a color to represent the support. Kinda rough for now, but highlights really old versions.
177
    public static string? GetStatus(string? framework)
178
    {
1,043✔
179
        if (framework == null)
1,043!
180
        {
×
181
            //Unknown/gray
182
            return "unknown";
×
183
        }
184
        else if (framework == "vb6" ||
1,043✔
185
            framework.Contains("v1") ||
1,043✔
186
            framework.Contains("v2") ||
1,043✔
187
            framework.Contains("v3.0") ||
1,043✔
188
            framework.Contains("v4.0") ||
1,043✔
189
            framework.Contains("v4.1") ||
1,043✔
190
            framework.Contains("v4.2") ||
1,043✔
191
            framework.Contains("v4.3") ||
1,043✔
192
            framework.Contains("v4.4") ||
1,043✔
193
            framework.Contains("v4.5") ||
1,043✔
194
            framework == "v4.6" || //Unclear if this should be net46 or v4.6 - I've seen both in wild
1,043✔
195
            framework == "v4.6.1" || //Unclear if this should be net461 or v4.6.1 - I've seen both in wild
1,043✔
196
            framework == "net45" || //Unclear if this should be net45 or v4.5 - I've seen both in wild
1,043✔
197
            framework == "net46" ||
1,043✔
198
            framework == "net461" ||
1,043✔
199
            framework.Contains("netcoreapp1") ||
1,043✔
200
            framework.Contains("netcoreapp2") ||
1,043✔
201
            framework.Contains("netcoreapp3") ||
1,043✔
202
            framework.Contains("netcoreapp5") || //details about netcoreapp5 are unclear, but this scenario was mentioned as supported here: https://github.com/dotnet/designs/blob/main/accepted/2020/net5/net5.md
1,043✔
203
            framework.Contains("net5.0"))
1,043✔
204
        {
466✔
205
            //Unsupported/End of life/red
206
            return "deprecated";
466✔
207
        }
208
        else if (framework.Contains("v3.5"))
577✔
209
        {
43✔
210
            //Supported, but old/orange
211
            return "EOL: 9-Jan-2029";
43✔
212
        }
213
        else if (framework.Contains("net6.0") ||
534✔
214
            framework.Contains("net7.0") ||
534✔
215
            framework.Contains("netstandard") ||
534✔
216
            framework == "net462" ||
534✔
217
            framework == "v4.6.2" ||
534✔
218
            framework.Contains("net47") ||
534✔
219
            framework.Contains("v4.7") ||
534✔
220
            framework.Contains("net48") ||
534✔
221
            framework.Contains("v4.8"))
534✔
222
        {
396✔
223
            //Supported/Ok/blue
224
            return "supported";
396✔
225
        }
226
        else if (framework.Contains("net8.0"))
138✔
227
        {
94✔
228
            return "in preview";
94✔
229
        }
230
        else
231
        {
44✔
232
            //Unknown/gray
233
            return "unknown";
44✔
234
        }
235
    }
1,043✔
236

237
    public static string GetLanguage(string directory)
238
    {
48✔
239
        //Check to see if it's a VB.NET or C# project
240
        int csFiles = new DirectoryInfo(directory).GetFiles("*.cs", SearchOption.AllDirectories).Length;
48✔
241
        int vbFiles = new DirectoryInfo(directory).GetFiles("*.vb", SearchOption.AllDirectories).Length;
48✔
242
        string language;
243
        if (csFiles >= vbFiles)
48!
244
        {
48✔
245
            language = "csharp";
48✔
246
        }
48✔
247
        else
248
        {
×
249
            language = "vb.net";
×
250
        }
×
251
        return language;
48✔
252
    }
48✔
253
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc