Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Conditional Content
product: (jtest)
product: (jtest)
sv-attr:0A01020401598D973E6641760F8AF4E50A01020401598D973E671AAA268425A3

Overview

You can specify the input scope for your analysis, which includes the file or set of files to test, as well as the test data location. Use one of the following ways:

  • Use the -resource switch to specify the file or set of files for testing (also see Running Static Analysis 1 for information on pointing to the data location). You can use multiple -resource switches to specify multiple resources.

    Code Block
    -resource [pattern]
  • Configure the jtest.resource property in the .properties file. Separate multiple resources with a comma:

    Code Block
    jtest.resource=pattern1,pattern2

Ant and Maven Pattern

If you use Ant or Maven, you can use the following pattern:

Code Block
<resource>pattern</resource>

You can use the <resources> element to define multiple resources

Code Block
<resources>
    <resource>pattern1</resource>
    <resource>pattern2</resource>
</resources>

Resource Pattern Syntax

Resource patterns are matched to generated paths according to the following convention: 

Code Block
ProjectName/resource/inside/of/project/directory.extension
ProjectName/EXT/resource/inside/of/external/source/directories.extension

The ProjectName value is generated according to following rules:

  • The Ant project name is taken from name property of project tag
  • The Maven project name takes formofgroupId:artifactId
  • The Gradle project name is takenfromgradle.settings file
  • Project names configured in IDEs are fully maintained

You can customize the Maven and Gradle project names with theprojectNameTemplateparameter. For details, see the build system plug-in manuals: [INSTALL]/manuals/ plugins-manual.html. 

Generated paths include the EXT string if the specified scope includes external resources. For example, an analyzed project may include sourcefilesformanotherlocationthatarelinkedto the project. In the following example the Simple.java file is located within the Demo project, whereas the Money.java file has been added by linking and itslocationsisoutsideof the project: 

Code Block
Demo/src/main/java/examples/eval/Simple.java
Demo/EXT/examples/bank/Money.java

You can use Ant-style wildcards and other parameters to refine patterns. The following table describes supported usage:

ParameterDescription
?Wildcard that matches one character (any character except path separators)
*Wildcard that matches zero or more characters (not including path separators)
**Wildcard that matches zero or more path segments.
/Separator for all operating systems
"[non-alphanumeric characters]"Use quotation marks when resource paths contain spaces or other non-alphanumeric characters.

If the -resource argument only contains one value, the value is matched against the project name and a wildcard (*) will be used. The following table shows examples of -resource switch usage.

ExpressionResult
-resource ProjectName/srcAnalyzes every file in the selected directory and subdirectories (withoutwildcards, the complete name of the folder has to be specified).
-resource ProjectName/**/*.javaAnalyzes every Java filefromselectedproject.
-resource **/src/main/java/my/company/*.javaAnalyzes every Java file from the specific subdirectory of every projectincurrentbuild.
-resource ProjectName/src/main/java/my/company/File.javaAnalyzes the single specified resource.
-resource c:/resource.lst

Analyzes the projects listed in the resource.lst file. Specify one project name per line:
ProjectName1
ProjectName2
Provide the path to the file as a value to the -resource argument.

Fine-tuning the Scope

Use the -include and -exclude switches to apply additional filters to the scope.

  • -include instructs Static Analysis Engine to test only the files that match the file system path; all other files are skipped.
  • -exclude instructs Static Analysis Engine to test all files except for those that match the file system path.

If both switches are specified, then all files that match -include, but not those that match -exclude patterns are tested.

Code Block
-include pattern
-exclude pattern

Alternatively, you can specify the pattern in the .properties file with the following options:

Code Block
jtest.include=pattern
jtest.exclude=pattern

Ant and Maven Pattern

If you use Ant or Maven, you can use the following pattern:

Code Block
<include>pattern</include>
<exclude>pattern</exclude>

Use Ant-style wildcards and other parameters to with the -include and -exclude filters. The following table describes their usage:  

ParameterDescription
?Wildcard that matches one character (any character except path separators)
*Wildcard that matches zero or more characters (not including path separators)
**Wildcard that matches zero or more path segments.
/Separator
path:Prefix for matching absolute disk path

You can specify a file system path to a list file (*.lst) to include or exclude files in bulk. Each item in the *.lst file is treated as a separate entry.  

Examples

UsageDescription
-include com/**Tests everything in packages that begin with "com".
-include path:**/Bank.javaTests only Bank.java files
-include path:C:/Project/src/**Tests all subfiles and subdirectories of C:/Project/src
-include path:C:/Project/src/*Tests all files in C:/Project/src, but not subdirectories
-include c:/include.lst

Tests all files listed in include.lst. Each line is treated as a single pattern.
Example:
If include.lst contains the following lines:
**/*Account
path:**/Bank.java
It has the same effect as the following command:
-include **/*Account
-include path: **/Bank.java

-exclude **/internal/**Tests everything except classes that have "internal" as part of the package name.

Creating

Project FilesYou can use the -project.* switch to create a project file, which contains necessary information about executing DTP Engines. Use the -project switch when the solution is not provided. The switch can be used multiple times to analyze many projects. ANT-style wildcards are also supported, as well as paths to *.lst files. The following table describes the parameters for using -project switches

Custom .json Data Files

In typical scenarions, Jtest runs on jtest.data.json data files that are automatically generated by build system plugins. Alternatively, you can manually create a .json file and provide Jtest with the path to that file using the -data command line option (see Running Static Analysis 1).

To manually create a data file Jtest will use for analysis, run jtestcli with the -project options. The available options are listed in the table below.

The example.data.json file is created in the root of the project configured with the -project.location option.

ParameterDescription
-project.location

Required. Enables generation of

a file and indicates where the file will be placed after generation. All other -project.* options are ignored if the -project.location option is not set. 

the .json file by specifying the root of the project.

Provide the absolute path to an existing directory. For example:

-project.location /home/adam/projects/myproject1

(info) All paths included in the Jtest report generated after analysis will be relative to the root of the project configured with this option.

-project.nameSets the project name.
-project.encodingSets the encoding of the project.
-project.sourcepathSets the source of project. Use this option multiple times to specify multiple source folders.
-project.sourcelevelSpecifies the Java compiler compliance level.
-project.classpathSpecifies the classpath.
-project.javahomeUsed to find and add the library to the bootclasspath
-project.classpath.jars.dirSpecifies the path to the directory with jars that should be appended to the project classpath. View the json file to verify the order of the jars and ensure it meets your project requirements.
-project.junit.outcomesSpecifies the path to the XML file with JUnit test results that will be used to generate a report. Use this option multiple times to specify multiple report files.
-project.compilation.classes   Specifies the path to the compiled project classes that will be used to generate metadata information required to perform the "Calculate Application Coverage" configuration.

Example

Code Block
-project.location C:/ExampleProject
-project.name ExampleProject
-project.encoding UTF-8
-project.sourcepath C:/ExampleProject/src
-project.sourcelevel C:/ExampleProject/src-test
-project.classpath C:/ExampleProject/lib/test.jar;C:/ExampleProject/lib/test2.jar
-project.javahome C:/Program Files/Java/jdk1.7