Total Pageviews

Showing posts with label Tools. Show all posts
Showing posts with label Tools. Show all posts

2014/12/09

Utilize CLOC(Count Lines of Code) to count lines of code

Requirement
If I would like to count lines of code for each Java program in my Java project, which tool can help me?

Solution
Go to http://cloc.sourceforge.net/ to download exe file (i.e. cloc-1.62.exe).

Assume cloc-1.62.exe had been saved into D:\software
Assume the Java project located in D:\workspace2\ave\ave-webapp\src\main\java
  • Step1. open command prompt.
  • Step2. Change directory to Java project directory, i.e. D:\workspace2\ave\ave-webapp\src\main\java
  • Step3. Execute this command: d:\software\cloc-1.62.exe . --by-file

Check the result:
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
D:\workspace2\ave\ave-webapp\src\main\java>d:\software\cloc-1.62.exe . --by-file
      94 text files.
      94 unique files.
       8 files ignored.

http://cloc.sourceforge.net v 1.62  T=0.32 s (296.3 files/s, 60038.9 lines/s)
------------------------------------------------------------------------------------------------------------
File                                                                     blank        comment           code
------------------------------------------------------------------------------------------------------------
.\gov\nta\ave\web\rest\Ave102eResource.java                                369            299           1505
.\gov\nta\ave\web\rest\Ave104eResource.java                                195            235            907
.\gov\nta\ave\web\rest\Ave103eResource.java                                198            235            891
.\gov\nta\ave\web\rest\Ave101eResource.java                                199            242            890
.\gov\nta\ave\web\rest\Ave106eResource.java                                188            148            783
.\gov\nta\ave\web\rest\Ave401eResource.java                                212            234            772
.\gov\nta\ave\web\rest\Ave201eResource.java                                110             91            576
.\gov\nta\ave\web\rest\Ave105eResource.java                                 85             16            405
.\gov\nta\ave\web\controller\Ave608rReportController.java                  107            114            338
.\gov\nta\ave\web\controller\Ave201eReportController.java                   69             38            334
.\gov\nta\ave\web\rest\Ave904eResource.java                                 57             71            309
.\gov\nta\ave\web\rest\Ave903eResource.java                                 80             23            251
.\gov\nta\ave\web\controller\Ave114rReportController.java                   58             43            227
.\gov\nta\ave\web\controller\Ave613rReportController.java                   54             37            194
.\gov\nta\ave\web\controller\Ave401eReportController.java                   70             38            178
.\gov\nta\ave\web\rest\Ave121eResource.java                                 46             26            168
.\gov\nta\ave\web\rest\Ave115qResource.java                                 31             38            168
.\gov\nta\ave\web\rest\Ave907eResource.java                                 45             66            157
.\gov\nta\ave\web\rest\Ave117rResource.java                                 50             43            150
.\gov\nta\ave\web\controller\Ave609rReportController.java                   33             35            148
.\gov\nta\ave\web\controller\Ave108rReportController.java                   35             41            147
.\gov\nta\ave\web\controller\Ave116rReportController.java                   43             24            146
.\gov\nta\ave\web\rest\Ave909eResource.java                                 39             13            140
.\gov\nta\ave\web\controller\Ave611rReportController.java                   30             12            137
.\gov\nta\ave\web\controller\Ave502rReportController.java                   40             30            117
.\gov\nta\ave\web\controller\Ave105eReportController.java                   24              2            112
.\gov\nta\ave\web\controller\Ave610rReportController.java                   40             29            111
.\gov\nta\ave\web\rest\Ave905eResource.java                                 31              4            108
.\gov\nta\ave\web\controller\Ave605rReportController.java                   24             16            104
.\gov\nta\ave\web\rest\Ave112qResource.java                                 32             25            100
.\gov\nta\ave\web\controller\Ave117rReportController.java                   17             11             82
.\gov\nta\ave\web\rest\Ave501eResource.java                                 14              0             78
.\gov\nta\ave\web\controller\Ave607rReportController.java                   20             10             75
.\gov\nta\ave\web\dto\Ave102eFormBean.java                                  40             32             75
.\gov\nta\ave\web\rest\Ave114rResource.java                                 16             25             73
.\gov\nta\ave\web\controller\Ave601rReportController.java                   17              2             71
.\gov\nta\ave\web\rest\Ave901eResource.java                                 15              0             71
.\gov\nta\ave\web\controller\Ave602rReportController.java                   17              2             71
.\gov\nta\ave\web\rest\Ave110qResource.java                                 19              1             70
.\gov\nta\ave\web\dto\Ave106eFormBean.java                                  26             16             68
.\gov\nta\ave\web\controller\Ave405rReportController.java                   18             10             67
.\gov\nta\ave\web\rest\Ave122qResource.java                                 14              8             67
.\gov\nta\ave\web\controller\Ave406rReportController.java                   23              4             67
.\gov\nta\ave\web\rest\Ave111qResource.java                                 17              1             64
.\gov\nta\ave\web\controller\Ave612rReportController.java                   17             11             61
.\gov\nta\ave\web\controller\Ave604rReportController.java                   16              1             58
.\gov\nta\ave\web\controller\Ave403rReportController.java                   18             12             56
.\gov\nta\ave\web\dto\Ave101eFormBean.java                                  14              7             56
.\gov\nta\ave\web\dto\Ave103eFormBean.java                                  14              7             56
.\gov\nta\ave\web\dto\Ave104eFormBean.java                                  14              7             56
.\gov\nta\ave\web\controller\Ave408rReportController.java                   18             11             55
.\gov\nta\ave\web\controller\Ave603rReportController.java                   14              0             53
.\gov\nta\ave\web\controller\Ave410rReportController.java                   15             21             53
.\gov\nta\ave\web\controller\Ave606rReportController.java                   16             10             52
.\gov\nta\ave\web\controller\Ave115qReportController.java                   14              9             46
.\gov\nta\ave\web\controller\Ave107rReportController.java                   12              5             46
.\gov\nta\ave\web\controller\Ave904eReportController.java                   14              1             45
.\gov\nta\ave\web\rest\Ave902eResource.java                                 10              0             45
.\gov\nta\ave\web\controller\Ave113qReportController.java                   11              6             44
.\gov\nta\ave\web\dto\Ave201eFormBean.java                                  19             12             43
.\gov\nta\ave\web\controller\Ave203rReportController.java                   16             16             43
.\gov\nta\ave\web\controller\Ave501eReportController.java                   11              0             42
.\gov\nta\ave\web\controller\Ave903eReportController.java                   13              1             41
.\gov\nta\ave\web\controller\Ave901eReportController.java                   14              0             36
.\gov\nta\ave\web\controller\Ave402rReportController.java                   11              0             36
.\gov\nta\ave\web\controller\Ave303rReportController.java                   10              0             35
.\gov\nta\ave\web\controller\Ave302rReportController.java                   11              2             33
.\gov\nta\ave\web\rest\Ave113qResource.java                                  8             14             32
.\gov\nta\ave\web\controller\Ave404rReportController.java                    8              7             31
.\gov\nta\ave\web\controller\Ave204rReportController.java                    9              7             30
.\gov\nta\ave\web\controller\Ave202rReportController.java                    6              0             30
.\gov\nta\ave\web\controller\Ave407rReportController.java                    8              1             28
.\gov\nta\ave\web\controller\Ave301rReportController.java                    9              1             28
.\gov\nta\ave\web\controller\Ave409rReportController.java                    9              1             28
.\gov\nta\ave\web\dto\Ave608rFormBean.java                                  21              0             24
.\gov\nta\ave\web\dto\Ave609rFormBean.java                                  19              0             22
.\gov\nta\ave\web\dto\Ave401eFormBean.java                                  19              0             22
.\gov\nta\ave\web\dto\Ave903eFormBean.java                                  16              0             19
.\gov\nta\ave\web\dto\Ave121eFormBean.java                                  14              0             18
.\gov\nta\ave\web\dto\Ave613rFormBean.java                                   7              0             18
.\gov\nta\ave\web\dto\Ave610rFormBean.java                                  10              0             13
.\gov\nta\ave\web\dto\Ave105eFormBean.java                                   7              0             11
.\gov\nta\ave\web\dto\Ave122qFormBean.java                                   6              0             10
.\gov\nta\ave\web\dto\Ave907eFormBean.java                                   4              0              8
.\gov\nta\ave\web\dto\Ave113qFormBean.java                                   4              0              7
.\gov\nta\ave\web\dto\Ave905eFormBean.java                                   2              0              7
.\gov\nta\ave\web\dto\Ave203rFormBean.java                                   2              0              7
.\gov\nta\ave\web\dto\ComboboxDto.java                                       4              0              7
.\gov\nta\ave\web\dto\Ave606rFormBean.java                                   2              0              7
.\gov\nta\ave\web\dto\Ave404rFormBean.java                                   2              0              7
.\gov\nta\ave\web\dto\Ave403rFormBean.java                                   3              0              6
.\gov\nta\ave\web\rest\package-info.java                                     0              5              1
.\gov\nta\ave\web\controller\package-info.java                               0              3              1
.\gov\nta\ave\web\dto\package-info.java                                      0              3              1
------------------------------------------------------------------------------------------------------------
SUM:                                                                      3388           2571          13086
------------------------------------------------------------------------------------------------------------

