grails-CodeNarc and Service Stateless ruleSet - grails

I am trying to use codeNarc on a grails project, after installing it and running it I've have some rulesets violations messages that I would like to understand and resolve. The first on concern "GrailsStatelessService" and the second the "equals() and toString()" methods...
For the first one "GrailsStatelessService" the message I received is:
***************************
Violation in class app.TheServiceName. The class is marked as stateless but contains the non-final field 'aVariableName'
***************************
I've searched a little about that but not found a lot of tricks about that. Can someone please explain me what the real meaning of this ruleset and what I have to do to solve this problem/
About the second kind of ruleSet I found somewhere that it solved by overriding those methods in all the domain classes but is hat an obligation, a need, or do I just have to modify the ruleSet File to avoid those kinds of messages related to those rulesets?
And that introduces my last question: where to find this ruleSet File( the default one within codenarc) or the one i must include myself?

I find that the GrailsStatelessService rule does sometimes catch a real violation, so rather than disabling it, I modify it to ignore my commonly used field names.
BuildConfig.groovy:
codenarc.propertiesFile = 'grails-app/conf/codenarc.properties'
codenarc.properties:
GrailsStatelessService.addToIgnoreFieldNames=grailsApplication,applicationContext,sessionFactory

I am able to configure this CodeNarc rules as follows:
Install CodeNarc plugin [grails install-plugin codenarc]
Add following line in BuildConfig.groovy file [for details configuration]:
codenarc.propertiesFile = 'grails-app/conf/codenarc.properties'
In codenarc.properties - file, I add following rule for ignore few RULEs
codenarc.properties = {
GrailsDomainHasEquals.enabled = false
GrailsDomainHasToString.enabled = false
EmptyMethod.enabled = false
}
Run following command for generating CodeNarc Report: grails codenarc

Sometimes condenarc mix things ups. Adding Service at the end of the name of the service remove this "issue" if you are not using a class as stateless but codenarc believes so. I had this problem with this Service:
private CurrencyConverterFactory currencyConverterFactory
And I fixed with:
private CurrencyConverterFactory currencyConverterFactoryService
I hope this helps someone.

The documentation does a good job of explaining that rule:
Checks for non-final fields on a Grails service class. Grails service
classes are singletons by default, and so they should be reentrant. In
most cases, this implies (or at least encourages) that they should be
stateless.
This rule ignores final fields (either instance or static). Fields
that are static and non-final, however, do cause a violation.

If you are using the Grails CodeNarc plugin, then see the plugin documentation for a list of the CodeNarc rulesets that are included by default. There is also a section on "Configuring The CodeNarc RuleSet File(s)" -- so by all means create your own custom ruleset.
http://www.grails.org/plugin/codenarc/
It is expected that you customize the set of rules appropriate for your team/project. Other than the "basic" rulset, the other provided rulesets all contain rules that may or may not be appropriate for you.
The GrailsDomainHasToString and GrailsDomainHasEquals rules are perfect examples -- many organizations disable those rules.
See the CodeNarc documentation for more information on turning off a rule:
http://codenarc.sourceforge.net/codenarc-configuring-rules.html

Related

Suffix appended to properties logged through Serilog for dotnet

We're logging to Elastic through the Serilog dotnet package and have noticed that properties that we add to the Poerperties part of the log events seem to be suffixed with _ (underscore) and then some type identifier. For example:
This causes some issues for us in the indexing process. I've been looking through the Serilog library code to try to find the source of this but without any luck. Can someone point me in the right direction as to where the suffix is added to the property names?
It looks like you're overriding the ElasticsearchSinkOptions.CustomFormatter with code to do this when constructing the sink. Using the default formatter (leaving this un-set) should not result in this style of property name.
If this doesn't cover it, please post as much as you can to show how the sink is being configured in your app.
See also:
https://github.com/serilog-contrib/serilog-sinks-elasticsearch#a-note-about-fields-inside-elasticsearch
https://github.com/serilog-contrib/serilog-sinks-elasticsearch/issues/184

Skylark - can a rule access the attributes of another rule from its label?

