代码重构-了解你的代码:cloc + simian

article/2025/11/9 10:00:10

文章目录

  • 前言
  • cloc
    • 安装
    • 使用
  • Simian
    • 安装
    • 使用

前言

关于代码重构有很多书籍,理论和工具。准备开个系列边学习边分享。

这次先学习和介绍两个比较简单的工具。

cloc

cloc counts blank lines, comment lines, and physical lines of source code in many programming languages.

cloc主要用于统计代码行数,会统计空格、注释和我们工程中,各项代码的分布情况。显示效果如下:

在这里插入图片描述

repo地址:

https://github.com/AlDanial/cloc

安装

release 地址

https://github.com/AlDanial/cloc/releases/tag/1.88

mac可以使用brew安装

brew install cloc

使用

统计文件夹
cloc ./

统计文件

cloc hello.c

git repo的某次提交

prompt> git clone http://git.tiker.net/trees/pudb.gitprompt> cd pudbprompt> cloc 6be804e07a5db

更多信息参考

https://github.com/AlDanial/cloc#quick-start-

Simian

Simian (Similarity Analyser) identifies duplication in Java, C#, C, C++, COBOL, Ruby, JSP, ASP, HTML, XML, Visual Basic, Groovy source code and even plain text files. In fact, simian can be used on any human readable files such as ini files, deployment descriptors, you name it.

Simian用于检查Java, C#, C, C++, COBOL, Ruby, JSP, ASP, HTML, XML, Visual Basic, Groovy代码中的重复部分(对于其他文字也同样适用)。基于行的代码匹配,不涉及到语义层面。所以检查出来的代码就是完全重复的。对去除重复代码有一定的帮助。

对于开源或者非商业用途,是可以免费使用的。

A Personal/SOHO License for Simian is US$99.

A project/build server license for Simian is US$499 and entitles you to use Simian on any number of machines solely for the licensed project, or on a single machine for many projects.

安装

下载界面

http://www.harukizaemon.com/simian/get_it_now.html

使用

举例如下:
/d/simian-2.5.10/bin/simian-2.5.10.exe -includes="C:\projects\my-projects\**\*.cs" -threshold=5 -formatter=xml:d:/simian5_cs.xml

-includes 指定了需要检测的文件内容
***.cs表示检测文件夹中所有的cs文件
-threshold指定了重复的行数阈值
-formatter指定了输出的文件

输出的xml文件会指出哪些文件的哪些行会有重复,最后有一个统计数据。


http://chatgpt.dhexx.cn/article/qOf3DhP1.shtml

相关文章

安全团队不可错过的 7 个开源工具

微信搜索逆锋起笔关注后回复编程pdf 领取编程大佬们所推荐的 23 种编程资料! 项目地址:https://github.com/tmobile/pacbot 文章来源:安全牛 开源工具是网络安全团队武器库中必不可少的利器,在云计算普及的今天,虽然云安全厂商们大…

html去除重复代码,simian 查找项目中的重复代码

证明文件是完整的,可忽略 然后解压simian-2.5.10.tar.gz,并把解压后的文件放到D:Program_Filessimian-2.5.10目录下 使用bin目录下的jar 执行命令,从src目录下找到重复3行的重复代码,并将找到的结果放入D:esult.txt中 java -jar D…

如何产出规范、安全、高质量的代码?

对于一个软件开发团队,可以通过哪些代码质量指标和扫描方法让团队产出规范、安全、高质量的代码?让开发团队运行的安全、透明、可靠?本文总结了其中一些实践和工具,包含常见代码质量扫描工具、代码质量指标、第三方依赖管理、安全…

重复代码检查工具simian的基本用法