D:\workspace2\ave\ave-webapp\src\main\java>


Reference
[1] http://cloc.sourceforge.net/

2014/10/21

How to copy text from Notepad++ to Microsoft Word and keep its color to distinguish keywords


Notepad++ can distinguish between different languages source code can be written in. For example, a language could distinguish certain keywords that have to be differently interpreted, and as such it can be useful to distinguish these keywords using another color or font. 


For example.
The language is Java.

The language is SQL.


Scenario
If we would like to copy SQL statement from Notepad++ to Microsoft Word in my system design document, but it seems cannot keep its color to distinguish keywords. 
For example.

Resolution
Step1. Select text you would like to copy.

Step2. Plugins --> NppExport --> Copy RTF to clipboard

Step3. Paste text to Microsoft word


2014/10/15

JRebel - Reload any changes without restart server

As a developer, we do not want to waste time to restart server again and again to see the implace of code changes.
You can try JRebel to save your time.

If you are using Eclipse, here has good step-by-step installation and configuration guide: http://manuals.zeroturnaround.com/jrebel/ide/eclipse.html

For more information, please check http://zeroturnaround.com/software/jrebel/learn/

Demo

Here has code snippet, and it will print debug message as entering this method
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
  @RequestMapping(value = "/query/tab1", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)  
  public @ResponseBody  
  List findTab1(@RequestBody Fms420rFormBean formBean, Alerter alerter) {  
    log.debug("test");  
    List dataList = service.queryTab1(formBean.getYear(), formBean.getMonth());  
    if (CollectionUtils.isEmpty(dataList)) {  
      alerter.info(Messages.warning_notFound());  
    } else {  
      alerter.info(Messages.success_find());  
     }  
     return dataList;  
   } 

