Groovy対応のステップカウンター

毎日ではないが、Groovyのスクリプトを書いてたりするので、どのくらいの量を書いたかを
知りたい。
成長を数字で実感したいのだ。
だが、Groovyに対応しているステップカンターが意外とない。


今使っているAmateras StepCounterを改造して、Groovyのステップ数もカウントできるようにした。


ベースは、Version 1.16(Eclipse 3.0以上/NetBeans 5.0向け) を使用した。
1.17、2.0だと手持ちのPHPのソースの中に含まれる[]をどうやら
カテゴリと認識して、想定しない動きをしてしまう箇所があるため。



チェックアウト

mkdir D:\workspace_other\amateras\stepcounter\tags\1.16
cd /d D:\workspace_other\amateras\stepcounter\tags\1.16
svn co https://amateras.svn.sourceforge.net/svnroot/amateras/stepcounter/tags/1.16/tk.eclipse.plugin.stepcounter/ tk.eclipse.plugin.stepcounter/
'https://amateras.svn.sourceforge.net:443' のサーバ証明書の認証中にエラーが発生しました:
 - 証明書は信頼のおける機関が発行したものではありません。証明書を手動で認証
   するためにフィンガープリントを用いてください!
証明書情報:
 - ホスト名: *.svn.sourceforge.net
 - 有効範囲: Mon, 04 Jan 2010 06:21:55 GMT から Sat, 05 Feb 2011 01:03:23 GMT まで
 - 発行者: Equifax Secure Certificate Authority, Equifax, US
 - フィンガープリント: ea:d1:3e:01:cc:16:e9:9b:c2:ab:4b:0c:cc:26:5f:25:78:ea:89:b4
拒否しますか (R)、一時的に承認しますか (t)、常に承認しますか (p)? t
A    tk.eclipse.plugin.stepcounter\.classpath
A    tk.eclipse.plugin.stepcounter\plugin_ja.properties
A    tk.eclipse.plugin.stepcounter\.project
A    tk.eclipse.plugin.stepcounter\stepcounter.jar
A    tk.eclipse.plugin.stepcounter\src
A    tk.eclipse.plugin.stepcounter\src\tk
A    tk.eclipse.plugin.stepcounter\src\tk\eclipse
A    tk.eclipse.plugin.stepcounter\src\tk\eclipse\plugin
A    tk.eclipse.plugin.stepcounter\src\tk\eclipse\plugin\stepcounter
A    tk.eclipse.plugin.stepcounter\src\tk\eclipse\plugin\stepcounter\StepCountView.java
A    tk.eclipse.plugin.stepcounter\src\tk\eclipse\plugin\stepcounter\StepCounterPluginResources.properties
A    tk.eclipse.plugin.stepcounter\src\tk\eclipse\plugin\stepcounter\StepCountAction.java
A    tk.eclipse.plugin.stepcounter\src\tk\eclipse\plugin\stepcounter\StepCounterPlugin.java
A    tk.eclipse.plugin.stepcounter\src\tk\eclipse\plugin\stepcounter\StepCounterPluginResources_ja.properties
A    tk.eclipse.plugin.stepcounter\src\tk\stepcounter
A    tk.eclipse.plugin.stepcounter\src\tk\stepcounter\DefaultStepCounter.java
A    tk.eclipse.plugin.stepcounter\src\tk\stepcounter\PythonCounter.java
A    tk.eclipse.plugin.stepcounter\src\tk\stepcounter\ant
A    tk.eclipse.plugin.stepcounter\src\tk\stepcounter\ant\StepCounterTask.java
A    tk.eclipse.plugin.stepcounter\src\tk\stepcounter\StepCounterFactory.java
A    tk.eclipse.plugin.stepcounter\src\tk\stepcounter\Main.java
A    tk.eclipse.plugin.stepcounter\src\tk\stepcounter\gui
A    tk.eclipse.plugin.stepcounter\src\tk\stepcounter\gui\ConfigManager.java
A    tk.eclipse.plugin.stepcounter\src\tk\stepcounter\gui\MainWindowListener.java
A    tk.eclipse.plugin.stepcounter\src\tk\stepcounter\gui\StringUtility.java
A    tk.eclipse.plugin.stepcounter\src\tk\stepcounter\gui\MainWindow.java
A    tk.eclipse.plugin.stepcounter\src\tk\stepcounter\CountResult.java
A    tk.eclipse.plugin.stepcounter\src\tk\stepcounter\format
A    tk.eclipse.plugin.stepcounter\src\tk\stepcounter\format\CSVFormatter.java
A    tk.eclipse.plugin.stepcounter\src\tk\stepcounter\format\ResultFormatter.java
A    tk.eclipse.plugin.stepcounter\src\tk\stepcounter\format\DefaultFormatter.java
A    tk.eclipse.plugin.stepcounter\src\tk\stepcounter\format\FormatterFactory.java
A    tk.eclipse.plugin.stepcounter\src\tk\stepcounter\AreaComment.java
A    tk.eclipse.plugin.stepcounter\src\tk\stepcounter\StepCounter.java
A    tk.eclipse.plugin.stepcounter\src\tk\stepcounter\Util.java
A    tk.eclipse.plugin.stepcounter\.template
A    tk.eclipse.plugin.stepcounter\plugin.properties
A    tk.eclipse.plugin.stepcounter\build.properties
A    tk.eclipse.plugin.stepcounter\icons
A    tk.eclipse.plugin.stepcounter\icons\stepcounter.gif
A    tk.eclipse.plugin.stepcounter\.cvsignore
A    tk.eclipse.plugin.stepcounter\plugin.xml
A    tk.eclipse.plugin.stepcounter\.settings
A    tk.eclipse.plugin.stepcounter\.settings\org.eclipse.jdt.core.prefs
A    tk.eclipse.plugin.stepcounter\.settings\org.eclipse.core.resources.prefs
A    tk.eclipse.plugin.stepcounter\build.xml
リビジョン 2132 をチェックアウトしました。

