JDeveloper Auditing Framework (UKOUG Tech2013)

78
Quality Assurance JDeveloper Auditing Framework

description

Presentation on Quality Assurance with the JDeveloper Auditing Framework, covering: - how to use default auditing framework - creating custom rules and fixes to implement company and project standards - SuppressWarnings JDeveloper extension to suppresswarnings in XML files - ADF Code Guidelines JDeveloper extension - SonarQube plugin for JDeveloper (ojaudit)

Transcript of JDeveloper Auditing Framework (UKOUG Tech2013)

Page 1: JDeveloper Auditing Framework (UKOUG Tech2013)

Quality Assurance JDeveloper Auditing Framework

Page 2: JDeveloper Auditing Framework (UKOUG Tech2013)

About Us

Richard OlrichsMNwww.olrichs.nl@richardolrichs

Wilfred van der DeijlThe Future Groupwww.redheap.com@wilfreddeijl

Page 3: JDeveloper Auditing Framework (UKOUG Tech2013)

Agenda

● Audit Profiles and Preferences● Audit JDeveloper Extension Project● Creating Custom Rules● Creating Custom Fixes● SuppressWarnings● Automated QA

Page 4: JDeveloper Auditing Framework (UKOUG Tech2013)
Page 5: JDeveloper Auditing Framework (UKOUG Tech2013)

Aborts Compile On Error

Page 6: JDeveloper Auditing Framework (UKOUG Tech2013)
Page 7: JDeveloper Auditing Framework (UKOUG Tech2013)
Page 8: JDeveloper Auditing Framework (UKOUG Tech2013)
Page 9: JDeveloper Auditing Framework (UKOUG Tech2013)
Page 10: JDeveloper Auditing Framework (UKOUG Tech2013)
Page 11: JDeveloper Auditing Framework (UKOUG Tech2013)
Page 12: JDeveloper Auditing Framework (UKOUG Tech2013)
Page 13: JDeveloper Auditing Framework (UKOUG Tech2013)
Page 14: JDeveloper Auditing Framework (UKOUG Tech2013)

● Applies default Fix● Run analysis with single

(or few) rules● Example: Generate

unique JSF component ID

Page 15: JDeveloper Auditing Framework (UKOUG Tech2013)

Custom Rules

Page 16: JDeveloper Auditing Framework (UKOUG Tech2013)

Custom Rules

● Setting up JDeveloper Extension Project

● Implementing Custom Rule● Implementing Custom Fix

Page 17: JDeveloper Auditing Framework (UKOUG Tech2013)

Setting up JDev Project

Page 18: JDeveloper Auditing Framework (UKOUG Tech2013)

Setting up JDev Extension Project

● Install Extension SDK (Help>CheckForUpdates)● File > New > Applications >

Extension Application● extension.xml and MANIFEST.MF● Bundled as .ZIP● Can be distributed through custom JDeveloper

Update Center(aka network drive or URL)

Page 19: JDeveloper Auditing Framework (UKOUG Tech2013)
Page 20: JDeveloper Auditing Framework (UKOUG Tech2013)
Page 21: JDeveloper Auditing Framework (UKOUG Tech2013)
Page 22: JDeveloper Auditing Framework (UKOUG Tech2013)

Creating Custom Rules

Page 23: JDeveloper Auditing Framework (UKOUG Tech2013)
Page 24: JDeveloper Auditing Framework (UKOUG Tech2013)
Page 25: JDeveloper Auditing Framework (UKOUG Tech2013)
Page 26: JDeveloper Auditing Framework (UKOUG Tech2013)
Page 27: JDeveloper Auditing Framework (UKOUG Tech2013)
Page 28: JDeveloper Auditing Framework (UKOUG Tech2013)

Analyzing Java Code

Page 29: JDeveloper Auditing Framework (UKOUG Tech2013)

Analyzing XML Files

Page 30: JDeveloper Auditing Framework (UKOUG Tech2013)
Page 31: JDeveloper Auditing Framework (UKOUG Tech2013)

Disables Analyzer for current construct and all children

Page 32: JDeveloper Auditing Framework (UKOUG Tech2013)
Page 33: JDeveloper Auditing Framework (UKOUG Tech2013)

AuditContext

● Provides Traversal State● report() for Violations, Metrics,

Suppressions● Holds State for Analyzer

○ Setting Attributes for Child Constructs○ Setting Attributes for Parent Construct○ (Sharing Attributes between Analyzers)

Page 34: JDeveloper Auditing Framework (UKOUG Tech2013)

● AuditContext creates Analyzer State Keys● enter() on root-node (Workspaces) invoked

once, so can initialize keys

Page 35: JDeveloper Auditing Framework (UKOUG Tech2013)

Creating Custom Fix

Page 36: JDeveloper Auditing Framework (UKOUG Tech2013)
Page 37: JDeveloper Auditing Framework (UKOUG Tech2013)
Page 38: JDeveloper Auditing Framework (UKOUG Tech2013)
Page 39: JDeveloper Auditing Framework (UKOUG Tech2013)

Transform subclass

● apply(context, construct)○ applies fix by changing source○ TransformContext argument contains editor location,

violation, etc○ Construct is the object with the violation (eg. a

JavaMethod or XMLElement)● isQueryRequired(context, construct)

and query(context, construct)○ queries the user for additional info when applying fix

Page 40: JDeveloper Auditing Framework (UKOUG Tech2013)