And the console will print "test" debugging message as entering this method:
1:  19:15:45,493 INFO [stdout]  [20123] DEBUG gov.nta.fms.web.rest.Fms420rResource - test  

In order to test JRebel, I just modified the debug message to "JRebel test" and submit query without restart application server
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
 @RequestMapping(value = "/query/tab1", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)  
 public @ResponseBody  
 List findTab1(@RequestBody Fms420rFormBean formBean, Alerter alerter) {  
   log.debug("JRebel test");  
   List dataList = service.queryTab1(formBean.getYear(), formBean.getMonth());  
   if (CollectionUtils.isEmpty(dataList)) {  
     alerter.info(Messages.warning_notFound());  
   } else {  
     alerter.info(Messages.success_find());  
    }  
    return dataList;  
  } 
 
See....I don't redeploy and restart application server, but the console print the up-to-date debug message. 
1:  19:16:19,742 INFO [stdout]  [20123] DEBUG gov.nta.fms.web.rest.Fms420rResource - JRebel test  

It's because of JRebel reload any changes classes automatically. 
When you change any class or resource in your IDE, the change will reflect in you application immediately, skipping the build and redeploy phases.




2014/04/16

CronMaker - a utility which helps you to build cron expressions

It's a good utility to build cron expression as I use Quartz to write batch program.
http://www.cronmaker.com/

