Saturday, September 21, 2013

FindBug Installation : URL based Installation :


FindBug Installation : URL based Installation :

Step 1 : Go to eclipse Help ---->Install New Software










Step 2 : Use the Url  http://findbugs.cs.umd.edu/eclipse to put into 'Work with'  input field .
Click on  Add Button



Step 3: Fill the Name field with 'Findbug'



Step 4 : Click on Select All option /Or Select the appropriate version and then click next




Step 4: Accept the Agreement





Step 5 : Click Ok




Step 6 : Restart the Eclipse


Thursday, September 19, 2013

Why to Use Findbugs ,PMD and Checkstyle ?


PMD works on source code and therefore finds problems like: violation of naming conventions, lack of curly braces, misplaced null check, long parameter list, unnecessary constructor, missing break in switch, etc. PMD also tells you about the Cyclomatic complexity of your code which I find very helpful (FindBugs doesn't tell you about the Cyclomatic complexity).

FindBugs works on bytecode. Here are some problems FindBugs finds which PMD doesn't: equals() method fails on subtypes, clone method may return null, reference comparison of Boolean values, impossible cast, 32bit int shifted by an amount not in the range of 0-31, a collection which contains itself, equals method always returns true, an infinite loop, etc.
Usually each of them finds a different set of problems. Use both. These tools taught me a lot about how to write good Java code.

Checkstyle : The programming style adopted by a software development project can help to comply with good programming practices which improve the code quality, readability, re-usability, and reduce the cost of development.

Sonar will run CheckStyle, FindBugs and PMD, as well as a few other "plugins" such as Cobertura (code coverage) by default for Java projects. The main advntage is that it stores the history in a database. You can then see the trend

Summery : Conventions (Checkstyle) / Bad practices (PMD) / Potential bugs (FindBugs) .

Monday, September 2, 2013

Creating Finders method and Custom Queries







Creating Finders method and Custom Queries

Process For Finders method
 if you have some Finder methods do the entries like this
After running the service builder build on service.xml
(Copy and paste from XXXLocalServiceUtil ---->  XXXLocalServiceImpl  ) (change accordingly)
Then again  run service builder build .


Copy the finder function from XXXLocalServiceUtil

 public static java.util.List findByN_S(
        java.lang.String name, int status)
        throws com.liferay.portal.kernel.exception.SystemException {
        return getService().findByN_S(name, status);
    }

To XXXLocalServiceImpl after changing in following way

public java.util.List findByN_S(
            java.lang.String name, int status)
            throws com.liferay.portal.kernel.exception.SystemException {
            return ModOrganizationUtil.findByN_S(name, status);
    }

Process For Custom Queries method
Similerly if you have some custom queries for those function do the entries like this
(Copy and paste from XXXFinderImpl  ----->  XXXLocalServiceImpl) (change accordingly)
 Then again  run service builder build .

   public int searchOrg1stLevelCount(String name, String partnerKey, int status,
            java.util.LinkedHashMap searchParams, boolean isAndOperator)
            throws com.liferay.portal.kernel.exception.SystemException {
        return ModOrganizationFinderUtil.searchOrg1stLevelCount(name, partnerKey, status, searchParams, isAndOperator);
    }

Thursday, August 15, 2013

Running a Debug in Eclipse: (Also useful for Remote Java application)



Running a Debug in Eclipse:

(Also useful for Remote Java application)

We just need to connect the sourcecode in eclipse to your eclipse debug (that will automatically detect a running tomcat on your machine) .

*   Open Eclipse 
* Select Debug Configuration (below the Bug Picture)
It opens the following  panel
Select the Remote Java Applications menu from the left panel
Fill the name of the debug in which you want to run
Browse and select the source code on which debug should run
(P.S. You don’t need to change Host and Port generally for any tomcat running on local system)
Click on Debug , and its  Done .

* Note : If an error message appears like following  then your debug is already running.


Go to debug perspective (For both purpose either to close or look into already running Debug)

And Click on this symbol to close the already running Debugger .


Or To Use the Debug , Do some action on the web application ,like in my case I am submitting a form


The Debug appears at the point you added the debug




Press F8 (which is also Resume button),that will take you to the break point from there debug each line with F6.
If you want to go to next break point press F8.



Tuesday, August 6, 2013

Some interesting Eclipse Short-cuts



Shortcut for "Key" related Help :
CTRL + Shift + L.

Function Call Hierarchy :
 CTRL+ALT+H

For adding java doc comments to whole file :
CTRL+ALT+J

Open any file quickly java ,jsp,xml etc :
Ctrl + Shift + R

For Java type in or outside workspace(like in jars) :
 Ctrl + Shift + T

Go directly to a member (method, variable) :
Ctrl + O

jump from one member to the next (or previous) :
Ctrl + Shift + ↓ or Ctrl + Shift + ↑

Go to the last edit location:
Ctrl + Q

Go to a supertype/subtype:
Ctrl + T.

Go to other open editors:
Ctrl + E /

Monday, July 29, 2013

Maven commands needed for a Portlet with service layer



Liferay Service Portlet
---------------------------
When we create a Liferay portlet with service layer is in following structure .

--Root
    --Portlet
    --Service

//This will create the service layers
From Portlet > mvn liferay:build-service

//This will create the jar for the services
From Service > mvn clean package

//This will put the services jar into the folder that will be used for creating war
From Service >mvn install -Dliferay.auto.deploy.dir=(portlet path) -Dfile=.\target\name of the jar file .jar
 
//This will create the war
From Root : mvn clean package

then Copy and  Deploy the war from /target folder

Frequently Needed Maven commands in Liferay :






Steps To Generate Portlet : mvn archetype:generate
(then select appropriate  options by searching liferay )



Steps To Deploy Portlet* : mvn clean install -Dliferay.auto.deploy.dir=(Path of Liferay Deploy Directory)

To Create the War file* : mvn clean package


To install some dependencies jar* : mvn install:install-file -Dfile=D:\jar\util-taglib.jar -DgroupId=com.liferay.portal -DartifactId=util-taglib -Dversion=6.1.20 -Dpackaging=jar
 (DO THIS FOR ALL THE MISSING JARS REQUIRED ,you need to put first manually these jar in some folder(this case D:\jar\ ) than install using above command)


* Need to run all these command from the pom.xml path of the portlet