JArchitect Plugin for SonarQube

JArchitect plugin for Sonar

Plugin Prerequisites

  • Install Sonar.
  • Install SonarRunner.
  • Add the SonarRunner bin directory to the PATH environement variable.

Plugin installation and configuration

  • Copy the sonar-jarchitect.jar from $JArchitectInstallDir$/Plugins/Sonar or get it from here to the $SonarQubeInstallDir$\extensions\plugins directory.
  • Define the repository where the JArchitect rules will be loaded to sonar, for that you have just to add the following line to the sonar.properties file configuration.
    sonar.jarchitect.rules=your .jdproj file path

    The jdproj file is the jarchitect project created by the VisualJArchitect GUI.
    It's mandatory to define the sonar.jarchitect.jdproj configuration variable to load jarchitect rules inside sonar.

    You have to log as admin and activate these rules in the profile you want. and to add more rules you have just to add CQLinq rules in the jdproj, restart the sonar server and they will be added to the sonar rules.
  • Restart the sonarqube server.
  • Define the sonar.jarchitect.ConsolePath value in your sonar.project.properties configuration file. The value correspond to the full path of the JArchitect.Console.exe for windows or JArchitectConsole.sh script for linux.
  • Configure the .jdproj file to analyze and there are two ways to do it:
    • Define the sonar.jarchitect.jdproj value in your sonar.project.properties configuration file. The value correspond to the path of your .jdproj file.
    • Pass the sonar.jarchitect.jdproj as argument to sonar-runner
      sonar-runner -Dsonar.jarchitect.jdproj=your .jdproj path
    • When using JArchitect, only byte code (.jar,.war, .ear,..) is mandatory. However for the sonar plugin it's mandatory to define where the source code exist(The source code is automatically detected if you analyze an eclipse or maven projects).

Plugin features
  • Project metrics: the plugin provides some useful design metrics like Afferent coupling (Ca), Efferent coupling (Ce), Relational Cohesion(H), Instability (I), Abstractness (A), Distance from main sequence (D).
    These metrics could be added to the dashbord using the Custom Metrics Widgets

    And the metrics are available from the Design category:

  • JArchitect rules: After defining the sonar.jarchitect.jdproj in the sonar.properties file, the jarchitect rules repository will be added to the sonar rules.
    You have to log as admin in sonar to activate these rules in the profile you want.

  • JArchitect Widgets: The JArchitect sonar plugin provides some useful widgets to explore the JArchitect results:
    • Class Metrics widget:
      JArchitect calculate many interesting class metrics related to their design and implementation, some of these metrics could be discovered by this widget.
    • CQLinq queries widget:
      CQLinq is a powerful feature to create easily coding rules. To explore the results of the CQLinq queries, you have to create a CQLinq group named "Sonar Queries" in your jdproj file and add to it your queries:

      You have to define rules in this group, for that you have to add warnif count>0 at the beginning of your query:

      And add the Queries Widget in your sonar dashboard: