AppPerfect

Code Analyzing a Project

This tutorial provides a brief introduction to the AppPerfect Java Code Test product using a set of hands-on practice exercises. This tutorial assumes you have successfully downloaded and installed AppPerfect Java Code Test on your machine with the default options. Apart from this pre-requisite, this tutorial is self contained. Instructions given below are Windows-specific; if you are using a non-Windows machine, please use equivalent commands/instructions.

This document is divided into following sections

  1. Creating Project
  2. AppPerfect Java Code Test

Within each section, multiple exercises are listed. Each exercise forms a logical unit which is expected to take no more than a few minutes to perform. All exercises use the PetStore demo application running inside Apache Tomcat. The modified PetStore application and Tomcat are both bundled with this product.

All exercises assume you have installed the product in C:\AppPerfect\CodeTest folder and will be referred as CodeTest_HOME henceforth in tutorial. If you have installed the product in some other folder, modify the instructions below appropriately.

This tutorial is not intended as a comprehensive training guide. Please refer to the product documentation for detailed information. However, this tutorial will give you a very good overview of the products and substantially improve your productivity with the product.

Creating Project
Exercise 1: Launch AppPerfect Java Code Test
  1. Click on Start -> Programs ->AppPerfect Code Test x.x.x -> AppPerfect Java Code Test
  2. On launching AppPerfect Java Code Test a Welcome page will be displayed. Go through the brief description given for product.
    NB: Welcome page is displayed only when Code Test x.x.x is launched and last time no project was opened.
Exercise 2: Creating a Project
  1. Launch the Project Wizard by clicking File ->New... menu option. The New Project wizard will be launched.
  2. Go through the instruction provided on top of the General tab.
  3. Keep the default project name and location for the purpose of this exercise. We don't have to provide "Notification" settings or "Remote Application/AppServer" settings for this exercise. Click on the Next button.
  4. For this exercise we don't need to import any IDE project. Click on the Next button.
  5. In the Source tab click on the "Add File" button on the r.h.s., select "Files of type:" as *.jsp in the Open dialog and add jsp files from the location "CodeTest_HOME\tomcat\webapps\petstore"
  6. Now click on the "Add Folder" button on the r.h.s. and select the folder "CodeTest_HOME\tomcat\webapps\petstore\src". Click the Next button.
  7. Use the default JDK which is bundled with AppPerfect Java Code Test and click on the Next button.
  8. In the "Environment" tab we will provide the classpath for the sources added in the project.
  9. Click on the "Add File" button on the r.h.s. and navigate to the location - "CodeTest_HOME\tomcat\webapps\petstore\WEB-INF\lib" - select all the jars present in the "lib" folder.
  10. Click on the "Add File" button on the r.h.s. and navigate to the location - "CodeTest_HOME\tomcat\lib" - select "ant.jar", "el-api.jar", "jsp-api.jar" and "servlet-api.jar" jars and add them to classpath.
  11. Click on "Verify Classpath" button to validate the classpath.
  12. Classpath validation dialog will be launched and the classpath will be verified. A message saying that the classpath specified is correct should be displayed. Click on the "OK" button. Click on the Next button.
  13. In the "Target" tab select project type as "SERVER".
  14. Keep the default URL in the "Starting URL" field i.e., "http://localhost:8380/petstore". Select the "AppServers Settings" tab.
  15. Select the "Specify AppServer Settings" checkbox and select "Tomcat_5.x/6.x" from the drop down menu.
    NB: This is required only if you want to launch AppServer automatically while profiling, recording and replaying in AppPerfect Unit Tester or if you want to profile AppServer in AppPerfect Java Profiler.
  16. Specify the Server Home path - "CodeTest_HOME\tomcat" and the "Startup file" for the server - "CodeTest_HOME\tomcat\bin\catalina.bat".
  17. Select the "Launch server automatically (When required)" checkbox. Click on the Finish button.
  18. If applications asks for Starting URL validation, click on 'No' button. Normally Confirmation for Starting URL validation is not asked when "Launch server automatically (When required)" is checked. A confirmation message saying that the project is saved will be displayed. Click on the OK button.

Now using this Project we will create tests to demonstrate the functionalities of AppPerfect Java Code Test product.

AppPerfect Java Code Test

NB: Please follow the steps provided in the "Creating Project" section to first create a Project, then proceed further.

