This guide will help you execute a custom rule analysis in Kiuwan Analyzer.
If you need more information on programming a rule, please check the Getting Started with Rule Development page.
For rule development you need the following prerequisites:
The rules that Kiuwan executes are created using the Java language. A Kiuwan rule is composed by:
In this section, we will create a Java project in Eclipse that will contain both parts of the rule. We will use for this guide the Eclipse Luna Standard, but you can use any Eclipse version or any other IDE or editor you like following an equivalent process:
This is all that we need in the IDE part. Now we will launch Kiuwan Rule Developer and work simultaneously with both tools to create rules.
The Kiuwan Rule Developer is a GUI tool that will help you create, run and edit rules that can be executed in a Kiuwan analysis.
Once you have installed or upgraded Kiuwan Local Analyzer, follow these steps to run Kiuwan Rule Developer:
The Kiuwan Rule Developer user interface is divided into three areas:
The first thing we will do is configure the Kiuwan Rule Developer to synchronize with an IDE. In this case, we will use the Eclipse project we have created before.
Once the IDE and Kiuwan Rule Developer are wired, we can create a new rule definition.
After saving the rule, two files will be created:
Once the new rule window is closed, Kiuwan Rule Developer will be prepared to execute your rule's implementation. But we first need to create that implementation.
Back to Eclipse, you should refresh to project contents to see the files created by Kiuwan Rule Developer.
In our example, Kiuwan Rule Developer has created the following files:
If you open the rule base code file, you will see the basic rule template. This is where you should add the code to detect the violations you want to find in your Java code. For more information on this topic, check the Getting Started with Rule Development guide.
In our example, we want to detect the uses of System.out.print(String) and System.out.println(String) in Java code. So this will be the source code for our rule:
Eclipse compiles the rules as we save changes in the file (you should have the Build automatically option turned on, under the Project menu), so we already have a .class file in the build folder that Kiuwan Rule Developer can execute.
Note that you can access the Kiuwan API Javadoc anytime from your IDE, as we configured the Javadoc Location of the analyzer.jar file when we created the New Java Project, in the "Preparing your IDE" section.
Switch back to Kiuwan Rule Developer.
We will need a source code to test the rule against. We will copy the code example we entered when we created the rule in the new rule dialog:
As you can see in the previous screenshot, the "Rule execution results" tab will be automatically selected with the results of applying the rule to the test source code. In our example, one violation will be detected in line 4. This line uses one of the methods the rule looks for.
You can modify the rule in your IDE and execute it in Kiuwan Rule Editor as many times as you need until you are satisfied with your rule's implementation. Kiuwan Rule Editor automatically detects changes in the compiled code, as long as you have correctly configured your IDE as we did in the previous sections.
Read more here: Debug custom rules
Once we are happy with our rule, the next step is to upload the rule definition to Kiuwan.
After following the previous steps, everything should be prepared to run a new analysis with Kiuwan Local Analyzer.
Once your application has assigned the new quality model, we have to create a package with our rule so Kiuwan Local Analyzer can execute it.
Now everything should be prepared to launch your analysis.
The next step is to run Kiuwan Local Analyzer and analyze your application. If you need more information on this topic, please read the Kiuwan Local Analyzer page.
We will use a test application made of two Java classes. One with a rule violation, one with no violations. We will call this application Test application.
Follow these steps to analyze the application in Kiuwan Local Analyzer:
3. and 4.
Once the analisis is done, you can check the results by clicking View results. A browser window will open and the Kiuwan web page will appear with the results of the analysis.
Access the Defects section to see a defect emitted by the custom rule you have just created with Kiuwan Rule Developer.
In this quick start guide, we have seen how to create, modify, pack, install and execute a custom rule for Kiuwan. We can summarize the needed steps in the following list:
The next steps you should follow are:
Read the Getting Started with Rule Development guide.