Atomiq is a product by

# Atomiq Console Edition

## Atomiq Console Edition for build servers is the easiest way to reduce code duplication throughout your organization.

With Atomiq Console Edition, every check-in to your automated build server will report the amount of code duplication you have. The report is clean and easy to read and generated automatically for you. You simply add a task to your continuous integration build to launch Atomiq Console Edition with a couple of parameters, specifying the location to analyse, the file types to check, the minimal similarity length, and where you want the output file to be saved.

## Getting Started with Atomiq Console Edition

### Step 1

Copy all of the Atomiq Developer Edition and Atomiq Console Edition files onto a desired location of your build server. The most current version of Atomiq can be found on the download page.

### Step 3

Atomiq Console Edition is not a stand-alone application. It complements the Developer Edition, bringing the power of Atomiq's code analysis to the command line. Before running Atomiq Console Edition, you will first create an Atomiq Project using Atomiq Developer Edition. Once you save an Atomiq project from the Developer Edition, you're ready to run Nitriq Console Edition from the command line.

### Step 4

To run Atomiq Console Edition, open a command prompt and use the following command syntax:

    path\to\Atomiq.Console 1.0.28.90.exe -output path\to\output.html -project path\to\Atomiq_project.atomiqProj -blockNumMax ## -blockSizeMax ## -totalDupeLinesMax ##


The "output" and "project" parameters are required. The destination of the output document is specified in the -output flag. When Atomiq runs, it generates an HTML report file. Simply specify where you want Atomiq to generate this file. The -project flag tells Atomiq which project file to analyze.

Finally, there are three optional parameters. These settings will determine whether or not the analysis will succeed or fail.

• -blockNumMax will cause the analysis to fail if there are more blocks of similar code than the number specified.
• -blockSizeMax will cause the analysis to fail if there are more lines of duplicate code in a single block than the number specified.
• -totalDupeLinesMax will cause the analysis to fail if there are more lines of duplicate code in the entire project than the number specified.

In this example, I have placed Atomiq in C:\Program Files(x86)\Atomiq.Console. Here is what my command looks like:

"Atomiq.Console 1.0.28.90.exe" -output Output.html -project myProject.atomiqProj -blockNumMax 15 -blockSizeMax 40 -totalDupeLinesMax 200

### Step 5

Once Atomiq Console Edition has finished running (it may take a few seconds to complete), you can check the output HTML file to see the results of the analysis.

The top portion of the report displays the number of lines, blocks, and files that contained similar code; the options configured within the project in Atomiq Developer Edition; and the build constraints specified when running the command (with the results of the constraints displayed alongside them). Scrolling down will reveal the top 20 distinct blocks (sorted by size) followed by all of the similarities found within the project. The report details which files were similar, the size of the similar code blocks, and the lines where the code blocks were found.

## How to Incorporate Atomiq Console Edition into your Automated Builds

Now that the basics of Atomiq Console Edition have been covered, here is an example of integrating Atomiq into a continuous integration process. This example uses the open source project MvcContrib with NAnt as the project build tool.

### Step 1

While on your build server, open up Atomiq Developer Edition, select "New" and find the root directory of your project's source code:

### Step 2

Click the "Ok" button, let Atomiq analyze the code files, then save your project. In this example, I'm saving my atmoiqProj file in {projectBaseDirectory}\Atomiq:

### Step 3

You can now exit Atomiq Developer Edition once you have saved everything. If you desire, you can copy the Atomiq.Console.exe and the corresponding license file into the application:

### Step 4

The next step is to set up Atomiq Console in NAnt. In this example, the NAnt files are in the util folder and the project.build configuration file is in the base directory. The project.build file for NAnt that has two targets: Build and RunAtomiqConsole. Taking a look at the project.build file shows how simple it is to include Atomiq as a part of your NAnt build process:

        <target name="RunAtomiqConsole">
<echo message="Running Atomiq Console application" />
<exec
program="Atomiq\Atomiq.Console 1.0.28.90.exe"
commandline="-project Atomiq\example.atomiqProj -output Atomiq\output.html -blockNumMax 15 -blockSizeMax 40 -totalDupeLinesMax 200"
timeout="30000"
failonerror="true"
resultproperty="returnCode">
</exec>
<fail if="${returnCode != '0'}" message="${returnCode}" />
</target>


Simply add a new target that has a path to the Atomiq Console executable and the appropriate command line parameters that were detailed in the first tutorial. Atomiq Console Edition will return a value of zero if none of the build constraints fail.

### Step 5

Executing the RunAtomiqConsole target (path\to\NAnt.exe RunAtomiqConsole) results in the following:

Atomiq Console reported that at least one of its build constraints failed. Taking a look at the output document, we can see that all of them failed:

### Step 6

For the sake of this tutorial, I will simply adjust the build constraints to allow for the amount of similar code contained in the project. After making this adjustment, running NAnt with the RunAtomiqConsole target results in the following:

Success! As you can see, all of the Atomiq build constraints passed, causing NAnt to report a good build.