simian 查找项目中的重复代码

http://www.harukizaemon.com/simian/get_it_now.html地址下载

simian-2.5.10.tar.gz

simian-2.5.10.tar.gz.MD5   这个是用来检测上一个文件是否完整用的,

 

 证明文件是完整的,可忽略

 

然后解压simian-2.5.10.tar.gz,并把解压后的文件放到D:\Program_Files\simian-2.5.10目录下

 

使用bin目录下的jar

执行命令,从src目录下找到重复3行的重复代码,并将找到的结果放入D:\result.txt中

 

java -jar D:\Program_Files\simian-2.5.10\bin\simian-2.5.10.jar -threshold=3 "D:\workspace\idea\father\src\**\*.java" >> D:\result.txt

  

 

Simian命令行的格式:

java -jar simian.jar [options] [files]

Usage: [options] [files]

命令 描述
-balanceCurlyBraces[+/-] Accounts for curly braces when breaking lines
-balanceParentheses[+/-] Accounts for parentheses when breaking lines
-balanceSquareBrackets[+/-] Accounts for square brackets when breaking lines
-config=FNAME Reads the configuration from the specifiedfile
-defaultLanguage=LANG Assumes files are in the specified language if none can be inferred
-excludes=SPEC Excludes files matching the specified pattern
-failOnDuplication[+/-/%] Exits with a failure return code if duplication detected
-formatter=TYPE[:FNAME] Uses the specified output format when reporting
-ignoreBlocks=START:END Ignores all lines between START/END
-ignoreCharacterCase[+/-] Matches character literals irrespective of case
-ignoreCharacters[+/-] Completely ignores character literals
-ignoreCurlyBraces[+/-] Completely ignores curly braces
-ignoreIdentifierCase[+/-] Matches identifiers irresepctive of case
-ignoreIdentifiers[+/-] Completely ignores identifiers
-ignoreLiterals[+/-] Completely ignores all literals (strings, numbers and characters)
-ignoreModifiers[+/-] Ignores modifiers (public, private, static, etc.)
-ignoreNumbers[+/-] Completely ignores numbers
-ignoreOverlappingBlocks[+/-] Ignores blocks that wholly or partially overlap
-ignoreRegions[+/-] Ignores all lines between #region/#endregion
-ignoreStringCase[+/-] Matches string literals irrespective of case
-ignoreStrings[+/-] Completely ignores the contents of strings
-ignoreSubtypeNames[+/-] Matches on similar type names (eg. Reader and FilterReader)
-ignoreVariableNames[+/-] Completely ignores variable names (fields, parameters and locals)
-includes=SPEC Including files matching the specified pattern
-language=LANG Assumes ALL files are in the specified language
-reportDuplicateText[+/-] Prints the duplicate text in reports
-threshold=COUNT Matches will contain at least the specified number of lines

 

示例说明:

一些参数:
  • 检查包括子目录下的所有的c#文件:

"-recurse=*.cs" 

  • 检查当前目录下的所有c#文件 ,并且只检查代码3行以上重复的代码

-threshold=3 "*.cs"

  • 在当前目录的所有子文件夹下检测所有c和h后缀的文件:
    **/*.c **/*.h

 

  • 检测两个不同目录下的所有java文件:
    "/csharp-source/*.cs" "/java-source/*.java"

 

  • 检测所有子目录下的所有java文件,包括test类:
    -includes=**/*.java -excludes=**/*Test.java

 

  • 检测当前目录下的所有java文件,且忽略其中的数字的不同:
    -ignoreNumbers "*.java"

 

  • 检测所有java文件,并以xml格式显示结果:
    -formatter=xml "*.rb"

 

  • 从文件中读取配置参数(文件中一行只能包括一个simian有效的参数):
    -config=simian.config
posted @ 2020-11-05 22:03  飞叶-枯寂  阅读(315)  评论(0编辑  收藏  举报