JDeveloper Auditing Framework (UKOUG Tech2013)

Post on 09-May-2015

2.658 views 6 download

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)

Quality Assurance JDeveloper Auditing Framework

About Us

Richard OlrichsMNwww.olrichs.nl@richardolrichs

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

Agenda

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

Aborts Compile On Error

● Applies default Fix● Run analysis with single

(or few) rules● Example: Generate

unique JSF component ID

Custom Rules

Custom Rules

● Setting up JDeveloper Extension Project

● Implementing Custom Rule● Implementing Custom Fix

Setting up JDev Project

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)

Creating Custom Rules

Analyzing Java Code

Analyzing XML Files

Disables Analyzer for current construct and all children

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)

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

once, so can initialize keys

Creating Custom Fix

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

Violation Overload

Violation Overload

● Even ADF Sample Application from OTN has 157 issues

● Too many violations cause developers to ignore all of them

Violation Overload

SuppressWarnings Java Annotation

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

SuppressWarnings Java Annotation

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

JDeveloper 12c Suppression Schemes

JDeveloper 12c Suppression Scheme

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

Suppress Warnings in XML

Suppress Warnings in XML

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

Analyzer - Suppressing violations

Transform - Creating XML Comment

Audit Extension Project

Audit Extension Project

● Project standards● Company standards● Community standards

Audit Extension Project

ADF EMG Extension Project

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

Automated QA

OJAudit

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

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

Automated QASonarQube

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

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

Summary

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