[ https://issues.apache.org/jira/browse/RANGER-5018?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17903564#comment-17903564 ]
Madhan Neethiraj edited comment on RANGER-5018 at 12/6/24 9:19 PM: ------------------------------------------------------------------- * [Patch in review board|https://reviews.apache.org/r/75299] * [PR #424|https://github.com/apache/ranger/pull/424] was (Author: madhan.neethiraj): [PR #424|https://github.com/apache/ranger/pull/424] > agents-audit module: update for code readability improvement > ------------------------------------------------------------ > > Key: RANGER-5018 > URL: https://issues.apache.org/jira/browse/RANGER-5018 > Project: Ranger > Issue Type: Sub-task > Components: audit > Reporter: Madhan Neethiraj > Assignee: Madhan Neethiraj > Priority: Major > Fix For: 3.0.0 > > Attachments: RANGER-5018.patch > > Time Spent: 10m > Remaining Estimate: 0h > > Here are the steps I used to update the sources to be compliant with the > checkstyle requirements: > # Update IntelliJ IDE (one time operation) with code schema corresponding to > Ranger checkstyle requirements: > ## IntelliJ IDEA/Settings/Editor/Code Style/Java > ## Click on icon next to Scheme, then select Import Scheme/IntelliJ IDEA > code style XML > ## Pick dev-support/RangerCodeScheme-IntelliJ.xml from Apache Ranger master > branch > ## Click OK, OK > # Steps to update Java sources in a module to comply with checkstyle > requirements: > ## Add following property to module's pom.xml, so that build will fail on > checkstyle violations > *** <checkstyle.failOnViolation>true</checkstyle.failOnViolation> > ## Click on the module name in the Project navigation at the left side of > the IDE > ## Click on menu (at the top of the IDE): Code/Reformat Code > ## Check the following boxes, and click Run > *** Optimize Imports > *** Rearrange entries > *** Cleanup Code > *** Filters: Scope - All Places > *** Filters: File mask(s) - *.java > ## Build the module with command: *mvn clean install* > ## Review reported errors, similar to errors shown below, update sources to > address them, ensure that the build succeeds with no errors > *** [ERROR] src/main/java/org/apache/ranger/audit/test/TestEvents.java:[35] > (regexp) RegexpMultiline: Blank line after opening brace > *** [ERROR] > src/main/java/org/apache/ranger/audit/test/TestEvents.java:[35,1] (design) > HideUtilityClassConstructor: Utility classes should not have a public or > default constructor. > *** [ERROR] > src/main/java/org/apache/ranger/audit/test/TestEvents.java:[45,20] (naming) > LocalVariableName: Name 'AUDIT_PROPERTIES_FILE' must match pattern > '^([a-z][a-zA-Z0-9]*|_)$'. > *** [ERROR] > src/main/java/org/apache/ranger/audit/provider/AuditMessageException.java:[27] > (regexp) RegexpMultiline: Blank line after opening brace > *** [ERROR] > src/main/java/org/apache/ranger/audit/provider/BufferedAuditProvider.java:[26,44] > (coding) ExplicitInitialization: Variable 'mBuffer' explicitly initialized > to 'null' (default value for its type). > *** [ERROR] > src/main/java/org/apache/ranger/audit/provider/BufferedAuditProvider.java:[27,44] > (coding) ExplicitInitialization: Variable 'mDestination' explicitly > initialized to 'null' (default value for its type). > *** [ERROR] > src/main/java/org/apache/ranger/audit/provider/AuditWriterFactory.java:[1] > (misc) NewlineAtEndOfFile: File does not end with a newline > *** [ERROR] > src/main/java/org/apache/ranger/audit/provider/AuditWriterFactory.java:[35,49] > (coding) ExplicitInitialization: Variable 'me' explicitly initialized to > 'null' (default value for its type). > *** ... > *** [ERROR] Failed to execute goal > org.apache.maven.plugins:maven-checkstyle-plugin:3.1.0:check > (checkstyle-check) on project ranger-plugins-audit: You have 399 Checkstyle > violations. -> [Help 1] > ## Review each Java file in the module for the following and update where > necessary > ### Ensure that Logger initialization is at the top of the class, > immediately after class declartion. It is likely that the code reformat > performed earlier pushed this line after other initializations > **** private static final Logger LOG = > LoggerFactory.getLogger(TestEvents.class); > ### Separate member declaration of different scope/visibility with an empty > line - if it helps readability. Example: > **** private static final Logger logger = > LoggerFactory.getLogger(AuditWriterFactory.class); > **** > **** public static final String AUDIT_FILETYPE_DEFAULT = "json"; > **** public static final String AUDIT_JSON_FILEWRITER_IMPL = > "org.apache.ranger.audit.utils.RangerJSONAuditWriter"; > **** public static final String AUDIT_ORC_FILEWRITER_IMPL = > "org.apache.ranger.audit.utils.RangerORCAuditWriter"; > **** > **** private static volatile AuditWriterFactory me; > **** > **** public Map<String, String> auditConfigs; > **** public Properties props; > ### Join multiline statements into a single line. Example: > **** long timeSinceLastFlush = System.currentTimeMillis() > - lastFlushTime; > **** long timeSinceLastFlush = System.currentTimeMillis() - lastFlushTime; > ### Replace log statements having string concats with parameterized message. > Example: > **** LOG.info("AsyncAuditProvider-stats:" + mName + ": process lifetime" > + ": inLogs=" + lifeTimeInLogCount.get() > + ", outLogs=" + lifeTimeOutLogCount.get() > + ", dropped=" + lifeTimeDropCount.get()); > **** LOG.info("AsyncAuditProvider-stats:{}: process lifetime: inLogs={}, > outLogs={}, dropped={}", mName, lifeTimeInLogCount, lifeTimeOutLogCount, > lifeTimeDropCount); > ### Review Warnings flagged by the IDE by clicking on icon at the top-right > of the source file, and address as many of them as safely possible. However, > please make sure to not make any changes that can break existing usage (see > examples given below). Note that usage of a class (methods, fields) may not > be in Ranger repo - consider plugins for NiFi, Kudu, Trino that are not in > Ranger repo. > #### remove/rename a method or field > #### changing visibility of a method or field > #### changing signature of a method -- This message was sent by Atlassian Jira (v8.20.10#820010)