7.1.5. Import Modules Using the Build Unit(s) Importer

You can import Java modules based on build units into an existing Sonargraph system or while creating a new system.

Note: This importer can only work when you have previously build your system (hence the name). Java class and source files are analyzed to obtain class and source root information. A build unit contains Java class and corresponding source roots and corresponds to a module.

In a multi-module system setup normally the modules share common root directory structures (or definitions). The following root directories could be used in such a multi module system:

  • ./src/main/java (Java production code)

  • ./src/test/java (Java test code)

  • ./target/generated (generated Java code)

  • ./target/classes (compiled Java production code)

  • ./target/classes-test (compiled Java test code)

The main idea of the build unit importer is to collect at least 1 root directory containing compiled Java code (i.e. byte code) and at least 1 root directory containing corresponding Java source code. The common root directory of both would compromise the module root directory. So lets say the directory 'Common' contains './src/main/java' and './target/classes' containing byte code and source code the build unit import would recognize 'Common' as a build unit (i.e. module) with 2 root directories.

The build unit importer uses 2 important terms:

  • Root Segment

    Begins with '/' followed by full directory name or a part of it. It has only 1 '/'! It is used to recognize Root Definitions.

    In order to recognize './src/main/java' from the above example it would be necessary to define 3 root segments: '/src', '/main' and '/java'.

  • Root Definition

    './src/main/java' from the above example would be a root definition. It consists of 1 or more '/' and full directory name pairs.

In general the following 3 steps need to be performed:

  • Select the directory containing the build units you want to detect. The wizard will detect Class/Source Root Definitions based on predefined Root Segments. The Root Segments can be modified to obtain better Class/Source Root Definition matches. This will trigger the re-detection of Class/Source Root Definitions. In Unassigned Class/Source Roots you will see all roots that are currently not assigned to any module candidate.

  • Adjust the Root Segments and/or Class/Source Root Definitions (via context menu entries 'Add...', 'Edit...' and 'Delete') and rerun the import candidate detection until you obtain the desired Sonargraph import candidates (i.e. modules and class/source root directories).

  • Tweak the obtained Sonargraph import candidates by including/excluding selected entries.

Some things to keep in mind:

  • The wizard detects only the root directories that are not already contained in the Sonargraph workspace.

  • Modules containing only source roots are not checked by default, since Sonargraph needs the class files too.

  • Module candidates can be renamed via the context menu 'Edit...' entry.

  • To reset the wizard to it's initial state simply open the 'Select Directory' dialog and close it with 'Cancel'.

  • You can either modify Root Segments, Root Definitions or both to obtain the desired Sonargraph import candidates.

  • In the Root Segments and Root Definitions viewers you can use a search widget to find entries. Ctrl+Shift+F on Windows and Linux and Cmd+Shift+F on Mac.