### Installation

To install, simply unzip the contents of the distribution zip file into a directory and choose one of the various methods for running Simian:

- Command line interface
- Ant task
- Checkstyle plugin
- IntelliJ integration
- Programmatic Interface
- Maven
- Eclipse plugin

### Command Line Interface

This method allows you to execute Simian from the command line, shell scripts, batch files, etc. scanning a directory for all files matching a pattern.

The general form for the Java version is:

        java -jar simian.jar [options] [files]

And for the .NET version is:

        simian.exe [options] [files]

The `files` can be specified as any regular shell glob or simply a list of files and can be mixed with the `-includes` option. (See below for examples.)

For example, to find all java files in all sub-directories of the current directory:

        "**/*.java"

To find all java files in the current directory and set the threshold to 3:

        -threshold=3 "*.java"

To find all C# files in the current directory:

        "*.cs"

To find all C and header in all sub-directories of the current directory:

        **/*.c **/*.h

To find all java files in two different directories:

        "/csharp-source/*.cs" "/java-source/*.java"

To find all java files in all sub-directories, excluding Test classes:

        -includes=**/*.java -excludes=**/*Test.java

To find all java files in the current directory and ignore numbers:

        -ignoreNumbers "*.java"

To find all java files and display the results in xml format:

        -formatter=xml "*.rb"

To find all ruby files and sends the results in emacs compatible format to a file:

        -formatter=emacs:c:\temp\simian.log "*.rb"

To read configuration from a file (where each line of the file specifies at most one of any of the valid command-line arguments):

        -config=simian.config

### Notes

For most projects (including the nearly 400,000 LOC JDK 1.4 source base), the default VM size seems to be adequate. If you encounter:

        Exception in thread "main" java.lang.OutOfMemoryError

you will need to increase the VM heap size using the `-mx` JVM option.

### Ant Task

This method allows you to integrate Simian with the Ant, a java based build tool.

Somewhere in your build.xml file, define the task:

        <taskdef resource="simiantask.properties" classpath="simian.jar"/>

And finally, create a target to run the checker. For all defaults:

        <simian>
            <fileset dir="./main" includes="**/*.java"/>
        </simian>

To exclude test classes if they exists in the same tree as the source:

        <simian threshold="6">
            <fileset dir="./main" includes="**/*.java" excludes="**/*Test.java"/>
        </simian>

To change the minimum number of lines that is considered a match:

        <simian threshold="6">
            <fileset dir="./main" includes="**/*.java"/>
        </simian>

To force the language used for processing:

        <simian language="java">
            <fileset dir="./main" includes="**/*.*"/>
        </simian>

To have the build fail one or more matches are found:

        <simian failOnDuplication="true">
            <fileset dir="./main" includes="**/*.java"/>
        </simian>

To set a build property if one or more matches are found:

        <simian failureProperty="test.failure">
            <fileset dir="./main" includes="**/*.java"/>
        </simian>

By default, Simian outputs plain text using the default Ant logger. You can override this by using the nested `formatter` element. The `formatter` takes a `type` (either `"plain"`; `"xml"`; `"emacs"`; `"vs"`; or `"yml"`) and an optional filename (`toFile`). For example, to send output to a file:

        <simian>
            <formatter type="plain" toFile="simian-log.txt"/>
        </simian>

To produce XML output:

        <simian>
            <formatter type="xml" toFile="simian-log.xml"/>
        </simian>

You may specify any number of formatter elements allowing you to produce both XML and plain text output if necessary

### Checkstyle Plugin

This method allows you to integrate Simian with Checkstyle 3+. A remarkable java based code checker.

First, ensure the simian.jar file is on the classpath. Next, add the check to your configuiration file. (Note: The plugin runs as a FileSetCheck):

        <module name="Checker">
            ...

            <module name="au.com.redhillconsulting.simian.SimianCheck"/>
        </module>

To change the minimum number of lines that is considered a match:

        <module name="au.com.redhillconsulting.simian.SimianCheck"/>
            <property name="threshold" value="6"/>
        <module/>

To force the language used for processing:

        <module name="au.com.redhillconsulting.simian.SimianCheck"/>
            <property name="language" value="java"/>
        <module/>

### IntelliJ Integration

This method allows you to integrate Simian with IntelliJ as an external tool. This will then allow you to run simian from within IntelliJ and go straight to any matches by clicking on the file location.

This is really a short-cut way to define the tool using `Options|External Tools`.

Open the `_.xml` file in the `config/tools` directory of the your intellij settings (usually under the intellij home directory or under your home directory as `.IntelliJIdea`).

Add the following block:

        <tool name="Simian" showInMainMenu="true" showInEditor="true" showInProject="true"
              showInSearchPopup="true" disabled="false" useConsole="true" synchronizeAfterRun="true">
        <exec>
          <option name="COMMAND" value="$JDKPath$\bin\java.exe" />
          <option name="PARAMETERS" value="-jar simian.jar $FileDir$\**\*.java" />
          <option name="WORKING_DIRECTORY" />
        </exec>
        <filter>
          <option name="NAME" value="Duplicate Location" />
          <option name="DESCRIPTION" value="" />
          <option name="REGEXP" value=" Between lines $LINE$ and [0-9]* in $FILE_PATH$" />
        </filter>
      </tool>

Make sure to put the full path to simian.jar in the `PARAMETERS` option and the appropriate java runtime in the `COMMAND` option.

The `PARAMETERS` follows the general form of the command line interface allowing you to set parsing options, threshold, etc.

Re-start IntelliJ and you can click on `Tools|Simian`.

You should be able to click on the matching lines and go straight to the source code.

Java and all Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries.
.NET and all .NET-based marks are trademarks or registered trademarks of Microsoft® in the United States and other countries.
Copyright (c) 2003-07 RedHill Consulting Pty. Ltd. All rights reserved.