{"id":426,"date":"2013-04-21T15:20:16","date_gmt":"2013-04-21T14:20:16","guid":{"rendered":"http:\/\/qualilogy.com\/en\/?p=426"},"modified":"2013-09-01T18:25:47","modified_gmt":"2013-09-01T17:25:47","slug":"install-sonarqube-first-analysis-with-sonarqube-runner","status":"publish","type":"post","link":"http:\/\/qualilogy.com\/en\/install-sonarqube-first-analysis-with-sonarqube-runner\/","title":{"rendered":"Install SonarQube &#8211; First analysis with SonarQube Runner"},"content":{"rendered":"<p><a href=\"http:\/\/vicken.deviantart.com\/\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"alignright size-full wp-image-718\" alt=\"SonarRunner1\" src=\"http:\/\/qualilogy.com\/fr\/wp-content\/uploads\/sites\/2\/2013\/04\/SonarRunner1A.jpg\" width=\"350\" height=\"305\" \/><\/a>We have previously installed the <a title=\"The Sonar portal\" href=\"http:\/\/qualilogy.com\/en\/install-sonar-the-sonar-webap\/\" target=\"_blank\">SonarQube portal<\/a> with Tomcat, and the <a title=\"Sonar Runner\" href=\"http:\/\/qualilogy.com\/en\/install-sonar-sonar-runner\/\" target=\"_blank\">SonarQube Runner<\/a>, which will enable us to achieve our first analysis today.<\/p>\n<p><span id=\"result_box\" lang=\"en\"><span class=\"hps\">In the<\/span> <span class=\"hps\">installation folder<\/span> of the <span class=\"hps\">SonarQube<\/span> <span class=\"hps\">Runner,<\/span> <span class=\"hps\">we cand find<\/span> <span class=\"hps\">three<\/span> <span class=\"hps\">directories:<\/span><br \/>\n<\/span><\/p>\n<ul>\n<li><span id=\"result_box\" lang=\"en\"><span class=\"hps\">A directory<\/span> &#8216;<span class=\"hps\">..<\/span><span class=\"hps\">\\<\/span><span class=\"hps atn\">lib&#8217; <\/span><span>dedicated to<\/span><span>.a\u00a0 jar file<\/span> <span class=\"hps\">necessary for the execution<\/span> <span class=\"hps\">of the<\/span> <span class=\"hps atn\">SonarQube-<\/span><span>Runner.<\/span><\/span><\/li>\n<li><span id=\"result_box\" lang=\"en\"><span class=\"hps\">A directory<\/span> &#8216;<span class=\"hps\">..<\/span><span class=\"hps\">\\<\/span><span class=\"hps atn\">conf&#8217; <\/span><span>with<\/span> the <span class=\"hps\">file &#8216;<\/span><span class=\"hps\">sonar<\/span><span class=\"atn\">&#8211;<\/span><span>runner.properties<\/span><span>&#8216;<\/span> <span class=\"hps\">dedicated to the connectiong <\/span><span class=\"hps\">to<\/span> <span class=\"hps\">SonarQube<\/span> <span class=\"hps\">and our<\/span> <span class=\"hps\">database.<\/span><\/span><\/li>\n<li><span id=\"result_box\" lang=\"en\"><span class=\"hps\">A directory<\/span> &#8216;<span class=\"hps\">..<\/span><span class=\"hps\">\\<\/span><span class=\"hps atn\">bin&#8217; <\/span><span>where<\/span> <span class=\"hps\">is located <\/span>a<span class=\"hps\"> file &#8216;<\/span><span class=\"hps\">sonar<\/span><span class=\"atn\">&#8211;<\/span><span>runner.bat<\/span><span class=\"hps atn\">` <\/span><span>which allows us to<\/span> <span class=\"hps\">run an analysis<\/span><span>.<\/span><\/span><\/li>\n<\/ul>\n<p><span id=\"result_box\" lang=\"en\"><span class=\"hps\">Before configuring<\/span> <span class=\"hps\">it<\/span><span>, let<\/span>&#8216;<span class=\"hps\">s pause<\/span> a moment <span class=\"hps\">to think about<\/span> <span class=\"hps\">the organization of our<\/span> <span class=\"hps\">analysis<\/span> <span class=\"hps\">environment.<\/span><\/span><\/p>\n<p><!--more--><\/p>\n<h2>Analysis environment<\/h2>\n<p><span id=\"result_box\" lang=\"en\"><span class=\"hps\">When you install<\/span> <span class=\"hps\">a server<\/span> dedicated to <span class=\"hps\">code analysis<\/span><span>, it is important<\/span> <span class=\"hps\">to differentiate between<\/span> <span class=\"hps\">different<\/span> <span class=\"hps\">spaces according to<\/span> <span class=\"hps\">their purpose<\/span><span>:<\/span> <\/span><\/p>\n<ul>\n<li><span id=\"result_box\" lang=\"en\"><span class=\"hps\">The space for the<\/span> <span class=\"hps\">different software<\/span> <span class=\"hps\">and<\/span> <span class=\"hps\">their versions:<\/span> <span class=\"hps\">Oracle,<\/span> <span class=\"hps\">Java<\/span><span>, Tomcat<\/span><span>, SonarQube<\/span><span>, etc.<\/span><\/span><\/li>\n<li><span id=\"result_box\" lang=\"en\"><span class=\"hps\">The space<\/span> for<span class=\"hps\"> to the<\/span> <span class=\"hps\">delivery<\/span> <span class=\"hps\">and installation of the<\/span> <span class=\"hps\">source code<\/span> <span class=\"hps\">to be analyzed.<\/span><\/span><\/li>\n<li><span id=\"result_box\" lang=\"en\"><span class=\"hps\">The space<\/span> <span class=\"hps\">dedicated to the implementation<\/span> of <span class=\"hps\">analysis<\/span><span>:<\/span> <span class=\"hps\">configuration<\/span><span>, backups,<\/span> <span class=\"hps\">customizations<\/span><span>, reporting<\/span><span>,<\/span>\u00a0<span class=\"hps\">analysis<\/span> <span class=\"hps\">and documentation of your<\/span> <span class=\"hps\">(useful<\/span> <span class=\"hps\">when you begin to have<\/span> <span class=\"hps\">multiple analysis<\/span> <span class=\"hps\">or<\/span> you\u00a0<span class=\"hps\">must<\/span> <span class=\"hps\">work an old analysis<\/span> <span class=\"hps\">or<\/span> <span class=\"hps\">your<\/span> <span class=\"hps\">analysis server<\/span> <span class=\"hps\">is used by<\/span> <span class=\"hps\">different people<\/span><span>)<\/span><span>,<\/span> <span class=\"hps\">etc.<\/span><span>.<\/span><\/span><\/li>\n<\/ul>\n<p><span id=\"result_box\" lang=\"en\"><span class=\"hps\">SonarQube<\/span> <span class=\"hps\">allows us to specify<\/span> <span class=\"hps\">this space in<\/span> <span class=\"hps atn\">the file &#8216;<\/span><span>sonar<\/span><span class=\"atn\">&#8211;<\/span><span>runner.bat<\/span><span>&#8216;,<\/span> <span class=\"hps\">with<\/span> the <span class=\"hps\">variable <\/span><\/span>\u2018PROJECT HOME\u2019.<\/p>\n<p>We will look into this file for the following line:<\/p>\n<p style=\"padding-left: 30px\"><strong>set PROJECT_HOME= %CD%<\/strong><\/p>\n<p>and change it to indicate a subdirectory &#8216;\\Projects&#8217; in which we will place the configuration files of our analyzes. In reality, I would not locate this space in the SonarQube Runner directory, it is only for demonstration purposes.<\/p>\n<p>I modified the file &#8216;sonar-runner.bat&#8217; to insert the following three lines:<\/p>\n<ul>\n<li>Display the \u2018SONAR RUNNER HOME\u2019 folder:<\/li>\n<\/ul>\n<p style=\"padding-left: 30px\"><strong>echo \u201dSONAR_RUNNER_HOME = %SONAR_RUNNER_HOME%\u201d<\/strong><\/p>\n<ul>\n<li>Define the analysis directory \u2018PROJECT HOME\u2019 in a \u2018\\Projects\u2019 directory that we create under the previous folder, and display it:<\/li>\n<\/ul>\n<p style=\"padding-left: 30px\"><strong>set PROJECT_HOME=%SONAR_RUNNER_HOME%\\Projects<\/strong><br \/>\n<strong> echo \u201dPROJECT_HOME = %PROJECT_HOME%\u201d<\/strong><\/p>\n<h2>Configuring our initial analysis<\/h2>\n<p>To perform an analysis, the SonarQube Runner uses the file &#8216;sonar-project.properties&#8217; located in our analysis environment: the directory &#8216;Projects&#8217; created previously. Our goal is to analyze a Java application localized in this directory: &#8216;C:\\SRC\\Demo\\J2EE\\Source\\Extranet\\&#8217;.<\/p>\n<p>If you do not have source code, you can retrieve an example of code and configuration analysis in this page: <a title=\"Page d'exemples Sonar\" href=\"http:\/\/docs.codehaus.org\/display\/SONAR\/Sonar+Project+Examples\" target=\"_blank\">http:\/\/docs.codehaus.org\/display\/SONAR\/Sonar+Project+Examples<\/a>.<\/p>\n<p>Without going into the details of the parameters for an analysis of Java code, we will create the file &#8216;sonar-project.properties&#8217; with the following attributes:<\/p>\n<ul>\n<li>First, some mandatory data: a name \/ a key for this application, and a version number:<\/li>\n<\/ul>\n<p style=\"padding-left: 30px\"><strong># required metadata<\/strong><br \/>\n<strong> sonar.projectKey=EXT<\/strong><br \/>\n<strong> sonar.projectName=Extranet<\/strong><br \/>\n<strong> sonar.projectVersion=1.0<\/strong><\/p>\n<ul>\n<li>The location of the files to analyze:<\/li>\n<\/ul>\n<p style=\"padding-left: 30px\"><strong>sonar.sources=C:\/SRC\/Demo\/J2EE\/Source\/Extranet\/WEB-INF\/src\/<\/strong><\/p>\n<ul>\n<li>Last parameter: the programming language that will decide wich parser SonarQube will use to analyze this application:<\/li>\n<\/ul>\n<p style=\"padding-left: 30px\"><strong>#The value of the property must be the key of the language.<\/strong><br \/>\n<strong> sonar.language=java<\/strong><\/p>\n<h2>Packages and Java classes<\/h2>\n<p>One point to clarify if the Java language is unfamiliar to you. Java classes are organized into packages corresponding to the directories where the Java files are located. This package is shown in the first line of the java program.<\/p>\n<p><a href=\"http:\/\/qualilogy.com\/fr\/wp-content\/uploads\/sites\/2\/2013\/04\/PackageDeclare.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignright size-full wp-image-726\" alt=\"D\u00e9claration de package\" src=\"http:\/\/qualilogy.com\/fr\/wp-content\/uploads\/sites\/2\/2013\/04\/PackageDeclare.jpg\" width=\"332\" height=\"98\" \/><\/a>In this example, the file \u2018J2EEConnection.java\u2019 is located into the directory &#8216;C:\\SRC\\Demo\\J2EE\\Source\\Extranet\\WEB-INF\\src\\com\\extranet\\common\u2019. The root folder that we must precise in our configuration file, is the one immediately abote the directories \/ packages.<\/p>\n<p><a href=\"http:\/\/qualilogy.com\/fr\/wp-content\/uploads\/sites\/2\/2013\/04\/PackageOrg.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-727\" alt=\"Organisation des packages\" src=\"http:\/\/qualilogy.com\/fr\/wp-content\/uploads\/sites\/2\/2013\/04\/PackageOrg.jpg\" width=\"393\" height=\"147\" \/><\/a><\/p>\n<p>If you have any doubt, open a java file and look at the first line. Then navigate to the directory &#8216;father&#8217; of this package: this is the one you must specify in the configuration file.<\/p>\n<p>Normally, it is located in a &#8216;src&#8217; directory, but sometimes this standard is not respected, and the packages are organized in different folders. In this case, you must specify them in the &#8216;sonar-project.properties&#8217;, separated by a comma, as in the following example:<\/p>\n<p style=\"padding-left: 30px\"><strong>sources=..\/src1\/,..\/src2\/<\/strong><\/p>\n<h2>Running our first analysis<\/h2>\n<p>In a DOS command window, we run the &#8216;sonar-runner.bat&#8217; file.<br \/>\nThen, we can see the two variables pointing to the directory SonarQube Runner and our space &#8216;Projects&#8217;, and the configuration file of our analysis:<\/p>\n<p><a href=\"http:\/\/qualilogy.com\/fr\/wp-content\/uploads\/sites\/2\/2013\/04\/SonarRunnerExec1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-729\" alt=\"Ex\u00e9cution Sonar Runner\" src=\"http:\/\/qualilogy.com\/fr\/wp-content\/uploads\/sites\/2\/2013\/04\/SonarRunnerExec1.jpg\" width=\"684\" height=\"291\" \/><\/a><\/p>\n<p>Then, we can see the mention of the name of the project described in the &#8216;sonar-project.properties&#8217; file and the directory corresponding to the parameter &#8216;sonar.sources&#8217;.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-730\" alt=\"SonarRunnerExec2\" src=\"http:\/\/qualilogy.com\/fr\/wp-content\/uploads\/sites\/2\/2013\/04\/SonarRunnerExec2.jpg\" width=\"685\" height=\"253\" \/><\/p>\n<p>When you will see in this log the message \u2018ANALYSIS SUCCESFULL\u2019:<br \/>\n<a href=\"http:\/\/qualilogy.com\/fr\/wp-content\/uploads\/sites\/2\/2013\/04\/SonarRunnerExecFin.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-731\" alt=\"SonarRunnerExecFin\" src=\"http:\/\/qualilogy.com\/fr\/wp-content\/uploads\/sites\/2\/2013\/04\/SonarRunnerExecFin.jpg\" width=\"685\" height=\"90\" \/><\/a><\/p>\n<p>then you can visit the portal and see if SonarQube display the results of your first analysis.<\/p>\n<p><a href=\"http:\/\/qualilogy.com\/fr\/wp-content\/uploads\/sites\/2\/2013\/04\/SonarRunnerResults.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignright size-full wp-image-732\" alt=\"1\u00e8re analyse avec Sonar Runner\" src=\"http:\/\/qualilogy.com\/fr\/wp-content\/uploads\/sites\/2\/2013\/04\/SonarRunnerResults.jpg\" width=\"332\" height=\"136\" \/><\/a>We can see the project name and its version as defined in our configuration file &#8216;sonar-project.properties&#8217;.<\/p>\n<p>We have seen here only the most simple parameters necessary to perform an analysis. There are many others you can look at on this page <a title=\"Analyzing with Sonar Runner\" href=\"http:\/\/docs.codehaus.org\/display\/SONAR\/Analyzing+with+Sonar+Runner\" target=\"_blank\">Analyzing with SonarQube Runner<\/a>.<\/p>\n<p>We were able to carry out our first analysis in the simplest possible way, by setting some parameters required in the &#8216;sonar-project.properties&#8217; file, without the need to manage Maven xml files with a syntax sometimes complex.<\/p>\n<p>However, this approach has a drawback: looking at errors in a DOS window is not very user-friendly, especially for long analysis and \/ or when having many errors.<\/p>\n<p>Fortunately, we will see how to fix it, thanks to our friend Jenkins. This will be in our next post. See you soon.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We have previously installed the SonarQube portal with Tomcat, and the SonarQube Runner, which will enable us to achieve our first analysis today. In the installation folder of the SonarQube Runner, we cand find three directories: A directory &#8216;..\\lib&#8217; dedicated to.a\u00a0 jar file necessary for the execution of the SonarQube-Runner. A directory &#8216;..\\conf&#8217; with the [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-426","post","type-post","status-publish","format-standard","hentry","category-sonar-installation"],"_links":{"self":[{"href":"http:\/\/qualilogy.com\/en\/wp-json\/wp\/v2\/posts\/426"}],"collection":[{"href":"http:\/\/qualilogy.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/qualilogy.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/qualilogy.com\/en\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"http:\/\/qualilogy.com\/en\/wp-json\/wp\/v2\/comments?post=426"}],"version-history":[{"count":15,"href":"http:\/\/qualilogy.com\/en\/wp-json\/wp\/v2\/posts\/426\/revisions"}],"predecessor-version":[{"id":430,"href":"http:\/\/qualilogy.com\/en\/wp-json\/wp\/v2\/posts\/426\/revisions\/430"}],"wp:attachment":[{"href":"http:\/\/qualilogy.com\/en\/wp-json\/wp\/v2\/media?parent=426"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/qualilogy.com\/en\/wp-json\/wp\/v2\/categories?post=426"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/qualilogy.com\/en\/wp-json\/wp\/v2\/tags?post=426"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}