This question piggybacks this github issue. However, I have ran into this issue in one other context.
Context
Within Bazel, there are two repository rules, maven_jar and maven_server.
maven_jar(name, artifact, repository, server, sha1)
maven_server(name, repository, settings)
The maven_jar rule's server attribute is a label pointing to some maven_server target.
Currently, whenever the server attribute is provided, the maven_jar rule errors out.
What I would like to accomplish
Within maven_jar's implementation function, I would like to access the maven_server's attributes. Specifically, I would like to do something along the lines of:
def _impl(rtx):
settings_attr = rtx.attr.server.getSettings()
# alternatively
settings_attr = rtx.attr.server.getAttributes().settings
Is this behavior supported? If not, any way I can approximate it?
The server attribute is a label, so I'm not sure if one can obtain these values using its providers/aspects.
Repository rules are macros, so they do not have providers the same way "normal" rules do. Thus, if you specify a label attribute, it basically has to be a source file.
As settings.xml isn't supposed to be project-specific, I think it mgiht make more sense for maven_jar to use the users/system's settings.xml, as described in the Maven docs:
There are two locations where a settings.xml file may live:
The Maven install: ${maven.home}/conf/settings.xml
A user’s install: ${user.home}/.m2/settings.xml
The former settings.xml are also called
global settings, the latter settings.xml are referred to as user
settings. If both files exists, their contents gets merged, with the
user-specific settings.xml being dominant.

XTSE1650: net.sf.saxon.trans.LicenseException: Requested feature (xsl:import-schema) requires Saxon-EE

I use java and saxonee-9.5.1.6.jar included build path , when run, getting these errors at different times.
Error at xsl:import-schema on line 6 column 169 of stylesheet.xslt:
XTSE1650: net.sf.saxon.trans.LicenseException: Requested feature (xsl:import-schema)
requires Saxon-EE
Error on line 1 column 1
SXXP0003: Error reported by XML parser: Content is not allowed in prolog.
javax.xml.transform.TransformerConfigurationException: Failed to compile stylesheet. 1 error detected.
I open .xslt file in hex editor and dont see any different character at the beginning AND
I use transformerfactory in a different project but any error I get.
Check what the implementation class of tFactory is. My guess is it is probably net.sf.saxon.TransformerFactoryImpl - which is basically the Saxon-HE version.
When you use JAXP like this, you're very exposed to configuration problems, because it loads whatever it finds sitting around on the classpath, or is affected by system property settings which could be set in parts of the application you know nothing about.
If your application depends on particular features, it's best to load a specific TransformerFactory, e.g. tFactory = new com.saxonica.config.EnterpriseTransformerFactory().
I don't know whether your stylesheet expects the source document to be validated against the schema, but it it does, note that this isn't automatic: you can set properties on the factory to make it happen.
I would recommend using Saxon's s9api interface rather than JAXP for this kind of thing. The JAXP interface was designed for XSLT 1.0, and it's a real stretch to use it for some of the new 2.0 features like schema-awareness: it can be done, but you keep running into limitations.

How to add filters to OpenCover tool to skip some of the classes in a namespace

How can I add filters to skip some of the classes in a namespace/assembly. For example: SYM.UI is the base assembly and i want to skip SYM.UI.ViewModels. Writing the below filter but it is including all of them and not fulfilling my request:
+[SYM.UI*]* -[SYM.UI.ViewModels*]*
Kindly help me correcting this?
The opencover wiki is a good place to start.
The usage is described as +/-[modulefilter]typefilter (this is based on how you would see the types in IL; where the type filter also includes the namespace and module filter usually is the name of the assembly (without the file extension).
Thus to exclude your types you could use
+[SYM.UI]* -[SYM.UI]SYM.UI.ViewModels.*
NOTE: Exclusion filters take preference over inclusion filters.
You can use following:
"-filter:+[*]* -[SYM.UI]SYM.UI.ViewModels.*"
Note that the quotes must be around the -filter: part, too

IntelliJ Idea auto-complete for my own grails domain meta class methods?

I'm using IntelliJ Idea 10 IDE for my grails development and while it's great at working out the "standard" meta class methods on, for example, domain classes (save, findBy etc), it (obviously) can't pick up methods added by plugins or my own code.
While I don't expect the IDE to be able to pick these up automatically, I'm optimistically wondering if there's a way to tell IntelliJ that, for example, "myMethod" is added to all domain objects, and that it takes a map and returns "myType".
It's a long shot I know, but does anyone know how this might be done in config, a plugin, or by some smoke-and-mirrors so I can a) stop missing simple, stupid typos and b) get some auto-complete?
I think you're looking for the GroovyDSL scripting framework
http://confluence.jetbrains.net/display/GRVY/Scripting+IDE+for+DSL+awareness
its possible to save a *.gdsl file somethere in src dir, with content:
contributor(context()) {
def scope = com.intellij.psi.search.GlobalSearchScope.allScope(project);
delegatesTo(com.intellij.psi.JavaPsiFacade.getInstance(project).findClass('org.grails.datastore.gorm.GormStaticApi', scope)) delegatesTo(com.intellij.psi.JavaPsiFacade.getInstance(project).findClass('org.grails.datastore.gorm.GormEntity', scope))}

Resources