Exercise 1: Define a Java Code Test project
  1. Once the Project is successfully created another dialog - Define Project Properties - will be displayed.
  2. Read the instructions at top of each tab.
  3. In the General tab select analyze JSP files and specify following path - "CodeTest_HOME\tomcat\webapps\petstore" as Document Root folder.
  4. In the Rules tab, we need to choose the rules that need to be applied to the selected source files. Scroll through and review all the rules. For this exercise, apart from the selected default rules we will select one more rule viz.,'Declare_variable_final'. To do this, right click on any of the rule and select 'Find...' option from the popup menu. Type the rule name 'Declare_variable_final' in the 'Find Node:' text field. The rule will be listed below. Select the rule from the list. The rule will be highlighted in the Rules tree. Click the Close button to close the Find dialog. Mark check the rule for it to be applied for the test. Select Auto-Fix tab.
  5. In this tab, we need to choose the rules which should auto fix their violations. Right click on any of the rule and select 'Find...' option from the popup menu. Type the rule name 'Declare_variable_final' in the 'Find Node:' text field. The rule will be listed below. Select the rule from the list. The rule will be highlighted in the Rules tree. Click the Close button to close the Find dialog. Mark check the rule for it to be applied for the test. Keep the default options selected related to prompting before auto-fixing the rule and backup of your original code. The backup of your code is stored as a .java.BAK file in the same folder as the original file. Click OK.
  6. Now all the JSP & Java files which were added to the Source in the Project Wizard will be displayed in the Source tab.
  7. Click through all the menu items to familiarize yourself with the available features and how to access them. Viewing through all menu items will provide a reasonable overview of the application.
  8. The central concept of code analysis is Java coding rules. AppPerfect Java Code Test defines over 750 coding rules that are applied to your source code to identify issues. These rules can be viewed by clicking on Project -> Rules Manager... menu item. Detailed description, sample code, etc. are provided.
  9. Click on Tools ->Options... menu item. Click on the JDKs tab and ensure that the JDK path has been set correctly. This is the path provided for JDK during installation of AppPerfect Java Code Test. You may modify the path or add new JDK through this dialog box. It is critical that a correct version of JDK is available for AppPerfect Java Code Test to perform correctly.
  10. Click Help -> Table of Contents menu item to see AppPerfect Java Code Test product documentation.
Exercise 2: Perform Code Analysis, View and Analyze results
  1. To analyze the project, click on Project -> Run. As source files are being analyzed, output is displayed in the "Java Code Test Console" screen.
  2. Auto-Fix confirmation dialog will be displayed showing the Rule being violated, a short description for the rule, Original violated code and a suggested fix for the violation. Click on "Stop auto-fixing" button of the dialog. We will not Auto-Fix for this project.
  3. As rules violations are detected, they are added to the list in the main Window. Once the analysis is completed, you will see 'Finished Analyzing' in the status bar at the bottom.
  4. To view rules violations based on source files, click on Source tab at top left and select any of the files in the tree on the left. Files with rule violations are marked with a red flag mark. Files with no rule violations are marked with a green flag mark.
  5. To view rules violations based on rules, click on Rules tab at top left and select any of the rules in the tree on the left. Rules which were violated are marked with a red flag mark. Rules which were not violated are marked with a green flag mark. Click on any of the rules to see details about which files violated that rule.
  6. To view other available results, click on the other tabs shown on the right hand side view.
  7. We recommend that users fix rules violations based on the rules violation severity. Hence, fix "Critical" category rules violations first, then move on to "High", etc.
Exercise 3: Perform Auto-Fix
  1. Auto-Fix can be done only for Java files, it is not supported for JSP files.
  2. Select CheckForm.java in the Source tab. The Violated rules are displayed in the Violations tab of the main panel on the r.h.s. frame.
  3. Right click on the rule "Declare_variable_final" and select Fix Rule Violations -> This Line.
  4. A Auto-fix confirmation dialog will be displayed showing the Rule being violated, a short description for the rule, Original violated code and a suggested fix for the violation. Click Ok.
  5. Now select the Auto fixes tab. The auto fix details will be displayed here.
  6. Right click on the Auto fixed code in the Auto fix tab. Select Restore File option to restore the original file. This will revert the changes done by Auto fix. Now, you can see the violated rule for the line in the violations tab.
Library z-lib
We use cookies for analytics, advertising and to improve our site. By continuing to use our site, you accept to our Privacy policy and allow us to store cookies.