Sunday, January 25, 2015

Install & Configure Sonar with TFS 2012


This article demonstrates how to configure Sonar with TFS 2012 in Microsoft Windows Server 2008R2 environment with Microsoft SQL Server 2008R2 as the sonar database.

I've skipped the TFS installation and configuration part. You must have a configured TFS 2012 installation, before configuring sonar.


SonarQube Platform Overview
The SonarQube platform is made of 3 components:

1. A database to store:
The configuration of the SonarQube instance (security, plugins settings, etc.)
The quality snapshots of projects, views, etc.
2. A Web Server for users to browse quality snapshots and configure the SonarQube instance
3. One or more Analysers to analyze projects


Configure the Database

1. Open up the SQL Management Studio and create a new login as below.
login name : sonar
password : sonar


2. Create a new database : Database name : "sonar"
3. Create the database user and tick all the permissions


** points noted from sonar documentation:
Note that collation must be case-sensitive (CS) and accent-sensitive (AS).
Install and Configure the Web Server

1. Download and install the latest SonarQube version from here.
2. Create a folder on a disk partition that has a reasonable amount of free space and rename it as "Sonar". Inside of that, create another and rename it to "SonarQube".
3. Extract the downloaded SonarQube binaries inside the "SonarQube" folder.
4. Edit the below file and apply the below configurations.

X:\Sonar\SonarQube\conf\sonar.properties



- Apply the username and the password that was given when you create the sql user.
- Alter the Ms-SQL configuration string as below

#----- Microsoft SQLServer
# The Jtds open source driver is available in extensions/jdbc-driver/mssql. More details on http://jtds.sourceforge.net
# The validation query is optional.
sonar.jdbc.url: jdbc:jtds:sqlserver://<database server>;databaseName=SONAR;instanceName=<database instance>;selectMethod=cursor;
sonar.jdbc.driverClassName: com.microsoft.sqlserver.jdbc.SQLServerDriver
sonar.jdbc.validationQuery: select 1
sonar.jdbc.dialect= mssql

5. Now move to the below folder and create a new folder called "mssql" if it does not already exist.
6. Download Microsoft SQL JDBC Driver and extract the sqljdbc4.jar file to mssql folder.
7. Execute the StartSonar.bat from either x:\Sonar\SonarQube\bin\Windows-x64-64 or Windows-x64-32 depending on your configuration.
8. Then open up a command prompt as run as Administrator and execute InstallNTService.bat located in the folder used in step 7.



9. Restart your PC, and then navigate to http://localhost:9000 (from inside the installed server)
Default Admin user name/password : Admin/Admin


10. Now download and extract the SonaQubeRunner from here and extract to the below folder:
x:\Sonar\SonarQube\sonar-runner-2.4\

11. Replace Ms-SQL section (with what you have used in the previous step)of the configuration file located in the conf folder.


12. Now create a system variable called "SONAR_RUNNER_HOME" and point it to the Sonar Runner folder.

13. Add Sonar-runner bin folder to the "Path" Environment Variable


14. Open-up a new console and type "sonar-runner", if perform some checks.. then you are still on the road.
15. Create a file "sonar-project.properties" add it to the root folder of your Visual Studio solution, and add it to TFS.


16. Add these lines to that file.


17. Another 2 installations are needed to be done.
C# Plugin | Analysis Bootstrapper for Visual Studio Projects Plugin

Copy both downloaded plugins to x:\Sonar\Sonar-runner-2.4\extensions\plugin\ and then restart the SonarQube server.

18. To analyze your C# project. Open up a common prompt and navigate to the folder where your sonar-runner property file is located in. Type sonar-runner and once the analysis is finished, open up the Sonar portal, and you will see a new project is listed.





19. Now the last step, include a post build script in your main project.

20. Final step, create a CI build definition and trigger it, and when the build success, check the  http://<your sonar installed server>:9000, and you will see the project. You can create custom dashboards with inbuilt widgets to get more insight into your code base.

A useful Visual Studio extension called VSSonarExtension can be used to analyse code against the sonar default rules. You can read more about the extension here.

Most of the stuff that I've summarized here were extracted from the below sites :
http://docs.sonarqube.org/display/SONAR/Installing
http://www.sezok.de/sonar/sonar.html


Wednesday, December 10, 2014

Get MEC User Name (USID) inside the Map

There are two ways to retrieve the MEC username inside the MEC mapper.

1. Using a Standard API

    API : CRS008MI - Customer Order Interface
    Transaction: GetUserInfo
    Input: none
    Output Field Which contains USID : ZZUSID

2. Using the build in methods in com.intentia.ec.mapper package

string usid = getMvxUser();  

Sunday, November 16, 2014

MEC How to Get the Last API Name, Status and the Error Message

Recently, I've been working with Logging API errors using another custom M3 API (CRKR03) as a part of MEC development. Some API's had returned NOKs with additional white spaces i.e. TABS and Spaces exceeding the field (MESG) length of the CRKR03 that we have used to log errors.

First, let me explain how I've received the API NOK message by setting the ErrorHandling Property of the M3 API to Ignore M3 NOK.


if(!isLastAPICallOK() && getLastMIProgram().trim().equals("PDS001MI"))
{
    g_ErrorMessage = getLastAPIMessage().trim().replaceAll("\\s+", " ");
    ........ 
}  
Some API NOK messages are like the below (Note the additional white spaces)
'Item number 010411 does not exist                     
                                            
                                            
                                            
              WIT0103          ' 

Monday, November 10, 2014

Get the Inbound Trigger File Name

This article describes how to receive the inbound trigger file name (when using the Disk-in channels mode) using the code.

You can cross-verify the trigger file name by observing the archived manifest from the LifeCycle Manager.
 

Then locate the below value :



You can use the below code to get the trigger file name inside the mapper. (g_ProcessFileName is a string type global variable).

 g_ProcessFileName = getManifestInfo(ManifestConstants.COM_FILENAME);


Similarly, You can get most of the fields shown in manifest by using the getManifestInfo method and the ManifestConstant class. Please note that the ManifestConstants only contains the name of the key/attribute.

Get the UUID of the MEC Process

Recently, We were asked to log the MEC errors to a custom API. MEC process ID was required to be passed into this API as an input parameter.

You can verify the UUID from the LifeCycle Manager.


Using the below code, we could retrieve the UUID inside from the MEC mapper. (g_MapUUID is a global variable)
 g_MapUUID = com.intentia.ec.mapper.Mapping.this.strUUID; 

this variable can be even directly access as below.
 g_MapUUID = strUUID; 

or you can get this by using the manifest and global.
g_MapUUID = getManifestInfo(ManifestConstants.CMN_UUID); 

Please note that the ManifestConstants class contains only the names of the properties.