simian是一个检查重复代码的工具,支持通过命令行和UI方式来检查代码,可以检查多种语言(比如C\C, java, c#等)的代码,常见的编程语言都支持,下面先来看看如何使用命令行来检查c重复代码的。 E:\temp\simian-…

CC simian

看它还好.所以就收藏起来. 让开发自动化: 除掉构建脚本中的气味创建一致、可重复、可维护的构建 文档选项 打印本页将此页作为电子邮件发送级别: 初级Paul Duvall (paul.duvallstelligent.com), CTO, Stelligent Incorporated2006 年 11 月 1…

使用Simian检查Java项目中冗余代码

Simian UI 是一个用来发现重复代码的eclipse插件,对于改善设计,消除冗余代码很有帮助。 使用eclipse的Help->Software Update进行安装。站点地址为:http://www.integility.com/eclipse/ 安装后,按照提示重新启动eclipse. 1 在希望进行分析…

使用Simian工具扫描重复代码

工具下载地址:http://www.harukizaemon.com/simian/get_it_now.html 1. simian命令行的格式: java -jar simian.jar [options] [files] simian.exe [options] [files] 2. Usage: [options] [files] 命令描述-balanceCurlyBraces[/-]Accounts for curl…

异常解决java.lang.ClassNotFoundException: org.springframework.boot.actuate.endpoint.PublicMetrics

异常java.lang.ClassNotFoundException: org.springframework.boot.actuate.endpoint.PublicMetrics 原因:springboot-web 版本冲突 修改版本为1.5.9

关闭springboot健康检查 org.springframework.boot.actuate.health.AbstractHealthIndicator 89 health - Elastic

错误日志:org.springframework.boot.actuate.health.AbstractHealthIndicator 89 health - Elasticsearch health check failed java.net.ConnectException: Connection refused: no further information 出现这个错误是spring对Elasticsearch监测失败,解…

解决 Spring Cloud 整合 zipkin 报错:org.springframework.boot.actuate.health.CompositeHealthIndicator......

文章目录 一、问题描述二、解决方法 一、问题描述 我的 Spring Boot 版本是 2.3.4&#xff0c;Spring Cloud 版本是 Hoxton.SR1。 要整合 zipkin&#xff0c;先在服务端导入了以下依赖&#xff1a; <dependencies><dependency><groupId>io.zipkin.java</g…

NoClassDefFoundError: org/springframework/boot/actuate/web/trace/servlet/HttpTraceFilter

线上项目运行期间报错&#xff1a;java.lang.NoClassDefFoundError: org/springframework/boot/actuate/web/trace/servlet/HttpTraceFilter$CustomStatusResponseWrapper 提示class找不到&#xff0c;百思不得其解&#xff0c;sping的jar咋会找不到&#xff0c;最后怀疑是打包…

org/springframework/boot/actuate/metrics/cache/CacheMeterBinderProvider not found. Make sure your ow

报错信息如下 java.lang.IllegalStateException: Could not evaluate condition on org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration$EndpointWebMvcConfiguration due to org/springframework/boot/actuate/metrics/cache/CacheMeterBinder…

spring boot 源码解析52-actuate中MVCEndPoint解析

前言 之前的几篇文章分析了spring boot 中有关endpoint的实现,细心的朋友可以发现,在org.springframework.boot.actuate.endpoint.mvc 包下也有一系列的xxxEndpoint,这又是为什么呢? 原因是: 我们很多情况下,都是访问接口的方式获取应用的监控,之前的分析是其实现的底层,要想…

Unable to identify any set of controllers that can actuate the specified joints:

提示&#xff1a;文章写完后&#xff0c;目录可以自动生成&#xff0c;如何生成可参考右边的帮助文档 文章目录 背景一、解决办法二、总结 背景 具体的报错如下&#xff1a; [ERROR] [1649324583.023988413]: Unable to identify any set of controllers that can actuate the…

springboot整合Actuator监控

springboot整合Actuator监控。 1.简要说明&#xff1a; Actuator提供了对springboot应用程序监视和管理的能力&#xff0c;可以选择通过使用HTTP Endpoint或者使用JMX来管理和监控springboot应用程序。 Actuator 允许通过Endpoints对springboot进行监控和交互。springboot内…

项目监控之Spring Boot 监控端点 Actuator 入门

1. 概述 应用在部署在生产环境下&#xff0c;我们还需要考虑应用的管理与监控。例如说&#xff0c;应用是否健康存活、应用的 JVM 监控信息、服务器的监控信息&#xff08;CPU、内存、磁盘等等&#xff09;。 如果我们为应用的管理与监控做相应的开发&#xff0c;是需要一定的…

spring boot 源码解析23-actuate使用及EndPoint解析

前言 spring boot 中有个很诱人的组件–actuator,可以对spring boot应用做监控,只需在pom文件中加入如下配置即可: <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></depen…

ESXi挂载NFS共享存储

通常VMware的整体架构由三个部分组成&#xff0c;虚拟化环境&#xff08;包括ESXi与vCenter以及VM&#xff09;&#xff0c;交换机&#xff08;通常为万兆交换机或光纤交换机&#xff09;&#xff0c;存储&#xff08;netap、EMC等&#xff09;。使用光纤交换机&#xff0c;ESX…

Docker容器中挂载NFS共享目录

之前在https://blog.csdn.net/fengbingchun/article/details/110561129 介绍过使用Dockerfile构建ubuntu 16.04镜像,并在容器中编译执行Messy_Test项目.这里介绍下如何在容器中挂载NFS服务器上的共享目录. Dockerfile内容如下&#xff1a; FROM ubuntu:16.04 LABEL maintaine…

LINUX 下创建NFS共享目录

Linux下创建NFS共享目录的步骤如下 实验中服务器端IP为10.201.86.204&#xff0c;客户端IP为10.201.86.2051.在服务器端格式化需要共享的磁盘 fdisk /dev/sdb mkfs.xfs -f /dev/sdb12.安装NFS软件包 Server端和客户端都要安装 rpm -qa |grep nfs-utils rpm -qa |grep rpcb…