cachedb-import Setup

If your sources are stored in a source control manager and they are in XML format, we need to transform those sources to cls format. In such case, we will do it with cachedb-import. If your soruce is caché database or you are storing sources in cls format, then you can skip this step.

1. Install Git

1.1 Visit Git download page, and the latest git for Windows will start to download automatically

1.2 Install the downloaded exe file, selecting your preferred options

2. Get Gradle

2.1 Visit Gradle download page

2.2 Find the latest binary Gradle version, in this example we will get gradle-4.0.1-bin.zip, to your Downloads folder

2.3 Extracts the downloaded file to C:\sonarqube\gradle (or to C:\gradle if you are using it for a more generic purpose)

3. Define system variables

3.1 Open system properties dialog

3.2 Select Advanced System Settings

3.3 Click on Environment Variables... button

3.4 On the Envirnoment Variable dialog, click on system variables New... button

3.5 Define the GRADLE_HOME variable

3.6 Accept changes and edit Path variable to inlcude %GRADLE_HOME%\bin

3.7 Accept changes and close all dialogs

4. Check Gradle installation

4.1 A quick Gradle version check

> gradle -v
------------------------------------------------------------
Gradle 4.0.1
------------------------------------------------------------

Build time:   2017-07-07 14:02:41 UTC
Revision:     38e5dc0f772daecca1d2681885d3d85414eb6826

Groovy:       2.4.11
Ant:          Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM:          1.8.0_141 (Oracle Corporation 25.141-b15)
OS:           Windows Server 2016 10.0 amd64

5. Get cachedb-import

5.1 Clone the Github project

> git clone https://github.com/litesolutions/cachedb-import.git C:\sonarqube\repositories\cachedb-import

6. Build the project

6.1 Copy cachedb.jar and cachejdbc.jar from your Caché database installation into the lib directory of the cloned project

6.2 Build the jar with gradle. Remember you need JDK8 available on your PATH, and Gradle installed

> cd C:\sonarqube\repositories\cachedb-import
> gradlew.bat shadowJar
:compileJava
:processResources
:classes
:shadowJar

BUILD SUCCESSFUL

Total time: 13.906 secs

6.3 Check the library

> dir C:\sonarqube\repositories\cachedb-import\build\libs
 Volume in drive C has no label.
 Volume Serial Number is AAAA-AAAA

 Directory of C:\sonarqube\repositories\cachedb-import\build\libs

07/20/2017  05:17 PM    <DIR>          .
07/20/2017  05:17 PM    <DIR>          ..
07/20/2017  05:17 PM         2,413,783 cachedb-import.jar
               1 File(s)      2,413,783 bytes
               2 Dir(s)  55,216,111,616 bytes free

7. Prepare the executable environment

7.1 Copy the new library next to sonar path

> mkdir C:\sonarqube\cachedb-import
> copy C:\sonarqube\repositories\cachedb-import\build\libs\cachedb-import.jar C:\sonarqube\cachedb-import

7.2 Prepare the output path

> mkdir C:\sonarqube\cachedb-import\output

8. Setup default configuration

8.1 Create the properties file

C:\sonarqube\cachedb-import\db.properties
# Host where the Caché installation is.
# The default value is localhost.
#host=localhost

# Port to connect to.
# The default value is 1972.
#port=1972

# REQUIRED: Caché user
user=theuser

# REQUIRED: Caché user password
password=thepassword

# REQUIRED: Caché namespace in which the user has execution permissions
namespace=THENAMESPACE

1. Install git

1.1 Use your linux distribution to install git

$ sudo aptitude install git

2. Install Gradle

2.1 Visit Gradle download page

2.2 Find the latest binary Gradle version, in this example we will get gradle-3.2.1-bin.zip via wget command to /tmp folder

$ wget -P /tmp https://services.gradle.org/distributions/gradle-3.2.1-bin.zip

2.3 Extracts the downloaded file to /opt/gradle

$ sudo mkdir /opt/gradle

$ sudo unzip /tmp/gradle-3.2.1-bin.zip -d /opt/gradle

$ ls -la /opt/gradle
total 12
drwxr-xr-x  3 root root 4096 Sep 30 12:28 .
drwxr-xr-x  6 root root 4096 Sep 30 12:28 ..
drwxr-xr-x 10 root root 4096 Jul 27  2015 gradle-3.2.1

2.4 For easy upgrades on future it is highly recommended to create the symbolic link

$ sudo ln -s /opt/gradle/gradle-3.2.1 /opt/gradle/default-gradle

2.5 Include Gradle in the PATH for all users

/etc/profile
JAVA_HOME=/opt/java/default-jdk
export JAVA_HOME

GRADLE_HOME=/opt/gradle/default-gradle
export GRADLE_HOME

if [ "`id -u`" -eq 0 ]; then
  PATH="$JAVA_HOME/bin:$GRADLE_HOME/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
else
  PATH="$JAVA_HOME/bin:$GRADLE_HOME/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games"
fi
export PATH
. . .

After you change the /etc/profile file you need to logout and login again

3. Get cachedb-import

3.1 Clone the Github project

$ sudo git clone https://github.com/litesolutions/cachedb-import.git /opt/repositories/cachedb-import

4. Build the project

4.1 Copy cachedb.jar and cachejdbc.jar from your Caché database installation into the lib directory of the cloned project

4.2 Build the jar with gradle. Remember you need JDK8 available on your PATH, and Gradle installed

$ cd /opt/repositories/cachedb-import
$ sudo gradlew shadowJar

4.3 Check the library

$ ls -la /opt/repositories/cachedb-import/build/libs/
total 2368
drwxr-xr-x 2 root root    4096 Sep  2 13:15 .
drwxr-xr-x 7 root root    4096 Sep  2 13:15 ..
-rw-r--r-- 1 root root 2413323 Sep  2 13:15 cachedb-import.jar

5. Prepare the executable environment

5.1 Copy the new library next to sonar path

$ mkdir /opt/sonarqube/cachedb-import
$ cp /opt/repositories/cachedb-import/build/libs/cachedb-import.jar /opt/sonarqube/cachedb-import
$ chown -R sonar:sonar /opt/sonarqube/cachedb-import

5.2 Prepare the output path

$ mkdir /opt/sonarqube/cachedb-import/output

5.3 Set proper permissions to the output path

$ chmod 774 /opt/sonarqube/cachedb-import/output

6. Setup default configuration

6.1 Create the properties file

/opt/sonarqube/cachedb-import/db.properties
# Host where the Caché installation is.
# The default value is localhost.
#host=localhost

# Port to connect to.
# The default value is 1972.
#port=1972

# REQUIRED: Caché user
user=theuser

# REQUIRED: Caché user password
password=thepassword

# REQUIRED: Caché namespace in which the user has execution permissions
namespace=THENAMESPACE

7. Set cachedb-import ownership

7.1 If you are running the cachedb-import from a Continous Integration server, like Jenkins, you have to set proper ownership to allow the CI server to run. In our example, we will run in Apache Tomcat 8 (see Jenkins Installation), so we must set the tomcat8 group ownership

$ chown sonar:tomcat8 /opt/sonarqube/cachedb-import/output