What is XQuery ?
- XQuery is a query and functional programming language.
- XQuery is designed to query and transform collections of structured and unstructured data, usually in the form of XML (not just XML files, but anything that can appear as XML).
- XQuery is a W3C Recommendation.
- XQuery is compatible with several W3C standards, such as XML, Namespaces, XSLT, XPath, and XML Schema.
- XQuery is built on XPath expressions.
*****************************************************************************
Why Xquery ?
- Now a days XML is most widely used data transportation and data storage medium, XQuery is an official W3C recommendation to deal with the XML data.
- XML use is widespread across modern information systems in all industry, government, and academic sectors.
- XQuery is used to extract, create and manipulate the XML data.
- After the evolution of MarkLogic, exists, BaseX, XMLdb etc. XML databases XQuery is becoming the primary language to deal with XML content.
**********************************************************************
Why an analysis tool is needed?
- A good quality code is a code which is well documented, easy to understand, well structured and well optimized.
- Analyzing code without executing it. Generally used to find bugs or ensure conformance to coding guidelines.
****************************************************************************************
1- XQStyle Overview
Problem:
XQuery is
designed to query XML data - not just XML files, but anything that can appear
as XML, including databases. Xquery is a recommendation by W3C.
W3C
recommends coding conventions and coding standards for Xquery that should be
strictly followed to deliver a good quality code.
At present we
don’t have any specific tool/plugin for xquery code analysis which performs
automated code analysis or code review.
We have to
do it manually and that also requires extra hours and extra effort to ensure
and deliver a quality code.
Approach
Finalization:
The idea
for XQStyle tool came from an existing tool PMD (A java code analysis tool).
After researching
and analysing a lot on the working and features of PMD, I decided to
develop the XQStyle tool in Java, as
java has very good capability for file handling, IO operations, string handling
and xml document parsing.
Solution:
"XQStyle - An XQuery code analysis tool"
Features:
v XQStyle is very easy to use, it can be easily configured on developer machine.
v XQStyle supports analysis of XQuery versions such as 0.9, 0.9-ml, 1.0 and 1.0-ml .
v XQStyle supports analysis of XQuery versions such as 0.9, 0.9-ml, 1.0 and 1.0-ml .
v XQStyle can be easily integrated with build tools such as HUDSON/JENKINS (CI Tools).
v
XQStyle
takes the customized rule set configuration in the form of XML same as PMD.
v
If
developer will not provide the custom rule set configuration, XQStyle will
analyse the code using its built-in rulesets.
v
XQStyle
has basic all, design & code optimization rules recommended by W3C
for XQuery code analysis.
v
XQStyle
rules sets can be easily customized by developers as per their specific needs.
v
Developers
can categorise rules and set the prioritise of the rules as per their specific needs.
v
Developers
can also pass external parameters specific to configured rules which requires
external inputs. For eaxmple, Code Size or Function Length.
v
Developers
can easily enable or disable rules without removing the rule from the rule set
xml.
v
XQStyle
is capable of analysing the code for a single xquery file as well as on
directory input by recursively traversing the file system for the given
directory.
v
It
generates code analysis reports in two formats XML & HTML based on the
configured renderer. XMLRenderer generates the report in xml format and
HTMLRenderer generates the report in html format.
v
Violations
in the report can be easily filtered based on “High”, “Normal” & “Low” priorities.
v
XQStyle
can be easily integrated with XQuery code repository using Ant scripts/Batch
files.
2 Using XQStyle
2.1 System Requirements
v
Should
have Jre 5 or later version installed.
Dependency library: commons-lang3-3.1.jar or later (Download apache commons library from https://mvnrepository.com/artifact/org.apache.commons/commons-lang3)
v
The
path where the tool will be installed must have enough space and must have
admin privilege.
v
Apache
ant 1.8 (Optional, required only when ant script is used to generate reports).
2.2 Using on developer machine via windows bat file.
To
use this tool on developer machine you need to configure it using following
steps.
v
Extract
the XQStyle.zip file in C:\XQStyle or C:\XQStyle drive which contains
xqstyle.jar,its dependencies and a bat file ("runxqstyle.bat") .
v
Click
on the bat file “runxqstyle.bat” to
run the tool.
v
Provide
the xquery file name with full qualified path or directory path.
For e.g. : “C:\Users\Abhinav\Desktop\XqueryRepository”
v
Provide
the custom xqstyle ruleset xml file with full qualified path [its Optional,
Inbuilt rule sets will be used if not provided].
For e.g. : “C:\Users\Abhinav\Desktop\xqstyleruleset.xml”
v
Provide
the output directory will full full qualified path, where reports will be
saved.
For e.g. : “C:\Users\Abhinav\Desktop\report”
v
Go
to output directory of reports, you will be able to see reports generated by XQStyle.
v
Click
on the “index.html”, it contains report links for every xquery file and also
package name where xquery file kept on.
v
Click
on each link to view the report specific to each XQuery file. You can filter
violations based on High,Low and Normal priorities using check boxes.
v
Unmark
“High Priority” checkbox if you want to filter violations on Low and Normal
Priority.
v
Unmark
“Normal Priority” checkbox if you want to filter violations on Low and High
Priority.
v
Unmark
“Low Priority” checkbox if you want to filter violations on Normal and High
Priority.
2.3 Using on continuous integration tool (Jenkins/Hudson)
<project
name="XQStyle" basedir="." default="about">
<property name="lib.dir"
value="${basedir}/xqstyle-lib"/>
<property name="app.dir"
value="${basedir}/src"/>
<target name="about">
<echo>XQStyle xquery code analyser
script.</echo>
</target>
<!--
=============================================================
XQStyle CONFIGURATION START
=============================================================
-->
<target
name="xqstyle-init">
<echo>******Cleaning the
existing xqstyle-reports******</echo>
<delete
dir="${basedir}\xqstyle-reports" />
<echo>******Creating the
required directories for xqstyle-reports******</echo>
<mkdir
dir="${basedir}\xqstyle-reports" />
<touch
file="${basedir}\xqstyle-reports\index.html"/>
<!-- Pass the source directory or file as a parameter. e.g. -Dsource=c:\test\xquery --> <property name="source" value=""/> <!-- Pass the source directory or file as a parameter. e.g. -Dsource=c:\test\xqstyleruleset.xml. If this parameter is empty then built-in ruleset will be used --> <property name="ruleset" value=""/>
</target>
<target
name="run-xqstyle" depends="xqstyle-init">
<echo>******Processing
xquery analysis******</echo>
<java classname="com.xqstyle.renderers.XQStyleHtmlRenderer">
<arg value="${source}"/>
<arg value="${ruleset}"/> <arg value="${basedir}\xqstyle-reports"/>
<classpath>
<pathelement
location="${lib.dir}\xqstyle.jar"/>
<pathelement
location="${lib.dir}\commons-lang3-3.1.jar"/>
</classpath>
</java>
</target>
<!--
=============================================================
XQStyle
CONFIGURATION END
=============================================================
-->
</project>
|
v
Install
“HTML Publisher Plugin” in Hudson/Jenkins
via manage plugins.
v
Go
to “Configure” job for your project.
v
Under
“Build” section configure targets as
“run-xqstyle”
and Build file as “./xqstyle-ant-script.xml”.
v
Go
to “Post Build Actions/Taks”
section.
v
Select
“Publish HTML reports” chekbox and click on “add” button.
v
Provide
the location or path of reports directory created by ant acript.
v Save
the configuration changes.
v
Click
on “Build Now” to build the project.
Console
output:
v
Click
on HTML
Reports to view the generated report by XQStyle.
v
Reports
can be downloaded in zip format by clicking on “ZIP” link highlighted in red in
the index report.
v
User
can directly navigate back to work-space by clicking link highlighted in red in
the index report.
2.4 GUI
o
Open 'XQStyle.exe'
o
Select the Input directory
o
Select the target
directory
o
Select ruleset xml
(Optional)
o
Click on “Run XQStyle” to start analysis
o
See the log file.
o
See the report generated
in “Output Directory” provided.
o
Open the “index.html” file.
o
Reports can be
viewed same as described in first section 2.2