2014/02/20

Online SQL Formatting Tool

In some situations, we may need to figure out the report bugs via extracting SQL statement from console or log file. But the SQL statement normally does not have any formatting, and hard to read. It may lead to more debug time to spend. 

Here is a helpful SQL formatting tool: http://sqlformat.appspot.com/

Copy your SQL statement into this text area

Click Format SQL button or use Ctrl+F hotkey

The formatting SQL statement will show in the button of page

2014/02/07

Quick way to build prototypes - Moqups

Official site - https://moqups.com/home/

Moqups is a nifty HTML5 App used to create wireframes, mockups or UI concepts, prototypes depending on how you like to call them.


You can use Moqups to build prototype quickly to confirm user requirement as bellowing:



2012/07/27

Clear IE Cache Through Command Line

Scenario
Owing to Microsoft IE will cache JavaScript, CSS files, so it may not recognize when we update JavaScript or CSS files. 
We need to clear browser cache every time, when we update JavaScript or CSS files.

Solution
Windows provides command line to clear IE cache
  • All : RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 255 
  • History : RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 1
  • Cookies : RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2
  • Temp Internet Files : RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8
  • Form Data : RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 16
  • Passwords : RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 32
We need to clear cookies and temp internet files, so we copy the two commands into text file, and save as a bat file. Then move to C:\

And create a shortcut on your desktop.

As you need to clear browser cache, just click the batch file. It will clear cookies and temp internet files automatically.



2012/04/12

Apache Commons應用 - CollectionUtils

Requirement
報表輸出結果,應該依序輸出「營業事業所得稅」、「綜合所得稅」、「遺產稅」、「贈與稅」、「貨物稅」、「菸酒稅」、「證券交易稅」、「期貨交易稅」、「營業稅」、「特銷稅」。如果沒有資料,該稅別要顯示出來,數字要顯示0。結果如下,


根據user requirement要求的輸出結果,並不是按照tax code或者tax name的筆劃順序進行排序,此部份必須要根據query回來的的結果來做加工。

Problem
原本的作法是用SQL將統計資訊算出來,但是其只會傳回有存在的資料,若沒有符合條件,就不會回傳資料,故只有回傳兩筆資料。

從SQL回傳回來的結果會是一個List of value object,以目前的條件,只會有兩個value object,分別是「營利事業所得稅」與「期貨交易稅」。


Solution
由於資料固定只有10筆,放在SQL裡頭做的話,SQL會很複雜,日後維護不易,故此部份的資料加工放在AP端進行處理。
  1. 建立一個新的List物件, List result = new ArrayList();
  2. 根據回傳回來的list of value object來進行判斷
    1. List中是否有「營業事業所得稅」的資料
      • 若「有」,從List中找出該object,並add到新的List物件
      • 若「無」,add一筆空的資料到新的List物件
    2. List中是否有「 綜合所得稅 」的資料
      • 若「有」,從List中找出該object,並add到新的List物件
      • 若「無」,add一筆空的資料到新的List物件
    3. List中是否有「 遺產稅 」的資料
      • 若「有」,從List中找出該object,並add到新的List物件
      • 若「無」,add一筆空的資料到新的List物件
    4. 「 贈與稅 」、「 貨物稅 」、「 菸酒稅 」、「 證券交易稅 」、「 期貨交易稅 」、「 營業稅 」、「 特銷稅 」依此類推

Apache Commons有提供CollectionsUtils此API,其提供不少utility method來針對Collection物件進行一些處理,根據以上需求有兩個:

  1. 從List中check是否有存在特定的object
  2. 從List中取得特定的object

