Your most unhappy customers are your greatest source of learning.

Showing posts with label sonar. Show all posts
Showing posts with label sonar. Show all posts

How to upgrade sonar ?

1.    Take backup of current sonar filesystem & DB.
2.    Unzip sonar351 (Your current sonar version) in /opt/ folder.
3.    Shutdown Sonar.
4.     Update the content of the sonar.properties and wrapper.conf files located in the     {$NEW_SONAR_HOME}/conf directory according of the content of the related files in the {$OLD_SONAR_HOME}/conf directory
5.    Copy the directories extensions/plugins and extensions/rules from {$OLD_SONAR_HOME} to {$NEW_SONAR_HOME} (if you see problems while starting, try to remove the copied plugins from the extensions/plugins-directory and reinstall the plugins manually via the webinterface)
6.    Update sonar.properties with ldap settings
7.    Update sonar with http://url/setup
8.     Rename /opt/sonar351 to /opt/sonar
9.    Start Sonar

No relationship between generic parameter and method argument

Hi All,

If you are usinf findbugs to check code quality,
you may see violations like "No relationship between generic parameter and method argument".

Since Map.get() is not fully generic, we often find cases where a developer passed a different type of object (and hence bugs). Frequency of such cases went up when we started using artifacts/services from other teams. What are the reasons why Map.get(Object key) is not (fully) generic explains why get() is not fully generic.




Here's a helper method that provides checked access:

public static <K, V> V safeGet(Map<? super K, ? extends V> map, K key) {
    return map.get(key);
}
 
Sample Usage:
Map<List<String>, Date> map = new HashMap<List<String>, Date>();
// this compiles:
Date date = safeGet(map, Arrays.asList(""));
// this doesn't
Date date2 = safeGet(map, "foo");

jacoco code coverage with Ant - Sonar

Here is the detail for how to setup code coverage using jacoco plugin which is OOB come out with SONAR :

  1. Write sample java project called ant-jacoco-codecoverage
  2.  Project folder structure would be given as below snapshot:
  3. Under the target folder you may have to create classes & reports folders where reports folder will have one more folder called junit
  4. Write sample Java class One.java in src folder you can copy paste below code  :
    1. public class One {
        String message = "foo";
        public String foo() {
          return message;
        }
        public void uncoveredMethod() {
          System.out.println(foo());
        }
      }

What is LCOM4 ?

Hi Everybody,

If you want to know about the LCOM4(Lack of Cohesion of Methods) which sonar having , please see below example:

Cohesion is the degree to which the methods of a single class are tight together. When two methods in a class do not use a common attribute or a common method, it means that they share nothing and should probably not belong to the same class to respect the Single Responsibility Principle. In other words you can split your class into several new classes to gain modularity at class level.

LCOM4 lack of cohesion example

  • LCOM4=1 indicates a cohesive class, which is the "good" class.
  • LCOM4>=2 indicates a problem. The class should be split into so many smaller classes.
  • LCOM4=0 happens when there are no methods in a class. This is also a "bad" class.
There is not any magic here, only common sense. Let’s take a simple example with class Driver. This class has two fields : Car and Brain, and five methods : drive(), goTo(), stop(), getAngry() and drinkCoffee(). Here is the dependency graph between those components. There are three blocks of related components, so LCOM4 = 3, so the class seems to have three different responsibilities and breaks the Single Responsibility Principle.


Hope this will helpful to you to understand the LCOM4 concept which can be used for any programming language.

Switchoff plugin for sonar

Guys

Have you ever been tried to use switch off plugin of sonar ?

This plugin is really helpful when you switch-off any specific violation from the specific line or specific files.
I really liked this plugin.

See below details to get it installed :

LDAP integration with Sonar

If you want to integrate LDAP directory server with sonar, you can follow below steps.
Its very easy and useful for sonar security:


1) First start your Sonar and login with admin credentials.
2) Go Configuration >> Update Center and click on Available plugins and install LDAP plugin
3) Now stop your sonar server
4) open sonar.properties file and append below code
sonar.authenticator.class: org.sonar.plugins.ldap.LdapAuthenticator
sonar.authenticator.createUsers: true
ldap.url:ldap://ldap.xyz.com:389
ldap.baseDn:ou=People,ou=google,dc=google,dc=com
ldap.bindDn:CN=manager,DC=google,DC=com
ldap.bindPassword:abc123
ldap.loginAttribute: mail

5)Now start sonar server again and check sonar server log if any error comes.


Enjoy !!!!!

Best,
Jignesh

Welcome

You will find all the infomation related to sonar and jenkins

Most Reading

 

Like Me & Share

Buy Websites PRchecker.info

category

Members

Ranks