Skip to content

Commit 5fa8c18

Browse files
jpobstjonpryor
authored andcommitted
[Java.Interop] Replace Gendarme with Roslyn FxCop Analyzers (#523)
We used [Gendarme][0] for static code analysis on `Java.Interop.dll`; see 6ec5995. Unfortunately, Gendarme is dated and additionally requires on `.mdb` files for analysis to provide filename and line number information. Generation of `.mdb` files in turn requires compiling with `mcs`, which is (1) deprecated, and (2) does not support current C# features like [nullable reference types][1]. Replaces Gendarme usage with [Roslyn FxCop Analyzers][2], which get around the above issues, as well as provide additional benefits: * They run on every compile, so they will be seen as part of the normal development workflow instead of as a separate step. * They do source code analysis instead of binary analysis, which allows them to catch more issues. Roslyn Analyzers rely on the following two files: * [`src/Java.Interop/.editorconfig`][3], which controls the severity of Roslyn Analyzer rules. This is currently set up to mimic the previous Gendarme rules. * `src/Java.Interop/GlobalSuppressions.cs`, which uses the [`System.Diagnostics.CodeAnalysis.SuppressMessageAttribute`][4] assembly-level custom attribute to ignore some instances of rule violations. Visual Studio has a [**Suppress** > **In Suppression File**][5] context menu which will update `GlobalSuppressions.cs` to ignore a particular rule violation. In general, the `[SuppressMessageAttribute]` syntax is pretty similar to the previously used Gendarme syntax. [0]: https://www.mono-project.com/docs/tools+libraries/tools/gendarme/ [1]: https://docs.microsoft.com/en-us/dotnet/csharp/nullable-references [2]: https://docs.microsoft.com/en-us/visualstudio/code-quality/roslyn-analyzers-overview [3]: https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference?view=vs-2019 [4]: https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.codeanalysis.suppressmessageattribute [5]: https://docs.microsoft.com/en-us/visualstudio/code-quality/use-roslyn-analyzers?view=vs-2019#suppress-violations
1 parent 7558ca1 commit 5fa8c18

24 files changed

+298
-776
lines changed

Makefile

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ NATIVE_EXT = .so
1212
DLLMAP_OS_NAME = linux
1313
endif
1414

15-
GENDARME_URL = https://github.com/downloads/spouliot/gendarme/gendarme-2.10-bin.zip
16-
1715
PACKAGES = \
1816
packages/NUnit.3.11.0/NUnit.3.11.0.nupkg \
1917
packages/NUnit.Console.3.9.0/NUnit.Console.3.9.0.nupkg
@@ -95,15 +93,6 @@ src/Java.Runtime.Environment/Java.Runtime.Environment.dll.config: src/Java.Runti
9593
bin/Build$(CONFIGURATION)/JdkInfo.props
9694
sed -e 's#@JI_JVM_PATH@#$(JI_JVM_PATH)#g' -e 's#@OS_NAME@#$(DLLMAP_OS_NAME)#g' -e $(JAVA_RUNTIME_ENVIRONMENT_DLLMAP_OVERRIDE_CMD) < $< > $@
9795

98-
fxcop: lib/gendarme-2.10/gendarme.exe bin/GendarmeDebug/netstandard2.0/Java.Interop.dll
99-
cp src/Java.Interop/obj/Gendarme/netstandard2.0/Java.Interop.dll.mdb bin/GendarmeDebug/netstandard2.0
100-
$(RUNTIME) $< --html gendarme.html $(if @(GENDARME_XML),--xml gendarme.xml) --ignore gendarme-ignore.txt bin/GendarmeDebug/netstandard2.0/Java.Interop.dll
101-
102-
lib/gendarme-2.10/gendarme.exe:
103-
-mkdir -p `dirname "$@"`
104-
curl -L -o lib/gendarme-2.10/gendarme-2.10-bin.zip $(GENDARME_URL)
105-
(cd lib/gendarme-2.10 ; unzip gendarme-2.10-bin.zip)
106-
10796
JAVA_INTEROP_LIB = libjava-interop$(NATIVE_EXT)
10897
NATIVE_TIMING_LIB = libNativeTiming$(NATIVE_EXT)
10998

@@ -134,9 +123,6 @@ bin/Test$(CONFIGURATION)/Android.Interop-Tests.dll: $(wildcard src/Android.Inter
134123
bin/$(CONFIGURATION)/Java.Interop.dll: $(wildcard src/Java.Interop/*/*.cs) src/Java.Interop/Java.Interop.csproj
135124
$(MSBUILD) $(if $(V),/v:diag,) /p:Configuration=$(CONFIGURATION) $(if $(SNK),"/p:AssemblyOriginatorKeyFile=$(SNK)",)
136125

137-
bin/GendarmeDebug/netstandard2.0/Java.Interop.dll: $(wildcard src/Java.Interop/*/*.cs) src/Java.Interop/Java.Interop.csproj
138-
$(MSBUILD) $(if $(V),/v:diag,) /p:Configuration="Gendarme" $(if $(SNK),"/p:AssemblyOriginatorKeyFile=$(SNK)",) /p:CscToolExe=`which mcs` /p:LangVersion=Default /p:DiscoverEditorConfigFiles=False src/Java.Interop/Java.Interop.csproj
139-
140126
CSHARP_REFS = \
141127
bin/$(CONFIGURATION)/Java.Interop.dll \
142128
bin/$(CONFIGURATION)/Java.Interop.Export.dll \

build-tools/automation/azure-pipelines.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,6 @@ jobs:
8080
- script: make all CONFIGURATION=$(Build.Configuration)
8181
displayName: make all
8282

83-
- script: make fxcop
84-
displayName: Run Gendarme
85-
8683
- script: |
8784
r=0
8885
make run-all-tests CONFIGURATION=$(Build.Configuration) || r=$?
@@ -103,7 +100,6 @@ jobs:
103100
inputs:
104101
SourceFolder: $(System.DefaultWorkingDirectory)
105102
Contents: |
106-
gendarme.*
107103
xatb.jar
108104
bin.zip
109105
TargetFolder: $(Build.ArtifactStagingDirectory)

gendarme-ignore.txt

Lines changed: 0 additions & 704 deletions
This file was deleted.

src/Java.Interop/.editorconfig

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
# This files sets all rules from Gendarme as Code Analysis errors
2+
# via: https://github.com/spouliot/gendarme/wiki/GendarmeToFxCop(git)
3+
4+
[*.cs]
5+
dotnet_diagnostic.CA2001.severity = error
6+
dotnet_diagnostic.CA2214.severity = error
7+
dotnet_diagnostic.CA2222.severity = error
8+
dotnet_diagnostic.CA1065.severity = error
9+
dotnet_diagnostic.CA1041.severity = error
10+
dotnet_diagnostic.CA2230.severity = error
11+
dotnet_diagnostic.CA2006.severity = error
12+
dotnet_diagnostic.CA2002.severity = error
13+
dotnet_diagnostic.CA2211.severity = error
14+
dotnet_diagnostic.CA2243.severity = error
15+
dotnet_diagnostic.CA1053.severity = error
16+
# dotnet_diagnostic.CA1062.severity = error CheckParametersNullityInVisibleMethodsRule - We'll use NRT instead
17+
dotnet_diagnostic.CA2213.severity = error
18+
dotnet_diagnostic.CA2242.severity = error
19+
dotnet_diagnostic.CA2000.severity = error
20+
dotnet_diagnostic.CA2220.severity = error
21+
dotnet_diagnostic.CA1822.severity = error
22+
dotnet_diagnostic.CA2241.severity = error
23+
dotnet_diagnostic.CA1012.severity = error
24+
dotnet_diagnostic.CA1019.severity = error
25+
dotnet_diagnostic.CA1040.severity = error
26+
dotnet_diagnostic.CA1023.severity = error
27+
dotnet_diagnostic.CA1044.severity = error
28+
dotnet_diagnostic.CA1021.severity = error
29+
dotnet_diagnostic.CA1045.severity = error
30+
dotnet_diagnostic.CA1020.severity = error
31+
dotnet_diagnostic.CA1051.severity = error
32+
dotnet_diagnostic.CA1034.severity = error
33+
dotnet_diagnostic.CA1024.severity = error
34+
dotnet_diagnostic.CA1052.severity = error
35+
dotnet_diagnostic.CA1009.severity = error
36+
dotnet_diagnostic.CA2216.severity = error
37+
dotnet_diagnostic.CA1047.severity = error
38+
dotnet_diagnostic.CA2227.severity = error
39+
dotnet_diagnostic.CA1048.severity = error
40+
dotnet_diagnostic.CA2226.severity = error
41+
dotnet_diagnostic.CA1038.severity = error
42+
dotnet_diagnostic.CA1008.severity = error
43+
dotnet_diagnostic.CA1028.severity = error
44+
dotnet_diagnostic.CA2221.severity = error
45+
dotnet_diagnostic.CA2218.severity = error
46+
dotnet_diagnostic.CA1036.severity = error
47+
dotnet_diagnostic.CA1039.severity = error
48+
dotnet_diagnostic.CA1016.severity = error
49+
dotnet_diagnostic.CA1014.severity = error
50+
dotnet_diagnostic.CA1017.severity = error
51+
dotnet_diagnostic.CA1018.severity = error
52+
dotnet_diagnostic.CA1013.severity = error
53+
dotnet_diagnostic.CA2231.severity = error
54+
dotnet_diagnostic.CA2224.severity = error
55+
dotnet_diagnostic.CA1030.severity = error
56+
dotnet_diagnostic.CA1043.severity = error
57+
dotnet_diagnostic.CA1054.severity = error
58+
dotnet_diagnostic.CA1055.severity = error
59+
dotnet_diagnostic.CA1056.severity = error
60+
dotnet_diagnostic.CA1059.severity = error
61+
dotnet_diagnostic.CA2225.severity = error
62+
dotnet_diagnostic.CA1035.severity = error
63+
dotnet_diagnostic.CA1050.severity = error
64+
dotnet_diagnostic.CA1001.severity = error
65+
dotnet_diagnostic.CA1049.severity = error
66+
dotnet_diagnostic.CA1027.severity = error
67+
dotnet_diagnostic.CA1005.severity = error
68+
dotnet_diagnostic.CA1004.severity = error
69+
dotnet_diagnostic.CA1000.severity = error
70+
dotnet_diagnostic.CA1002.severity = error
71+
dotnet_diagnostic.CA1006.severity = error
72+
dotnet_diagnostic.CA1010.severity = error
73+
dotnet_diagnostic.CA1007.severity = error
74+
dotnet_diagnostic.CA1003.severity = error
75+
dotnet_diagnostic.CA2201.severity = error
76+
dotnet_diagnostic.CA2200.severity = error
77+
dotnet_diagnostic.CA1031.severity = error
78+
dotnet_diagnostic.CA2219.severity = error
79+
dotnet_diagnostic.CA1065.severity = error
80+
dotnet_diagnostic.CA2201.severity = error
81+
dotnet_diagnostic.CA1064.severity = error
82+
dotnet_diagnostic.CA2208.severity = error
83+
dotnet_diagnostic.CA1032.severity = error
84+
dotnet_diagnostic.CA1060.severity = error
85+
dotnet_diagnostic.CA1404.severity = error
86+
dotnet_diagnostic.CA1414.severity = error
87+
dotnet_diagnostic.CA2101.severity = error
88+
dotnet_diagnostic.CA1401.severity = error
89+
dotnet_diagnostic.CA2205.severity = error
90+
dotnet_diagnostic.CA1403.severity = error
91+
dotnet_diagnostic.CA1406.severity = error
92+
dotnet_diagnostic.CA1413.severity = error
93+
dotnet_diagnostic.CA1402.severity = error
94+
dotnet_diagnostic.CA1407.severity = error
95+
dotnet_diagnostic.CA1405.severity = error
96+
dotnet_diagnostic.CA1409.severity = error
97+
dotnet_diagnostic.CA1408.severity = error
98+
dotnet_diagnostic.CA1412.severity = error
99+
dotnet_diagnostic.CA1410.severity = error
100+
dotnet_diagnostic.CA1411.severity = error
101+
dotnet_diagnostic.CA1502.severity = error
102+
dotnet_diagnostic.CA1501.severity = error
103+
dotnet_diagnostic.CA1011.severity = error
104+
dotnet_diagnostic.CA1504.severity = error
105+
dotnet_diagnostic.CA1500.severity = error
106+
dotnet_diagnostic.CA1707.severity = error
107+
dotnet_diagnostic.CA1724.severity = error
108+
dotnet_diagnostic.CA1713.severity = error
109+
dotnet_diagnostic.CA1712.severity = error
110+
dotnet_diagnostic.CA1700.severity = error
111+
dotnet_diagnostic.CA1725.severity = error
112+
dotnet_diagnostic.CA1709.severity = error
113+
dotnet_diagnostic.CA1715.severity = error
114+
dotnet_diagnostic.CA1722.severity = error
115+
dotnet_diagnostic.CA1710.severity = error
116+
dotnet_diagnostic.CA1711.severity = error
117+
dotnet_diagnostic.CA1714.severity = error
118+
dotnet_diagnostic.CA1726.severity = error
119+
dotnet_diagnostic.CA1809.severity = error
120+
dotnet_diagnostic.CA1800.severity = error
121+
dotnet_diagnostic.CA1819.severity = error
122+
dotnet_diagnostic.CA1811.severity = error
123+
dotnet_diagnostic.CA1812.severity = error
124+
dotnet_diagnostic.CA1805.severity = error
125+
dotnet_diagnostic.CA1813.severity = error
126+
dotnet_diagnostic.CA1801.severity = error
127+
dotnet_diagnostic.CA1823.severity = error
128+
dotnet_diagnostic.CA1820.severity = error
129+
dotnet_diagnostic.CA1806.severity = error
130+
dotnet_diagnostic.CA1815.severity = error
131+
dotnet_diagnostic.CA1802.severity = error
132+
dotnet_diagnostic.CA1821.severity = error
133+
dotnet_diagnostic.CA1804.severity = error
134+
dotnet_diagnostic.CA2105.severity = error
135+
dotnet_diagnostic.CA2111.severity = error
136+
dotnet_diagnostic.CA2121.severity = error
137+
dotnet_diagnostic.CA2126.severity = error
138+
dotnet_diagnostic.CA2112.severity = error
139+
dotnet_diagnostic.CA2122.severity = error
140+
dotnet_diagnostic.CA2114.severity = error
141+
dotnet_diagnostic.CA2118.severity = error
142+
dotnet_diagnostic.CA2236.severity = error
143+
dotnet_diagnostic.CA2239.severity = error
144+
dotnet_diagnostic.CA2240.severity = error
145+
dotnet_diagnostic.CA2235.severity = error
146+
dotnet_diagnostic.CA2237.severity = error
147+
dotnet_diagnostic.CA2229.severity = error
148+
dotnet_diagnostic.CA2238.severity = error
149+
dotnet_diagnostic.CA2232.severity = error
150+
151+
# Disable some default Code Analysis warnings we aren't interested in
152+
dotnet_diagnostic.CA1033.severity = none # Interface methods should be callable by child types
153+
dotnet_diagnostic.CA1062.severity = none # Validate arguments of public methods (we'll use nullable reference types instead)
154+
dotnet_diagnostic.CA1063.severity = none # Implement IDisposable correctly
155+
dotnet_diagnostic.CA1303.severity = none # Do not pass literals as localized parameters
156+
dotnet_diagnostic.CA1305.severity = none # Specify IFormatProvider
157+
dotnet_diagnostic.CA1810.severity = none # Initialize reference type static fields inline
158+
dotnet_diagnostic.CA1816.severity = none # Call GC.SuppressFinalize correctly

0 commit comments

Comments
 (0)