改造対象ソース

D:\workspace_other\amateras\stepcounter\tags\1.16\tk.eclipse.plugin.stepcounter\amateras\stepcounter\tags\1.16\tk.eclipse.plugin.stepcounter\src\tk\stepcounter\StepCounterFactory.java

追加箇所

diff U3 C:/Documents and Settings/orangeclover/Local Settings/Temp/StepCounterFactory.java-revBASE.svn000.tmp.java D:/workspace_other/amateras/stepcounter/tags/1.16/tk.eclipse.plugin.stepcounter/src/tk/stepcounter/StepCounterFactory.java
--- C:/Documents and Settings/orangeclover/Local Settings/Temp/StepCounterFactory.java-revBASE.svn000.tmp.java	Mon Nov 08 21:14:16 2010
+++ D:/workspace_other/amateras/stepcounter/tags/1.16/tk.eclipse.plugin.stepcounter/src/tk/stepcounter/StepCounterFactory.java	Mon Nov 08 21:16:32 2010
@@ -273,6 +273,13 @@
 			counter.setFileType("Haskell");
 			return counter;
 
+		} else if(fileName.endsWith(".groovy")||fileName.endsWith(".gv")||fileName.endsWith(".gy")){
+			DefaultStepCounter counter = new DefaultStepCounter();
+			counter.addLineComment("//");
+			counter.addAreaComment(new AreaComment("/*","*/"));
+			counter.setFileType("Groovy");
+			return counter;
+
 		} else {
 			return null;
 		}

StepCounterFactory全体

package tk.stepcounter;

/**
 * ステップカウンタのインスタンスを生成するファクトリ。
 * このクラスを修正することで簡単に対応する形式を追加することができます。
 *
 * <ul>
 *   <li>1.16.0 - .htm(HTML), dicon</li>
 *   <li>1.15.0 - VB.NET, C#</li>
 *   <li>1.14.0 - Python, Lua, Haskell</li>
 * </ul>
 */
public class StepCounterFactory {

	/**
	 * Java用のカウンタを作成します。
	 */
	private static DefaultStepCounter createJavaCounter(String name){
		DefaultStepCounter counter = new DefaultStepCounter();
		counter.addLineComment("//");
		counter.addAreaComment(new AreaComment("/*","*/"));
		counter.setFileType(name);
//		counter.addSkipPattern("^package .+;$");
//		counter.addSkipPattern("^import .+;$");
		return counter;
	}

	/**
	 * VB用のカウンタを作成します。
	 */
	private static DefaultStepCounter createVBCounter(String name){
		DefaultStepCounter counter = new DefaultStepCounter();
		counter.addLineComment("'");
		counter.addLineComment("REM");
		counter.setFileType(name);
		return counter;
	}

	/**
	 * シェルスクリプト用のカウンタを作成します。
	 */
	private static DefaultStepCounter createShellCounter(String name){
		DefaultStepCounter counter = new DefaultStepCounter();
		counter.addLineComment("#");
		counter.setFileType(name);
		return counter;
	}

