Checking tool of object oriented exercises by nine rules.
1.6K
This tool validates the following nine rules for the object oriented programming exercise in Java language.
A book titled 'The ThoughtWorks Anthology: Essays on Software Technology and Innovation' are published. Chapter 6 in the book introduces object calisthenics for better software design. The rules shown in the book are as follows.
DONE),else keyword (DONE),DONE),DONE),Not support yet),DONE),DONE), andNot support yet).DONE),DONE), andDONE)Unfortunately, to confirm obeying the rules is by a human eye. Therefore, this tool was developed to validate the rules automatically by analyzing given Java source codes. By the way, this tool is programed to obey above rules.
The following demo shows validating Java source codes in top directory of 9rules project.

The demo was executed the following commands.
$ tree src/test/resources/hello/src/main/java/
// The result of tree command was printed.
$ java -jar target/9rules-1.1.0-SNAPSHOT.jar src/test/resources/hello/src/main/java/
// ... skip
src/test/resources/hello/src/main/java/sample/hello/HelloWorld.java
line: 10, setter method found.
line: 14, getter method found.
line: 18, method is too long (over 3 lines).
// ... skip
$ cat -n src/test/resources/hello/src/main/java/sample/hello/HelloWorld.java
// Print source code.
At the second command, the demo performed 9rules to validate given source directory. One of the results was shown in above list, 9rules reports that the following violations were found. You can find the violations to see the actual source code.
-jar option of the java command.
$ java -jar target/9rules-1.X.jar <TARGET SOURCE DIR...><TARGET SOURCE DIR...> accepts several directories and several source files.
The help message is as follows.
java -jar 9rules.jar [OPTIONS] <ARGUMENTS...>
OPTIONS:
--strict: Strictly level check (Default).
--general: General level check.
--rough: Rough level check.
--help: Print this message and exit.
ARGUMENTS:
Directories include Java source files, and Java source files.
If it is hard to obey the rules shown in above, we can lower the validating level by specifying the option.
--strict option) is just rules shown in above.--general option) is lowered as follows.
else keyword (same as strict),--rough option) is lowered as follows.
else keyword (same as strict),Container images for Docker of 9rules are:
tamada/9rules
1.1.1, latest1.1.01.0.0-v2To run the 9rules by the docker container:
$ docker run --rm -v "$PWD":/home/ninerules tamada/9rules <ARGUMENTS...>
ARGUMENTS...: the arguments for 9rules.--rm: remove the container after running.-v "$PWD":/home/ninerules: share volume $PWD in host to /home/ninerules in the container.
$PWD must be the absolute path.$ docker run --rm -v "$PWD":/home/ninerules tamada/9rules:latest src/main/java
src/main/java shows the source directory of the 9rules project.
Clone the project from GitHub.
Change directory to cloned project.
Run the following command to build the project.
Commands
$ git clone [email protected]:tamada/9rules.git$ cd 9rules$ mvn packagegit checkout -b my-new-feature)git commit -m 'Add some feature')mvn package)git push origin my-new-feature)Apache License v 2.0
このツールは,オブジェクト指向プログラミングエクササイズで言われている9つのルールが遵守できているかを確認するツールです.
ThoughtWorksアンソロジー ――アジャイルとオブジェクト指向によるソフトウェアイノベーション という本がオライリージャパンから出版されている. その本の第5章にて,オブジェクト指向エクササイズという,ソフトウェア設計を改善する9つのルールが紹介されている. そのルールは次の通りである.
DONEelse句を使用しないこと.DONEDONEDONE未実装DONEDONE未実装DONEDONEDONE残念ながら,これらのルールに従っているかを確認する方法は目視のみでした. そのため,与えられた Java ソースコードが上記ルールに従っているかを自動的に検証するため,このツールを作成しました. なお,このツール自体も,上記ルールに従うよう作成しています.
以下のデモでは,サンプルソースコードが 9rules のルールに従っているかを確認しています. この実行結果を得るには,9rules プロジェクトのトップディレクトリにて同じコマンドを入力してください.

実行しているコマンドは次の通りです.
$ tree src/test/resources/hello/src/main/java/
// tree コマンドの結果が表示される.
$ java -jar target/9rules-1.0-SNAPSHOT.jar src/test/resources/hello/src/main/java/
// ... 途中省略
src/test/resources/hello/src/main/java/sample/hello/HelloWorld.java
line: 10, setter method found.
line: 14, getter method found.
line: 18, method is too long (over 3 lines).
// ... 途中省略
$ cat -n src/test/resources/hello/src/main/java/sample/hello/HelloWorld.java
// ソースコードの内容を確認している.
2つ目のコマンドが実際に実行しているところです.
実行結果の,src/test/resources/hello/src/main/java/sample/hello/HelloWorld.java を見てみましょう.
ルールの違反が3つあると出力されています.これはつまり以下の内容が指摘されています.
指摘された違反が正しいかを実際にソースコードをみて確認してください.
javaコマンドの -jarオプションに 9rules-1.X.jar を指定してください.
$ java -jar target/9rules-1.X.jar <TARGET SOURCE DIR...><TARGET SOURCE DIR...> には複数のディレクトリや,Javaのソースファイルを指定できます.
ヘルプメッセージは次の通りです.
java -jar 9rules.jar [OPTIONS] <ARGUMENTS...>
OPTIONS:
--strict: Strictly level check (Default).
--general: General level check.
--rough: Rough level check.
--help: Print this message and exit.
ARGUMENTS:
Directories include Java source files, and Java source files.
上記に示した9つのルールの遵守が難しい場合は,オプションの指定で,違反レベルを下げることも可能です. If it is hard to obey the rules shown in above, we can lower the validating level by specifying the option.
--strictオプション(デフォルト)では,上記に示したルールで検証します.--generalオプションでは,次のルールで検証します.
---strictと同じ).else句を使用しないこと(---strictと同じ).---strictと同じ).未実装未実装---strictと同じ).---strictと同じ).else句を使用しないこと(---strictと同じ).---strictと同じ).未実装未実装---strictと同じ).---strictと同じ).GitHub からプロジェクトをクローンしてください.
クローンしてできたディレクトリに移動してください.
Mavenコマンドを実行し,プロジェクトをビルドしてください.
上記の手順は以下のコマンドを実行するのと同じです.
$ git clone [email protected]:tamada/9rules.git$ cd 9rules$ mvn packagegit checkout -b my-new-feature)git commit -m 'Add some feature')mvn package)git push origin my-new-feature)Apache License v 2.0
Content type
Image
Digest
Size
46.7 MB
Last updated
over 5 years ago
docker pull tamada/9rules