Integrate JArchitect with AppVeyor


Integrate JArchitect with AppVeyor


This awesome in-depth tutorial is based on the NDepend (JArchitect like for .Net) integration written by Jimmy Pelletier.


In this documentation I provide step by step instructions on how to integrate JArchitect into your CI pipeline for quality control and historical analytics. For quality control I will demonstrate how to fail your build when violating an JArchitect rule and for historical analytics we will publish the JArchitect report as a build artifact.


Prerequisites & Assumptions

In order to follow along with the steps provided in this article there are a few prerequisites. You will need:

  • A Java project of some kind checked into GitHub.

  • A DevOps license key. To obtain such file contact us at support@codergears.com. If you are in trial period let us know your company name and postal address in the email. Else if you own a DevOps license key, let us know your license key in the email.

I have also assumed you know how to work with Java and Git.


Go to top


Making the tools available during the build

In order to run JArchitect as part of your build pipeline you will need to make the JArchitect.Console.exe available to run during the build. When working with a cloud build agent like AppVeyor, options for installing tools and setting up the environment are limited. We’ll simply be checking JArchitect into source control. First download the JArchitect Installer. Then copy its content into a tools directory. I put mine in ./tools/JArchitect. You will also need to activate your DevOps license key.


Create an JArchitect project

To do anything with JArchitect we need to create an JArchitect project. The way to get this done is to:

  • Install JArchitect,;

  • Select your project.

  • Click “Analyze Project”.

  • Select “Edit Project” from the “Project” menu,

  • Select “Paths Referenced” on the right hand side.

  • Select each path listed and Right click to select “Set as Path Relative (to the JArchitect Project File Location)”.

  • Save your changes.
An JArchitect Developer license is needed to do these steps. If you only have DevOps licensing you can still create a JArchitect project from VisualJArchitect.exe Start Page > New JArchitect project, and then populate the list of projects to analyze. In such situation you'll still need to set paths referenced as relative to the JArchitect Project File Location, as explained above.


Go to top


Create your build script

Next we need to add a build script to tell AppVeyor how to build your project. Full details of how AppVeyor build scripts work can be found in the AppVeyor documentation but the one I’ll include here is pretty self explanatory and is correct at the time of writing (September 2018). The file is placed in the root of the repository and is called appveyor.yaml.

The interesting thing to note is that we need to resolve the full absolute path of the JArchitect project file to pass in to JArchitect. Notice that here our JArchitect project file is named SomeProject.jdproj.


Go to top


Setting up AppVeyor and our first build

Next we need to set up our GitHub repo to build in AppVeyor.

  • Log in or sign up to AppVeyor using your GitHub account.

  • Click “New Project” from the home screen.

  • Add your project from the list of repos available from your GitHub account.

  • Click “New Build”.

Go to top


Failing the build

JArchitect will now fail on any Quality Gate failure. AppVeyor terminates a build upon a command that returns a non-zero exit code. At least one Quality Gate failing means that JArchitect.Console.exe will return a non-zero exit code as explained in Quality Gates and Build Failure.

Thus, the easiest way to test build failure is to modify the “Critical Issues” quality gate. First remove the predicate that restricts this rule to considering only critical issues. Then reduce the failif threshold so it will fail on a single issue. With the default rule set and nearly any solution this should be enough to trip the quality gate. Your Quality Gate CQLinq query should now look like this:

// <QualityGate Name="Critical Issues" Unit="issues" />
failif count > 1 issues
warnif count > 0 issues
from i in Issues
select new { i, i.Severity, i.Debt, i.AnnualInterest }

Go to top


Publishing the JArchitect report

To publish the JArchitect report we need a bunch of files the JArchitect writes to ./JArchitectOut during the build process. AppVeyor allows us to zip these files up and present them for download. Add the following to the end of your appveyor.yaml file:

artifacts:
  - path: JArchitectOut
    name: JArchitectOut
    type: zip

Then download the zip file from the “Artifacts” tab on a completed build and extract it to view the html report.