//List中是否有「營業事業所得稅」的資料
1:  private static boolean is35Exist(List list) {  
2:      return CollectionUtils.exists(list, new Predicate() {  
3:        @Override  
4:        public boolean evaluate(Object obj) {  
5:          NIG630ReportBean bean = (NIG630ReportBean) obj;  
6:          return "營利事業所得稅".equals(bean.getTaxNm());  
7:        }  
8:      });  
9:    }  

//從List中找出該object
1:  private static NIG630ReportBean find35(List list){  
2:      return (NIG630ReportBean) CollectionUtils.find(list, new Predicate() {  
3:        @Override  
4:        public boolean evaluate(Object obj) {  
5:          NIG630ReportBean bean = (NIG630ReportBean) obj;  
6:          return "營利事業所得稅".equals(bean.getTaxNm());  
7:        }  
8:      });  
9:    }  





2011/09/07

How to Automatically Add Javadoc and File Headers to Your Source Code

Problem
In our project, we need to fix all checkstyle checking errors. One of the most annoying error is missing a Javadoc comment.





Solution
We can install an Eclipse Plugin, JAutodoc, to help us.
JAutodoc is an Eclipse Plugin for automatically adding Javadoc and file headers to your source code. It optionally generates initial comments from element name by using Velocity templates for Javadoc and file headers.
Official site: http://jautodoc.sourceforge.net/index.html


Where to download?





How to Install?
1. Before you install, please shutdown your eclipse
2. copy two jar files to plugins folder
3. copy one feature folder to features folder

4. Restart Eclipse


How to Use?
Select a single or multiple class(es): right click --> JAutodoc --> Add Javadoc


 JAutodoc will generate comments from element name as shown below
 
 JAutodoc will generate comments from method name as shown below






2011/07/30

Java Tools: Source Code Optimization and Analysis


Below is a list of some tools that can help you examine your Java source code for potential problems:

2011/04/07

Utilize Recursive Java Decompiler to Decompile Jar File



2. Unzip jd-gui-0.3.3.windows.zip and execute jd-gui.exe

3. assign jar file which you want to do decompile



4. File --> Save All Sources




6. Install Doxygen

7. Assign project name, source code directory, destination directory. And check "Scan
recursively"


8. Change to "Mode", and do some configuration

9. Change to "Output", and do some configuration

10. Change to "Diagram", and do some configuration

11. Click "Run" tab, and click "Run doxygen"

12. Check result

2011/01/07

Utilize JDeveloper and SchemaSpy to maintain database schema & document

Scenario
1. I need to change database schema frequently, and add comments for each column (it does not have any comments originally).
2. I have to deliver the up-to-date schema document to customer.

Solution
1. Use JDeveloper to maintain database schema and add comments for each column.
2. Use SchemaSpy to generate the up-to-date database schema [Concerning SchemaSpy, please refer to http://albert-myptc.blogspot.com/2010/12/schemaspy-quick-start.html]


Prerequisite

1. Download JDeveloper from http://www.oracle.com/technetwork/developer-tools/jdev/downloads/soft11-098086.html

2. Launch JDeveloper after you installed it

3. JDeveloper workspace

4. Setup database connection

5. Check the connection in Database Navigator

5.Create a new Project

6. Choose "Generic Project", and click OK

7. Click Finish

8. Project had been created

9. Create Database Diagram from project




Before change
I would like to add three columns to NIGT036, and add comments for each column.

Use JDeveloper to change database schema
1. Select specific table --> Column --> Add

2. Assign "Column Name", "Data Type", "Precision", and then click Apply

3. Check the result

4. Add comments for each column

5. Assign Comment and then click Apply

Generate the latest schema document via SchemaSpy
1. execute the command:
java -jar "C:\schemaSpy_5.0.0.jar" -dp "C:\ojdbc6.jar" -t orathin -db dev02 -s ap_tax -host 192.168.30.102 -port 1521 -u ap_tax -p taxtest -schemas AP_TAX -connprops "C:\schemaSpyGUI\properties\orathin.properties" -i "NIG.*" -charset UTF-8 -o "C:\schemaSpyGUI\output" -norows -hq

You can get more information about this command from http://schemaspy.sourceforge.net/

2. check the result