Sunday, May 23, 2010

How to recover deleted file in Eclipse ?


Suppose you have deleted any file by mistake. That file was not checked in in the SVN/CVS and your manager/team lead calling you for status........ what the hell is........ but if you used Eclipse then no need to worry.This tutorial explain you how to do that.....
You can recover deleted file in eclipse means deleted files can be restored from the local history of Eclipse.
Following are the screen shots that show how to recover deleted files in eclipse.

1) Let this is your folder structure of Eclipse Project.





2) Let you have deleted ThreadDemo.java File from Eclipse IDE by mistake.






3) You clicked on the OK button, Now you realized that it was not useless file. You need it. now what to do........





4) Finally you have deleted file..... don't worry, eclipse is with you........ It store all files in its temp folder for some time. We can recover from Eclipse. Now start operation.........
    right clicks on the Eclipse project and select "Restore From local history"



5) You'll get list of all deleted files in eclipse ........., Select the files that you like to Restore and clicks on the "Restore" button.




6) Thanks god it is eclipse...... :)


Saturday, May 8, 2010

How to find Cut and Paste Code in Eclipse Using PMD ?

PMD is is great tool for finding code violation and many other defects before product release( If you have not installed then follow this link How to install PMD in Eclipse ? ). One of that feature is find the repeated cut and paste code. Cut/copy/paste is very bad programming practice. Repeated (Cut&Paste) code generally indicates poor planning or team coordination. Therefore we should be refactor our code to remove that bad practice.Refactoring classes with repeating code should be given a high priority. PMD is very effective to find out such classes by scanning the code in a way similar to PMD violation checks. The number of lines of similarity (the metrics used by PMD to match code patterns) is 25 by default and can be set in PMD's Preferences page.
  1. Start Eclipse
  2. First Go to the package explorer and Right Click on your project and select PMD | Find Suspect Cut And Paste
            
                  




  3. PMD creates a folder reports under your project and stores the result text file



  4. Select Window | Show View | Navigator
  5. In Navigator view click on Your Project and then on the reports folder
  6. The report file cpd-report.txt should look like this:
    Found a 5 line (15 tokens) duplication in the following files:
    Starting at line 21 of G:\besthowtodo\workspace\HelloDynaWeb\src\com\besthowtodo\tutorials\dynaweb\DemoPMDThread.java
    Starting at line 25 of G:\besthowtodo\workspace\HelloDynaWeb\src\com\besthowtodo\tutorials\dynaweb\DemoPMDThread.java
          public void WRITE_SOMETHING_WITH_COPY_PASTE(String INPUT_PARAMETER) {
                 System.out.println(INPUT_PARAMETER);
          }
          public static void main(String[] args) {


How to Generating PMD Reports InEclipse ?

You have configured and found the all violation but I think you also like to save all that data for future reference. You can do this without using any other tool. For situations of this kind PMD provides a handy reporting tool it is able to generate reports in multiple formats. Currently PMD can generate reports in HTML, XML, plain text as well as Comma Separated Value (CSV) formats.
  1. Right Click on the java project in the project explorer and select PMD | Generate reports
  2. It creates a report folder in your application and create violation report.
  3. Select Window | Show View | Navigator
  4. In Navigator view click on Project and then on the reports folder
  5. That folder content same report in different format one of them html format. It is something like: