IBM Rational Software Analyzer
IBM Rational Software Analyzer Setting up custom rules
This module will cover Setting up custom rules for IBM Rational® Software Analyzer versions 7.0 and higher.
Module objectives
Module objectives Topics covered in this module: What are rules? How to write your own rules Setting up a custom plug-in for the custom rule When you complete this module you are able to: Set up custom rules in Rational Software Analyzer
This course covers three topics. It provides you with information about what a rule is, how to write your own rules and how to set up a custom plug-in for the custom rule. When you complete this module you are able to set up custom rules in Rational Software Analyzer.
Custom rules in Rational Software Analyzer
Custom rules in Rational Software Analyzer Rational Software Analyzer ships with a set of pre-defined rules, but you want to define your own rules. Rational Software Analyzer is a collection of plug-ins. These plug-ins define all the Rational Software Analyzer behavior including the rules and their definitions. To add new rules you need to expand the plug-ins by adding your own custom plug-ins to those already there.
When Rational Software Analyzer is installed it comes with its own set of pre-determined rules ready for analysis. However these rules are by no means exhaustive. In fact part of the purpose of Rational Software Analyzer is to allow you to create rules to bring their own form of governance to the code base. Rational Software Analyzer is a collection of plug-ins, so the rules are plug-ins as well. In order to create a new rule you need to create a new plug-in to extend the Rational Software Analyzer framework.
How to write your own rules
How to write your own rules Eclipse offers a plug-in creation wizard that will help you get started. In the Eclipse shell go to File -> New -> Project -> Plug-In Project. All the defaults will work except you will need to uncheck the box that states “This plug-in makes contributions to the UI”.
Creating a plug-in can appear to be a difficult task, but Eclipse has a wizard in place to do most of the work for you. The Eclipse plug-in wizard will create the project and all the preliminary configuration information. This will create the basis from which you can create your Rational Software Analyzer custom rule. Other various values can be changed to something meaningful to you.
Setting up a custom plug-in
Setting up a custom plug-in Steps to set up the custom plug-in Once the plug-in Project has been generated, find the project in the navigator. Open the plug-in.xml file. Go to the Dependencies tab. Plug-ins that are required for this plug-in. The custom plug-in will always require: com.ibm.rsaz.analysis.core – This holds all the core functionality Software Analyzer stuff. For Java™ com.ibm.analysis.codereview.java com.eclipse.jdt.core For C com.ibm.analysis.codereview.cpp com.eclipse.cdt.core
Now that you have run the wizard and you have your preliminary plug-in, you will need to tailor it to make it grab all the Rational Software Analyzer information. You will do this through the plug-in.xml file. This file holds all the configuration information for the plug-in. Right now it is a blank slate. You will add in some dependencies. These are the plug-ins that your plug-in will look for to extend. You will configure it to look for the Rational Software Analyzer plug-ins you need. For the purposes of this presentation, proceed with making this plug-in a Java rule.
Setting up a custom plug-in: Extending
Setting up a custom plug-in: Extending From the same plugin.xml file, go to the Extensions tab and add a new Extension com.ibm.rsaz.analysis.core.analysisCategory. This will create the rule category for where this rule is placed in Rational Software Analyzer. Set these values in the extension: id - Set to a unique value Label – This is how the rule shows in the Rational Software Analyzer rule menu Class should be set to com.ibm.rsaz.analysis.core.category.DefaultAnalysisCategory. That class has most of the functionality needed for a category
You now have your plug-in extending the Rational Software Analyzer plug-ins, but you need to configure your plug-in so Rational Software Analyzer knows what to do with it. First, you need to tell Rational Software Analyzer how to categorize your rule, so it knows how to display it in the Rules tab. You can do this by adding an Extension to the plug-in that will create an analysisCategory extension.
Setting up a custom plug-in: Extending (2)
Setting up a custom plug-in: Extending (2) The hierarchy of Rational Software Analyzer rule displays is: Providers (one to many) Categories (one to many) Rules
To clarify why you were doing a category extension in the previous slide, here is an explanation of the hierarchy with Rational Software Analyzer rules. Every rule must belong somewhere in the hierarchy. There must be at least one provider, who must have at least one category, who can have many rules. It is up to you on how you want to extend the existing rule providers or create an entirely new provider to implement the plug-in extension.
Setting up a custom plug-in: Extending (3)
Setting up a custom plug-in: Extending (3) Define the rule From the same Extensions tab, create a new Extension for com.ibm.rsaz.analysis.core.analysisRule. In the extension, set this data: id – This must be an unique value. label – This is how the rule shows in Rational Software Analyzer. severity - This sets how important the rule is from a warning to a critical defect. class – This defines the Java class that will define the actual behavior of the rule. You will discuss what needs to be implemented in this class in the next set of slides.
Now you know what category you are going to put your rule in Rational Software Analyzer, but you need to define the rule itself. You can do this by creating a new extension to the Rational Software Analyzer analysisRule. This will tell Rational Software Analyzer what your rule name is and where it is located. However the behavior of the rule will need to be implemented in the Java class. This is where all of the true implementation will take place.
Summary
Summary Custom rules in Rational Software Analyzer are the creation of custom plug-ins. Eclipse has a wizard to aid with the creation of the plug-in. Configuration of the plug-in to extend the rule is done in the plugin.xml file. The actual implementation of the rule is done in the Java class of the rule definition.
This module provided an overview of rules in Rational Software Analyzer. You should now be comfortable with understanding what a rule is and you should know how to write and set up a custom plug-in for a custom rule.
Additional resources
Additional resources Additional resources on ibm.com http://www-01.ibm.com/software/awdtools/swanalyzer/enterprise/index.html http://www-01.ibm.com/software/awdtools/swanalyzer/enterprise/support/ http://www.ibm.com/developerworks/rational/library/08/0429_gutz1/index.html?S_TACT=105AGX54&S_CMP=B0612
Additional resources can be found on the ibm.com Web site and in the Whitepaper on “Static analysis IBM Rational Software Analyzer: Getting started”.
Feedback
Feedback Your feedback is valuable You can help improve the quality of IBM Education Assistant content to better meet your needs by providing feedback. Did you find this module useful? Did it help you solve a problem or answer a question? Do you have suggestions for improvements? Click to send e-mail feedback: mailto:iea@us.ibm.com?subject=Feedback_about_rsar_setting_up_custom_files.ppt This module is also available in PDF format at: ../rsar_setting_up_custom_files.pdf
You can help improve the quality of IBM Education Assistant content by providing feedback.
Trademarks