Skip to content

[Java.Interop] Replace Gendarme with Roslyn FxCop Analyzers. #523

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 22, 2019
Merged
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
14 changes: 0 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ NATIVE_EXT = .so
DLLMAP_OS_NAME = linux
endif

GENDARME_URL = https://github.com/downloads/spouliot/gendarme/gendarme-2.10-bin.zip

PACKAGES = \
packages/NUnit.3.11.0/NUnit.3.11.0.nupkg \
packages/NUnit.Console.3.9.0/NUnit.Console.3.9.0.nupkg
Expand Down Expand Up @@ -95,15 +93,6 @@ src/Java.Runtime.Environment/Java.Runtime.Environment.dll.config: src/Java.Runti
bin/Build$(CONFIGURATION)/JdkInfo.props
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) < $< > $@

fxcop: lib/gendarme-2.10/gendarme.exe bin/GendarmeDebug/netstandard2.0/Java.Interop.dll
cp src/Java.Interop/obj/Gendarme/netstandard2.0/Java.Interop.dll.mdb bin/GendarmeDebug/netstandard2.0
$(RUNTIME) $< --html gendarme.html $(if @(GENDARME_XML),--xml gendarme.xml) --ignore gendarme-ignore.txt bin/GendarmeDebug/netstandard2.0/Java.Interop.dll

lib/gendarme-2.10/gendarme.exe:
-mkdir -p `dirname "$@"`
curl -L -o lib/gendarme-2.10/gendarme-2.10-bin.zip $(GENDARME_URL)
(cd lib/gendarme-2.10 ; unzip gendarme-2.10-bin.zip)

JAVA_INTEROP_LIB = libjava-interop$(NATIVE_EXT)
NATIVE_TIMING_LIB = libNativeTiming$(NATIVE_EXT)

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

