javaWeb代码工程统计
直接放在src/test/java包内运行
/**
* 代码行数统计
* @author ThinkGem
* @version 2014-7-22
*/
public class CodeCounter { public static void main(String[] args) {
//获取当前类的资源文件路径,即../../target/test-classes/
String file = CodeCounter.class.getResource("/").getFile();
// System.out.println(file);
//path=D:/Source_Code/koudaimini/src/
//设置统计根路径为src
// String path = file.replace("target/test-classes", "src");
String path = "D:\\Source_Code\\zbg\\modules\\zbg-api\\src"; ArrayList<File> al = CodeCounter.getFile(new File(path));
for (File f : al) {
if (f.getName().matches(".*\\.java$")){ // 匹配java格式的文件
CodeCounter.count(f);
System.out.println(f);
}
}
System.out.println("统计文件:" + CodeCounter.files);
System.out.println("代码行数:" + CodeCounter.codeLines);
System.out.println("注释行数:" + CodeCounter.commentLines);
System.out.println("空白行数:" + CodeCounter.blankLines);
}
static long files = 0;
static long codeLines = 0;
static long commentLines = 0;
static long blankLines = 0;
static ArrayList<File> fileArray = new ArrayList<File>(); /**
* 获得目录下的文件和子目录下的文件
* @param f
* @return
*/
public static ArrayList<File> getFile(File f) {
File[] ff = f.listFiles();
for (File child : ff) {
if (child.isDirectory()) {
CodeCounter.getFile(child);
} else {
CodeCounter.fileArray.add(child);
}
}
return CodeCounter.fileArray; } /**
* 统计方法
* @param f
*/
private static void count(File f) {
BufferedReader br = null;
boolean flag = false;
try {
br = new BufferedReader(new FileReader(f));
String line = "";
while ((line = br.readLine()) != null) {
line = line.trim(); // 除去注释前的空格
if (line.matches("^[ ]*$")) { // 匹配空行
CodeCounter.blankLines++;
} else if (line.startsWith("//")) {
CodeCounter.commentLines++;
} else if (line.startsWith("/*") && !line.endsWith("*/")) {
CodeCounter.commentLines++;
flag = true;
} else if (line.startsWith("/*") && line.endsWith("*/")) {
CodeCounter.commentLines++;
} else if (flag == true) {
CodeCounter.commentLines++;
if (line.endsWith("*/")) {
flag = false;
}
} else {
CodeCounter.codeLines++;
}
}
CodeCounter.files++;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (br != null) {
try {
br.close();
br = null;
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
类似结果
D:/。。/koudaimini/src/
统计文件:46
代码行数:2798
注释行数:814
空白行数:652
javaWeb代码工程统计的更多相关文章
- [statsvn]-svn代码量统计
用statasvn进行代码量统计的时候,第一步需要获取到项目的日志,但是我本机的svn1.4没有安装命令行,重新运行1.4的安装包也没有命令行的选项... 那就升级到最新的svn1.8好了,下载最新的 ...
- 如何创建 SVN 服务器,并搭建自己的 SVN 仓库 如何将代码工程添加到VisualSVN Server里面管理
如何创建 SVN 服务器,并搭建自己的 SVN 仓库,附链接: https://jingyan.baidu.com/article/6b97984dca0d9c1ca3b0bf40.html 如何将代 ...
- 【转】Git 代码行统计命令集
查看git上个人代码量 git log --author="username" --pretty=tformat: --numstat | awk '{ add += $1; su ...
- IDEA 代码量统计(Statistic)
IDEA 代码量统计(Statistic) 1.1 前言 项目到了一定阶段,都会想要看看项目的代码量情况,这里主要使用插件Statistic进行代码统计查看. 1.2 安装插件步骤 找到插件市场入口并 ...
- “代码量统计脚本”
概述 本文从一段统计C/C++程序脚本入手,记录shell脚本常用和重要的知识点. 代码量统计程序 文件名称,count_code_line.sh 12345678910111213141516171 ...
- 代码图形统计工具git_stats web
目录 一.简介 二.安装ruby 三.配置git_stats 四.通过nginx把网页展示出来 一.简介 仓库代码统计工具之一,可以按git提交人.提交次数.修改文件数.代码行数.注释量在时间维度上进 ...
- mac OS X下git代码行统计命令
1.统计某人的代码提交量,包括增加,删除 git log --author=-- --until=-- --pretty=tformat: --numstat | awk '{ add += $1 ; ...
- 【转】Git代码行统计命令集
http://blog.csdn.NET/dwarven/article/details/46550117 http://blog.csdn.net/hshl1214/article/details/ ...
- iOS纯代码工程手动快速适配
首先说下让自己的程序支持iPhone6和6+,第一种使用官方提供的launch screen.xib,这个直接看官方文档即可,这里不再多述:第二种方法是和之前iPhone5的类似,比较简单,为iPho ...
随机推荐
- sql-多表查询
一:外连接 1.左外连接(left join) select * from A left join B on A.id=B.a_id 结果如下 很明显,A表的所有数据都显示出来了 ...
- dom4j 操作总结
在官网https://dom4j.github.io/下载最新的dom4j的jar包,以及配合xpath解析的http://central.maven.org/maven2/jaxen/jaxen/1 ...
- mysql 的 select into 带来的错误数据问题
在写存储过程的时候,会有一个被忽视的问题: 比如 select user_name into @user_name from user where id = 1; 会出现 其实没有 id =1 这条数 ...
- 2018-10-19,下午4点拿到京东offer
今天12点没有问题就签.岗位,地点都很满足.京东居然对我这么好,保证以后不做损坏京东利益的事写给以后的自己.
- json字符转对象之new Function('return ' + str)
var jsonStr = '{"id":1,"name":"linda","hobbies":[{"id&q ...
- centos6.9 编译安装 zabbix-3.0.15
本文采用编译安装,请在zabbix官网下载所需版本.此处安装版本是:zabbix-3.0.15.tar.gz 操作系统:centos 6.9 一.安装mysqlmysql-community-libs ...
- JSP内置对象page/pageContext/Config/Exception
Config对象 config对象实是在一个Servlet初始化时,JSP引擎向它传递信息用的,此信息包括Servlet初始化时所要用到的参数(通过属性名和属性值构成)以及服务器的有关信息(通过传递一 ...
- sshpass 使用方法
首先下载sshpass并且安装 $ tar -zxvf sshpass-1.06.tar.gz $ cd sshpass-1.06 $ ./configure --prefix=/usr/local/ ...
- Python之路(一)-python简介
一.python简介,python2.x与python3.x的区别 Python是著名的“龟叔”Guido van Rossum在1989年圣诞节期间,为了打发无聊的圣诞节而编写的一个编程语言. Py ...
- SQL SERVER占用CPU过高优化
操作系统是Windows2008R2 ,数据库是SQL2014 64位. 近阶段服务器出现过几次死机,管理员反馈机器内存使用率100%导致机器卡死.于是做了个监测服务器的软件实时记录CPU数据,几日观 ...