How To Write a Custom Audit

Part 4: Deploying the Audit to Together

The previous parts of this tutorial explained all the coding for the audit. This part explains the deployment steps. Two more files are required:

Together needs the two files in order to locate and use your new audit.

  1. You can create the JAR file within Together. From the main menu, choose File > Export.

  2. In the resulting dialog, choose JAR file and click Next. The JAR Export page opens.

  3. In the Select resources to export list on the left, check CustomAudit.

  4. The right side of the dialog has a list of project resources. Uncheck .classpath and .project since these files do not need to be in the JAR file.

  5. In the Select the export destination field, click Browse to find the destination for the JAR:

    $Together_home$\eclipse\plugins\com.togethersoft.sapient.audit


    Together scans for audits in this directory. Here, you find the audit.jar file that contains all the standard audits that come with Together as well as any additional JAR files added for custom audits.

  6. In the File name field, enter the JAR name, example.jar. Then click Save.

  7. Make sure that the option Export generated class files and resources is checked. Your dialog should be similar to the following.

    JAR package specification

  8. Click Finish. This creates the JAR file in the proper place.

  9. Now, create the audit XML plugin file. In the UML Explorer view, right click on the CustomAudit project, and choose New > Other.

  10. In the resulting dialog, choose Simple > File, and click Next.

  11. In New File dialog, click the CustomAudit project. In the File name field, enter example.xml.

  12. Click Finish. The newly created empty file opens in the editor.

  13. Click the Source tab at the bottom of the editor. Then copy and paste the following text into the file:

      <?xml version="1.0"?>
      <plugin>

       <inspector id="Audit">
        <category id="CS" description="Coding style">
         <analyzer id="EM" name="Empty Method" implementation="EmptyMethodRule" library="example.jar">
          <parameter type="string" name="severity" value="Info" />
         </analyzer>
        </category>
       </inspector>
      </plugin>


    The category tag determines the category in the QA preferences where the user selects which audits to apply. While you could create an entirely new category, this example simply uses an existing category, Coding style.

    The analyzer tag defines the audit's abbreviation, name, and the JAR where it is located. The abbreviation and name display on the audit tab for QA preferences, under the Coding style group.

    The parameter tag sets the default severity for the audit.

  14. Save the audit plugin XML file. Then copy it to the same directory as example.jar:

    $Together_home$\eclipse\plugins\com.togethersoft.sapient.audit


    Together scans the audit directory looking for audits, using the XML files in the audit directory to determine which audits to load and where to find them. Together can find example.xml file and load the audit from example.jar.

Part 5: Using the Audit