	/**
	 * XML用のカウンタを作成します。
	 */
	private static DefaultStepCounter createXMLCounter(String name){
		DefaultStepCounter counter = new DefaultStepCounter();
		counter.addAreaComment(new AreaComment("<!--","-->"));
		counter.setFileType(name);
		return counter;
	}

	/**
	 * ステップカウンタのインスタンスを取得します。
	 * 未対応の形式の場合、nullを返します。
	 *
	 * @param fileName ファイル名
	 * @return ファイル名に対応したステップカウンタのインスタンス。未対応の場合null。
	 */
	public static StepCounter getCounter(String fileName){
		// 小文字に変換
		fileName = fileName.toLowerCase();

		if(fileName.endsWith(".java")){
			// Java用カウンタを作成
			return createJavaCounter("Java");

		} else if(fileName.endsWith(".cpp") || fileName.endsWith(".c")){
			// C/C++用カウンタを作成
			return createJavaCounter("C/C++");

		} else if(fileName.endsWith(".h")){
			//ヘッダファイル用カウンタを作成
			return createJavaCounter("h");

		} else if(fileName.endsWith(".cs")){
			// C#用カウンタを作成
			return createJavaCounter("C#");

		} else if(fileName.endsWith(".jsp")){
			// JSP用カウンタを作成
			DefaultStepCounter counter = new DefaultStepCounter();
			counter.addLineComment("//");
			counter.addAreaComment(new AreaComment("/*","*/"));
			counter.addAreaComment(new AreaComment("<%--","--%>"));
			counter.addAreaComment(new AreaComment("<!--","-->"));
			counter.setFileType("JSP");
			return counter;

		} else if(fileName.endsWith(".php") || fileName.endsWith(".php3")){
			// PHP用カウンタを作成
			DefaultStepCounter counter = new DefaultStepCounter();
			counter.addLineComment("//");
			counter.addAreaComment(new AreaComment("/*","*/"));
			counter.addAreaComment(new AreaComment("<!--","-->"));
			counter.setFileType("PHP");
			return counter;

		} else if(fileName.endsWith(".asp") || fileName.endsWith(".asa")){
			// ASP用カウンタを作成
			DefaultStepCounter counter = new DefaultStepCounter();
			counter.addLineComment("'");
			counter.addAreaComment(new AreaComment("<!--","-->"));
			counter.setFileType("ASP");
			return counter;

		} else if(fileName.endsWith(".html") || fileName.endsWith(".htm")){
			// HTML用カウンタを作成
			return createXMLCounter("HTML");

		} else if(fileName.endsWith(".xhtml")){
			// XHTML用カウンタを作成
			return createXMLCounter("XHTML");
			
		} else if(fileName.endsWith(".js")){
			// JavaScript用カウンタを作成
			return createJavaCounter("js");

		} else if(fileName.endsWith(".vbs")){
			// VBScript用カウンタを作成
			return createVBCounter("vbs");

		} else if(fileName.endsWith(".bas") || fileName.endsWith(".frm") || fileName.endsWith(".cls")){
			// VB用カウンタを作成
			return createVBCounter("VB");

		} else if(fileName.endsWith(".vb")){
			// VB.NET用カウンタを作成
			return createVBCounter("VB.NET");

		} else if(fileName.endsWith(".pl") || fileName.endsWith(".pm")){
			// Perl用カウンタを作成
			DefaultStepCounter counter = new DefaultStepCounter();
			counter.addLineComment("#");
			counter.addAreaComment(new AreaComment("=pod","=cut"));
			counter.setFileType("Perl");
			return counter;

		} else if(fileName.endsWith(".py")){
			// Python用カウンタを作成
//			DefaultStepCounter counter = new DefaultStepCounter();
//			counter.addLineComment("#");
//			counter.setFileType("Python");
			return new PythonCounter();

		} else if(fileName.endsWith(".rb")){
			// Ruby用カウンタを作成
			DefaultStepCounter counter = new DefaultStepCounter();
			counter.addLineComment("#");
			counter.addAreaComment(new AreaComment("=begin","=end"));
			counter.setFileType("Ruby");
			return counter;

		} else if(fileName.endsWith(".tcl")){
			// Tcl用カウンタを作成
			return createShellCounter("Tcl");

		} else if(fileName.endsWith(".sql")){
			// SQL用カウンタを作成
			DefaultStepCounter counter = new DefaultStepCounter();
			counter.addLineComment("#");
			counter.addLineComment("--");
			counter.addLineComment("REM");
			counter.addAreaComment(new AreaComment("/*","*/"));
			counter.setFileType("SQL");
			return counter;

		} else if(fileName.endsWith(".cfm")){
			// ColdFusion用カウンタを作成
			DefaultStepCounter counter = new DefaultStepCounter();
			counter.addAreaComment(new AreaComment("<!--","-->"));
			counter.addAreaComment(new AreaComment("<!---","--->"));
			counter.setFileType("CFM");
			return counter;

		} else if(fileName.endsWith(".properties")) {
			// プロパティファイル用カウンタを作成
			return createShellCounter("Properties");

		} else if(fileName.endsWith(".xml") || fileName.endsWith(".dicon")) {
			// XML用カウンタを作成
			return createXMLCounter("XML");

		} else if(fileName.endsWith(".xsl")) {
			// XSLT用カウンタを作成
			return createXMLCounter("XSLT");

		} else if(fileName.endsWith(".xi")) {
			// Xi用カウンタを作成
			return createXMLCounter("Xi");

		} else if(fileName.endsWith(".dtd")) {
			// DTD用カウンタを作成
			return createXMLCounter("DTD");

		} else if(fileName.endsWith(".tld")) {
			// TLD用カウンタを作成
			return createXMLCounter("TLD");

		} else if(fileName.endsWith(".xsd")) {
			// XMLSchema用カウンタを作成
			return createXMLCounter("XMLSchema");

		} else if(fileName.endsWith(".bat")){
			// BATファイル用カウンタを作成
			DefaultStepCounter counter = new DefaultStepCounter();
			counter.addLineComment("REM");
			counter.setFileType("BAT");
			return counter;

		} else if(fileName.endsWith(".css")){
			// CSS用カウンタを作成
			DefaultStepCounter counter = new DefaultStepCounter();
			counter.addAreaComment(new AreaComment("/*","*/"));
			counter.setFileType("CSS");
			return counter;

		} else if(fileName.endsWith(".l") || fileName.endsWith(".el") || fileName.endsWith(".cl")){
			// Lisp用カウンタを作成
			DefaultStepCounter counter = new DefaultStepCounter();
			counter.addLineComment(";");
			counter.setFileType("Lisp");
			return counter;

		} else if(fileName.endsWith(".scm")){
			// Scheme用カウンタを作成
			DefaultStepCounter counter = new DefaultStepCounter();
			counter.addLineComment(";");
			counter.setFileType("Scheme");
			return counter;

		} else if(fileName.endsWith(".st")){
			// Smalltalk用カウンタを作成
			DefaultStepCounter counter = new DefaultStepCounter();
			counter.addAreaComment(new AreaComment("\"","\""));
			counter.setFileType("Smalltalk");
			return counter;

		} else if(fileName.endsWith(".vm") || fileName.endsWith(".vsl")){
			// Velocity用カウンタを作成
			DefaultStepCounter counter = new DefaultStepCounter();
			counter.addLineComment("##");
			counter.setFileType("Velocity");
			return counter;

		} else if(fileName.endsWith(".ini")){
			// INI用カウンタを作成
			DefaultStepCounter counter = new DefaultStepCounter();
			counter.addLineComment(";");
			counter.setFileType("INI");
			return counter;

		} else if(fileName.endsWith(".lua")){
			// Luaカウンタを作成
			DefaultStepCounter counter = new DefaultStepCounter();
			counter.addLineComment("--");
			counter.addAreaComment(new AreaComment("--[[","]]"));
			counter.addAreaComment(new AreaComment("--[===[","]===]"));
			counter.setFileType("Lua");
			return counter;

		} else if(fileName.endsWith(".hs")){
			// Haskellカウンタを作成
			DefaultStepCounter counter = new DefaultStepCounter();
			counter.addLineComment("--");
			counter.addAreaComment(new AreaComment("{-","-}"));
			counter.setFileType("Haskell");
			return counter;

		} else if(fileName.endsWith(".groovy")||fileName.endsWith(".gv")||fileName.endsWith(".gy")){
			DefaultStepCounter counter = new DefaultStepCounter();
			counter.addLineComment("//");
			counter.addAreaComment(new AreaComment("/*","*/"));
			counter.setFileType("Groovy");
			return counter;

		} else {
			return null;
		}
	}
}

作成したjar

コンパイルして作成したjarは以下に置いてある。
http://dl.dropbox.com/u/645223/stepcounter/stepcounter.jar