Exercise 1.3: Defining an architectural control rule
This exercise assumes you have completed Exercise 1.1: Importing the required resources. In Exercise 1.3 you read a user scenario first. Then you assume the role of the software architect described in the user scenario and use the project you imported in Exercise 1.1 to complete the exercise.
User scenario
To prevent extraneous dependencies, the architect wants to put a safeguard in place to ensure that none are introduced into the application. To do this, he creates a rule from a supplied wizard. The rule is to alert him if the utility package becomes dependent on the application package.
After creating the rule, the architect runs a code review by applying it to a code base. The findings will show any extraneous dependencies in the application.
Exercise
In this exercise you perform the following tasks:
- Define a rule based on a supplied wizard.
- Verify that your user-defined rule is added to the Structural Analysis code review.
- Run the Structural Analysis code review.
- View the code review findings that do not adhere to the criteria of your rule.
Defining a rule
To define an architectural control rule based on a supplied wizard:
- On the toolbar in the Code Review view click the Manage Rules icon,
.

- In the Preferences window click New rule. The New Code Review Rule wizard opens.
The New Code Review Rule wizard, as shown in the next screen capture, takes you through a few steps to define your own rule. In this exercise, you will design an architectural control rule to alert you if a dependency between two components is introduced.
- In the Architectural Control list of rules, click Component [dependency] introduced. Notice that when you select this choice, the text below the list tells you to use this template to disallow a dependency between two components. Click Next.

- Under Basic properties, accept the defaults that put the rule in the structural analysis category, with a problem severity level.

- Under Specific properties, specify the independent and dependent components for the rule:
- Independent Component: workspace\StructuralAnalysis\src\com.ibm.r2a.rules.rsa.examples.architecturalcontrol\IndependentComponent.java
- Dependent Component: workspace\StructuralAnalysis\src\com.ibm.r2a.rules.rsa.examples.architecturalcontrol\DependentComponent.java.
- Click Finish.
Seeing your rule added to a code review
- After you define a rule, the Preferences window appears. In the Select Code Review list, click Complete Code Review if it is not already the selected code review. This shows all code review categories.
- Expand the Structural Analysis folder to see the rule you just created.
- Click the rule to see the properties you set for it, as shown in the following screen capture:

Selecting a code review that applies your rule only
To run a code review for your rule only, clear all folders in the list except for the Structural Analysis folder, as shown in the previous screen capture. Click OK.
Selecting a code base to review
To select the workspace as the code base to review:
- On the toolbar in the Code Review view click the Review icon (
) > Review Workspace.
Running the code review
Once you select the code base to review, the code review runs. You can track its status by checking the progress bar in the lower-right corner of the view.
Viewing the code review findings
When the code review is finished, the findings are shown in the Code Review view, as shown in the following screen capture. Below the tab the statistics line summarizes the review.

- Expand the Structural Analysis folder to see the findings in it.

- Double-click the third finding to see the source code for it in the editor, as shown in the following screen capture:

You have completed Exercise 1.3: Defining an architectural control rule.
Leveraging the power of user-defined rules
By creating your own rules, you put custom safeguards in place to monitor the implementation of your design. You can take the following measures:
- Specify criteria for a rule.
- Assign a severity level to the rule: problem, warning, or recommendation.
- Run a code review on your rule or rules only.
Wrapping up Exercise 1.3
You have completed Exercise 2: Defining an architectural control rule. In it you performed the following tasks:
- Defined a rule based on a supplied wizard.
- Verified that your user-defined rule was added to the Structural Analysis code review.
- Ran the Structural Analysis code review.
- Viewed the code review findings that do not adhere to the criteria of your rule.
Now you are ready to begin Exercise 1.4: Resolving a structural problem.