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 ...
随机推荐
- tiny4412 --uboot移植(2) 点灯
开发环境:win10 64位 + VMware12 + Ubuntu14.04 32位 工具链:linaro提供的gcc-linaro-6.1.1-2016.08-x86_64_arm-linux-g ...
- 29.Mysql监控
29.Mysql监控29.1 如何选择一个监控方案 29.1.1 选择何种监控方式 29.1.2 如何选择合适自己的监控工具29.2 常用网络监控工具 29.2.1 Cacti简介 29.2.2 Na ...
- JS中的offset scroll event client
一.offset 一般用来检测盒子的偏移.位移,都是只读属性,不能赋值 offsetWidth和offsetHeight表示的是:调用者盒子的宽和高,包括盒子自身的padding和border off ...
- Java代码获取spring 容器的bean几种方式
一.目的 写了一个项目,多个module,然后想在A模块中实现固定的config注入,当B模块引用A时候,能够直接填写相对应的配置信息就行了.但是遇到一个问题,B引用A时候,A的配置信息总是填充不了, ...
- PowerShell 脚本中调用密文密码
1. 把密码转变为加密的字符串.使用命令 ConvertFrom-SecureString Read-Host "Enter Password" -AsSecureString | ...
- boost asio 学习(三)post与dispatch
http://www.gamedev.net/blog/950/entry-2249317-a-guide-to-getting-started-with-boostasio?pg=4 本章节为io_ ...
- javaScrpit 开端
JavaScript 代码可以直接嵌在网页的任何地方,不过我们通常把JavaScrpit放到<head>中: <html> <head> <script> ...
- M1卡知识点描述
- tensorflow学习之(二)Seesion的两种打开模式
#Seesion的两种打开模式 import tensorflow as tf matrix1 = tf.constant([[3,3]])#一行两列的一个矩阵 matrix2 = tf.consta ...
- Configuration Error: deployment source 'SocietyManage:war exploded' is not valid
Configuration Error: deployment source 'SocietyManage:war exploded' is not valid 原因:没有下图的底下的红色框的内容.( ...