bin/GendarmeDebug/netstandard2.0/Java.Interop.dll: $(wildcard src/Java.Interop/*/*.cs) src/Java.Interop/Java.Interop.csproj
$(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

CSHARP_REFS = \
bin/$(CONFIGURATION)/Java.Interop.dll \
bin/$(CONFIGURATION)/Java.Interop.Export.dll \
Expand Down
4 changes: 0 additions & 4 deletions build-tools/automation/azure-pipelines.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ jobs:
- script: make all CONFIGURATION=$(Build.Configuration)
displayName: make all

- script: make fxcop
displayName: Run Gendarme

- script: |
r=0
make run-all-tests CONFIGURATION=$(Build.Configuration) || r=$?
Expand All @@ -103,7 +100,6 @@ jobs:
inputs:
SourceFolder: $(System.DefaultWorkingDirectory)
Contents: |
gendarme.*
xatb.jar
bin.zip
TargetFolder: $(Build.ArtifactStagingDirectory)
Expand Down
704 changes: 0 additions & 704 deletions gendarme-ignore.txt

This file was deleted.

158 changes: 158 additions & 0 deletions src/Java.Interop/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
# This files sets all rules from Gendarme as Code Analysis errors
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the "nature" of this file? What causes errors to be generated? Any build, meaning we'd see future failures in PR builds? Or just builds within "some supported IDE"?

When an error is found, how is it reported?

What's the workflow?

Copy link
Contributor Author

@jpobst jpobst Nov 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are understood by msbuild and are passed to csc.exe which actually does the source code analysis at compile time (this is source code analysis, not binary analysis like Gendarme or FxCop):

csc.exe ... /analyzerconfig:C:\code\xamarin-android\external\Java.Interop\.editorconfig

They are reported by the compiler just like any other compiler generated warning or error, so this will now fail builds from the msbuild command line, in IDEs, and in CI/PR builds without any additional steps.

Example:
https://devdiv.visualstudio.com/DevDiv/_build/results?buildId=3261455&view=results

If we want to ignore an instance, that goes in the suppression file. VS has a tooltip of "Suppress this error in suppression file" to do it for you, other editors may need to do it by hand, but the syntax is pretty similar to the Gendarme syntax.

# via: https://github.com/spouliot/gendarme/wiki/GendarmeToFxCop(git)

[*.cs]
dotnet_diagnostic.CA2001.severity = error
dotnet_diagnostic.CA2214.severity = error
dotnet_diagnostic.CA2222.severity = error
dotnet_diagnostic.CA1065.severity = error
dotnet_diagnostic.CA1041.severity = error
dotnet_diagnostic.CA2230.severity = error
dotnet_diagnostic.CA2006.severity = error
dotnet_diagnostic.CA2002.severity = error
dotnet_diagnostic.CA2211.severity = error
dotnet_diagnostic.CA2243.severity = error
dotnet_diagnostic.CA1053.severity = error
# dotnet_diagnostic.CA1062.severity = error CheckParametersNullityInVisibleMethodsRule - We'll use NRT instead
dotnet_diagnostic.CA2213.severity = error
dotnet_diagnostic.CA2242.severity = error
dotnet_diagnostic.CA2000.severity = error
dotnet_diagnostic.CA2220.severity = error
dotnet_diagnostic.CA1822.severity = error
dotnet_diagnostic.CA2241.severity = error
dotnet_diagnostic.CA1012.severity = error
dotnet_diagnostic.CA1019.severity = error
dotnet_diagnostic.CA1040.severity = error
dotnet_diagnostic.CA1023.severity = error
dotnet_diagnostic.CA1044.severity = error
dotnet_diagnostic.CA1021.severity = error
dotnet_diagnostic.CA1045.severity = error
dotnet_diagnostic.CA1020.severity = error
dotnet_diagnostic.CA1051.severity = error
dotnet_diagnostic.CA1034.severity = error
dotnet_diagnostic.CA1024.severity = error
dotnet_diagnostic.CA1052.severity = error
dotnet_diagnostic.CA1009.severity = error
dotnet_diagnostic.CA2216.severity = error
dotnet_diagnostic.CA1047.severity = error
dotnet_diagnostic.CA2227.severity = error
dotnet_diagnostic.CA1048.severity = error
dotnet_diagnostic.CA2226.severity = error
dotnet_diagnostic.CA1038.severity = error
dotnet_diagnostic.CA1008.severity = error
dotnet_diagnostic.CA1028.severity = error
dotnet_diagnostic.CA2221.severity = error
dotnet_diagnostic.CA2218.severity = error
dotnet_diagnostic.CA1036.severity = error
dotnet_diagnostic.CA1039.severity = error
dotnet_diagnostic.CA1016.severity = error
dotnet_diagnostic.CA1014.severity = error
dotnet_diagnostic.CA1017.severity = error
dotnet_diagnostic.CA1018.severity = error
dotnet_diagnostic.CA1013.severity = error
dotnet_diagnostic.CA2231.severity = error
dotnet_diagnostic.CA2224.severity = error
dotnet_diagnostic.CA1030.severity = error
dotnet_diagnostic.CA1043.severity = error
dotnet_diagnostic.CA1054.severity = error
dotnet_diagnostic.CA1055.severity = error
dotnet_diagnostic.CA1056.severity = error
dotnet_diagnostic.CA1059.severity = error
dotnet_diagnostic.CA2225.severity = error
dotnet_diagnostic.CA1035.severity = error
dotnet_diagnostic.CA1050.severity = error
dotnet_diagnostic.CA1001.severity = error
dotnet_diagnostic.CA1049.severity = error
dotnet_diagnostic.CA1027.severity = error
dotnet_diagnostic.CA1005.severity = error
dotnet_diagnostic.CA1004.severity = error
dotnet_diagnostic.CA1000.severity = error
dotnet_diagnostic.CA1002.severity = error
dotnet_diagnostic.CA1006.severity = error
dotnet_diagnostic.CA1010.severity = error
dotnet_diagnostic.CA1007.severity = error
dotnet_diagnostic.CA1003.severity = error
dotnet_diagnostic.CA2201.severity = error
dotnet_diagnostic.CA2200.severity = error
dotnet_diagnostic.CA1031.severity = error
dotnet_diagnostic.CA2219.severity = error
dotnet_diagnostic.CA1065.severity = error
dotnet_diagnostic.CA2201.severity = error
dotnet_diagnostic.CA1064.severity = error
dotnet_diagnostic.CA2208.severity = error
dotnet_diagnostic.CA1032.severity = error
dotnet_diagnostic.CA1060.severity = error
dotnet_diagnostic.CA1404.severity = error
dotnet_diagnostic.CA1414.severity = error
dotnet_diagnostic.CA2101.severity = error
dotnet_diagnostic.CA1401.severity = error
dotnet_diagnostic.CA2205.severity = error
dotnet_diagnostic.CA1403.severity = error
dotnet_diagnostic.CA1406.severity = error
dotnet_diagnostic.CA1413.severity = error
dotnet_diagnostic.CA1402.severity = error
dotnet_diagnostic.CA1407.severity = error
dotnet_diagnostic.CA1405.severity = error
dotnet_diagnostic.CA1409.severity = error
dotnet_diagnostic.CA1408.severity = error
dotnet_diagnostic.CA1412.severity = error
dotnet_diagnostic.CA1410.severity = error
dotnet_diagnostic.CA1411.severity = error
dotnet_diagnostic.CA1502.severity = error
dotnet_diagnostic.CA1501.severity = error
dotnet_diagnostic.CA1011.severity = error
dotnet_diagnostic.CA1504.severity = error
dotnet_diagnostic.CA1500.severity = error
dotnet_diagnostic.CA1707.severity = error
dotnet_diagnostic.CA1724.severity = error
dotnet_diagnostic.CA1713.severity = error
dotnet_diagnostic.CA1712.severity = error
dotnet_diagnostic.CA1700.severity = error
dotnet_diagnostic.CA1725.severity = error
dotnet_diagnostic.CA1709.severity = error
dotnet_diagnostic.CA1715.severity = error
dotnet_diagnostic.CA1722.severity = error
dotnet_diagnostic.CA1710.severity = error
dotnet_diagnostic.CA1711.severity = error
dotnet_diagnostic.CA1714.severity = error
dotnet_diagnostic.CA1726.severity = error
dotnet_diagnostic.CA1809.severity = error
dotnet_diagnostic.CA1800.severity = error
dotnet_diagnostic.CA1819.severity = error
dotnet_diagnostic.CA1811.severity = error
dotnet_diagnostic.CA1812.severity = error
dotnet_diagnostic.CA1805.severity = error
dotnet_diagnostic.CA1813.severity = error
dotnet_diagnostic.CA1801.severity = error
dotnet_diagnostic.CA1823.severity = error
dotnet_diagnostic.CA1820.severity = error
dotnet_diagnostic.CA1806.severity = error
dotnet_diagnostic.CA1815.severity = error
dotnet_diagnostic.CA1802.severity = error
dotnet_diagnostic.CA1821.severity = error
dotnet_diagnostic.CA1804.severity = error
dotnet_diagnostic.CA2105.severity = error
dotnet_diagnostic.CA2111.severity = error
dotnet_diagnostic.CA2121.severity = error
dotnet_diagnostic.CA2126.severity = error
dotnet_diagnostic.CA2112.severity = error
dotnet_diagnostic.CA2122.severity = error
dotnet_diagnostic.CA2114.severity = error
dotnet_diagnostic.CA2118.severity = error
dotnet_diagnostic.CA2236.severity = error
dotnet_diagnostic.CA2239.severity = error
dotnet_diagnostic.CA2240.severity = error
dotnet_diagnostic.CA2235.severity = error
dotnet_diagnostic.CA2237.severity = error
dotnet_diagnostic.CA2229.severity = error
dotnet_diagnostic.CA2238.severity = error
dotnet_diagnostic.CA2232.severity = error

# Disable some default Code Analysis warnings we aren't interested in
dotnet_diagnostic.CA1033.severity = none # Interface methods should be callable by child types
dotnet_diagnostic.CA1062.severity = none # Validate arguments of public methods (we'll use nullable reference types instead)
dotnet_diagnostic.CA1063.severity = none # Implement IDisposable correctly
dotnet_diagnostic.CA1303.severity = none # Do not pass literals as localized parameters
dotnet_diagnostic.CA1305.severity = none # Specify IFormatProvider
dotnet_diagnostic.CA1810.severity = none # Initialize reference type static fields inline
dotnet_diagnostic.CA1816.severity = none # Call GC.SuppressFinalize correctly
Loading