Violation Overload

Page 41: JDeveloper Auditing Framework (UKOUG Tech2013)
Page 42: JDeveloper Auditing Framework (UKOUG Tech2013)

Violation Overload

● Even ADF Sample Application from OTN has 157 issues

● Too many violations cause developers to ignore all of them

Page 43: JDeveloper Auditing Framework (UKOUG Tech2013)

Violation Overload

Page 44: JDeveloper Auditing Framework (UKOUG Tech2013)

SuppressWarnings Java Annotation

@SuppressWarnings annotation introduced in Java 1.5 and tells Java Compiler to suppress warnings

Page 45: JDeveloper Auditing Framework (UKOUG Tech2013)

SuppressWarnings Java Annotation

JDeveloper 12c now also “listens” to annotation and suppresses warnings itself (not only javac)

Page 46: JDeveloper Auditing Framework (UKOUG Tech2013)

JDeveloper 12c Suppression Schemes

Page 47: JDeveloper Auditing Framework (UKOUG Tech2013)

JDeveloper 12c Suppression Scheme

Why not create our own for non-Java (aka XML)?

Page 48: JDeveloper Auditing Framework (UKOUG Tech2013)

Suppress Warnings in XML

Page 49: JDeveloper Auditing Framework (UKOUG Tech2013)

Suppress Warnings in XML

Page 50: JDeveloper Auditing Framework (UKOUG Tech2013)
Page 51: JDeveloper Auditing Framework (UKOUG Tech2013)
Page 52: JDeveloper Auditing Framework (UKOUG Tech2013)

SuppressWarnings

● JDeveloper 12c natively supports @SuppressWarning in Java

● JDev extension adds<!-- SuppressWarning -->

● Extension available today● JDeveloper 12c only as Suppression

Schemes is new 12c feature

Page 53: JDeveloper Auditing Framework (UKOUG Tech2013)

Analyzer - Suppressing violations

Page 54: JDeveloper Auditing Framework (UKOUG Tech2013)

Transform - Creating XML Comment

Page 55: JDeveloper Auditing Framework (UKOUG Tech2013)

Audit Extension Project

Page 56: JDeveloper Auditing Framework (UKOUG Tech2013)

Audit Extension Project

● Project standards● Company standards● Community standards

Page 57: JDeveloper Auditing Framework (UKOUG Tech2013)

Audit Extension Project

Page 58: JDeveloper Auditing Framework (UKOUG Tech2013)

ADF EMG Extension Project

Page 59: JDeveloper Auditing Framework (UKOUG Tech2013)
Page 60: JDeveloper Auditing Framework (UKOUG Tech2013)
Page 61: JDeveloper Auditing Framework (UKOUG Tech2013)
Page 62: JDeveloper Auditing Framework (UKOUG Tech2013)
Page 63: JDeveloper Auditing Framework (UKOUG Tech2013)

ADF Code Guidelines Extension

● JDeveloper extension available today● ADF Code Guidelines auditing during

development● Community project at java.net: adfemg-

auditrules● Contribute and discuss at ADF EMG● JDeveloper 12c only

○ at least for now. No reason why this can’t be backported to JDeveloper 11g

Page 64: JDeveloper Auditing Framework (UKOUG Tech2013)

Automated QA

Page 65: JDeveloper Auditing Framework (UKOUG Tech2013)

OJAudit

● Command line auditing● JDEV_HOME/jdev/bin/ojaudit -help● Output in XML/text/HTML or custom xsl

Page 66: JDeveloper Auditing Framework (UKOUG Tech2013)
Page 67: JDeveloper Auditing Framework (UKOUG Tech2013)

Automated QA

● Simple solution: Run ojaudit from CI server and publish output

● Benefit: Same rules during development and CI QA

● @SuppressWarnings and<!--SuppressWarning--> keep list of violations short and actionable

Page 68: JDeveloper Auditing Framework (UKOUG Tech2013)

Automated QASonarQube

Page 69: JDeveloper Auditing Framework (UKOUG Tech2013)
Page 70: JDeveloper Auditing Framework (UKOUG Tech2013)

SonarQube

● Tool to manage Code Quality● Rules, Violations, Metrics, Test Coverage, etc● Free Open Source● Initially Java, but now 20+ languages● Historical data, thus trends● Highly extensible through plugins

Page 71: JDeveloper Auditing Framework (UKOUG Tech2013)
Page 72: JDeveloper Auditing Framework (UKOUG Tech2013)
Page 73: JDeveloper Auditing Framework (UKOUG Tech2013)
Page 74: JDeveloper Auditing Framework (UKOUG Tech2013)
Page 75: JDeveloper Auditing Framework (UKOUG Tech2013)

ADF EMG SonarQube plugin

● SonarQube plugin○ runs ojaudit○ converts ojaudit output to SonarQube violations

● www.sonarqube.com for base product● Watch ADF EMG for availability of plugin● Not specific to ADF, but for any JDev project● Tested with JDeveloper 12c, but should work

with any version

Page 77: JDeveloper Auditing Framework (UKOUG Tech2013)

Summary

● Audit Profiles and Preferences● Creating Custom Rules● Creating Custom Fixes● SuppressWarnings JDev Extension● ADF Code Guidelines JDev Extension● SonarQube ojaudit plugin

Page 78: JDeveloper Auditing Framework (UKOUG Tech2013)